1 /* Extensive GtkListStore tests.
2 * Copyright (C) 2007 Imendio AB
3 * Authors: Kristian Rietveld <kris@imendio.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * - Test implementations of the interfaces: DnD, sortable, buildable
21 * and the tree model interface itself?
22 * - Need to check if the emitted signals are right.
23 * - Needs analysis with the code coverage tool once it is there.
28 #include "treemodel.h"
30 static inline gboolean
31 iters_equal (GtkTreeIter *a,
34 if (a->stamp != b->stamp)
37 if (a->user_data != b->user_data)
40 /* user_data2 and user_data3 are not used in GtkListStore */
46 iter_position (GtkListStore *store,
53 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
57 if (gtk_tree_path_get_indices (path)[0] != n)
60 gtk_tree_path_free (path);
75 list_store_setup (ListStore *fixture,
76 gconstpointer test_data)
80 fixture->store = gtk_list_store_new (1, G_TYPE_INT);
82 for (i = 0; i < 5; i++)
84 gtk_list_store_insert (fixture->store, &fixture->iter[i], i);
85 gtk_list_store_set (fixture->store, &fixture->iter[i], 0, i, -1);
90 list_store_teardown (ListStore *fixture,
91 gconstpointer test_data)
93 g_object_unref (fixture->store);
101 check_model (ListStore *fixture,
108 path = gtk_tree_path_new ();
109 gtk_tree_path_down (path);
111 /* Check validity of the model and validity of the iters-persistent
114 for (i = 0; i < 5; i++)
121 /* The saved iterator at new_order[i] should match the iterator
125 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
128 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter));
129 g_assert (iters_equal (&iter, &fixture->iter[new_order[i]]));
131 gtk_tree_path_next (path);
134 gtk_tree_path_free (path);
139 list_store_test_insert_high_values (void)
141 GtkTreeIter iter, iter2;
142 GtkTreeIter iter_copy;
145 store = gtk_list_store_new (1, G_TYPE_INT);
147 gtk_list_store_insert (store, &iter, 1234);
148 g_assert (gtk_list_store_iter_is_valid (store, &iter));
149 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 1);
150 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
151 g_assert (iters_equal (&iter, &iter_copy));
152 g_assert (iter_position (store, &iter, 0));
154 gtk_list_store_insert (store, &iter2, 765);
155 g_assert (gtk_list_store_iter_is_valid (store, &iter2));
156 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 2);
158 /* Walk over the model */
159 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
160 g_assert (iters_equal (&iter, &iter_copy));
161 g_assert (iter_position (store, &iter, 0));
163 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
164 g_assert (iters_equal (&iter2, &iter_copy));
165 g_assert (iter_position (store, &iter2, 1));
167 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
169 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
170 g_assert (iters_equal (&iter2, &iter_copy));
171 g_assert (iter_position (store, &iter2, 1));
173 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
174 g_assert (iters_equal (&iter, &iter_copy));
175 g_assert (iter_position (store, &iter, 0));
177 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
179 g_object_unref (store);
183 list_store_test_append (void)
185 GtkTreeIter iter, iter2;
186 GtkTreeIter iter_copy;
189 store = gtk_list_store_new (1, G_TYPE_INT);
191 gtk_list_store_append (store, &iter);
192 g_assert (gtk_list_store_iter_is_valid (store, &iter));
193 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 1);
194 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
195 g_assert (iters_equal (&iter, &iter_copy));
196 g_assert (iter_position (store, &iter, 0));
198 gtk_list_store_append (store, &iter2);
199 g_assert (gtk_list_store_iter_is_valid (store, &iter2));
200 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 2);
202 /* Walk over the model */
203 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
204 g_assert (iters_equal (&iter, &iter_copy));
205 g_assert (iter_position (store, &iter, 0));
207 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
208 g_assert (iters_equal (&iter2, &iter_copy));
209 g_assert (iter_position (store, &iter2, 1));
211 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
213 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
214 g_assert (iters_equal (&iter2, &iter_copy));
215 g_assert (iter_position (store, &iter2, 1));
217 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
218 g_assert (iters_equal (&iter, &iter_copy));
219 g_assert (iter_position (store, &iter, 0));
221 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
223 g_object_unref (store);
227 list_store_test_prepend (void)
229 GtkTreeIter iter, iter2;
230 GtkTreeIter iter_copy;
233 store = gtk_list_store_new (1, G_TYPE_INT);
235 gtk_list_store_prepend (store, &iter);
236 g_assert (gtk_list_store_iter_is_valid (store, &iter));
237 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 1);
238 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
239 g_assert (iters_equal (&iter, &iter_copy));
240 g_assert (iter_position (store, &iter, 0));
242 gtk_list_store_prepend (store, &iter2);
243 g_assert (gtk_list_store_iter_is_valid (store, &iter2));
244 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 2);
246 /* Walk over the model */
247 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
248 g_assert (iters_equal (&iter2, &iter_copy));
249 g_assert (iter_position (store, &iter2, 0));
251 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
252 g_assert (iters_equal (&iter, &iter_copy));
253 g_assert (iter_position (store, &iter, 1));
255 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
257 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
258 g_assert (iters_equal (&iter, &iter_copy));
259 g_assert (iter_position (store, &iter, 1));
261 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
262 g_assert (iters_equal (&iter2, &iter_copy));
263 g_assert (iter_position (store, &iter2, 0));
265 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
267 g_object_unref (store);
271 list_store_test_insert_after (void)
273 GtkTreeIter iter, iter2, iter3;
274 GtkTreeIter iter_copy;
277 store = gtk_list_store_new (1, G_TYPE_INT);
279 gtk_list_store_append (store, &iter);
280 gtk_list_store_append (store, &iter2);
282 gtk_list_store_insert_after (store, &iter3, &iter);
283 g_assert (gtk_list_store_iter_is_valid (store, &iter3));
284 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 3);
285 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
286 g_assert (iters_equal (&iter3, &iter_copy));
287 g_assert (iter_position (store, &iter3, 1));
289 /* Walk over the model */
290 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
291 g_assert (iters_equal (&iter, &iter_copy));
292 g_assert (iter_position (store, &iter_copy, 0));
294 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
295 g_assert (iters_equal (&iter3, &iter_copy));
296 g_assert (iter_position (store, &iter_copy, 1));
298 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
299 g_assert (iters_equal (&iter2, &iter_copy));
300 g_assert (iter_position (store, &iter_copy, 2));
302 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
304 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 2));
305 g_assert (iters_equal (&iter2, &iter_copy));
306 g_assert (iter_position (store, &iter2, 2));
308 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
309 g_assert (iters_equal (&iter3, &iter_copy));
310 g_assert (iter_position (store, &iter3, 1));
312 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
313 g_assert (iters_equal (&iter, &iter_copy));
314 g_assert (iter_position (store, &iter, 0));
316 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
318 g_object_unref (store);
322 list_store_test_insert_after_NULL (void)
324 GtkTreeIter iter, iter2;
325 GtkTreeIter iter_copy;
328 store = gtk_list_store_new (1, G_TYPE_INT);
330 gtk_list_store_append (store, &iter);
332 /* move_after NULL is basically a prepend */
333 gtk_list_store_insert_after (store, &iter2, NULL);
334 g_assert (gtk_list_store_iter_is_valid (store, &iter2));
335 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 2);
337 /* Walk over the model */
338 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
339 g_assert (iters_equal (&iter2, &iter_copy));
340 g_assert (iter_position (store, &iter2, 0));
342 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
343 g_assert (iters_equal (&iter, &iter_copy));
344 g_assert (iter_position (store, &iter, 1));
346 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
348 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 0));
349 g_assert (iters_equal (&iter2, &iter_copy));
351 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
352 g_assert (iters_equal (&iter, &iter_copy));
353 g_assert (iter_position (store, &iter, 1));
355 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
356 g_assert (iters_equal (&iter2, &iter_copy));
357 g_assert (iter_position (store, &iter2, 0));
359 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
361 g_object_unref (store);
365 list_store_test_insert_before (void)
367 GtkTreeIter iter, iter2, iter3;
368 GtkTreeIter iter_copy;
371 store = gtk_list_store_new (1, G_TYPE_INT);
373 gtk_list_store_append (store, &iter);
374 gtk_list_store_append (store, &iter2);
376 gtk_list_store_insert_before (store, &iter3, &iter2);
377 g_assert (gtk_list_store_iter_is_valid (store, &iter3));
378 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 3);
379 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
380 g_assert (iters_equal (&iter3, &iter_copy));
381 g_assert (iter_position (store, &iter3, 1));
383 /* Walk over the model */
384 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
385 g_assert (iters_equal (&iter, &iter_copy));
386 g_assert (iter_position (store, &iter_copy, 0));
388 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
389 g_assert (iters_equal (&iter3, &iter_copy));
390 g_assert (iter_position (store, &iter_copy, 1));
392 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
393 g_assert (iters_equal (&iter2, &iter_copy));
394 g_assert (iter_position (store, &iter_copy, 2));
396 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
398 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
399 g_assert (iters_equal (&iter3, &iter_copy));
401 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 2));
402 g_assert (iters_equal (&iter2, &iter_copy));
403 g_assert (iter_position (store, &iter2, 2));
405 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
406 g_assert (iters_equal (&iter3, &iter_copy));
407 g_assert (iter_position (store, &iter3, 1));
409 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
410 g_assert (iters_equal (&iter, &iter_copy));
411 g_assert (iter_position (store, &iter, 0));
413 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
415 g_object_unref (store);
419 list_store_test_insert_before_NULL (void)
421 GtkTreeIter iter, iter2;
422 GtkTreeIter iter_copy;
425 store = gtk_list_store_new (1, G_TYPE_INT);
427 gtk_list_store_append (store, &iter);
429 /* move_before NULL is basically an append */
430 gtk_list_store_insert_before (store, &iter2, NULL);
431 g_assert (gtk_list_store_iter_is_valid (store, &iter2));
432 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) == 2);
434 /* Walk over the model */
435 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter_copy));
436 g_assert (iters_equal (&iter, &iter_copy));
437 g_assert (iter_position (store, &iter, 0));
439 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
440 g_assert (iters_equal (&iter2, &iter_copy));
441 g_assert (iter_position (store, &iter2, 1));
443 g_assert (!gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter_copy));
445 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter_copy, NULL, 1));
446 g_assert (iters_equal (&iter2, &iter_copy));
447 g_assert (iter_position (store, &iter2, 1));
449 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
450 g_assert (iters_equal (&iter, &iter_copy));
451 g_assert (iter_position (store, &iter, 0));
453 g_assert (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (store), &iter_copy));
455 g_object_unref (store);
460 list_store_set_gvalue_to_transform (void)
464 GValue value = G_VALUE_INIT;
466 /* https://bugzilla.gnome.org/show_bug.cgi?id=677649 */
467 store = gtk_list_store_new (1, G_TYPE_LONG);
468 gtk_list_store_append (store, &iter);
470 g_value_init (&value, G_TYPE_INT);
471 g_value_set_int (&value, 42);
472 gtk_list_store_set_value (store, &iter, 0, &value);
477 list_store_test_remove_begin (ListStore *fixture,
478 gconstpointer user_data)
480 int new_order[5] = { -1, 1, 2, 3, 4 };
484 /* Remove node at 0 */
485 path = gtk_tree_path_new_from_indices (0, -1);
486 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &iter, path);
487 gtk_tree_path_free (path);
489 g_assert (gtk_list_store_remove (fixture->store, &iter) == TRUE);
490 g_assert (!gtk_list_store_iter_is_valid (fixture->store, &fixture->iter[0]));
491 g_assert (iters_equal (&iter, &fixture->iter[1]));
493 check_model (fixture, new_order, 0);
497 list_store_test_remove_middle (ListStore *fixture,
498 gconstpointer user_data)
500 int new_order[5] = { 0, 1, -1, 3, 4 };
504 /* Remove node at 2 */
505 path = gtk_tree_path_new_from_indices (2, -1);
506 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &iter, path);
507 gtk_tree_path_free (path);
509 g_assert (gtk_list_store_remove (fixture->store, &iter) == TRUE);
510 g_assert (!gtk_list_store_iter_is_valid (fixture->store, &fixture->iter[2]));
511 g_assert (iters_equal (&iter, &fixture->iter[3]));
513 check_model (fixture, new_order, 2);
517 list_store_test_remove_end (ListStore *fixture,
518 gconstpointer user_data)
520 int new_order[5] = { 0, 1, 2, 3, -1 };
524 /* Remove node at 4 */
525 path = gtk_tree_path_new_from_indices (4, -1);
526 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &iter, path);
527 gtk_tree_path_free (path);
529 g_assert (gtk_list_store_remove (fixture->store, &iter) == FALSE);
530 g_assert (!gtk_list_store_iter_is_valid (fixture->store, &fixture->iter[4]));
532 check_model (fixture, new_order, 4);
536 list_store_test_clear (ListStore *fixture,
537 gconstpointer user_data)
541 gtk_list_store_clear (fixture->store);
543 g_assert (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (fixture->store), NULL) == 0);
545 for (i = 0; i < 5; i++)
546 g_assert (!gtk_list_store_iter_is_valid (fixture->store, &fixture->iter[i]));
552 list_store_test_reorder (ListStore *fixture,
553 gconstpointer user_data)
555 int new_order[5] = { 4, 1, 0, 2, 3 };
557 gtk_list_store_reorder (fixture->store, new_order);
558 check_model (fixture, new_order, -1);
564 list_store_test_swap_begin (ListStore *fixture,
565 gconstpointer user_data)
567 /* We swap nodes 0 and 1 at the beginning */
568 int new_order[5] = { 1, 0, 2, 3, 4 };
573 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_a, "0"));
574 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_b, "1"));
576 gtk_list_store_swap (fixture->store, &iter_a, &iter_b);
577 check_model (fixture, new_order, -1);
581 list_store_test_swap_middle_next (ListStore *fixture,
582 gconstpointer user_data)
584 /* We swap nodes 2 and 3 in the middle that are next to each other */
585 int new_order[5] = { 0, 1, 3, 2, 4 };
590 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_a, "2"));
591 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_b, "3"));
593 gtk_list_store_swap (fixture->store, &iter_a, &iter_b);
594 check_model (fixture, new_order, -1);
598 list_store_test_swap_middle_apart (ListStore *fixture,
599 gconstpointer user_data)
601 /* We swap nodes 1 and 3 in the middle that are apart from each other */
602 int new_order[5] = { 0, 3, 2, 1, 4 };
607 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_a, "1"));
608 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_b, "3"));
610 gtk_list_store_swap (fixture->store, &iter_a, &iter_b);
611 check_model (fixture, new_order, -1);
615 list_store_test_swap_end (ListStore *fixture,
616 gconstpointer user_data)
618 /* We swap nodes 3 and 4 at the end */
619 int new_order[5] = { 0, 1, 2, 4, 3 };
624 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_a, "3"));
625 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter_b, "4"));
627 gtk_list_store_swap (fixture->store, &iter_a, &iter_b);
628 check_model (fixture, new_order, -1);
632 list_store_test_swap_single (void)
635 GtkTreeIter iter_copy;
638 store = gtk_list_store_new (1, G_TYPE_INT);
640 /* Check if swap on a store with a single node does not corrupt
644 gtk_list_store_append (store, &iter);
647 gtk_list_store_swap (store, &iter, &iter);
648 g_assert (iters_equal (&iter, &iter_copy));
649 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
650 g_assert (iters_equal (&iter, &iter_copy));
652 g_object_unref (store);
658 list_store_test_move_after_from_start (ListStore *fixture,
659 gconstpointer user_data)
661 /* We move node 0 after 2 */
662 int new_order[5] = { 1, 2, 0, 3, 4 };
665 GtkTreeIter position;
667 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "0"));
668 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "2"));
670 gtk_list_store_move_after (fixture->store, &iter, &position);
671 check_model (fixture, new_order, -1);
675 list_store_test_move_after_next (ListStore *fixture,
676 gconstpointer user_data)
678 /* We move node 2 after 3 */
679 int new_order[5] = { 0, 1, 3, 2, 4 };
682 GtkTreeIter position;
684 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "2"));
685 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "3"));
687 gtk_list_store_move_after (fixture->store, &iter, &position);
688 check_model (fixture, new_order, -1);
692 list_store_test_move_after_apart (ListStore *fixture,
693 gconstpointer user_data)
695 /* We move node 1 after 3 */
696 int new_order[5] = { 0, 2, 3, 1, 4 };
699 GtkTreeIter position;
701 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "1"));
702 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "3"));
704 gtk_list_store_move_after (fixture->store, &iter, &position);
705 check_model (fixture, new_order, -1);
709 list_store_test_move_after_end (ListStore *fixture,
710 gconstpointer user_data)
712 /* We move node 2 after 4 */
713 int new_order[5] = { 0, 1, 3, 4, 2 };
716 GtkTreeIter position;
718 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "2"));
719 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "4"));
721 gtk_list_store_move_after (fixture->store, &iter, &position);
722 check_model (fixture, new_order, -1);
726 list_store_test_move_after_from_end (ListStore *fixture,
727 gconstpointer user_data)
729 /* We move node 4 after 1 */
730 int new_order[5] = { 0, 1, 4, 2, 3 };
733 GtkTreeIter position;
735 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "4"));
736 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "1"));
738 gtk_list_store_move_after (fixture->store, &iter, &position);
739 check_model (fixture, new_order, -1);
743 list_store_test_move_after_change_ends (ListStore *fixture,
744 gconstpointer user_data)
746 /* We move 0 after 4, this will cause both the head and tail ends to
749 int new_order[5] = { 1, 2, 3, 4, 0 };
752 GtkTreeIter position;
754 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "0"));
755 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "4"));
757 gtk_list_store_move_after (fixture->store, &iter, &position);
758 check_model (fixture, new_order, -1);
762 list_store_test_move_after_NULL (ListStore *fixture,
763 gconstpointer user_data)
765 /* We move node 2, NULL should prepend */
766 int new_order[5] = { 2, 0, 1, 3, 4 };
770 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "2"));
772 gtk_list_store_move_after (fixture->store, &iter, NULL);
773 check_model (fixture, new_order, -1);
777 list_store_test_move_after_single (void)
780 GtkTreeIter iter_copy;
783 store = gtk_list_store_new (1, G_TYPE_INT);
785 /* Check if move-after on a store with a single node does not corrupt
789 gtk_list_store_append (store, &iter);
792 gtk_list_store_move_after (store, &iter, NULL);
793 g_assert (iters_equal (&iter, &iter_copy));
794 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
795 g_assert (iters_equal (&iter, &iter_copy));
797 gtk_list_store_move_after (store, &iter, &iter);
798 g_assert (iters_equal (&iter, &iter_copy));
799 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
800 g_assert (iters_equal (&iter, &iter_copy));
802 g_object_unref (store);
808 list_store_test_move_before_next (ListStore *fixture,
809 gconstpointer user_data)
811 /* We move node 3 before 2 */
812 int new_order[5] = { 0, 1, 3, 2, 4 };
815 GtkTreeIter position;
817 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "3"));
818 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "2"));
820 gtk_list_store_move_before (fixture->store, &iter, &position);
821 check_model (fixture, new_order, -1);
825 list_store_test_move_before_apart (ListStore *fixture,
826 gconstpointer user_data)
828 /* We move node 1 before 3 */
829 int new_order[5] = { 0, 2, 1, 3, 4 };
832 GtkTreeIter position;
834 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "1"));
835 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "3"));
837 gtk_list_store_move_before (fixture->store, &iter, &position);
838 check_model (fixture, new_order, -1);
842 list_store_test_move_before_to_start (ListStore *fixture,
843 gconstpointer user_data)
845 /* We move node 2 before 0 */
846 int new_order[5] = { 2, 0, 1, 3, 4 };
849 GtkTreeIter position;
851 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "2"));
852 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "0"));
854 gtk_list_store_move_before (fixture->store, &iter, &position);
855 check_model (fixture, new_order, -1);
859 list_store_test_move_before_from_end (ListStore *fixture,
860 gconstpointer user_data)
862 /* We move node 4 before 2 (replace end) */
863 int new_order[5] = { 0, 1, 4, 2, 3 };
866 GtkTreeIter position;
868 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "4"));
869 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "2"));
871 gtk_list_store_move_before (fixture->store, &iter, &position);
872 check_model (fixture, new_order, -1);
876 list_store_test_move_before_change_ends (ListStore *fixture,
877 gconstpointer user_data)
879 /* We move node 4 before 0 */
880 int new_order[5] = { 4, 0, 1, 2, 3 };
883 GtkTreeIter position;
885 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "4"));
886 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &position, "0"));
888 gtk_list_store_move_before (fixture->store, &iter, &position);
889 check_model (fixture, new_order, -1);
893 list_store_test_move_before_NULL (ListStore *fixture,
894 gconstpointer user_data)
896 /* We move node 2, NULL should append */
897 int new_order[5] = { 0, 1, 3, 4, 2 };
901 g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store), &iter, "2"));
903 gtk_list_store_move_before (fixture->store, &iter, NULL);
904 check_model (fixture, new_order, -1);
908 list_store_test_move_before_single (void)
911 GtkTreeIter iter_copy;
914 store = gtk_list_store_new (1, G_TYPE_INT);
916 /* Check if move-before on a store with a single node does not corrupt
920 gtk_list_store_append (store, &iter);
923 gtk_list_store_move_before (store, &iter, NULL);
924 g_assert (iters_equal (&iter, &iter_copy));
925 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
926 g_assert (iters_equal (&iter, &iter_copy));
928 gtk_list_store_move_before (store, &iter, &iter);
929 g_assert (iters_equal (&iter, &iter_copy));
930 g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
931 g_assert (iters_equal (&iter, &iter_copy));
933 g_object_unref (store);
937 /* iter invalidation */
940 list_store_test_iter_previous_invalid (ListStore *fixture,
941 gconstpointer user_data)
945 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (fixture->store), &iter);
947 g_assert (gtk_tree_model_iter_previous (GTK_TREE_MODEL (fixture->store),
949 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter) == FALSE);
950 g_assert (iter.stamp == 0);
954 list_store_test_iter_next_invalid (ListStore *fixture,
955 gconstpointer user_data)
960 path = gtk_tree_path_new_from_indices (4, -1);
961 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &iter, path);
962 gtk_tree_path_free (path);
964 g_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store),
966 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter) == FALSE);
967 g_assert (iter.stamp == 0);
971 list_store_test_iter_children_invalid (ListStore *fixture,
972 gconstpointer user_data)
974 GtkTreeIter iter, child;
976 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (fixture->store), &iter);
977 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter) == TRUE);
979 g_assert (gtk_tree_model_iter_children (GTK_TREE_MODEL (fixture->store),
980 &child, &iter) == FALSE);
981 g_assert (gtk_list_store_iter_is_valid (fixture->store, &child) == FALSE);
982 g_assert (child.stamp == 0);
986 list_store_test_iter_nth_child_invalid (ListStore *fixture,
987 gconstpointer user_data)
989 GtkTreeIter iter, child;
991 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (fixture->store), &iter);
992 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter) == TRUE);
994 g_assert (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (fixture->store),
995 &child, &iter, 0) == FALSE);
996 g_assert (gtk_list_store_iter_is_valid (fixture->store, &child) == FALSE);
997 g_assert (child.stamp == 0);
1001 list_store_test_iter_parent_invalid (ListStore *fixture,
1002 gconstpointer user_data)
1004 GtkTreeIter iter, child;
1006 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (fixture->store), &child);
1007 g_assert (gtk_list_store_iter_is_valid (fixture->store, &child) == TRUE);
1009 g_assert (gtk_tree_model_iter_parent (GTK_TREE_MODEL (fixture->store),
1010 &iter, &child) == FALSE);
1011 g_assert (gtk_list_store_iter_is_valid (fixture->store, &iter) == FALSE);
1012 g_assert (iter.stamp == 0);
1019 register_list_store_tests (void)
1022 g_test_add_func ("/ListStore/insert-high-values",
1023 list_store_test_insert_high_values);
1024 g_test_add_func ("/ListStore/append",
1025 list_store_test_append);
1026 g_test_add_func ("/ListStore/prepend",
1027 list_store_test_prepend);
1028 g_test_add_func ("/ListStore/insert-after",
1029 list_store_test_insert_after);
1030 g_test_add_func ("/ListStore/insert-after-NULL",
1031 list_store_test_insert_after_NULL);
1032 g_test_add_func ("/ListStore/insert-before",
1033 list_store_test_insert_before);
1034 g_test_add_func ("/ListStore/insert-before-NULL",
1035 list_store_test_insert_before_NULL);
1037 /* setting values (FIXME) */
1038 g_test_add_func ("/ListStore/set-gvalue-to-transform",
1039 list_store_set_gvalue_to_transform);
1042 g_test_add ("/ListStore/remove-begin", ListStore, NULL,
1043 list_store_setup, list_store_test_remove_begin,
1044 list_store_teardown);
1045 g_test_add ("/ListStore/remove-middle", ListStore, NULL,
1046 list_store_setup, list_store_test_remove_middle,
1047 list_store_teardown);
1048 g_test_add ("/ListStore/remove-end", ListStore, NULL,
1049 list_store_setup, list_store_test_remove_end,
1050 list_store_teardown);
1052 g_test_add ("/ListStore/clear", ListStore, NULL,
1053 list_store_setup, list_store_test_clear,
1054 list_store_teardown);
1057 g_test_add ("/ListStore/reorder", ListStore, NULL,
1058 list_store_setup, list_store_test_reorder,
1059 list_store_teardown);
1062 g_test_add ("/ListStore/swap-begin", ListStore, NULL,
1063 list_store_setup, list_store_test_swap_begin,
1064 list_store_teardown);
1065 g_test_add ("/ListStore/swap-middle-next", ListStore, NULL,
1066 list_store_setup, list_store_test_swap_middle_next,
1067 list_store_teardown);
1068 g_test_add ("/ListStore/swap-middle-apart", ListStore, NULL,
1069 list_store_setup, list_store_test_swap_middle_apart,
1070 list_store_teardown);
1071 g_test_add ("/ListStore/swap-end", ListStore, NULL,
1072 list_store_setup, list_store_test_swap_end,
1073 list_store_teardown);
1074 g_test_add_func ("/ListStore/swap-single",
1075 list_store_test_swap_single);
1078 g_test_add ("/ListStore/move-after-from-start", ListStore, NULL,
1079 list_store_setup, list_store_test_move_after_from_start,
1080 list_store_teardown);
1081 g_test_add ("/ListStore/move-after-next", ListStore, NULL,
1082 list_store_setup, list_store_test_move_after_next,
1083 list_store_teardown);
1084 g_test_add ("/ListStore/move-after-apart", ListStore, NULL,
1085 list_store_setup, list_store_test_move_after_apart,
1086 list_store_teardown);
1087 g_test_add ("/ListStore/move-after-end", ListStore, NULL,
1088 list_store_setup, list_store_test_move_after_end,
1089 list_store_teardown);
1090 g_test_add ("/ListStore/move-after-from-end", ListStore, NULL,
1091 list_store_setup, list_store_test_move_after_from_end,
1092 list_store_teardown);
1093 g_test_add ("/ListStore/move-after-change-ends", ListStore, NULL,
1094 list_store_setup, list_store_test_move_after_change_ends,
1095 list_store_teardown);
1096 g_test_add ("/ListStore/move-after-NULL", ListStore, NULL,
1097 list_store_setup, list_store_test_move_after_NULL,
1098 list_store_teardown);
1099 g_test_add_func ("/ListStore/move-after-single",
1100 list_store_test_move_after_single);
1102 g_test_add ("/ListStore/move-before-next", ListStore, NULL,
1103 list_store_setup, list_store_test_move_before_next,
1104 list_store_teardown);
1105 g_test_add ("/ListStore/move-before-apart", ListStore, NULL,
1106 list_store_setup, list_store_test_move_before_apart,
1107 list_store_teardown);
1108 g_test_add ("/ListStore/move-before-to-start", ListStore, NULL,
1109 list_store_setup, list_store_test_move_before_to_start,
1110 list_store_teardown);
1111 g_test_add ("/ListStore/move-before-from-end", ListStore, NULL,
1112 list_store_setup, list_store_test_move_before_from_end,
1113 list_store_teardown);
1114 g_test_add ("/ListStore/move-before-change-ends", ListStore, NULL,
1115 list_store_setup, list_store_test_move_before_change_ends,
1116 list_store_teardown);
1117 g_test_add ("/ListStore/move-before-NULL", ListStore, NULL,
1118 list_store_setup, list_store_test_move_before_NULL,
1119 list_store_teardown);
1120 g_test_add_func ("/ListStore/move-before-single",
1121 list_store_test_move_before_single);
1123 /* iter invalidation */
1124 g_test_add ("/ListStore/iter-prev-invalid", ListStore, NULL,
1125 list_store_setup, list_store_test_iter_previous_invalid,
1126 list_store_teardown);
1127 g_test_add ("/ListStore/iter-next-invalid", ListStore, NULL,
1128 list_store_setup, list_store_test_iter_next_invalid,
1129 list_store_teardown);
1130 g_test_add ("/ListStore/iter-children-invalid", ListStore, NULL,
1131 list_store_setup, list_store_test_iter_children_invalid,
1132 list_store_teardown);
1133 g_test_add ("/ListStore/iter-nth-child-invalid", ListStore, NULL,
1134 list_store_setup, list_store_test_iter_nth_child_invalid,
1135 list_store_teardown);
1136 g_test_add ("/ListStore/iter-parent-invalid", ListStore, NULL,
1137 list_store_setup, list_store_test_iter_parent_invalid,
1138 list_store_teardown);