diff options
author | Emmanuele Bassi <ebassi@gmail.com> | 2022-10-18 08:45:03 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2022-10-18 08:45:03 +0000 |
commit | a862cc39013e841cd6bff02ab7a02937e2836c93 (patch) | |
tree | 62834abbb1c2893f934660be96a29398609967de /json-glib | |
parent | e29cf26dac3b018c245aabf8391d2edff7a2881d (diff) | |
parent | 951c3591c0102d62ac1123baa1cfad224f68a9e4 (diff) | |
download | json-glib-a862cc39013e841cd6bff02ab7a02937e2836c93.tar.gz |
Merge branch 'ebassi/test-message' into 'master'
Replace g_print with g_test_message
See merge request GNOME/json-glib!56
Diffstat (limited to 'json-glib')
-rw-r--r-- | json-glib/tests/boxed.c | 24 | ||||
-rw-r--r-- | json-glib/tests/builder.c | 6 | ||||
-rw-r--r-- | json-glib/tests/generator.c | 30 | ||||
-rw-r--r-- | json-glib/tests/invalid.c | 47 | ||||
-rw-r--r-- | json-glib/tests/node.c | 14 | ||||
-rw-r--r-- | json-glib/tests/parser.c | 482 | ||||
-rw-r--r-- | json-glib/tests/path.c | 22 | ||||
-rw-r--r-- | json-glib/tests/serialize-complex.c | 3 | ||||
-rw-r--r-- | json-glib/tests/serialize-full.c | 24 | ||||
-rw-r--r-- | json-glib/tests/serialize-simple.c | 3 |
10 files changed, 212 insertions, 443 deletions
diff --git a/json-glib/tests/boxed.c b/json-glib/tests/boxed.c index e9facff..e89c04d 100644 --- a/json-glib/tests/boxed.c +++ b/json-glib/tests/boxed.c @@ -72,12 +72,9 @@ test_boxed_serialize (gconstpointer boxed) json_node_take_object (node, object); - if (g_test_verbose ()) - { - g_print ("Serialize: { foo: %" G_GINT64_FORMAT ", bar: %s }\n", - json_object_get_int_member (object, "foo"), - json_object_get_boolean_member (object, "bar") ? "true" : "false"); - } + g_test_message ("Serialize: { foo: %" G_GINT64_FORMAT ", bar: %s }", + json_object_get_int_member (object, "foo"), + json_object_get_boolean_member (object, "bar") ? "true" : "false"); return node; } @@ -97,12 +94,9 @@ test_boxed_deserialize (JsonNode *node) test->foo = json_object_get_int_member (object, "foo"); test->bar = json_object_get_boolean_member (object, "bar"); - if (g_test_verbose ()) - { - g_print ("Deserialize: { foo: %d, bar: %s }\n", - test->foo, - test->bar ? "true" : "false"); - } + g_test_message ("Deserialize: { foo: %d, bar: %s }", + test->foo, + test->bar ? "true" : "false"); return test; } @@ -118,8 +112,7 @@ test_boxed_get_type (void) test_boxed_copy, test_boxed_free); - if (g_test_verbose ()) - g_print ("Registering transform functions\n"); + g_test_message ("Registering transform functions"); json_boxed_register_serialize_func (b_type, JSON_NODE_OBJECT, test_boxed_serialize); @@ -229,8 +222,7 @@ test_serialize_boxed (void) g_assert_cmpint (len, ==, strlen (serialize_data)); g_assert_cmpstr (data, ==, serialize_data); - if (g_test_verbose ()) - g_print ("TestObject:\n%s\n", data); + g_test_message ("TestObject: %s", data); g_free (data); g_object_unref (obj); diff --git a/json-glib/tests/builder.c b/json-glib/tests/builder.c index 42569d7..34d57ef 100644 --- a/json-glib/tests/builder.c +++ b/json-glib/tests/builder.c @@ -70,8 +70,7 @@ test_builder_complex (void) json_generator_set_root (generator, node); data = json_generator_to_data (generator, &length); - if (g_test_verbose ()) - g_print ("Builder complex: '%*s'\n", (int)length, data); + g_test_message ("Builder complex: '%*s'", (int)length, data); g_assert_cmpint (length, ==, strlen (complex_object)); g_assert_cmpstr (data, ==, complex_object); @@ -106,8 +105,7 @@ test_builder_empty (void) json_generator_set_root (generator, node); data = json_generator_to_data (generator, &length); - if (g_test_verbose ()) - g_print ("Builder empty: '%*s'\n", (int)length, data); + g_test_message ("Builder empty: '%*s'", (int)length, data); g_assert_cmpint (length, ==, strlen (empty_object)); g_assert_cmpstr (data, ==, empty_object); diff --git a/json-glib/tests/generator.c b/json-glib/tests/generator.c index f6ac0f1..034de5a 100644 --- a/json-glib/tests/generator.c +++ b/json-glib/tests/generator.c @@ -141,10 +141,9 @@ test_simple_array (void) g_object_set (generator, "pretty", FALSE, NULL); data = json_generator_to_data (generator, &len); - if (g_test_verbose ()) - g_print ("checking simple array `%s' (expected: %s)\n", - data, - simple_array); + g_test_message ("checking simple array '%s' (expected: '%s')", + data, + simple_array); g_assert_cmpint (len, ==, strlen (simple_array)); g_assert_cmpstr (data, ==, simple_array); @@ -218,10 +217,9 @@ test_simple_object (void) g_object_set (generator, "pretty", FALSE, NULL); data = json_generator_to_data (generator, &len); - if (g_test_verbose ()) - g_print ("checking simple object `%s' (expected: %s)\n", - data, - simple_object); + g_test_message ("checking simple object '%s' (expected: '%s')", + data, + simple_object); g_assert_cmpint (len, ==, strlen (simple_object)); g_assert_cmpstr (data, ==, simple_object); @@ -278,10 +276,9 @@ test_nested_object (void) g_object_set (generator, "pretty", FALSE, NULL); data = json_generator_to_data (generator, &len); - if (g_test_verbose ()) - g_print ("checking nested object `%s' (expected: %s)\n", - data, - nested_object); + g_test_message ("checking nested object '%s' (expected: '%s')", + data, + nested_object); g_assert_cmpint (len, ==, strlen (nested_object)); g_assert_cmpstr (data, ==, nested_object); @@ -312,11 +309,10 @@ test_decimal_separator (void) str = json_generator_to_data (generator, NULL); - if (g_test_verbose ()) - g_print ("%s: value: %.2f - string: '%s'\n", - G_STRFUNC, - json_node_get_double (node), - str); + g_test_message ("%s: value: '%.2f' - string: '%s'", + G_STRFUNC, + json_node_get_double (node), + str); g_assert_nonnull (str); expected = strstr (str, decimal_separator[i].sep); diff --git a/json-glib/tests/invalid.c b/json-glib/tests/invalid.c index 3cab2c2..600031d 100644 --- a/json-glib/tests/invalid.c +++ b/json-glib/tests/invalid.c @@ -18,17 +18,12 @@ test_invalid_bareword (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); - g_assert_false (res); g_assert_error (error, JSON_PARSER_ERROR, JSON_PARSER_ERROR_INVALID_BAREWORD); - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); - g_clear_error (&error); g_object_unref (parser); @@ -45,16 +40,13 @@ test_invalid_assignment (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_nonnull (error); - - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); + g_test_message ("error: %s", error->message); g_clear_error (&error); @@ -72,16 +64,13 @@ test_invalid_value (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_nonnull (error); - - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); + g_test_message ("error: %s", error->message); g_clear_error (&error); @@ -99,16 +88,13 @@ test_invalid_array (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_nonnull (error); - - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); + g_test_message ("error: %s", error->message); g_clear_error (&error); @@ -126,16 +112,13 @@ test_invalid_object (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_nonnull (error); - - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); + g_test_message ("error: %s", error->message); g_clear_error (&error); @@ -153,17 +136,13 @@ test_missing_comma (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_error (error, JSON_PARSER_ERROR, JSON_PARSER_ERROR_MISSING_COMMA); - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); - g_clear_error (&error); g_object_unref (parser); @@ -180,17 +159,13 @@ test_trailing_comma (gconstpointer user_data) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("invalid data: '%s'...", json); + g_test_message ("invalid data: '%s'...", json); res = json_parser_load_from_data (parser, json, -1, &error); g_assert_false (res); g_assert_error (error, JSON_PARSER_ERROR, JSON_PARSER_ERROR_TRAILING_COMMA); - if (g_test_verbose ()) - g_print ("expected error: %s\n", error->message); - g_clear_error (&error); g_object_unref (parser); diff --git a/json-glib/tests/node.c b/json-glib/tests/node.c index 764ea36..7728f94 100644 --- a/json-glib/tests/node.c +++ b/json-glib/tests/node.c @@ -213,17 +213,14 @@ test_gvalue_autopromotion (void) g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_VALUE); - if (g_test_verbose ()) - g_print ("Autopromotion of int to int64\n"); - + g_test_message ("Autopromotion of int to int64"); g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, 42); json_node_set_value (node, &value); json_node_get_value (node, &check); - if (g_test_verbose ()) - g_print ("Expecting an gint64, got a %s\n", g_type_name (G_VALUE_TYPE (&check))); + g_test_message ("Expecting an gint64, got a '%s'", g_type_name (G_VALUE_TYPE (&check))); g_assert_cmpint (G_VALUE_TYPE (&check), ==, G_TYPE_INT64); g_assert_cmpint (g_value_get_int64 (&check), ==, 42); @@ -233,17 +230,14 @@ test_gvalue_autopromotion (void) g_value_unset (&value); g_value_unset (&check); - if (g_test_verbose ()) - g_print ("Autopromotion of float to double\n"); - + g_test_message ("Autopromotion of float to double"); g_value_init (&value, G_TYPE_FLOAT); g_value_set_float (&value, 3.14159f); json_node_set_value (node, &value); json_node_get_value (node, &check); - if (g_test_verbose ()) - g_print ("Expecting a gdouble, got a %s\n", g_type_name (G_VALUE_TYPE (&check))); + g_test_message ("Expecting a gdouble, got a '%s'", g_type_name (G_VALUE_TYPE (&check))); g_assert_cmpint (G_VALUE_TYPE (&check), ==, G_TYPE_DOUBLE); json_assert_fuzzy_equals (g_value_get_double (&check), 3.14159, 0.00001); diff --git a/json-glib/tests/parser.c b/json-glib/tests/parser.c index bd23798..afe3653 100644 --- a/json-glib/tests/parser.c +++ b/json-glib/tests/parser.c @@ -120,10 +120,11 @@ static const gchar *test_nested_objects[] = { static const struct { const gchar *str; const gchar *var; + JsonNodeType type; } test_assignments[] = { - { "var foo = [ false, false, true ]", "foo" }, - { "var bar = [ true, 42 ];", "bar" }, - { "var baz = { \"foo\" : false }", "baz" } + { "var foo = [ false, false, true ]", "foo", JSON_NODE_ARRAY }, + { "var bar = [ true, 42 ];", "bar", JSON_NODE_ARRAY }, + { "var baz = { \"foo\" : false }", "baz", JSON_NODE_OBJECT } }; static const struct @@ -148,24 +149,9 @@ test_empty_with_parser (JsonParser *parser) { GError *error = NULL; - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with empty string...\n"); - - if (!json_parser_load_from_data (parser, test_empty_string, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - if (g_test_verbose ()) - g_print ("checking json_parser_get_root...\n"); - - g_assert_null (json_parser_get_root (parser)); - } + json_parser_load_from_data (parser, test_empty_string, -1, &error); + g_assert_no_error (error); + g_assert_null (json_parser_get_root (parser)); } static void @@ -194,42 +180,25 @@ test_base_value (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with base-values...\n"); - for (guint i = 0; i < n_test_base_values; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_base_values[i].str, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root; - - g_assert_nonnull (json_parser_get_root (parser)); - - root = json_parser_get_root (parser); - g_assert_nonnull (root); - g_assert_null (json_node_get_parent (root)); - - if (g_test_verbose ()) - g_print ("checking root node is of the desired type %s...\n", - test_base_values[i].gtype == G_TYPE_INVALID ? "<null>" - : g_type_name (test_base_values[i].gtype)); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, test_base_values[i].type); - g_assert_cmpint (json_node_get_value_type (root), ==, test_base_values[i].gtype); - - if (test_base_values[i].verify_value) - test_base_values[i].verify_value (root); - } + json_parser_load_from_data (parser, test_base_values[i].str, -1, &error); + g_assert_no_error (error); + + JsonNode *root = json_parser_get_root (parser); + + g_assert_nonnull (root); + g_assert_null (json_node_get_parent (root)); + + g_test_message ("Checking root node type '%s'...", + json_node_type_name (root)); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, test_base_values[i].type); + g_assert_cmpint (json_node_get_value_type (root), ==, test_base_values[i].gtype); + + if (test_base_values[i].verify_value) + test_base_values[i].verify_value (root); } g_object_unref (parser); @@ -244,37 +213,19 @@ test_empty_array (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with empty array...\n"); + json_parser_load_from_data (parser, test_empty_array_string, -1, &error); - if (!json_parser_load_from_data (parser, test_empty_array_string, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root; - JsonArray *array; - - g_assert_nonnull (json_parser_get_root (parser)); + g_assert_no_error (error); - if (g_test_verbose ()) - g_print ("checking root node is an array...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); - g_assert_null (json_node_get_parent (root)); + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); + g_assert_null (json_node_get_parent (root)); - array = json_node_get_array (root); - g_assert_nonnull (array); + JsonArray *array = json_node_get_array (root); + g_assert_nonnull (array); - if (g_test_verbose ()) - g_print ("checking array is empty...\n"); - g_assert_cmpint (json_array_get_length (array), ==, 0); - } + g_assert_cmpint (json_array_get_length (array), ==, 0); g_object_unref (parser); } @@ -287,56 +238,34 @@ test_simple_array (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with simple arrays...\n"); - for (guint i = 0; i < n_test_simple_arrays; i++) { GError *error = NULL; - if (g_test_verbose ()) - g_print ("Parsing: '%s'\n", test_simple_arrays[i].str); - - if (!json_parser_load_from_data (parser, test_simple_arrays[i].str, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root, *node; - JsonArray *array; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an array...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); - g_assert_null (json_node_get_parent (root)); - - array = json_node_get_array (root); - g_assert_nonnull (array); - - if (g_test_verbose ()) - g_print ("checking array is of the desired length (%d)...\n", - test_simple_arrays[i].len); - g_assert_cmpint (json_array_get_length (array), ==, test_simple_arrays[i].len); - - if (g_test_verbose ()) - g_print ("checking element %d is of the desired type %s...\n", - test_simple_arrays[i].element, - g_type_name (test_simple_arrays[i].gtype)); - node = json_array_get_element (array, test_simple_arrays[i].element); - g_assert_nonnull (node); - g_assert_true (json_node_get_parent (node) == root); - g_assert_cmpint (JSON_NODE_TYPE (node), ==, test_simple_arrays[i].type); - g_assert_cmpint (json_node_get_value_type (node), ==, test_simple_arrays[i].gtype); - } + g_test_message ("Parsing: '%s'", test_simple_arrays[i].str); + + json_parser_load_from_data (parser, test_simple_arrays[i].str, -1, &error); + + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); + g_assert_null (json_node_get_parent (root)); + + JsonArray *array = json_node_get_array (root); + g_assert_nonnull (array); + + g_assert_cmpint (json_array_get_length (array), ==, test_simple_arrays[i].len); + + g_test_message ("checking element %d is of the desired type %s...", + test_simple_arrays[i].element, + g_type_name (test_simple_arrays[i].gtype)); + + JsonNode *node = json_array_get_element (array, test_simple_arrays[i].element); + g_assert_nonnull (node); + g_assert_true (json_node_get_parent (node) == root); + g_assert_cmpint (JSON_NODE_TYPE (node), ==, test_simple_arrays[i].type); + g_assert_cmpint (json_node_get_value_type (node), ==, test_simple_arrays[i].gtype); } g_object_unref (parser); @@ -350,42 +279,21 @@ test_nested_array (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with nested arrays...\n"); - for (guint i = 0; i < n_test_nested_arrays; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_nested_arrays[i], -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root; - JsonArray *array; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an array...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); - g_assert_null (json_node_get_parent (root)); - - array = json_node_get_array (root); - g_assert_nonnull (array); - - if (g_test_verbose ()) - g_print ("checking array is not empty...\n"); - g_assert_cmpint (json_array_get_length (array), >, 0); - } + json_parser_load_from_data (parser, test_nested_arrays[i], -1, &error); + g_assert_no_error (error); + + JsonNode *root = json_parser_get_root (parser); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_ARRAY); + g_assert_null (json_node_get_parent (root)); + + JsonArray *array = json_node_get_array (root); + g_assert_nonnull (array); + + g_assert_cmpint (json_array_get_length (array), >, 0); } g_object_unref (parser); @@ -400,38 +308,17 @@ test_empty_object (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with empty object...\n"); - - if (!json_parser_load_from_data (parser, test_empty_object_string, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root; - JsonObject *object; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an object...\n"); - root = json_parser_get_root (parser); - g_assert_null (json_node_get_parent (root)); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); - g_assert_null (json_node_get_parent (root)); + json_parser_load_from_data (parser, test_empty_object_string, -1, &error); + g_assert_no_error (error); - object = json_node_get_object (root); - g_assert_nonnull (object); + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + g_assert_null (json_node_get_parent (root)); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); - if (g_test_verbose ()) - g_print ("checking object is empty...\n"); - g_assert_cmpint (json_object_get_size (object), ==, 0); - } + JsonObject *object = json_node_get_object (root); + g_assert_nonnull (object); + g_assert_cmpint (json_object_get_size (object), ==, 0); g_object_unref (parser); } @@ -444,53 +331,35 @@ test_simple_object (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with simple objects...\n"); - for (guint i = 0; i < n_test_simple_objects; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_simple_objects[i].str, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root, *node; - JsonObject *object; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an object...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); - g_assert_null (json_node_get_parent (root)); - - object = json_node_get_object (root); - g_assert_nonnull (object); - - if (g_test_verbose ()) - g_print ("checking object is of the desired size (%d)...\n", - test_simple_objects[i].size); - g_assert_cmpint (json_object_get_size (object), ==, test_simple_objects[i].size); - - if (g_test_verbose ()) - g_print ("checking member '%s' is of the desired type %s...\n", - test_simple_objects[i].member, - g_type_name (test_simple_objects[i].gtype)); - node = json_object_get_member (object, test_simple_objects[i].member); - g_assert_nonnull (node); - g_assert_true (json_node_get_parent (node) == root); - g_assert_cmpint (JSON_NODE_TYPE (node), ==, test_simple_objects[i].type); - g_assert_cmpint (json_node_get_value_type (node), ==, test_simple_objects[i].gtype); - } + json_parser_load_from_data (parser, test_simple_objects[i].str, -1, &error); + g_assert_no_error (error); + + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + + g_test_message ("checking root node is an object..."); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); + g_assert_null (json_node_get_parent (root)); + + JsonObject *object = json_node_get_object (root); + g_assert_nonnull (object); + + g_test_message ("checking object is of the desired size '%d'...", + test_simple_objects[i].size); + g_assert_cmpint (json_object_get_size (object), ==, test_simple_objects[i].size); + + g_test_message ("checking member '%s' exists and is of the desired type '%s'...", + test_simple_objects[i].member, + g_type_name (test_simple_objects[i].gtype)); + JsonNode *node = json_object_get_member (object, test_simple_objects[i].member); + g_assert_nonnull (node); + g_assert_true (json_node_get_parent (node) == root); + g_assert_cmpint (JSON_NODE_TYPE (node), ==, test_simple_objects[i].type); + g_assert_cmpint (json_node_get_value_type (node), ==, test_simple_objects[i].gtype); } g_object_unref (parser); @@ -504,42 +373,25 @@ test_nested_object (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with nested objects...\n"); - for (guint i = 0; i < n_test_nested_objects; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_nested_objects[i], -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root; - JsonObject *object; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an object...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); - g_assert_null (json_node_get_parent (root)); - - object = json_node_get_object (root); - g_assert_nonnull (object); - - if (g_test_verbose ()) - g_print ("checking object is not empty...\n"); - g_assert_cmpint (json_object_get_size (object), >, 0); - } + json_parser_load_from_data (parser, test_nested_objects[i], -1, &error); + g_assert_no_error (error); + + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + + g_test_message ("checking root node is an object..."); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); + g_assert_null (json_node_get_parent (root)); + + JsonObject *object = json_node_get_object (root); + g_assert_nonnull (object); + + g_test_message ("checking object is not empty..."); + g_assert_cmpint (json_object_get_size (object), >, 0); } g_object_unref (parser); @@ -553,34 +405,25 @@ test_assignment (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with assignments...\n"); - for (guint i = 0; i < n_test_assignments; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_assignments[i].str, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - gchar *var; - - if (g_test_verbose ()) - g_print ("checking assignment...\n"); - - g_assert_true (json_parser_has_assignment (parser, &var)); - g_assert_nonnull (var); - g_assert_cmpstr (var, ==, test_assignments[i].var); - g_assert_nonnull (json_parser_get_root (parser)); - } + json_parser_load_from_data (parser, test_assignments[i].str, -1, &error); + g_assert_no_error (error); + + g_test_message ("checking variable '%s' is assigned...", + test_assignments[i].var); + + char *var = NULL; + g_assert_true (json_parser_has_assignment (parser, &var)); + g_assert_nonnull (var); + g_assert_cmpstr (var, ==, test_assignments[i].var); + + g_test_message ("checking for a root of the desired type..."); + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, test_assignments[i].type); } g_object_unref (parser); @@ -594,52 +437,33 @@ test_unicode_escape (void) parser = json_parser_new (); g_assert_true (JSON_IS_PARSER (parser)); - if (g_test_verbose ()) - g_print ("checking json_parser_load_from_data with unicode escape...\n"); - for (guint i = 0; i < n_test_unicode; i++) { GError *error = NULL; - if (!json_parser_load_from_data (parser, test_unicode[i].str, -1, &error)) - { - if (g_test_verbose ()) - g_print ("Error: %s\n", error->message); - - g_error_free (error); - g_object_unref (parser); - exit (1); - } - else - { - JsonNode *root, *node; - JsonObject *object; - - g_assert_nonnull (json_parser_get_root (parser)); - - if (g_test_verbose ()) - g_print ("checking root node is an object...\n"); - root = json_parser_get_root (parser); - g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); - - object = json_node_get_object (root); - g_assert_true (object); - - if (g_test_verbose ()) - g_print ("checking object is not empty...\n"); - g_assert_cmpint (json_object_get_size (object), >, 0); - - node = json_object_get_member (object, test_unicode[i].member); - g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_VALUE); - - if (g_test_verbose ()) - g_print ("checking simple string equality...\n"); - g_assert_cmpstr (json_node_get_string (node), ==, test_unicode[i].match); - - if (g_test_verbose ()) - g_print ("checking for valid UTF-8...\n"); - g_assert_true (g_utf8_validate (json_node_get_string (node), -1, NULL)); - } + json_parser_load_from_data (parser, test_unicode[i].str, -1, &error); + g_assert_no_error (error); + + g_test_message ("checking root node is an object..."); + JsonNode *root = json_parser_get_root (parser); + g_assert_nonnull (root); + g_assert_cmpint (JSON_NODE_TYPE (root), ==, JSON_NODE_OBJECT); + + JsonObject *object = json_node_get_object (root); + g_assert_nonnull (object); + + g_test_message ("checking object is not empty..."); + g_assert_cmpint (json_object_get_size (object), >, 0); + + g_test_message ("checking for object member '%s'...", test_unicode[i].member); + JsonNode *node = json_object_get_member (object, test_unicode[i].member); + g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_VALUE); + + g_test_message ("checking simple string equality..."); + g_assert_cmpstr (json_node_get_string (node), ==, test_unicode[i].match); + + g_test_message ("checking for valid UTF-8..."); + g_assert_true (g_utf8_validate (json_node_get_string (node), -1, NULL)); } g_object_unref (parser); diff --git a/json-glib/tests/path.c b/json-glib/tests/path.c index 864e84a..d8ddea6 100644 --- a/json-glib/tests/path.c +++ b/json-glib/tests/path.c @@ -200,8 +200,7 @@ path_expressions_valid (gconstpointer data) JsonPath *path = json_path_new (); GError *error = NULL; - if (g_test_verbose ()) - g_print ("* %s ('%s')\n", desc, expr); + g_test_message ("* %s ('%s')", desc, expr); g_assert_true (json_path_compile (path, expr, &error)); g_assert_no_error (error); @@ -220,9 +219,7 @@ path_expressions_invalid (gconstpointer data) JsonPath *path = json_path_new (); GError *error = NULL; - if (g_test_verbose ()) - g_print ("* %s ('%s')\n", desc, expr); - + g_test_message ("* %s ('%s')", desc, expr); g_assert_false (json_path_compile (path, expr, &error)); g_assert_error (error, JSON_PATH_ERROR, (int) code); @@ -257,15 +254,12 @@ path_match (gconstpointer data) json_generator_set_root (gen, matches); str = json_generator_to_data (gen, NULL); - if (g_test_verbose ()) - { - g_print ("* %s ('%s') =>\n" - "- result: %s\n" - "- expected: %s\n", - desc, expr, - str, - res); - } + g_test_message ("* %s ('%s') =>\n" + "- result: %s\n" + "- expected: %s", + desc, expr, + str, + res); g_assert_cmpstr (str, ==, res); diff --git a/json-glib/tests/serialize-complex.c b/json-glib/tests/serialize-complex.c index b43c143..4292f65 100644 --- a/json-glib/tests/serialize-complex.c +++ b/json-glib/tests/serialize-complex.c @@ -273,8 +273,7 @@ test_serialize (void) data = json_gobject_to_data (G_OBJECT (obj), &len); g_assert_cmpint (len, >, 0); - if (g_test_verbose ()) - g_print ("TestObject:\n%s\n", data); + g_test_message ("TestObject: %s", data); parser = json_parser_new (); json_parser_load_from_data (parser, data, -1, &error); diff --git a/json-glib/tests/serialize-full.c b/json-glib/tests/serialize-full.c index 9e8d512..bd78a79 100644 --- a/json-glib/tests/serialize-full.c +++ b/json-glib/tests/serialize-full.c @@ -406,19 +406,17 @@ test_deserialize (void) error = NULL; object = json_gobject_from_data (TEST_TYPE_OBJECT, var_test, -1, &error); - if (error) - g_error ("*** Unable to parse buffer: %s\n", error->message); - - if (g_test_verbose ()) - g_print ("*** TestObject ***\n" - " foo: %s\n" - " bar: %s\n" - " baz: %s\n" - " meh: %s\n", - TEST_OBJECT (object)->m_int == 42 ? "<true>" : "<false>", - TEST_OBJECT (object)->m_bool == TRUE ? "<true>" : "<false>", - TEST_OBJECT (object)->m_str != NULL ? "<true>" : "<false>", - TEST_OBJECT (object)->m_enum == TEST_ENUM_BAZ ? "<true>" : "<false>"); + g_assert_no_error (error); + + g_test_message ("*** TestObject ***\n" + " foo: %s\n" + " bar: %s\n" + " baz: %s\n" + " meh: %s", + TEST_OBJECT (object)->m_int == 42 ? "<true>" : "<false>", + TEST_OBJECT (object)->m_bool == TRUE ? "<true>" : "<false>", + TEST_OBJECT (object)->m_str != NULL ? "<true>" : "<false>", + TEST_OBJECT (object)->m_enum == TEST_ENUM_BAZ ? "<true>" : "<false>"); g_assert_cmpint (TEST_OBJECT (object)->m_int, ==, 42); g_assert_true (TEST_OBJECT (object)->m_bool); diff --git a/json-glib/tests/serialize-simple.c b/json-glib/tests/serialize-simple.c index 6d456af..11f39b9 100644 --- a/json-glib/tests/serialize-simple.c +++ b/json-glib/tests/serialize-simple.c @@ -146,8 +146,7 @@ test_serialize (void) g_assert_cmpint (len, >, 0); g_assert_cmpint (len, ==, strlen (data)); - if (g_test_verbose ()) - g_print ("TestObject:\n%s\n", data); + g_test_message ("TestObject: %s", data); g_free (data); g_object_unref (obj); |