forked from json-c/json-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make default double serializer ignore userdata again
The user might want to use the userdata for something different, so the serializer should ignore it by default. Explicitly setting the serializer to json_object_double_to_json_string will still make it interpret the userdata as a format string.
- Loading branch information
Showing
6 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Tests if the format string for double serialization is handled correctly | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "config.h" | ||
|
||
#include "json_object.h" | ||
#include "json_object_private.h" | ||
|
||
int main() | ||
{ | ||
struct json_object *obj = json_object_new_double(0.5); | ||
|
||
printf("Test default serializer:\n"); | ||
printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj)); | ||
|
||
printf("Test default serializer with custom userdata:\n"); | ||
obj->_userdata = "test"; | ||
printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj)); | ||
|
||
printf("Test explicit serializer with custom userdata:\n"); | ||
json_object_set_serializer(obj, json_object_double_to_json_string, "test", NULL); | ||
printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj)); | ||
|
||
printf("Test reset serializer:\n"); | ||
json_object_set_serializer(obj, NULL, NULL, NULL); | ||
printf("obj.to_string(reset)=%s\n", json_object_to_json_string(obj)); | ||
|
||
json_object_put(obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Test default serializer: | ||
obj.to_string(standard)=0.5 | ||
Test default serializer with custom userdata: | ||
obj.to_string(userdata)=0.5 | ||
Test explicit serializer with custom userdata: | ||
obj.to_string(custom)=test | ||
Test reset serializer: | ||
obj.to_string(reset)=0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
# Common definitions | ||
if test -z "$srcdir"; then | ||
srcdir="${0%/*}" | ||
test "$srcdir" = "$0" && srcdir=. | ||
test -z "$srcdir" && srcdir=. | ||
fi | ||
. "$srcdir/test-defs.sh" | ||
|
||
run_output_test test_double_serializer | ||
exit $? |