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_string_noalloc.c 1.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Tests if binary strings are supported.
  3. */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <string.h>
  8. #include "config.h"
  9. #include "json_inttypes.h"
  10. #include "json_object.h"
  11. #include "json_tokener.h"
  12. int main(void)
  13. {
  14. /* this test has a space after the null character. check that it's still included */
  15. char *str = strdup("This string should be longer than 32 characters");
  16. struct json_object *jso_str = NULL;
  17. if (!str)
  18. {
  19. puts("FAIL: strdup() returned NULL");
  20. return 1;
  21. }
  22. jso_str = json_object_new_string_noalloc(str);
  23. if (!jso_str)
  24. {
  25. puts("FAIL: json_object_new_string_noalloc(str) returned NULL");
  26. free(str);
  27. return 2;
  28. }
  29. json_object_put(jso_str);
  30. jso_str = NULL;
  31. str = strdup("this string is short");
  32. if (!str)
  33. {
  34. puts("FAIL: strdup() returned NULL");
  35. return 1;
  36. }
  37. jso_str = json_object_new_string_noalloc(str);
  38. if (!jso_str)
  39. {
  40. puts("FAIL: json_object_new_string_noalloc(str) returned NULL");
  41. free(str);
  42. return 3;
  43. }
  44. json_object_put(jso_str);
  45. puts("PASS");
  46. return 0;
  47. }