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, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
31 p = gtk_tree_path_new ();
32 for (i = 0; i < 100; i++)
34 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, i);
35 gtk_tree_path_append_index (p, i);
38 indices = gtk_tree_path_get_indices (p);
39 for (i = 0; i < 100; i++)
40 g_assert_cmpint (indices[i], ==, i);
42 gtk_tree_path_free (p);
52 p = gtk_tree_path_new ();
53 for (i = 0; i < 100; i++)
55 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, i);
56 gtk_tree_path_prepend_index (p, i);
59 indices = gtk_tree_path_get_indices (p);
60 for (i = 0; i < 100; i++)
61 g_assert_cmpint (indices[i], ==, 99 - i);
63 gtk_tree_path_free (p);
69 const gchar *str = "0:1:2:3:4:5:6:7:8:9:10";
75 p = gtk_tree_path_new_from_string (str);
76 indices = gtk_tree_path_get_indices (p);
77 for (i = 0; i < 10; i++)
78 g_assert_cmpint (indices[i], ==, i);
79 s = gtk_tree_path_to_string (p);
80 g_assert_cmpstr (s, ==, str);
82 gtk_tree_path_free (p);
87 test_from_indices (void)
93 p = gtk_tree_path_new_from_indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
94 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, 10);
95 indices = gtk_tree_path_get_indices (p);
96 for (i = 0; i < 10; i++)
97 g_assert_cmpint (indices[i], ==, i);
98 gtk_tree_path_free (p);
105 p = gtk_tree_path_new_first ();
106 g_assert_cmpint (gtk_tree_path_get_depth (p), ==, 1);
107 g_assert_cmpint (gtk_tree_path_get_indices (p)[0], ==, 0);
108 gtk_tree_path_free (p);
112 test_navigation (void)
121 p = gtk_tree_path_new_from_indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1);
122 q = gtk_tree_path_copy (p);
123 g_assert (gtk_tree_path_compare (p, q) == 0);
124 gtk_tree_path_next (q);
125 pi = gtk_tree_path_get_indices (p);
126 qi = gtk_tree_path_get_indices (q);
127 for (i = 0; i < 9; i++)
128 g_assert_cmpint (pi[i], ==, qi[i]);
129 g_assert_cmpint (qi[9], ==, pi[9] + 1);
131 g_assert (!gtk_tree_path_is_ancestor (p, q));
132 g_assert (!gtk_tree_path_is_ancestor (q, p));
133 g_assert (!gtk_tree_path_is_descendant (p, q));
134 g_assert (!gtk_tree_path_is_descendant (q, p));
136 res = gtk_tree_path_prev (q);
138 g_assert (gtk_tree_path_compare (p, q) == 0);
140 g_assert (!gtk_tree_path_is_ancestor (p, q));
141 g_assert (!gtk_tree_path_is_ancestor (q, p));
142 g_assert (!gtk_tree_path_is_descendant (p, q));
143 g_assert (!gtk_tree_path_is_descendant (q, p));
145 gtk_tree_path_down (q);
147 g_assert (gtk_tree_path_compare (p, q) < 0);
149 g_assert (gtk_tree_path_is_ancestor (p, q));
150 g_assert (!gtk_tree_path_is_ancestor (q, p));
151 g_assert (!gtk_tree_path_is_descendant (p, q));
152 g_assert (gtk_tree_path_is_descendant (q, p));
154 res = gtk_tree_path_prev (q);
157 res = gtk_tree_path_up (q);
159 g_assert (gtk_tree_path_compare (p, q) == 0);
161 g_assert_cmpint (gtk_tree_path_get_depth (q), ==, 10);
162 res = gtk_tree_path_up (q);
164 g_assert_cmpint (gtk_tree_path_get_depth (q), ==, 9);
166 gtk_tree_path_free (p);
167 gtk_tree_path_free (q);
171 main (int argc, char *argv[])
173 gtk_test_init (&argc, &argv, NULL);
175 g_test_add_func ("/tree-path/append", test_append);
176 g_test_add_func ("/tree-path/prepend", test_prepend);
177 g_test_add_func ("/tree-path/to-string", test_to_string);
178 g_test_add_func ("/tree-path/from-indices", test_from_indices);
179 g_test_add_func ("/tree-path/first", test_first);
180 g_test_add_func ("/tree-path/navigation", test_navigation);
182 return g_test_run ();