• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/json-c/tests/test_null.c

  1 /*
  2  * Tests if binary strings are supported.
  3  */
  4 
  5 #include "config.h"
  6 #include <stdio.h>
  7 #include <string.h>
  8 
  9 #include "json_inttypes.h"
 10 #include "json_object.h"
 11 #include "json_tokener.h"
 12 
 13 int main(void)
 14 {
 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);
 20 
 21         int strings_match = !strcmp(expected, json);
 22         int retval = 0;
 23         if (strings_match)
 24         {
 25                 printf("JSON write result is correct: %s\n", json);
 26                 puts("PASS");
 27         }
 28         else
 29         {
 30                 puts("JSON write result doesn't match expected string");
 31                 printf("expected string: ");
 32                 puts(expected);
 33                 printf("parsed string:   ");
 34                 puts(json);
 35                 puts("FAIL");
 36                 retval = 1;
 37         }
 38         json_object_put(string);
 39 
 40         struct json_object *parsed_str = json_tokener_parse(expected);
 41         if (parsed_str)
 42         {
 43                 int parsed_len = json_object_get_string_len(parsed_str);
 44                 const char *parsed_cstr = json_object_get_string(parsed_str);
 45                 int ii;
 46                 printf("Re-parsed object string len=%d, chars=[", parsed_len);
 47                 for (ii = 0; ii < parsed_len; ii++)
 48                 {
 49                         printf("%s%d", (ii ? ", " : ""), (int)parsed_cstr[ii]);
 50                 }
 51                 puts("]");
 52                 json_object_put(parsed_str);
 53         }
 54         else
 55         {
 56                 puts("ERROR: failed to parse");
 57         }
 58         return retval;
 59 }
 60 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt