]> Pileus Git - ~andy/gtk/blob - gtk/tests/action.c
Don't unref floating menuitems
[~andy/gtk] / gtk / tests / action.c
1 /* GtkAction tests.
2  *
3  * Authors: Jan Arne Petersen <jpetersen@openismus.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <gtk/gtk.h>
22
23 /* Fixture */
24
25 typedef struct
26 {
27   GtkAction *action;
28 } ActionTest;
29
30 static void
31 action_test_setup (ActionTest    *fixture,
32                    gconstpointer  test_data)
33 {
34   fixture->action = gtk_action_new ("name", "label", NULL, NULL);
35 }
36
37 static void
38 action_test_teardown (ActionTest    *fixture,
39                       gconstpointer  test_data)
40 {
41   g_object_unref (fixture->action);
42 }
43
44 static void
45 notify_count_emmisions (GObject    *object,
46                         GParamSpec *pspec,
47                         gpointer    data)
48 {
49   unsigned int *i = data;
50   (*i)++;
51 }
52
53 static void
54 menu_item_label_notify_count (ActionTest    *fixture,
55                               gconstpointer  test_data)
56 {
57   GtkWidget *item = gtk_menu_item_new ();
58   unsigned int emmisions = 0;
59
60   g_object_ref_sink (item);
61   g_signal_connect (item, "notify::label",
62                     G_CALLBACK (notify_count_emmisions), &emmisions);
63
64   gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item),
65                                          fixture->action);
66
67   g_assert_cmpuint (emmisions, ==, 1);
68
69   gtk_action_set_label (fixture->action, "new label");
70
71   g_assert_cmpuint (emmisions, ==, 2);
72
73   g_object_unref (item);
74 }
75
76 /* main */
77
78 int
79 main (int    argc,
80       char **argv)
81 {
82   gtk_test_init (&argc, &argv, NULL);
83
84   g_test_add ("/Action/MenuItem/label-notify-count",
85               ActionTest, NULL,
86               action_test_setup,
87               menu_item_label_notify_count,
88               action_test_teardown);
89
90   return g_test_run ();
91 }
92