diff options
author | Philip Withnall <withnall@endlessm.com> | 2020-06-09 15:41:24 +0100 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2020-06-09 15:41:24 +0100 |
commit | 13142637c8132f49e1bd012786eb5f7f7c6dc986 (patch) | |
tree | 9093e7eb80630cdc8336493f0f7b91e2c8f57c60 /json-glib/tests/parser.c | |
parent | 0a562b86894f1244b4dac573c72b000ea38bcc75 (diff) | |
download | json-glib-13142637c8132f49e1bd012786eb5f7f7c6dc986.tar.gz |
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>
Diffstat (limited to 'json-glib/tests/parser.c')
-rw-r--r-- | json-glib/tests/parser.c | 26 |
1 files 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); } |