]> Pileus Git - ~andy/gtk/blob - gtk/tests/action.c
filechooserbutton: Update the combo box even after the dialog is cancelled
[~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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <gtk/gtk.h>
20
21 /* Fixture */
22
23 typedef struct
24 {
25   GtkAction *action;
26 } ActionTest;
27
28 static void
29 action_test_setup (ActionTest    *fixture,
30                    gconstpointer  test_data)
31 {
32   fixture->action = gtk_action_new ("name", "label", NULL, NULL);
33 }
34
35 static void
36 action_test_teardown (ActionTest    *fixture,
37                       gconstpointer  test_data)
38 {
39   g_object_unref (fixture->action);
40 }
41
42 static void
43 notify_count_emmisions (GObject    *object,
44                         GParamSpec *pspec,
45                         gpointer    data)
46 {
47   unsigned int *i = data;
48   (*i)++;
49 }
50
51 static void
52 menu_item_label_notify_count (ActionTest    *fixture,
53                               gconstpointer  test_data)
54 {
55   GtkWidget *item = gtk_menu_item_new ();
56   unsigned int emmisions = 0;
57
58   g_object_ref_sink (item);
59   g_signal_connect (item, "notify::label",
60                     G_CALLBACK (notify_count_emmisions), &emmisions);
61
62   gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item),
63                                          fixture->action);
64
65   g_assert_cmpuint (emmisions, ==, 1);
66
67   gtk_action_set_label (fixture->action, "new label");
68
69   g_assert_cmpuint (emmisions, ==, 2);
70
71   g_object_unref (item);
72 }
73
74 /* main */
75
76 int
77 main (int    argc,
78       char **argv)
79 {
80   gtk_test_init (&argc, &argv, NULL);
81
82   g_test_add ("/Action/MenuItem/label-notify-count",
83               ActionTest, NULL,
84               action_test_setup,
85               menu_item_label_notify_count,
86               action_test_teardown);
87
88   return g_test_run ();
89 }
90