diff options
author | Michał Cichoń <michcic@gmail.com> | 2015-08-25 19:56:24 +0200 |
---|---|---|
committer | Michał Cichoń <michcic@gmail.com> | 2015-08-25 19:56:24 +0200 |
commit | 682f23e7bb4a52bedf46eff5c4859e1308eda124 (patch) | |
tree | 30ad4f37b434ecdfb5edc36dfbaf7fc924e53c0e /json-c/src/tests/test_null.c | |
parent | 8b41fc907bcd27d24c895062ae8a61b305fc2d46 (diff) | |
download | pianobar-windows-build-682f23e7bb4a52bedf46eff5c4859e1308eda124.tar.gz pianobar-windows-build-682f23e7bb4a52bedf46eff5c4859e1308eda124.tar.bz2 pianobar-windows-build-682f23e7bb4a52bedf46eff5c4859e1308eda124.zip |
Update build ref
Diffstat (limited to 'json-c/src/tests/test_null.c')
-rw-r--r-- | json-c/src/tests/test_null.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/json-c/src/tests/test_null.c b/json-c/src/tests/test_null.c new file mode 100644 index 0000000..da86fb6 --- /dev/null +++ b/json-c/src/tests/test_null.c @@ -0,0 +1,57 @@ +/*
+* Tests if binary strings are supported.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "config.h"
+
+#include "json_inttypes.h"
+#include "json_object.h"
+#include "json_tokener.h"
+
+int main()
+{
+ // this test has a space after the null character. check that it's still included
+ const char *input = " \0 ";
+ const char *expected = "\" \\u0000 \"";
+ struct json_object *string = json_object_new_string_len(input, 3);
+ const char *json = json_object_to_json_string(string);
+
+ int strings_match = !strcmp( expected, json);
+ int retval = 0;
+ if (strings_match)
+ {
+ printf("JSON write result is correct: %s\n", json);
+ printf("PASS\n");
+ } else {
+ printf("JSON write result doesn't match expected string\n");
+ printf("expected string: ");
+ printf("%s\n", expected);
+ printf("parsed string: ");
+ printf("%s\n", json);
+ printf("FAIL\n");
+ retval=1;
+ }
+ json_object_put(string);
+
+ struct json_object *parsed_str = json_tokener_parse(expected);
+ if (parsed_str)
+ {
+ int parsed_len = json_object_get_string_len(parsed_str);
+ const char *parsed_cstr = json_object_get_string(parsed_str);
+ int ii;
+ printf("Re-parsed object string len=%d, chars=[", parsed_len);
+ for (ii = 0; ii < parsed_len ; ii++)
+ {
+ printf("%s%d", (ii ? ", " : ""), (int)parsed_cstr[ii]);
+ }
+ printf("]\n");
+ json_object_put(parsed_str);
+ }
+ else
+ {
+ printf("ERROR: failed to parse\n");
+ }
+ return retval;
+}
|