QMI: add uqmi tool with all depends
[tomato.git] / release / src / router / libjson-c / tests / test4.c
blob23e97dac1b891648eefa418a4ad1d6dccca95933
1 /*
2 * gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
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 void print_hex( const char* s)
15 const char *iter = s;
16 unsigned char ch;
17 while ((ch = *iter++) != 0)
19 if( ',' != ch)
20 printf("%x ", ch);
21 else
22 printf( ",");
24 printf("\n");
27 int main()
29 const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
30 const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
31 struct json_object *parse_result = json_tokener_parse((char*)input);
32 const char *unjson = json_object_get_string(parse_result);
34 printf("input: %s\n", input);
36 int strings_match = !strcmp( expected, unjson);
37 int retval = 0;
38 if (strings_match)
40 printf("JSON parse result is correct: %s\n", unjson);
41 printf("PASS\n");
42 } else {
43 printf("JSON parse result doesn't match expected string\n");
44 printf("expected string bytes: ");
45 print_hex( expected);
46 printf("parsed string bytes: ");
47 print_hex( unjson);
48 printf("FAIL\n");
49 retval = 1;
51 json_object_put(parse_result);
52 return retval;