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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 /* test that attach_next_to picks the places
23 * we expect it to pick, when there is any choice
29 GtkWidget *child, *sibling, *z, *A, *B;
30 gint left, top, width, height;
32 g = (GtkGrid *)gtk_grid_new ();
34 child = gtk_label_new ("a");
35 gtk_grid_attach_next_to (g, child, NULL, GTK_POS_LEFT, 1, 1);
36 gtk_container_child_get (GTK_CONTAINER (g), child,
42 g_assert_cmpint (left, ==, -1);
43 g_assert_cmpint (top, ==, 0);
44 g_assert_cmpint (width, ==, 1);
45 g_assert_cmpint (height, ==, 1);
48 child = gtk_label_new ("b");
49 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_RIGHT, 2, 2);
50 gtk_container_child_get (GTK_CONTAINER (g), child,
56 g_assert_cmpint (left, ==, 0);
57 g_assert_cmpint (top, ==, 0);
58 g_assert_cmpint (width, ==, 2);
59 g_assert_cmpint (height, ==, 2);
61 /* this one should just be ignored */
62 z = gtk_label_new ("z");
63 gtk_grid_attach (g, z, 4, 4, 1, 1);
65 child = gtk_label_new ("c");
66 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_BOTTOM, 3, 1);
67 gtk_container_child_get (GTK_CONTAINER (g), child,
73 g_assert_cmpint (left, ==, -1);
74 g_assert_cmpint (top, ==, 1);
75 g_assert_cmpint (width, ==, 3);
76 g_assert_cmpint (height, ==, 1);
78 child = gtk_label_new ("u");
79 gtk_grid_attach_next_to (g, child, z, GTK_POS_LEFT, 2, 1);
80 gtk_container_child_get (GTK_CONTAINER (g), child,
86 g_assert_cmpint (left, ==, 2);
87 g_assert_cmpint (top, ==, 4);
88 g_assert_cmpint (width, ==, 2);
89 g_assert_cmpint (height, ==, 1);
91 child = gtk_label_new ("v");
92 gtk_grid_attach_next_to (g, child, z, GTK_POS_RIGHT, 2, 1);
93 gtk_container_child_get (GTK_CONTAINER (g), child,
99 g_assert_cmpint (left, ==, 5);
100 g_assert_cmpint (top, ==, 4);
101 g_assert_cmpint (width, ==, 2);
102 g_assert_cmpint (height, ==, 1);
104 child = gtk_label_new ("x");
105 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
106 gtk_container_child_get (GTK_CONTAINER (g), child,
107 "left-attach", &left,
112 g_assert_cmpint (left, ==, 4);
113 g_assert_cmpint (top, ==, 2);
114 g_assert_cmpint (width, ==, 1);
115 g_assert_cmpint (height, ==, 2);
117 child = gtk_label_new ("x");
118 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
119 gtk_container_child_get (GTK_CONTAINER (g), child,
120 "left-attach", &left,
125 g_assert_cmpint (left, ==, 4);
126 g_assert_cmpint (top, ==, 2);
127 g_assert_cmpint (width, ==, 1);
128 g_assert_cmpint (height, ==, 2);
130 child = gtk_label_new ("y");
131 gtk_grid_attach_next_to (g, child, z, GTK_POS_BOTTOM, 1, 2);
132 gtk_container_child_get (GTK_CONTAINER (g), child,
133 "left-attach", &left,
138 g_assert_cmpint (left, ==, 4);
139 g_assert_cmpint (top, ==, 5);
140 g_assert_cmpint (width, ==, 1);
141 g_assert_cmpint (height, ==, 2);
143 A = gtk_label_new ("A");
144 gtk_grid_attach (g, A, 10, 10, 1, 1);
145 B = gtk_label_new ("B");
146 gtk_grid_attach (g, B, 10, 12, 1, 1);
148 child = gtk_label_new ("D");
149 gtk_grid_attach_next_to (g, child, A, GTK_POS_RIGHT, 1, 3);
150 gtk_container_child_get (GTK_CONTAINER (g), child,
151 "left-attach", &left,
156 g_assert_cmpint (left, ==, 11);
157 g_assert_cmpint (top, ==, 10);
158 g_assert_cmpint (width, ==, 1);
159 g_assert_cmpint (height, ==, 3);
167 gint left, top, width, height;
169 g = (GtkGrid *)gtk_grid_new ();
171 gtk_orientable_set_orientation (GTK_ORIENTABLE (g), GTK_ORIENTATION_HORIZONTAL);
173 child = gtk_label_new ("a");
174 gtk_container_add (GTK_CONTAINER (g), child);
175 gtk_container_child_get (GTK_CONTAINER (g), child,
176 "left-attach", &left,
181 g_assert_cmpint (left, ==, 0);
182 g_assert_cmpint (top, ==, 0);
183 g_assert_cmpint (width, ==, 1);
184 g_assert_cmpint (height, ==, 1);
186 child = gtk_label_new ("b");
187 gtk_container_add (GTK_CONTAINER (g), child);
188 gtk_container_child_get (GTK_CONTAINER (g), child,
189 "left-attach", &left,
194 g_assert_cmpint (left, ==, 1);
195 g_assert_cmpint (top, ==, 0);
196 g_assert_cmpint (width, ==, 1);
197 g_assert_cmpint (height, ==, 1);
199 child = gtk_label_new ("c");
200 gtk_container_add (GTK_CONTAINER (g), child);
201 gtk_container_child_get (GTK_CONTAINER (g), child,
202 "left-attach", &left,
207 g_assert_cmpint (left, ==, 2);
208 g_assert_cmpint (top, ==, 0);
209 g_assert_cmpint (width, ==, 1);
210 g_assert_cmpint (height, ==, 1);
212 gtk_orientable_set_orientation (GTK_ORIENTABLE (g), GTK_ORIENTATION_VERTICAL);
214 child = gtk_label_new ("d");
215 gtk_container_add (GTK_CONTAINER (g), child);
216 gtk_container_child_get (GTK_CONTAINER (g), child,
217 "left-attach", &left,
222 g_assert_cmpint (left, ==, 0);
223 g_assert_cmpint (top, ==, 1);
224 g_assert_cmpint (width, ==, 1);
225 g_assert_cmpint (height, ==, 1);
232 gtk_test_init (&argc, &argv);
234 g_test_add_func ("/grid/attach", test_attach);
235 g_test_add_func ("/grid/add", test_add);