You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_parse.c 35 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. #ifdef NDEBUG
  2. #undef NDEBUG
  3. #endif
  4. #include <assert.h>
  5. #include <stddef.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "json.h"
  10. #include "json_tokener.h"
  11. #include "json_visit.h"
  12. static void test_basic_parse(void);
  13. static void test_utf8_parse(void);
  14. static void test_verbose_parse(void);
  15. static void test_incremental_parse(void);
  16. int main(void)
  17. {
  18. MC_SET_DEBUG(1);
  19. static const char separator[] = "==================================";
  20. test_basic_parse();
  21. puts(separator);
  22. test_utf8_parse();
  23. puts(separator);
  24. test_verbose_parse();
  25. puts(separator);
  26. test_incremental_parse();
  27. puts(separator);
  28. return 0;
  29. }
  30. static json_c_visit_userfunc clear_serializer;
  31. static void do_clear_serializer(json_object *jso);
  32. static void single_incremental_parse(const char *test_string, int clear_serializer)
  33. {
  34. size_t ii;
  35. int chunksize = atoi(getenv("TEST_PARSE_CHUNKSIZE"));
  36. struct json_tokener *tok;
  37. enum json_tokener_error jerr;
  38. json_object *all_at_once_obj, *new_obj;
  39. const char *all_at_once_str, *new_str;
  40. new_obj = NULL;
  41. assert(chunksize > 0);
  42. all_at_once_obj = json_tokener_parse(test_string);
  43. if (clear_serializer)
  44. do_clear_serializer(all_at_once_obj);
  45. all_at_once_str = json_object_to_json_string(all_at_once_obj);
  46. tok = json_tokener_new();
  47. size_t test_string_len = strlen(test_string) + 1; // Including '\0' !
  48. for (ii = 0; ii < test_string_len; ii += chunksize)
  49. {
  50. int len_to_parse = chunksize;
  51. if (ii + chunksize > test_string_len)
  52. len_to_parse = test_string_len - ii;
  53. if (getenv("TEST_PARSE_DEBUG") != NULL)
  54. printf(" chunk: %.*s\n", len_to_parse, &test_string[ii]);
  55. new_obj = json_tokener_parse_ex(tok, &test_string[ii], len_to_parse);
  56. jerr = json_tokener_get_error(tok);
  57. if (jerr != json_tokener_continue || new_obj)
  58. break;
  59. }
  60. if (clear_serializer && new_obj)
  61. do_clear_serializer(new_obj);
  62. new_str = json_object_to_json_string(new_obj);
  63. if (strcmp(all_at_once_str, new_str) != 0)
  64. {
  65. printf("ERROR: failed to parse (%s) in %d byte chunks: %s != %s\n", test_string,
  66. chunksize, all_at_once_str, new_str);
  67. }
  68. json_tokener_free(tok);
  69. if (all_at_once_obj)
  70. json_object_put(all_at_once_obj);
  71. if (new_obj)
  72. json_object_put(new_obj);
  73. }
  74. static void single_basic_parse(const char *test_string, int clear_serializer)
  75. {
  76. json_object *new_obj;
  77. new_obj = json_tokener_parse(test_string);
  78. if (clear_serializer)
  79. do_clear_serializer(new_obj);
  80. printf("new_obj.to_string(%s)=%s\n", test_string, json_object_to_json_string(new_obj));
  81. json_object_put(new_obj);
  82. if (getenv("TEST_PARSE_CHUNKSIZE") != NULL)
  83. single_incremental_parse(test_string, clear_serializer);
  84. }
  85. static void test_basic_parse(void)
  86. {
  87. single_basic_parse("\"\003\"", 0);
  88. single_basic_parse("/* hello */\"foo\"", 0);
  89. single_basic_parse("// hello\n\"foo\"", 0);
  90. single_basic_parse("\"foo\"blue", 0);
  91. single_basic_parse("\'foo\'", 0);
  92. single_basic_parse("\"\\u0041\\u0042\\u0043\"", 0);
  93. single_basic_parse("\"\\u4e16\\u754c\\u00df\"", 0);
  94. single_basic_parse("\"\\u4E16\"", 0);
  95. single_basic_parse("\"\\u4e1\"", 0);
  96. single_basic_parse("\"\\u4e1@\"", 0);
  97. single_basic_parse("\"\\ud840\\u4e16\"", 0);
  98. single_basic_parse("\"\\ud840\"", 0);
  99. single_basic_parse("\"\\udd27\"", 0);
  100. // Test with a "short" high surrogate
  101. single_basic_parse("[9,'\\uDAD", 0);
  102. single_basic_parse("\"[9,'\\uDAD\"", 0);
  103. // Test with a supplemental character that looks like a high surrogate
  104. single_basic_parse("\"\\uD836\\uDE87\"", 0);
  105. single_basic_parse("null", 0);
  106. single_basic_parse("NaN", 0);
  107. single_basic_parse("-NaN", 0); /* non-sensical, returns null */
  108. single_basic_parse("Inf", 0); /* must use full string, returns null */
  109. single_basic_parse("inf", 0); /* must use full string, returns null */
  110. single_basic_parse("Infinity", 0);
  111. single_basic_parse("infinity", 0);
  112. single_basic_parse("-Infinity", 0);
  113. single_basic_parse("-infinity", 0);
  114. single_basic_parse("{ \"min\": Infinity, \"max\": -Infinity}", 0);
  115. single_basic_parse("Infinity!", 0);
  116. single_basic_parse("Infinitynull", 0);
  117. single_basic_parse("InfinityXXXX", 0);
  118. single_basic_parse("-Infinitynull", 0);
  119. single_basic_parse("-InfinityXXXX", 0);
  120. single_basic_parse("Infinoodle", 0);
  121. single_basic_parse("InfinAAA", 0);
  122. single_basic_parse("-Infinoodle", 0);
  123. single_basic_parse("-InfinAAA", 0);
  124. single_basic_parse("True", 0);
  125. single_basic_parse("False", 0);
  126. /* not case sensitive */
  127. single_basic_parse("tRue", 0);
  128. single_basic_parse("fAlse", 0);
  129. single_basic_parse("nAn", 0);
  130. single_basic_parse("iNfinity", 0);
  131. single_basic_parse("12", 0);
  132. single_basic_parse("12.3", 0);
  133. /* Even though, when using json_tokener_parse() there's no way to
  134. * know when there is more data after the parsed object,
  135. * an object is successfully returned anyway (in some cases)
  136. */
  137. single_basic_parse("12.3.4", 0);
  138. single_basic_parse("2015-01-15", 0);
  139. single_basic_parse("12.3xxx", 0);
  140. single_basic_parse("12.3{\"a\":123}", 0);
  141. single_basic_parse("12.3\n", 0);
  142. single_basic_parse("12.3 ", 0);
  143. single_basic_parse("{\"FoO\" : -12.3E512}", 0);
  144. single_basic_parse("{\"FoO\" : -12.3e512}", 0);
  145. single_basic_parse("{\"FoO\" : -12.3E51.2}", 0); /* non-sensical, returns null */
  146. single_basic_parse("{\"FoO\" : -12.3E512E12}", 0); /* non-sensical, returns null */
  147. single_basic_parse("[\"\\n\"]", 0);
  148. single_basic_parse("[\"\\nabc\\n\"]", 0);
  149. single_basic_parse("[null]", 0);
  150. single_basic_parse("[]", 0);
  151. single_basic_parse("[false]", 0);
  152. single_basic_parse("[\"abc\",null,\"def\",12]", 0);
  153. single_basic_parse("{}", 0);
  154. single_basic_parse("{ \"foo\": \"bar\" }", 0);
  155. single_basic_parse("{ \'foo\': \'bar\' }", 0);
  156. single_basic_parse("{ \"foo\": \"bar\", \"baz\": null, \"bool0\": true }", 0);
  157. single_basic_parse("{ \"foo\": [null, \"foo\"] }", 0);
  158. single_basic_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, "
  159. "\"arr\": [ 1, 2, 3, null, 5 ] }",
  160. 0);
  161. single_basic_parse("{ \"abc\": \"blue\nred\\ngreen\" }", 0);
  162. // Clear serializer for these tests so we see the actual parsed value.
  163. single_basic_parse("null", 1);
  164. single_basic_parse("false", 1);
  165. single_basic_parse("[0e]", 1);
  166. single_basic_parse("[0e+]", 1);
  167. single_basic_parse("[0e+-1]", 1);
  168. single_basic_parse("\"hello world!\"", 1);
  169. // uint64/int64 range test
  170. single_basic_parse("[9223372036854775806]", 1);
  171. single_basic_parse("[9223372036854775807]", 1);
  172. single_basic_parse("[9223372036854775808]", 1);
  173. single_basic_parse("[-9223372036854775807]", 1);
  174. single_basic_parse("[-9223372036854775808]", 1);
  175. single_basic_parse("[-9223372036854775809]", 1);
  176. single_basic_parse("[18446744073709551614]", 1);
  177. single_basic_parse("[18446744073709551615]", 1);
  178. single_basic_parse("[18446744073709551616]", 1);
  179. }
  180. static void test_utf8_parse(void)
  181. {
  182. // json_tokener_parse doesn't support checking for byte order marks.
  183. // It's the responsibility of the caller to detect and skip a BOM.
  184. // Both of these checks return null.
  185. const char *utf8_bom = "\xEF\xBB\xBF";
  186. const char *utf8_bom_and_chars = "\xEF\xBB\xBF{}";
  187. single_basic_parse(utf8_bom, 0);
  188. single_basic_parse(utf8_bom_and_chars, 0);
  189. }
  190. // Clear the re-serialization information that the tokener
  191. // saves to ensure that the output reflects the actual
  192. // values we parsed, rather than just the original input.
  193. static void do_clear_serializer(json_object *jso)
  194. {
  195. json_c_visit(jso, 0, clear_serializer, NULL);
  196. }
  197. static int clear_serializer(json_object *jso, int flags, json_object *parent_jso,
  198. const char *jso_key, size_t *jso_index, void *userarg)
  199. {
  200. if (jso)
  201. json_object_set_serializer(jso, NULL, NULL, NULL);
  202. return JSON_C_VISIT_RETURN_CONTINUE;
  203. }
  204. static void test_verbose_parse(void)
  205. {
  206. json_object *new_obj;
  207. enum json_tokener_error error = json_tokener_success;
  208. new_obj = json_tokener_parse_verbose("{ foo }", &error);
  209. assert(error == json_tokener_error_parse_object_key_name);
  210. assert(new_obj == NULL);
  211. new_obj = json_tokener_parse("{ foo }");
  212. assert(new_obj == NULL);
  213. new_obj = json_tokener_parse("foo");
  214. assert(new_obj == NULL);
  215. new_obj = json_tokener_parse_verbose("foo", &error);
  216. assert(new_obj == NULL);
  217. /* b/c the string starts with 'f' parsing return a boolean error */
  218. assert(error == json_tokener_error_parse_boolean);
  219. puts("json_tokener_parse_verbose() OK");
  220. }
  221. struct incremental_step
  222. {
  223. const char *string_to_parse;
  224. int length;
  225. int char_offset;
  226. enum json_tokener_error expected_error;
  227. int reset_tokener; /* Set to 1 to call json_tokener_reset() after parsing */
  228. int tok_flags; /* JSON_TOKENER_* flags to pass to json_tokener_set_flags() */
  229. } incremental_steps[] = {
  230. /* Check that full json messages can be parsed, both w/ and w/o a reset */
  231. {"{ \"foo\": 123 }", -1, -1, json_tokener_success, 0, 0},
  232. {"{ \"foo\": 456 }", -1, -1, json_tokener_success, 1, 0},
  233. {"{ \"foo\": 789 }", -1, -1, json_tokener_success, 1, 0},
  234. /* Check the comment parse*/
  235. {"/* hello */{ \"foo\"", -1, -1, json_tokener_continue, 0, 0},
  236. {"/* hello */:/* hello */", -1, -1, json_tokener_continue, 0, 0},
  237. {"\"bar\"/* hello */", -1, -1, json_tokener_continue, 0, 0},
  238. {"}/* hello */", -1, -1, json_tokener_success, 1, 0},
  239. {"/ hello ", -1, 1, json_tokener_error_parse_comment, 1, 0},
  240. {"/* hello\"foo\"", -1, -1, json_tokener_continue, 1, 0},
  241. {"/* hello*\"foo\"", -1, -1, json_tokener_continue, 1, 0},
  242. {"// hello\"foo\"", -1, -1, json_tokener_continue, 1, 0},
  243. /* Check a basic incremental parse */
  244. {"{ \"foo", -1, -1, json_tokener_continue, 0, 0},
  245. {"\": {\"bar", -1, -1, json_tokener_continue, 0, 0},
  246. {"\":13}}", -1, -1, json_tokener_success, 1, 0},
  247. /* Check the UTF-16 surrogate pair handling in various ways.
  248. * Note: \ud843\udd1e is u+1D11E, Musical Symbol G Clef
  249. * Your terminal may not display these correctly, in particular
  250. * PuTTY doesn't currently show this character.
  251. */
  252. /* parse one char at every time */
  253. {"\"\\", -1, -1, json_tokener_continue, 0, 0},
  254. {"u", -1, -1, json_tokener_continue, 0, 0},
  255. {"d", -1, -1, json_tokener_continue, 0, 0},
  256. {"8", -1, -1, json_tokener_continue, 0, 0},
  257. {"3", -1, -1, json_tokener_continue, 0, 0},
  258. {"4", -1, -1, json_tokener_continue, 0, 0},
  259. {"\\", -1, -1, json_tokener_continue, 0, 0},
  260. {"u", -1, -1, json_tokener_continue, 0, 0},
  261. {"d", -1, -1, json_tokener_continue, 0, 0},
  262. {"d", -1, -1, json_tokener_continue, 0, 0},
  263. {"1", -1, -1, json_tokener_continue, 0, 0},
  264. {"e\"", -1, -1, json_tokener_success, 1, 0},
  265. /* parse two char at every time */
  266. {"\"\\u", -1, -1, json_tokener_continue, 0, 0},
  267. {"d8", -1, -1, json_tokener_continue, 0, 0},
  268. {"34", -1, -1, json_tokener_continue, 0, 0},
  269. {"\\u", -1, -1, json_tokener_continue, 0, 0},
  270. {"dd", -1, -1, json_tokener_continue, 0, 0},
  271. {"1e\"", -1, -1, json_tokener_success, 1, 0},
  272. /* check the low surrogate pair */
  273. {"\"\\ud834", -1, -1, json_tokener_continue, 0, 0},
  274. {"\\udd1e\"", -1, -1, json_tokener_success, 1, 0},
  275. {"\"\\ud834\\", -1, -1, json_tokener_continue, 0, 0},
  276. {"udd1e\"", -1, -1, json_tokener_success, 1, 0},
  277. {"\"\\ud834\\u", -1, -1, json_tokener_continue, 0, 0},
  278. {"dd1e\"", -1, -1, json_tokener_success, 1, 0},
  279. {"\"fff \\ud834\\ud", -1, -1, json_tokener_continue, 0, 0},
  280. {"d1e bar\"", -1, -1, json_tokener_success, 1, 0},
  281. {"\"fff \\ud834\\udd", -1, -1, json_tokener_continue, 0, 0},
  282. {"1e bar\"", -1, -1, json_tokener_success, 1, 0},
  283. /* \ud83d\ude00 is U+1F600, Grinning Face
  284. * Displays fine in PuTTY, though you may need "less -r"
  285. */
  286. {"\"fff \\ud83d\\ude", -1, -1, json_tokener_continue, 0, 0},
  287. {"00 bar\"", -1, -1, json_tokener_success, 1, 0},
  288. /* Check a utf-8 char (a+umlaut) that has bytes that look negative when
  289. char are signed (see also control char check below) */
  290. {"\"\xc3\xa4\"", -1, -1, json_tokener_success, 1, 0},
  291. {"\"\xc3\xa4\"", -1, -1, json_tokener_success, 1, JSON_TOKENER_STRICT},
  292. /* Check that json_tokener_reset actually resets */
  293. {"{ \"foo", -1, -1, json_tokener_continue, 1, 0},
  294. {": \"bar\"}", -1, 0, json_tokener_error_parse_unexpected, 1, 0},
  295. /* Check a supplemental code point that looks like a high surrogate */
  296. {"\"\\uD836", -1, -1, json_tokener_continue, 0, 0},
  297. {"\\uDE87", -1, -1, json_tokener_continue, 0, 0},
  298. {"\"", -1, -1, json_tokener_success, 1, 0},
  299. /* Check incremental parsing with trailing characters */
  300. {"{ \"foo", -1, -1, json_tokener_continue, 0, 0},
  301. {"\": {\"bar", -1, -1, json_tokener_continue, 0, 0},
  302. {"\":13}}XXXX", 10, 6, json_tokener_success, 0, 0},
  303. {"XXXX", 4, 0, json_tokener_error_parse_unexpected, 1, 0},
  304. /* Check that trailing characters can change w/o a reset */
  305. {"{\"x\": 123 }\"X\"", -1, 11, json_tokener_success, 0, 0},
  306. {"\"Y\"", -1, -1, json_tokener_success, 1, 0},
  307. /* Trailing characters should cause a failure in strict mode */
  308. {"{\"foo\":9}{\"bar\":8}", -1, 9, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  309. /* ... unless explicitly allowed. */
  310. {"{\"foo\":9}{\"bar\":8}", -1, 9, json_tokener_success, 0,
  311. JSON_TOKENER_STRICT | JSON_TOKENER_ALLOW_TRAILING_CHARS},
  312. {"{\"b\":8}ignored garbage", -1, 7, json_tokener_success, 1,
  313. JSON_TOKENER_STRICT | JSON_TOKENER_ALLOW_TRAILING_CHARS},
  314. /* To stop parsing a number we need to reach a non-digit, e.g. a \0 */
  315. {"1", 1, 1, json_tokener_continue, 0, 0},
  316. /* This should parse as the number 12, since it continues the "1" */
  317. {"2", 2, 1, json_tokener_success, 0, 0},
  318. {"12{", 3, 2, json_tokener_success, 1, 0},
  319. /* Parse number in strict mode */
  320. {"[02]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  321. {"0e+0", 5, 4, json_tokener_success, 1, 0},
  322. {"[0e+0]", -1, -1, json_tokener_success, 1, 0},
  323. /* The behavior when missing the exponent varies slightly */
  324. {"0e", 2, 2, json_tokener_continue, 1, 0},
  325. {"0e", 3, 2, json_tokener_success, 1, 0},
  326. {"0e", 3, 2, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
  327. {"[0e]", -1, -1, json_tokener_success, 1, 0},
  328. {"[0e]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  329. {"0e+", 3, 3, json_tokener_continue, 1, 0},
  330. {"0e+", 4, 3, json_tokener_success, 1, 0},
  331. {"0e+", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
  332. {"[0e+]", -1, -1, json_tokener_success, 1, 0},
  333. {"[0e+]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  334. {"0e-", 3, 3, json_tokener_continue, 1, 0},
  335. {"0e-", 4, 3, json_tokener_success, 1, 0},
  336. {"0e-", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
  337. {"[0e-]", -1, -1, json_tokener_success, 1, 0},
  338. {"[0e-]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  339. /* You might expect this to fail, but it won't because
  340. it's a valid partial parse; note the char_offset: */
  341. {"0e+-", 5, 3, json_tokener_success, 1, 0},
  342. {"0e+-", 5, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  343. {"[0e+-]", -1, 4, json_tokener_error_parse_number, 1, 0},
  344. /* Similar tests for other kinds of objects: */
  345. /* These could all return success immediately, since regardless of
  346. what follows the false/true/null token we *will* return a json object,
  347. but it currently doesn't work that way. hmm... */
  348. {"false", 5, 5, json_tokener_continue, 1, 0},
  349. {"false", 6, 5, json_tokener_success, 1, 0},
  350. {"true", 4, 4, json_tokener_continue, 1, 0},
  351. {"true", 5, 4, json_tokener_success, 1, 0},
  352. {"null", 4, 4, json_tokener_continue, 1, 0},
  353. {"null", 5, 4, json_tokener_success, 1, 0},
  354. {"Infinity", 9, 8, json_tokener_success, 1, 0},
  355. {"infinity", 9, 8, json_tokener_success, 1, 0},
  356. {"infinity", 9, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  357. {"-infinity", 10, 9, json_tokener_success, 1, 0},
  358. {"-infinity", 10, 1, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  359. {"inf", 3, 3, json_tokener_continue, 0, 0},
  360. {"inity", 6, 5, json_tokener_success, 1, 0},
  361. {"-inf", 4, 4, json_tokener_continue, 0, 0},
  362. {"inity", 6, 5, json_tokener_success, 1, 0},
  363. {"i", 1, 1, json_tokener_continue, 0, 0},
  364. {"n", 1, 1, json_tokener_continue, 0, 0},
  365. {"f", 1, 1, json_tokener_continue, 0, 0},
  366. {"i", 1, 1, json_tokener_continue, 0, 0},
  367. {"n", 1, 1, json_tokener_continue, 0, 0},
  368. {"i", 1, 1, json_tokener_continue, 0, 0},
  369. {"t", 1, 1, json_tokener_continue, 0, 0},
  370. {"y", 1, 1, json_tokener_continue, 0, 0},
  371. {"", 1, 0, json_tokener_success, 1, 0},
  372. {"-", 1, 1, json_tokener_continue, 0, 0},
  373. {"inf", 3, 3, json_tokener_continue, 0, 0},
  374. {"ini", 3, 3, json_tokener_continue, 0, 0},
  375. {"ty", 3, 2, json_tokener_success, 1, 0},
  376. {"-", 1, 1, json_tokener_continue, 0, 0},
  377. {"i", 1, 1, json_tokener_continue, 0, 0},
  378. {"nfini", 5, 5, json_tokener_continue, 0, 0},
  379. {"ty", 3, 2, json_tokener_success, 1, 0},
  380. {"-i", 2, 2, json_tokener_continue, 0, 0},
  381. {"nfinity", 8, 7, json_tokener_success, 1, 0},
  382. {"InfinityX", 10, 8, json_tokener_success, 0, 0},
  383. {"X", 1, 0, json_tokener_error_parse_unexpected, 1, 0},
  384. {"Infinity1234", 13, 8, json_tokener_success, 0, 0},
  385. {"1234", 5, 4, json_tokener_success, 1, 0},
  386. {"Infinity9999", 8, 8, json_tokener_continue, 0, 0},
  387. /* returns the Infinity loaded up by the previous call: */
  388. {"1234", 5, 0, json_tokener_success, 0, 0},
  389. {"1234", 5, 4, json_tokener_success, 1, 0},
  390. /* INT64_MAX */
  391. {"[9223372036854775807]", 22, 21, json_tokener_success, 1, 0},
  392. /* INT64_MAX+1 => parsed as uint64 */
  393. {"[9223372036854775808]", 22, 21, json_tokener_success, 1, 0},
  394. /* INT64_MIN */
  395. {"[-9223372036854775808]", 23, 22, json_tokener_success, 1, 0},
  396. /* INT64_MIN-1 => success, but value ends up capped */
  397. {"[-9223372036854775809]", 23, 22, json_tokener_success, 1, 0},
  398. /* INT64_MIN-1 => failure due to underflow detected */
  399. {"[-9223372036854775809]", 23, 21, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  400. /* UINT64_MAX */
  401. {"[18446744073709551615]", 23, 22, json_tokener_success, 1, 0},
  402. /* UINT64_MAX+1 => success, but value ends up capped */
  403. {"[18446744073709551616]", 23, 22, json_tokener_success, 1, 0},
  404. /* UINT64_MAX+1 => failure due to overflow detected */
  405. {"[18446744073709551616]", 23, 21, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
  406. /* XXX this seems like a bug, should fail with _error_parse_number instead */
  407. {"18446744073709551616", 21, 20, json_tokener_success, 1, 0},
  408. {"18446744073709551616", 21, 20, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
  409. /* Exceeding integer limits as double parse OK */
  410. {"[9223372036854775808.0]", 24, 23, json_tokener_success, 1, 0},
  411. {"[-9223372036854775809.0]", 25, 24, json_tokener_success, 1, 0},
  412. {"[-9223372036854775809.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT},
  413. {"[18446744073709551615.0]", 25, 24, json_tokener_success, 1, 0},
  414. {"[18446744073709551616.0]", 25, 24, json_tokener_success, 1, 0},
  415. {"[18446744073709551616.0]", 25, 24, json_tokener_success, 1, JSON_TOKENER_STRICT},
  416. /* offset=1 because "n" is the start of "null". hmm... */
  417. {"noodle", 7, 1, json_tokener_error_parse_null, 1, 0},
  418. /* offset=2 because "na" is the start of "nan". hmm... */
  419. {"naodle", 7, 2, json_tokener_error_parse_null, 1, 0},
  420. /* offset=2 because "tr" is the start of "true". hmm... */
  421. {"track", 6, 2, json_tokener_error_parse_boolean, 1, 0},
  422. {"fail", 5, 2, json_tokener_error_parse_boolean, 1, 0},
  423. /* Although they may initially look like they should fail,
  424. * the next few tests check that parsing multiple sequential
  425. * json objects in the input works as expected
  426. */
  427. {"null123", 8, 4, json_tokener_success, 0, 0},
  428. {&"null123"[4], 4, 3, json_tokener_success, 1, 0},
  429. {"nullx", 6, 4, json_tokener_success, 0, 0},
  430. {&"nullx"[4], 2, 0, json_tokener_error_parse_unexpected, 1, 0},
  431. {"{\"a\":1}{\"b\":2}", 15, 7, json_tokener_success, 0, 0},
  432. {&"{\"a\":1}{\"b\":2}"[7], 8, 7, json_tokener_success, 1, 0},
  433. /*
  434. * Though this may seem invalid at first glance, it
  435. * parses as three separate numbers, 2015, -1 and -15
  436. * Of course, simply pasting together a stream of arbitrary
  437. * positive numbers won't work, since there'll be no way to
  438. * tell where in e.g. "2015015" the next number stats, so
  439. * a reliably parsable stream must not include json_type_int
  440. * or json_type_double objects without some other delimiter.
  441. * e.g. whitespace
  442. */
  443. {&"2015-01-15"[0], 11, 4, json_tokener_success, 1, 0},
  444. {&"2015-01-15"[4], 7, 3, json_tokener_success, 1, 0},
  445. {&"2015-01-15"[7], 4, 3, json_tokener_success, 1, 0},
  446. {&"2015 01 15"[0], 11, 5, json_tokener_success, 1, 0},
  447. {&"2015 01 15"[4], 7, 4, json_tokener_success, 1, 0},
  448. {&"2015 01 15"[7], 4, 3, json_tokener_success, 1, 0},
  449. /* Strings have a well defined end point, so we can stop at the quote */
  450. {"\"blue\"", -1, -1, json_tokener_success, 0, 0},
  451. /* Check each of the escape sequences defined by the spec */
  452. {"\"\\\"\"", -1, -1, json_tokener_success, 0, 0},
  453. {"\"\\\\\"", -1, -1, json_tokener_success, 0, 0},
  454. {"\"\\b\"", -1, -1, json_tokener_success, 0, 0},
  455. {"\"\\f\"", -1, -1, json_tokener_success, 0, 0},
  456. {"\"\\n\"", -1, -1, json_tokener_success, 0, 0},
  457. {"\"\\r\"", -1, -1, json_tokener_success, 0, 0},
  458. {"\"\\t\"", -1, -1, json_tokener_success, 0, 0},
  459. {"\"\\/\"", -1, -1, json_tokener_success, 0, 0},
  460. // Escaping a forward slash is optional
  461. {"\"/\"", -1, -1, json_tokener_success, 0, 0},
  462. /* Check wrong escape sequences */
  463. {"\"\\a\"", -1, 2, json_tokener_error_parse_string, 1, 0},
  464. /* Check '\'' in strict model */
  465. {"\'foo\'", -1, 5, json_tokener_success, 1, 0},
  466. {"\'foo\'", -1, 0, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  467. /* Parse array/object */
  468. {"[1,2,3]", -1, -1, json_tokener_success, 0, 0},
  469. {"[1,2,3}", -1, 6, json_tokener_error_parse_array, 1, 0},
  470. {"{\"a\"}", -1, 4, json_tokener_error_parse_object_key_sep, 1, 0},
  471. {"{\"a\":1]", -1, 6, json_tokener_error_parse_object_value_sep, 1, 0},
  472. {"{\"a\"::1}", -1, 5, json_tokener_error_parse_unexpected, 1, 0},
  473. {"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1, 0},
  474. {"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1, 0},
  475. {"\"a\":1}", -1, 3, json_tokener_success, 1, 0},
  476. {"{\"a\":1", -1, -1, json_tokener_continue, 1, 0}, //}
  477. {"[,]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
  478. {"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
  479. /* This behaviour doesn't entirely follow the json spec, but until we have
  480. * a way to specify how strict to be we follow Postel's Law and be liberal
  481. * in what we accept (up to a point).
  482. */
  483. {"[1,2,3,]", -1, -1, json_tokener_success, 0, 0},
  484. {"[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  485. {"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0, 0},
  486. {"[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0, JSON_TOKENER_STRICT},
  487. {"{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 1, JSON_TOKENER_STRICT},
  488. // utf-8 test
  489. // acsll encoding
  490. {"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 1,
  491. JSON_TOKENER_VALIDATE_UTF8},
  492. {"\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22", -1, -1, json_tokener_success, 1, 0},
  493. // utf-8 encoding
  494. {"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 1,
  495. JSON_TOKENER_VALIDATE_UTF8},
  496. {"\x22\xe4\xb8", -1, 3, json_tokener_error_parse_utf8_string, 0, JSON_TOKENER_VALIDATE_UTF8},
  497. {"\x96\xe7\x95\x8c\x22", -1, 0, json_tokener_error_parse_utf8_string, 1,
  498. JSON_TOKENER_VALIDATE_UTF8},
  499. {"\x22\xe4\xb8\x96\xe7\x95\x8c\x22", -1, -1, json_tokener_success, 1, 0},
  500. {"\x22\xcf\x80\xcf\x86\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8},
  501. {"\x22\xf0\xa5\x91\x95\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8},
  502. // wrong utf-8 encoding
  503. {"\x22\xe6\x9d\x4e\x22", -1, 3, json_tokener_error_parse_utf8_string, 1,
  504. JSON_TOKENER_VALIDATE_UTF8},
  505. {"\x22\xe6\x9d\x4e\x22", -1, 5, json_tokener_success, 1, 0},
  506. // GBK encoding
  507. {"\x22\xc0\xee\xc5\xf4\x22", -1, 2, json_tokener_error_parse_utf8_string, 1,
  508. JSON_TOKENER_VALIDATE_UTF8},
  509. {"\x22\xc0\xee\xc5\xf4\x22", -1, 6, json_tokener_success, 1, 0},
  510. // char after space
  511. {"\x20\x20\x22\xe4\xb8\x96\x22", -1, -1, json_tokener_success, 1, JSON_TOKENER_VALIDATE_UTF8},
  512. {"\x20\x20\x81\x22\xe4\xb8\x96\x22", -1, 2, json_tokener_error_parse_utf8_string, 1,
  513. JSON_TOKENER_VALIDATE_UTF8},
  514. {"\x5b\x20\x81\x31\x5d", -1, 2, json_tokener_error_parse_utf8_string, 1,
  515. JSON_TOKENER_VALIDATE_UTF8},
  516. // char in state inf
  517. {"\x49\x6e\x66\x69\x6e\x69\x74\x79", 9, 8, json_tokener_success, 1, 0},
  518. {"\x49\x6e\x66\x81\x6e\x69\x74\x79", -1, 3, json_tokener_error_parse_utf8_string, 1,
  519. JSON_TOKENER_VALIDATE_UTF8},
  520. // char in escape unicode
  521. {"\x22\x5c\x75\x64\x38\x35\x35\x5c\x75\x64\x63\x35\x35\x22", 15, 14, json_tokener_success, 1,
  522. JSON_TOKENER_VALIDATE_UTF8},
  523. {"\x22\x5c\x75\x64\x38\x35\x35\xc0\x75\x64\x63\x35\x35\x22", -1, 8,
  524. json_tokener_error_parse_utf8_string, 1, JSON_TOKENER_VALIDATE_UTF8},
  525. {"\x22\x5c\x75\x64\x30\x30\x33\x31\xc0\x22", -1, 9, json_tokener_error_parse_utf8_string, 1,
  526. JSON_TOKENER_VALIDATE_UTF8},
  527. // char in number
  528. {"\x31\x31\x81\x31\x31", -1, 2, json_tokener_error_parse_utf8_string, 1,
  529. JSON_TOKENER_VALIDATE_UTF8},
  530. // char in object
  531. {"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 1,
  532. JSON_TOKENER_VALIDATE_UTF8},
  533. // Note, current asciiz APIs can't parse \x00, skip it
  534. { "\"0\x01\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
  535. "\x10\x11\x12\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"",
  536. -1, -1, json_tokener_success, 1, 0 },
  537. { "{\"0\x01\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
  538. "\x10\x11\x12\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\":1}",
  539. -1, -1, json_tokener_success, 1, 0 },
  540. // Test control chars again, this time in strict mode, which should fail
  541. { "\"\x01\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  542. { "\"\x02\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  543. { "\"\x03\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  544. { "\"\x04\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  545. { "\"\x05\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  546. { "\"\x06\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  547. { "\"\x07\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  548. { "\"\x08\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  549. { "\"\x09\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  550. { "\"\x0a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  551. { "\"\x0b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  552. { "\"\x0c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  553. { "\"\x0d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  554. { "\"\x0e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  555. { "\"\x0f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  556. { "\"\x10\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  557. { "\"\x11\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  558. { "\"\x12\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  559. { "\"\x13\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  560. { "\"\x14\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  561. { "\"\x15\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  562. { "\"\x16\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  563. { "\"\x17\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  564. { "\"\x18\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  565. { "\"\x19\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  566. { "\"\x1a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  567. { "\"\x1b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  568. { "\"\x1c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  569. { "\"\x1d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  570. { "\"\x1e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  571. { "\"\x1f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  572. { "{\"\x01\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  573. { "{\"\x02\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  574. { "{\"\x03\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  575. { "{\"\x04\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  576. { "{\"\x05\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  577. { "{\"\x06\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  578. { "{\"\x07\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  579. { "{\"\x08\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  580. { "{\"\x09\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  581. { "{\"\x0a\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  582. { "{\"\x0b\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  583. { "{\"\x0c\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  584. { "{\"\x0d\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  585. { "{\"\x0e\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  586. { "{\"\x0f\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  587. { "{\"\x10\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  588. { "{\"\x11\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  589. { "{\"\x12\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  590. { "{\"\x13\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  591. { "{\"\x14\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  592. { "{\"\x15\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  593. { "{\"\x16\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  594. { "{\"\x17\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  595. { "{\"\x18\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  596. { "{\"\x19\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  597. { "{\"\x1a\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  598. { "{\"\x1b\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  599. { "{\"\x1c\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  600. { "{\"\x1d\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  601. { "{\"\x1e\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  602. { "{\"\x1f\":1}", -1, 2, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
  603. {NULL, -1, -1, json_tokener_success, 0, 0},
  604. };
  605. static void test_incremental_parse(void)
  606. {
  607. json_object *new_obj;
  608. enum json_tokener_error jerr;
  609. struct json_tokener *tok;
  610. const char *string_to_parse;
  611. int ii;
  612. int num_ok, num_error;
  613. num_ok = 0;
  614. num_error = 0;
  615. printf("Starting incremental tests.\n");
  616. printf("Note: quotes and backslashes seen in the output here are literal values passed\n");
  617. printf(" to the parse functions. e.g. this is 4 characters: \"\\f\"\n");
  618. string_to_parse = "{ \"foo"; /* } */
  619. printf("json_tokener_parse(%s) ... ", string_to_parse);
  620. new_obj = json_tokener_parse(string_to_parse);
  621. if (new_obj == NULL)
  622. printf("%s", "got error as expected\n");
  623. /* test incremental parsing in various forms */
  624. tok = json_tokener_new();
  625. for (ii = 0; incremental_steps[ii].string_to_parse != NULL; ii++)
  626. {
  627. int this_step_ok = 0;
  628. struct incremental_step *step = &incremental_steps[ii];
  629. int length = step->length;
  630. size_t expected_char_offset;
  631. json_tokener_set_flags(tok, step->tok_flags);
  632. if (length == -1)
  633. length = (int)strlen(step->string_to_parse);
  634. if (step->char_offset == -1)
  635. expected_char_offset = length;
  636. else
  637. expected_char_offset = step->char_offset;
  638. printf("json_tokener_parse_ex(tok, %-12s, %3d) ... ", step->string_to_parse,
  639. length);
  640. new_obj = json_tokener_parse_ex(tok, step->string_to_parse, length);
  641. jerr = json_tokener_get_error(tok);
  642. if (step->expected_error != json_tokener_success)
  643. {
  644. if (new_obj != NULL)
  645. printf("ERROR: invalid object returned: %s\n",
  646. json_object_to_json_string(new_obj));
  647. else if (jerr != step->expected_error)
  648. printf("ERROR: got wrong error: %s\n",
  649. json_tokener_error_desc(jerr));
  650. else if (json_tokener_get_parse_end(tok) != expected_char_offset)
  651. printf("ERROR: wrong char_offset %zu != expected %zu\n",
  652. json_tokener_get_parse_end(tok), expected_char_offset);
  653. else
  654. {
  655. printf("OK: got correct error: %s\n",
  656. json_tokener_error_desc(jerr));
  657. this_step_ok = 1;
  658. }
  659. }
  660. else
  661. {
  662. if (new_obj == NULL &&
  663. !(step->length >= 4 && strncmp(step->string_to_parse, "null", 4) == 0))
  664. printf("ERROR: expected valid object, instead: %s\n",
  665. json_tokener_error_desc(jerr));
  666. else if (json_tokener_get_parse_end(tok) != expected_char_offset)
  667. printf("ERROR: wrong char_offset %zu != expected %zu\n",
  668. json_tokener_get_parse_end(tok), expected_char_offset);
  669. else
  670. {
  671. printf("OK: got object of type [%s]: %s\n",
  672. json_type_to_name(json_object_get_type(new_obj)),
  673. json_object_to_json_string(new_obj));
  674. this_step_ok = 1;
  675. }
  676. }
  677. if (new_obj)
  678. json_object_put(new_obj);
  679. if (step->reset_tokener & 1)
  680. json_tokener_reset(tok);
  681. if (this_step_ok)
  682. num_ok++;
  683. else
  684. num_error++;
  685. }
  686. json_tokener_free(tok);
  687. printf("End Incremental Tests OK=%d ERROR=%d\n", num_ok, num_error);
  688. }