summaryrefslogtreecommitdiff
path: root/testsuite/gtk/gtkapplicationwindow.c
blob: fa5f743cb60383c0c3b8e88a3774f53d405696f4 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <gtk/gtk.h>

static void
removed (GActionGroup *group,
         const gchar  *name,
         gpointer      user_data)
{
  gboolean *was_removed = user_data;

  *was_removed = TRUE;
}

static void
test_as_actiongroup (void)
{
  GSimpleAction *action;
  gboolean was_removed;
  gpointer window;
  gchar **list;

  /* do a dummy round... */
  window = g_object_ref_sink (g_object_new (GTK_TYPE_APPLICATION_WINDOW, NULL));
  gtk_widget_destroy (window);
  g_object_unref (window);

  /* create a window, add an action */
  window = g_object_ref_sink (g_object_new (GTK_TYPE_APPLICATION_WINDOW, NULL));
  action = g_simple_action_new ("foo", NULL);
  g_action_map_add_action (window, G_ACTION (action));
  g_object_unref (action);

  /* check which actions we have in the group */
  list = g_action_group_list_actions (window);
  g_assert_cmpstr (list[0], ==, "foo");
  g_assert_cmpstr (list[1], ==, NULL);
  g_strfreev (list);

  /* make sure that destroying the window keeps our view of the actions
   * consistent.
   */
  g_signal_connect (window, "action-removed", G_CALLBACK (removed), &was_removed);
  gtk_widget_destroy (window);

  /* One of two things will have happened, depending on the
   * implementation.  Both are valid:
   *
   *  - we received a signal that the action was removed when we
   *    destroyed the window; or
   *
   *  - the action is still available.
   *
   * Make sure we're in one of those states.
   *
   * This additionally ensures that calling into methods on the window
   * will continue to work after it has been destroy (and not segfault).
   */
  list = g_action_group_list_actions (window);

  if (was_removed == FALSE)
    {
      /* should still be here */
      g_assert_cmpstr (list[0], ==, "foo");
      g_assert_cmpstr (list[1], ==, NULL);
    }
  else
    /* should be gone */
    g_assert_cmpstr (list[0], ==, NULL);

  g_object_unref (window);
  g_strfreev (list);
}

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

  g_test_add_func ("/gtkapplicationwindow/as-actiongroup", test_as_actiongroup);

  return g_test_run ();
}