From 03db2690e23cf0ef4e383d28729f79b12a5c83c1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Apr 2021 08:16:45 -0400 Subject: [PATCH 1/3] testsuite: Reduce use of g_assert Stop using g_assert() in the gdk tests. --- testsuite/gdk/arrayimpl.c | 2 +- testsuite/gdk/display.c | 12 ++++----- testsuite/gdk/encoding.c | 4 +-- testsuite/gdk/rgba.c | 52 +++++++++++++++++++-------------------- testsuite/gdk/seat.c | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/testsuite/gdk/arrayimpl.c b/testsuite/gdk/arrayimpl.c index 3c3ebb992d..ce44598ac3 100644 --- a/testsuite/gdk/arrayimpl.c +++ b/testsuite/gdk/arrayimpl.c @@ -67,7 +67,7 @@ gdk_array(test_splice) (void) gsize old_size = gdk_array(get_size) (&v); pos = g_random_int_range (0, old_size + 1); - g_assert (pos <= old_size); + g_assert_true (pos <= old_size); remove = g_random_int_range (0, 4); remove = MIN (remove, old_size - pos); add = g_random_int_range (0, 4); diff --git a/testsuite/gdk/display.c b/testsuite/gdk/display.c index c5b3b1641a..1cda169a5b 100644 --- a/testsuite/gdk/display.c +++ b/testsuite/gdk/display.c @@ -9,10 +9,10 @@ test_unset_display_subprocess1 (void) g_unsetenv ("DISPLAY"); - g_assert (!gtk_init_check ()); + g_assert_false (gtk_init_check ()); manager = gdk_display_manager_get (); - g_assert (manager != NULL); - g_assert (gdk_display_manager_get_default_display (manager) == NULL); + g_assert_nonnull (manager); + g_assert_null (gdk_display_manager_get_default_display (manager)); } static void @@ -41,10 +41,10 @@ test_bad_display_subprocess1 (void) g_setenv ("DISPLAY", "poo", TRUE); - g_assert (!gtk_init_check ()); + g_assert_false (gtk_init_check ()); manager = gdk_display_manager_get (); - g_assert (manager != NULL); - g_assert (gdk_display_manager_get_default_display (manager) == NULL); + g_assert_nonnull (manager); + g_assert_null (gdk_display_manager_get_default_display (manager)); } static void diff --git a/testsuite/gdk/encoding.c b/testsuite/gdk/encoding.c index 40ef8ae9e0..53b23aaeee 100644 --- a/testsuite/gdk/encoding.c +++ b/testsuite/gdk/encoding.c @@ -26,8 +26,8 @@ test_to_text_list (void) length = 25; n = gdk_x11_display_text_property_to_text_list (display, encoding, format, text, length, &list); g_assert_cmpint (n, ==, 2); - g_assert (g_str_has_prefix (list[0], "abcdef ")); - g_assert (g_str_has_prefix (list[1], "ABCDEF ")); + g_assert_true (g_str_has_prefix (list[0], "abcdef ")); + g_assert_true (g_str_has_prefix (list[1], "ABCDEF ")); gdk_x11_free_text_list (list); } diff --git a/testsuite/gdk/rgba.c b/testsuite/gdk/rgba.c index 26a94655e2..e92fd04c41 100644 --- a/testsuite/gdk/rgba.c +++ b/testsuite/gdk/rgba.c @@ -9,62 +9,62 @@ test_color_parse (void) gboolean res; res = gdk_rgba_parse (&color, "foo"); - g_assert (!res); + g_assert_true (!res); res = gdk_rgba_parse (&color, ""); - g_assert (!res); + g_assert_true (!res); expected.red = 100/255.; expected.green = 90/255.; expected.blue = 80/255.; expected.alpha = 0.1; res = gdk_rgba_parse (&color, "rgba(100,90,80,0.1)"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); expected.red = 0.4; expected.green = 0.3; expected.blue = 0.2; expected.alpha = 0.1; res = gdk_rgba_parse (&color, "rgba(40%,30%,20%,0.1)"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); res = gdk_rgba_parse (&color, "rgba( 40 % , 30 % , 20 % , 0.1 )"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); expected.red = 1.0; expected.green = 0.0; expected.blue = 0.0; expected.alpha = 1.0; res = gdk_rgba_parse (&color, "red"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); expected.red = 0.0; expected.green = 0x8080 / 65535.; expected.blue = 1.0; expected.alpha = 1.0; res = gdk_rgba_parse (&color, "#0080ff"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); expected.red = 0.0; expected.green = 0.0; expected.blue = 0.0; expected.alpha = 1.0; res = gdk_rgba_parse (&color, "rgb(0,0,0)"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); expected.red = 0.0; expected.green = 0x8080 / 65535.; expected.blue = 1.0; expected.alpha = 0x8888 / 65535.; res = gdk_rgba_parse (&color, "#0080ff88"); - g_assert (res); - g_assert (gdk_rgba_equal (&color, &expected)); + g_assert_true (res); + g_assert_true (gdk_rgba_equal (&color, &expected)); } static void @@ -88,7 +88,7 @@ test_color_to_string (void) orig = g_strdup (setlocale (LC_ALL, NULL)); res = gdk_rgba_to_string (&rgba); gdk_rgba_parse (&out, res); - g_assert (gdk_rgba_equal (&rgba, &out)); + g_assert_true (gdk_rgba_equal (&rgba, &out)); setlocale (LC_ALL, "de_DE.utf-8"); res_de = gdk_rgba_to_string (&rgba); @@ -118,7 +118,7 @@ test_color_copy (void) rgba.alpha = 0.9; out = gdk_rgba_copy (&rgba); - g_assert (gdk_rgba_equal (&rgba, out)); + g_assert_true (gdk_rgba_equal (&rgba, out)); gdk_rgba_free (out); } @@ -132,28 +132,28 @@ test_color_parse_nonsense (void) /*http://bugzilla.gnome.org/show_bug.cgi?id=667485 */ res = gdk_rgba_parse (&color, "rgb(,,)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(%,%,%)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(nan,nan,nan)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(inf,inf,inf)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(1p12,0,0)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(5d1%,1,1)"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(0,0,0)moo"); - g_assert (!res); + g_assert_false (res); res = gdk_rgba_parse (&color, "rgb(0,0,0) moo"); - g_assert (!res); + g_assert_false (res); } int diff --git a/testsuite/gdk/seat.c b/testsuite/gdk/seat.c index 75fd9616fd..8949350cbc 100644 --- a/testsuite/gdk/seat.c +++ b/testsuite/gdk/seat.c @@ -21,7 +21,7 @@ test_list_seats (void) seat = l->data; g_assert_true (GDK_IS_SEAT (seat)); - g_assert (gdk_seat_get_display (seat) == display); + g_assert_true (gdk_seat_get_display (seat) == display); if (seat == seat0) found_default = TRUE; From 90d187894d5d96111617fe017c41ee2ad4929b30 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Apr 2021 08:30:56 -0400 Subject: [PATCH 2/3] testsuite: Reduce use of g_assert Stop using g_assert() in the reftests. --- testsuite/reftests/gtk-reftest.c | 4 +++- testsuite/reftests/reftest-compare.c | 10 +++++----- testsuite/reftests/reftest-snapshot.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/testsuite/reftests/gtk-reftest.c b/testsuite/reftests/gtk-reftest.c index 38a2817ddf..efe48e6480 100644 --- a/testsuite/reftests/gtk-reftest.c +++ b/testsuite/reftests/gtk-reftest.c @@ -275,6 +275,7 @@ save_image (cairo_surface_t *surface, { GError *error = NULL; char *filename; + int ret; filename = get_output_file (test_name, extension, &error); if (filename == NULL) @@ -285,7 +286,8 @@ save_image (cairo_surface_t *surface, } g_test_message ("Storing test result image at %s", filename); - g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS); + ret = cairo_surface_write_to_png (surface, filename); + g_assert_true (ret == CAIRO_STATUS_SUCCESS); g_free (filename); } diff --git a/testsuite/reftests/reftest-compare.c b/testsuite/reftests/reftest-compare.c index 34285ace72..5c682e1591 100644 --- a/testsuite/reftests/reftest-compare.c +++ b/testsuite/reftests/reftest-compare.c @@ -34,9 +34,9 @@ get_surface_size (cairo_surface_t *surface, cairo_clip_extents (cr, &x1, &y1, &x2, &y2); cairo_destroy (cr); - g_assert (x1 == 0 && y1 == 0); - g_assert (x2 > 0 && y2 > 0); - g_assert ((int) x2 == x2 && (int) y2 == y2); + g_assert_true (x1 == 0 && y1 == 0); + g_assert_true (x2 > 0 && y2 > 0); + g_assert_true ((int) x2 == x2 && (int) y2 == y2); *width = x2; *height = y2; @@ -62,7 +62,7 @@ coerce_surface_for_comparison (cairo_surface_t *surface, cairo_destroy (cr); - g_assert (cairo_surface_status (coerced) == CAIRO_STATUS_SUCCESS); + g_assert_true (cairo_surface_status (coerced) == CAIRO_STATUS_SUCCESS); return coerced; } @@ -110,7 +110,7 @@ buffer_diff_core (const guchar *buf_a, diff = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); - g_assert (cairo_surface_status (diff) == CAIRO_STATUS_SUCCESS); + g_assert_true (cairo_surface_status (diff) == CAIRO_STATUS_SUCCESS); buf_diff = cairo_image_surface_get_data (diff); stride_diff = cairo_image_surface_get_stride (diff); row = (guint32 *) (buf_diff + y * stride_diff); diff --git a/testsuite/reftests/reftest-snapshot.c b/testsuite/reftests/reftest-snapshot.c index de08c0b026..7a7a77fd96 100644 --- a/testsuite/reftests/reftest-snapshot.c +++ b/testsuite/reftests/reftest-snapshot.c @@ -209,7 +209,7 @@ reftest_inhibit_snapshot (void) G_MODULE_EXPORT void reftest_uninhibit_snapshot (void) { - g_assert (inhibit_count > 0); + g_assert_true (inhibit_count > 0); inhibit_count--; } @@ -260,7 +260,7 @@ snapshot_widget (GtkWidget *widget) GdkPaintable *paintable; cairo_surface_t *surface; - g_assert (gtk_widget_get_realized (widget)); + g_assert_true (gtk_widget_get_realized (widget)); loop = g_main_loop_new (NULL, FALSE); @@ -304,7 +304,7 @@ reftest_snapshot_ui_file (const char *ui_file) g_assert_no_error (error); window = builder_get_toplevel (builder); g_object_unref (builder); - g_assert (window); + g_assert_true (window); gtk_widget_show (window); From f9fa92766bace56b3c3924840dbc4a040793a405 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Apr 2021 08:33:41 -0400 Subject: [PATCH 3/3] testsuite: Reduce use of g_assert Stop using g_assert() in the css tests. --- testsuite/css/change/test-css-change.c | 4 ++-- testsuite/css/data.c | 2 +- testsuite/css/nodes/test-css-nodes.c | 2 +- testsuite/css/style/test-css-style.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/testsuite/css/change/test-css-change.c b/testsuite/css/change/test-css-change.c index 1d60f0bcff..24650fa4c2 100644 --- a/testsuite/css/change/test-css-change.c +++ b/testsuite/css/change/test-css-change.c @@ -77,7 +77,7 @@ load_ui_file (GFile *file, gboolean generate) ui_file = g_file_get_path (file); css_file = test_get_other_file (ui_file, ".css"); - g_assert (css_file != NULL); + g_assert_nonnull (css_file); provider = gtk_css_provider_new (); gtk_css_provider_load_from_path (provider, css_file); @@ -90,7 +90,7 @@ load_ui_file (GFile *file, gboolean generate) if (window == NULL) window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); - g_assert (window != NULL); + g_assert_nonnull (window); output = NULL; diff --git a/testsuite/css/data.c b/testsuite/css/data.c index 978be0e55e..9cb3544de6 100644 --- a/testsuite/css/data.c +++ b/testsuite/css/data.c @@ -84,7 +84,7 @@ test_parse (gconstpointer data) g_assert_nonnull (bytes); g_assert_no_error (error); if (test->mimetype == NULL) - g_assert (mimetype == NULL); + g_assert_null (mimetype); else g_assert_cmpstr (mimetype, ==, test->mimetype); diff --git a/testsuite/css/nodes/test-css-nodes.c b/testsuite/css/nodes/test-css-nodes.c index a44c4e4508..d8dd50471e 100644 --- a/testsuite/css/nodes/test-css-nodes.c +++ b/testsuite/css/nodes/test-css-nodes.c @@ -80,7 +80,7 @@ load_ui_file (GFile *file, gboolean generate) builder = gtk_builder_new_from_file (ui_file); window = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); - g_assert (window != NULL); + g_assert_nonnull (window); output = NULL; g_signal_connect (window, "map", G_CALLBACK (style_context_changed), &output); diff --git a/testsuite/css/style/test-css-style.c b/testsuite/css/style/test-css-style.c index 93367fc336..68e8bfefcf 100644 --- a/testsuite/css/style/test-css-style.c +++ b/testsuite/css/style/test-css-style.c @@ -97,7 +97,7 @@ load_ui_file (GFile *file, gboolean generate) ui_file = g_file_get_path (file); css_file = test_get_other_file (ui_file, ".css"); - g_assert (css_file != NULL); + g_assert_nonnull (css_file); provider = gtk_css_provider_new (); gtk_css_provider_load_from_path (provider, css_file); @@ -108,7 +108,7 @@ load_ui_file (GFile *file, gboolean generate) builder = gtk_builder_new_from_file (ui_file); window = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); - g_assert (window != NULL); + g_assert_nonnull (window); output = NULL; g_signal_connect (window, "map", G_CALLBACK (style_context_changed), &output); @@ -125,7 +125,7 @@ load_ui_file (GFile *file, gboolean generate) } reference_file = test_get_other_file (ui_file, ".nodes"); - g_assert (reference_file != NULL); + g_assert_nonnull (reference_file); diff = diff_with_file (reference_file, output, -1, &error); g_assert_no_error (error);