1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 /* test that attach_next_to picks the places
21 * we expect it to pick, when there is any choice
27 GtkWidget *child, *sibling, *z, *A, *B;
28 gint left, top, width, height;
30 g = (GtkGrid *)gtk_grid_new ();
32 child = gtk_label_new ("a");
33 gtk_grid_attach_next_to (g, child, NULL, GTK_POS_LEFT, 1, 1);
34 gtk_container_child_get (GTK_CONTAINER (g), child,
40 g_assert_cmpint (left, ==, -1);
41 g_assert_cmpint (top, ==, 0);
42 g_assert_cmpint (width, ==, 1);
43 g_assert_cmpint (height, ==, 1);
46 child = gtk_label_new ("b");
47 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_RIGHT, 2, 2);
48 gtk_container_child_get (GTK_CONTAINER (g), child,
54 g_assert_cmpint (left, ==, 0);
55 g_assert_cmpint (top, ==, 0);
56 g_assert_cmpint (width, ==, 2);
57 g_assert_cmpint (height, ==, 2);
59 /* this one should just be ignored */
60 z = gtk_label_new ("z");
61 gtk_grid_attach (g, z, 4, 4, 1, 1);
63 child = gtk_label_new ("c");
64 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_BOTTOM, 3, 1);
65 gtk_container_child_get (GTK_CONTAINER (g), child,
71 g_assert_cmpint (left, ==, -1);
72 g_assert_cmpint (top, ==, 1);
73 g_assert_cmpint (width, ==, 3);
74 g_assert_cmpint (height, ==, 1);
76 child = gtk_label_new ("u");
77 gtk_grid_attach_next_to (g, child, z, GTK_POS_LEFT, 2, 1);
78 gtk_container_child_get (GTK_CONTAINER (g), child,
84 g_assert_cmpint (left, ==, 2);
85 g_assert_cmpint (top, ==, 4);
86 g_assert_cmpint (width, ==, 2);
87 g_assert_cmpint (height, ==, 1);
89 child = gtk_label_new ("v");
90 gtk_grid_attach_next_to (g, child, z, GTK_POS_RIGHT, 2, 1);
91 gtk_container_child_get (GTK_CONTAINER (g), child,
97 g_assert_cmpint (left, ==, 5);
98 g_assert_cmpint (top, ==, 4);
99 g_assert_cmpint (width, ==, 2);
100 g_assert_cmpint (height, ==, 1);
102 child = gtk_label_new ("x");
103 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
104 gtk_container_child_get (GTK_CONTAINER (g), child,
105 "left-attach", &left,
110 g_assert_cmpint (left, ==, 4);
111 g_assert_cmpint (top, ==, 2);
112 g_assert_cmpint (width, ==, 1);
113 g_assert_cmpint (height, ==, 2);
115 child = gtk_label_new ("x");
116 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
117 gtk_container_child_get (GTK_CONTAINER (g), child,
118 "left-attach", &left,
123 g_assert_cmpint (left, ==, 4);
124 g_assert_cmpint (top, ==, 2);
125 g_assert_cmpint (width, ==, 1);
126 g_assert_cmpint (height, ==, 2);
128 child = gtk_label_new ("y");
129 gtk_grid_attach_next_to (g, child, z, GTK_POS_BOTTOM, 1, 2);
130 gtk_container_child_get (GTK_CONTAINER (g), child,
131 "left-attach", &left,
136 g_assert_cmpint (left, ==, 4);
137 g_assert_cmpint (top, ==, 5);
138 g_assert_cmpint (width, ==, 1);
139 g_assert_cmpint (height, ==, 2);
141 A = gtk_label_new ("A");
142 gtk_grid_attach (g, A, 10, 10, 1, 1);
143 B = gtk_label_new ("B");
144 gtk_grid_attach (g, B, 10, 12, 1, 1);
146 child = gtk_label_new ("D");
147 gtk_grid_attach_next_to (g, child, A, GTK_POS_RIGHT, 1, 3);
148 gtk_container_child_get (GTK_CONTAINER (g), child,
149 "left-attach", &left,
154 g_assert_cmpint (left, ==, 11);
155 g_assert_cmpint (top, ==, 10);
156 g_assert_cmpint (width, ==, 1);
157 g_assert_cmpint (height, ==, 3);
165 gint left, top, width, height;
167 g = (GtkGrid *)gtk_grid_new ();
169 gtk_orientable_set_orientation (GTK_ORIENTABLE (g), GTK_ORIENTATION_HORIZONTAL);
171 child = gtk_label_new ("a");
172 gtk_container_add (GTK_CONTAINER (g), child);
173 gtk_container_child_get (GTK_CONTAINER (g), child,
174 "left-attach", &left,
179 g_assert_cmpint (left, ==, 0);
180 g_assert_cmpint (top, ==, 0);
181 g_assert_cmpint (width, ==, 1);
182 g_assert_cmpint (height, ==, 1);
184 child = gtk_label_new ("b");
185 gtk_container_add (GTK_CONTAINER (g), child);
186 gtk_container_child_get (GTK_CONTAINER (g), child,
187 "left-attach", &left,
192 g_assert_cmpint (left, ==, 1);
193 g_assert_cmpint (top, ==, 0);
194 g_assert_cmpint (width, ==, 1);
195 g_assert_cmpint (height, ==, 1);
197 child = gtk_label_new ("c");
198 gtk_container_add (GTK_CONTAINER (g), child);
199 gtk_container_child_get (GTK_CONTAINER (g), child,
200 "left-attach", &left,
205 g_assert_cmpint (left, ==, 2);
206 g_assert_cmpint (top, ==, 0);
207 g_assert_cmpint (width, ==, 1);
208 g_assert_cmpint (height, ==, 1);
210 gtk_orientable_set_orientation (GTK_ORIENTABLE (g), GTK_ORIENTATION_VERTICAL);
212 child = gtk_label_new ("d");
213 gtk_container_add (GTK_CONTAINER (g), child);
214 gtk_container_child_get (GTK_CONTAINER (g), child,
215 "left-attach", &left,
220 g_assert_cmpint (left, ==, 0);
221 g_assert_cmpint (top, ==, 1);
222 g_assert_cmpint (width, ==, 1);
223 g_assert_cmpint (height, ==, 1);
230 gtk_test_init (&argc, &argv);
232 g_test_add_func ("/grid/attach", test_attach);
233 g_test_add_func ("/grid/add", test_add);