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 */
23static void
24test_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 (str: "a");
33 gtk_grid_attach_next_to (grid: g, child, NULL, side: GTK_POS_LEFT, width: 1, height: 1);
34 gtk_grid_query_child (grid: g, child,
35 column: &left, row: &top,
36 width: &width, height: &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 (str: "b");
44 gtk_grid_attach_next_to (grid: g, child, sibling, side: GTK_POS_RIGHT, width: 2, height: 2);
45 gtk_grid_query_child (grid: g, child,
46 column: &left, row: &top,
47 width: &width, height: &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 (str: "z");
55 gtk_grid_attach (grid: g, child: z, column: 4, row: 4, width: 1, height: 1);
56
57 child = gtk_label_new (str: "c");
58 gtk_grid_attach_next_to (grid: g, child, sibling, side: GTK_POS_BOTTOM, width: 3, height: 1);
59 gtk_grid_query_child (grid: g, child,
60 column: &left, row: &top,
61 width: &width, height: &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 (str: "u");
68 gtk_grid_attach_next_to (grid: g, child, sibling: z, side: GTK_POS_LEFT, width: 2, height: 1);
69 gtk_grid_query_child (grid: g, child,
70 column: &left, row: &top,
71 width: &width, height: &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 (str: "v");
78 gtk_grid_attach_next_to (grid: g, child, sibling: z, side: GTK_POS_RIGHT, width: 2, height: 1);
79 gtk_grid_query_child (grid: g, child,
80 column: &left, row: &top,
81 width: &width, height: &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 (str: "x");
88 gtk_grid_attach_next_to (grid: g, child, sibling: z, side: GTK_POS_TOP, width: 1, height: 2);
89 gtk_grid_query_child (grid: g, child,
90 column: &left, row: &top,
91 width: &width, height: &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 (str: "x");
98 gtk_grid_attach_next_to (grid: g, child, sibling: z, side: GTK_POS_TOP, width: 1, height: 2);
99 gtk_grid_query_child (grid: g, child,
100 column: &left, row: &top,
101 width: &width, height: &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 (str: "y");
108 gtk_grid_attach_next_to (grid: g, child, sibling: z, side: GTK_POS_BOTTOM, width: 1, height: 2);
109 gtk_grid_query_child (grid: g, child,
110 column: &left, row: &top,
111 width: &width, height: &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 (str: "A");
118 gtk_grid_attach (grid: g, child: A, column: 10, row: 10, width: 1, height: 1);
119 B = gtk_label_new (str: "B");
120 gtk_grid_attach (grid: g, child: B, column: 10, row: 12, width: 1, height: 1);
121
122 child = gtk_label_new (str: "D");
123 gtk_grid_attach_next_to (grid: g, child, sibling: A, side: GTK_POS_RIGHT, width: 1, height: 3);
124 gtk_grid_query_child (grid: g, child,
125 column: &left, row: &top,
126 width: &width, height: &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
133int
134main (int argc,
135 char *argv[])
136{
137 gtk_test_init (argcp: &argc, argvp: &argv);
138
139 g_test_add_func (testpath: "/grid/attach", test_func: test_attach);
140
141 return g_test_run();
142}
143

source code of gtk/testsuite/gtk/grid.c