1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18 #include <gtk/gtk.h>
19
20 /* test that attach_next_to picks the places
21 * we expect it to pick, when there is any choice
22 */
23 static void
test_attach(void)24 test_attach (void)
25 {
26 GtkGrid *g;
27 GtkWidget *child, *sibling, *z, *A, *B;
28 int left, top, width, height;
29
30 g = (GtkGrid *)gtk_grid_new ();
31
32 child = gtk_label_new ("a");
33 gtk_grid_attach_next_to (g, child, NULL, GTK_POS_LEFT, 1, 1);
34 gtk_grid_query_child (g, child,
35 &left, &top,
36 &width, &height);
37 g_assert_cmpint (left, ==, -1);
38 g_assert_cmpint (top, ==, 0);
39 g_assert_cmpint (width, ==, 1);
40 g_assert_cmpint (height, ==, 1);
41
42 sibling = child;
43 child = gtk_label_new ("b");
44 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_RIGHT, 2, 2);
45 gtk_grid_query_child (g, child,
46 &left, &top,
47 &width, &height);
48 g_assert_cmpint (left, ==, 0);
49 g_assert_cmpint (top, ==, 0);
50 g_assert_cmpint (width, ==, 2);
51 g_assert_cmpint (height, ==, 2);
52
53 /* this one should just be ignored */
54 z = gtk_label_new ("z");
55 gtk_grid_attach (g, z, 4, 4, 1, 1);
56
57 child = gtk_label_new ("c");
58 gtk_grid_attach_next_to (g, child, sibling, GTK_POS_BOTTOM, 3, 1);
59 gtk_grid_query_child (g, child,
60 &left, &top,
61 &width, &height);
62 g_assert_cmpint (left, ==, -1);
63 g_assert_cmpint (top, ==, 1);
64 g_assert_cmpint (width, ==, 3);
65 g_assert_cmpint (height, ==, 1);
66
67 child = gtk_label_new ("u");
68 gtk_grid_attach_next_to (g, child, z, GTK_POS_LEFT, 2, 1);
69 gtk_grid_query_child (g, child,
70 &left, &top,
71 &width, &height);
72 g_assert_cmpint (left, ==, 2);
73 g_assert_cmpint (top, ==, 4);
74 g_assert_cmpint (width, ==, 2);
75 g_assert_cmpint (height, ==, 1);
76
77 child = gtk_label_new ("v");
78 gtk_grid_attach_next_to (g, child, z, GTK_POS_RIGHT, 2, 1);
79 gtk_grid_query_child (g, child,
80 &left, &top,
81 &width, &height);
82 g_assert_cmpint (left, ==, 5);
83 g_assert_cmpint (top, ==, 4);
84 g_assert_cmpint (width, ==, 2);
85 g_assert_cmpint (height, ==, 1);
86
87 child = gtk_label_new ("x");
88 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
89 gtk_grid_query_child (g, child,
90 &left, &top,
91 &width, &height);
92 g_assert_cmpint (left, ==, 4);
93 g_assert_cmpint (top, ==, 2);
94 g_assert_cmpint (width, ==, 1);
95 g_assert_cmpint (height, ==, 2);
96
97 child = gtk_label_new ("x");
98 gtk_grid_attach_next_to (g, child, z, GTK_POS_TOP, 1, 2);
99 gtk_grid_query_child (g, child,
100 &left, &top,
101 &width, &height);
102 g_assert_cmpint (left, ==, 4);
103 g_assert_cmpint (top, ==, 2);
104 g_assert_cmpint (width, ==, 1);
105 g_assert_cmpint (height, ==, 2);
106
107 child = gtk_label_new ("y");
108 gtk_grid_attach_next_to (g, child, z, GTK_POS_BOTTOM, 1, 2);
109 gtk_grid_query_child (g, child,
110 &left, &top,
111 &width, &height);
112 g_assert_cmpint (left, ==, 4);
113 g_assert_cmpint (top, ==, 5);
114 g_assert_cmpint (width, ==, 1);
115 g_assert_cmpint (height, ==, 2);
116
117 A = gtk_label_new ("A");
118 gtk_grid_attach (g, A, 10, 10, 1, 1);
119 B = gtk_label_new ("B");
120 gtk_grid_attach (g, B, 10, 12, 1, 1);
121
122 child = gtk_label_new ("D");
123 gtk_grid_attach_next_to (g, child, A, GTK_POS_RIGHT, 1, 3);
124 gtk_grid_query_child (g, child,
125 &left, &top,
126 &width, &height);
127 g_assert_cmpint (left, ==, 11);
128 g_assert_cmpint (top, ==, 10);
129 g_assert_cmpint (width, ==, 1);
130 g_assert_cmpint (height, ==, 3);
131 }
132
133 int
main(int argc,char * argv[])134 main (int argc,
135 char *argv[])
136 {
137 gtk_test_init (&argc, &argv);
138
139 g_test_add_func ("/grid/attach", test_attach);
140
141 return g_test_run();
142 }
143