3 * Copyright (C) 2011, Red Hat, Inc.
4 * Authors: Matthias Clasen <mclasen@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
29 p = gtk_tree_path_new ();
30 for (i = 0; i < 100; i++)
32 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, i);
33 gtk_tree_path_append_index (p, i);
36 indices = gtk_tree_path_get_indices (p);
37 for (i = 0; i < 100; i++)
38 g_assert_cmpint (indices[i], ==, i);
40 gtk_tree_path_free (p);
50 p = gtk_tree_path_new ();
51 for (i = 0; i < 100; i++)
53 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, i);
54 gtk_tree_path_prepend_index (p, i);
57 indices = gtk_tree_path_get_indices (p);
58 for (i = 0; i < 100; i++)
59 g_assert_cmpint (indices[i], ==, 99 - i);
61 gtk_tree_path_free (p);
67 const gchar *str = "0:1:2:3:4:5:6:7:8:9:10";
73 p = gtk_tree_path_new_from_string (str);
74 indices = gtk_tree_path_get_indices (p);
75 for (i = 0; i < 10; i++)
76 g_assert_cmpint (indices[i], ==, i);
77 s = gtk_tree_path_to_string (p);
78 g_assert_cmpstr (s, ==, str);
80 gtk_tree_path_free (p);
85 test_from_indices (void)
91 p = gtk_tree_path_new_from_indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
92 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, 10);
93 indices = gtk_tree_path_get_indices (p);
94 for (i = 0; i < 10; i++)
95 g_assert_cmpint (indices[i], ==, i);
96 gtk_tree_path_free (p);
103 p = gtk_tree_path_new_first ();
104 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, 1);
105 g_assert_cmpint (gtk_tree_path_get_indices (p)[0], ==, 0);
106 gtk_tree_path_free (p);
110 test_navigation (void)
119 p = gtk_tree_path_new_from_indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
120 q = gtk_tree_path_copy (p);
121 g_assert (gtk_tree_path_compare (p, q) == 0);
122 gtk_tree_path_next (q);
123 pi = gtk_tree_path_get_indices (p);
124 qi = gtk_tree_path_get_indices (q);
125 for (i = 0; i < 9; i++)
126 g_assert_cmpint (pi[i], ==, qi[i]);
127 g_assert_cmpint (qi[9], ==, pi[9] + 1);
129 g_assert (!gtk_tree_path_is_ancestor (p, q));
130 g_assert (!gtk_tree_path_is_ancestor (q, p));
131 g_assert (!gtk_tree_path_is_descendant (p, q));
132 g_assert (!gtk_tree_path_is_descendant (q, p));
134 res = gtk_tree_path_prev (q);
136 g_assert (gtk_tree_path_compare (p, q) == 0);
138 g_assert (!gtk_tree_path_is_ancestor (p, q));
139 g_assert (!gtk_tree_path_is_ancestor (q, p));
140 g_assert (!gtk_tree_path_is_descendant (p, q));
141 g_assert (!gtk_tree_path_is_descendant (q, p));
143 gtk_tree_path_down (q);
145 g_assert (gtk_tree_path_compare (p, q) < 0);
147 g_assert (gtk_tree_path_is_ancestor (p, q));
148 g_assert (!gtk_tree_path_is_ancestor (q, p));
149 g_assert (!gtk_tree_path_is_descendant (p, q));
150 g_assert (gtk_tree_path_is_descendant (q, p));
152 res = gtk_tree_path_prev (q);
155 res = gtk_tree_path_up (q);
157 g_assert (gtk_tree_path_compare (p, q) == 0);
159 g_assert_cmpint (gtk_tree_path_get_depth (q), ==, 10);
160 res = gtk_tree_path_up (q);
162 g_assert_cmpint (gtk_tree_path_get_depth (q), ==, 9);
164 gtk_tree_path_free (p);
165 gtk_tree_path_free (q);
169 main (int argc, char *argv[])
171 gtk_test_init (&argc, &argv, NULL);
173 g_test_add_func ("/tree-path/append", test_append);
174 g_test_add_func ("/tree-path/prepend", test_prepend);
175 g_test_add_func ("/tree-path/to-string", test_to_string);
176 g_test_add_func ("/tree-path/from-indices", test_from_indices);
177 g_test_add_func ("/tree-path/first", test_first);
178 g_test_add_func ("/tree-path/navigation", test_navigation);
180 return g_test_run ();