2 * Tests if binary strings are supported.
9 #include "json_inttypes.h"
10 #include "json_object.h"
11 #include "json_tokener.h"
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);
25 printf("JSON write result is correct: %s\n", json);
28 printf("JSON write result doesn't match expected string\n");
29 printf("expected string: ");
30 printf("%s\n", expected);
31 printf("parsed string: ");
36 json_object_put(string);
38 struct json_object *parsed_str = json_tokener_parse(expected);
41 int parsed_len = json_object_get_string_len(parsed_str);
42 const char *parsed_cstr = json_object_get_string(parsed_str);
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]);
50 json_object_put(parsed_str);
54 printf("ERROR: failed to parse\n");