[librsvg: 1/2] tests: Use more specific variants of g_assert()



commit 59ba523c88f1e0d91bf0bf657f97a21deb7ddd2f
Author: Sven Neumann <sven svenfoo org>
Date:   Thu Jan 30 19:53:57 2020 +0100

    tests: Use more specific variants of g_assert()

 tests/api.c        | 236 +++++++++++++++++++++++++++--------------------------
 tests/errors.c     |  11 +--
 tests/loading.c    |  11 +--
 tests/rsvg-test.c  |  86 +++++++++----------
 tests/test-utils.c |  31 +++----
 5 files changed, 185 insertions(+), 190 deletions(-)
---
diff --git a/tests/api.c b/tests/api.c
index 9a72cbd4..ffe1b210 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -59,7 +59,7 @@ flags_registration (void)
     g_assert (G_FLAGS_CLASS_TYPE (type_class) == ty);
 
     flags_class = G_FLAGS_CLASS (type_class);
-    g_assert (flags_class->n_values == 3);
+    g_assert_cmpint (flags_class->n_values, ==, 3);
 
     g_assert (flags_value_matches(&flags_class->values[0],
                                   RSVG_HANDLE_FLAGS_NONE,
@@ -114,7 +114,7 @@ error_registration (void)
     g_assert (G_ENUM_CLASS_TYPE (type_class) == ty);
 
     enum_class = G_ENUM_CLASS (type_class);
-    g_assert (enum_class->n_values == 1);
+    g_assert_cmpint (enum_class->n_values, ==, 1);
 
     g_assert (enum_value_matches (&enum_class->values[0],
                                   RSVG_ERROR_FAILED,
@@ -234,7 +234,8 @@ static const PixbufTest pixbuf_tests[] = {
 };
 
 static void
-test_pixbuf (gconstpointer data) {
+test_pixbuf (gconstpointer data)
+{
     const PixbufTest *test = data;
 
     char *filename = get_test_filename ("example.svg");
@@ -244,8 +245,8 @@ test_pixbuf (gconstpointer data) {
 
     g_free (filename);
 
-    g_assert (pixbuf != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (pixbuf);
+    g_assert_no_error (error);
     g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, test->expected_width);
     g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, test->expected_height);
 
@@ -261,9 +262,9 @@ noops (void)
     rsvg_cleanup ();
 
     /* Just test that these are in the binary */
-    g_assert (rsvg_handle_get_title != NULL);
-    g_assert (rsvg_handle_get_desc != NULL);
-    g_assert (rsvg_handle_get_metadata != NULL);
+    g_assert_nonnull (rsvg_handle_get_title);
+    g_assert_nonnull (rsvg_handle_get_desc);
+    g_assert_nonnull (rsvg_handle_get_metadata);
 }
 
 static void
@@ -277,8 +278,8 @@ set_dpi (void)
     rsvg_set_default_dpi (100.0);
 
     handle = rsvg_handle_new_from_file (filename, &error);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     rsvg_handle_get_dimensions (handle, &dim);
     g_assert_cmpint (dim.width,  ==, 100);
@@ -291,8 +292,8 @@ set_dpi (void)
     g_object_unref (handle);
 
     handle = rsvg_handle_new_from_file (filename, &error);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     rsvg_handle_set_dpi_x_y (handle, 400.0, 300.0);
     rsvg_handle_get_dimensions (handle, &dim);
@@ -310,7 +311,7 @@ base_uri (void)
     const char *uri;
 
     uri = rsvg_handle_get_base_uri (handle);
-    g_assert (uri == NULL);
+    g_assert_null (uri);
 
     rsvg_handle_set_base_uri (handle, "file:///foo/bar.svg");
     uri = rsvg_handle_get_base_uri (handle);
@@ -328,7 +329,7 @@ base_gfile (void)
     const char *uri;
 
     uri = rsvg_handle_get_base_uri (handle);
-    g_assert (uri == NULL);
+    g_assert_null (uri);
 
     file = g_file_new_for_uri ("file:///foo/bar.svg");
 
@@ -353,18 +354,18 @@ handle_write_close_free (void)
     g_assert (g_file_get_contents (filename, &data, &length, &error));
     g_free (filename);
 
-    g_assert (data != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (data);
+    g_assert_no_error (error);
 
     RsvgHandle *handle = rsvg_handle_new_with_flags (RSVG_HANDLE_FLAGS_NONE);
 
     for (i = 0; i < length; i++) {
         g_assert (rsvg_handle_write (handle, (guchar *) &data[i], 1, &error));
-        g_assert (error == NULL);
+        g_assert_no_error (error);
     }
 
     g_assert (rsvg_handle_close (handle, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     rsvg_handle_free (handle);
     g_free (data);
@@ -382,13 +383,13 @@ handle_new_from_file (void)
     /* rsvg_handle_new_from_file() can take both filenames and URIs */
 
     handle = rsvg_handle_new_from_file (filename, &error);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
     g_object_unref (handle);
 
     handle = rsvg_handle_new_from_file (uri, &error);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
     g_object_unref (handle);
 
     g_free (filename);
@@ -406,12 +407,12 @@ handle_new_from_data (void)
     g_assert (g_file_get_contents (filename, &data, &length, &error));
     g_free (filename);
 
-    g_assert (data != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (data);
+    g_assert_no_error (error);
 
     RsvgHandle *handle = rsvg_handle_new_from_data ((guint8 *) data, length, &error);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     g_object_unref (handle);
     g_free (data);
@@ -423,7 +424,7 @@ handle_new_from_gfile_sync (void)
     char *filename = get_test_filename ("dpi.svg");
     GError *error = NULL;
     GFile *file = g_file_new_for_path (filename);
-    g_assert (file != NULL);
+    g_assert_nonnull (file);
 
     g_free (filename);
 
@@ -432,8 +433,8 @@ handle_new_from_gfile_sync (void)
                                                           NULL,
                                                           &error);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     g_object_unref (handle);
     g_object_unref (file);
@@ -445,13 +446,13 @@ handle_new_from_stream_sync (void)
     char *filename = get_test_filename ("dpi.svg");
     GError *error = NULL;
     GFile *file = g_file_new_for_path (filename);
-    g_assert (file != NULL);
+    g_assert_nonnull (file);
 
     g_free (filename);
 
     GFileInputStream *stream = g_file_read (file, NULL, &error);
     g_assert (stream != NULL);
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     RsvgHandle *handle = rsvg_handle_new_from_stream_sync (G_INPUT_STREAM (stream),
                                                            file,
@@ -459,8 +460,8 @@ handle_new_from_stream_sync (void)
                                                            NULL,
                                                            &error);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     g_object_unref (handle);
     g_object_unref (file);
@@ -473,18 +474,18 @@ handle_read_stream_sync (void)
     char *filename = get_test_filename ("dpi.svg");
     GError *error = NULL;
     GFile *file = g_file_new_for_path (filename);
-    g_assert (file != NULL);
+    g_assert_nonnull (file);
 
     g_free (filename);
 
     GFileInputStream *stream = g_file_read (file, NULL, &error);
-    g_assert (stream != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (stream);
+    g_assert_no_error (error);
 
     RsvgHandle *handle = rsvg_handle_new ();
 
     g_assert (rsvg_handle_read_stream_sync (handle, G_INPUT_STREAM (stream), NULL, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     g_object_unref (handle);
     g_object_unref (file);
@@ -500,8 +501,8 @@ handle_has_sub (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     g_assert (rsvg_handle_has_sub (handle, EXAMPLE_ONE_ID));
     g_assert (rsvg_handle_has_sub (handle, EXAMPLE_TWO_ID));
@@ -519,8 +520,8 @@ test_get_pixbuf (gboolean sub)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     GdkPixbuf *pixbuf;
     if (sub) {
@@ -529,7 +530,7 @@ test_get_pixbuf (gboolean sub)
         pixbuf = rsvg_handle_get_pixbuf (handle);
     }
 
-    g_assert (pixbuf != NULL);
+    g_assert_nonnull (pixbuf);
 
     /* Note that rsvg_handle_get_pixbuf_sub() creates a surface the size of the
      * whole SVG, not just the size of the sub-element.
@@ -543,9 +544,9 @@ test_get_pixbuf (gboolean sub)
 
     g_object_unref (pixbuf);
 
-    g_assert (surface_a != NULL);
-    g_assert (surface_b != NULL);
-    g_assert (surface_diff != NULL);
+    g_assert_nonnull (surface_a);
+    g_assert_nonnull (surface_b);
+    g_assert_nonnull (surface_diff);
 
     cairo_t *cr = cairo_create (surface_b);
     if (sub) {
@@ -590,8 +591,8 @@ dimensions_and_position (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     RsvgDimensionData dim;
 
@@ -604,13 +605,14 @@ dimensions_and_position (void)
     g_assert_cmpint (pos.x, ==, EXAMPLE_TWO_X);
     g_assert_cmpint (pos.y, ==, EXAMPLE_TWO_Y);
 
-    g_assert (!rsvg_handle_get_position_sub (handle, &pos, EXAMPLE_NONEXISTENT_ID));
-    g_assert (!rsvg_handle_get_dimensions_sub (handle, &dim, EXAMPLE_NONEXISTENT_ID));
+    g_assert_false (rsvg_handle_get_position_sub (handle, &pos, EXAMPLE_NONEXISTENT_ID));
+    g_assert_false (rsvg_handle_get_dimensions_sub (handle, &dim, EXAMPLE_NONEXISTENT_ID));
 
     g_object_unref (handle);
 }
 
-struct size_func_data {
+struct size_func_data
+{
     gboolean called;
     gboolean destroyed;
     gboolean testing_size_func_calls;
@@ -622,10 +624,10 @@ size_func (gint *width, gint *height, gpointer user_data)
     struct size_func_data *data = user_data;
 
     if (data->testing_size_func_calls) {
-        g_assert (!data->called);
+        g_assert_false (data->called);
         data->called = TRUE;
 
-        g_assert (!data->destroyed);
+        g_assert_false (data->destroyed);
     }
 
     *width = 42;
@@ -638,7 +640,7 @@ size_func_destroy (gpointer user_data)
     struct size_func_data *data = user_data;
 
     if (data->testing_size_func_calls) {
-        g_assert (!data->destroyed);
+        g_assert_false (data->destroyed);
         data->destroyed = TRUE;
     }
 }
@@ -655,8 +657,8 @@ set_size_callback (void)
     handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     data.called = FALSE;
     data.destroyed = FALSE;
@@ -670,8 +672,8 @@ set_size_callback (void)
 
     g_object_unref (handle);
 
-    g_assert (data.called);
-    g_assert (data.destroyed);
+    g_assert_true (data.called);
+    g_assert_true (data.destroyed);
 }
 
 static void
@@ -686,8 +688,8 @@ reset_size_callback (void)
     handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     data_1.called = FALSE;
     data_1.destroyed = FALSE;
@@ -700,11 +702,11 @@ reset_size_callback (void)
     data_2.testing_size_func_calls = TRUE;
 
     rsvg_handle_set_size_callback (handle, size_func, &data_2, size_func_destroy);
-    g_assert (data_1.destroyed);
+    g_assert_true (data_1.destroyed);
 
     g_object_unref (handle);
 
-    g_assert (data_2.destroyed);
+    g_assert_true (data_2.destroyed);
 }
 
 static void
@@ -735,15 +737,15 @@ render_with_zero_size_callback (void)
     handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     rsvg_handle_set_size_callback (handle, zero_size_func, NULL, NULL);
 
     pixbuf = rsvg_handle_get_pixbuf (handle);
-    g_assert (pixbuf != NULL);
-    g_assert (gdk_pixbuf_get_width (pixbuf) == 1);
-    g_assert (gdk_pixbuf_get_height (pixbuf) == 1);
+    g_assert_nonnull (pixbuf);
+    g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, 1);
+    g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, 1);
 
     g_object_unref (pixbuf);
     g_object_unref (handle);
@@ -764,23 +766,23 @@ get_pixbuf_with_size_callback (void)
     rsvg_handle_set_size_callback (handle, pixbuf_size_func, NULL, NULL);
 
     char *filename = get_test_filename ("example.svg");
-    guchar *data;
+    guchar *data = NULL;
     gsize length;
     GError *error = NULL;
 
     g_assert (g_file_get_contents (filename, (gchar **) &data, &length, &error));
-    g_assert (data != NULL);
+    g_assert_nonnull (data);
 
     g_free (filename);
 
     g_assert (rsvg_handle_write (handle, data, length, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     g_assert (rsvg_handle_close (handle, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     GdkPixbuf *pixbuf = rsvg_handle_get_pixbuf (handle);
-    g_assert (pixbuf != NULL);
+    g_assert_nonnull (pixbuf);
     g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, 420);
     g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, 430);
 
@@ -797,14 +799,16 @@ detects_cairo_context_in_error (void)
         GError *error = NULL;
 
         RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
-        g_assert (handle != NULL);
-        g_assert (error == NULL);
+        g_free (filename);
+
+        g_assert_nonnull (handle);
+        g_assert_no_error (error);
 
         /* this is wrong; it is to simulate creating a surface and a cairo_t in error */
         cairo_surface_t *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, -1, -1);
         cairo_t *cr = cairo_create (surf);
         /* rsvg_handle_render_cairo() should return FALSE when it gets a cr in an error state */
-        g_assert (!rsvg_handle_render_cairo (handle, cr));
+        g_assert_false (rsvg_handle_render_cairo (handle, cr));
 
         return;
     }
@@ -838,8 +842,8 @@ can_draw_to_non_image_surface (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     rect.x = 0.0;
     rect.y = 0.0;
@@ -882,8 +886,8 @@ render_cairo_sub (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     cairo_surface_t *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 200, 200);
     cairo_t *cr = cairo_create (surf);
@@ -914,8 +918,8 @@ get_intrinsic_dimensions (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     gboolean has_width;
     RsvgLength width;
@@ -952,8 +956,8 @@ render_document (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     cairo_surface_t *output = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 150, 150);
     cairo_t *cr = cairo_create (output);
@@ -961,7 +965,7 @@ render_document (void)
     RsvgRectangle viewport = { 50.0, 50.0, 50.0, 50.0 };
 
     g_assert (rsvg_handle_render_document (handle, cr, &viewport, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     cairo_destroy (cr);
 
@@ -998,23 +1002,22 @@ get_geometry_for_layer (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     RsvgRectangle viewport = { 0.0, 0.0, 100.0, 400.0 };
     RsvgRectangle ink_rect;
     RsvgRectangle logical_rect;
 
-    g_assert (!rsvg_handle_get_geometry_for_layer (handle, "#nonexistent", &viewport,
-                                                   &ink_rect, &logical_rect, &error));
-    g_assert (error != NULL);
+    g_assert_false (rsvg_handle_get_geometry_for_layer (handle, "#nonexistent", &viewport,
+                                                        &ink_rect, &logical_rect, &error));
+    g_assert_nonnull (error);
 
-    g_error_free (error);
-    error = NULL;
+    g_clear_error (&error);
 
     g_assert (rsvg_handle_get_geometry_for_layer (handle, "#two", &viewport,
                                                   &ink_rect, &logical_rect, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     g_assert_cmpfloat (ink_rect.x, ==, 5.0);
     g_assert_cmpfloat (ink_rect.y, ==, 195.0);
@@ -1038,8 +1041,8 @@ render_layer (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     cairo_surface_t *output = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
     cairo_t *cr = cairo_create (output);
@@ -1047,7 +1050,7 @@ render_layer (void)
     RsvgRectangle viewport = { 100.0, 100.0, 100.0, 100.0 };
 
     g_assert (rsvg_handle_render_layer (handle, cr, "#bar", &viewport, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     cairo_destroy (cr);
 
@@ -1084,22 +1087,21 @@ untransformed_element (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     RsvgRectangle ink_rect;
     RsvgRectangle logical_rect;
 
     g_assert (!rsvg_handle_get_geometry_for_element (handle, "#nonexistent",
                                                      &ink_rect, &logical_rect, &error));
-    g_assert (error != NULL);
+    g_assert_nonnull (error);
 
-    g_error_free (error);
-    error = NULL;
+    g_clear_error (&error);
 
     g_assert (rsvg_handle_get_geometry_for_element (handle, "#foo",
                                                     &ink_rect, &logical_rect, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     g_assert_cmpfloat (ink_rect.x, ==, 0.0);
     g_assert_cmpfloat (ink_rect.y, ==, 0.0);
@@ -1117,7 +1119,7 @@ untransformed_element (void)
     RsvgRectangle viewport = { 100.0, 100.0, 100.0, 100.0 };
 
     g_assert (rsvg_handle_render_element (handle, cr, "#foo", &viewport, &error));
-    g_assert (error == NULL);
+    g_assert_no_error (error);
 
     cairo_destroy (cr);
 
@@ -1157,7 +1159,7 @@ no_write_before_close (void)
     RsvgHandle *handle = rsvg_handle_new();
     GError *error = NULL;
 
-    g_assert (rsvg_handle_close (handle, &error) == FALSE);
+    g_assert_false (rsvg_handle_close (handle, &error));
     g_assert_error (error, RSVG_ERROR, RSVG_ERROR_FAILED);
     g_error_free (error);
 
@@ -1171,10 +1173,10 @@ empty_write_close (void)
     GError *error = NULL;
     guchar buf = 0;
 
-    g_assert (rsvg_handle_write (handle, &buf, 0, &error) == TRUE);
+    g_assert_true (rsvg_handle_write (handle, &buf, 0, &error));
     g_assert_no_error (error);
 
-    g_assert (rsvg_handle_close (handle, &error) == FALSE);
+    g_assert_false (rsvg_handle_close (handle, &error));
     g_assert_error (error, RSVG_ERROR, RSVG_ERROR_FAILED);
 
     g_error_free (error);
@@ -1200,10 +1202,10 @@ cannot_request_external_elements (void)
         handle = rsvg_handle_new_from_file (filename, &error);
         g_free (filename);
 
-        g_assert (handle != NULL);
-        g_assert (error == NULL);
+        g_assert_nonnull (handle);
+        g_assert_no_error (error);
 
-        g_assert (rsvg_handle_get_position_sub (handle, &pos, "dpi.svg#one") == FALSE);
+        g_assert_false (rsvg_handle_get_position_sub (handle, &pos, "dpi.svg#one"));
 
         g_object_unref (handle);
     }
@@ -1250,8 +1252,8 @@ property_dpi (void)
                   "dpi-y", &y,
                   NULL);
 
-    g_assert (x == 42.0);
-    g_assert (y == 43.0);
+    g_assert_cmpfloat (x, ==, 42.0);
+    g_assert_cmpfloat (y, ==, 43.0);
 
     g_object_unref (handle);
 }
@@ -1268,7 +1270,7 @@ property_base_uri (void)
                   "base-uri", &uri,
                   NULL);
 
-    g_assert (strcmp (uri, "file:///foo/bar.svg") == 0);
+    g_assert_cmpstr (uri, ==, "file:///foo/bar.svg");
     g_free (uri);
 
     g_object_unref (handle);
@@ -1283,8 +1285,8 @@ property_dimensions (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     int width;
     int height;
@@ -1316,8 +1318,8 @@ property_deprecated (void)
     RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     char *title;
     char *desc;
@@ -1329,9 +1331,9 @@ property_deprecated (void)
                   "metadata", &metadata,
                   NULL);
 
-    g_assert (title == NULL);
-    g_assert (desc == NULL);
-    g_assert (metadata == NULL);
+    g_assert_null (title);
+    g_assert_null (desc);
+    g_assert_null (metadata);
 
     g_object_unref (handle);
 }
diff --git a/tests/errors.c b/tests/errors.c
index e03c97ba..540a51bf 100644
--- a/tests/errors.c
+++ b/tests/errors.c
@@ -34,8 +34,8 @@ test_loading_error (gconstpointer data)
     handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
 
-    g_assert (handle == NULL);
-    g_assert (g_error_matches (error, RSVG_ERROR, RSVG_ERROR_FAILED));
+    g_assert_null (handle);
+    g_assert_error (error, RSVG_ERROR, RSVG_ERROR_FAILED);
 
     g_error_free (error);
 }
@@ -52,13 +52,14 @@ test_instancing_limit (gconstpointer data)
 
     handle = rsvg_handle_new_from_file (filename, &error);
     g_free (filename);
-    g_assert (handle != NULL);
-    g_assert (error == NULL);
+
+    g_assert_nonnull (handle);
+    g_assert_no_error (error);
 
     surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 11);
     cr = cairo_create (surf);
 
-    g_assert (!rsvg_handle_render_cairo (handle, cr));
+    g_assert_false (rsvg_handle_render_cairo (handle, cr));
 
     g_object_unref (handle);
 }
diff --git a/tests/loading.c b/tests/loading.c
index a48707b8..32a20e19 100644
--- a/tests/loading.c
+++ b/tests/loading.c
@@ -10,7 +10,8 @@
 #include "librsvg/rsvg.h"
 #include "test-utils.h"
 
-typedef struct {
+typedef struct
+{
     const char *test_name;
     const char *fixture;
     size_t buf_size;
@@ -28,7 +29,7 @@ load_n_bytes_at_a_time (gconstpointer data)
     FILE *file;
 
     file = fopen (filename, "rb");
-    g_assert (file != NULL);
+    g_assert_nonnull (file);
 
     handle = rsvg_handle_new_with_flags (RSVG_HANDLE_FLAGS_NONE);
 
@@ -40,9 +41,9 @@ load_n_bytes_at_a_time (gconstpointer data)
         num_read = fread (buf, 1, fixture_data->buf_size, file);
 
         if (num_read > 0) {
-            g_assert (rsvg_handle_write (handle, buf, num_read, NULL) != FALSE);
+            g_assert_true (rsvg_handle_write (handle, buf, num_read, NULL));
         } else {
-            g_assert (ferror (file) == 0);
+            g_assert_cmpint (ferror (file), ==, 0);
 
             if (feof (file)) {
                 done = TRUE;
@@ -53,7 +54,7 @@ load_n_bytes_at_a_time (gconstpointer data)
     fclose (file);
     g_free (filename);
 
-    g_assert (rsvg_handle_close (handle, NULL) != FALSE);
+    g_assert_true (rsvg_handle_close (handle, NULL));
 
     g_object_unref (handle);
 
diff --git a/tests/rsvg-test.c b/tests/rsvg-test.c
index ddda19cc..4f935bb1 100644
--- a/tests/rsvg-test.c
+++ b/tests/rsvg-test.c
@@ -43,7 +43,8 @@
 static char *_output_dir;
 
 static char *
-get_output_dir (void) {
+get_output_dir (void)
+{
     if (_output_dir == NULL) {
        char *cwd = g_get_current_dir ();
         _output_dir = g_strconcat (cwd, G_DIR_SEPARATOR_S, "output", NULL);
@@ -57,18 +58,18 @@ static char *
 get_output_file (const char *test_file,
                  const char *extension)
 {
-  const char *output_dir = get_output_dir ();
-  char *result, *base;
+    const char *output_dir = get_output_dir ();
+    char *result, *base;
 
-  base = g_path_get_basename (test_file);
+    base = g_path_get_basename (test_file);
 
-  if (g_str_has_suffix (base, ".svg"))
-    base[strlen (base) - strlen (".svg")] = '\0';
+    if (g_str_has_suffix (base, ".svg"))
+       base[strlen (base) - strlen (".svg")] = '\0';
 
-  result = g_strconcat (output_dir, G_DIR_SEPARATOR_S, base, extension, NULL);
-  g_free (base);
+    result = g_strconcat (output_dir, G_DIR_SEPARATOR_S, base, extension, NULL);
+    g_free (base);
 
-  return result;
+    return result;
 }
 
 static void
@@ -76,12 +77,12 @@ save_image (cairo_surface_t *surface,
             const char      *test_name,
             const char      *extension)
 {
-  char *filename = get_output_file (test_name, extension);
+    char *filename = get_output_file (test_name, extension);
 
-  g_test_message ("Storing test result image at %s", filename);
-  g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS);
+    g_test_message ("Storing test result image at %s", filename);
+    g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS);
 
-  g_free (filename);
+    g_free (filename);
 }
 
 static gboolean
@@ -97,11 +98,11 @@ is_svg_or_subdir (GFile *file)
     ignore = g_str_has_prefix (basename, "ignore") || strcmp (basename, "resources") == 0;
 
     if (ignore)
-       goto out;
+       goto out;
 
     if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY) {
-       result = TRUE;
-       goto out;
+       result = TRUE;
+       goto out;
     }
 
     result = g_str_has_suffix (basename, ".svg");
@@ -118,39 +119,39 @@ read_from_stream (void          *stream,
                   unsigned int   length)
 
 {
-  gssize result;
-  GError *error = NULL;
+    gssize result;
+    GError *error = NULL;
 
-  result = g_input_stream_read (stream, data, length, NULL, &error);
-  g_assert_no_error (error);
-  g_assert (result == length);
+    result = g_input_stream_read (stream, data, length, NULL, &error);
+    g_assert_no_error (error);
+    g_assert_cmpint (result, ==, length);
 
-  return CAIRO_STATUS_SUCCESS;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_surface_t *
 read_png (const char *test_name)
 {
-  char *reference_uri;
-  GFileInputStream *stream;
-  GFile *file;
-  GError *error = NULL;
-  cairo_surface_t *surface;
+    char *reference_uri = NULL;
+    GFileInputStream *stream;
+    GFile *file;
+    GError *error = NULL;
+    cairo_surface_t *surface;
 
-  reference_uri = g_strconcat (test_name, "-ref.png", NULL);
-  file = g_file_new_for_uri (reference_uri);
-  g_free (reference_uri);
+    reference_uri = g_strconcat (test_name, "-ref.png", NULL);
+    file = g_file_new_for_uri (reference_uri);
+    g_free (reference_uri);
 
-  stream = g_file_read (file, NULL, &error);
-  g_assert_no_error (error);
-  g_assert (stream);
+    stream = g_file_read (file, NULL, &error);
+    g_assert_no_error (error);
+    g_assert_nonnull (stream);
 
-  surface = cairo_image_surface_create_from_png_stream (read_from_stream, stream);
+    surface = cairo_image_surface_create_from_png_stream (read_from_stream, stream);
 
-  g_object_unref (stream);
-  g_object_unref (file);
+    g_object_unref (stream);
+    g_object_unref (file);
 
-  return surface;
+    return surface;
 }
 
 static cairo_surface_t *
@@ -221,7 +222,7 @@ rsvg_cairo_check (gconstpointer data)
     cairo_surface_t *render_surface;
     cairo_surface_t *surface_a, *surface_b, *surface_diff;
     TestUtilsBufferDiffResult result;
-    char *test_file_base;
+    char *test_file_base = NULL;
     unsigned int width_a, height_a, stride_a;
     unsigned int width_b, height_b, stride_b;
     GError *error = NULL;
@@ -232,7 +233,7 @@ rsvg_cairo_check (gconstpointer data)
 
     rsvg = rsvg_handle_new_from_gfile_sync (test_file, 0, NULL, &error);
     g_assert_no_error (error);
-    g_assert (rsvg != NULL);
+    g_assert_nonnull (rsvg);
 
     rsvg_handle_internal_set_testing (rsvg, TRUE);
 
@@ -241,8 +242,8 @@ rsvg_cairo_check (gconstpointer data)
     else
       rsvg_handle_set_dpi_x_y (rsvg, 72.0, 72.0);
     rsvg_handle_get_dimensions (rsvg, &dimensions);
-    g_assert (dimensions.width > 0);
-    g_assert (dimensions.height > 0);
+    g_assert_cmpint (dimensions.width, >, 0);
+    g_assert_cmpint (dimensions.height, >, 0);
 
     render_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                                 dimensions.width + 2 * FRAME_SIZE,
@@ -273,7 +274,7 @@ rsvg_cairo_check (gconstpointer data)
        stride_a != stride_b) {
         g_test_fail ();
         g_test_message ("Image size mismatch (%dx%d != %dx%d)\n",
-                        width_a, height_a, width_b, height_b); 
+                        width_a, height_a, width_b, height_b);
     }
     else {
 #ifdef __x86_64__
@@ -351,4 +352,3 @@ main (int argc, char **argv)
 
     return result;
 }
-
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 847703b5..5dc20e1f 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -224,9 +224,7 @@ test_utils_get_test_data_path (void)
     if (data_path)
         return data_path;
 
-    data_path = g_build_filename (g_test_get_dir (G_TEST_DIST),
-                                  "fixtures",
-                                  NULL);
+    data_path = g_test_build_filename (G_TEST_DIST, "fixtures", NULL);
 
     return data_path;
 }
@@ -234,15 +232,10 @@ test_utils_get_test_data_path (void)
 static int
 compare_files (gconstpointer a, gconstpointer b)
 {
-    GFile *file1 = G_FILE (a);
-    GFile *file2 = G_FILE (b);
-    char *uri1, *uri2;
-    int result;
+    char *uri1 = g_file_get_uri (G_FILE(a));
+    char *uri2 = g_file_get_uri (G_FILE(b));
 
-    uri1 = g_file_get_uri (file1);
-    uri2 = g_file_get_uri (file2);
-
-    result = strcmp (uri1, uri2);
+    int result = strcmp (uri1, uri2);
 
     g_free (uri1);
     g_free (uri2);
@@ -259,10 +252,9 @@ test_utils_add_test_for_all_files (const gchar   *prefix,
 {
     GFileEnumerator *enumerator;
     GFileInfo *info;
-    GList *l, *files;
+    GList *l, *files = NULL;
     GError *error = NULL;
 
-
     if (g_file_query_file_type (file, 0, NULL) != G_FILE_TYPE_DIRECTORY)
     {
         gchar *test_path;
@@ -279,13 +271,12 @@ test_utils_add_test_for_all_files (const gchar   *prefix,
         g_test_add_data_func_full (test_path, g_object_ref (file), test_func, g_object_unref);
 
         g_free (test_path);
+
         return;
     }
 
-
     enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
     g_assert_no_error (error);
-    files = NULL;
 
     while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
     {
@@ -319,10 +310,10 @@ create_font_config_for_testing (void)
 {
     const char *font_paths[] =
     {
-        "resources/Roboto-Regular.ttf",
-        "resources/Roboto-Italic.ttf",
-        "resources/Roboto-Bold.ttf",
-        "resources/Roboto-BoldItalic.ttf",
+        "Roboto-Regular.ttf",
+        "Roboto-Italic.ttf",
+        "Roboto-Bold.ttf",
+        "Roboto-BoldItalic.ttf",
     };
 
     FcConfig *config = FcConfigCreate ();
@@ -330,7 +321,7 @@ create_font_config_for_testing (void)
 
     for (i = 0; i < G_N_ELEMENTS(font_paths); i++)
     {
-        char *font_path = g_test_build_filename (G_TEST_DIST, font_paths[i], NULL);
+        char *font_path = g_test_build_filename (G_TEST_DIST, "resources", font_paths[i], NULL);
 
         if (!FcConfigAppFontAddFile (config, (const FcChar8 *) font_path))
         {


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