[json-glib] tests: Add new test for reader level bug



commit 40abd7add9e3fa7288fdd144fd96da5270a86663
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Feb 1 23:31:02 2014 +0100

    tests: Add new test for reader level bug
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723428

 json-glib/tests/reader.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/json-glib/tests/reader.c b/json-glib/tests/reader.c
index 2b75522..19f58c9 100644
--- a/json-glib/tests/reader.c
+++ b/json-glib/tests/reader.c
@@ -11,6 +11,9 @@ static const gchar *test_base_array_data =
 static const gchar *test_base_object_data =
 "{ \"text\" : \"hello, world!\", \"foo\" : null, \"blah\" : 47, \"double\" : 42.47 }";
 
+static const gchar *test_reader_level_data =
+" { \"list\": { \"181195771\": { \"given_url\": \"http://www.gnome.org/json-glib-test\"; } } }";
+
 static const gchar *expected_member_name[] = {
   "text",
   "foo",
@@ -133,6 +136,45 @@ test_base_array (void)
   g_object_unref (reader);
 }
 
+static void
+test_reader_level (void)
+{
+  JsonParser *parser = json_parser_new ();
+  JsonReader *reader = json_reader_new (NULL);
+  GError *error = NULL;
+  char **members;
+
+  json_parser_load_from_data (parser, test_reader_level_data, -1, &error);
+  g_assert (error == NULL);
+
+  json_reader_set_root (reader, json_parser_get_root (parser));
+
+  g_assert (json_reader_count_members (reader) > 0);
+
+  /* Grab the list */
+  g_assert (json_reader_read_member (reader, "list"));
+
+  members = json_reader_list_members (reader);
+  g_assert (members != NULL);
+  g_strfreev (members);
+
+  g_assert (json_reader_read_member (reader, "181195771"));
+
+  g_assert (!json_reader_read_member (reader, "resolved_url"));
+  g_assert (json_reader_get_error (reader) != NULL);
+  json_reader_end_member (reader);
+
+  g_assert (json_reader_read_member (reader, "given_url"));
+  g_assert_cmpstr (json_reader_get_string_value (reader), ==, "http://www.gnome.org/json-glib-test";);
+  json_reader_end_member (reader);
+
+  json_reader_end_member (reader);
+
+  json_reader_end_member (reader);
+  g_clear_object (&reader);
+  g_clear_object (&parser);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -142,6 +184,7 @@ main (int   argc,
 
   g_test_add_func ("/reader/base-array", test_base_array);
   g_test_add_func ("/reader/base-object", test_base_object);
+  g_test_add_func ("/reader/level", test_reader_level);
 
   return g_test_run ();
 }


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