test_utils.c 581 B

123456789101112131415161718192021222324252627282930
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "cJSON_Utils.h"
  4. int main()
  5. {
  6. const char *json="{"
  7. "\"foo\": [\"bar\", \"baz\"],"
  8. "\"\": 0,"
  9. "\"a/b\": 1,"
  10. "\"c%d\": 2,"
  11. "\"e^f\": 3,"
  12. "\"g|h\": 4,"
  13. "\"i\\\\j\": 5,"
  14. "\"k\\\"l\": 6,"
  15. "\" \": 7,"
  16. "\"m~n\": 8"
  17. "}";
  18. const char *tests[12]={"","/foo","/foo/0","/","/a~1b","/c%d","/e^f","/g|h","/i\\j","/k\"l","/ ","/m~0n"};
  19. printf("JSON Pointer Tests\n");
  20. cJSON *root=cJSON_Parse(json);
  21. for (int i=0;i<12;i++)
  22. {
  23. printf("Test %d:\n%s\n\n",i+1,cJSON_Print(cJSONUtils_GetPointer(root,tests[i])));
  24. }
  25. }