summaryrefslogtreecommitdiff
path: root/testsuite/gtk/flowbox.c
blob: 0a7752d5d343c20eb7b9b30e222f7880091597da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <gtk/gtk.h>

static gboolean
main_loop_quit_cb (gpointer data)
{
  gboolean *done = data;

  *done = TRUE;

  g_main_context_wakeup (NULL);

  return FALSE;
}

static void
show_and_wait (GtkWidget *widget)
{
  gboolean done = FALSE;

  g_timeout_add (500, main_loop_quit_cb, &done);
  gtk_widget_set_visible (widget, TRUE);
  while (!done)
    g_main_context_iteration (NULL, FALSE);
}

/* this was triggering a crash in gtk_flow_box_measure(),
 * see #2702
 */
static void
test_measure_crash (void)
{
  GtkWidget *window, *box, *child;

  window = gtk_window_new ();
  box = gtk_flow_box_new ();
  gtk_widget_set_valign (GTK_WIDGET (box), GTK_ALIGN_START);
  child = g_object_new (GTK_TYPE_FLOW_BOX_CHILD,
                        "css-name", "nopadding",
                        NULL);
  gtk_flow_box_insert (GTK_FLOW_BOX (box), child, -1);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_VERTICAL);
  gtk_flow_box_set_row_spacing (GTK_FLOW_BOX (box), 0);

  gtk_window_set_child (GTK_WINDOW (window), box);

  show_and_wait (window);

  gtk_window_destroy (GTK_WINDOW (window));
}

int
main (int argc, char *argv[])
{
  gtk_test_init (&argc, &argv);

  g_test_add_func ("/flowbox/measure-crash", test_measure_crash);

  return g_test_run ();
}