Jehiah Czebotar | ac601b5 | 2011-01-14 17:23:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Tests if binary strings are supported. |
| 3 | */ |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <string.h> |
| 7 | #include "config.h" |
| 8 | |
| 9 | #include "json_inttypes.h" |
| 10 | #include "json_object.h" |
| 11 | |
| 12 | int main() { |
| 13 | // this test has a space after the null character. check that it's still included |
| 14 | const char *input = " \0 "; |
| 15 | const char *expected = "\" \\u0000 \""; |
| 16 | struct json_object *string = json_object_new_string_len(input, 3); |
| 17 | const char *json = json_object_to_json_string(string); |
| 18 | |
| 19 | int strings_match = !strcmp( expected, json); |
| 20 | int retval = 0; |
| 21 | if (strings_match) { |
| 22 | printf("JSON write result is correct: %s\n", json); |
| 23 | printf("PASS\n"); |
| 24 | } else { |
| 25 | printf("JSON write result doesn't match expected string\n"); |
| 26 | printf("expected string: "); |
| 27 | printf("%s\n", expected); |
| 28 | printf("parsed string: "); |
| 29 | printf("%s\n", json); |
| 30 | printf("FAIL\n"); |
| 31 | retval=1; |
| 32 | } |
| 33 | json_object_put(string); |
| 34 | return retval; |
| 35 | } |