You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_null.c 880 B

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