[json-glib] tests: Add more checks to the parser stream unit



commit c9de87387f3b2494e4e770fd1d2ffca9ebfdbfe5
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 17 15:30:32 2014 +0100

    tests: Add more checks to the parser stream unit

 json-glib/tests/parser.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/json-glib/tests/parser.c b/json-glib/tests/parser.c
index 1747697..bdfbf13 100644
--- a/json-glib/tests/parser.c
+++ b/json-glib/tests/parser.c
@@ -653,6 +653,7 @@ test_stream_sync (void)
   GFileInputStream *stream;
   GError *error = NULL;
   JsonNode *root;
+  JsonArray *array;
   char *path;
 
   parser = json_parser_new ();
@@ -660,16 +661,21 @@ test_stream_sync (void)
   path = g_test_build_filename (G_TEST_DIST, "stream-load.json", NULL);
   file = g_file_new_for_path (path);
   stream = g_file_read (file, NULL, &error);
-  g_assert (error == NULL);
+  g_assert_no_error (error);
   g_assert (stream != NULL);
 
   json_parser_load_from_stream (parser, G_INPUT_STREAM (stream), NULL, &error);
-  g_assert (error == NULL);
+  g_assert_no_error (error);
 
   root = json_parser_get_root (parser);
   g_assert (root != NULL);
   g_assert (JSON_NODE_HOLDS_ARRAY (root));
 
+  array = json_node_get_array (root);
+  g_assert_cmpint (json_array_get_length (array), ==, 1);
+  g_assert (JSON_NODE_HOLDS_OBJECT (json_array_get_element (array, 0)));
+  g_assert (json_object_has_member (json_array_get_object_element (array, 0), "hello"));
+
   g_object_unref (stream);
   g_object_unref (file);
   g_object_unref (parser);
@@ -685,16 +691,20 @@ on_load_complete (GObject      *gobject,
   GMainLoop *main_loop = user_data;
   GError *error = NULL;
   JsonNode *root;
-  gboolean res;
+  JsonArray *array;
 
-  res = json_parser_load_from_stream_finish (parser, result, &error);
-  g_assert (res);
-  g_assert (error == NULL);
+  json_parser_load_from_stream_finish (parser, result, &error);
+  g_assert_no_error (error);
 
   root = json_parser_get_root (parser);
   g_assert (root != NULL);
   g_assert (JSON_NODE_HOLDS_ARRAY (root));
 
+  array = json_node_get_array (root);
+  g_assert_cmpint (json_array_get_length (array), ==, 1);
+  g_assert (JSON_NODE_HOLDS_OBJECT (json_array_get_element (array, 0)));
+  g_assert (json_object_has_member (json_array_get_object_element (array, 0), "hello"));
+
   g_main_loop_quit (main_loop);
 }
 


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