[json-glib/json-glib-0-8] [tests] Add a test case for Object members with empty strings



commit 8806fbf1842b1af1927054928b59e69c9de8d25e
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Thu Oct 29 14:05:35 2009 +0000

    [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.
    
    (cherry picked from commit 17fc731ed54b754285bac76c7ac23eac6b96bf24)

 json-glib/tests/object-test.c |   13 +++++++++++++
 tests/test-parser.c           |    1 +
 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 }
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]