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 969 B

1234567891011121314151617181920212223242526272829303132333435
  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. // this test has a space after the null character. check that it's still included
  11. const char *input = " \0 ";
  12. const char *expected = "\" \\u0000 \"";
  13. struct json_object *string = json_object_new_string_len(input, 3);
  14. const char *json = json_object_to_json_string(string);
  15. int strings_match = !strcmp( expected, json);
  16. int retval = 0;
  17. if (strings_match) {
  18. printf("JSON write result is correct: %s\n", json);
  19. printf("PASS\n");
  20. } else {
  21. printf("JSON write result doesn't match expected string\n");
  22. printf("expected string: ");
  23. printf("%s\n", expected);
  24. printf("parsed string: ");
  25. printf("%s\n", json);
  26. printf("FAIL\n");
  27. retval=1;
  28. }
  29. json_object_put(string);
  30. return retval;
  31. }