]> Pileus Git - ~andy/gtk/blob - tests/a11y/focus.c
1b83ea60a2b6d964327b1d30f5ea24a245f96204
[~andy/gtk] / tests / a11y / focus.c
1 /*
2  * Copyright (C) 2011 Red Hat Inc.
3  *
4  * Author:
5  *      Matthias Clasen <mclasen@redhat.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <gtk/gtk.h>
22 #include <string.h>
23 const gchar data[] =
24   "<interface>"
25   "  <object class='GtkWindow' id='window1'>"
26   "    <property name='visible'>True</property>"
27   "    <child>"
28   "      <object class='GtkBox' id='box1'>"
29   "        <property name='visible'>True</property>"
30   "        <child>"
31   "          <object class='GtkEntry' id='entry1'>"
32   "            <property name='visible'>True</property>"
33   "            <property name='text'>entry1</property>"
34   "          </object>"
35   "        </child>"
36   "        <child>"
37   "          <object class='GtkEntry' id='entry2'>"
38   "            <property name='visible'>True</property>"
39   "            <property name='text'>entry2</property>"
40   "          </object>"
41   "        </child>"
42   "      </object>"
43   "    </child>"
44   "  </object>"
45   "</interface>";
46
47 static void
48 got_active (GObject *win, GParamSpec *pspec, gpointer data)
49 {
50   gtk_main_quit ();
51 }
52
53 static void
54 test_focus_change (void)
55 {
56   GtkBuilder *builder;
57   GError *error;
58   GtkWidget *window;
59   GtkWidget *entry1;
60   GtkWidget *entry2;
61   AtkObject *wa;
62   AtkObject *ea1;
63   AtkObject *ea2;
64   GtkWidget *focus;
65   AtkStateSet *set;
66   gboolean ret;
67
68   builder = gtk_builder_new ();
69   error = NULL;
70   gtk_builder_add_from_string (builder, data, -1, &error);
71   g_assert_no_error (error);
72   window = (GtkWidget*)gtk_builder_get_object (builder, "window1");
73   entry1 = (GtkWidget*)gtk_builder_get_object (builder, "entry1");
74   entry2 = (GtkWidget*)gtk_builder_get_object (builder, "entry2");
75
76   wa = gtk_widget_get_accessible (window);
77   ea1 = gtk_widget_get_accessible (entry1);
78   ea2 = gtk_widget_get_accessible (entry2);
79
80 #if 0
81   g_signal_connect (window, "notify::is-active", G_CALLBACK (got_active), NULL);
82   gtk_widget_show (window);
83   gtk_main ();
84   g_assert (gtk_window_is_active (GTK_WINDOW (window)));
85 #endif
86
87   focus = gtk_window_get_focus (GTK_WINDOW (window));
88   g_assert (focus == entry1);
89
90   set = atk_object_ref_state_set (ea1);
91   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
92   g_assert (ret);
93   g_object_unref (set);
94   set = atk_object_ref_state_set (ea2);
95   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
96   g_assert (!ret);
97   g_object_unref (set);
98
99   gtk_widget_grab_focus (entry2);
100
101   focus = gtk_window_get_focus (GTK_WINDOW (window));
102   g_assert (focus == entry2);
103
104   set = atk_object_ref_state_set (ea1);
105   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
106   g_assert (!ret);
107   g_object_unref (set);
108   set = atk_object_ref_state_set (ea2);
109   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
110   g_assert (ret);
111   g_object_unref (set);
112
113   g_object_unref (builder);
114 }
115
116
117 int
118 main (int argc, char *argv[])
119 {
120   gtk_test_init (&argc, &argv, NULL);
121
122   g_test_add_func ("/focus/change", test_focus_change);
123
124   return g_test_run ();
125 }
126