Commit 0c3dd0cf authored by Matthias Clasen's avatar Matthias Clasen
Browse files

Merge branch 'testsuite-asserts' into 'master'

testsuite: Reduce the use of g_assert

Closes #3864

See merge request !3432
parents 442f4855 4164abd9
Pipeline #274211 passed with stages
in 33 minutes and 34 seconds
......@@ -751,7 +751,6 @@ demo_filter_by_name (gpointer item,
gpointer user_data)
{
GtkTreeListRow *row = item;
GtkFilterListModel *model = user_data;
GListModel *children;
GtkDemo *demo;
guint i, n;
......@@ -762,7 +761,7 @@ demo_filter_by_name (gpointer item,
return TRUE;
g_assert (GTK_IS_TREE_LIST_ROW (row));
g_assert (GTK_IS_FILTER_LIST_MODEL (model));
g_assert (GTK_IS_FILTER_LIST_MODEL (user_data));
/* Show a row if itself of any parent matches */
for (parent = row; parent; parent = gtk_tree_list_row_get_parent (parent))
......
......@@ -848,7 +848,12 @@ gdk_wayland_device_pad_get_n_groups (GdkDevicePad *pad)
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
GDK_DEVICE (pad));
#ifdef G_DISABLE_ASSERT
if (data == NULL)
return 0;
#else
g_assert (data != NULL);
#endif
return g_list_length (data->mode_groups);
}
......@@ -863,7 +868,12 @@ gdk_wayland_device_pad_get_group_n_modes (GdkDevicePad *pad,
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
GDK_DEVICE (pad));
#ifdef G_DISABLE_ASSERT
if (data == NULL)
return 0;
#else
g_assert (data != NULL);
#endif
group = g_list_nth_data (data->mode_groups, n_group);
if (!group)
......@@ -909,7 +919,12 @@ gdk_wayland_device_pad_get_feature_group (GdkDevicePad *pad,
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
GDK_DEVICE (pad));
#ifdef G_DISABLE_ASSERT
if (data == NULL)
return -1;
#else
g_assert (data != NULL);
#endif
for (l = data->mode_groups, i = 0; l; l = l->next, i++)
{
......@@ -4236,7 +4251,14 @@ tablet_pad_handle_button (void *data,
wp_tablet_pad, button, state));
group = tablet_pad_lookup_button_group (pad, button);
#ifdef G_DISABLE_ASSERT
if (group == NULL)
return;
#else
g_assert (group != NULL);
#endif
n_group = g_list_index (pad->mode_groups, group);
event = gdk_pad_event_new_button (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED
......
......@@ -58,6 +58,19 @@
#include "gdk/gdk-private.h"
/* Keep g_assert() defined even if we disable it globally,
* as we use it in many places as a handy mechanism to check
* for non-NULL
*/
#ifdef G_DISABLE_ASSERT
# undef g_assert
# define g_assert(expr) G_STMT_START { \
if G_LIKELY (expr) ; else \
g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#expr); \
} G_STMT_END
#endif
/**
* GdkWaylandDisplay:
*
......
......@@ -433,8 +433,6 @@ gsk_gl_driver_slice_texture (GskGLDriver *self,
guint *out_n_slices)
{
const int max_texture_size = gsk_gl_driver_get_max_texture_size (self) / 4; // XXX Too much?
const int tex_width = texture->width;
const int tex_height = texture->height;
const int cols = (texture->width / max_texture_size) + 1;
const int rows = (texture->height / max_texture_size) + 1;
int col, row;
......@@ -442,7 +440,7 @@ gsk_gl_driver_slice_texture (GskGLDriver *self,
TextureSlice *slices;
Texture *tex;
g_assert (tex_width > max_texture_size || tex_height > max_texture_size);
g_assert (texture->width > max_texture_size || texture->height > max_texture_size);
tex = gdk_texture_get_render_data (texture, self);
......
......@@ -1997,12 +1997,11 @@ render_unblurred_inset_shadow_node (GskGLRenderer *self,
GskRenderNode *node,
RenderOpBuilder *builder)
{
const float blur_radius = gsk_inset_shadow_node_get_blur_radius (node);
const float dx = gsk_inset_shadow_node_get_dx (node);
const float dy = gsk_inset_shadow_node_get_dy (node);
const float spread = gsk_inset_shadow_node_get_spread (node);
g_assert (blur_radius == 0);
g_assert (gsk_inset_shadow_node_get_blur_radius (node) == 0);
ops_set_program (builder, &self->programs->inset_shadow_program);
ops_set_inset_shadow (builder, transform_rect (self, builder, gsk_inset_shadow_node_get_outline (node)),
......
......@@ -246,7 +246,7 @@ gsk_ngl_texture_atlas_initialize (GskNglDriver *driver,
{
/* Insert a single pixel at 0,0 for use in coloring */
gboolean packed;
gboolean packed G_GNUC_UNUSED;
int x, y;
guint gl_format;
guint gl_type;
......
......@@ -1420,7 +1420,7 @@ gtk_at_spi_context_get_property (GObject *gobject,
static void
gtk_at_spi_context_constructed (GObject *gobject)
{
GtkAtSpiContext *self = GTK_AT_SPI_CONTEXT (gobject);
GtkAtSpiContext *self G_GNUC_UNUSED = GTK_AT_SPI_CONTEXT (gobject);
/* Make sure that we were properly constructed */
g_assert (self->bus_address);
......
......@@ -369,7 +369,7 @@ apply_response_for_action_area (GtkDialog *dialog,
GtkWidget *child,
int response_id)
{
GtkDialogPrivate *priv = gtk_dialog_get_instance_private (dialog);
GtkDialogPrivate *priv G_GNUC_UNUSED = gtk_dialog_get_instance_private (dialog);
g_assert (gtk_widget_get_parent (child) == priv->action_area);
}
......
......@@ -1935,9 +1935,9 @@ gtk_expression_watch_ref (GtkExpressionWatch *watch)
static void
gtk_expression_watch_finalize (gpointer data)
{
GtkExpressionWatch *watch = data;
GtkExpressionWatch *watch G_GNUC_UNUSED = data;
g_assert (!gtk_expression_watch_is_watching (watch));
g_assert (!gtk_expression_watch_is_watching (data));
}
/**
......
......@@ -104,7 +104,7 @@ gtk_list_item_manager_augment_node (GtkRbTree *tree,
static void
gtk_list_item_manager_clear_node (gpointer _item)
{
GtkListItemManagerItem *item = _item;
GtkListItemManagerItem *item G_GNUC_UNUSED = _item;
g_assert (item->widget == NULL);
}
......
......@@ -320,7 +320,7 @@ static void
gtk_settings_class_init (GtkSettingsClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
guint result;
guint result G_GNUC_UNUSED;
gobject_class->finalize = gtk_settings_finalize;
gobject_class->get_property = gtk_settings_get_property;
......
......@@ -882,7 +882,7 @@ gtk_signal_action_print (GtkShortcutAction *action,
static void
gtk_signal_action_constructed (GObject *gobject)
{
GtkSignalAction *self = GTK_SIGNAL_ACTION (gobject);
GtkSignalAction *self G_GNUC_UNUSED = GTK_SIGNAL_ACTION (gobject);
g_assert (self->name != NULL && self->name[0] != '\0');
......@@ -1162,7 +1162,7 @@ gtk_named_action_get_property (GObject *gobject,
static void
gtk_named_action_constructed (GObject *gobject)
{
GtkNamedAction *self = GTK_NAMED_ACTION (gobject);
GtkNamedAction *self G_GNUC_UNUSED = GTK_NAMED_ACTION (gobject);
g_assert (self->name != NULL && self->name[0] != '\0');
......
......@@ -80,7 +80,10 @@ gtk_test_init (int *argcp,
char ***argvp,
...)
{
g_test_init (argcp, argvp, NULL);
/* g_test_init is defined as a macro that aborts if assertions
* are disabled. We don't want that, so we call the function.
*/
(g_test_init) (argcp, argvp, NULL);
gtk_disable_setlocale();
setlocale (LC_ALL, "en_US.UTF-8");
......
......@@ -3513,7 +3513,7 @@ prelight_or_select (GtkTreeView *tree_view,
static void
ensure_unprelighted (GtkTreeView *tree_view)
{
GtkTreeViewPrivate *priv = gtk_tree_view_get_instance_private (tree_view);
GtkTreeViewPrivate *priv G_GNUC_UNUSED = gtk_tree_view_get_instance_private (tree_view);
do_prelight (tree_view,
NULL, NULL,
......
......@@ -903,6 +903,7 @@ update_go_buttons (GtkInspectorWindow *iw)
{
object = NULL;
kind = CHILD_KIND_OTHER;
position = 0;
}
if (parent)
......
......@@ -66,7 +66,7 @@ if debug
gtk_debug_cflags += '-DG_ENABLE_CONSISTENCY_CHECKS'
endif
elif optimization in ['2', '3', 's']
gtk_debug_cflags += '-DG_DISABLE_CAST_CHECKS -DG_DISABLE_ASSERT'
gtk_debug_cflags += ['-DG_DISABLE_CAST_CHECKS', '-DG_DISABLE_ASSERT']
endif
add_project_arguments(gtk_debug_cflags, language: 'c')
......@@ -270,7 +270,6 @@ elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
'-Wmissing-include-dirs',
'-Wmissing-noreturn',
'-Wnested-externs',
'-Wnull-dereference',
'-Wold-style-definition',
'-Wpointer-arith',
'-Wshadow',
......@@ -304,6 +303,10 @@ elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
if cc.get_id() == 'gcc'
test_cflags += ['-Wcast-align'] # This warns too much on clang
endif
if not gtk_debug_cflags.contains('-DG_DISABLE_ASSERT')
test_cflags += ['-Wnull-dereference'] # Too noisy when assertions are disabled
endif
else
test_cflags = []
endif
......
......@@ -34,13 +34,13 @@ test_error_trapping (GdkDisplay *gdk_display)
gdk_x11_display_error_trap_push (gdk_display);
XListProperties (d, 0, &dummy); /* round trip */
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadWindow);
g_assert_true (error == BadWindow);
gdk_x11_display_error_trap_push (gdk_display);
XSetCloseDownMode (d, 12345); /* not a round trip */
XSetCloseDownMode (d, DestroyAll);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
/* try the same without sync */
gdk_x11_display_error_trap_push (gdk_display);
......@@ -60,17 +60,17 @@ test_error_trapping (GdkDisplay *gdk_display)
gdk_x11_display_error_trap_push (gdk_display);
XSetCloseDownMode (d, 12345);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == Success);
g_assert_true (error == Success);
gdk_x11_display_error_trap_push (gdk_display);
XSetCloseDownMode (d, 12345);
gdk_x11_display_error_trap_push (gdk_display);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == Success);
g_assert_true (error == Success);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
/* try nested, without sync */
gdk_x11_display_error_trap_push (gdk_display);
......@@ -104,23 +104,23 @@ test_error_trapping (GdkDisplay *gdk_display)
gdk_x11_display_error_trap_push (gdk_display);
XSync (d, TRUE); /* not an error */
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == Success);
g_assert_true (error == Success);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
/* non-roundtrip non-error request after error request, inside trap */
gdk_x11_display_error_trap_push (gdk_display);
XSetCloseDownMode (d, 12345);
XMapWindow (d, DefaultRootWindow (d));
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
/* a non-roundtrip non-error request before error request, inside trap */
gdk_x11_display_error_trap_push (gdk_display);
XMapWindow (d, DefaultRootWindow (d));
XSetCloseDownMode (d, 12345);
error = gdk_x11_display_error_trap_pop (gdk_display);
g_assert (error == BadValue);
g_assert_true (error == BadValue);
/* Not part of any test, just a double-check
* that all errors have arrived
......
......@@ -105,7 +105,7 @@ main (int argc, char *argv[])
{
guint i;
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
setlocale (LC_ALL, "C");
for (i = 0; i < G_N_ELEMENTS (tests); i++)
......
......@@ -81,7 +81,7 @@ int_free_func (int data)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
setlocale (LC_ALL, "C");
g_test_add_func ("/intarray/simple", int_array_test_simple);
......
......@@ -31,7 +31,7 @@ test_set_source_big_pixbuf (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
g_test_add_func ("/drawing/set-source-big-pixbuf", test_set_source_big_pixbuf);
......
......@@ -73,7 +73,7 @@ test_clipboard_basic (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
......
......@@ -57,7 +57,7 @@ test_cursor_fallback (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
......
......@@ -68,7 +68,7 @@ test_bad_display (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gdk_set_allowed_backends ("x11");
......
......@@ -43,7 +43,7 @@ test_set_default (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
/* Open default display */
gdk_display_open (NULL);
......
......@@ -37,7 +37,7 @@ test_to_text_list (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
g_test_add_func ("/encoding/to-text-list", test_to_text_list);
......
......@@ -128,7 +128,7 @@ main (int argc, char *argv[])
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
g_test_add_func ("/keysyms/basic", test_keysyms_basic);
......
......@@ -180,7 +180,7 @@ main (int argc, char *argv[])
Color color;
GEnumClass *enum_class;
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
enum_class = g_type_class_ref (GDK_TYPE_MEMORY_FORMAT);
......
......@@ -33,7 +33,7 @@ test_format (gconstpointer d)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
g_test_add_data_func ("/pixbuf/format/png", "png", test_format);
g_test_add_data_func ("/pixbuf/format/jpeg", "jpeg", test_format);
......
......@@ -110,7 +110,7 @@ test_rectangle_contains (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
......
......@@ -159,7 +159,7 @@ test_color_parse_nonsense (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
g_test_add_func ("/rgba/parse", test_color_parse);
g_test_add_func ("/rgba/parse/nonsense", test_color_parse_nonsense);
......
......@@ -127,7 +127,7 @@ test_default_seat (void)
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
(g_test_init) (&argc, &argv, NULL);
gtk_init ();
......
......@@ -104,9 +104,11 @@ save_image (cairo_surface_t *surface,
const char *extension)
{
char *filename = get_output_file (test_name, ".node", extension);
int status;
g_print ("Storing test result image at %s\n", filename);
g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS);
status = cairo_surface_write_to_png (surface, filename);
g_assert_true (status == CAIRO_STATUS_SUCCESS);
g_free (filename);
}
......@@ -207,12 +209,12 @@ main (int argc, char **argv)
g_bytes_unref (bytes);
g_assert_no_error (error);
g_assert (node != NULL);
g_assert_nonnull (node);
}
/* Render the .node file and download to cairo surface */
texture = gsk_renderer_render_texture (renderer, node, NULL);
g_assert (texture != NULL);
g_assert_nonnull (texture);
rendered_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
gdk_texture_get_width (texture),
......
......@@ -173,7 +173,7 @@ parse_node_file (GFile *file, gboolean generate)
g_clear_error (&error);
return FALSE;
}
g_assert (bytes != NULL);
g_assert_nonnull (bytes);
errors = g_string_new ("");
......
......@@ -266,7 +266,7 @@ test_invert (void)
transform = apply_test_transform (transform, j);
transform = apply_test_transform (transform, k);
inverse = gsk_transform_invert (gsk_transform_ref (transform));
g_assert (inverse != NULL || transform == NULL);
g_assert_true (inverse != NULL || transform == NULL);
identity = gsk_transform_transform (gsk_transform_ref (transform), inverse);
graphene_assert_fuzzy_transform_equal (identity, NULL, EPSILON);
......@@ -372,6 +372,7 @@ test_print_parse (void)
GskTransform *transform, *parsed;
guint i, j, k;
char *str1, *str2;
gboolean ret;
for (i = 0; i < G_N_ELEMENTS (test_transforms); i++)
{
......@@ -384,14 +385,15 @@ test_print_parse (void)
transform = apply_test_transform (transform, k);
str1 = gsk_transform_to_string (transform);
g_assert (str1);
g_assert (strlen (str1) > 0);
g_assert_nonnull (str1);
g_assert_true (strlen (str1) > 0);
str2 = gsk_transform_to_string (transform);
g_assert_cmpstr (str1, ==, str2);
g_free (str2);
g_assert (gsk_transform_parse (str1, &parsed));
ret = gsk_transform_parse (str1, &parsed);
g_assert_true (ret);
graphene_assert_fuzzy_transform_equal (parsed, transform, EPSILON);
str2 = gsk_transform_to_string (parsed);
......
......@@ -28,31 +28,32 @@ test_one_accel (const char *accel,
GdkModifierType mods;
guint *keycodes;
char *label, *name;
gboolean ret;
accel_key = 0;
g_assert (gtk_accelerator_parse_with_keycode (accel,
gdk_display_get_default (),
&accel_key,
&keycodes,
&mods));
ret = gtk_accelerator_parse_with_keycode (accel,
gdk_display_get_default (),
&accel_key,
&keycodes,
&mods);
g_assert_true (ret);
if (has_keysym)
{
guint accel_key_2;
GdkModifierType mods_2;
g_assert (gtk_accelerator_parse (accel,
&accel_key_2,
&mods_2));
g_assert (accel_key == accel_key_2);
g_assert (mods == mods_2);
ret = gtk_accelerator_parse (accel, &accel_key_2, &mods_2);
g_assert_true (ret);
g_assert_true (accel_key == accel_key_2);
g_assert_true (mods == mods_2);
}
if (has_keysym)
g_assert (accel_key == exp_key);
g_assert (mods == exp_mods);
g_assert (keycodes);
g_assert (keycodes[0] != 0);
g_assert_true (accel_key == exp_key);
g_assert_true (mods == exp_mods);
g_assert_nonnull (keycodes);
g_assert_true (keycodes[0] != 0);