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_double_serializer.c 929 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Tests if the format string for double serialization is handled correctly
  3. */
  4. #include <stdio.h>
  5. #include "config.h"
  6. #include "json_object.h"
  7. #include "json_object_private.h"
  8. int main()
  9. {
  10. struct json_object *obj = json_object_new_double(0.5);
  11. printf("Test default serializer:\n");
  12. printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj));
  13. printf("Test default serializer with custom userdata:\n");
  14. obj->_userdata = "test";
  15. printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj));
  16. printf("Test explicit serializer with custom userdata:\n");
  17. json_object_set_serializer(obj, json_object_double_to_json_string, "test", NULL);
  18. printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj));
  19. printf("Test reset serializer:\n");
  20. json_object_set_serializer(obj, NULL, NULL, NULL);
  21. printf("obj.to_string(reset)=%s\n", json_object_to_json_string(obj));
  22. json_object_put(obj);
  23. }