]> Pileus Git - ~andy/gtk/blob - tests/a11y/focus.c
59b58fd53c85825bf36022930968dd84164ce898
[~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, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <gtk/gtk.h>
24 #include <string.h>
25 const gchar data[] =
26   "<interface>"
27   "  <object class='GtkWindow' id='window1'>"
28   "    <property name='visible'>True</property>"
29   "    <child>"
30   "      <object class='GtkBox' id='box1'>"
31   "        <property name='visible'>True</property>"
32   "        <child>"
33   "          <object class='GtkEntry' id='entry1'>"
34   "            <property name='visible'>True</property>"
35   "            <property name='text'>entry1</property>"
36   "          </object>"
37   "        </child>"
38   "        <child>"
39   "          <object class='GtkEntry' id='entry2'>"
40   "            <property name='visible'>True</property>"
41   "            <property name='text'>entry2</property>"
42   "          </object>"
43   "        </child>"
44   "      </object>"
45   "    </child>"
46   "  </object>"
47   "</interface>";
48
49 static void
50 got_active (GObject *win, GParamSpec *pspec, gpointer data)
51 {
52   gtk_main_quit ();
53 }
54
55 static void
56 test_focus_change (void)
57 {
58   GtkBuilder *builder;
59   GError *error;
60   GtkWidget *window;
61   GtkWidget *entry1;
62   GtkWidget *entry2;
63   AtkObject *wa;
64   AtkObject *ea1;
65   AtkObject *ea2;
66   GtkWidget *focus;
67   AtkStateSet *set;
68   gboolean ret;
69
70   builder = gtk_builder_new ();
71   error = NULL;
72   gtk_builder_add_from_string (builder, data, -1, &error);
73   g_assert_no_error (error);
74   window = (GtkWidget*)gtk_builder_get_object (builder, "window1");
75   entry1 = (GtkWidget*)gtk_builder_get_object (builder, "entry1");
76   entry2 = (GtkWidget*)gtk_builder_get_object (builder, "entry2");
77
78   wa = gtk_widget_get_accessible (window);
79   ea1 = gtk_widget_get_accessible (entry1);
80   ea2 = gtk_widget_get_accessible (entry2);
81
82 #if 0
83   g_signal_connect (window, "notify::is-active", G_CALLBACK (got_active), NULL);
84   gtk_widget_show (window);
85   gtk_main ();
86   g_assert (gtk_window_is_active (GTK_WINDOW (window)));
87 #endif
88
89   focus = gtk_window_get_focus (GTK_WINDOW (window));
90   g_assert (focus == entry1);
91
92   set = atk_object_ref_state_set (ea1);
93   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
94   g_assert (ret);
95   g_object_unref (set);
96   set = atk_object_ref_state_set (ea2);
97   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
98   g_assert (!ret);
99   g_object_unref (set);
100
101   gtk_widget_grab_focus (entry2);
102
103   focus = gtk_window_get_focus (GTK_WINDOW (window));
104   g_assert (focus == entry2);
105
106   set = atk_object_ref_state_set (ea1);
107   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
108   g_assert (!ret);
109   g_object_unref (set);
110   set = atk_object_ref_state_set (ea2);
111   ret = atk_state_set_contains_state (set, ATK_STATE_FOCUSED);
112   g_assert (ret);
113   g_object_unref (set);
114
115   g_object_unref (builder);
116 }
117
118
119 int
120 main (int argc, char *argv[])
121 {
122   gtk_test_init (&argc, &argv, NULL);
123
124   g_test_add_func ("/focus/change", test_focus_change);
125
126   return g_test_run ();
127 }
128