summaryrefslogtreecommitdiff
path: root/json-glib/tests/parser.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2014-04-17 15:30:32 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2014-04-17 15:32:06 +0100
commitc9de87387f3b2494e4e770fd1d2ffca9ebfdbfe5 (patch)
treec3fc03cabddebd5d56e35a3694b00cd9bc68d481 /json-glib/tests/parser.c
parente31683d2804916da23d1e48b80b124b37df1c8e6 (diff)
downloadjson-glib-c9de87387f3b2494e4e770fd1d2ffca9ebfdbfe5.tar.gz
tests: Add more checks to the parser stream unit
Diffstat (limited to 'json-glib/tests/parser.c')
-rw-r--r--json-glib/tests/parser.c22
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);
}