QMI: add uqmi tool with all depends
[tomato.git] / release / src / router / libjson-c / tests / test_null.c
blob1f07910ee1756907b04292e909c9b800cc36772c
1 /*
2 * Tests if binary strings are supported.
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include "config.h"
9 #include "json_inttypes.h"
10 #include "json_object.h"
11 #include "json_tokener.h"
13 int main()
15 // this test has a space after the null character. check that it's still included
16 const char *input = " \0 ";
17 const char *expected = "\" \\u0000 \"";
18 struct json_object *string = json_object_new_string_len(input, 3);
19 const char *json = json_object_to_json_string(string);
21 int strings_match = !strcmp( expected, json);
22 int retval = 0;
23 if (strings_match)
25 printf("JSON write result is correct: %s\n", json);
26 printf("PASS\n");
27 } else {
28 printf("JSON write result doesn't match expected string\n");
29 printf("expected string: ");
30 printf("%s\n", expected);
31 printf("parsed string: ");
32 printf("%s\n", json);
33 printf("FAIL\n");
34 retval=1;
36 json_object_put(string);
38 struct json_object *parsed_str = json_tokener_parse(expected);
39 if (parsed_str)
41 int parsed_len = json_object_get_string_len(parsed_str);
42 const char *parsed_cstr = json_object_get_string(parsed_str);
43 int ii;
44 printf("Re-parsed object string len=%d, chars=[", parsed_len);
45 for (ii = 0; ii < parsed_len ; ii++)
47 printf("%s%d", (ii ? ", " : ""), (int)parsed_cstr[ii]);
49 printf("]\n");
50 json_object_put(parsed_str);
52 else
54 printf("ERROR: failed to parse\n");
56 return retval;