summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2009-09-28 14:02:14 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2009-09-28 14:02:14 +0100
commit17fc731ed54b754285bac76c7ac23eac6b96bf24 (patch)
tree1891d1684912490ff32a2919a105e19224d79837
parent5181bf24bf3cde743de590ab3ffa0471df9e4799 (diff)
downloadjson-glib-17fc731ed54b754285bac76c7ac23eac6b96bf24.tar.gz
[tests] Add a test case for Object members with empty strings
Both the Object API and the Parser should not choke on members with empty strings as their value. The Object should just have a member associated with a JSON_NODE_VALUE node type and an empty string as the contents.
-rw-r--r--json-glib/tests/object-test.c13
-rw-r--r--tests/test-parser.c1
2 files changed, 14 insertions, 0 deletions
diff --git a/json-glib/tests/object-test.c b/json-glib/tests/object-test.c
index 04c862c..3d7b4d1 100644
--- a/json-glib/tests/object-test.c
+++ b/json-glib/tests/object-test.c
@@ -103,6 +103,18 @@ test_foreach_member (void)
json_object_unref (object);
}
+static void
+test_empty_member (void)
+{
+ JsonObject *object = json_object_new ();
+
+ json_object_set_string_member (object, "string", "");
+ g_assert (json_object_has_member (object, "string"));
+ g_assert_cmpstr (json_object_get_string_member (object, "string"), ==, "");
+
+ json_object_unref (object);
+}
+
int
main (int argc,
char *argv[])
@@ -114,6 +126,7 @@ main (int argc,
g_test_add_func ("/object/add-member", test_add_member);
g_test_add_func ("/object/remove-member", test_remove_member);
g_test_add_func ("/object/foreach-member", test_foreach_member);
+ g_test_add_func ("/object/empty-member", test_empty_member);
return g_test_run ();
}
diff --git a/tests/test-parser.c b/tests/test-parser.c
index 460b772..04269f0 100644
--- a/tests/test-parser.c
+++ b/tests/test-parser.c
@@ -56,6 +56,7 @@ static const struct {
GType gtype;
} test_simple_objects[] = {
{ "{ \"test\" : 42 }", 1, "test", JSON_NODE_VALUE, G_TYPE_INT64 },
+ { "{ \"name\" : \"\", \"state\" : 1 }", 2, "name", JSON_NODE_VALUE, G_TYPE_STRING },
{ "{ \"foo\" : \"bar\", \"baz\" : null }", 2, "baz", JSON_NODE_NULL, G_TYPE_INVALID },
{ "{ \"channel\" : \"/meta/connect\" }", 1, "channel", JSON_NODE_VALUE, G_TYPE_STRING }
};