1 /* Extensive GtkTreeModelFilter tests.
2 * Copyright (C) 2009,2011 Kristian Rietveld <kris@gtk.org>
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "treemodel.h"
24 #include "gtktreemodelrefcount.h"
27 * - Proper coverage checking to see if the unit tests cover
29 * - Check if the iterator stamp is incremented at the correct times.
31 * For more thorough testing:
32 * - Test with randomized models.
33 * - Extensively test a filter model wrapping a sort model,
34 * or a sort model wrapping a filter model by:
35 * # Checking structure.
36 * # Checking for correct signals emissions.
37 * # Checking correct reference counting.
38 * # Tests should be done with the sort and filter model
39 * in various filtering and sorting states.
47 #define LEVEL_LENGTH 5
50 create_tree_store_set_values (GtkTreeStore *store,
57 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
58 path_string = gtk_tree_path_to_string (path);
60 gtk_tree_store_set (store, iter,
65 gtk_tree_path_free (path);
70 create_tree_store_recurse (int depth,
77 for (i = 0; i < LEVEL_LENGTH; i++)
81 gtk_tree_store_insert (store, &iter, parent, i);
82 create_tree_store_set_values (store, &iter, visible);
85 create_tree_store_recurse (depth - 1, store, &iter, visible);
90 create_tree_store (int depth,
95 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
97 create_tree_store_recurse (depth, store, NULL, visible);
108 GtkWidget *tree_view;
111 GtkTreeModelFilter *filter;
113 SignalMonitor *monitor;
115 guint block_signals : 1;
120 filter_test_store_signal (FilterTest *fixture)
122 if (fixture->block_signals)
123 g_signal_stop_emission_by_name (fixture->store, "row-changed");
128 filter_test_setup_generic (FilterTest *fixture,
129 gconstpointer test_data,
134 const GtkTreePath *vroot = test_data;
135 GtkTreeModel *filter;
137 fixture->store = create_tree_store (depth, !empty);
139 g_signal_connect_swapped (fixture->store, "row-changed",
140 G_CALLBACK (filter_test_store_signal), fixture);
142 /* Please forgive me for casting const away. */
143 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture->store),
144 (GtkTreePath *)vroot);
145 fixture->filter = GTK_TREE_MODEL_FILTER (filter);
148 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
150 /* We need a tree view that's listening to get ref counting from that
153 fixture->tree_view = gtk_tree_view_new_with_model (filter);
155 fixture->monitor = signal_monitor_new (filter);
159 filter_test_setup_expand_root (FilterTest *fixture)
164 path = gtk_tree_path_new_from_indices (0, -1);
166 for (i = 0; i < LEVEL_LENGTH; i++)
168 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view),
170 gtk_tree_path_next (path);
172 gtk_tree_path_free (path);
176 filter_test_setup (FilterTest *fixture,
177 gconstpointer test_data)
179 filter_test_setup_generic (fixture, test_data, 3, FALSE, FALSE);
183 filter_test_setup_empty (FilterTest *fixture,
184 gconstpointer test_data)
186 filter_test_setup_generic (fixture, test_data, 3, TRUE, FALSE);
190 filter_test_setup_unfiltered (FilterTest *fixture,
191 gconstpointer test_data)
193 filter_test_setup_generic (fixture, test_data, 3, FALSE, TRUE);
197 filter_test_setup_unfiltered_root_expanded (FilterTest *fixture,
198 gconstpointer test_data)
200 filter_test_setup_unfiltered (fixture, test_data);
201 filter_test_setup_expand_root (fixture);
205 filter_test_setup_empty_unfiltered (FilterTest *fixture,
206 gconstpointer test_data)
208 filter_test_setup_generic (fixture, test_data, 3, TRUE, TRUE);
212 filter_test_setup_empty_unfiltered_root_expanded (FilterTest *fixture,
213 gconstpointer test_data)
215 filter_test_setup_empty_unfiltered (fixture, test_data);
216 filter_test_setup_expand_root (fixture);
220 strip_virtual_root (GtkTreePath *path,
221 GtkTreePath *root_path)
223 GtkTreePath *real_path;
228 int depth = gtk_tree_path_get_depth (path);
229 int root_depth = gtk_tree_path_get_depth (root_path);
231 real_path = gtk_tree_path_new ();
233 for (j = 0; j < depth - root_depth; j++)
234 gtk_tree_path_append_index (real_path,
235 gtk_tree_path_get_indices (path)[root_depth + j]);
238 real_path = gtk_tree_path_copy (path);
244 count_visible (FilterTest *fixture,
245 GtkTreePath *store_path)
251 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
254 for (i = 0; i < LEVEL_LENGTH; i++)
258 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
270 filter_test_append_refilter_signals_recurse (FilterTest *fixture,
271 GtkTreePath *store_path,
272 GtkTreePath *filter_path,
274 GtkTreePath *root_path)
277 int rows_deleted = 0;
280 gtk_tree_path_down (store_path);
281 gtk_tree_path_down (filter_path);
283 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
286 for (i = 0; i < LEVEL_LENGTH; i++)
289 GtkTreePath *real_path;
291 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
296 (!gtk_tree_path_is_descendant (store_path, root_path)
297 || !gtk_tree_path_compare (store_path, root_path)))
299 if (!gtk_tree_path_compare (store_path, root_path))
302 && gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
305 GtkTreePath *store_copy;
306 GtkTreePath *filter_copy;
308 store_copy = gtk_tree_path_copy (store_path);
309 filter_copy = gtk_tree_path_copy (filter_path);
310 filter_test_append_refilter_signals_recurse (fixture,
315 gtk_tree_path_free (store_copy);
316 gtk_tree_path_free (filter_copy);
320 gtk_tree_path_next (store_path);
321 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
324 gtk_tree_path_next (filter_path);
329 real_path = strip_virtual_root (filter_path, root_path);
333 /* This row will be inserted */
334 signal_monitor_append_signal_path (fixture->monitor, ROW_CHANGED,
337 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
340 signal_monitor_append_signal_path (fixture->monitor,
341 ROW_HAS_CHILD_TOGGLED,
346 GtkTreePath *store_copy;
347 GtkTreePath *filter_copy;
349 store_copy = gtk_tree_path_copy (store_path);
350 filter_copy = gtk_tree_path_copy (filter_path);
351 filter_test_append_refilter_signals_recurse (fixture,
356 gtk_tree_path_free (store_copy);
357 gtk_tree_path_free (filter_copy);
361 GtkTreePath *tmp_path;
363 /* If all child rows are invisible, then the last row to
364 * become invisible will emit row-has-child-toggled on the
368 tmp_path = gtk_tree_path_copy (store_path);
369 gtk_tree_path_append_index (tmp_path, 0);
371 if (count_visible (fixture, tmp_path) == 0)
372 signal_monitor_append_signal_path (fixture->monitor,
373 ROW_HAS_CHILD_TOGGLED,
376 gtk_tree_path_free (tmp_path);
380 gtk_tree_path_next (filter_path);
384 /* This row will be deleted */
386 signal_monitor_append_signal_path (fixture->monitor, ROW_DELETED,
390 gtk_tree_path_free (real_path);
392 gtk_tree_path_next (store_path);
393 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
396 if (rows_deleted == LEVEL_LENGTH
397 && gtk_tree_path_get_depth (filter_path) > 1)
399 GtkTreePath *real_path;
401 gtk_tree_path_up (store_path);
402 gtk_tree_path_up (filter_path);
404 /* A row-has-child-toggled will be emitted on the parent */
407 && gtk_tree_path_is_descendant (store_path, root_path)
408 && gtk_tree_path_compare (store_path, root_path)))
410 real_path = strip_virtual_root (filter_path, root_path);
411 signal_monitor_append_signal_path (fixture->monitor,
412 ROW_HAS_CHILD_TOGGLED,
415 gtk_tree_path_free (real_path);
421 filter_test_append_refilter_signals (FilterTest *fixture,
424 /* A special function that walks the tree store like the
425 * model validation functions below.
428 GtkTreePath *filter_path;
430 path = gtk_tree_path_new ();
431 filter_path = gtk_tree_path_new ();
432 filter_test_append_refilter_signals_recurse (fixture,
437 gtk_tree_path_free (path);
438 gtk_tree_path_free (filter_path);
442 filter_test_append_refilter_signals_with_vroot (FilterTest *fixture,
444 GtkTreePath *root_path)
446 /* A special function that walks the tree store like the
447 * model validation functions below.
450 GtkTreePath *filter_path;
452 path = gtk_tree_path_new ();
453 filter_path = gtk_tree_path_new ();
454 filter_test_append_refilter_signals_recurse (fixture,
459 gtk_tree_path_free (path);
460 gtk_tree_path_free (filter_path);
464 filter_test_enable_filter (FilterTest *fixture)
466 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
467 gtk_tree_model_filter_refilter (fixture->filter);
471 filter_test_block_signals (FilterTest *fixture)
473 fixture->block_signals = TRUE;
477 filter_test_unblock_signals (FilterTest *fixture)
479 fixture->block_signals = FALSE;
483 filter_test_teardown (FilterTest *fixture,
484 gconstpointer test_data)
486 signal_monitor_free (fixture->monitor);
488 gtk_widget_destroy (fixture->tree_view);
490 g_object_unref (fixture->filter);
491 g_object_unref (fixture->store);
495 * Model structure validation
499 check_filter_model_recurse (FilterTest *fixture,
500 GtkTreePath *store_parent_path,
501 GtkTreePath *filter_parent_path)
504 GtkTreeIter store_iter;
505 GtkTreeIter filter_iter;
506 gboolean store_has_next, filter_has_next;
508 gtk_tree_path_down (store_parent_path);
509 gtk_tree_path_down (filter_parent_path);
511 store_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
512 &store_iter, store_parent_path);
513 filter_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->filter),
514 &filter_iter, filter_parent_path);
516 for (i = 0; i < LEVEL_LENGTH; i++)
520 g_return_if_fail (store_has_next == TRUE);
522 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
530 gchar *filter_str, *store_str;
532 g_return_if_fail (filter_has_next == TRUE);
535 tmp = gtk_tree_model_get_path (GTK_TREE_MODEL (fixture->filter),
537 g_return_if_fail (gtk_tree_path_compare (tmp, filter_parent_path) == 0);
539 /* Verify model content */
540 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
544 gtk_tree_model_get (GTK_TREE_MODEL (fixture->filter),
549 g_return_if_fail (g_strcmp0 (store_str, filter_str) == 0);
554 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->filter),
557 g_return_if_fail (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store), &store_iter));
559 check_filter_model_recurse (fixture,
560 gtk_tree_path_copy (store_parent_path),
564 /* Only when we do not recurse we need to free tmp */
565 gtk_tree_path_free (tmp);
567 gtk_tree_path_next (filter_parent_path);
568 filter_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->filter), &filter_iter);
571 gtk_tree_path_next (store_parent_path);
572 store_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &store_iter);
575 /* Both models should have no more content! */
576 g_return_if_fail (store_has_next == FALSE);
577 g_return_if_fail (filter_has_next == FALSE);
579 gtk_tree_path_free (store_parent_path);
580 gtk_tree_path_free (filter_parent_path);
584 check_filter_model (FilterTest *fixture)
588 if (fixture->monitor)
589 signal_monitor_assert_is_empty (fixture->monitor);
591 path = gtk_tree_path_new ();
593 check_filter_model_recurse (fixture, path, gtk_tree_path_copy (path));
597 check_filter_model_with_root (FilterTest *fixture,
600 if (fixture->monitor)
601 signal_monitor_assert_is_empty (fixture->monitor);
603 check_filter_model_recurse (fixture,
604 gtk_tree_path_copy (path),
605 gtk_tree_path_new ());
611 check_level_length (GtkTreeModelFilter *filter,
613 const int expected_length)
619 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), NULL);
620 g_assert_cmpint (model_length, ==, expected_length);
625 gboolean retrieved_iter = FALSE;
628 retrieved_iter = gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (filter),
630 g_return_if_fail (retrieved_iter);
631 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), &iter);
632 g_assert_cmpint (model_length, ==, expected_length);
637 set_path_visibility (FilterTest *fixture,
641 GtkTreeIter store_iter;
643 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
645 gtk_tree_store_set (fixture->store, &store_iter,
652 insert_path_with_visibility (FilterTest *fixture,
653 const gchar *path_string,
658 GtkTreeIter parent, iter;
660 path = gtk_tree_path_new_from_string (path_string);
661 position = gtk_tree_path_get_indices (path)[gtk_tree_path_get_depth (path)];
662 gtk_tree_path_up (path);
664 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &parent, path))
666 gtk_tree_store_insert (fixture->store, &iter, &parent, position);
667 create_tree_store_set_values (fixture->store, &iter, visible);
669 gtk_tree_path_free (path);
678 verify_test_suite (FilterTest *fixture,
679 gconstpointer user_data)
681 check_filter_model (fixture);
685 verify_test_suite_vroot (FilterTest *fixture,
686 gconstpointer user_data)
688 check_filter_model_with_root (fixture, (GtkTreePath *)user_data);
693 filled_hide_root_level (FilterTest *fixture,
694 gconstpointer user_data)
696 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
697 set_path_visibility (fixture, "2", FALSE);
698 check_filter_model (fixture);
699 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
701 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
702 set_path_visibility (fixture, "0", FALSE);
703 check_filter_model (fixture);
704 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
706 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
707 set_path_visibility (fixture, "4", FALSE);
708 check_filter_model (fixture);
709 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
713 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
714 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
716 set_path_visibility (fixture, "1", FALSE);
717 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
719 set_path_visibility (fixture, "3", FALSE);
720 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 5);
722 check_filter_model (fixture);
725 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
726 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
727 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
728 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
730 set_path_visibility (fixture, "1", TRUE);
731 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
733 set_path_visibility (fixture, "3", TRUE);
734 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
736 check_filter_model (fixture);
740 filled_hide_child_levels (FilterTest *fixture,
741 gconstpointer user_data)
743 set_path_visibility (fixture, "0:2", FALSE);
744 check_filter_model (fixture);
745 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
746 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
748 set_path_visibility (fixture, "0:4", FALSE);
749 check_filter_model (fixture);
750 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
751 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
753 set_path_visibility (fixture, "0:4:3", FALSE);
754 check_filter_model (fixture);
755 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
756 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
758 set_path_visibility (fixture, "0:4:0", FALSE);
759 set_path_visibility (fixture, "0:4:1", FALSE);
760 set_path_visibility (fixture, "0:4:2", FALSE);
761 set_path_visibility (fixture, "0:4:4", FALSE);
762 check_filter_model (fixture);
763 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
764 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
766 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
767 set_path_visibility (fixture, "0:4", TRUE);
768 check_filter_model (fixture);
769 check_level_length (fixture->filter, "0:3", 0);
771 set_path_visibility (fixture, "0:2", TRUE);
772 check_filter_model (fixture);
773 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
774 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
775 check_level_length (fixture->filter, "0:4", 0);
777 /* Once 0:4:0 got inserted, 0:4 became a parent. Because 0:4 is
778 * not visible, not signals are emitted.
780 set_path_visibility (fixture, "0:4:2", TRUE);
781 set_path_visibility (fixture, "0:4:4", TRUE);
782 signal_monitor_assert_is_empty (fixture->monitor);
783 check_level_length (fixture->filter, "0:4", 2);
787 filled_hide_child_levels_root_expanded (FilterTest *fixture,
788 gconstpointer user_data)
792 path = gtk_tree_path_new_from_indices (0, -1);
793 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
794 gtk_tree_path_free (path);
796 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
797 set_path_visibility (fixture, "0:2", FALSE);
798 check_filter_model (fixture);
799 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
800 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
802 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
803 set_path_visibility (fixture, "0:4", FALSE);
804 check_filter_model (fixture);
805 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
806 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
808 set_path_visibility (fixture, "0:4:3", FALSE);
809 check_filter_model (fixture);
810 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
811 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
813 set_path_visibility (fixture, "0:4:0", FALSE);
814 set_path_visibility (fixture, "0:4:1", FALSE);
815 set_path_visibility (fixture, "0:4:2", FALSE);
816 set_path_visibility (fixture, "0:4:4", FALSE);
817 check_filter_model (fixture);
818 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
819 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
821 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
822 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
823 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
824 set_path_visibility (fixture, "0:4", TRUE);
825 check_filter_model (fixture);
826 check_level_length (fixture->filter, "0:3", 0);
828 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
829 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
830 set_path_visibility (fixture, "0:2", TRUE);
831 check_filter_model (fixture);
832 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
833 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
834 check_level_length (fixture->filter, "0:4", 0);
836 /* has-child-toggled for 0:4 is required. */
837 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
838 set_path_visibility (fixture, "0:4:2", TRUE);
839 set_path_visibility (fixture, "0:4:4", TRUE);
840 signal_monitor_assert_is_empty (fixture->monitor);
841 check_level_length (fixture->filter, "0:4", 2);
846 filled_vroot_hide_root_level (FilterTest *fixture,
847 gconstpointer user_data)
849 GtkTreePath *path = (GtkTreePath *)user_data;
851 /* These changes do not affect the filter's root level */
852 set_path_visibility (fixture, "0", FALSE);
853 check_filter_model_with_root (fixture, path);
854 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
855 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
857 set_path_visibility (fixture, "4", FALSE);
858 check_filter_model_with_root (fixture, path);
859 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
860 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
862 /* Even though we set the virtual root parent node to FALSE,
863 * the virtual root contents remain.
865 set_path_visibility (fixture, "2", FALSE);
866 check_filter_model_with_root (fixture, path);
867 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
868 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
871 set_path_visibility (fixture, "1", FALSE);
872 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
873 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
875 set_path_visibility (fixture, "3", FALSE);
876 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
877 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
879 check_filter_model_with_root (fixture, path);
882 set_path_visibility (fixture, "2", TRUE);
883 check_filter_model_with_root (fixture, path);
884 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
885 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
887 set_path_visibility (fixture, "1", TRUE);
888 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
889 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
891 set_path_visibility (fixture, "3", TRUE);
892 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
893 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
895 check_filter_model_with_root (fixture, path);
897 /* Now test changes in the virtual root level */
898 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
899 set_path_visibility (fixture, "2:2", FALSE);
900 check_filter_model_with_root (fixture, path);
901 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
903 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "3");
904 set_path_visibility (fixture, "2:4", FALSE);
905 check_filter_model_with_root (fixture, path);
906 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
908 set_path_visibility (fixture, "1:4", FALSE);
909 check_filter_model_with_root (fixture, path);
910 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
912 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "3");
913 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "3");
914 set_path_visibility (fixture, "2:4", TRUE);
915 check_filter_model_with_root (fixture, path);
916 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
918 set_path_visibility (fixture, "2", FALSE);
919 check_filter_model_with_root (fixture, path);
920 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
922 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
923 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
924 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
925 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
926 set_path_visibility (fixture, "2:0", FALSE);
927 set_path_visibility (fixture, "2:1", FALSE);
928 set_path_visibility (fixture, "2:2", FALSE);
929 set_path_visibility (fixture, "2:3", FALSE);
930 set_path_visibility (fixture, "2:4", FALSE);
931 check_filter_model_with_root (fixture, path);
932 check_level_length (fixture->filter, NULL, 0);
934 set_path_visibility (fixture, "2", TRUE);
935 check_filter_model_with_root (fixture, path);
936 check_level_length (fixture->filter, NULL, 0);
938 set_path_visibility (fixture, "1:4", FALSE);
939 check_filter_model_with_root (fixture, path);
940 check_level_length (fixture->filter, NULL, 0);
942 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
943 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
944 set_path_visibility (fixture, "2:4", TRUE);
945 check_filter_model_with_root (fixture, path);
946 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
948 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
949 set_path_visibility (fixture, "2:4", FALSE);
950 check_filter_model_with_root (fixture, path);
951 check_level_length (fixture->filter, NULL, 0);
953 set_path_visibility (fixture, "2", FALSE);
954 check_filter_model_with_root (fixture, path);
955 check_level_length (fixture->filter, NULL, 0);
957 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
958 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
959 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
960 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
961 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2");
962 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
963 set_path_visibility (fixture, "2:0", TRUE);
964 set_path_visibility (fixture, "2:1", TRUE);
965 set_path_visibility (fixture, "2:2", TRUE);
966 check_filter_model_with_root (fixture, path);
967 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
969 set_path_visibility (fixture, "2", TRUE);
970 check_filter_model_with_root (fixture, path);
971 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
975 filled_vroot_hide_child_levels (FilterTest *fixture,
976 gconstpointer user_data)
978 GtkTreePath *path = (GtkTreePath *)user_data;
980 set_path_visibility (fixture, "2:0:2", FALSE);
981 check_filter_model_with_root (fixture, path);
982 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
983 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
985 set_path_visibility (fixture, "2:0:4", FALSE);
986 check_filter_model_with_root (fixture, path);
987 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
988 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
990 set_path_visibility (fixture, "2:0:4:3", FALSE);
991 check_filter_model_with_root (fixture, path);
992 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
993 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
995 set_path_visibility (fixture, "2:0:4:0", FALSE);
996 set_path_visibility (fixture, "2:0:4:1", FALSE);
997 set_path_visibility (fixture, "2:0:4:2", FALSE);
998 set_path_visibility (fixture, "2:0:4:4", FALSE);
999 check_filter_model_with_root (fixture, path);
1000 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1001 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1003 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
1004 set_path_visibility (fixture, "2:0:4", TRUE);
1005 check_filter_model_with_root (fixture, path);
1006 check_level_length (fixture->filter, "0:3", 0);
1008 set_path_visibility (fixture, "2:0:2", TRUE);
1009 check_filter_model_with_root (fixture, path);
1010 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1011 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1012 check_level_length (fixture->filter, "0:4", 0);
1014 /* Once 0:4:0 got inserted, 0:4 became a parent. However, 0:4 is not
1015 * visible, so no signal should be emitted.
1017 set_path_visibility (fixture, "2:0:4:2", TRUE);
1018 set_path_visibility (fixture, "2:0:4:4", TRUE);
1019 check_level_length (fixture->filter, "0:4", 2);
1020 signal_monitor_assert_is_empty (fixture->monitor);
1024 filled_vroot_hide_child_levels_root_expanded (FilterTest *fixture,
1025 gconstpointer user_data)
1027 GtkTreePath *path = (GtkTreePath *)user_data;
1028 GtkTreePath *tmp_path;
1030 tmp_path = gtk_tree_path_new_from_indices (0, -1);
1031 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), tmp_path, FALSE);
1032 gtk_tree_path_free (tmp_path);
1034 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
1035 set_path_visibility (fixture, "2:0:2", FALSE);
1036 check_filter_model_with_root (fixture, path);
1037 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1038 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
1040 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
1041 set_path_visibility (fixture, "2:0:4", FALSE);
1042 check_filter_model_with_root (fixture, path);
1043 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1044 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1046 set_path_visibility (fixture, "2:0:4:3", FALSE);
1047 check_filter_model_with_root (fixture, path);
1048 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1049 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1051 set_path_visibility (fixture, "2:0:4:0", FALSE);
1052 set_path_visibility (fixture, "2:0:4:1", FALSE);
1053 set_path_visibility (fixture, "2:0:4:2", FALSE);
1054 set_path_visibility (fixture, "2:0:4:4", FALSE);
1055 check_filter_model_with_root (fixture, path);
1056 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1057 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1059 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
1060 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
1061 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
1062 set_path_visibility (fixture, "2:0:4", TRUE);
1063 check_filter_model_with_root (fixture, path);
1064 check_level_length (fixture->filter, "0:3", 0);
1066 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
1067 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
1068 set_path_visibility (fixture, "2:0:2", TRUE);
1069 check_filter_model_with_root (fixture, path);
1070 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1071 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1072 check_level_length (fixture->filter, "0:4", 0);
1074 /* Once 0:4:0 got inserted, 0:4 became a parent */
1075 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
1076 set_path_visibility (fixture, "2:0:4:2", TRUE);
1077 set_path_visibility (fixture, "2:0:4:4", TRUE);
1078 check_level_length (fixture->filter, "0:4", 2);
1079 signal_monitor_assert_is_empty (fixture->monitor);
1083 empty_show_nodes (FilterTest *fixture,
1084 gconstpointer user_data)
1086 check_filter_model (fixture);
1087 check_level_length (fixture->filter, NULL, 0);
1089 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1090 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1091 set_path_visibility (fixture, "3", TRUE);
1092 check_filter_model (fixture);
1093 check_level_length (fixture->filter, NULL, 1);
1094 check_level_length (fixture->filter, "0", 0);
1096 set_path_visibility (fixture, "3:2:2", TRUE);
1097 check_filter_model (fixture);
1098 check_level_length (fixture->filter, NULL, 1);
1099 check_level_length (fixture->filter, "0", 0);
1101 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1102 set_path_visibility (fixture, "3:2", TRUE);
1103 check_filter_model (fixture);
1104 check_level_length (fixture->filter, NULL, 1);
1105 check_level_length (fixture->filter, "0", 1);
1106 check_level_length (fixture->filter, "0:0", 1);
1107 check_level_length (fixture->filter, "0:0:0", 0);
1109 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1110 set_path_visibility (fixture, "3", FALSE);
1111 check_filter_model (fixture);
1112 check_level_length (fixture->filter, NULL, 0);
1114 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1115 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1116 set_path_visibility (fixture, "3:2:1", TRUE);
1117 set_path_visibility (fixture, "3", TRUE);
1118 check_filter_model (fixture);
1119 check_level_length (fixture->filter, NULL, 1);
1120 check_level_length (fixture->filter, "0", 1);
1121 check_level_length (fixture->filter, "0:0", 2);
1122 check_level_length (fixture->filter, "0:0:0", 0);
1126 empty_show_multiple_nodes (FilterTest *fixture,
1127 gconstpointer user_data)
1130 GtkTreePath *changed_path;
1132 check_filter_model (fixture);
1133 check_level_length (fixture->filter, NULL, 0);
1135 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1136 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1137 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1138 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1140 /* We simulate a change in visible func condition with this. The
1141 * visibility state of multiple nodes changes at once, we emit row-changed
1142 * for these nodes (and others) after that.
1144 filter_test_block_signals (fixture);
1145 set_path_visibility (fixture, "3", TRUE);
1146 set_path_visibility (fixture, "4", TRUE);
1147 filter_test_unblock_signals (fixture);
1149 changed_path = gtk_tree_path_new ();
1150 gtk_tree_path_append_index (changed_path, 2);
1151 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1152 &iter, changed_path);
1153 /* Invisible node - so no signals expected */
1154 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1155 changed_path, &iter);
1157 gtk_tree_path_next (changed_path);
1158 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1159 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1160 changed_path, &iter);
1162 gtk_tree_path_next (changed_path);
1163 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1164 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1165 changed_path, &iter);
1167 gtk_tree_path_free (changed_path);
1169 check_filter_model (fixture);
1170 check_level_length (fixture->filter, NULL, 2);
1171 check_level_length (fixture->filter, "0", 0);
1173 set_path_visibility (fixture, "3:2:2", TRUE);
1174 check_filter_model (fixture);
1175 check_level_length (fixture->filter, NULL, 2);
1176 check_level_length (fixture->filter, "0", 0);
1178 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1179 set_path_visibility (fixture, "3:2", TRUE);
1180 check_filter_model (fixture);
1181 check_level_length (fixture->filter, NULL, 2);
1182 check_level_length (fixture->filter, "0", 1);
1183 check_level_length (fixture->filter, "0:0", 1);
1184 check_level_length (fixture->filter, "0:0:0", 0);
1186 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1187 set_path_visibility (fixture, "3", FALSE);
1188 check_filter_model (fixture);
1189 check_level_length (fixture->filter, NULL, 1);
1191 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1192 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1193 set_path_visibility (fixture, "3:2:1", TRUE);
1194 set_path_visibility (fixture, "3", TRUE);
1195 check_filter_model (fixture);
1196 check_level_length (fixture->filter, NULL, 2);
1197 check_level_length (fixture->filter, "0", 1);
1198 check_level_length (fixture->filter, "0:0", 2);
1199 check_level_length (fixture->filter, "0:0:0", 0);
1203 empty_vroot_show_nodes (FilterTest *fixture,
1204 gconstpointer user_data)
1206 GtkTreePath *path = (GtkTreePath *)user_data;
1208 check_filter_model_with_root (fixture, path);
1209 check_level_length (fixture->filter, NULL, 0);
1211 set_path_visibility (fixture, "2", TRUE);
1212 check_filter_model_with_root (fixture, path);
1213 check_level_length (fixture->filter, NULL, 0);
1215 set_path_visibility (fixture, "2:2:2", TRUE);
1216 check_filter_model_with_root (fixture, path);
1217 check_level_length (fixture->filter, NULL, 0);
1219 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1220 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1221 set_path_visibility (fixture, "2:2", TRUE);
1222 check_filter_model_with_root (fixture, path);
1223 check_level_length (fixture->filter, NULL, 1);
1224 check_level_length (fixture->filter, "0", 1);
1225 check_level_length (fixture->filter, "0:0", 0);
1227 set_path_visibility (fixture, "3", TRUE);
1228 check_filter_model_with_root (fixture, path);
1229 check_level_length (fixture->filter, NULL, 1);
1231 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1232 set_path_visibility (fixture, "2:2", FALSE);
1233 check_filter_model_with_root (fixture, path);
1234 check_level_length (fixture->filter, NULL, 0);
1236 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1237 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1238 set_path_visibility (fixture, "2:2:1", TRUE);
1239 set_path_visibility (fixture, "2:2", TRUE);
1240 check_filter_model_with_root (fixture, path);
1241 check_level_length (fixture->filter, NULL, 1);
1242 check_level_length (fixture->filter, "0", 2);
1243 check_level_length (fixture->filter, "0:1", 0);
1247 empty_vroot_show_multiple_nodes (FilterTest *fixture,
1248 gconstpointer user_data)
1251 GtkTreePath *changed_path;
1252 GtkTreePath *path = (GtkTreePath *)user_data;
1254 check_filter_model_with_root (fixture, path);
1255 check_level_length (fixture->filter, NULL, 0);
1257 /* We simulate a change in visible func condition with this. The
1258 * visibility state of multiple nodes changes at once, we emit row-changed
1259 * for these nodes (and others) after that.
1261 filter_test_block_signals (fixture);
1262 set_path_visibility (fixture, "2", TRUE);
1263 set_path_visibility (fixture, "3", TRUE);
1264 filter_test_unblock_signals (fixture);
1266 changed_path = gtk_tree_path_new ();
1267 gtk_tree_path_append_index (changed_path, 1);
1268 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1269 &iter, changed_path);
1270 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1271 changed_path, &iter);
1273 gtk_tree_path_next (changed_path);
1274 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1275 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1276 changed_path, &iter);
1278 gtk_tree_path_next (changed_path);
1279 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1280 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1281 changed_path, &iter);
1283 gtk_tree_path_next (changed_path);
1284 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1285 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1286 changed_path, &iter);
1288 gtk_tree_path_free (changed_path);
1290 check_filter_model_with_root (fixture, path);
1291 check_level_length (fixture->filter, NULL, 0);
1293 set_path_visibility (fixture, "2:2:2", TRUE);
1294 check_filter_model_with_root (fixture, path);
1295 check_level_length (fixture->filter, NULL, 0);
1297 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1298 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1299 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1300 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1302 /* Again, we simulate a call to refilter */
1303 filter_test_block_signals (fixture);
1304 set_path_visibility (fixture, "2:2", TRUE);
1305 set_path_visibility (fixture, "2:3", TRUE);
1306 filter_test_unblock_signals (fixture);
1308 changed_path = gtk_tree_path_new ();
1309 gtk_tree_path_append_index (changed_path, 2);
1310 gtk_tree_path_append_index (changed_path, 1);
1311 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1312 &iter, changed_path);
1313 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1314 changed_path, &iter);
1316 gtk_tree_path_next (changed_path);
1317 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1318 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1319 changed_path, &iter);
1321 gtk_tree_path_next (changed_path);
1322 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1323 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1324 changed_path, &iter);
1326 gtk_tree_path_next (changed_path);
1327 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1328 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1329 changed_path, &iter);
1331 gtk_tree_path_free (changed_path);
1333 check_filter_model_with_root (fixture, path);
1334 check_level_length (fixture->filter, NULL, 2);
1335 check_level_length (fixture->filter, "0", 1);
1336 check_level_length (fixture->filter, "0:0", 0);
1338 set_path_visibility (fixture, "3", TRUE);
1339 check_filter_model_with_root (fixture, path);
1340 check_level_length (fixture->filter, NULL, 2);
1342 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1343 set_path_visibility (fixture, "2:2", FALSE);
1344 check_filter_model_with_root (fixture, path);
1345 check_level_length (fixture->filter, NULL, 1);
1347 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1348 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1349 set_path_visibility (fixture, "2:2:1", TRUE);
1350 set_path_visibility (fixture, "2:2", TRUE);
1351 check_filter_model_with_root (fixture, path);
1352 check_level_length (fixture->filter, NULL, 2);
1353 check_level_length (fixture->filter, "0", 2);
1354 check_level_length (fixture->filter, "0:1", 0);
1359 unfiltered_hide_single (FilterTest *fixture,
1360 gconstpointer user_data)
1363 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1364 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1365 set_path_visibility (fixture, "2", FALSE);
1367 signal_monitor_assert_is_empty (fixture->monitor);
1368 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1370 /* The view only shows the root level, so we only expect signals
1371 * for the root level.
1373 filter_test_append_refilter_signals (fixture, 1);
1374 filter_test_enable_filter (fixture);
1376 check_filter_model (fixture);
1377 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1381 unfiltered_hide_single_root_expanded (FilterTest *fixture,
1382 gconstpointer user_data)
1385 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1386 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1387 set_path_visibility (fixture, "2", FALSE);
1389 signal_monitor_assert_is_empty (fixture->monitor);
1390 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1392 filter_test_append_refilter_signals (fixture, 2);
1393 filter_test_enable_filter (fixture);
1395 check_filter_model (fixture);
1396 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1400 unfiltered_hide_single_child (FilterTest *fixture,
1401 gconstpointer user_data)
1404 /* This row is not shown, so its signal is not propagated */
1405 set_path_visibility (fixture, "2:2", FALSE);
1407 signal_monitor_assert_is_empty (fixture->monitor);
1408 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1409 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1411 /* The view only shows the root level, so we only expect signals
1412 * for the root level.
1414 filter_test_append_refilter_signals (fixture, 0);
1415 filter_test_enable_filter (fixture);
1417 check_filter_model (fixture);
1418 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1419 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1423 unfiltered_hide_single_child_root_expanded (FilterTest *fixture,
1424 gconstpointer user_data)
1427 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1428 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1429 set_path_visibility (fixture, "2:2", FALSE);
1431 signal_monitor_assert_is_empty (fixture->monitor);
1432 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1433 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1435 filter_test_append_refilter_signals (fixture, 2);
1436 filter_test_enable_filter (fixture);
1438 check_filter_model (fixture);
1439 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1440 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1444 unfiltered_hide_single_multi_level (FilterTest *fixture,
1445 gconstpointer user_data)
1448 /* This row is not shown, so its signal is not propagated */
1449 set_path_visibility (fixture, "2:2:2", FALSE);
1451 /* This row is not shown, so its signal is not propagated */
1452 set_path_visibility (fixture, "2:2", FALSE);
1454 signal_monitor_assert_is_empty (fixture->monitor);
1455 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1456 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1457 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1459 /* The view only shows the root level, so we only expect signals
1460 * for the root level.
1462 filter_test_append_refilter_signals (fixture, 1);
1463 filter_test_enable_filter (fixture);
1465 check_filter_model (fixture);
1466 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1467 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1469 set_path_visibility (fixture, "2:2", TRUE);
1471 check_filter_model (fixture);
1472 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1473 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1474 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1478 unfiltered_hide_single_multi_level_root_expanded (FilterTest *fixture,
1479 gconstpointer user_data)
1482 /* This row is not shown, so its signal is not propagated */
1483 set_path_visibility (fixture, "2:2:2", FALSE);
1485 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1486 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1487 set_path_visibility (fixture, "2:2", FALSE);
1489 signal_monitor_assert_is_empty (fixture->monitor);
1490 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1491 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1492 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1494 filter_test_append_refilter_signals (fixture, 2);
1495 filter_test_enable_filter (fixture);
1497 check_filter_model (fixture);
1498 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1499 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1501 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1502 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1503 set_path_visibility (fixture, "2:2", TRUE);
1505 check_filter_model (fixture);
1506 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1507 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1508 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1514 unfiltered_vroot_hide_single (FilterTest *fixture,
1515 gconstpointer user_data)
1518 GtkTreePath *path = (GtkTreePath *)user_data;
1520 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1521 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1522 set_path_visibility (fixture, "2:2", FALSE);
1524 signal_monitor_assert_is_empty (fixture->monitor);
1525 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1527 /* The view only shows the root level, so we only expect signals
1528 * for the root level. (Though for the depth argument, we have to
1529 * take the virtual root into account).
1531 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1532 filter_test_enable_filter (fixture);
1534 check_filter_model_with_root (fixture, path);
1535 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1539 unfiltered_vroot_hide_single_child (FilterTest *fixture,
1540 gconstpointer user_data)
1543 GtkTreePath *path = (GtkTreePath *)user_data;
1545 /* Not visible, so no signal will be received. */
1546 set_path_visibility (fixture, "2:2:2", FALSE);
1548 signal_monitor_assert_is_empty (fixture->monitor);
1549 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1550 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1552 /* The view only shows the root level, so we only expect signals
1553 * for the root level. (Though for the depth argument, we have to
1554 * take the virtual root into account).
1556 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1557 filter_test_enable_filter (fixture);
1559 check_filter_model_with_root (fixture, path);
1560 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1561 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1565 unfiltered_vroot_hide_single_child_root_expanded (FilterTest *fixture,
1566 gconstpointer user_data)
1569 GtkTreePath *path = (GtkTreePath *)user_data;
1571 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1572 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1573 set_path_visibility (fixture, "2:2:2", FALSE);
1575 signal_monitor_assert_is_empty (fixture->monitor);
1576 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1577 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1579 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1580 filter_test_enable_filter (fixture);
1582 check_filter_model_with_root (fixture, path);
1583 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1584 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1588 unfiltered_vroot_hide_single_multi_level (FilterTest *fixture,
1589 gconstpointer user_data)
1592 GtkTreePath *path = (GtkTreePath *)user_data;
1594 /* This row is not shown, so its signal is not propagated */
1595 set_path_visibility (fixture, "2:2:2:2", FALSE);
1597 /* Not shown, so no signal */
1598 set_path_visibility (fixture, "2:2:2", FALSE);
1600 signal_monitor_assert_is_empty (fixture->monitor);
1601 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1602 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1603 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1605 /* We only expect signals for the root level. The depth is 2
1606 * because we have to take the virtual root into account.
1608 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1609 filter_test_enable_filter (fixture);
1611 check_filter_model_with_root (fixture, path);
1612 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1613 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1615 /* Not shown, so no signal */
1616 set_path_visibility (fixture, "2:2:2", TRUE);
1618 check_filter_model_with_root (fixture, path);
1619 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1620 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1621 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1625 unfiltered_vroot_hide_single_multi_level_root_expanded (FilterTest *fixture,
1626 gconstpointer user_data)
1629 GtkTreePath *path = (GtkTreePath *)user_data;
1631 /* This row is not shown, so its signal is not propagated */
1632 set_path_visibility (fixture, "2:2:2:2", FALSE);
1634 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1635 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1636 set_path_visibility (fixture, "2:2:2", FALSE);
1638 signal_monitor_assert_is_empty (fixture->monitor);
1639 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1640 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1641 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1643 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1644 filter_test_enable_filter (fixture);
1646 check_filter_model_with_root (fixture, path);
1647 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1648 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1650 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1651 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1652 set_path_visibility (fixture, "2:2:2", TRUE);
1654 check_filter_model_with_root (fixture, path);
1655 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1656 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1657 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1661 unfiltered_show_single (FilterTest *fixture,
1662 gconstpointer user_data)
1665 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1666 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1667 set_path_visibility (fixture, "2", TRUE);
1669 signal_monitor_assert_is_empty (fixture->monitor);
1670 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1672 /* We only expect signals for the root level */
1673 filter_test_append_refilter_signals (fixture, 1);
1674 filter_test_enable_filter (fixture);
1676 check_filter_model (fixture);
1677 check_level_length (fixture->filter, NULL, 1);
1681 unfiltered_show_single_child (FilterTest *fixture,
1682 gconstpointer user_data)
1685 set_path_visibility (fixture, "2:2", TRUE);
1687 signal_monitor_assert_is_empty (fixture->monitor);
1688 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1689 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1691 /* We only expect signals for the root level */
1692 filter_test_append_refilter_signals (fixture, 1);
1693 filter_test_enable_filter (fixture);
1695 check_filter_model (fixture);
1696 check_level_length (fixture->filter, NULL, 0);
1698 /* From here we are filtered, "2" in the real model is "0" in the filter
1701 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1702 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1703 set_path_visibility (fixture, "2", TRUE);
1704 signal_monitor_assert_is_empty (fixture->monitor);
1705 check_level_length (fixture->filter, NULL, 1);
1706 check_level_length (fixture->filter, "0", 1);
1710 unfiltered_show_single_child_root_expanded (FilterTest *fixture,
1711 gconstpointer user_data)
1714 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1715 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1716 set_path_visibility (fixture, "2:2", TRUE);
1718 signal_monitor_assert_is_empty (fixture->monitor);
1719 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1720 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1722 filter_test_append_refilter_signals (fixture, 2);
1723 filter_test_enable_filter (fixture);
1725 check_filter_model (fixture);
1726 check_level_length (fixture->filter, NULL, 0);
1728 /* From here we are filtered, "2" in the real model is "0" in the filter
1731 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1732 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1733 set_path_visibility (fixture, "2", TRUE);
1734 signal_monitor_assert_is_empty (fixture->monitor);
1735 check_level_length (fixture->filter, NULL, 1);
1736 check_level_length (fixture->filter, "0", 1);
1740 unfiltered_show_single_multi_level (FilterTest *fixture,
1741 gconstpointer user_data)
1744 /* The view is not showing these rows (collapsed state), so it is not
1745 * referenced. The signal should not go through.
1747 set_path_visibility (fixture, "2:2:2", TRUE);
1748 set_path_visibility (fixture, "2:2", TRUE);
1750 signal_monitor_assert_is_empty (fixture->monitor);
1751 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1752 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1753 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1755 /* We only expect signals for the first level */
1756 filter_test_append_refilter_signals (fixture, 1);
1757 filter_test_enable_filter (fixture);
1759 check_filter_model (fixture);
1760 check_level_length (fixture->filter, NULL, 0);
1762 /* From here we are filtered, "2" in the real model is "0" in the filter
1765 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1766 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1767 set_path_visibility (fixture, "2", TRUE);
1768 check_filter_model (fixture);
1769 check_level_length (fixture->filter, NULL, 1);
1770 check_level_length (fixture->filter, "0", 1);
1771 check_level_length (fixture->filter, "0:0", 1);
1775 unfiltered_show_single_multi_level_root_expanded (FilterTest *fixture,
1776 gconstpointer user_data)
1779 /* The view is not showing this row (collapsed state), so it is not
1780 * referenced. The signal should not go through.
1782 set_path_visibility (fixture, "2:2:2", TRUE);
1784 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1785 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1786 set_path_visibility (fixture, "2:2", TRUE);
1788 signal_monitor_assert_is_empty (fixture->monitor);
1789 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1790 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1791 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1793 filter_test_append_refilter_signals (fixture, 2);
1794 filter_test_enable_filter (fixture);
1796 check_filter_model (fixture);
1797 check_level_length (fixture->filter, NULL, 0);
1799 /* From here we are filtered, "2" in the real model is "0" in the filter
1802 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1803 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1804 set_path_visibility (fixture, "2", TRUE);
1805 check_filter_model (fixture);
1806 check_level_length (fixture->filter, NULL, 1);
1807 check_level_length (fixture->filter, "0", 1);
1808 check_level_length (fixture->filter, "0:0", 1);
1812 unfiltered_vroot_show_single (FilterTest *fixture,
1813 gconstpointer user_data)
1816 GtkTreePath *path = (GtkTreePath *)user_data;
1818 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1819 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1820 set_path_visibility (fixture, "2:2", TRUE);
1822 signal_monitor_assert_is_empty (fixture->monitor);
1823 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1825 /* The view only shows the root level, so the filter model only has
1826 * the first two levels cached.
1828 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1829 filter_test_enable_filter (fixture);
1831 check_filter_model_with_root (fixture, path);
1832 check_level_length (fixture->filter, NULL, 1);
1836 unfiltered_vroot_show_single_child (FilterTest *fixture,
1837 gconstpointer user_data)
1840 GtkTreePath *path = (GtkTreePath *)user_data;
1842 set_path_visibility (fixture, "2:2:2", TRUE);
1844 signal_monitor_assert_is_empty (fixture->monitor);
1845 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1846 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1848 /* The view only shows the root level, so the filter model only has
1849 * the first two levels cached.
1851 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1852 filter_test_enable_filter (fixture);
1854 check_filter_model_with_root (fixture, path);
1855 check_level_length (fixture->filter, NULL, 0);
1857 /* From here we are filtered, "2" in the real model is "0" in the filter
1860 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1861 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1862 set_path_visibility (fixture, "2:2", TRUE);
1863 signal_monitor_assert_is_empty (fixture->monitor);
1864 check_level_length (fixture->filter, NULL, 1);
1865 check_level_length (fixture->filter, "0", 1);
1869 unfiltered_vroot_show_single_child_root_expanded (FilterTest *fixture,
1870 gconstpointer user_data)
1873 GtkTreePath *path = (GtkTreePath *)user_data;
1875 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1876 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1877 set_path_visibility (fixture, "2:2:2", TRUE);
1879 signal_monitor_assert_is_empty (fixture->monitor);
1880 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1881 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1883 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1884 filter_test_enable_filter (fixture);
1886 check_filter_model_with_root (fixture, path);
1887 check_level_length (fixture->filter, NULL, 0);
1889 /* From here we are filtered, "2" in the real model is "0" in the filter
1892 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1893 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1894 set_path_visibility (fixture, "2:2", TRUE);
1895 signal_monitor_assert_is_empty (fixture->monitor);
1896 check_level_length (fixture->filter, NULL, 1);
1897 check_level_length (fixture->filter, "0", 1);
1902 unfiltered_vroot_show_single_multi_level (FilterTest *fixture,
1903 gconstpointer user_data)
1906 GtkTreePath *path = (GtkTreePath *)user_data;
1908 /* The view is not showing this row (collapsed state), so it is not
1909 * referenced. The signal should not go through.
1911 set_path_visibility (fixture, "2:2:2:2", TRUE);
1913 set_path_visibility (fixture, "2:2:2", TRUE);
1915 signal_monitor_assert_is_empty (fixture->monitor);
1916 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1917 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1918 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1920 /* We only expect signals for the root level */
1921 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1922 filter_test_enable_filter (fixture);
1924 check_filter_model_with_root (fixture, path);
1925 check_level_length (fixture->filter, NULL, 0);
1927 /* From here we are filtered, "2" in the real model is "0" in the filter
1930 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1931 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1932 set_path_visibility (fixture, "2:2", TRUE);
1933 check_filter_model_with_root (fixture, path);
1934 check_level_length (fixture->filter, NULL, 1);
1935 check_level_length (fixture->filter, "0", 1);
1936 check_level_length (fixture->filter, "0:0", 1);
1940 unfiltered_vroot_show_single_multi_level_root_expanded (FilterTest *fixture,
1941 gconstpointer user_data)
1944 GtkTreePath *path = (GtkTreePath *)user_data;
1946 /* The view is not showing this row (collapsed state), so it is not
1947 * referenced. The signal should not go through.
1949 set_path_visibility (fixture, "2:2:2:2", TRUE);
1951 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1952 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1953 set_path_visibility (fixture, "2:2:2", TRUE);
1955 signal_monitor_assert_is_empty (fixture->monitor);
1956 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1957 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1958 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1960 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1961 filter_test_enable_filter (fixture);
1963 check_filter_model_with_root (fixture, path);
1964 check_level_length (fixture->filter, NULL, 0);
1966 /* From here we are filtered, "2" in the real model is "0" in the filter
1969 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1970 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1971 set_path_visibility (fixture, "2:2", TRUE);
1972 check_filter_model_with_root (fixture, path);
1973 check_level_length (fixture->filter, NULL, 1);
1974 check_level_length (fixture->filter, "0", 1);
1975 check_level_length (fixture->filter, "0:0", 1);
1979 unfiltered_rows_reordered_root_level (FilterTest *fixture,
1980 gconstpointer user_data)
1982 int order0[] = { 1, 2, 3, 4, 0 };
1983 int order1[] = { 0, 2, 1, 3, 4 };
1984 int order2[] = { 4, 0, 1, 2, 3 };
1985 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
1988 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1990 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1992 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1994 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1996 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1999 path = gtk_tree_path_new ();
2000 signal_monitor_append_signal_reordered (fixture->monitor,
2003 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2004 signal_monitor_assert_is_empty (fixture->monitor);
2006 signal_monitor_append_signal_reordered (fixture->monitor,
2009 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
2010 signal_monitor_assert_is_empty (fixture->monitor);
2012 signal_monitor_append_signal_reordered (fixture->monitor,
2015 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2016 signal_monitor_assert_is_empty (fixture->monitor);
2018 gtk_tree_path_free (path);
2022 unfiltered_rows_reordered_child_level (FilterTest *fixture,
2023 gconstpointer user_data)
2025 int order0[] = { 1, 2, 3, 4, 0 };
2026 int order1[] = { 0, 2, 1, 3, 4 };
2027 int order2[] = { 4, 0, 1, 2, 3 };
2028 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
2032 path = gtk_tree_path_new_from_indices (0, -1);
2033 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2035 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2037 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2039 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2041 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2043 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2046 signal_monitor_append_signal_reordered (fixture->monitor,
2049 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2050 signal_monitor_assert_is_empty (fixture->monitor);
2052 signal_monitor_append_signal_reordered (fixture->monitor,
2055 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
2056 signal_monitor_assert_is_empty (fixture->monitor);
2058 signal_monitor_append_signal_reordered (fixture->monitor,
2061 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2062 signal_monitor_assert_is_empty (fixture->monitor);
2064 gtk_tree_path_free (path);
2068 filtered_rows_reordered_root_level_first_hidden (FilterTest *fixture,
2069 gconstpointer user_data)
2071 int order0[] = { 1, 2, 3, 0 };
2072 int order1[] = { 0, 2, 1, 3 };
2073 int order2[] = { 3, 0, 1, 2 };
2074 GtkTreeIter iter1, iter2, iter3, iter4;
2077 /* Hide middle path */
2078 signal_monitor_append_signal (fixture->monitor,
2080 set_path_visibility (fixture, "0", FALSE);
2081 signal_monitor_assert_is_empty (fixture->monitor);
2083 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2085 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2087 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2089 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2092 path = gtk_tree_path_new ();
2093 signal_monitor_append_signal_reordered (fixture->monitor,
2096 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2097 signal_monitor_assert_is_empty (fixture->monitor);
2099 signal_monitor_append_signal_reordered (fixture->monitor,
2102 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2103 signal_monitor_assert_is_empty (fixture->monitor);
2105 signal_monitor_append_signal_reordered (fixture->monitor,
2108 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2109 signal_monitor_assert_is_empty (fixture->monitor);
2111 gtk_tree_path_free (path);
2115 filtered_rows_reordered_root_level_middle_hidden (FilterTest *fixture,
2116 gconstpointer user_data)
2118 int order0[] = { 1, 2, 3, 0 };
2119 int order1[] = { 0, 2, 1, 3 };
2120 int order2[] = { 3, 0, 1, 2 };
2121 GtkTreeIter iter0, iter1, iter3, iter4;
2124 /* Hide middle path */
2125 signal_monitor_append_signal (fixture->monitor,
2127 set_path_visibility (fixture, "2", FALSE);
2128 signal_monitor_assert_is_empty (fixture->monitor);
2130 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2132 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2134 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2136 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2139 path = gtk_tree_path_new ();
2140 signal_monitor_append_signal_reordered (fixture->monitor,
2143 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2144 signal_monitor_assert_is_empty (fixture->monitor);
2146 signal_monitor_append_signal_reordered (fixture->monitor,
2149 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2150 signal_monitor_assert_is_empty (fixture->monitor);
2152 signal_monitor_append_signal_reordered (fixture->monitor,
2155 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2156 signal_monitor_assert_is_empty (fixture->monitor);
2158 gtk_tree_path_free (path);
2162 filtered_rows_reordered_child_level_first_hidden (FilterTest *fixture,
2163 gconstpointer user_data)
2165 int order0[] = { 1, 2, 3, 0 };
2166 int order1[] = { 0, 2, 1, 3 };
2167 int order2[] = { 3, 0, 1, 2 };
2168 GtkTreeIter iter1, iter2, iter3, iter4;
2172 path = gtk_tree_path_new_from_indices (0, -1);
2173 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, TRUE);
2175 /* Hide middle path */
2176 signal_monitor_append_signal (fixture->monitor,
2177 ROW_DELETED, "0:0");
2178 set_path_visibility (fixture, "0:0", FALSE);
2179 signal_monitor_assert_is_empty (fixture->monitor);
2181 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2183 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2185 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2187 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2190 signal_monitor_append_signal_reordered (fixture->monitor,
2193 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2194 signal_monitor_assert_is_empty (fixture->monitor);
2196 signal_monitor_append_signal_reordered (fixture->monitor,
2199 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2200 signal_monitor_assert_is_empty (fixture->monitor);
2202 signal_monitor_append_signal_reordered (fixture->monitor,
2205 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2206 signal_monitor_assert_is_empty (fixture->monitor);
2208 gtk_tree_path_free (path);
2212 filtered_rows_reordered_child_level_middle_hidden (FilterTest *fixture,
2213 gconstpointer user_data)
2215 int order0[] = { 1, 2, 3, 0 };
2216 int order1[] = { 0, 2, 1, 3 };
2217 int order2[] = { 3, 0, 1, 2 };
2218 GtkTreeIter iter0, iter1, iter3, iter4;
2222 path = gtk_tree_path_new_from_indices (0, -1);
2223 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2225 /* Hide middle path */
2226 signal_monitor_append_signal (fixture->monitor,
2227 ROW_DELETED, "0:2");
2228 set_path_visibility (fixture, "0:2", FALSE);
2229 signal_monitor_assert_is_empty (fixture->monitor);
2231 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2233 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2235 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2237 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2240 signal_monitor_append_signal_reordered (fixture->monitor,
2243 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2244 signal_monitor_assert_is_empty (fixture->monitor);
2246 signal_monitor_append_signal_reordered (fixture->monitor,
2249 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2250 signal_monitor_assert_is_empty (fixture->monitor);
2252 signal_monitor_append_signal_reordered (fixture->monitor,
2255 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2256 signal_monitor_assert_is_empty (fixture->monitor);
2258 gtk_tree_path_free (path);
2262 filtered_rows_reordered_child_level_4_hidden (FilterTest *fixture,
2263 gconstpointer user_data)
2265 int order0[] = { 0 };
2266 GtkTreeIter iter1, iter4;
2270 path = gtk_tree_path_new_from_indices (0, -1);
2271 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2273 /* Hide last 4 paths */
2274 signal_monitor_append_signal (fixture->monitor,
2275 ROW_DELETED, "0:4");
2276 signal_monitor_append_signal (fixture->monitor,
2277 ROW_DELETED, "0:3");
2278 signal_monitor_append_signal (fixture->monitor,
2279 ROW_DELETED, "0:2");
2280 signal_monitor_append_signal (fixture->monitor,
2281 ROW_DELETED, "0:0");
2282 set_path_visibility (fixture, "0:4", FALSE);
2283 set_path_visibility (fixture, "0:3", FALSE);
2284 set_path_visibility (fixture, "0:2", FALSE);
2285 set_path_visibility (fixture, "0:0", FALSE);
2286 signal_monitor_assert_is_empty (fixture->monitor);
2288 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2290 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2293 signal_monitor_append_signal_reordered (fixture->monitor,
2296 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2297 signal_monitor_assert_is_empty (fixture->monitor);
2299 gtk_tree_path_free (path);
2303 filtered_rows_reordered_child_level_all_hidden (FilterTest *fixture,
2304 gconstpointer user_data)
2306 GtkTreeIter iter1, iter4;
2310 path = gtk_tree_path_new_from_indices (0, -1);
2311 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2312 gtk_tree_path_free (path);
2314 /* Hide last 4 paths */
2315 signal_monitor_append_signal (fixture->monitor,
2316 ROW_DELETED, "0:4");
2317 signal_monitor_append_signal (fixture->monitor,
2318 ROW_DELETED, "0:3");
2319 signal_monitor_append_signal (fixture->monitor,
2320 ROW_DELETED, "0:2");
2321 signal_monitor_append_signal (fixture->monitor,
2322 ROW_DELETED, "0:1");
2323 signal_monitor_append_signal (fixture->monitor,
2324 ROW_DELETED, "0:0");
2325 signal_monitor_append_signal (fixture->monitor,
2326 ROW_HAS_CHILD_TOGGLED, "0");
2327 set_path_visibility (fixture, "0:4", FALSE);
2328 set_path_visibility (fixture, "0:3", FALSE);
2329 set_path_visibility (fixture, "0:2", FALSE);
2330 set_path_visibility (fixture, "0:1", FALSE);
2331 set_path_visibility (fixture, "0:0", FALSE);
2332 signal_monitor_assert_is_empty (fixture->monitor);
2334 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2336 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2339 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2340 signal_monitor_assert_is_empty (fixture->monitor);
2344 insert_before (void)
2346 GtkTreeStore *store;
2347 GtkTreeModel *filter;
2348 GtkWidget *tree_view;
2349 SignalMonitor *monitor;
2351 GtkTreeIter last_iter;
2354 /* This tests two aspects of the row-inserted handling:
2355 * 1) If the newly inserted node was already handled by building
2356 * the root level, don't handle it a second time.
2357 * 2) Offsets of existing nodes must be updated when a new
2361 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2362 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2363 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2366 tree_view = gtk_tree_view_new_with_model (filter);
2367 monitor = signal_monitor_new (filter);
2369 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 0);
2372 path = gtk_tree_path_new_from_indices (0, -1);
2373 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2374 gtk_tree_path_free (path);
2376 gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
2377 0, "Foo", 1, TRUE, -1);
2379 signal_monitor_assert_is_empty (monitor);
2380 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2383 path = gtk_tree_path_new_from_indices (1, -1);
2384 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2385 gtk_tree_path_free (path);
2387 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2388 0, "Foo", 1, TRUE, -1);
2391 signal_monitor_assert_is_empty (monitor);
2392 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2394 /* Insert on 1 again -- invisible */
2395 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2396 0, "Foo", 1, FALSE, -1);
2398 signal_monitor_assert_is_empty (monitor);
2399 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2401 /* Insert on 1 again -- visible */
2402 path = gtk_tree_path_new_from_indices (1, -1);
2403 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2404 gtk_tree_path_free (path);
2406 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2407 0, "Foo", 1, TRUE, -1);
2409 signal_monitor_assert_is_empty (monitor);
2410 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2412 /* Modify the iter that should be at the last position and check the
2415 path = gtk_tree_path_new_from_indices (2, -1);
2416 signal_monitor_append_signal_path (monitor, ROW_CHANGED, path);
2417 gtk_tree_path_free (path);
2419 gtk_tree_store_set (store, &last_iter, 0, "Foo changed", -1);
2421 signal_monitor_assert_is_empty (monitor);
2422 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2428 GtkTreeStore *store;
2429 GtkTreeModel *filter;
2430 GtkWidget *tree_view;
2431 SignalMonitor *monitor;
2432 GtkTreeIter parent, iter;
2435 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2437 gtk_tree_store_insert_with_values (store, &parent, NULL, 0,
2438 0, "Parent", 1, TRUE, -1);
2441 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2442 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2445 tree_view = gtk_tree_view_new_with_model (filter);
2446 monitor = signal_monitor_new (filter);
2448 /* Insert child -- invisible */
2449 path = gtk_tree_path_new_from_indices (0, -1);
2450 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2451 /* The signal is received twice, once a pass through from GtkTreeStore
2452 * and one generated by GtkTreeModelFilter. Not accurate, but cannot
2455 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2456 gtk_tree_path_free (path);
2458 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2459 0, "Child", 1, FALSE, -1);
2461 signal_monitor_assert_is_empty (monitor);
2462 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2465 path = gtk_tree_path_new_from_indices (0, 0, -1);
2466 gtk_tree_path_up (path); /* 0 */
2467 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2468 gtk_tree_path_free (path);
2470 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
2471 0, "Child", 1, TRUE, -1);
2473 signal_monitor_assert_is_empty (monitor);
2474 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2476 /* Insert child -- invisible */
2477 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2478 0, "Child", 1, FALSE, -1);
2480 signal_monitor_assert_is_empty (monitor);
2481 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2489 GtkTreeIter iter, iter1, iter2, iter3;
2491 GtkTreeModel *filter;
2492 GtkWidget *view G_GNUC_UNUSED;
2494 list = gtk_list_store_new (1, G_TYPE_INT);
2495 gtk_list_store_insert_with_values (list, &iter1, 0, 0, 1, -1);
2496 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
2497 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
2498 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
2499 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
2500 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
2501 gtk_list_store_insert_with_values (list, &iter2, 6, 0, 7, -1);
2502 gtk_list_store_insert_with_values (list, &iter3, 7, 0, 8, -1);
2504 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
2505 view = gtk_tree_view_new_with_model (filter);
2507 gtk_list_store_remove (list, &iter1);
2508 gtk_list_store_remove (list, &iter3);
2509 gtk_list_store_remove (list, &iter2);
2511 gtk_widget_destroy (view);
2512 g_object_unref (filter);
2513 g_object_unref (list);
2517 remove_node_vroot (void)
2519 GtkTreeIter parent, root;
2520 GtkTreeIter iter, iter1, iter2, iter3;
2522 GtkTreeModel *filter;
2524 GtkWidget *view G_GNUC_UNUSED;
2526 tree = gtk_tree_store_new (1, G_TYPE_INT);
2527 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2528 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2530 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2531 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2532 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2533 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2534 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2535 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2536 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2537 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2539 path = gtk_tree_path_new_from_indices (0, 0, -1);
2540 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2541 gtk_tree_path_free (path);
2543 view = gtk_tree_view_new_with_model (filter);
2545 gtk_tree_store_remove (tree, &iter1);
2546 gtk_tree_store_remove (tree, &iter3);
2547 gtk_tree_store_remove (tree, &iter2);
2549 gtk_widget_destroy (view);
2550 g_object_unref (filter);
2551 g_object_unref (tree);
2555 remove_vroot_ancestor (void)
2557 GtkTreeIter parent, root;
2558 GtkTreeIter iter, iter1, iter2, iter3;
2560 GtkTreeModel *filter;
2562 GtkWidget *view G_GNUC_UNUSED;
2564 tree = gtk_tree_store_new (1, G_TYPE_INT);
2565 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2566 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2568 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2569 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2570 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2571 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2572 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2573 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2574 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2575 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2577 path = gtk_tree_path_new_from_indices (0, 0, -1);
2578 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2579 gtk_tree_path_free (path);
2581 view = gtk_tree_view_new_with_model (filter);
2583 gtk_tree_store_remove (tree, &parent);
2585 gtk_widget_destroy (view);
2586 g_object_unref (filter);
2587 g_object_unref (tree);
2591 ref_count_single_level (void)
2593 GtkTreeIter iter[5];
2594 GtkTreeModel *model;
2595 GtkTreeModelRefCount *ref_model;
2596 GtkTreeModel *filter_model;
2597 GtkWidget *tree_view;
2599 model = gtk_tree_model_ref_count_new ();
2600 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2602 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[0], NULL);
2603 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[1], NULL);
2604 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[2], NULL);
2605 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[3], NULL);
2606 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[4], NULL);
2608 assert_root_level_unreferenced (ref_model);
2610 filter_model = gtk_tree_model_filter_new (model, NULL);
2611 tree_view = gtk_tree_view_new_with_model (filter_model);
2613 assert_node_ref_count (ref_model, &iter[0], 2);
2614 assert_node_ref_count (ref_model, &iter[1], 1);
2615 assert_node_ref_count (ref_model, &iter[2], 1);
2616 assert_node_ref_count (ref_model, &iter[3], 1);
2617 assert_node_ref_count (ref_model, &iter[4], 1);
2619 gtk_widget_destroy (tree_view);
2621 assert_node_ref_count (ref_model, &iter[0], 1);
2622 assert_node_ref_count (ref_model, &iter[1], 0);
2623 assert_node_ref_count (ref_model, &iter[2], 0);
2624 assert_node_ref_count (ref_model, &iter[3], 0);
2625 assert_node_ref_count (ref_model, &iter[4], 0);
2627 g_object_unref (filter_model);
2629 assert_node_ref_count (ref_model, &iter[0], 0);
2631 g_object_unref (ref_model);
2635 ref_count_two_levels (void)
2637 GtkTreeIter parent1, parent2, iter, iter_first;
2638 GtkTreeModel *model;
2639 GtkTreeModelRefCount *ref_model;
2640 GtkTreeModel *filter_model;
2641 GtkWidget *tree_view;
2643 model = gtk_tree_model_ref_count_new ();
2644 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2646 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL);
2647 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
2648 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_first, &parent2);
2649 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2650 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2652 assert_entire_model_unreferenced (ref_model);
2654 filter_model = gtk_tree_model_filter_new (model, NULL);
2655 tree_view = gtk_tree_view_new_with_model (filter_model);
2657 /* This is quite confusing:
2658 * - node 0 has a ref count of 2 because it is referenced as the
2659 * first node in a level and by the tree view.
2660 * - node 1 has a ref count of 2 because it is referenced by its
2661 * child level and by the tree view.
2663 assert_root_level_referenced (ref_model, 2);
2664 assert_node_ref_count (ref_model, &iter_first, 1);
2665 assert_node_ref_count (ref_model, &iter, 0);
2667 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
2669 assert_node_ref_count (ref_model, &parent1, 2);
2670 assert_node_ref_count (ref_model, &parent2, 2);
2671 assert_node_ref_count (ref_model, &iter_first, 2);
2672 assert_node_ref_count (ref_model, &iter, 1);
2674 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2676 /* The child level is not destroyed because its parent is visible */
2677 assert_node_ref_count (ref_model, &parent1, 2);
2678 assert_node_ref_count (ref_model, &parent2, 2);
2679 assert_node_ref_count (ref_model, &iter_first, 1);
2680 assert_node_ref_count (ref_model, &iter, 0);
2682 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2684 assert_node_ref_count (ref_model, &parent1, 2);
2685 assert_node_ref_count (ref_model, &parent2, 2);
2686 assert_node_ref_count (ref_model, &iter_first, 1);
2687 assert_node_ref_count (ref_model, &iter, 0);
2689 gtk_widget_destroy (tree_view);
2691 assert_root_level_referenced (ref_model, 1);
2692 assert_node_ref_count (ref_model, &iter_first, 1);
2693 assert_node_ref_count (ref_model, &iter, 0);
2695 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2697 /* The root level and first level remain cached, only the references on the
2698 * first nodes of these levels are kept.
2700 assert_node_ref_count (ref_model, &parent1, 1);
2701 assert_node_ref_count (ref_model, &parent2, 1);
2702 assert_node_ref_count (ref_model, &iter_first, 1);
2703 assert_node_ref_count (ref_model, &iter, 0);
2705 g_object_unref (filter_model);
2706 g_object_unref (ref_model);
2710 ref_count_three_levels (void)
2712 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2713 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2714 GtkTreeModel *model;
2715 GtkTreeModelRefCount *ref_model;
2716 GtkTreeModel *filter_model;
2718 GtkWidget *tree_view;
2720 model = gtk_tree_model_ref_count_new ();
2721 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2728 * + iter_parent2_first
2732 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2733 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2734 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2735 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2736 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2737 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2738 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2740 assert_entire_model_unreferenced (ref_model);
2742 filter_model = gtk_tree_model_filter_new (model, NULL);
2743 tree_view = gtk_tree_view_new_with_model (filter_model);
2745 /* This is quite confusing:
2746 * - node 0 has a ref count of 2 because it is referenced as the
2747 * first node in a level and by the tree view.
2748 * - node 1 has a ref count of 2 because it is referenced by its
2749 * child level and by the tree view.
2751 assert_root_level_referenced (ref_model, 2);
2752 assert_node_ref_count (ref_model, &parent1, 1);
2753 assert_node_ref_count (ref_model, &parent2, 0);
2754 assert_level_unreferenced (ref_model, &parent1);
2755 assert_level_unreferenced (ref_model, &parent2);
2757 path = gtk_tree_path_new_from_indices (1, -1);
2758 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2760 assert_node_ref_count (ref_model, &grandparent1, 2);
2761 assert_node_ref_count (ref_model, &grandparent2, 2);
2762 assert_node_ref_count (ref_model, &parent1, 3);
2763 assert_node_ref_count (ref_model, &parent2, 2);
2764 assert_node_ref_count (ref_model, &iter_parent1, 1);
2765 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2766 assert_node_ref_count (ref_model, &iter_parent2, 0);
2768 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2770 assert_node_ref_count (ref_model, &grandparent1, 2);
2771 assert_node_ref_count (ref_model, &grandparent2, 2);
2772 assert_node_ref_count (ref_model, &parent1, 3);
2773 assert_node_ref_count (ref_model, &parent2, 2);
2774 assert_node_ref_count (ref_model, &iter_parent1, 2);
2775 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2776 assert_node_ref_count (ref_model, &iter_parent2, 1);
2778 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2780 assert_node_ref_count (ref_model, &grandparent1, 2);
2781 assert_node_ref_count (ref_model, &grandparent2, 2);
2782 assert_node_ref_count (ref_model, &parent1, 2);
2783 assert_node_ref_count (ref_model, &parent2, 1);
2784 assert_node_ref_count (ref_model, &iter_parent1, 1);
2785 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2786 assert_node_ref_count (ref_model, &iter_parent2, 0);
2788 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2790 assert_node_ref_count (ref_model, &grandparent1, 2);
2791 assert_node_ref_count (ref_model, &grandparent2, 2);
2792 assert_node_ref_count (ref_model, &parent1, 1);
2793 assert_node_ref_count (ref_model, &parent2, 0);
2794 assert_node_ref_count (ref_model, &iter_parent1, 0);
2795 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2796 assert_node_ref_count (ref_model, &iter_parent2, 0);
2798 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2800 assert_node_ref_count (ref_model, &grandparent1, 2);
2801 assert_node_ref_count (ref_model, &grandparent2, 2);
2802 assert_node_ref_count (ref_model, &parent1, 3);
2803 assert_node_ref_count (ref_model, &parent2, 2);
2804 assert_node_ref_count (ref_model, &iter_parent1, 1);
2805 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2806 assert_node_ref_count (ref_model, &iter_parent2, 0);
2808 gtk_tree_path_append_index (path, 1);
2809 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2811 assert_node_ref_count (ref_model, &grandparent1, 2);
2812 assert_node_ref_count (ref_model, &grandparent2, 2);
2813 assert_node_ref_count (ref_model, &parent1, 3);
2814 assert_node_ref_count (ref_model, &parent2, 2);
2815 assert_node_ref_count (ref_model, &iter_parent1, 1);
2816 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2817 assert_node_ref_count (ref_model, &iter_parent2, 1);
2819 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2821 assert_node_ref_count (ref_model, &grandparent1, 2);
2822 assert_node_ref_count (ref_model, &grandparent2, 2);
2823 assert_node_ref_count (ref_model, &parent1, 3);
2824 assert_node_ref_count (ref_model, &parent2, 2);
2825 assert_node_ref_count (ref_model, &iter_parent1, 1);
2826 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2827 assert_node_ref_count (ref_model, &iter_parent2, 0);
2829 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2831 assert_node_ref_count (ref_model, &grandparent1, 2);
2832 assert_node_ref_count (ref_model, &grandparent2, 2);
2833 assert_node_ref_count (ref_model, &parent1, 3);
2834 assert_node_ref_count (ref_model, &parent2, 2);
2835 assert_node_ref_count (ref_model, &iter_parent1, 1);
2836 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2837 assert_node_ref_count (ref_model, &iter_parent2, 0);
2839 gtk_tree_path_up (path);
2840 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2841 gtk_tree_path_free (path);
2843 assert_node_ref_count (ref_model, &grandparent1, 2);
2844 assert_node_ref_count (ref_model, &grandparent2, 2);
2845 assert_node_ref_count (ref_model, &parent1, 2);
2846 assert_node_ref_count (ref_model, &parent2, 1);
2847 assert_node_ref_count (ref_model, &iter_parent1, 1);
2848 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2849 assert_node_ref_count (ref_model, &iter_parent2, 0);
2851 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2853 assert_node_ref_count (ref_model, &grandparent1, 2);
2854 assert_node_ref_count (ref_model, &grandparent2, 2);
2855 assert_node_ref_count (ref_model, &parent1, 1);
2856 assert_node_ref_count (ref_model, &parent2, 0);
2857 assert_node_ref_count (ref_model, &iter_parent1, 0);
2858 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2859 assert_node_ref_count (ref_model, &iter_parent2, 0);
2861 gtk_widget_destroy (tree_view);
2863 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2865 /* The root level and first level remain cached, only the references on the
2866 * first nodes of these levels are kept. Grandparent2 is the parent
2867 * of the first level with parent1, so grandparent2 keeps a reference
2870 assert_node_ref_count (ref_model, &grandparent1, 1);
2871 assert_node_ref_count (ref_model, &grandparent2, 1);
2872 assert_node_ref_count (ref_model, &parent1, 1);
2873 assert_node_ref_count (ref_model, &parent2, 0);
2874 assert_node_ref_count (ref_model, &iter_parent1, 0);
2875 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2876 assert_node_ref_count (ref_model, &iter_parent2, 0);
2878 g_object_unref (filter_model);
2879 g_object_unref (ref_model);
2883 ref_count_delete_row (void)
2885 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2886 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2887 GtkTreeModel *model;
2888 GtkTreeModelRefCount *ref_model;
2889 GtkTreeModel *filter_model;
2891 GtkWidget *tree_view;
2893 model = gtk_tree_model_ref_count_new ();
2894 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2901 * + iter_parent2_first
2905 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2906 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2907 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2908 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2909 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2910 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2911 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2913 assert_entire_model_unreferenced (ref_model);
2915 filter_model = gtk_tree_model_filter_new (model, NULL);
2916 tree_view = gtk_tree_view_new_with_model (filter_model);
2918 assert_root_level_referenced (ref_model, 2);
2919 assert_node_ref_count (ref_model, &parent1, 1);
2920 assert_node_ref_count (ref_model, &parent2, 0);
2921 assert_level_unreferenced (ref_model, &parent1);
2922 assert_level_unreferenced (ref_model, &parent2);
2924 path = gtk_tree_path_new_from_indices (1, -1);
2925 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2926 gtk_tree_path_free (path);
2928 assert_node_ref_count (ref_model, &grandparent1, 2);
2929 assert_node_ref_count (ref_model, &grandparent2, 2);
2930 assert_node_ref_count (ref_model, &parent1, 3);
2931 assert_node_ref_count (ref_model, &parent2, 2);
2932 assert_node_ref_count (ref_model, &iter_parent1, 2);
2933 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2934 assert_node_ref_count (ref_model, &iter_parent2, 1);
2936 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter_parent2);
2938 assert_node_ref_count (ref_model, &grandparent1, 2);
2939 assert_node_ref_count (ref_model, &grandparent2, 2);
2940 assert_node_ref_count (ref_model, &parent1, 3);
2941 assert_node_ref_count (ref_model, &parent2, 2);
2942 assert_node_ref_count (ref_model, &iter_parent1, 2);
2943 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2945 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1);
2947 assert_node_ref_count (ref_model, &grandparent1, 2);
2948 assert_node_ref_count (ref_model, &grandparent2, 2);
2949 assert_node_ref_count (ref_model, &parent2, 3);
2950 assert_level_referenced (ref_model, 2, &parent2);
2952 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
2954 assert_node_ref_count (ref_model, &grandparent1, 2);
2956 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2958 assert_node_ref_count (ref_model, &grandparent1, 2);
2960 gtk_widget_destroy (tree_view);
2961 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2963 assert_node_ref_count (ref_model, &grandparent1, 1);
2965 g_object_unref (filter_model);
2967 assert_node_ref_count (ref_model, &grandparent1, 0);
2969 g_object_unref (ref_model);
2973 ref_count_filter_row_length_1 (void)
2975 GtkTreeIter level1_1;
2976 GtkTreeIter level2_1;
2977 GtkTreeIter level3_1;
2978 GtkTreeIter level4_1;
2979 GtkTreeModel *model;
2980 GtkTreeModelRefCount *ref_model;
2981 GtkTreeModel *filter_model;
2983 GtkWidget *tree_view;
2984 GType column_types[] = { G_TYPE_BOOLEAN };
2986 model = gtk_tree_model_ref_count_new ();
2987 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2989 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
2998 * Node level1_1 is expanded. This makes that levels 1 and 2 are
2999 * visible. Level 3 is cached because its parent is visible. Level 4
3003 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3004 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3005 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3006 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3008 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3009 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3010 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3011 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3013 assert_entire_model_unreferenced (ref_model);
3015 filter_model = gtk_tree_model_filter_new (model, NULL);
3016 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3017 tree_view = gtk_tree_view_new_with_model (filter_model);
3019 assert_node_ref_count (ref_model, &level1_1, 3);
3020 assert_node_ref_count (ref_model, &level2_1, 1);
3021 assert_node_ref_count (ref_model, &level3_1, 0);
3022 assert_node_ref_count (ref_model, &level4_1, 0);
3024 path = gtk_tree_path_new_from_indices (0, -1);
3025 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
3026 gtk_tree_path_free (path);
3028 assert_node_ref_count (ref_model, &level1_1, 3);
3029 assert_node_ref_count (ref_model, &level2_1, 3);
3030 assert_node_ref_count (ref_model, &level3_1, 1);
3031 assert_node_ref_count (ref_model, &level4_1, 0);
3033 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, FALSE, -1);
3035 assert_node_ref_count (ref_model, &level1_1, 3);
3036 assert_node_ref_count (ref_model, &level2_1, 3);
3037 assert_node_ref_count (ref_model, &level3_1, 1);
3038 assert_node_ref_count (ref_model, &level4_1, 0);
3040 /* level3_1 has a visible parent, so the node is kept in the cache. */
3041 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, FALSE, -1);
3043 assert_node_ref_count (ref_model, &level1_1, 3);
3044 assert_node_ref_count (ref_model, &level2_1, 3);
3045 assert_node_ref_count (ref_model, &level3_1, 1);
3046 assert_node_ref_count (ref_model, &level4_1, 0);
3048 /* level2_1 has a visible parent, so is kept in the cache. However,
3049 * the external reference should be released.
3051 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, FALSE, -1);
3053 assert_node_ref_count (ref_model, &level1_1, 3);
3054 assert_node_ref_count (ref_model, &level2_1, 1);
3055 assert_node_ref_count (ref_model, &level3_1, 0);
3056 assert_node_ref_count (ref_model, &level4_1, 0);
3058 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, FALSE, -1);
3060 assert_node_ref_count (ref_model, &level1_1, 2);
3061 assert_node_ref_count (ref_model, &level2_1, 1);
3062 assert_node_ref_count (ref_model, &level3_1, 0);
3063 assert_node_ref_count (ref_model, &level4_1, 0);
3065 gtk_widget_destroy (tree_view);
3066 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3068 assert_node_ref_count (ref_model, &level1_1, 2);
3069 assert_node_ref_count (ref_model, &level2_1, 1);
3071 g_object_unref (filter_model);
3073 assert_node_ref_count (ref_model, &level1_1, 0);
3075 g_object_unref (ref_model);
3079 ref_count_filter_row_length_1_remove_in_root_level (void)
3081 GtkTreeIter level1_1;
3082 GtkTreeIter level2_1;
3083 GtkTreeIter level3_1;
3084 GtkTreeIter level4_1;
3085 GtkTreeModel *model;
3086 GtkTreeModelRefCount *ref_model;
3087 GtkTreeModel *filter_model;
3089 GtkWidget *tree_view;
3090 GType column_types[] = { G_TYPE_BOOLEAN };
3092 model = gtk_tree_model_ref_count_new ();
3093 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3095 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3105 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3106 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3107 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3108 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3110 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3111 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3112 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3113 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3115 assert_entire_model_unreferenced (ref_model);
3117 filter_model = gtk_tree_model_filter_new (model, NULL);
3118 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3119 tree_view = gtk_tree_view_new_with_model (filter_model);
3121 assert_node_ref_count (ref_model, &level1_1, 3);
3122 assert_node_ref_count (ref_model, &level2_1, 1);
3123 assert_node_ref_count (ref_model, &level3_1, 0);
3124 assert_node_ref_count (ref_model, &level4_1, 0);
3126 path = gtk_tree_path_new_from_indices (0, -1);
3127 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3128 gtk_tree_path_free (path);
3130 assert_node_ref_count (ref_model, &level1_1, 3);
3131 assert_node_ref_count (ref_model, &level2_1, 3);
3132 assert_node_ref_count (ref_model, &level3_1, 3);
3133 assert_node_ref_count (ref_model, &level4_1, 2);
3135 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, FALSE, -1);
3137 assert_node_ref_count (ref_model, &level1_1, 2);
3138 assert_node_ref_count (ref_model, &level2_1, 1);
3139 assert_node_ref_count (ref_model, &level3_1, 0);
3140 assert_node_ref_count (ref_model, &level4_1, 0);
3142 gtk_widget_destroy (tree_view);
3143 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3145 assert_node_ref_count (ref_model, &level1_1, 2);
3146 assert_node_ref_count (ref_model, &level2_1, 1);
3147 assert_node_ref_count (ref_model, &level3_1, 0);
3148 assert_node_ref_count (ref_model, &level4_1, 0);
3150 g_object_unref (filter_model);
3152 assert_node_ref_count (ref_model, &level1_1, 0);
3153 assert_node_ref_count (ref_model, &level2_1, 0);
3154 assert_node_ref_count (ref_model, &level3_1, 0);
3155 assert_node_ref_count (ref_model, &level4_1, 0);
3157 g_object_unref (ref_model);
3161 ref_count_filter_row_length_1_remove_in_child_level (void)
3163 GtkTreeIter level1_1;
3164 GtkTreeIter level2_1;
3165 GtkTreeIter level3_1;
3166 GtkTreeIter level4_1;
3167 GtkTreeModel *model;
3168 GtkTreeModelRefCount *ref_model;
3169 GtkTreeModel *filter_model;
3171 GtkWidget *tree_view;
3172 GType column_types[] = { G_TYPE_BOOLEAN };
3174 model = gtk_tree_model_ref_count_new ();
3175 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3177 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3187 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3188 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3189 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3190 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3192 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3193 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3194 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3195 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3197 assert_entire_model_unreferenced (ref_model);
3199 filter_model = gtk_tree_model_filter_new (model, NULL);
3200 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3201 tree_view = gtk_tree_view_new_with_model (filter_model);
3203 assert_node_ref_count (ref_model, &level1_1, 3);
3204 assert_node_ref_count (ref_model, &level2_1, 1);
3205 assert_node_ref_count (ref_model, &level3_1, 0);
3206 assert_node_ref_count (ref_model, &level4_1, 0);
3208 path = gtk_tree_path_new_from_indices (0, -1);
3209 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3210 gtk_tree_path_free (path);
3212 assert_node_ref_count (ref_model, &level1_1, 3);
3213 assert_node_ref_count (ref_model, &level2_1, 3);
3214 assert_node_ref_count (ref_model, &level3_1, 3);
3215 assert_node_ref_count (ref_model, &level4_1, 2);
3217 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, FALSE, -1);
3219 assert_node_ref_count (ref_model, &level1_1, 3);
3220 assert_node_ref_count (ref_model, &level2_1, 1);
3221 assert_node_ref_count (ref_model, &level3_1, 0);
3222 assert_node_ref_count (ref_model, &level4_1, 0);
3224 gtk_widget_destroy (tree_view);
3225 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3227 assert_node_ref_count (ref_model, &level1_1, 2);
3228 assert_node_ref_count (ref_model, &level2_1, 1);
3229 assert_node_ref_count (ref_model, &level3_1, 0);
3230 assert_node_ref_count (ref_model, &level4_1, 0);
3232 g_object_unref (filter_model);
3234 assert_node_ref_count (ref_model, &level1_1, 0);
3235 assert_node_ref_count (ref_model, &level2_1, 0);
3236 assert_node_ref_count (ref_model, &level3_1, 0);
3237 assert_node_ref_count (ref_model, &level4_1, 0);
3239 g_object_unref (ref_model);
3243 ref_count_filter_row_length_gt_1 (void)
3245 GtkTreeIter level1_1, level1_2;
3246 GtkTreeIter level2_1, level2_2;
3247 GtkTreeIter level3_1, level3_2;
3248 GtkTreeIter level4_1, level4_2;
3249 GtkTreeModel *model;
3250 GtkTreeModelRefCount *ref_model;
3251 GtkTreeModel *filter_model;
3253 GtkWidget *tree_view;
3254 GType column_types[] = { G_TYPE_BOOLEAN };
3256 model = gtk_tree_model_ref_count_new ();
3257 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3259 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3272 * Node level1_2 is expanded. This makes that levels 1 and 2 are
3273 * visible. Level 3 is cached because its parent is visible. Level 4
3277 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3278 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_2, NULL);
3279 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_2);
3280 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_2, &level1_2);
3281 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_2);
3282 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_2, &level2_2);
3283 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_2);
3284 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_2, &level3_2);
3286 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3287 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, TRUE, -1);
3288 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3289 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, TRUE, -1);
3290 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3291 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_2, 0, TRUE, -1);
3292 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3293 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_2, 0, TRUE, -1);
3295 assert_entire_model_unreferenced (ref_model);
3297 filter_model = gtk_tree_model_filter_new (model, NULL);
3298 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3299 tree_view = gtk_tree_view_new_with_model (filter_model);
3301 assert_node_ref_count (ref_model, &level1_1, 2);
3302 assert_node_ref_count (ref_model, &level1_2, 2);
3303 assert_node_ref_count (ref_model, &level2_1, 1);
3304 assert_node_ref_count (ref_model, &level2_2, 0);
3305 assert_node_ref_count (ref_model, &level3_1, 0);
3306 assert_node_ref_count (ref_model, &level3_2, 0);
3307 assert_node_ref_count (ref_model, &level4_1, 0);
3308 assert_node_ref_count (ref_model, &level4_2, 0);
3310 path = gtk_tree_path_new_from_indices (1, -1);
3311 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
3312 gtk_tree_path_free (path);
3314 assert_node_ref_count (ref_model, &level1_1, 2);
3315 assert_node_ref_count (ref_model, &level1_2, 2);
3316 assert_node_ref_count (ref_model, &level2_1, 2);
3317 assert_node_ref_count (ref_model, &level2_2, 2);
3318 assert_node_ref_count (ref_model, &level3_1, 1);
3319 assert_node_ref_count (ref_model, &level3_2, 0);
3320 assert_node_ref_count (ref_model, &level4_1, 0);
3321 assert_node_ref_count (ref_model, &level4_2, 0);
3323 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, FALSE, -1);
3325 assert_node_ref_count (ref_model, &level1_1, 2);
3326 assert_node_ref_count (ref_model, &level1_2, 2);
3327 assert_node_ref_count (ref_model, &level2_1, 2);
3328 assert_node_ref_count (ref_model, &level2_2, 2);
3329 assert_node_ref_count (ref_model, &level3_1, 1);
3330 assert_node_ref_count (ref_model, &level3_2, 0);
3331 assert_node_ref_count (ref_model, &level4_1, 0);
3332 assert_node_ref_count (ref_model, &level4_2, 0);
3334 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, FALSE, -1);
3336 assert_node_ref_count (ref_model, &level1_1, 2);
3337 assert_node_ref_count (ref_model, &level1_2, 2);
3338 assert_node_ref_count (ref_model, &level2_1, 2);
3339 assert_node_ref_count (ref_model, &level2_2, 2);
3340 assert_node_ref_count (ref_model, &level3_1, 0);
3341 assert_node_ref_count (ref_model, &level3_2, 1);
3342 assert_node_ref_count (ref_model, &level4_1, 0);
3343 assert_node_ref_count (ref_model, &level4_2, 0);
3345 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, FALSE, -1);
3347 assert_node_ref_count (ref_model, &level1_1, 2);
3348 assert_node_ref_count (ref_model, &level1_2, 2);
3349 assert_node_ref_count (ref_model, &level2_1, 2);
3350 assert_node_ref_count (ref_model, &level2_2, 0);
3351 assert_node_ref_count (ref_model, &level3_1, 0);
3352 assert_node_ref_count (ref_model, &level3_2, 0);
3353 assert_node_ref_count (ref_model, &level4_1, 0);
3354 assert_node_ref_count (ref_model, &level4_2, 0);
3356 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, FALSE, -1);
3358 assert_node_ref_count (ref_model, &level1_1, 2);
3359 assert_node_ref_count (ref_model, &level1_2, 0);
3360 assert_node_ref_count (ref_model, &level2_1, 0);
3361 assert_node_ref_count (ref_model, &level2_2, 0);
3362 assert_node_ref_count (ref_model, &level3_1, 0);
3363 assert_node_ref_count (ref_model, &level3_2, 0);
3364 assert_node_ref_count (ref_model, &level4_1, 0);
3365 assert_node_ref_count (ref_model, &level4_2, 0);
3367 gtk_widget_destroy (tree_view);
3368 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3370 assert_node_ref_count (ref_model, &level1_1, 1);
3372 g_object_unref (filter_model);
3374 assert_node_ref_count (ref_model, &level1_1, 0);
3376 g_object_unref (ref_model);
3380 ref_count_filter_row_length_gt_1_visible_children (void)
3382 GtkTreeIter level1_1, level1_2;
3383 GtkTreeIter level2_1, level2_2;
3384 GtkTreeIter level3_1, level3_2;
3385 GtkTreeIter level4_1, level4_2;
3386 GtkTreeModel *model;
3387 GtkTreeModelRefCount *ref_model;
3388 GtkTreeModel *filter_model;
3390 GtkWidget *tree_view;
3391 GType column_types[] = { G_TYPE_BOOLEAN };
3393 model = gtk_tree_model_ref_count_new ();
3394 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3396 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3410 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3411 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_2, NULL);
3412 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_2);
3413 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_2, &level1_2);
3414 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_2);
3415 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_2, &level2_2);
3416 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_2);
3417 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_2, &level3_2);
3419 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3420 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, TRUE, -1);
3421 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3422 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, TRUE, -1);
3423 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3424 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_2, 0, TRUE, -1);
3425 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3426 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_2, 0, TRUE, -1);
3428 assert_entire_model_unreferenced (ref_model);
3430 filter_model = gtk_tree_model_filter_new (model, NULL);
3431 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3432 tree_view = gtk_tree_view_new_with_model (filter_model);
3434 assert_node_ref_count (ref_model, &level1_1, 2);
3435 assert_node_ref_count (ref_model, &level1_2, 2);
3436 assert_node_ref_count (ref_model, &level2_1, 1);
3437 assert_node_ref_count (ref_model, &level2_2, 0);
3438 assert_node_ref_count (ref_model, &level3_1, 0);
3439 assert_node_ref_count (ref_model, &level3_2, 0);
3440 assert_node_ref_count (ref_model, &level4_1, 0);
3441 assert_node_ref_count (ref_model, &level4_2, 0);
3443 path = gtk_tree_path_new_from_indices (1, -1);
3444 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3445 gtk_tree_path_free (path);
3447 assert_node_ref_count (ref_model, &level1_1, 2);
3448 assert_node_ref_count (ref_model, &level1_2, 2);
3449 assert_node_ref_count (ref_model, &level2_1, 2);
3450 assert_node_ref_count (ref_model, &level2_2, 2);
3451 assert_node_ref_count (ref_model, &level3_1, 2);
3452 assert_node_ref_count (ref_model, &level3_2, 2);
3453 assert_node_ref_count (ref_model, &level4_1, 2);
3454 assert_node_ref_count (ref_model, &level4_2, 1);
3456 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, FALSE, -1);
3458 assert_node_ref_count (ref_model, &level1_1, 2);
3459 assert_node_ref_count (ref_model, &level1_2, 2);
3460 assert_node_ref_count (ref_model, &level2_1, 2);
3461 assert_node_ref_count (ref_model, &level2_2, 0);
3462 assert_node_ref_count (ref_model, &level3_1, 0);
3463 assert_node_ref_count (ref_model, &level3_2, 0);
3464 assert_node_ref_count (ref_model, &level4_1, 0);
3465 assert_node_ref_count (ref_model, &level4_2, 0);
3467 gtk_widget_destroy (tree_view);
3468 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3470 assert_node_ref_count (ref_model, &level1_1, 1);
3471 assert_node_ref_count (ref_model, &level1_2, 1);
3472 assert_node_ref_count (ref_model, &level2_1, 1);
3473 assert_node_ref_count (ref_model, &level2_2, 0);
3474 assert_node_ref_count (ref_model, &level3_1, 0);
3475 assert_node_ref_count (ref_model, &level3_2, 0);
3476 assert_node_ref_count (ref_model, &level4_1, 0);
3477 assert_node_ref_count (ref_model, &level4_2, 0);
3479 g_object_unref (filter_model);
3481 assert_node_ref_count (ref_model, &level1_1, 0);
3482 assert_node_ref_count (ref_model, &level1_2, 0);
3483 assert_node_ref_count (ref_model, &level2_1, 0);
3484 assert_node_ref_count (ref_model, &level2_2, 0);
3485 assert_node_ref_count (ref_model, &level3_1, 0);
3486 assert_node_ref_count (ref_model, &level3_2, 0);
3487 assert_node_ref_count (ref_model, &level4_1, 0);
3488 assert_node_ref_count (ref_model, &level4_2, 0);
3490 g_object_unref (ref_model);
3494 ref_count_cleanup (void)
3496 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
3497 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
3498 GtkTreeModel *model;
3499 GtkTreeModelRefCount *ref_model;
3500 GtkTreeModel *filter_model;
3501 GtkWidget *tree_view;
3503 model = gtk_tree_model_ref_count_new ();
3504 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3511 * + iter_parent2_first
3515 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3516 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3517 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
3518 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
3519 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
3520 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
3521 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
3523 filter_model = gtk_tree_model_filter_new (model, NULL);
3524 tree_view = gtk_tree_view_new_with_model (filter_model);
3526 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
3528 assert_node_ref_count (ref_model, &grandparent1, 2);
3529 assert_node_ref_count (ref_model, &grandparent2, 2);
3530 assert_node_ref_count (ref_model, &parent1, 3);
3531 assert_node_ref_count (ref_model, &parent2, 2);
3532 assert_node_ref_count (ref_model, &iter_parent1, 2);
3533 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
3534 assert_node_ref_count (ref_model, &iter_parent2, 1);
3536 gtk_widget_destroy (tree_view);
3538 assert_node_ref_count (ref_model, &grandparent1, 1);
3539 assert_node_ref_count (ref_model, &grandparent2, 1);
3540 assert_node_ref_count (ref_model, &parent1, 2);
3541 assert_node_ref_count (ref_model, &parent2, 1);
3542 assert_node_ref_count (ref_model, &iter_parent1, 1);
3543 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3544 assert_node_ref_count (ref_model, &iter_parent2, 0);
3546 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3548 /* The root level and first level remain cached, only the references on the
3549 * first nodes of these levels are kept. Grandparent2 is the parent
3550 * of the first level with parent1, so grandparent2 keeps a reference
3553 assert_node_ref_count (ref_model, &grandparent1, 1);
3554 assert_node_ref_count (ref_model, &grandparent2, 1);
3555 assert_node_ref_count (ref_model, &parent1, 1);
3556 assert_node_ref_count (ref_model, &parent2, 0);
3557 assert_node_ref_count (ref_model, &iter_parent1, 0);
3558 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
3559 assert_node_ref_count (ref_model, &iter_parent2, 0);
3561 g_object_unref (filter_model);
3562 g_object_unref (ref_model);
3566 ref_count_row_ref (void)
3568 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
3569 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
3570 GtkTreeModel *model;
3571 GtkTreeModelRefCount *ref_model;
3572 GtkTreeModel *filter_model;
3573 GtkWidget *tree_view;
3575 GtkTreeRowReference *row_ref;
3577 model = gtk_tree_model_ref_count_new ();
3578 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3589 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3590 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3591 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
3592 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
3593 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
3594 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
3595 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
3597 filter_model = gtk_tree_model_filter_new (model, NULL);
3598 tree_view = gtk_tree_view_new_with_model (filter_model);
3600 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3601 row_ref = gtk_tree_row_reference_new (filter_model, path);
3602 gtk_tree_path_free (path);
3604 assert_node_ref_count (ref_model, &grandparent1, 2);
3605 assert_node_ref_count (ref_model, &grandparent2, 3);
3606 assert_node_ref_count (ref_model, &parent1, 1);
3607 assert_node_ref_count (ref_model, &parent2, 2);
3608 assert_node_ref_count (ref_model, &iter_parent1, 0);
3609 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3610 assert_node_ref_count (ref_model, &iter_parent2, 1);
3612 gtk_tree_row_reference_free (row_ref);
3614 assert_node_ref_count (ref_model, &grandparent1, 2);
3615 assert_node_ref_count (ref_model, &grandparent2, 2);
3616 assert_node_ref_count (ref_model, &parent1, 1);
3617 assert_node_ref_count (ref_model, &parent2, 1);
3618 assert_node_ref_count (ref_model, &iter_parent1, 0);
3619 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3620 assert_node_ref_count (ref_model, &iter_parent2, 0);
3622 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3623 row_ref = gtk_tree_row_reference_new (filter_model, path);
3624 gtk_tree_path_free (path);
3626 assert_node_ref_count (ref_model, &grandparent1, 2);
3627 assert_node_ref_count (ref_model, &grandparent2, 3);
3628 assert_node_ref_count (ref_model, &parent1, 1);
3629 assert_node_ref_count (ref_model, &parent2, 2);
3630 assert_node_ref_count (ref_model, &iter_parent1, 0);
3631 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3632 assert_node_ref_count (ref_model, &iter_parent2, 1);
3634 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
3636 assert_node_ref_count (ref_model, &grandparent1, 2);
3637 assert_node_ref_count (ref_model, &grandparent2, 2);
3638 assert_node_ref_count (ref_model, &parent1, 1);
3639 assert_node_ref_count (ref_model, &iter_parent1, 0);
3641 gtk_tree_row_reference_free (row_ref);
3643 assert_node_ref_count (ref_model, &grandparent1, 2);
3644 assert_node_ref_count (ref_model, &grandparent2, 2);
3645 assert_node_ref_count (ref_model, &parent1, 1);
3646 assert_node_ref_count (ref_model, &iter_parent1, 0);
3648 gtk_widget_destroy (tree_view);
3650 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3652 /* The root level and first level remain cached, only the references on the
3653 * first nodes of these levels are kept. Grandparent2 is the parent
3654 * of the first level with parent1, so grandparent2 keeps a reference
3657 assert_node_ref_count (ref_model, &grandparent1, 1);
3658 assert_node_ref_count (ref_model, &grandparent2, 1);
3659 assert_node_ref_count (ref_model, &parent1, 1);
3661 g_object_unref (filter_model);
3662 g_object_unref (ref_model);
3666 ref_count_transfer_root_level_insert (void)
3668 GtkTreeIter grandparent1, grandparent2, grandparent3;
3669 GtkTreeIter new_node;
3670 GtkTreeModel *model;
3671 GtkTreeModelRefCount *ref_model;
3672 GtkTreeModel *filter_model;
3673 GtkWidget *tree_view;
3675 model = gtk_tree_model_ref_count_new ();
3676 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3683 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3684 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3685 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3687 filter_model = gtk_tree_model_filter_new (model, NULL);
3688 tree_view = gtk_tree_view_new_with_model (filter_model);
3690 assert_node_ref_count (ref_model, &grandparent1, 2);
3691 assert_node_ref_count (ref_model, &grandparent2, 1);
3692 assert_node_ref_count (ref_model, &grandparent3, 1);
3694 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
3696 assert_node_ref_count (ref_model, &new_node, 2);
3697 assert_node_ref_count (ref_model, &grandparent1, 1);
3698 assert_node_ref_count (ref_model, &grandparent2, 1);
3699 assert_node_ref_count (ref_model, &grandparent3, 1);
3701 gtk_widget_destroy (tree_view);
3702 g_object_unref (filter_model);
3703 g_object_unref (ref_model);
3707 ref_count_transfer_root_level_remove (void)
3709 GtkTreeIter grandparent1, grandparent2, grandparent3;
3710 GtkTreeModel *model;
3711 GtkTreeModelRefCount *ref_model;
3712 GtkTreeModel *filter_model;
3713 GtkWidget *tree_view;
3715 model = gtk_tree_model_ref_count_new ();
3716 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3723 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3724 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3725 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3727 filter_model = gtk_tree_model_filter_new (model, NULL);
3728 tree_view = gtk_tree_view_new_with_model (filter_model);
3730 assert_node_ref_count (ref_model, &grandparent1, 2);
3731 assert_node_ref_count (ref_model, &grandparent2, 1);
3732 assert_node_ref_count (ref_model, &grandparent3, 1);
3734 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent1);
3736 assert_node_ref_count (ref_model, &grandparent2, 2);
3737 assert_node_ref_count (ref_model, &grandparent3, 1);
3739 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
3741 assert_node_ref_count (ref_model, &grandparent3, 2);
3743 gtk_widget_destroy (tree_view);
3744 g_object_unref (filter_model);
3745 g_object_unref (ref_model);
3749 ref_count_transfer_root_level_remove_filtered (void)
3751 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
3752 GtkTreeModel *model;
3753 GtkTreeModelRefCount *ref_model;
3754 GtkTreeModel *filter_model;
3755 GtkWidget *tree_view;
3756 GType column_types[] = { G_TYPE_BOOLEAN };
3758 model = gtk_tree_model_ref_count_new ();
3759 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3761 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3770 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3771 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3772 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3773 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, NULL);
3775 /* Filter first node */
3776 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
3777 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3778 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
3779 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
3781 filter_model = gtk_tree_model_filter_new (model, NULL);
3782 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3783 tree_view = gtk_tree_view_new_with_model (filter_model);
3785 assert_node_ref_count (ref_model, &grandparent1, 0);
3786 assert_node_ref_count (ref_model, &grandparent2, 2);
3787 assert_node_ref_count (ref_model, &grandparent3, 1);
3788 assert_node_ref_count (ref_model, &grandparent4, 1);
3790 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
3792 gtk_tree_model_ref_count_dump (ref_model);
3794 assert_node_ref_count (ref_model, &grandparent1, 0);
3795 assert_node_ref_count (ref_model, &grandparent3, 2);
3796 assert_node_ref_count (ref_model, &grandparent4, 1);
3798 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent3);
3800 assert_node_ref_count (ref_model, &grandparent1, 0);
3801 assert_node_ref_count (ref_model, &grandparent4, 2);
3803 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent4);
3805 /* Check level length to get root level cached again */
3806 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), NULL, 0);
3808 assert_node_ref_count (ref_model, &grandparent1, 1);
3810 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3812 assert_node_ref_count (ref_model, &grandparent1, 1);
3813 assert_node_ref_count (ref_model, &grandparent2, 0);
3815 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3817 assert_node_ref_count (ref_model, &grandparent1, 1);
3818 assert_node_ref_count (ref_model, &grandparent2, 1);
3820 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), NULL, 1);
3822 gtk_widget_destroy (tree_view);
3823 g_object_unref (filter_model);
3824 g_object_unref (ref_model);
3828 ref_count_transfer_root_level_reordered (void)
3830 GtkTreeIter grandparent1, grandparent2, grandparent3;
3831 GtkTreeModel *model;
3832 GtkTreeModelRefCount *ref_model;
3833 GtkTreeModel *filter_model;
3834 GtkWidget *tree_view;
3836 model = gtk_tree_model_ref_count_new ();
3837 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3844 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3845 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3846 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3848 filter_model = gtk_tree_model_filter_new (model, NULL);
3849 tree_view = gtk_tree_view_new_with_model (filter_model);
3851 assert_node_ref_count (ref_model, &grandparent1, 2);
3852 assert_node_ref_count (ref_model, &grandparent2, 1);
3853 assert_node_ref_count (ref_model, &grandparent3, 1);
3855 /* gtk_tree_store_move() will emit rows-reordered */
3856 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3857 &grandparent1, &grandparent3);
3859 assert_node_ref_count (ref_model, &grandparent2, 2);
3860 assert_node_ref_count (ref_model, &grandparent3, 1);
3861 assert_node_ref_count (ref_model, &grandparent1, 1);
3863 gtk_widget_destroy (tree_view);
3864 g_object_unref (filter_model);
3865 g_object_unref (ref_model);
3869 ref_count_transfer_root_level_reordered_filtered (void)
3871 GtkTreeIter grandparent1, grandparent2, grandparent3;
3872 GtkTreeModel *model;
3873 GtkTreeModelRefCount *ref_model;
3874 GtkTreeModel *filter_model;
3875 GtkWidget *tree_view;
3876 GType column_types[] = { G_TYPE_BOOLEAN };
3878 model = gtk_tree_model_ref_count_new ();
3879 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3881 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3889 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3890 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3891 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3893 /* Test with 1 node filtered */
3894 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3895 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
3897 filter_model = gtk_tree_model_filter_new (model, NULL);
3898 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3899 tree_view = gtk_tree_view_new_with_model (filter_model);
3901 assert_node_ref_count (ref_model, &grandparent1, 0);
3902 assert_node_ref_count (ref_model, &grandparent2, 2);
3903 assert_node_ref_count (ref_model, &grandparent3, 1);
3905 /* Move the invisible node grandparent1 */
3907 /* gtk_tree_store_move() will emit rows-reordered */
3908 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3909 &grandparent1, &grandparent3);
3911 assert_node_ref_count (ref_model, &grandparent2, 2);
3912 assert_node_ref_count (ref_model, &grandparent3, 1);
3913 assert_node_ref_count (ref_model, &grandparent1, 0);
3915 /* Move the invisible node grandparent1 */
3917 /* gtk_tree_store_move() will emit rows-reordered */
3918 gtk_tree_store_move_before (GTK_TREE_STORE (model),
3919 &grandparent1, &grandparent2);
3921 assert_node_ref_count (ref_model, &grandparent1, 0);
3922 assert_node_ref_count (ref_model, &grandparent2, 2);
3923 assert_node_ref_count (ref_model, &grandparent3, 1);
3925 /* Now swap grandparent2 and grandparent3, first reference must transfer */
3926 /* gtk_tree_store_swap() will emit rows-reordered */
3927 gtk_tree_store_swap (GTK_TREE_STORE (model),
3928 &grandparent2, &grandparent3);
3930 assert_node_ref_count (ref_model, &grandparent1, 0);
3931 assert_node_ref_count (ref_model, &grandparent3, 2);
3932 assert_node_ref_count (ref_model, &grandparent2, 1);
3935 gtk_tree_store_swap (GTK_TREE_STORE (model),
3936 &grandparent2, &grandparent3);
3938 assert_node_ref_count (ref_model, &grandparent1, 0);
3939 assert_node_ref_count (ref_model, &grandparent2, 2);
3940 assert_node_ref_count (ref_model, &grandparent3, 1);
3942 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
3944 assert_node_ref_count (ref_model, &grandparent1, 2);
3945 assert_node_ref_count (ref_model, &grandparent2, 1);
3946 assert_node_ref_count (ref_model, &grandparent3, 1);
3948 /* Test with two nodes filtered */
3949 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
3950 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
3952 assert_node_ref_count (ref_model, &grandparent1, 0);
3953 assert_node_ref_count (ref_model, &grandparent2, 0);
3954 assert_node_ref_count (ref_model, &grandparent3, 2);
3956 /* gtk_tree_store_move() will emit rows-reordered */
3957 gtk_tree_store_move_before (GTK_TREE_STORE (model),
3958 &grandparent3, &grandparent1);
3960 assert_node_ref_count (ref_model, &grandparent3, 2);
3961 assert_node_ref_count (ref_model, &grandparent2, 0);
3962 assert_node_ref_count (ref_model, &grandparent1, 0);
3964 gtk_widget_destroy (tree_view);
3965 g_object_unref (filter_model);
3966 g_object_unref (ref_model);
3970 ref_count_transfer_root_level_filter (void)
3972 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
3973 GtkTreeIter new_node;
3974 GtkTreeModel *model;
3975 GtkTreeModelRefCount *ref_model;
3976 GtkTreeModel *filter_model;
3977 GtkWidget *tree_view;
3978 GType column_types[] = { G_TYPE_BOOLEAN };
3980 model = gtk_tree_model_ref_count_new ();
3981 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3983 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3992 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3993 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3994 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3995 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, NULL);
3997 /* Filter first node */
3998 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
3999 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4000 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
4001 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4003 filter_model = gtk_tree_model_filter_new (model, NULL);
4004 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4005 tree_view = gtk_tree_view_new_with_model (filter_model);
4007 assert_node_ref_count (ref_model, &grandparent1, 0);
4008 assert_node_ref_count (ref_model, &grandparent2, 2);
4009 assert_node_ref_count (ref_model, &grandparent3, 1);
4010 assert_node_ref_count (ref_model, &grandparent4, 1);
4012 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4014 assert_node_ref_count (ref_model, &grandparent1, 0);
4015 assert_node_ref_count (ref_model, &grandparent2, 0);
4016 assert_node_ref_count (ref_model, &grandparent3, 2);
4017 assert_node_ref_count (ref_model, &grandparent4, 1);
4019 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, FALSE, -1);
4021 assert_node_ref_count (ref_model, &grandparent1, 0);
4022 assert_node_ref_count (ref_model, &grandparent2, 0);
4023 assert_node_ref_count (ref_model, &grandparent3, 0);
4024 assert_node_ref_count (ref_model, &grandparent4, 2);
4026 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, FALSE, -1);
4028 assert_node_ref_count (ref_model, &grandparent1, 0);
4029 assert_node_ref_count (ref_model, &grandparent2, 0);
4030 assert_node_ref_count (ref_model, &grandparent3, 0);
4031 assert_node_ref_count (ref_model, &grandparent4, 1);
4033 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4035 assert_node_ref_count (ref_model, &grandparent1, 0);
4036 assert_node_ref_count (ref_model, &grandparent2, 2);
4037 assert_node_ref_count (ref_model, &grandparent3, 0);
4038 assert_node_ref_count (ref_model, &grandparent4, 0);
4040 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4042 assert_node_ref_count (ref_model, &grandparent1, 0);
4043 assert_node_ref_count (ref_model, &grandparent2, 0);
4044 assert_node_ref_count (ref_model, &grandparent3, 0);
4045 assert_node_ref_count (ref_model, &grandparent4, 1);
4047 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4049 assert_node_ref_count (ref_model, &grandparent1, 2);
4050 assert_node_ref_count (ref_model, &grandparent2, 0);
4051 assert_node_ref_count (ref_model, &grandparent3, 0);
4052 assert_node_ref_count (ref_model, &grandparent4, 0);
4054 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
4056 assert_node_ref_count (ref_model, &new_node, 0);
4057 assert_node_ref_count (ref_model, &grandparent1, 2);
4058 assert_node_ref_count (ref_model, &grandparent2, 0);
4059 assert_node_ref_count (ref_model, &grandparent3, 0);
4060 assert_node_ref_count (ref_model, &grandparent4, 0);
4062 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4064 assert_node_ref_count (ref_model, &new_node, 0);
4065 assert_node_ref_count (ref_model, &grandparent1, 0);
4066 assert_node_ref_count (ref_model, &grandparent2, 0);
4067 assert_node_ref_count (ref_model, &grandparent3, 0);
4068 assert_node_ref_count (ref_model, &grandparent4, 1);
4070 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4071 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
4073 assert_node_ref_count (ref_model, &new_node, 0);
4074 assert_node_ref_count (ref_model, &grandparent1, 0);
4075 assert_node_ref_count (ref_model, &grandparent2, 0);
4076 assert_node_ref_count (ref_model, &grandparent3, 0);
4077 assert_node_ref_count (ref_model, &grandparent4, 1);
4079 gtk_tree_store_set (GTK_TREE_STORE (model), &new_node, 0, TRUE, -1);
4081 assert_node_ref_count (ref_model, &new_node, 2);
4082 assert_node_ref_count (ref_model, &grandparent1, 0);
4083 assert_node_ref_count (ref_model, &grandparent2, 0);
4084 assert_node_ref_count (ref_model, &grandparent3, 0);
4085 assert_node_ref_count (ref_model, &grandparent4, 0);
4087 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4088 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4090 assert_node_ref_count (ref_model, &grandparent1, 0);
4091 assert_node_ref_count (ref_model, &grandparent2, 2);
4092 assert_node_ref_count (ref_model, &grandparent3, 0);
4093 assert_node_ref_count (ref_model, &grandparent4, 0);
4095 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4096 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
4098 gtk_widget_destroy (tree_view);
4099 g_object_unref (filter_model);
4100 g_object_unref (ref_model);
4104 ref_count_transfer_child_level_insert (void)
4106 GtkTreeIter grandparent1;
4107 GtkTreeIter parent1, parent2, parent3;
4108 GtkTreeIter new_node;
4109 GtkTreeModel *model;
4110 GtkTreeModelRefCount *ref_model;
4111 GtkTreeModel *filter_model;
4112 GtkWidget *tree_view;
4114 model = gtk_tree_model_ref_count_new ();
4115 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4123 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4124 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4125 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4126 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4128 filter_model = gtk_tree_model_filter_new (model, NULL);
4129 tree_view = gtk_tree_view_new_with_model (filter_model);
4131 assert_node_ref_count (ref_model, &grandparent1, 3);
4132 assert_node_ref_count (ref_model, &parent1, 1);
4133 assert_node_ref_count (ref_model, &parent2, 0);
4134 assert_node_ref_count (ref_model, &parent3, 0);
4136 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &grandparent1);
4138 assert_node_ref_count (ref_model, &grandparent1, 3);
4139 assert_node_ref_count (ref_model, &new_node, 1);
4140 assert_node_ref_count (ref_model, &parent1, 0);
4141 assert_node_ref_count (ref_model, &parent2, 0);
4142 assert_node_ref_count (ref_model, &parent3, 0);
4144 gtk_widget_destroy (tree_view);
4145 g_object_unref (filter_model);
4146 g_object_unref (ref_model);
4150 ref_count_transfer_child_level_remove (void)
4152 GtkTreeIter grandparent1;
4153 GtkTreeIter parent1, parent2, parent3;
4154 GtkTreeModel *model;
4155 GtkTreeModelRefCount *ref_model;
4156 GtkTreeModel *filter_model;
4157 GtkWidget *tree_view;
4159 model = gtk_tree_model_ref_count_new ();
4160 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4168 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4169 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4170 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4171 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4173 filter_model = gtk_tree_model_filter_new (model, NULL);
4174 tree_view = gtk_tree_view_new_with_model (filter_model);
4176 assert_node_ref_count (ref_model, &grandparent1, 3);
4177 assert_node_ref_count (ref_model, &parent1, 1);
4178 assert_node_ref_count (ref_model, &parent2, 0);
4179 assert_node_ref_count (ref_model, &parent3, 0);
4181 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1);
4183 gtk_tree_model_ref_count_dump (ref_model);
4185 assert_node_ref_count (ref_model, &grandparent1, 3);
4186 assert_node_ref_count (ref_model, &parent2, 1);
4187 assert_node_ref_count (ref_model, &parent3, 0);
4189 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
4191 assert_node_ref_count (ref_model, &grandparent1, 3);
4192 assert_node_ref_count (ref_model, &parent3, 1);
4194 gtk_widget_destroy (tree_view);
4195 g_object_unref (filter_model);
4196 g_object_unref (ref_model);
4200 ref_count_transfer_child_level_remove_filtered (void)
4202 GtkTreeIter grandparent1;
4203 GtkTreeIter parent1, parent2, parent3, parent4;
4204 GtkTreeModel *model;
4205 GtkTreeModelRefCount *ref_model;
4206 GtkTreeModel *filter_model;
4207 GtkWidget *tree_view;
4208 GType column_types[] = { G_TYPE_BOOLEAN };
4210 model = gtk_tree_model_ref_count_new ();
4211 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4213 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4223 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4224 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4225 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4226 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4227 gtk_tree_store_append (GTK_TREE_STORE (model), &parent4, &grandparent1);
4229 /* Filter first node */
4230 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4231 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, FALSE, -1);
4232 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4233 gtk_tree_store_set (GTK_TREE_STORE (model), &parent3, 0, TRUE, -1);
4234 gtk_tree_store_set (GTK_TREE_STORE (model), &parent4, 0, TRUE, -1);
4236 filter_model = gtk_tree_model_filter_new (model, NULL);
4237 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4238 tree_view = gtk_tree_view_new_with_model (filter_model);
4240 assert_node_ref_count (ref_model, &grandparent1, 3);
4241 assert_node_ref_count (ref_model, &parent1, 0);
4242 assert_node_ref_count (ref_model, &parent2, 1);
4243 assert_node_ref_count (ref_model, &parent3, 0);
4244 assert_node_ref_count (ref_model, &parent4, 0);
4246 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
4248 assert_node_ref_count (ref_model, &grandparent1, 3);
4249 assert_node_ref_count (ref_model, &parent1, 0);
4250 assert_node_ref_count (ref_model, &parent3, 1);
4251 assert_node_ref_count (ref_model, &parent4, 0);
4253 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent3);
4255 assert_node_ref_count (ref_model, &grandparent1, 3);
4256 assert_node_ref_count (ref_model, &parent1, 0);
4257 assert_node_ref_count (ref_model, &parent4, 1);
4259 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent4);
4261 /* Check level length to get level cached again */
4262 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), "0", 0);
4264 assert_node_ref_count (ref_model, &grandparent1, 3);
4265 assert_node_ref_count (ref_model, &parent1, 1);
4267 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4269 assert_node_ref_count (ref_model, &grandparent1, 3);
4270 assert_node_ref_count (ref_model, &parent1, 1);
4271 assert_node_ref_count (ref_model, &parent2, 0);
4273 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4275 assert_node_ref_count (ref_model, &grandparent1, 3);
4276 assert_node_ref_count (ref_model, &parent1, 1);
4277 assert_node_ref_count (ref_model, &parent2, 0);
4279 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), "0", 1);
4281 gtk_widget_destroy (tree_view);
4282 g_object_unref (filter_model);
4283 g_object_unref (ref_model);
4287 ref_count_transfer_child_level_reordered (void)
4289 GtkTreeIter grandparent1;
4290 GtkTreeIter parent1, parent2, parent3;
4291 GtkTreeModel *model;
4292 GtkTreeModelRefCount *ref_model;
4293 GtkTreeModel *filter_model;
4294 GtkWidget *tree_view;
4296 model = gtk_tree_model_ref_count_new ();
4297 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4305 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4306 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4307 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4308 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4310 filter_model = gtk_tree_model_filter_new (model, NULL);
4311 tree_view = gtk_tree_view_new_with_model (filter_model);
4313 assert_node_ref_count (ref_model, &grandparent1, 3);
4314 assert_node_ref_count (ref_model, &parent1, 1);
4315 assert_node_ref_count (ref_model, &parent2, 0);
4316 assert_node_ref_count (ref_model, &parent3, 0);
4318 /* gtk_tree_store_move() will emit rows-reordered */
4319 gtk_tree_store_move_after (GTK_TREE_STORE (model),
4320 &parent1, &parent3);
4322 assert_node_ref_count (ref_model, &grandparent1, 3);
4323 assert_node_ref_count (ref_model, &parent2, 1);
4324 assert_node_ref_count (ref_model, &parent3, 0);
4325 assert_node_ref_count (ref_model, &parent1, 0);
4327 gtk_widget_destroy (tree_view);
4328 g_object_unref (filter_model);
4329 g_object_unref (ref_model);
4333 ref_count_transfer_child_level_reordered_filtered (void)
4335 GtkTreeIter grandparent1;
4336 GtkTreeIter parent1, parent2, parent3;
4337 GtkTreeModel *model;
4338 GtkTreeModelRefCount *ref_model;
4339 GtkTreeModel *filter_model;
4340 GtkWidget *tree_view;
4341 GType column_types[] = { G_TYPE_BOOLEAN };
4343 model = gtk_tree_model_ref_count_new ();
4344 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4346 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4355 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4356 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4357 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4358 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4360 /* Test with 1 node filtered (parent1) */
4361 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4362 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4363 gtk_tree_store_set (GTK_TREE_STORE (model), &parent3, 0, TRUE, -1);
4365 filter_model = gtk_tree_model_filter_new (model, NULL);
4366 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4367 tree_view = gtk_tree_view_new_with_model (filter_model);
4369 assert_node_ref_count (ref_model, &grandparent1, 3);
4370 assert_node_ref_count (ref_model, &parent1, 0);
4371 assert_node_ref_count (ref_model, &parent2, 1);
4372 assert_node_ref_count (ref_model, &parent3, 0);
4374 /* Move invisible node parent 1 */
4376 /* gtk_tree_store_move() will emit rows-reordered */
4377 gtk_tree_store_move_after (GTK_TREE_STORE (model),
4378 &parent1, &parent3);
4380 assert_node_ref_count (ref_model, &grandparent1, 3);
4381 assert_node_ref_count (ref_model, &parent2, 1);
4382 assert_node_ref_count (ref_model, &parent3, 0);
4383 assert_node_ref_count (ref_model, &parent1, 0);
4385 /* Move invisible node parent 1 */
4387 /* gtk_tree_store_move() will emit rows-reordered */
4388 gtk_tree_store_move_before (GTK_TREE_STORE (model),
4389 &parent1, &parent2);
4391 assert_node_ref_count (ref_model, &grandparent1, 3);
4392 assert_node_ref_count (ref_model, &parent1, 0);
4393 assert_node_ref_count (ref_model, &parent2, 1);
4394 assert_node_ref_count (ref_model, &parent3, 0);
4396 /* Now swap parent2 and parent2, first reference must transfer */
4397 /* gtk_tree_store_swap() will emit rows-reordered */
4398 gtk_tree_store_swap (GTK_TREE_STORE (model),
4399 &parent2, &parent3);
4401 assert_node_ref_count (ref_model, &grandparent1, 3);
4402 assert_node_ref_count (ref_model, &parent1, 0);
4403 assert_node_ref_count (ref_model, &parent3, 1);
4404 assert_node_ref_count (ref_model, &parent2, 0);
4407 gtk_tree_store_swap (GTK_TREE_STORE (model),
4408 &parent2, &parent3);
4410 assert_node_ref_count (ref_model, &grandparent1, 3);
4411 assert_node_ref_count (ref_model, &parent1, 0);
4412 assert_node_ref_count (ref_model, &parent2, 1);
4413 assert_node_ref_count (ref_model, &parent3, 0);
4415 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, TRUE, -1);
4417 assert_node_ref_count (ref_model, &parent1, 1);
4418 assert_node_ref_count (ref_model, &parent2, 0);
4419 assert_node_ref_count (ref_model, &parent3, 0);
4421 /* Test with two nodes filtered */
4422 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, FALSE, -1);
4423 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, FALSE, -1);
4425 assert_node_ref_count (ref_model, &parent1, 0);
4426 assert_node_ref_count (ref_model, &parent2, 0);
4427 assert_node_ref_count (ref_model, &parent3, 1);
4429 /* gtk_tree_store_move() will emit rows-reordered */
4430 gtk_tree_store_move_before (GTK_TREE_STORE (model),
4431 &parent3, &parent1);
4433 assert_node_ref_count (ref_model, &parent3, 1);
4434 assert_node_ref_count (ref_model, &parent2, 0);
4435 assert_node_ref_count (ref_model, &parent1, 0);
4437 gtk_widget_destroy (tree_view);
4438 g_object_unref (filter_model);
4439 g_object_unref (ref_model);
4443 ref_count_transfer_child_level_filter (void)
4446 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
4447 GtkTreeIter new_node;
4448 GtkTreeModel *model;
4449 GtkTreeModelRefCount *ref_model;
4450 GtkTreeModel *filter_model;
4451 GtkWidget *tree_view;
4452 GType column_types[] = { G_TYPE_BOOLEAN };
4454 model = gtk_tree_model_ref_count_new ();
4455 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4457 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4467 gtk_tree_store_append (GTK_TREE_STORE (model), &root, NULL);
4468 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, &root);
4469 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, &root);
4470 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, &root);
4471 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, &root);
4473 /* Filter first node */
4474 gtk_tree_store_set (GTK_TREE_STORE (model), &root, 0, TRUE, -1);
4475 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4476 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4477 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
4478 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4480 filter_model = gtk_tree_model_filter_new (model, NULL);
4481 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4482 tree_view = gtk_tree_view_new_with_model (filter_model);
4484 assert_node_ref_count (ref_model, &grandparent1, 0);
4485 assert_node_ref_count (ref_model, &grandparent2, 1);
4486 assert_node_ref_count (ref_model, &grandparent3, 0);
4487 assert_node_ref_count (ref_model, &grandparent4, 0);
4489 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4491 assert_node_ref_count (ref_model, &grandparent1, 0);
4492 assert_node_ref_count (ref_model, &grandparent2, 0);
4493 assert_node_ref_count (ref_model, &grandparent3, 1);
4494 assert_node_ref_count (ref_model, &grandparent4, 0);
4496 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, FALSE, -1);
4498 assert_node_ref_count (ref_model, &grandparent1, 0);
4499 assert_node_ref_count (ref_model, &grandparent2, 0);
4500 assert_node_ref_count (ref_model, &grandparent3, 0);
4501 assert_node_ref_count (ref_model, &grandparent4, 1);
4503 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, FALSE, -1);
4505 assert_node_ref_count (ref_model, &grandparent1, 0);
4506 assert_node_ref_count (ref_model, &grandparent2, 0);
4507 assert_node_ref_count (ref_model, &grandparent3, 0);
4508 assert_node_ref_count (ref_model, &grandparent4, 1);
4510 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4512 assert_node_ref_count (ref_model, &grandparent1, 0);
4513 assert_node_ref_count (ref_model, &grandparent2, 1);
4514 assert_node_ref_count (ref_model, &grandparent3, 0);
4515 assert_node_ref_count (ref_model, &grandparent4, 0);
4517 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4519 assert_node_ref_count (ref_model, &grandparent1, 0);
4520 assert_node_ref_count (ref_model, &grandparent2, 0);
4521 assert_node_ref_count (ref_model, &grandparent3, 0);
4522 assert_node_ref_count (ref_model, &grandparent4, 1);
4524 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4526 assert_node_ref_count (ref_model, &grandparent1, 1);
4527 assert_node_ref_count (ref_model, &grandparent2, 0);
4528 assert_node_ref_count (ref_model, &grandparent3, 0);
4529 assert_node_ref_count (ref_model, &grandparent4, 0);
4531 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &root);
4533 assert_node_ref_count (ref_model, &new_node, 0);
4534 assert_node_ref_count (ref_model, &grandparent1, 1);
4535 assert_node_ref_count (ref_model, &grandparent2, 0);
4536 assert_node_ref_count (ref_model, &grandparent3, 0);
4537 assert_node_ref_count (ref_model, &grandparent4, 0);
4539 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4541 assert_node_ref_count (ref_model, &new_node, 0);
4542 assert_node_ref_count (ref_model, &grandparent1, 0);
4543 assert_node_ref_count (ref_model, &grandparent2, 0);
4544 assert_node_ref_count (ref_model, &grandparent3, 0);
4545 assert_node_ref_count (ref_model, &grandparent4, 1);
4547 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4548 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &root);
4550 assert_node_ref_count (ref_model, &new_node, 0);
4551 assert_node_ref_count (ref_model, &grandparent1, 0);
4552 assert_node_ref_count (ref_model, &grandparent2, 0);
4553 assert_node_ref_count (ref_model, &grandparent3, 0);
4554 assert_node_ref_count (ref_model, &grandparent4, 1);
4556 gtk_tree_store_set (GTK_TREE_STORE (model), &new_node, 0, TRUE, -1);
4558 assert_node_ref_count (ref_model, &new_node, 1);
4559 assert_node_ref_count (ref_model, &grandparent1, 0);
4560 assert_node_ref_count (ref_model, &grandparent2, 0);
4561 assert_node_ref_count (ref_model, &grandparent3, 0);
4562 assert_node_ref_count (ref_model, &grandparent4, 0);
4564 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4565 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4567 assert_node_ref_count (ref_model, &grandparent1, 0);
4568 assert_node_ref_count (ref_model, &grandparent2, 1);
4569 assert_node_ref_count (ref_model, &grandparent3, 0);
4570 assert_node_ref_count (ref_model, &grandparent4, 0);
4572 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4573 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
4575 gtk_widget_destroy (tree_view);
4576 g_object_unref (filter_model);
4577 g_object_unref (ref_model);
4582 specific_path_dependent_filter_func (GtkTreeModel *model,
4588 path = gtk_tree_model_get_path (model, iter);
4589 if (gtk_tree_path_get_indices (path)[0] < 4)
4596 specific_path_dependent_filter (void)
4602 GtkTreeModel *filter;
4604 list = gtk_list_store_new (1, G_TYPE_INT);
4605 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
4606 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
4607 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
4608 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
4609 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
4610 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
4611 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
4612 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
4614 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (list));
4615 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (sort), NULL);
4616 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4617 specific_path_dependent_filter_func,
4620 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort), 0,
4621 GTK_SORT_DESCENDING);
4623 for (i = 0; i < 4; i++)
4625 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
4627 gtk_list_store_remove (list, &iter);
4629 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
4631 gtk_list_store_remove (list, &iter);
4634 g_object_unref (filter);
4635 g_object_unref (sort);
4636 g_object_unref (list);
4641 specific_append_after_collapse_visible_func (GtkTreeModel *model,
4646 gboolean hide_negative_numbers;
4648 gtk_tree_model_get (model, iter, 1, &number, -1);
4649 hide_negative_numbers = GPOINTER_TO_INT (g_object_get_data (data, "private-hide-negative-numbers"));
4651 return (number >= 0 || !hide_negative_numbers);
4655 specific_append_after_collapse (void)
4657 /* This test is based on one of the test cases I found in my
4658 * old test cases directory. I unfortunately do not have a record
4659 * from who this test case originated. -Kris.
4663 * - Show tree, expand, collapse.
4668 GtkTreeIter child_iter;
4669 GtkTreeIter child_iter2;
4670 GtkTreePath *append_path;
4671 GtkTreeStore *store;
4672 GtkTreeModel *filter;
4676 GtkWidget *tree_view;
4678 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT);
4680 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4681 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
4682 GINT_TO_POINTER (FALSE));
4683 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4684 specific_append_after_collapse_visible_func,
4687 sort = gtk_tree_model_sort_new_with_model (filter);
4689 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4690 tree_view = gtk_tree_view_new_with_model (sort);
4691 gtk_container_add (GTK_CONTAINER (window), tree_view);
4692 gtk_widget_realize (tree_view);
4694 while (gtk_events_pending ())
4695 gtk_main_iteration ();
4697 gtk_tree_store_prepend (store, &iter, NULL);
4698 gtk_tree_store_set (store, &iter,
4699 0, "hallo", 1, 1, -1);
4701 gtk_tree_store_append (store, &child_iter, &iter);
4702 gtk_tree_store_set (store, &child_iter,
4703 0, "toemaar", 1, 1, -1);
4705 gtk_tree_store_append (store, &child_iter2, &child_iter);
4706 gtk_tree_store_set (store, &child_iter2,
4707 0, "very deep", 1, 1, -1);
4709 append_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &child_iter2);
4711 gtk_tree_store_append (store, &child_iter, &iter);
4712 gtk_tree_store_set (store, &child_iter,
4713 0, "sja", 1, 1, -1);
4715 gtk_tree_store_append (store, &child_iter, &iter);
4716 gtk_tree_store_set (store, &child_iter,
4717 0, "some word", 1, -1, -1);
4719 /* Expand and collapse the tree */
4720 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4721 while (gtk_events_pending ())
4722 gtk_main_iteration ();
4724 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
4725 while (gtk_events_pending ())
4726 gtk_main_iteration ();
4728 /* Add another it */
4729 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
4730 GINT_TO_POINTER (TRUE));
4732 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, append_path))
4734 gtk_tree_store_append (store, &child_iter, &iter);
4735 gtk_tree_store_set (store, &child_iter,
4736 0, "new new new !!", 1, 1, -1);
4738 gtk_tree_path_free (append_path);
4741 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4742 while (gtk_events_pending ())
4743 gtk_main_iteration ();
4748 specific_sort_filter_remove_node_compare_func (GtkTreeModel *model,
4757 specific_sort_filter_remove_node_visible_func (GtkTreeModel *model,
4763 /* Do reference the model */
4764 gtk_tree_model_get (model, iter, 0, &item, -1);
4771 specific_sort_filter_remove_node (void)
4773 /* This test is based on one of the test cases I found in my
4774 * old test cases directory. I unfortunately do not have a record
4775 * from who this test case originated. -Kris.
4778 * - Create tree store, sort, filter models. The sort model has
4779 * a default sort func that is enabled, filter model a visible func
4780 * that defaults to returning FALSE.
4781 * - Remove a node from the tree store.
4785 GtkTreeStore *store;
4786 GtkTreeModel *filter;
4790 GtkWidget *tree_view;
4792 store = gtk_tree_store_new (1, G_TYPE_STRING);
4793 gtk_tree_store_append (store, &iter, NULL);
4794 gtk_tree_store_set (store, &iter, 0, "Hello1", -1);
4796 gtk_tree_store_append (store, &iter, NULL);
4797 gtk_tree_store_set (store, &iter, 0, "Hello2", -1);
4799 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
4800 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
4801 specific_sort_filter_remove_node_compare_func, NULL, NULL);
4803 filter = gtk_tree_model_filter_new (sort, NULL);
4804 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4805 specific_sort_filter_remove_node_visible_func,
4809 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4810 tree_view = gtk_tree_view_new_with_model (filter);
4811 gtk_container_add (GTK_CONTAINER (window), tree_view);
4812 gtk_widget_realize (tree_view);
4814 while (gtk_events_pending ())
4815 gtk_main_iteration ();
4818 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
4819 gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
4820 gtk_tree_store_remove (store, &iter);
4822 while (gtk_events_pending ())
4823 gtk_main_iteration ();
4828 specific_sort_filter_remove_root (void)
4830 /* This test is based on one of the test cases I found in my
4831 * old test cases directory. I unfortunately do not have a record
4832 * from who this test case originated. -Kris.
4835 GtkTreeModel *model, *sort, *filter;
4836 GtkTreeIter root, mid, leaf;
4839 model = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
4840 gtk_tree_store_append (GTK_TREE_STORE (model), &root, NULL);
4841 gtk_tree_store_append (GTK_TREE_STORE (model), &mid, &root);
4842 gtk_tree_store_append (GTK_TREE_STORE (model), &leaf, &mid);
4844 path = gtk_tree_model_get_path (model, &mid);
4846 sort = gtk_tree_model_sort_new_with_model (model);
4847 filter = gtk_tree_model_filter_new (sort, path);
4849 gtk_tree_path_free (path);
4851 gtk_tree_store_remove (GTK_TREE_STORE (model), &root);
4853 g_object_unref (filter);
4854 g_object_unref (sort);
4855 g_object_unref (model);
4860 specific_root_mixed_visibility (void)
4863 GtkTreeModel *filter;
4864 /* A bit nasty, apologies */
4867 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4869 for (i = 0; i < LEVEL_LENGTH; i++)
4873 gtk_tree_store_insert (fixture.store, &iter, NULL, i);
4875 create_tree_store_set_values (fixture.store, &iter, TRUE);
4877 create_tree_store_set_values (fixture.store, &iter, FALSE);
4880 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
4881 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4882 fixture.monitor = NULL;
4884 gtk_tree_model_filter_set_visible_column (fixture.filter, 1);
4886 /* In order to trigger the potential bug, we should not access
4887 * the filter model here (so don't call the check functions).
4890 /* Change visibility of an odd row to TRUE */
4891 set_path_visibility (&fixture, "3", TRUE);
4892 check_filter_model (&fixture);
4893 check_level_length (fixture.filter, NULL, 4);
4899 specific_has_child_filter_filter_func (GtkTreeModel *model,
4903 return gtk_tree_model_iter_has_child (model, iter);
4907 specific_has_child_filter (void)
4909 GtkTreeModel *filter;
4910 GtkTreeIter iter, root;
4911 FilterTest fixture; /* This is not how it should be done */
4912 GtkWidget *tree_view;
4914 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4915 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
4916 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4917 fixture.monitor = signal_monitor_new (filter);
4919 tree_view = gtk_tree_view_new_with_model (filter);
4921 /* We will filter on parent state using a filter function. We will
4922 * manually keep the boolean column in sync, so that we can use
4923 * check_filter_model() to check the consistency of the model.
4925 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
4926 * to be able to check the structure here. We keep the calls to
4927 * check_filter_model() commented out until then.
4929 gtk_tree_model_filter_set_visible_func (fixture.filter,
4930 specific_has_child_filter_filter_func,
4933 /* The first node will be initially invisible: no signals */
4934 gtk_tree_store_append (fixture.store, &root, NULL);
4935 create_tree_store_set_values (fixture.store, &root, FALSE);
4937 /* check_filter_model (&fixture); */
4938 check_level_length (fixture.filter, NULL, 0);
4939 signal_monitor_assert_is_empty (fixture.monitor);
4941 /* Insert a child node. This will cause the parent to become visible
4942 * since there is a child now.
4944 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
4945 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4946 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4948 gtk_tree_store_append (fixture.store, &iter, &root);
4949 create_tree_store_set_values (fixture.store, &iter, TRUE);
4951 /* Parent must now be visible. Do the level length check first,
4952 * to avoid modifying the child model triggering a row-changed to
4955 check_level_length (fixture.filter, NULL, 1);
4956 check_level_length (fixture.filter, "0", 0);
4957 signal_monitor_assert_is_empty (fixture.monitor);
4959 /* This should propagate row-changed */
4960 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
4961 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4963 set_path_visibility (&fixture, "0", TRUE);
4964 /* check_filter_model (&fixture); */
4965 signal_monitor_assert_is_empty (fixture.monitor);
4967 /* New root node, no child, so no signal */
4968 gtk_tree_store_append (fixture.store, &root, NULL);
4969 check_level_length (fixture.filter, NULL, 1);
4970 signal_monitor_assert_is_empty (fixture.monitor);
4972 /* When the child comes in, this node will become visible */
4973 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
4974 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4975 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4976 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
4977 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4979 gtk_tree_store_append (fixture.store, &iter, &root);
4980 check_level_length (fixture.filter, NULL, 2);
4981 check_level_length (fixture.filter, "1", 0);
4983 create_tree_store_set_values (fixture.store, &root, TRUE);
4984 create_tree_store_set_values (fixture.store, &iter, TRUE);
4986 /* check_filter_model (&fixture); */
4987 signal_monitor_assert_is_empty (fixture.monitor);
4989 /* Add another child for 1 */
4990 gtk_tree_store_append (fixture.store, &iter, &root);
4991 create_tree_store_set_values (fixture.store, &iter, TRUE);
4992 check_level_length (fixture.filter, NULL, 2);
4993 check_level_length (fixture.filter, "0", 0);
4994 check_level_length (fixture.filter, "1", 0);
4995 signal_monitor_assert_is_empty (fixture.monitor);
4997 /* Now remove one of the remaining child rows */
4998 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5000 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5002 gtk_tree_store_remove (fixture.store, &iter);
5004 check_level_length (fixture.filter, NULL, 1);
5005 check_level_length (fixture.filter, "0", 0);
5007 set_path_visibility (&fixture, "0", FALSE);
5008 /* check_filter_model (&fixture); */
5009 signal_monitor_assert_is_empty (fixture.monitor);
5014 specific_root_has_child_filter_filter_func (GtkTreeModel *model,
5021 path = gtk_tree_model_get_path (model, iter);
5022 depth = gtk_tree_path_get_depth (path);
5023 gtk_tree_path_free (path);
5028 return gtk_tree_model_iter_has_child (model, iter);
5032 specific_root_has_child_filter (void)
5034 GtkTreeModel *filter;
5035 GtkTreeIter iter, root;
5036 FilterTest fixture; /* This is not how it should be done ... */
5037 GtkWidget *tree_view;
5039 /* This is a variation on the above test case, specific has-child-filter,
5040 * herein the has-child check for visibility only applies to root level
5041 * nodes. In this test, children are always visible because we
5042 * only filter based on the "has child" criterion.
5045 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5046 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
5047 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5048 fixture.monitor = signal_monitor_new (filter);
5050 tree_view = gtk_tree_view_new_with_model (filter);
5052 /* We will filter on parent state using a filter function. We will
5053 * manually keep the boolean column in sync, so that we can use
5054 * check_filter_model() to check the consistency of the model.
5056 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
5057 * to be able to check the structure here. We keep the calls to
5058 * check_filter_model() commented out until then.
5060 gtk_tree_model_filter_set_visible_func (fixture.filter,
5061 specific_root_has_child_filter_filter_func,
5064 /* Add a first node, this will be invisible initially, so no signal
5065 * should be emitted.
5067 gtk_tree_store_append (fixture.store, &root, NULL);
5068 create_tree_store_set_values (fixture.store, &root, FALSE);
5070 signal_monitor_assert_is_empty (fixture.monitor);
5071 /* check_filter_model (&fixture); */
5072 check_level_length (fixture.filter, NULL, 0);
5074 /* Add a child node. This will cause the parent to become visible,
5075 * so we expect row-inserted signals for both.
5077 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5078 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5079 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5081 gtk_tree_store_append (fixture.store, &iter, &root);
5082 signal_monitor_assert_is_empty (fixture.monitor);
5084 check_level_length (fixture.filter, NULL, 1);
5085 check_level_length (fixture.filter, "0", 1);
5087 /* Modify the content of iter, no signals because the parent is not
5090 create_tree_store_set_values (fixture.store, &iter, TRUE);
5091 signal_monitor_assert_is_empty (fixture.monitor);
5093 /* Parent must now be visible. Do the level length check first,
5094 * to avoid modifying the child model triggering a row-changed to
5097 check_level_length (fixture.filter, NULL, 1);
5098 check_level_length (fixture.filter, "0", 1);
5101 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5102 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5104 set_path_visibility (&fixture, "0", TRUE);
5105 /* check_filter_model (&fixture); */
5107 signal_monitor_assert_is_empty (fixture.monitor);
5109 /* Insert another node in the root level. Initially invisible, so
5110 * not expecting any signal.
5112 gtk_tree_store_append (fixture.store, &root, NULL);
5113 check_level_length (fixture.filter, NULL, 1);
5115 signal_monitor_assert_is_empty (fixture.monitor);
5117 /* Adding a child node which also makes parent at path 1 visible. */
5118 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5119 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5120 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5122 gtk_tree_store_append (fixture.store, &iter, &root);
5123 check_level_length (fixture.filter, NULL, 2);
5124 check_level_length (fixture.filter, "1", 1);
5126 signal_monitor_assert_is_empty (fixture.monitor);
5128 /* Check if row-changed is propagated */
5129 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5130 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5132 create_tree_store_set_values (fixture.store, &root, TRUE);
5133 create_tree_store_set_values (fixture.store, &iter, TRUE);
5134 /* check_filter_model (&fixture); */
5135 signal_monitor_assert_is_empty (fixture.monitor);
5137 /* Insert another child under node 1 */
5138 gtk_tree_store_append (fixture.store, &iter, &root);
5139 create_tree_store_set_values (fixture.store, &iter, TRUE);
5140 check_level_length (fixture.filter, NULL, 2);
5141 check_level_length (fixture.filter, "0", 1);
5142 check_level_length (fixture.filter, "1", 2);
5143 signal_monitor_assert_is_empty (fixture.monitor);
5145 /* Set a child node to invisible. This should not yield any
5146 * change, because filtering is only done on whether the root
5147 * node has a child, which it still has.
5149 set_path_visibility (&fixture, "0:0", FALSE);
5150 signal_monitor_assert_is_empty (fixture.monitor);
5152 /* Now remove one of the remaining child rows */
5153 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5154 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5156 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5158 gtk_tree_store_remove (fixture.store, &iter);
5160 check_level_length (fixture.filter, NULL, 1);
5161 check_level_length (fixture.filter, "0", 2);
5162 signal_monitor_assert_is_empty (fixture.monitor);
5164 /* Set visibility of 0 to FALSE, no-op for filter model since
5165 * the child 0:0 is already gone
5167 set_path_visibility (&fixture, "0", FALSE);
5168 /* check_filter_model (&fixture); */
5169 signal_monitor_assert_is_empty (fixture.monitor);
5173 specific_has_child_filter_on_sort_model (void)
5175 GtkTreeModel *filter;
5176 GtkTreeModel *sort_model;
5177 GtkTreeIter iter, root;
5178 FilterTest fixture; /* This is not how it should be done */
5179 GtkWidget *tree_view;
5181 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5182 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
5183 filter = gtk_tree_model_filter_new (sort_model, NULL);
5184 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5185 fixture.monitor = signal_monitor_new (filter);
5187 tree_view = gtk_tree_view_new_with_model (filter);
5189 /* We will filter on parent state using a filter function. We will
5190 * manually keep the boolean column in sync, so that we can use
5191 * check_filter_model() to check the consistency of the model.
5193 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
5194 * to be able to check the structure here. We keep the calls to
5195 * check_filter_model() commented out until then.
5197 gtk_tree_model_filter_set_visible_func (fixture.filter,
5198 specific_has_child_filter_filter_func,
5201 /* The first node will be initially invisible: no signals */
5202 gtk_tree_store_append (fixture.store, &root, NULL);
5203 create_tree_store_set_values (fixture.store, &root, FALSE);
5205 /* check_filter_model (&fixture); */
5206 check_level_length (fixture.filter, NULL, 0);
5207 signal_monitor_assert_is_empty (fixture.monitor);
5209 /* Insert a child node. This will cause the parent to become visible
5210 * since there is a child now.
5212 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5213 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5215 gtk_tree_store_append (fixture.store, &iter, &root);
5216 create_tree_store_set_values (fixture.store, &iter, TRUE);
5218 /* Parent must now be visible. Do the level length check first,
5219 * to avoid modifying the child model triggering a row-changed to
5222 check_level_length (fixture.filter, NULL, 1);
5223 check_level_length (fixture.filter, "0", 0);
5224 signal_monitor_assert_is_empty (fixture.monitor);
5226 /* This should propagate row-changed */
5227 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5228 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5230 set_path_visibility (&fixture, "0", TRUE);
5231 /* check_filter_model (&fixture); */
5232 signal_monitor_assert_is_empty (fixture.monitor);
5234 /* New root node, no child, so no signal */
5235 gtk_tree_store_append (fixture.store, &root, NULL);
5236 check_level_length (fixture.filter, NULL, 1);
5237 signal_monitor_assert_is_empty (fixture.monitor);
5239 /* When the child comes in, this node will become visible */
5240 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5241 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5242 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5243 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5245 gtk_tree_store_append (fixture.store, &iter, &root);
5246 check_level_length (fixture.filter, NULL, 2);
5247 check_level_length (fixture.filter, "1", 0);
5249 create_tree_store_set_values (fixture.store, &root, TRUE);
5250 create_tree_store_set_values (fixture.store, &iter, TRUE);
5252 /* check_filter_model (&fixture); */
5253 signal_monitor_assert_is_empty (fixture.monitor);
5255 /* Add another child for 1 */
5256 gtk_tree_store_append (fixture.store, &iter, &root);
5257 create_tree_store_set_values (fixture.store, &iter, TRUE);
5258 check_level_length (fixture.filter, NULL, 2);
5259 check_level_length (fixture.filter, "0", 0);
5260 check_level_length (fixture.filter, "1", 0);
5261 signal_monitor_assert_is_empty (fixture.monitor);
5263 /* Now remove one of the remaining child rows */
5264 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5266 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5268 gtk_tree_store_remove (fixture.store, &iter);
5270 check_level_length (fixture.filter, NULL, 1);
5271 check_level_length (fixture.filter, "0", 0);
5273 set_path_visibility (&fixture, "0", FALSE);
5274 /* check_filter_model (&fixture); */
5275 signal_monitor_assert_is_empty (fixture.monitor);
5279 specific_at_least_2_children_filter_filter_func (GtkTreeModel *model,
5283 return gtk_tree_model_iter_n_children (model, iter) >= 2;
5287 specific_at_least_2_children_filter (void)
5289 GtkTreeModel *filter;
5290 GtkTreeIter iter, root;
5291 FilterTest fixture; /* This is not how it should be done */
5292 GtkWidget *tree_view;
5294 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5295 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
5296 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5297 fixture.monitor = signal_monitor_new (filter);
5299 tree_view = gtk_tree_view_new_with_model (filter);
5301 gtk_tree_model_filter_set_visible_func (fixture.filter,
5302 specific_at_least_2_children_filter_filter_func,
5305 /* The first node will be initially invisible: no signals */
5306 gtk_tree_store_append (fixture.store, &root, NULL);
5307 create_tree_store_set_values (fixture.store, &root, FALSE);
5309 /* check_filter_model (&fixture); */
5310 check_level_length (fixture.filter, NULL, 0);
5311 signal_monitor_assert_is_empty (fixture.monitor);
5313 /* Insert a child node. Nothing should happen.
5315 gtk_tree_store_append (fixture.store, &iter, &root);
5316 create_tree_store_set_values (fixture.store, &iter, TRUE);
5318 check_level_length (fixture.filter, NULL, 0);
5319 signal_monitor_assert_is_empty (fixture.monitor);
5321 /* Insert a second child node. This will cause the parent to become
5324 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5325 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5327 gtk_tree_store_append (fixture.store, &iter, &root);
5328 create_tree_store_set_values (fixture.store, &iter, TRUE);
5330 /* Parent must now be visible. Do the level length check first,
5331 * to avoid modifying the child model triggering a row-changed to
5334 check_level_length (fixture.filter, NULL, 1);
5335 check_level_length (fixture.filter, "0", 0);
5336 signal_monitor_assert_is_empty (fixture.monitor);
5338 /* This should propagate row-changed */
5339 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5340 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5342 set_path_visibility (&fixture, "0", TRUE);
5343 /* check_filter_model (&fixture); */
5344 signal_monitor_assert_is_empty (fixture.monitor);
5346 /* New root node, no child, so no signal */
5347 gtk_tree_store_append (fixture.store, &root, NULL);
5348 check_level_length (fixture.filter, NULL, 1);
5349 signal_monitor_assert_is_empty (fixture.monitor);
5351 /* First child, no signal, no change */
5352 gtk_tree_store_append (fixture.store, &iter, &root);
5353 check_level_length (fixture.filter, NULL, 1);
5354 signal_monitor_assert_is_empty (fixture.monitor);
5356 /* When the second child comes in, this node will become visible */
5357 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5358 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5359 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5360 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5362 gtk_tree_store_append (fixture.store, &iter, &root);
5363 check_level_length (fixture.filter, NULL, 2);
5364 check_level_length (fixture.filter, "1", 0);
5366 create_tree_store_set_values (fixture.store, &root, TRUE);
5367 create_tree_store_set_values (fixture.store, &iter, TRUE);
5369 /* check_filter_model (&fixture); */
5370 signal_monitor_assert_is_empty (fixture.monitor);
5372 /* Add another child for 1 */
5373 gtk_tree_store_append (fixture.store, &iter, &root);
5374 create_tree_store_set_values (fixture.store, &iter, TRUE);
5375 check_level_length (fixture.filter, NULL, 2);
5376 check_level_length (fixture.filter, "0", 0);
5377 check_level_length (fixture.filter, "1", 0);
5378 signal_monitor_assert_is_empty (fixture.monitor);
5380 /* Now remove one of the remaining child rows */
5381 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5383 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5385 gtk_tree_store_remove (fixture.store, &iter);
5387 check_level_length (fixture.filter, NULL, 1);
5388 check_level_length (fixture.filter, "0", 0);
5390 set_path_visibility (&fixture, "0", FALSE);
5391 /* check_filter_model (&fixture); */
5392 signal_monitor_assert_is_empty (fixture.monitor);
5396 specific_at_least_2_children_filter_on_sort_model (void)
5398 GtkTreeModel *filter;
5399 GtkTreeModel *sort_model;
5400 GtkTreeIter iter, root;
5401 FilterTest fixture; /* This is not how it should be done */
5402 GtkWidget *tree_view;
5404 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5405 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
5406 filter = gtk_tree_model_filter_new (sort_model, NULL);
5407 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5408 fixture.monitor = signal_monitor_new (filter);
5410 tree_view = gtk_tree_view_new_with_model (filter);
5412 gtk_tree_model_filter_set_visible_func (fixture.filter,
5413 specific_at_least_2_children_filter_filter_func,
5416 /* The first node will be initially invisible: no signals */
5417 gtk_tree_store_append (fixture.store, &root, NULL);
5418 create_tree_store_set_values (fixture.store, &root, FALSE);
5420 /* check_filter_model (&fixture); */
5421 check_level_length (fixture.filter, NULL, 0);
5422 signal_monitor_assert_is_empty (fixture.monitor);
5424 /* Insert a child node. Nothing should happen.
5426 gtk_tree_store_append (fixture.store, &iter, &root);
5427 create_tree_store_set_values (fixture.store, &iter, TRUE);
5429 check_level_length (fixture.filter, NULL, 0);
5430 signal_monitor_assert_is_empty (fixture.monitor);
5433 GtkTreePath *path = gtk_tree_path_new_from_indices (0, 0, -1);
5434 GtkTreeRowReference *ref;
5436 ref = gtk_tree_row_reference_new (sort_model, path);
5437 gtk_tree_path_free (path);
5440 /* Insert a second child node. This will cause the parent to become
5443 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5444 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5446 gtk_tree_store_append (fixture.store, &iter, &root);
5447 create_tree_store_set_values (fixture.store, &iter, TRUE);
5449 /* Parent must now be visible. Do the level length check first,
5450 * to avoid modifying the child model triggering a row-changed to
5453 check_level_length (fixture.filter, NULL, 1);
5454 check_level_length (fixture.filter, "0", 0);
5455 signal_monitor_assert_is_empty (fixture.monitor);
5457 /* This should propagate row-changed */
5458 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5459 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5461 set_path_visibility (&fixture, "0", TRUE);
5462 /* check_filter_model (&fixture); */
5463 signal_monitor_assert_is_empty (fixture.monitor);
5465 /* New root node, no child, so no signal */
5466 gtk_tree_store_append (fixture.store, &root, NULL);
5467 check_level_length (fixture.filter, NULL, 1);
5468 signal_monitor_assert_is_empty (fixture.monitor);
5473 specific_filter_add_child (void)
5475 /* This test is based on one of the test cases I found in my
5476 * old test cases directory. I unfortunately do not have a record
5477 * from who this test case originated. -Kris.
5481 GtkTreeIter iter_first;
5483 GtkTreeStore *store;
5484 GtkTreeModel *filter G_GNUC_UNUSED;
5486 store = gtk_tree_store_new (1, G_TYPE_STRING);
5488 gtk_tree_store_append (store, &iter_first, NULL);
5489 gtk_tree_store_set (store, &iter_first, 0, "Hello", -1);
5491 gtk_tree_store_append (store, &iter, NULL);
5492 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5494 gtk_tree_store_append (store, &iter, NULL);
5495 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5497 gtk_tree_store_append (store, &iter, NULL);
5498 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5500 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
5502 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5503 gtk_tree_store_append (store, &child, &iter_first);
5504 gtk_tree_store_set (store, &child, 0, "Hello", -1);
5508 specific_list_store_clear (void)
5512 GtkTreeModel *filter;
5513 GtkWidget *view G_GNUC_UNUSED;
5515 list = gtk_list_store_new (1, G_TYPE_INT);
5516 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
5517 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
5518 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
5519 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
5520 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
5521 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
5522 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
5523 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
5525 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
5526 view = gtk_tree_view_new_with_model (filter);
5528 gtk_list_store_clear (list);
5532 specific_sort_ref_leaf_and_remove_ancestor (void)
5534 GtkTreeIter iter, child, child2, child3;
5538 GtkTreeRowReference *rowref;
5539 GtkWidget *view G_GNUC_UNUSED;
5541 tree = gtk_tree_store_new (1, G_TYPE_INT);
5542 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5543 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5544 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5545 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5547 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5548 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5549 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5551 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
5552 view = gtk_tree_view_new_with_model (sort);
5553 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5555 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5556 rowref = gtk_tree_row_reference_new (sort, path);
5557 gtk_tree_path_free (path);
5559 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5560 rowref = gtk_tree_row_reference_new (sort, path);
5561 gtk_tree_path_free (path);
5563 path = gtk_tree_path_new_from_indices (3, 0, -1);
5564 rowref = gtk_tree_row_reference_new (sort, path);
5565 gtk_tree_path_free (path);
5567 path = gtk_tree_path_new_from_indices (3, -1);
5568 rowref = gtk_tree_row_reference_new (sort, path);
5569 gtk_tree_path_free (path);
5571 /* Deleting a parent */
5572 path = gtk_tree_path_new_from_indices (3, 0, -1);
5573 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5574 gtk_tree_store_remove (tree, &iter);
5575 gtk_tree_path_free (path);
5577 gtk_tree_row_reference_free (rowref);
5581 specific_ref_leaf_and_remove_ancestor (void)
5583 GtkTreeIter iter, child, child2, child3;
5585 GtkTreeModel *filter;
5587 GtkTreeRowReference *rowref;
5588 GtkWidget *view G_GNUC_UNUSED;
5590 tree = gtk_tree_store_new (1, G_TYPE_INT);
5591 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5592 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5593 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5594 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5596 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5597 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5598 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5600 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), NULL);
5601 view = gtk_tree_view_new_with_model (filter);
5602 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5604 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5605 rowref = gtk_tree_row_reference_new (filter, path);
5606 gtk_tree_path_free (path);
5608 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5609 rowref = gtk_tree_row_reference_new (filter, path);
5610 gtk_tree_path_free (path);
5612 path = gtk_tree_path_new_from_indices (3, 0, -1);
5613 rowref = gtk_tree_row_reference_new (filter, path);
5614 gtk_tree_path_free (path);
5616 path = gtk_tree_path_new_from_indices (3, -1);
5617 rowref = gtk_tree_row_reference_new (filter, path);
5618 gtk_tree_path_free (path);
5620 /* Deleting a parent */
5621 path = gtk_tree_path_new_from_indices (3, 0, -1);
5622 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5623 gtk_tree_store_remove (tree, &iter);
5624 gtk_tree_path_free (path);
5626 gtk_tree_row_reference_free (rowref);
5630 specific_virtual_ref_leaf_and_remove_ancestor (void)
5632 GtkTreeIter iter, child, child2, child3;
5634 GtkTreeModel *filter;
5636 GtkTreeRowReference *rowref;
5637 GtkWidget *view G_GNUC_UNUSED;
5639 tree = gtk_tree_store_new (1, G_TYPE_INT);
5640 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5641 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5642 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5643 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5645 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5646 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5647 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5649 /* Set a virtual root of 3:0 */
5650 path = gtk_tree_path_new_from_indices (3, 0, -1);
5651 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
5652 gtk_tree_path_free (path);
5654 view = gtk_tree_view_new_with_model (filter);
5655 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5657 path = gtk_tree_path_new_from_indices (0, 0, -1);
5658 rowref = gtk_tree_row_reference_new (filter, path);
5659 gtk_tree_path_free (path);
5661 path = gtk_tree_path_new_from_indices (0, 0, -1);
5662 rowref = gtk_tree_row_reference_new (filter, path);
5663 gtk_tree_path_free (path);
5665 path = gtk_tree_path_new_from_indices (0, -1);
5666 rowref = gtk_tree_row_reference_new (filter, path);
5667 gtk_tree_path_free (path);
5669 /* Deleting the virtual root */
5670 path = gtk_tree_path_new_from_indices (3, 0, -1);
5671 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5672 gtk_tree_store_remove (tree, &iter);
5673 gtk_tree_path_free (path);
5675 gtk_tree_row_reference_free (rowref);
5680 specific_bug_301558_sort_func (GtkTreeModel *model,
5687 gtk_tree_model_get (model, a, 0, &i, -1);
5688 gtk_tree_model_get (model, b, 0, &j, -1);
5694 specific_bug_301558 (void)
5696 /* Test case for GNOME Bugzilla bug 301558 provided by
5700 GtkTreeModel *filter;
5702 GtkTreeIter root, iter, iter2;
5703 GtkWidget *view G_GNUC_UNUSED;
5707 g_test_bug ("301558");
5709 tree = gtk_tree_store_new (2, G_TYPE_INT, G_TYPE_BOOLEAN);
5710 gtk_tree_store_append (tree, &iter, NULL);
5711 gtk_tree_store_set (tree, &iter, 0, 123, 1, TRUE, -1);
5712 gtk_tree_store_append (tree, &iter2, &iter);
5713 gtk_tree_store_set (tree, &iter2, 0, 73, 1, TRUE, -1);
5715 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
5716 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
5717 specific_bug_301558_sort_func,
5720 filter = gtk_tree_model_filter_new (sort, NULL);
5721 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter), 1);
5723 view = gtk_tree_view_new_with_model (filter);
5725 while (gtk_events_pending ())
5726 gtk_main_iteration ();
5730 for (i = 0; i < 10; i++)
5732 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tree), &root))
5733 g_assert_not_reached ();
5737 gtk_tree_store_append (tree, &iter, &root);
5738 gtk_tree_store_set (tree, &iter, 0, 456, 1, TRUE, -1);
5743 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tree), &root);
5744 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tree), &iter,
5746 gtk_tree_store_remove (tree, &iter);
5755 specific_bug_311955_filter_func (GtkTreeModel *model,
5761 gtk_tree_model_get (model, iter, 0, &value, -1);
5763 return (value != 0);
5767 specific_bug_311955 (void)
5769 /* This is a test case for GNOME Bugzilla bug 311955. It was written
5772 GtkTreeIter iter, child, root;
5773 GtkTreeStore *store;
5775 GtkTreeModel *filter;
5777 GtkWidget *window G_GNUC_UNUSED;
5778 GtkWidget *tree_view;
5783 g_test_bug ("311955");
5785 store = gtk_tree_store_new (1, G_TYPE_INT);
5787 gtk_tree_store_append (store, &root, NULL);
5788 gtk_tree_store_set (store, &root, 0, 33, -1);
5790 gtk_tree_store_append (store, &iter, &root);
5791 gtk_tree_store_set (store, &iter, 0, 50, -1);
5793 gtk_tree_store_append (store, &iter, NULL);
5794 gtk_tree_store_set (store, &iter, 0, 22, -1);
5796 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
5797 filter = gtk_tree_model_filter_new (sort, NULL);
5799 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
5800 specific_bug_311955_filter_func,
5803 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
5804 tree_view = gtk_tree_view_new_with_model (filter);
5805 g_object_unref (store);
5807 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
5809 while (gtk_events_pending ())
5810 gtk_main_iteration ();
5812 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
5813 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
5816 for (i = 0; i < 4; i++)
5818 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
5820 gtk_tree_store_append (store, &iter, &root);
5823 gtk_tree_store_set (store, &iter, 0, i, -1);
5827 gtk_tree_store_append (store, &child, &iter);
5828 gtk_tree_store_set (store, &child, 0, 10, -1);
5832 while (gtk_events_pending ())
5833 gtk_main_iteration ();
5835 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5836 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 1);
5838 /* Remove bottommost child from the tree. */
5839 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
5840 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), &root);
5842 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter, &root, n - 2))
5844 if (gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &child, &iter))
5845 gtk_tree_store_remove (store, &child);
5848 g_assert_not_reached ();
5850 path = gtk_tree_path_new_from_indices (0, 2, -1);
5851 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
5852 gtk_tree_path_free (path);
5854 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5855 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
5859 specific_bug_311955_clean (void)
5861 /* Cleaned up version of the test case for GNOME Bugzilla bug 311955,
5862 * which is easier to understand.
5864 GtkTreeIter iter, child, grandchild;
5865 GtkTreeStore *store;
5867 GtkTreeModel *filter;
5869 GtkWidget *tree_view;
5872 store = gtk_tree_store_new (1, G_TYPE_INT);
5874 gtk_tree_store_append (store, &iter, NULL);
5875 gtk_tree_store_set (store, &iter, 0, 1, -1);
5877 gtk_tree_store_append (store, &child, &iter);
5878 gtk_tree_store_set (store, &child, 0, 1, -1);
5880 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
5881 filter = gtk_tree_model_filter_new (sort, NULL);
5883 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
5884 specific_bug_311955_filter_func,
5887 tree_view = gtk_tree_view_new_with_model (filter);
5888 g_object_unref (store);
5890 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
5892 while (gtk_events_pending ())
5893 gtk_main_iteration ();
5895 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
5896 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
5898 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
5900 gtk_tree_store_append (store, &child, &iter);
5901 gtk_tree_store_set (store, &child, 0, 0, -1);
5903 gtk_tree_store_append (store, &child, &iter);
5904 gtk_tree_store_set (store, &child, 0, 1, -1);
5906 gtk_tree_store_append (store, &child, &iter);
5907 gtk_tree_store_set (store, &child, 0, 1, -1);
5909 gtk_tree_store_append (store, &grandchild, &child);
5910 gtk_tree_store_set (store, &grandchild, 0, 1, -1);
5912 gtk_tree_store_append (store, &child, &iter);
5913 /* Don't set a value: assume 0 */
5915 /* Remove leaf node, check trigger row-has-child-toggled */
5916 path = gtk_tree_path_new_from_indices (0, 3, 0, -1);
5917 gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
5918 gtk_tree_path_free (path);
5919 gtk_tree_store_remove (store, &iter);
5921 path = gtk_tree_path_new_from_indices (0, 2, -1);
5922 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
5923 gtk_tree_path_free (path);
5925 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5926 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
5928 gtk_widget_destroy (tree_view);
5932 specific_bug_346800 (void)
5934 /* This is a test case for GNOME Bugzilla bug 346800. It was written
5935 * by Jonathan Matthew.
5938 GtkTreeIter node_iters[50];
5939 GtkTreeIter child_iters[50];
5940 GtkTreeModel *model;
5941 GtkTreeModelFilter *filter;
5942 GtkTreeStore *store;
5946 columns = g_new (GType, 2);
5947 columns[0] = G_TYPE_STRING;
5948 columns[1] = G_TYPE_BOOLEAN;
5949 store = gtk_tree_store_newv (2, columns);
5950 model = GTK_TREE_MODEL (store);
5952 g_test_bug ("346800");
5954 filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
5955 gtk_tree_model_filter_set_visible_column (filter, 1);
5957 for (i=0; i<items; i++)
5959 /* allocate random amounts of junk, otherwise the filter model's arrays can expand without moving */
5962 gtk_tree_store_append (store, &node_iters[i], NULL);
5963 gtk_tree_store_set (store, &node_iters[i],
5965 1, ((i%6) == 0) ? FALSE : TRUE,
5969 gtk_tree_store_append (store, &child_iters[i], &node_iters[i]);
5970 gtk_tree_store_set (store, &child_iters[i],
5971 0, "something else",
5974 gtk_tree_model_filter_refilter (filter);
5978 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-1], 1,
5979 (i & 1) ? TRUE : FALSE, -1);
5980 gtk_tree_model_filter_refilter (filter);
5982 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-2], 1,
5983 (i & 1) ? FALSE: TRUE, -1);
5984 gtk_tree_model_filter_refilter (filter);
5990 specific_bug_464173_visible_func (GtkTreeModel *model,
5994 gboolean *visible = (gboolean *)data;
6000 specific_bug_464173 (void)
6002 /* Test case for GNOME Bugzilla bug 464173, test case written
6003 * by Andreas Koehler.
6005 GtkTreeStore *model;
6006 GtkTreeModelFilter *f_model;
6007 GtkTreeIter iter1, iter2;
6008 GtkWidget *view G_GNUC_UNUSED;
6009 gboolean visible = TRUE;
6011 g_test_bug ("464173");
6013 model = gtk_tree_store_new (1, G_TYPE_STRING);
6014 gtk_tree_store_append (model, &iter1, NULL);
6015 gtk_tree_store_set (model, &iter1, 0, "Foo", -1);
6016 gtk_tree_store_append (model, &iter2, &iter1);
6017 gtk_tree_store_set (model, &iter2, 0, "Bar", -1);
6019 f_model = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL(model), NULL));
6020 gtk_tree_model_filter_set_visible_func (f_model,
6021 specific_bug_464173_visible_func,
6024 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (f_model));
6027 gtk_tree_model_filter_refilter (f_model);
6032 specific_bug_540201_filter_func (GtkTreeModel *model,
6036 gboolean has_children;
6038 has_children = gtk_tree_model_iter_has_child (model, iter);
6040 return has_children;
6044 specific_bug_540201 (void)
6046 /* Test case for GNOME Bugzilla bug 540201, steps provided by
6049 GtkTreeIter iter, root;
6050 GtkTreeStore *store;
6051 GtkTreeModel *filter;
6053 GtkWidget *tree_view G_GNUC_UNUSED;
6055 g_test_bug ("540201");
6057 store = gtk_tree_store_new (1, G_TYPE_INT);
6059 gtk_tree_store_append (store, &root, NULL);
6060 gtk_tree_store_set (store, &root, 0, 33, -1);
6062 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6063 tree_view = gtk_tree_view_new_with_model (filter);
6065 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6066 specific_bug_540201_filter_func,
6069 gtk_tree_store_append (store, &iter, &root);
6070 gtk_tree_store_set (store, &iter, 0, 50, -1);
6072 gtk_tree_store_append (store, &iter, &root);
6073 gtk_tree_store_set (store, &iter, 0, 22, -1);
6076 gtk_tree_store_append (store, &root, NULL);
6077 gtk_tree_store_set (store, &root, 0, 33, -1);
6079 gtk_tree_store_append (store, &iter, &root);
6080 gtk_tree_store_set (store, &iter, 0, 22, -1);
6085 specific_bug_549287_visible_func (GtkTreeModel *model,
6089 gboolean result = FALSE;
6091 result = gtk_tree_model_iter_has_child (model, iter);
6097 specific_bug_549287 (void)
6099 /* Test case for GNOME Bugzilla bug 529287, provided by Julient Puydt */
6102 GtkTreeStore *store;
6103 GtkTreeModel *filtered;
6104 GtkWidget *view G_GNUC_UNUSED;
6106 GtkTreeIter *swap, *parent, *child;
6108 g_test_bug ("529287");
6110 store = gtk_tree_store_new (1, G_TYPE_STRING);
6111 filtered = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6112 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filtered),
6113 specific_bug_549287_visible_func,
6116 view = gtk_tree_view_new_with_model (filtered);
6118 for (i = 0; i < 4; i++)
6120 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
6122 parent = gtk_tree_iter_copy (&iter);
6123 child = gtk_tree_iter_copy (&iter);
6125 while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store),
6134 gtk_tree_store_append (store, child, parent);
6135 gtk_tree_store_set (store, child,
6139 gtk_tree_iter_free (parent);
6140 gtk_tree_iter_free (child);
6144 gtk_tree_store_append (store, &iter, NULL);
6145 gtk_tree_store_set (store, &iter,
6150 /* since we inserted something, we changed the visibility conditions: */
6151 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filtered));
6156 specific_bug_621076_visible_func (GtkTreeModel *model,
6160 gboolean visible = FALSE;
6163 gtk_tree_model_get (model, iter, 0, &str, -1);
6164 if (str != NULL && g_str_has_prefix (str, "visible"))
6170 GtkTreeIter child_iter;
6173 /* Recursively check if we have a visible child */
6174 for (valid = gtk_tree_model_iter_children (model, &child_iter, iter);
6175 valid; valid = gtk_tree_model_iter_next (model, &child_iter))
6177 if (specific_bug_621076_visible_func (model, &child_iter, data))
6192 specific_bug_621076 (void)
6194 /* Test case for GNOME Bugzilla bug 621076, provided by Xavier Claessens */
6196 /* This test case differs from has-child-filter and root-has-child-filter
6197 * in that the visible function both filters on content and model
6198 * structure. Also, it is recursive.
6201 GtkTreeStore *store;
6202 GtkTreeModel *filter;
6204 GtkTreeIter group_iter;
6205 GtkTreeIter item_iter;
6206 SignalMonitor *monitor;
6208 g_test_bug ("621076");
6210 store = gtk_tree_store_new (1, G_TYPE_STRING);
6211 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6212 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6213 specific_bug_621076_visible_func,
6216 view = gtk_tree_view_new_with_model (filter);
6217 g_object_ref_sink (view);
6219 monitor = signal_monitor_new (filter);
6221 signal_monitor_append_signal (monitor, ROW_INSERTED, "0");
6222 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6223 0, "visible-group-0",
6225 signal_monitor_assert_is_empty (monitor);
6227 /* visible-group-0 is not expanded, so ROW_INSERTED should not be emitted
6228 * for its children. However, ROW_HAS_CHILD_TOGGLED should be emitted on
6229 * visible-group-0 to tell the view that row can be expanded. */
6230 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
6231 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
6232 group_iter = item_iter;
6233 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6236 signal_monitor_assert_is_empty (monitor);
6238 signal_monitor_append_signal (monitor, ROW_INSERTED, "1");
6239 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6240 0, "visible-group-1",
6242 signal_monitor_assert_is_empty (monitor);
6244 /* We are adding an hidden item inside visible-group-1, so
6245 * ROW_HAS_CHILD_TOGGLED should not be emitted. It is emitted though,
6246 * because the signal originating at TreeStore will be propagated,
6247 * as well a generated signal because the state of the parent *could*
6248 * change by a change in the model.
6250 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6251 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6252 group_iter = item_iter;
6253 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6256 signal_monitor_assert_is_empty (monitor);
6258 /* This group is invisible and its parent too. Nothing should be emitted */
6259 group_iter = item_iter;
6260 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6263 signal_monitor_assert_is_empty (monitor);
6265 /* Adding a visible item in this group hierarchy will make all nodes
6266 * in this path visible. The first level should simply tell the view
6267 * that it now has a child, and the view will load the tree if needed
6268 * (depends on the expanded state).
6270 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6271 group_iter = item_iter;
6272 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6273 0, "visible-1:0:0:0",
6275 signal_monitor_assert_is_empty (monitor);
6277 check_level_length (GTK_TREE_MODEL_FILTER (filter), "1", 1);
6279 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6282 signal_monitor_assert_is_empty (monitor);
6284 /* Parent is invisible, and adding this invisible item won't change that,
6285 * so no signal should be emitted. */
6286 group_iter = item_iter;
6287 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6290 signal_monitor_assert_is_empty (monitor);
6292 /* This makes group-2 visible, so it gets inserted and tells it has
6295 signal_monitor_append_signal (monitor, ROW_INSERTED, "2");
6296 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6297 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6300 signal_monitor_assert_is_empty (monitor);
6302 /* group-2 is already visible, so this time it is a normal insertion */
6303 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6306 signal_monitor_assert_is_empty (monitor);
6309 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6312 signal_monitor_assert_is_empty (monitor);
6314 /* Parent is invisible, and adding this invisible item won't change that,
6315 * so no signal should be emitted. */
6316 group_iter = item_iter;
6317 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6320 signal_monitor_assert_is_empty (monitor);
6322 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6325 signal_monitor_assert_is_empty (monitor);
6327 /* This will make group 3 visible. */
6328 signal_monitor_append_signal (monitor, ROW_INSERTED, "3");
6329 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
6330 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
6331 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
6332 signal_monitor_assert_is_empty (monitor);
6334 /* Make sure all groups are expanded, so the filter has the tree cached */
6335 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
6336 while (gtk_events_pending ())
6337 gtk_main_iteration ();
6339 /* Should only yield a row-changed */
6340 signal_monitor_append_signal (monitor, ROW_CHANGED, "3:0");
6341 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
6342 signal_monitor_assert_is_empty (monitor);
6344 /* Now remove/hide some items. If a group loses its last item, the group
6345 * should be deleted instead of the item.
6348 signal_monitor_append_signal (monitor, ROW_DELETED, "2:1");
6349 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:2");
6350 gtk_tree_store_remove (store, &item_iter);
6351 signal_monitor_assert_is_empty (monitor);
6353 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
6354 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6355 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
6356 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:1");
6357 gtk_tree_store_set (store, &item_iter, 0, "invisible-2:1", -1);
6358 signal_monitor_assert_is_empty (monitor);
6360 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0:0:0");
6361 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1:0:0");
6362 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0");
6363 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6364 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "1:0:0:0");
6365 gtk_tree_store_remove (store, &item_iter);
6366 signal_monitor_assert_is_empty (monitor);
6368 /* Hide a group using row-changed instead of row-deleted */
6369 /* Caution: group 2 is gone, so offsets of the signals have moved. */
6370 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
6371 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6372 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
6373 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter,
6375 gtk_tree_store_set (store, &item_iter, 0, "invisible-3:1", -1);
6376 signal_monitor_assert_is_empty (monitor);
6381 GtkTreeViewColumn *col;
6383 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
6385 col = gtk_tree_view_column_new_with_attributes ("foo",
6386 gtk_cell_renderer_text_new (),
6388 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
6390 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
6391 g_signal_connect (window, "delete-event",
6392 G_CALLBACK (gtk_widget_destroy), NULL);
6393 g_signal_connect (window, "destroy",
6394 G_CALLBACK (gtk_main_quit), NULL);
6396 gtk_container_add (GTK_CONTAINER (window), view);
6398 gtk_widget_show (view);
6399 gtk_widget_show (window);
6406 signal_monitor_free (monitor);
6407 g_object_unref (view);
6408 g_object_unref (store);
6409 g_object_unref (filter);
6413 specific_bug_657353_related (void)
6415 GtkTreeIter node1, node2, node3, node4;
6416 GtkTreeModel *model;
6417 GtkTreeModelRefCount *ref_model;
6418 GtkTreeModel *filter_model;
6419 GtkWidget *tree_view;
6420 GType column_types[] = { G_TYPE_BOOLEAN };
6422 /* gtk_tree_model_filter_rows_reordered() used to have a problem to
6423 * not properly transfer the first ref count when the first node in
6424 * the level does not have elt->offset == 0. This test checks for
6425 * that. This bug could cause the faulty condition
6426 * elt->ext_ref_count > elt->ref_count
6430 model = gtk_tree_model_ref_count_new ();
6431 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
6433 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
6436 gtk_tree_store_append (GTK_TREE_STORE (model), &node1, NULL);
6437 gtk_tree_store_append (GTK_TREE_STORE (model), &node2, NULL);
6438 gtk_tree_store_append (GTK_TREE_STORE (model), &node3, NULL);
6439 gtk_tree_store_append (GTK_TREE_STORE (model), &node4, NULL);
6441 /* Hide the first node */
6442 gtk_tree_store_set (GTK_TREE_STORE (model), &node1, 0, FALSE, -1);
6443 gtk_tree_store_set (GTK_TREE_STORE (model), &node2, 0, TRUE, -1);
6444 gtk_tree_store_set (GTK_TREE_STORE (model), &node3, 0, TRUE, -1);
6445 gtk_tree_store_set (GTK_TREE_STORE (model), &node4, 0, TRUE, -1);
6447 filter_model = gtk_tree_model_filter_new (model, NULL);
6448 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
6449 tree_view = gtk_tree_view_new_with_model (filter_model);
6451 assert_node_ref_count (ref_model, &node1, 0);
6452 assert_node_ref_count (ref_model, &node2, 2);
6453 assert_node_ref_count (ref_model, &node3, 1);
6454 assert_node_ref_count (ref_model, &node4, 1);
6456 /* Swap nodes 2 and 3 */
6458 /* gtk_tree_store_swap() will emit rows-reordered */
6459 gtk_tree_store_swap (GTK_TREE_STORE (model),
6462 assert_node_ref_count (ref_model, &node1, 0);
6463 assert_node_ref_count (ref_model, &node3, 2);
6464 assert_node_ref_count (ref_model, &node2, 1);
6465 assert_node_ref_count (ref_model, &node4, 1);
6468 gtk_tree_store_set (GTK_TREE_STORE (model), &node3, 0, FALSE, -1);
6470 assert_node_ref_count (ref_model, &node1, 0);
6471 assert_node_ref_count (ref_model, &node3, 0);
6472 assert_node_ref_count (ref_model, &node2, 2);
6473 assert_node_ref_count (ref_model, &node4, 1);
6475 gtk_widget_destroy (tree_view);
6476 g_object_unref (filter_model);
6477 g_object_unref (ref_model);
6481 specific_bug_657353_visible_func (GtkTreeModel *model,
6486 gboolean ret = FALSE;
6488 gtk_tree_model_get (model, iter, 0, &str, -1);
6489 ret = strstr (str, "hidden") ? FALSE : TRUE;
6496 specific_bug_657353 (void)
6498 GtkListStore *store;
6499 GtkTreeModel *sort_model;
6500 GtkTreeModel *filter_model;
6501 GtkTreeIter iter, iter_a, iter_b, iter_c;
6502 GtkWidget *tree_view;
6504 /* This is a very carefully crafted test case that is triggering the
6505 * situation described in bug 657353.
6507 * GtkListStore acts like EphyCompletionModel
6508 * GtkTreeModelSort acts like the sort model added in
6509 * ephy_location_entry_set_completion.
6510 * GtkTreeModelFilter acts like the filter model in
6511 * GtkEntryCompletion.
6514 /* Set up a model that's wrapped in a GtkTreeModelSort. The first item
6517 store = gtk_list_store_new (1, G_TYPE_STRING);
6518 gtk_list_store_insert_with_values (store, &iter_b, 0, 0, "BBB hidden", -1);
6519 gtk_list_store_insert_with_values (store, &iter, 1, 0, "EEE", -1);
6520 gtk_list_store_insert_with_values (store, &iter, 2, 0, "DDD", -1);
6521 gtk_list_store_insert_with_values (store, &iter_c, 3, 0, "CCC", -1);
6523 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
6525 filter_model = gtk_tree_model_filter_new (sort_model, NULL);
6526 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model),
6527 specific_bug_657353_visible_func,
6528 filter_model, NULL);
6530 tree_view = gtk_tree_view_new_with_model (filter_model);
6532 /* This triggers emission of rows-reordered. The elt with offset == 0
6533 * is hidden, which used to cause misbehavior. (The first reference should
6534 * have moved to CCC, which did not happen).
6536 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
6537 0, GTK_SORT_ASCENDING);
6539 /* By inserting another item that will appear at the first position, a
6540 * reference transfer is done from CCC (which failed to get this reference
6541 * earlier) to AAA. At this point, the rule
6542 * elt->ref_count >= elt->ext_ref_count is broken for CCC.
6544 gtk_list_store_insert_with_values (store, &iter_a, 6, 0, "AAA", -1);
6546 /* When we hide CCC, the references cannot be correctly released, because
6547 * CCC failed to get a reference during rows-reordered. The faulty condition
6548 * only manifests itself here with MODEL_FILTER_DEBUG disabled (as is usual
6551 gtk_list_store_set (store, &iter_c, 0, "CCC hidden", -1);
6553 gtk_widget_destroy (tree_view);
6554 g_object_unref (filter_model);
6555 g_object_unref (sort_model);
6556 g_object_unref (store);
6560 specific_bug_658696 (void)
6562 GtkTreeStore *store;
6563 GtkTreeModel *filter;
6567 store = create_tree_store (4, TRUE);
6569 vroot = gtk_tree_path_new_from_indices (0, 0, -1);
6570 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), vroot);
6571 gtk_tree_path_free (vroot);
6573 /* This used to cause a crash in gtk_tree_model_filter_check_ancestors() */
6574 gtk_tree_store_append (store, &iter, NULL);
6580 register_filter_model_tests (void)
6582 g_test_add ("/TreeModelFilter/self/verify-test-suite",
6586 filter_test_teardown);
6588 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-1",
6589 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6591 verify_test_suite_vroot,
6592 filter_test_teardown);
6593 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-2",
6594 FilterTest, gtk_tree_path_new_from_indices (2, 3, -1),
6596 verify_test_suite_vroot,
6597 filter_test_teardown);
6600 g_test_add ("/TreeModelFilter/filled/hide-root-level",
6603 filled_hide_root_level,
6604 filter_test_teardown);
6605 g_test_add ("/TreeModelFilter/filled/hide-child-levels",
6608 filled_hide_child_levels,
6609 filter_test_teardown);
6610 g_test_add ("/TreeModelFilter/filled/hide-child-levels/root-expanded",
6613 filled_hide_child_levels_root_expanded,
6614 filter_test_teardown);
6616 g_test_add ("/TreeModelFilter/filled/hide-root-level/vroot",
6617 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6619 filled_vroot_hide_root_level,
6620 filter_test_teardown);
6621 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot",
6622 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6624 filled_vroot_hide_child_levels,
6625 filter_test_teardown);
6626 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot-root-expanded",
6627 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6629 filled_vroot_hide_child_levels_root_expanded,
6630 filter_test_teardown);
6633 g_test_add ("/TreeModelFilter/empty/show-nodes",
6635 filter_test_setup_empty,
6637 filter_test_teardown);
6638 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes",
6640 filter_test_setup_empty,
6641 empty_show_multiple_nodes,
6642 filter_test_teardown);
6644 g_test_add ("/TreeModelFilter/empty/show-nodes/vroot",
6645 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6646 filter_test_setup_empty,
6647 empty_vroot_show_nodes,
6648 filter_test_teardown);
6649 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes/vroot",
6650 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6651 filter_test_setup_empty,
6652 empty_vroot_show_multiple_nodes,
6653 filter_test_teardown);
6656 g_test_add ("/TreeModelFilter/unfiltered/hide-single",
6658 filter_test_setup_unfiltered,
6659 unfiltered_hide_single,
6660 filter_test_teardown);
6661 g_test_add ("/TreeModelFilter/unfiltered/hide-single/root-expanded",
6663 filter_test_setup_unfiltered_root_expanded,
6664 unfiltered_hide_single_root_expanded,
6665 filter_test_teardown);
6666 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child",
6668 filter_test_setup_unfiltered,
6669 unfiltered_hide_single_child,
6670 filter_test_teardown);
6671 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/root-expanded",
6673 filter_test_setup_unfiltered_root_expanded,
6674 unfiltered_hide_single_child_root_expanded,
6675 filter_test_teardown);
6676 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level",
6678 filter_test_setup_unfiltered,
6679 unfiltered_hide_single_multi_level,
6680 filter_test_teardown);
6681 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/root-expanded",
6683 filter_test_setup_unfiltered_root_expanded,
6684 unfiltered_hide_single_multi_level_root_expanded,
6685 filter_test_teardown);
6687 g_test_add ("/TreeModelFilter/unfiltered/hide-single/vroot",
6688 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6689 filter_test_setup_unfiltered,
6690 unfiltered_vroot_hide_single,
6691 filter_test_teardown);
6692 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot",
6693 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6694 filter_test_setup_unfiltered,
6695 unfiltered_vroot_hide_single_child,
6696 filter_test_teardown);
6697 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot/root-expanded",
6698 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6699 filter_test_setup_unfiltered_root_expanded,
6700 unfiltered_vroot_hide_single_child_root_expanded,
6701 filter_test_teardown);
6702 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot",
6703 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6704 filter_test_setup_unfiltered,
6705 unfiltered_vroot_hide_single_multi_level,
6706 filter_test_teardown);
6707 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot/root-expanded",
6708 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6709 filter_test_setup_unfiltered_root_expanded,
6710 unfiltered_vroot_hide_single_multi_level_root_expanded,
6711 filter_test_teardown);
6715 g_test_add ("/TreeModelFilter/unfiltered/show-single",
6717 filter_test_setup_empty_unfiltered,
6718 unfiltered_show_single,
6719 filter_test_teardown);
6720 g_test_add ("/TreeModelFilter/unfiltered/show-single-child",
6722 filter_test_setup_empty_unfiltered,
6723 unfiltered_show_single_child,
6724 filter_test_teardown);
6725 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/root-expanded",
6727 filter_test_setup_empty_unfiltered_root_expanded,
6728 unfiltered_show_single_child_root_expanded,
6729 filter_test_teardown);
6730 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level",
6732 filter_test_setup_empty_unfiltered,
6733 unfiltered_show_single_multi_level,
6734 filter_test_teardown);
6735 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/root-expanded",
6737 filter_test_setup_empty_unfiltered_root_expanded,
6738 unfiltered_show_single_multi_level_root_expanded,
6739 filter_test_teardown);
6741 g_test_add ("/TreeModelFilter/unfiltered/show-single/vroot",
6742 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6743 filter_test_setup_empty_unfiltered,
6744 unfiltered_vroot_show_single,
6745 filter_test_teardown);
6746 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot",
6747 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6748 filter_test_setup_empty_unfiltered,
6749 unfiltered_vroot_show_single_child,
6750 filter_test_teardown);
6751 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot/root-expanded",
6752 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6753 filter_test_setup_empty_unfiltered_root_expanded,
6754 unfiltered_vroot_show_single_child_root_expanded,
6755 filter_test_teardown);
6756 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot",
6757 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6758 filter_test_setup_empty_unfiltered,
6759 unfiltered_vroot_show_single_multi_level,
6760 filter_test_teardown);
6761 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot/root-expanded",
6762 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6763 filter_test_setup_empty_unfiltered_root_expanded,
6764 unfiltered_vroot_show_single_multi_level_root_expanded,
6765 filter_test_teardown);
6768 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/root-level",
6770 filter_test_setup_unfiltered,
6771 unfiltered_rows_reordered_root_level,
6772 filter_test_teardown);
6773 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/child-level",
6775 filter_test_setup_unfiltered,
6776 unfiltered_rows_reordered_child_level,
6777 filter_test_teardown);
6779 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/first-hidden",
6782 filtered_rows_reordered_root_level_first_hidden,
6783 filter_test_teardown);
6784 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/middle-hidden",
6787 filtered_rows_reordered_root_level_middle_hidden,
6788 filter_test_teardown);
6789 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/first-hidden",
6792 filtered_rows_reordered_child_level_first_hidden,
6793 filter_test_teardown);
6794 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/middle-hidden",
6797 filtered_rows_reordered_child_level_middle_hidden,
6798 filter_test_teardown);
6799 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/4-hidden",
6802 filtered_rows_reordered_child_level_4_hidden,
6803 filter_test_teardown);
6804 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/all-hidden",
6807 filtered_rows_reordered_child_level_all_hidden,
6808 filter_test_teardown);
6810 /* Inserts in child models after creation of filter model */
6811 g_test_add_func ("/TreeModelFilter/insert/before",
6813 g_test_add_func ("/TreeModelFilter/insert/child",
6816 /* Removals from child model after creating of filter model */
6817 g_test_add_func ("/TreeModelFilter/remove/node",
6819 g_test_add_func ("/TreeModelFilter/remove/node-vroot",
6821 g_test_add_func ("/TreeModelFilter/remove/vroot-ancestor",
6822 remove_vroot_ancestor);
6824 /* Reference counting */
6825 g_test_add_func ("/TreeModelFilter/ref-count/single-level",
6826 ref_count_single_level);
6827 g_test_add_func ("/TreeModelFilter/ref-count/two-levels",
6828 ref_count_two_levels);
6829 g_test_add_func ("/TreeModelFilter/ref-count/three-levels",
6830 ref_count_three_levels);
6831 g_test_add_func ("/TreeModelFilter/ref-count/delete-row",
6832 ref_count_delete_row);
6833 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1",
6834 ref_count_filter_row_length_1);
6835 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1-remove-in-root-level",
6836 ref_count_filter_row_length_1_remove_in_root_level);
6837 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1-remove-in-child-level",
6838 ref_count_filter_row_length_1_remove_in_child_level);
6839 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-gt-1",
6840 ref_count_filter_row_length_gt_1);
6841 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-gt-1-visible-children",
6842 ref_count_filter_row_length_gt_1_visible_children);
6843 g_test_add_func ("/TreeModelFilter/ref-count/cleanup",
6845 g_test_add_func ("/TreeModelFilter/ref-count/row-ref",
6848 /* Reference counting, transfer of first reference on
6849 * first node in level. This is a GtkTreeModelFilter-specific
6852 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/insert",
6853 ref_count_transfer_root_level_insert);
6854 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/remove",
6855 ref_count_transfer_root_level_remove);
6856 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/remove/filtered",
6857 ref_count_transfer_root_level_remove_filtered);
6858 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered",
6859 ref_count_transfer_root_level_reordered);
6860 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered/filtered",
6861 ref_count_transfer_root_level_reordered_filtered);
6862 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/filter",
6863 ref_count_transfer_root_level_filter);
6864 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/insert",
6865 ref_count_transfer_child_level_insert);
6866 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/remove",
6867 ref_count_transfer_child_level_remove);
6868 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/remove/filtered",
6869 ref_count_transfer_child_level_remove_filtered);
6870 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered",
6871 ref_count_transfer_child_level_reordered);
6872 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered/filtered",
6873 ref_count_transfer_child_level_reordered_filtered);
6874 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/filter",
6875 ref_count_transfer_child_level_filter);
6877 g_test_add_func ("/TreeModelFilter/specific/path-dependent-filter",
6878 specific_path_dependent_filter);
6879 g_test_add_func ("/TreeModelFilter/specific/append-after-collapse",
6880 specific_append_after_collapse);
6881 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-node",
6882 specific_sort_filter_remove_node);
6883 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-root",
6884 specific_sort_filter_remove_root);
6885 g_test_add_func ("/TreeModelFilter/specific/root-mixed-visibility",
6886 specific_root_mixed_visibility);
6887 g_test_add_func ("/TreeModelFilter/specific/has-child-filter",
6888 specific_has_child_filter);
6889 g_test_add_func ("/TreeModelFilter/specific/has-child-filter-on-sort-model",
6890 specific_has_child_filter_on_sort_model);
6891 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter",
6892 specific_at_least_2_children_filter);
6893 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter-on-sort-model",
6894 specific_at_least_2_children_filter_on_sort_model);
6895 g_test_add_func ("/TreeModelFilter/specific/root-has-child-filter",
6896 specific_root_has_child_filter);
6897 g_test_add_func ("/TreeModelFilter/specific/filter-add-child",
6898 specific_filter_add_child);
6899 g_test_add_func ("/TreeModelFilter/specific/list-store-clear",
6900 specific_list_store_clear);
6901 g_test_add_func ("/TreeModelFilter/specific/sort-ref-leaf-and-remove-ancestor",
6902 specific_sort_ref_leaf_and_remove_ancestor);
6903 g_test_add_func ("/TreeModelFilter/specific/ref-leaf-and-remove-ancestor",
6904 specific_ref_leaf_and_remove_ancestor);
6905 g_test_add_func ("/TreeModelFilter/specific/virtual-ref-leaf-and-remove-ancestor",
6906 specific_virtual_ref_leaf_and_remove_ancestor);
6908 g_test_add_func ("/TreeModelFilter/specific/bug-301558",
6909 specific_bug_301558);
6910 g_test_add_func ("/TreeModelFilter/specific/bug-311955",
6911 specific_bug_311955);
6912 g_test_add_func ("/TreeModelFilter/specific/bug-311955-clean",
6913 specific_bug_311955_clean);
6914 g_test_add_func ("/TreeModelFilter/specific/bug-346800",
6915 specific_bug_346800);
6916 g_test_add_func ("/TreeModelFilter/specific/bug-464173",
6917 specific_bug_464173);
6918 g_test_add_func ("/TreeModelFilter/specific/bug-540201",
6919 specific_bug_540201);
6920 g_test_add_func ("/TreeModelFilter/specific/bug-549287",
6921 specific_bug_549287);
6922 g_test_add_func ("/TreeModelFilter/specific/bug-621076",
6923 specific_bug_621076);
6924 g_test_add_func ("/TreeModelFilter/specific/bug-657353-related",
6925 specific_bug_657353_related);
6926 g_test_add_func ("/TreeModelFilter/specific/bug-657353",
6927 specific_bug_657353);
6928 g_test_add_func ("/TreeModelFilter/specific/bug-658696",
6929 specific_bug_658696);