[json-glib: 1/3] tests: Factor out a helper function
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib: 1/3] tests: Factor out a helper function
- Date: Tue, 16 Jun 2020 13:37:46 +0000 (UTC)
commit 13142637c8132f49e1bd012786eb5f7f7c6dc986
Author: Philip Withnall <withnall endlessm com>
Date: Tue Jun 9 15:41:24 2020 +0100
tests: Factor out a helper function
This introduces no functional changes, but will allow that code to be
reused in the following commit.
Signed-off-by: Philip Withnall <withnall endlessm com>
json-glib/tests/parser.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/json-glib/tests/parser.c b/json-glib/tests/parser.c
index 7af4329..acc6276 100644
--- a/json-glib/tests/parser.c
+++ b/json-glib/tests/parser.c
@@ -689,20 +689,13 @@ test_stream_sync (void)
g_free (path);
}
+/* Assert that the JSON in @parser was correctly loaded from stream-load.json. */
static void
-on_load_complete (GObject *gobject,
- GAsyncResult *result,
- gpointer user_data)
+assert_stream_load_json_correct (JsonParser *parser)
{
- JsonParser *parser = JSON_PARSER (gobject);
- GMainLoop *main_loop = user_data;
- GError *error = NULL;
JsonNode *root;
JsonArray *array;
- 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));
@@ -711,6 +704,21 @@ on_load_complete (GObject *gobject,
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"));
+}
+
+static void
+on_load_complete (GObject *gobject,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ JsonParser *parser = JSON_PARSER (gobject);
+ GMainLoop *main_loop = user_data;
+ GError *error = NULL;
+
+ json_parser_load_from_stream_finish (parser, result, &error);
+ g_assert_no_error (error);
+
+ assert_stream_load_json_correct (parser);
g_main_loop_quit (main_loop);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]