1 #include <gtk/gtk.h>
2 
3 static gboolean
main_loop_quit_cb(gpointer data)4 main_loop_quit_cb (gpointer data)
5 {
6   gboolean *done = data;
7 
8   *done = TRUE;
9 
10   g_main_context_wakeup (NULL);
11 
12   return FALSE;
13 }
14 
15 static void
show_and_wait(GtkWidget * widget)16 show_and_wait (GtkWidget *widget)
17 {
18   gboolean done = FALSE;
19 
20   g_timeout_add (500, main_loop_quit_cb, &done);
21   gtk_widget_show (widget);
22   while (!done)
23     g_main_context_iteration (NULL, FALSE);
24 }
25 
26 /* this was triggering a crash in gtk_flow_box_measure(),
27  * see #2702
28  */
29 static void
test_measure_crash(void)30 test_measure_crash (void)
31 {
32   GtkWidget *window, *box, *child;
33 
34   window = gtk_window_new ();
35   box = gtk_flow_box_new ();
36   gtk_widget_set_valign (GTK_WIDGET (box), GTK_ALIGN_START);
37   child = g_object_new (GTK_TYPE_FLOW_BOX_CHILD,
38                         "css-name", "nopadding",
39                         NULL);
40   gtk_flow_box_insert (GTK_FLOW_BOX (box), child, -1);
41   gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_VERTICAL);
42   gtk_flow_box_set_row_spacing (GTK_FLOW_BOX (box), 0);
43 
44   gtk_window_set_child (GTK_WINDOW (window), box);
45 
46   show_and_wait (window);
47 
48   gtk_window_destroy (GTK_WINDOW (window));
49 }
50 
51 int
main(int argc,char * argv[])52 main (int argc, char *argv[])
53 {
54   gtk_test_init (&argc, &argv);
55 
56   g_test_add_func ("/flowbox/measure-crash", test_measure_crash);
57 
58   return g_test_run ();
59 }
60