2 * Copyright (C) 2011 Red Hat Inc.
5 * Matthias Clasen <mclasen@redhat.com>
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.
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.
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/>.
21 #define GDK_DISABLE_DEPRECATION_WARNINGS
27 test_scrolled_window_child_count (void)
30 AtkObject *accessible;
32 sw = gtk_scrolled_window_new (NULL, NULL);
33 g_object_ref_sink (sw);
34 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
35 GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
36 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), gtk_label_new ("Bla"));
38 accessible = gtk_widget_get_accessible (sw);
39 g_assert_cmpint (atk_object_get_n_accessible_children (accessible), ==, 3);
52 children_changed (AtkObject *accessible,
59 data->n_children = atk_object_get_n_accessible_children (accessible);
63 add_child (GtkWidget *container,
66 if (GTK_IS_SCROLLED_WINDOW (container))
67 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), child);
69 gtk_container_add (GTK_CONTAINER (container), child);
73 remove_child (GtkWidget *container,
76 if (GTK_IS_SCROLLED_WINDOW (container))
78 if (gtk_widget_get_parent (child) != container)
79 child = gtk_widget_get_parent (child);
82 gtk_container_remove (GTK_CONTAINER (container), child);
86 parent_notify (AtkObject *obj, GParamSpec *pspec, SignalData *data)
89 data->parent = atk_object_get_parent (obj);
93 test_add_remove (GtkWidget *widget)
95 AtkObject *accessible;
96 AtkObject *child_accessible;
98 SignalData remove_data;
99 SignalData parent_data[3];
104 accessible = gtk_widget_get_accessible (widget);
107 remove_data.count = 0;
108 g_signal_connect (accessible, "children_changed::add",
109 G_CALLBACK (children_changed), &add_data);
110 g_signal_connect (accessible, "children_changed::remove",
111 G_CALLBACK (children_changed), &remove_data);
113 step_children = atk_object_get_n_accessible_children (accessible);
115 for (i = 0; i < 3; i++)
117 if (gtk_container_child_type (GTK_CONTAINER (widget)) == G_TYPE_NONE)
120 child[i] = gtk_label_new ("bla");
121 parent_data[i].count = 0;
122 child_accessible = gtk_widget_get_accessible (child[i]);
123 g_signal_connect (child_accessible, "notify::accessible-parent",
124 G_CALLBACK (parent_notify), &(parent_data[i]));
125 add_child (widget, child[i]);
127 g_assert_cmpint (add_data.count, ==, i + 1);
128 g_assert_cmpint (add_data.n_children, ==, step_children + i + 1);
129 g_assert_cmpint (remove_data.count, ==, 0);
130 g_assert_cmpint (parent_data[i].count, ==, 1);
131 if (GTK_IS_SCROLLED_WINDOW (widget) ||
132 GTK_IS_NOTEBOOK (widget))
133 g_assert (atk_object_get_parent (ATK_OBJECT (parent_data[i].parent)) == accessible);
135 g_assert (parent_data[i].parent == accessible);
137 for (j = 0 ; j < i; j++)
139 remove_child (widget, child[j]);
140 g_assert_cmpint (add_data.count, ==, i);
141 g_assert_cmpint (remove_data.count, ==, j + 1);
142 g_assert_cmpint (remove_data.n_children, ==, step_children + i - j - 1);
143 if (parent_data[j].count == 2)
144 g_assert (parent_data[j].parent == NULL);
148 set = atk_object_ref_state_set (ATK_OBJECT (parent_data[j].parent));
149 g_assert (atk_state_set_contains_state (set, ATK_STATE_DEFUNCT));
150 g_object_unref (set);
154 g_signal_handlers_disconnect_by_func (accessible, G_CALLBACK (children_changed), &add_data);
155 g_signal_handlers_disconnect_by_func (accessible, G_CALLBACK (children_changed), &remove_data);
159 add_child_test (const gchar *prefix,
160 GTestFixtureFunc test_func,
165 path = g_strdup_printf ("%s/%s", prefix, G_OBJECT_TYPE_NAME (widget));
166 g_test_add_vtable (path,
168 g_object_ref (widget),
170 (GTestFixtureFunc) test_func,
171 (GTestFixtureFunc) g_object_unref);
176 add_child_tests (GtkWidget *widget)
178 g_object_ref_sink (widget);
179 add_child_test ("/child/add-remove", (GTestFixtureFunc)test_add_remove, widget);
180 g_object_unref (widget);
184 main (int argc, char *argv[])
186 gtk_test_init (&argc, &argv, NULL);
188 g_test_add_func ("/scrolledwindow/child-count", test_scrolled_window_child_count);
190 add_child_tests (gtk_scrolled_window_new (NULL, NULL));
191 add_child_tests (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
192 add_child_tests (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL));
193 add_child_tests (gtk_grid_new ());
194 add_child_tests (gtk_event_box_new ());
195 add_child_tests (gtk_window_new (GTK_WINDOW_TOPLEVEL));
196 add_child_tests (gtk_assistant_new ());
197 add_child_tests (gtk_frame_new ("frame"));
198 add_child_tests (gtk_expander_new ("expander"));
199 add_child_tests (gtk_table_new (2, 2, FALSE));
200 add_child_tests (gtk_text_view_new ());
201 add_child_tests (gtk_tree_view_new ());
203 /* gail doesn't handle non-label children in these */
204 add_child_tests (gtk_button_new ());
205 add_child_tests (gtk_statusbar_new ());
207 add_child_tests (gtk_notebook_new ());
209 return g_test_run ();