blob: 73729b82fc42b676801a11405d2cac983a6f06a9 [file] [log] [blame]
Jehiah Czebotarac601b52011-01-14 17:23:06 +00001/*
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
12int 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}