|
|
@ -64,15 +64,66 @@ int test_simple() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int test_primitive() {
|
|
|
|
int test_primitive() {
|
|
|
|
|
|
|
|
int r;
|
|
|
|
jsmn_parser p;
|
|
|
|
jsmn_parser p;
|
|
|
|
jsmntok_t tokens[10];
|
|
|
|
jsmntok_t tok[10];
|
|
|
|
const char *js;
|
|
|
|
const char *js;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"boolVar\" : true";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "boolVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "true"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"boolVar\" : false";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "boolVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "false"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"intVar\" : 12345";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "intVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "12345"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"floatVar\" : 12.345";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "floatVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "12.345"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"nullVar\" : null";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "nullVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "null"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js = "\"strVar\" : \"hello world\"";
|
|
|
|
|
|
|
|
jsmn_init(&p);
|
|
|
|
|
|
|
|
r = jsmn_parse(&p, js, tok, 10);
|
|
|
|
|
|
|
|
check(r == JSMN_SUCCESS && tok[0].type == JSMN_STRING
|
|
|
|
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[0], "strVar"));
|
|
|
|
|
|
|
|
check(TOKEN_STIRNG(js, tok[1], "hello world"));
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int main() {
|
|
|
|
test(test_simple, "general test for a simple JSON string");
|
|
|
|
test(test_simple, "general test for a simple JSON string");
|
|
|
|
test(test_primitive, "test primitive JSON data types");
|
|
|
|
test(test_primitive, "test primitive JSON data types");
|
|
|
|
|
|
|
|
printf("\nPASSED: %d\nFAILED: %d\n", test_passed, test_failed);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|