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.
22 #include "treemodel.h"
23 #include "gtktreemodelrefcount.h"
26 * - Proper coverage checking to see if the unit tests cover
28 * - Check if the iterator stamp is incremented at the correct times.
36 #define LEVEL_LENGTH 5
39 create_tree_store_set_values (GtkTreeStore *store,
46 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
47 path_string = gtk_tree_path_to_string (path);
49 gtk_tree_store_set (store, iter,
54 gtk_tree_path_free (path);
59 create_tree_store_recurse (int depth,
66 for (i = 0; i < LEVEL_LENGTH; i++)
70 gtk_tree_store_insert (store, &iter, parent, i);
71 create_tree_store_set_values (store, &iter, visible);
74 create_tree_store_recurse (depth - 1, store, &iter, visible);
79 create_tree_store (int depth,
84 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
86 create_tree_store_recurse (depth, store, NULL, visible);
100 GtkTreeModelFilter *filter;
102 SignalMonitor *monitor;
104 guint block_signals : 1;
109 filter_test_store_signal (FilterTest *fixture)
111 if (fixture->block_signals)
112 g_signal_stop_emission_by_name (fixture->store, "row-changed");
117 filter_test_setup_generic (FilterTest *fixture,
118 gconstpointer test_data,
123 const GtkTreePath *vroot = test_data;
124 GtkTreeModel *filter;
126 fixture->store = create_tree_store (depth, !empty);
128 g_signal_connect_swapped (fixture->store, "row-changed",
129 G_CALLBACK (filter_test_store_signal), fixture);
131 /* Please forgive me for casting const away. */
132 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture->store),
133 (GtkTreePath *)vroot);
134 fixture->filter = GTK_TREE_MODEL_FILTER (filter);
137 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
139 /* We need a tree view that's listening to get ref counting from that
142 fixture->tree_view = gtk_tree_view_new_with_model (filter);
144 fixture->monitor = signal_monitor_new (filter);
148 filter_test_setup_expand_root (FilterTest *fixture)
153 path = gtk_tree_path_new_from_indices (0, -1);
155 for (i = 0; i < LEVEL_LENGTH; i++)
157 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view),
159 gtk_tree_path_next (path);
161 gtk_tree_path_free (path);
165 filter_test_setup (FilterTest *fixture,
166 gconstpointer test_data)
168 filter_test_setup_generic (fixture, test_data, 3, FALSE, FALSE);
172 filter_test_setup_empty (FilterTest *fixture,
173 gconstpointer test_data)
175 filter_test_setup_generic (fixture, test_data, 3, TRUE, FALSE);
179 filter_test_setup_unfiltered (FilterTest *fixture,
180 gconstpointer test_data)
182 filter_test_setup_generic (fixture, test_data, 3, FALSE, TRUE);
186 filter_test_setup_unfiltered_root_expanded (FilterTest *fixture,
187 gconstpointer test_data)
189 filter_test_setup_unfiltered (fixture, test_data);
190 filter_test_setup_expand_root (fixture);
194 filter_test_setup_empty_unfiltered (FilterTest *fixture,
195 gconstpointer test_data)
197 filter_test_setup_generic (fixture, test_data, 3, TRUE, TRUE);
201 filter_test_setup_empty_unfiltered_root_expanded (FilterTest *fixture,
202 gconstpointer test_data)
204 filter_test_setup_empty_unfiltered (fixture, test_data);
205 filter_test_setup_expand_root (fixture);
209 strip_virtual_root (GtkTreePath *path,
210 GtkTreePath *root_path)
212 GtkTreePath *real_path;
217 int depth = gtk_tree_path_get_depth (path);
218 int root_depth = gtk_tree_path_get_depth (root_path);
220 real_path = gtk_tree_path_new ();
222 for (j = 0; j < depth - root_depth; j++)
223 gtk_tree_path_append_index (real_path,
224 gtk_tree_path_get_indices (path)[root_depth + j]);
227 real_path = gtk_tree_path_copy (path);
233 count_visible (FilterTest *fixture,
234 GtkTreePath *store_path)
240 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
243 for (i = 0; i < LEVEL_LENGTH; i++)
247 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
259 filter_test_append_refilter_signals_recurse (FilterTest *fixture,
260 GtkTreePath *store_path,
261 GtkTreePath *filter_path,
263 GtkTreePath *root_path)
266 int rows_deleted = 0;
269 gtk_tree_path_down (store_path);
270 gtk_tree_path_down (filter_path);
272 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
275 for (i = 0; i < LEVEL_LENGTH; i++)
278 GtkTreePath *real_path;
280 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
285 (!gtk_tree_path_is_descendant (store_path, root_path)
286 || !gtk_tree_path_compare (store_path, root_path)))
288 if (!gtk_tree_path_compare (store_path, root_path))
291 && gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
294 GtkTreePath *store_copy;
295 GtkTreePath *filter_copy;
297 store_copy = gtk_tree_path_copy (store_path);
298 filter_copy = gtk_tree_path_copy (filter_path);
299 filter_test_append_refilter_signals_recurse (fixture,
304 gtk_tree_path_free (store_copy);
305 gtk_tree_path_free (filter_copy);
309 gtk_tree_path_next (store_path);
310 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
313 gtk_tree_path_next (filter_path);
318 real_path = strip_virtual_root (filter_path, root_path);
322 /* This row will be inserted */
323 signal_monitor_append_signal_path (fixture->monitor, ROW_CHANGED,
326 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
329 signal_monitor_append_signal_path (fixture->monitor,
330 ROW_HAS_CHILD_TOGGLED,
335 GtkTreePath *store_copy;
336 GtkTreePath *filter_copy;
338 store_copy = gtk_tree_path_copy (store_path);
339 filter_copy = gtk_tree_path_copy (filter_path);
340 filter_test_append_refilter_signals_recurse (fixture,
345 gtk_tree_path_free (store_copy);
346 gtk_tree_path_free (filter_copy);
350 GtkTreePath *tmp_path;
352 /* If all child rows are invisible, then the last row to
353 * become invisible will emit row-has-child-toggled on the
357 tmp_path = gtk_tree_path_copy (store_path);
358 gtk_tree_path_append_index (tmp_path, 0);
360 if (count_visible (fixture, tmp_path) == 0)
361 signal_monitor_append_signal_path (fixture->monitor,
362 ROW_HAS_CHILD_TOGGLED,
365 gtk_tree_path_free (tmp_path);
369 gtk_tree_path_next (filter_path);
373 /* This row will be deleted */
375 signal_monitor_append_signal_path (fixture->monitor, ROW_DELETED,
379 gtk_tree_path_free (real_path);
381 gtk_tree_path_next (store_path);
382 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
385 if (rows_deleted == LEVEL_LENGTH
386 && gtk_tree_path_get_depth (filter_path) > 1)
388 GtkTreePath *real_path;
390 gtk_tree_path_up (store_path);
391 gtk_tree_path_up (filter_path);
393 /* A row-has-child-toggled will be emitted on the parent */
396 && gtk_tree_path_is_descendant (store_path, root_path)
397 && gtk_tree_path_compare (store_path, root_path)))
399 real_path = strip_virtual_root (filter_path, root_path);
400 signal_monitor_append_signal_path (fixture->monitor,
401 ROW_HAS_CHILD_TOGGLED,
404 gtk_tree_path_free (real_path);
410 filter_test_append_refilter_signals (FilterTest *fixture,
413 /* A special function that walks the tree store like the
414 * model validation functions below.
417 GtkTreePath *filter_path;
419 path = gtk_tree_path_new ();
420 filter_path = gtk_tree_path_new ();
421 filter_test_append_refilter_signals_recurse (fixture,
426 gtk_tree_path_free (path);
427 gtk_tree_path_free (filter_path);
431 filter_test_append_refilter_signals_with_vroot (FilterTest *fixture,
433 GtkTreePath *root_path)
435 /* A special function that walks the tree store like the
436 * model validation functions below.
439 GtkTreePath *filter_path;
441 path = gtk_tree_path_new ();
442 filter_path = gtk_tree_path_new ();
443 filter_test_append_refilter_signals_recurse (fixture,
448 gtk_tree_path_free (path);
449 gtk_tree_path_free (filter_path);
453 filter_test_enable_filter (FilterTest *fixture)
455 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
456 gtk_tree_model_filter_refilter (fixture->filter);
460 filter_test_block_signals (FilterTest *fixture)
462 fixture->block_signals = TRUE;
466 filter_test_unblock_signals (FilterTest *fixture)
468 fixture->block_signals = FALSE;
472 filter_test_teardown (FilterTest *fixture,
473 gconstpointer test_data)
475 signal_monitor_free (fixture->monitor);
477 gtk_widget_destroy (fixture->tree_view);
479 g_object_unref (fixture->filter);
480 g_object_unref (fixture->store);
484 * Model structure validation
488 check_filter_model_recurse (FilterTest *fixture,
489 GtkTreePath *store_parent_path,
490 GtkTreePath *filter_parent_path)
493 GtkTreeIter store_iter;
494 GtkTreeIter filter_iter;
495 gboolean store_has_next, filter_has_next;
497 gtk_tree_path_down (store_parent_path);
498 gtk_tree_path_down (filter_parent_path);
500 store_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
501 &store_iter, store_parent_path);
502 filter_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->filter),
503 &filter_iter, filter_parent_path);
505 for (i = 0; i < LEVEL_LENGTH; i++)
509 g_return_if_fail (store_has_next == TRUE);
511 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
519 gchar *filter_str, *store_str;
521 g_return_if_fail (filter_has_next == TRUE);
524 tmp = gtk_tree_model_get_path (GTK_TREE_MODEL (fixture->filter),
526 g_return_if_fail (gtk_tree_path_compare (tmp, filter_parent_path) == 0);
528 /* Verify model content */
529 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
533 gtk_tree_model_get (GTK_TREE_MODEL (fixture->filter),
538 g_return_if_fail (g_strcmp0 (store_str, filter_str) == 0);
543 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->filter),
546 g_return_if_fail (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store), &store_iter));
548 check_filter_model_recurse (fixture,
549 gtk_tree_path_copy (store_parent_path),
553 /* Only when we do not recurse we need to free tmp */
554 gtk_tree_path_free (tmp);
556 gtk_tree_path_next (filter_parent_path);
557 filter_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->filter), &filter_iter);
560 gtk_tree_path_next (store_parent_path);
561 store_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &store_iter);
564 /* Both models should have no more content! */
565 g_return_if_fail (store_has_next == FALSE);
566 g_return_if_fail (filter_has_next == FALSE);
568 gtk_tree_path_free (store_parent_path);
569 gtk_tree_path_free (filter_parent_path);
573 check_filter_model (FilterTest *fixture)
577 if (fixture->monitor)
578 signal_monitor_assert_is_empty (fixture->monitor);
580 path = gtk_tree_path_new ();
582 check_filter_model_recurse (fixture, path, gtk_tree_path_copy (path));
586 check_filter_model_with_root (FilterTest *fixture,
589 if (fixture->monitor)
590 signal_monitor_assert_is_empty (fixture->monitor);
592 check_filter_model_recurse (fixture,
593 gtk_tree_path_copy (path),
594 gtk_tree_path_new ());
600 check_level_length (GtkTreeModelFilter *filter,
602 const int expected_length)
608 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), NULL);
609 g_assert_cmpint (model_length, ==, expected_length);
614 gboolean retrieved_iter = FALSE;
617 retrieved_iter = gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (filter),
619 g_return_if_fail (retrieved_iter);
620 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), &iter);
621 g_assert_cmpint (model_length, ==, expected_length);
626 set_path_visibility (FilterTest *fixture,
630 GtkTreeIter store_iter;
632 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
634 gtk_tree_store_set (fixture->store, &store_iter,
641 insert_path_with_visibility (FilterTest *fixture,
642 const gchar *path_string,
647 GtkTreeIter parent, iter;
649 path = gtk_tree_path_new_from_string (path_string);
650 position = gtk_tree_path_get_indices (path)[gtk_tree_path_get_depth (path)];
651 gtk_tree_path_up (path);
653 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &parent, path))
655 gtk_tree_store_insert (fixture->store, &iter, &parent, position);
656 create_tree_store_set_values (fixture->store, &iter, visible);
658 gtk_tree_path_free (path);
667 verify_test_suite (FilterTest *fixture,
668 gconstpointer user_data)
670 check_filter_model (fixture);
674 verify_test_suite_vroot (FilterTest *fixture,
675 gconstpointer user_data)
677 check_filter_model_with_root (fixture, (GtkTreePath *)user_data);
682 filled_hide_root_level (FilterTest *fixture,
683 gconstpointer user_data)
685 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
686 set_path_visibility (fixture, "2", FALSE);
687 check_filter_model (fixture);
688 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
690 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
691 set_path_visibility (fixture, "0", FALSE);
692 check_filter_model (fixture);
693 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
695 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
696 set_path_visibility (fixture, "4", FALSE);
697 check_filter_model (fixture);
698 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
702 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
703 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
705 set_path_visibility (fixture, "1", FALSE);
706 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
708 set_path_visibility (fixture, "3", FALSE);
709 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 5);
711 check_filter_model (fixture);
714 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
715 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
716 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
717 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
719 set_path_visibility (fixture, "1", TRUE);
720 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
722 set_path_visibility (fixture, "3", TRUE);
723 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
725 check_filter_model (fixture);
729 filled_hide_child_levels (FilterTest *fixture,
730 gconstpointer user_data)
732 set_path_visibility (fixture, "0:2", FALSE);
733 check_filter_model (fixture);
734 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
735 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
737 set_path_visibility (fixture, "0:4", FALSE);
738 check_filter_model (fixture);
739 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
740 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
742 set_path_visibility (fixture, "0:4:3", FALSE);
743 check_filter_model (fixture);
744 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
745 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
747 set_path_visibility (fixture, "0:4:0", FALSE);
748 set_path_visibility (fixture, "0:4:1", FALSE);
749 set_path_visibility (fixture, "0:4:2", FALSE);
750 set_path_visibility (fixture, "0:4:4", FALSE);
751 check_filter_model (fixture);
752 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
753 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
755 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
756 set_path_visibility (fixture, "0:4", TRUE);
757 check_filter_model (fixture);
758 check_level_length (fixture->filter, "0:3", 0);
760 set_path_visibility (fixture, "0:2", TRUE);
761 check_filter_model (fixture);
762 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
763 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
764 check_level_length (fixture->filter, "0:4", 0);
766 /* Once 0:4:0 got inserted, 0:4 became a parent. Because 0:4 is
767 * not visible, not signals are emitted.
769 set_path_visibility (fixture, "0:4:2", TRUE);
770 set_path_visibility (fixture, "0:4:4", TRUE);
771 signal_monitor_assert_is_empty (fixture->monitor);
772 check_level_length (fixture->filter, "0:4", 2);
776 filled_hide_child_levels_root_expanded (FilterTest *fixture,
777 gconstpointer user_data)
781 path = gtk_tree_path_new_from_indices (0, -1);
782 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
783 gtk_tree_path_free (path);
785 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
786 set_path_visibility (fixture, "0:2", FALSE);
787 check_filter_model (fixture);
788 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
789 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
791 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
792 set_path_visibility (fixture, "0:4", FALSE);
793 check_filter_model (fixture);
794 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
795 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
797 set_path_visibility (fixture, "0:4:3", FALSE);
798 check_filter_model (fixture);
799 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
800 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
802 set_path_visibility (fixture, "0:4:0", FALSE);
803 set_path_visibility (fixture, "0:4:1", FALSE);
804 set_path_visibility (fixture, "0:4:2", FALSE);
805 set_path_visibility (fixture, "0:4:4", FALSE);
806 check_filter_model (fixture);
807 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
808 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
810 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
811 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
812 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
813 set_path_visibility (fixture, "0:4", TRUE);
814 check_filter_model (fixture);
815 check_level_length (fixture->filter, "0:3", 0);
817 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
818 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
819 set_path_visibility (fixture, "0:2", TRUE);
820 check_filter_model (fixture);
821 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
822 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
823 check_level_length (fixture->filter, "0:4", 0);
825 /* has-child-toggled for 0:4 is required. */
826 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
827 set_path_visibility (fixture, "0:4:2", TRUE);
828 set_path_visibility (fixture, "0:4:4", TRUE);
829 signal_monitor_assert_is_empty (fixture->monitor);
830 check_level_length (fixture->filter, "0:4", 2);
835 filled_vroot_hide_root_level (FilterTest *fixture,
836 gconstpointer user_data)
838 GtkTreePath *path = (GtkTreePath *)user_data;
840 /* These changes do not affect the filter's root level */
841 set_path_visibility (fixture, "0", FALSE);
842 check_filter_model_with_root (fixture, path);
843 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
844 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
846 set_path_visibility (fixture, "4", FALSE);
847 check_filter_model_with_root (fixture, path);
848 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
849 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
851 /* Even though we set the virtual root parent node to FALSE,
852 * the virtual root contents remain.
854 set_path_visibility (fixture, "2", FALSE);
855 check_filter_model_with_root (fixture, path);
856 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
857 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
860 set_path_visibility (fixture, "1", FALSE);
861 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
862 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
864 set_path_visibility (fixture, "3", FALSE);
865 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
866 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
868 check_filter_model_with_root (fixture, path);
871 set_path_visibility (fixture, "2", TRUE);
872 check_filter_model_with_root (fixture, path);
873 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
874 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
876 set_path_visibility (fixture, "1", TRUE);
877 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
878 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
880 set_path_visibility (fixture, "3", TRUE);
881 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
882 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
884 check_filter_model_with_root (fixture, path);
886 /* Now test changes in the virtual root level */
887 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
888 set_path_visibility (fixture, "2:2", FALSE);
889 check_filter_model_with_root (fixture, path);
890 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
892 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "3");
893 set_path_visibility (fixture, "2:4", FALSE);
894 check_filter_model_with_root (fixture, path);
895 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
897 set_path_visibility (fixture, "1:4", FALSE);
898 check_filter_model_with_root (fixture, path);
899 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
901 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "3");
902 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "3");
903 set_path_visibility (fixture, "2:4", TRUE);
904 check_filter_model_with_root (fixture, path);
905 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
907 set_path_visibility (fixture, "2", FALSE);
908 check_filter_model_with_root (fixture, path);
909 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
911 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
912 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
913 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
914 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
915 set_path_visibility (fixture, "2:0", FALSE);
916 set_path_visibility (fixture, "2:1", FALSE);
917 set_path_visibility (fixture, "2:2", FALSE);
918 set_path_visibility (fixture, "2:3", FALSE);
919 set_path_visibility (fixture, "2:4", FALSE);
920 check_filter_model_with_root (fixture, path);
921 check_level_length (fixture->filter, NULL, 0);
923 set_path_visibility (fixture, "2", TRUE);
924 check_filter_model_with_root (fixture, path);
925 check_level_length (fixture->filter, NULL, 0);
927 set_path_visibility (fixture, "1:4", FALSE);
928 check_filter_model_with_root (fixture, path);
929 check_level_length (fixture->filter, NULL, 0);
931 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
932 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
933 set_path_visibility (fixture, "2:4", TRUE);
934 check_filter_model_with_root (fixture, path);
935 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
937 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
938 set_path_visibility (fixture, "2:4", FALSE);
939 check_filter_model_with_root (fixture, path);
940 check_level_length (fixture->filter, NULL, 0);
942 set_path_visibility (fixture, "2", FALSE);
943 check_filter_model_with_root (fixture, path);
944 check_level_length (fixture->filter, NULL, 0);
946 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
947 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
948 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
949 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
950 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2");
951 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
952 set_path_visibility (fixture, "2:0", TRUE);
953 set_path_visibility (fixture, "2:1", TRUE);
954 set_path_visibility (fixture, "2:2", TRUE);
955 check_filter_model_with_root (fixture, path);
956 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
958 set_path_visibility (fixture, "2", TRUE);
959 check_filter_model_with_root (fixture, path);
960 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
964 filled_vroot_hide_child_levels (FilterTest *fixture,
965 gconstpointer user_data)
967 GtkTreePath *path = (GtkTreePath *)user_data;
969 set_path_visibility (fixture, "2:0:2", FALSE);
970 check_filter_model_with_root (fixture, path);
971 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
972 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
974 set_path_visibility (fixture, "2:0:4", FALSE);
975 check_filter_model_with_root (fixture, path);
976 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
977 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
979 set_path_visibility (fixture, "2:0:4:3", FALSE);
980 check_filter_model_with_root (fixture, path);
981 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
982 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
984 set_path_visibility (fixture, "2:0:4:0", FALSE);
985 set_path_visibility (fixture, "2:0:4:1", FALSE);
986 set_path_visibility (fixture, "2:0:4:2", FALSE);
987 set_path_visibility (fixture, "2:0:4:4", FALSE);
988 check_filter_model_with_root (fixture, path);
989 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
990 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
992 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
993 set_path_visibility (fixture, "2:0:4", TRUE);
994 check_filter_model_with_root (fixture, path);
995 check_level_length (fixture->filter, "0:3", 0);
997 set_path_visibility (fixture, "2:0:2", TRUE);
998 check_filter_model_with_root (fixture, path);
999 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1000 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1001 check_level_length (fixture->filter, "0:4", 0);
1003 /* Once 0:4:0 got inserted, 0:4 became a parent */
1004 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
1005 set_path_visibility (fixture, "2:0:4:2", TRUE);
1006 set_path_visibility (fixture, "2:0:4:4", TRUE);
1007 check_level_length (fixture->filter, "0:4", 2);
1011 filled_vroot_hide_child_levels_root_expanded (FilterTest *fixture,
1012 gconstpointer user_data)
1014 GtkTreePath *path = (GtkTreePath *)user_data;
1015 GtkTreePath *tmp_path;
1017 tmp_path = gtk_tree_path_new_from_indices (0, -1);
1018 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), tmp_path, FALSE);
1019 gtk_tree_path_free (tmp_path);
1021 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
1022 set_path_visibility (fixture, "2:0:2", FALSE);
1023 check_filter_model_with_root (fixture, path);
1024 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1025 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
1027 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
1028 set_path_visibility (fixture, "2:0:4", FALSE);
1029 check_filter_model_with_root (fixture, path);
1030 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1031 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1033 set_path_visibility (fixture, "2:0:4:3", FALSE);
1034 check_filter_model_with_root (fixture, path);
1035 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1036 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1038 set_path_visibility (fixture, "2:0:4:0", FALSE);
1039 set_path_visibility (fixture, "2:0:4:1", FALSE);
1040 set_path_visibility (fixture, "2:0:4:2", FALSE);
1041 set_path_visibility (fixture, "2:0:4: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 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
1047 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
1048 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
1049 set_path_visibility (fixture, "2:0:4", TRUE);
1050 check_filter_model_with_root (fixture, path);
1051 check_level_length (fixture->filter, "0:3", 0);
1053 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
1054 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
1055 set_path_visibility (fixture, "2:0:2", TRUE);
1056 check_filter_model_with_root (fixture, path);
1057 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1058 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1059 check_level_length (fixture->filter, "0:4", 0);
1061 /* Once 0:4:0 got inserted, 0:4 became a parent */
1062 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
1063 set_path_visibility (fixture, "2:0:4:2", TRUE);
1064 set_path_visibility (fixture, "2:0:4:4", TRUE);
1065 check_level_length (fixture->filter, "0:4", 2);
1069 empty_show_nodes (FilterTest *fixture,
1070 gconstpointer user_data)
1072 check_filter_model (fixture);
1073 check_level_length (fixture->filter, NULL, 0);
1075 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1076 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1077 set_path_visibility (fixture, "3", TRUE);
1078 check_filter_model (fixture);
1079 check_level_length (fixture->filter, NULL, 1);
1080 check_level_length (fixture->filter, "0", 0);
1082 set_path_visibility (fixture, "3:2:2", TRUE);
1083 check_filter_model (fixture);
1084 check_level_length (fixture->filter, NULL, 1);
1085 check_level_length (fixture->filter, "0", 0);
1087 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1088 set_path_visibility (fixture, "3:2", TRUE);
1089 check_filter_model (fixture);
1090 check_level_length (fixture->filter, NULL, 1);
1091 check_level_length (fixture->filter, "0", 1);
1092 check_level_length (fixture->filter, "0:0", 1);
1093 check_level_length (fixture->filter, "0:0:0", 0);
1095 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1096 set_path_visibility (fixture, "3", FALSE);
1097 check_filter_model (fixture);
1098 check_level_length (fixture->filter, NULL, 0);
1100 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1101 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1102 set_path_visibility (fixture, "3:2:1", TRUE);
1103 set_path_visibility (fixture, "3", TRUE);
1104 check_filter_model (fixture);
1105 check_level_length (fixture->filter, NULL, 1);
1106 check_level_length (fixture->filter, "0", 1);
1107 check_level_length (fixture->filter, "0:0", 2);
1108 check_level_length (fixture->filter, "0:0:0", 0);
1112 empty_show_multiple_nodes (FilterTest *fixture,
1113 gconstpointer user_data)
1116 GtkTreePath *changed_path;
1118 check_filter_model (fixture);
1119 check_level_length (fixture->filter, NULL, 0);
1121 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1122 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1123 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1124 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1126 /* We simulate a change in visible func condition with this. The
1127 * visibility state of multiple nodes changes at once, we emit row-changed
1128 * for these nodes (and others) after that.
1130 filter_test_block_signals (fixture);
1131 set_path_visibility (fixture, "3", TRUE);
1132 set_path_visibility (fixture, "4", TRUE);
1133 filter_test_unblock_signals (fixture);
1135 changed_path = gtk_tree_path_new ();
1136 gtk_tree_path_append_index (changed_path, 2);
1137 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1138 &iter, changed_path);
1139 /* Invisible node - so no signals expected */
1140 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1141 changed_path, &iter);
1143 gtk_tree_path_next (changed_path);
1144 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1145 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1146 changed_path, &iter);
1148 gtk_tree_path_next (changed_path);
1149 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1150 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1151 changed_path, &iter);
1153 gtk_tree_path_free (changed_path);
1155 check_filter_model (fixture);
1156 check_level_length (fixture->filter, NULL, 2);
1157 check_level_length (fixture->filter, "0", 0);
1159 set_path_visibility (fixture, "3:2:2", TRUE);
1160 check_filter_model (fixture);
1161 check_level_length (fixture->filter, NULL, 2);
1162 check_level_length (fixture->filter, "0", 0);
1164 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1165 set_path_visibility (fixture, "3:2", TRUE);
1166 check_filter_model (fixture);
1167 check_level_length (fixture->filter, NULL, 2);
1168 check_level_length (fixture->filter, "0", 1);
1169 check_level_length (fixture->filter, "0:0", 1);
1170 check_level_length (fixture->filter, "0:0:0", 0);
1172 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1173 set_path_visibility (fixture, "3", FALSE);
1174 check_filter_model (fixture);
1175 check_level_length (fixture->filter, NULL, 1);
1177 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1178 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1179 set_path_visibility (fixture, "3:2:1", TRUE);
1180 set_path_visibility (fixture, "3", TRUE);
1181 check_filter_model (fixture);
1182 check_level_length (fixture->filter, NULL, 2);
1183 check_level_length (fixture->filter, "0", 1);
1184 check_level_length (fixture->filter, "0:0", 2);
1185 check_level_length (fixture->filter, "0:0:0", 0);
1189 empty_vroot_show_nodes (FilterTest *fixture,
1190 gconstpointer user_data)
1192 GtkTreePath *path = (GtkTreePath *)user_data;
1194 check_filter_model_with_root (fixture, path);
1195 check_level_length (fixture->filter, NULL, 0);
1197 set_path_visibility (fixture, "2", TRUE);
1198 check_filter_model_with_root (fixture, path);
1199 check_level_length (fixture->filter, NULL, 0);
1201 set_path_visibility (fixture, "2:2:2", TRUE);
1202 check_filter_model_with_root (fixture, path);
1203 check_level_length (fixture->filter, NULL, 0);
1205 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1206 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1207 set_path_visibility (fixture, "2:2", TRUE);
1208 check_filter_model_with_root (fixture, path);
1209 check_level_length (fixture->filter, NULL, 1);
1210 check_level_length (fixture->filter, "0", 1);
1211 check_level_length (fixture->filter, "0:0", 0);
1213 set_path_visibility (fixture, "3", TRUE);
1214 check_filter_model_with_root (fixture, path);
1215 check_level_length (fixture->filter, NULL, 1);
1217 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1218 set_path_visibility (fixture, "2:2", FALSE);
1219 check_filter_model_with_root (fixture, path);
1220 check_level_length (fixture->filter, NULL, 0);
1222 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1223 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1224 set_path_visibility (fixture, "2:2:1", TRUE);
1225 set_path_visibility (fixture, "2:2", TRUE);
1226 check_filter_model_with_root (fixture, path);
1227 check_level_length (fixture->filter, NULL, 1);
1228 check_level_length (fixture->filter, "0", 2);
1229 check_level_length (fixture->filter, "0:1", 0);
1233 empty_vroot_show_multiple_nodes (FilterTest *fixture,
1234 gconstpointer user_data)
1237 GtkTreePath *changed_path;
1238 GtkTreePath *path = (GtkTreePath *)user_data;
1240 check_filter_model_with_root (fixture, path);
1241 check_level_length (fixture->filter, NULL, 0);
1243 /* We simulate a change in visible func condition with this. The
1244 * visibility state of multiple nodes changes at once, we emit row-changed
1245 * for these nodes (and others) after that.
1247 filter_test_block_signals (fixture);
1248 set_path_visibility (fixture, "2", TRUE);
1249 set_path_visibility (fixture, "3", TRUE);
1250 filter_test_unblock_signals (fixture);
1252 changed_path = gtk_tree_path_new ();
1253 gtk_tree_path_append_index (changed_path, 1);
1254 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1255 &iter, changed_path);
1256 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1257 changed_path, &iter);
1259 gtk_tree_path_next (changed_path);
1260 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1261 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1262 changed_path, &iter);
1264 gtk_tree_path_next (changed_path);
1265 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1266 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1267 changed_path, &iter);
1269 gtk_tree_path_next (changed_path);
1270 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1271 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1272 changed_path, &iter);
1274 gtk_tree_path_free (changed_path);
1276 check_filter_model_with_root (fixture, path);
1277 check_level_length (fixture->filter, NULL, 0);
1279 set_path_visibility (fixture, "2:2:2", TRUE);
1280 check_filter_model_with_root (fixture, path);
1281 check_level_length (fixture->filter, NULL, 0);
1283 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1284 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1285 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1286 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1288 /* Again, we simulate a call to refilter */
1289 filter_test_block_signals (fixture);
1290 set_path_visibility (fixture, "2:2", TRUE);
1291 set_path_visibility (fixture, "2:3", TRUE);
1292 filter_test_unblock_signals (fixture);
1294 changed_path = gtk_tree_path_new ();
1295 gtk_tree_path_append_index (changed_path, 2);
1296 gtk_tree_path_append_index (changed_path, 1);
1297 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1298 &iter, changed_path);
1299 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1300 changed_path, &iter);
1302 gtk_tree_path_next (changed_path);
1303 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1304 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1305 changed_path, &iter);
1307 gtk_tree_path_next (changed_path);
1308 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1309 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1310 changed_path, &iter);
1312 gtk_tree_path_next (changed_path);
1313 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1314 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1315 changed_path, &iter);
1317 gtk_tree_path_free (changed_path);
1319 check_filter_model_with_root (fixture, path);
1320 check_level_length (fixture->filter, NULL, 2);
1321 check_level_length (fixture->filter, "0", 1);
1322 check_level_length (fixture->filter, "0:0", 0);
1324 set_path_visibility (fixture, "3", TRUE);
1325 check_filter_model_with_root (fixture, path);
1326 check_level_length (fixture->filter, NULL, 2);
1328 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1329 set_path_visibility (fixture, "2:2", FALSE);
1330 check_filter_model_with_root (fixture, path);
1331 check_level_length (fixture->filter, NULL, 1);
1333 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1334 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1335 set_path_visibility (fixture, "2:2:1", TRUE);
1336 set_path_visibility (fixture, "2:2", TRUE);
1337 check_filter_model_with_root (fixture, path);
1338 check_level_length (fixture->filter, NULL, 2);
1339 check_level_length (fixture->filter, "0", 2);
1340 check_level_length (fixture->filter, "0:1", 0);
1345 unfiltered_hide_single (FilterTest *fixture,
1346 gconstpointer user_data)
1349 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1350 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1351 set_path_visibility (fixture, "2", FALSE);
1353 signal_monitor_assert_is_empty (fixture->monitor);
1354 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1356 /* The view only shows the root level, so we only expect signals
1357 * for the root level.
1359 filter_test_append_refilter_signals (fixture, 1);
1360 filter_test_enable_filter (fixture);
1362 check_filter_model (fixture);
1363 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1367 unfiltered_hide_single_root_expanded (FilterTest *fixture,
1368 gconstpointer user_data)
1371 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1372 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1373 set_path_visibility (fixture, "2", FALSE);
1375 signal_monitor_assert_is_empty (fixture->monitor);
1376 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1378 filter_test_append_refilter_signals (fixture, 2);
1379 filter_test_enable_filter (fixture);
1381 check_filter_model (fixture);
1382 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1386 unfiltered_hide_single_child (FilterTest *fixture,
1387 gconstpointer user_data)
1390 /* This row is not shown, so its signal is not propagated */
1391 set_path_visibility (fixture, "2:2", FALSE);
1393 signal_monitor_assert_is_empty (fixture->monitor);
1394 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1395 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1397 /* The view only shows the root level, so we only expect signals
1398 * for the root level.
1400 filter_test_append_refilter_signals (fixture, 0);
1401 filter_test_enable_filter (fixture);
1403 check_filter_model (fixture);
1404 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1405 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1409 unfiltered_hide_single_child_root_expanded (FilterTest *fixture,
1410 gconstpointer user_data)
1413 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1414 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1415 set_path_visibility (fixture, "2:2", FALSE);
1417 signal_monitor_assert_is_empty (fixture->monitor);
1418 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1419 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1421 filter_test_append_refilter_signals (fixture, 2);
1422 filter_test_enable_filter (fixture);
1424 check_filter_model (fixture);
1425 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1426 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1430 unfiltered_hide_single_multi_level (FilterTest *fixture,
1431 gconstpointer user_data)
1434 /* This row is not shown, so its signal is not propagated */
1435 set_path_visibility (fixture, "2:2:2", FALSE);
1437 /* This row is not shown, so its signal is not propagated */
1438 set_path_visibility (fixture, "2:2", FALSE);
1440 signal_monitor_assert_is_empty (fixture->monitor);
1441 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1442 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1443 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1445 /* The view only shows the root level, so we only expect signals
1446 * for the root level.
1448 filter_test_append_refilter_signals (fixture, 1);
1449 filter_test_enable_filter (fixture);
1451 check_filter_model (fixture);
1452 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1453 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1455 set_path_visibility (fixture, "2:2", TRUE);
1457 check_filter_model (fixture);
1458 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1459 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1460 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1464 unfiltered_hide_single_multi_level_root_expanded (FilterTest *fixture,
1465 gconstpointer user_data)
1468 /* This row is not shown, so its signal is not propagated */
1469 set_path_visibility (fixture, "2:2:2", FALSE);
1471 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1472 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1473 set_path_visibility (fixture, "2:2", FALSE);
1475 signal_monitor_assert_is_empty (fixture->monitor);
1476 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1477 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1478 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1480 filter_test_append_refilter_signals (fixture, 2);
1481 filter_test_enable_filter (fixture);
1483 check_filter_model (fixture);
1484 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1485 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1487 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1488 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1489 set_path_visibility (fixture, "2:2", TRUE);
1491 check_filter_model (fixture);
1492 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1493 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1494 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1500 unfiltered_vroot_hide_single (FilterTest *fixture,
1501 gconstpointer user_data)
1504 GtkTreePath *path = (GtkTreePath *)user_data;
1506 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1507 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1508 set_path_visibility (fixture, "2:2", FALSE);
1510 signal_monitor_assert_is_empty (fixture->monitor);
1511 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1513 /* The view only shows the root level, so we only expect signals
1514 * for the root level. (Though for the depth argument, we have to
1515 * take the virtual root into account).
1517 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1518 filter_test_enable_filter (fixture);
1520 check_filter_model_with_root (fixture, path);
1521 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1525 unfiltered_vroot_hide_single_child (FilterTest *fixture,
1526 gconstpointer user_data)
1529 GtkTreePath *path = (GtkTreePath *)user_data;
1531 /* Not visible, so no signal will be received. */
1532 set_path_visibility (fixture, "2:2:2", FALSE);
1534 signal_monitor_assert_is_empty (fixture->monitor);
1535 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1536 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1538 /* The view only shows the root level, so we only expect signals
1539 * for the root level. (Though for the depth argument, we have to
1540 * take the virtual root into account).
1542 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1543 filter_test_enable_filter (fixture);
1545 check_filter_model_with_root (fixture, path);
1546 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1547 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1551 unfiltered_vroot_hide_single_child_root_expanded (FilterTest *fixture,
1552 gconstpointer user_data)
1555 GtkTreePath *path = (GtkTreePath *)user_data;
1557 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1558 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1559 set_path_visibility (fixture, "2:2:2", FALSE);
1561 signal_monitor_assert_is_empty (fixture->monitor);
1562 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1563 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1565 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1566 filter_test_enable_filter (fixture);
1568 check_filter_model_with_root (fixture, path);
1569 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1570 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1574 unfiltered_vroot_hide_single_multi_level (FilterTest *fixture,
1575 gconstpointer user_data)
1578 GtkTreePath *path = (GtkTreePath *)user_data;
1580 /* This row is not shown, so its signal is not propagated */
1581 set_path_visibility (fixture, "2:2:2:2", FALSE);
1583 /* Not shown, so no signal */
1584 set_path_visibility (fixture, "2:2:2", FALSE);
1586 signal_monitor_assert_is_empty (fixture->monitor);
1587 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1588 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1589 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1591 /* We only expect signals for the root level. The depth is 2
1592 * because we have to take the virtual root into account.
1594 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1595 filter_test_enable_filter (fixture);
1597 check_filter_model_with_root (fixture, path);
1598 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1599 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1601 /* Not shown, so no signal */
1602 set_path_visibility (fixture, "2:2:2", TRUE);
1604 check_filter_model_with_root (fixture, path);
1605 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1606 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1607 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1611 unfiltered_vroot_hide_single_multi_level_root_expanded (FilterTest *fixture,
1612 gconstpointer user_data)
1615 GtkTreePath *path = (GtkTreePath *)user_data;
1617 /* This row is not shown, so its signal is not propagated */
1618 set_path_visibility (fixture, "2:2:2:2", FALSE);
1620 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1621 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1622 set_path_visibility (fixture, "2:2:2", FALSE);
1624 signal_monitor_assert_is_empty (fixture->monitor);
1625 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1626 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1627 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1629 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1630 filter_test_enable_filter (fixture);
1632 check_filter_model_with_root (fixture, path);
1633 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1634 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1636 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1637 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1638 set_path_visibility (fixture, "2:2:2", TRUE);
1640 check_filter_model_with_root (fixture, path);
1641 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1642 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1643 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1647 unfiltered_show_single (FilterTest *fixture,
1648 gconstpointer user_data)
1651 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1652 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1653 set_path_visibility (fixture, "2", TRUE);
1655 signal_monitor_assert_is_empty (fixture->monitor);
1656 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1658 /* We only expect signals for the root level */
1659 filter_test_append_refilter_signals (fixture, 1);
1660 filter_test_enable_filter (fixture);
1662 check_filter_model (fixture);
1663 check_level_length (fixture->filter, NULL, 1);
1667 unfiltered_show_single_child (FilterTest *fixture,
1668 gconstpointer user_data)
1671 set_path_visibility (fixture, "2:2", TRUE);
1673 signal_monitor_assert_is_empty (fixture->monitor);
1674 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1675 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1677 /* We only expect signals for the root level */
1678 filter_test_append_refilter_signals (fixture, 1);
1679 filter_test_enable_filter (fixture);
1681 check_filter_model (fixture);
1682 check_level_length (fixture->filter, NULL, 0);
1684 /* From here we are filtered, "2" in the real model is "0" in the filter
1687 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1688 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1689 set_path_visibility (fixture, "2", TRUE);
1690 signal_monitor_assert_is_empty (fixture->monitor);
1691 check_level_length (fixture->filter, NULL, 1);
1692 check_level_length (fixture->filter, "0", 1);
1696 unfiltered_show_single_child_root_expanded (FilterTest *fixture,
1697 gconstpointer user_data)
1700 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1701 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1702 set_path_visibility (fixture, "2:2", TRUE);
1704 signal_monitor_assert_is_empty (fixture->monitor);
1705 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1706 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1708 filter_test_append_refilter_signals (fixture, 2);
1709 filter_test_enable_filter (fixture);
1711 check_filter_model (fixture);
1712 check_level_length (fixture->filter, NULL, 0);
1714 /* From here we are filtered, "2" in the real model is "0" in the filter
1717 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1718 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1719 set_path_visibility (fixture, "2", TRUE);
1720 signal_monitor_assert_is_empty (fixture->monitor);
1721 check_level_length (fixture->filter, NULL, 1);
1722 check_level_length (fixture->filter, "0", 1);
1726 unfiltered_show_single_multi_level (FilterTest *fixture,
1727 gconstpointer user_data)
1730 /* The view is not showing these rows (collapsed state), so it is not
1731 * referenced. The signal should not go through.
1733 set_path_visibility (fixture, "2:2:2", TRUE);
1734 set_path_visibility (fixture, "2:2", TRUE);
1736 signal_monitor_assert_is_empty (fixture->monitor);
1737 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1738 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1739 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1741 /* We only expect signals for the first level */
1742 filter_test_append_refilter_signals (fixture, 1);
1743 filter_test_enable_filter (fixture);
1745 check_filter_model (fixture);
1746 check_level_length (fixture->filter, NULL, 0);
1748 /* From here we are filtered, "2" in the real model is "0" in the filter
1751 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1752 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1753 set_path_visibility (fixture, "2", TRUE);
1754 check_filter_model (fixture);
1755 check_level_length (fixture->filter, NULL, 1);
1756 check_level_length (fixture->filter, "0", 1);
1757 check_level_length (fixture->filter, "0:0", 1);
1761 unfiltered_show_single_multi_level_root_expanded (FilterTest *fixture,
1762 gconstpointer user_data)
1765 /* The view is not showing this row (collapsed state), so it is not
1766 * referenced. The signal should not go through.
1768 set_path_visibility (fixture, "2:2:2", TRUE);
1770 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1771 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1772 set_path_visibility (fixture, "2:2", TRUE);
1774 signal_monitor_assert_is_empty (fixture->monitor);
1775 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1776 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1777 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1779 filter_test_append_refilter_signals (fixture, 2);
1780 filter_test_enable_filter (fixture);
1782 check_filter_model (fixture);
1783 check_level_length (fixture->filter, NULL, 0);
1785 /* From here we are filtered, "2" in the real model is "0" in the filter
1788 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1789 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1790 set_path_visibility (fixture, "2", TRUE);
1791 check_filter_model (fixture);
1792 check_level_length (fixture->filter, NULL, 1);
1793 check_level_length (fixture->filter, "0", 1);
1794 check_level_length (fixture->filter, "0:0", 1);
1798 unfiltered_vroot_show_single (FilterTest *fixture,
1799 gconstpointer user_data)
1802 GtkTreePath *path = (GtkTreePath *)user_data;
1804 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1805 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1806 set_path_visibility (fixture, "2:2", TRUE);
1808 signal_monitor_assert_is_empty (fixture->monitor);
1809 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1811 /* The view only shows the root level, so the filter model only has
1812 * the first two levels cached.
1814 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1815 filter_test_enable_filter (fixture);
1817 check_filter_model_with_root (fixture, path);
1818 check_level_length (fixture->filter, NULL, 1);
1822 unfiltered_vroot_show_single_child (FilterTest *fixture,
1823 gconstpointer user_data)
1826 GtkTreePath *path = (GtkTreePath *)user_data;
1828 set_path_visibility (fixture, "2:2:2", TRUE);
1830 signal_monitor_assert_is_empty (fixture->monitor);
1831 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1832 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1834 /* The view only shows the root level, so the filter model only has
1835 * the first two levels cached.
1837 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1838 filter_test_enable_filter (fixture);
1840 check_filter_model_with_root (fixture, path);
1841 check_level_length (fixture->filter, NULL, 0);
1843 /* From here we are filtered, "2" in the real model is "0" in the filter
1846 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1847 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1848 set_path_visibility (fixture, "2:2", TRUE);
1849 signal_monitor_assert_is_empty (fixture->monitor);
1850 check_level_length (fixture->filter, NULL, 1);
1851 check_level_length (fixture->filter, "0", 1);
1855 unfiltered_vroot_show_single_child_root_expanded (FilterTest *fixture,
1856 gconstpointer user_data)
1859 GtkTreePath *path = (GtkTreePath *)user_data;
1861 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1862 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1863 set_path_visibility (fixture, "2:2:2", TRUE);
1865 signal_monitor_assert_is_empty (fixture->monitor);
1866 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1867 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1869 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1870 filter_test_enable_filter (fixture);
1872 check_filter_model_with_root (fixture, path);
1873 check_level_length (fixture->filter, NULL, 0);
1875 /* From here we are filtered, "2" in the real model is "0" in the filter
1878 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1879 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1880 set_path_visibility (fixture, "2:2", TRUE);
1881 signal_monitor_assert_is_empty (fixture->monitor);
1882 check_level_length (fixture->filter, NULL, 1);
1883 check_level_length (fixture->filter, "0", 1);
1888 unfiltered_vroot_show_single_multi_level (FilterTest *fixture,
1889 gconstpointer user_data)
1892 GtkTreePath *path = (GtkTreePath *)user_data;
1894 /* The view is not showing this row (collapsed state), so it is not
1895 * referenced. The signal should not go through.
1897 set_path_visibility (fixture, "2:2:2:2", TRUE);
1899 set_path_visibility (fixture, "2:2:2", TRUE);
1901 signal_monitor_assert_is_empty (fixture->monitor);
1902 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1903 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1904 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1906 /* We only expect signals for the root level */
1907 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1908 filter_test_enable_filter (fixture);
1910 check_filter_model_with_root (fixture, path);
1911 check_level_length (fixture->filter, NULL, 0);
1913 /* From here we are filtered, "2" in the real model is "0" in the filter
1916 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1917 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1918 set_path_visibility (fixture, "2:2", TRUE);
1919 check_filter_model_with_root (fixture, path);
1920 check_level_length (fixture->filter, NULL, 1);
1921 check_level_length (fixture->filter, "0", 1);
1922 check_level_length (fixture->filter, "0:0", 1);
1926 unfiltered_vroot_show_single_multi_level_root_expanded (FilterTest *fixture,
1927 gconstpointer user_data)
1930 GtkTreePath *path = (GtkTreePath *)user_data;
1932 /* The view is not showing this row (collapsed state), so it is not
1933 * referenced. The signal should not go through.
1935 set_path_visibility (fixture, "2:2:2:2", TRUE);
1937 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1938 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1939 set_path_visibility (fixture, "2:2:2", TRUE);
1941 signal_monitor_assert_is_empty (fixture->monitor);
1942 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1943 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1944 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1946 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1947 filter_test_enable_filter (fixture);
1949 check_filter_model_with_root (fixture, path);
1950 check_level_length (fixture->filter, NULL, 0);
1952 /* From here we are filtered, "2" in the real model is "0" in the filter
1955 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1956 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1957 set_path_visibility (fixture, "2:2", TRUE);
1958 check_filter_model_with_root (fixture, path);
1959 check_level_length (fixture->filter, NULL, 1);
1960 check_level_length (fixture->filter, "0", 1);
1961 check_level_length (fixture->filter, "0:0", 1);
1965 unfiltered_rows_reordered_root_level (FilterTest *fixture,
1966 gconstpointer user_data)
1968 int order0[] = { 1, 2, 3, 4, 0 };
1969 int order1[] = { 0, 2, 1, 3, 4 };
1970 int order2[] = { 4, 0, 1, 2, 3 };
1971 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
1974 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1976 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1978 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1980 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1982 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1985 path = gtk_tree_path_new ();
1986 signal_monitor_append_signal_reordered (fixture->monitor,
1989 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
1990 signal_monitor_assert_is_empty (fixture->monitor);
1992 signal_monitor_append_signal_reordered (fixture->monitor,
1995 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
1996 signal_monitor_assert_is_empty (fixture->monitor);
1998 signal_monitor_append_signal_reordered (fixture->monitor,
2001 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2002 signal_monitor_assert_is_empty (fixture->monitor);
2004 gtk_tree_path_free (path);
2008 unfiltered_rows_reordered_child_level (FilterTest *fixture,
2009 gconstpointer user_data)
2011 int order0[] = { 1, 2, 3, 4, 0 };
2012 int order1[] = { 0, 2, 1, 3, 4 };
2013 int order2[] = { 4, 0, 1, 2, 3 };
2014 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
2018 path = gtk_tree_path_new_from_indices (0, -1);
2019 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2021 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2023 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2025 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2027 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2029 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2032 signal_monitor_append_signal_reordered (fixture->monitor,
2035 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2036 signal_monitor_assert_is_empty (fixture->monitor);
2038 signal_monitor_append_signal_reordered (fixture->monitor,
2041 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
2042 signal_monitor_assert_is_empty (fixture->monitor);
2044 signal_monitor_append_signal_reordered (fixture->monitor,
2047 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2048 signal_monitor_assert_is_empty (fixture->monitor);
2050 gtk_tree_path_free (path);
2054 filtered_rows_reordered_root_level_first_hidden (FilterTest *fixture,
2055 gconstpointer user_data)
2057 int order0[] = { 1, 2, 3, 0 };
2058 int order1[] = { 0, 2, 1, 3 };
2059 int order2[] = { 3, 0, 1, 2 };
2060 GtkTreeIter iter1, iter2, iter3, iter4;
2063 /* Hide middle path */
2064 signal_monitor_append_signal (fixture->monitor,
2066 set_path_visibility (fixture, "0", FALSE);
2067 signal_monitor_assert_is_empty (fixture->monitor);
2069 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2071 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2073 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2075 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2078 path = gtk_tree_path_new ();
2079 signal_monitor_append_signal_reordered (fixture->monitor,
2082 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2083 signal_monitor_assert_is_empty (fixture->monitor);
2085 signal_monitor_append_signal_reordered (fixture->monitor,
2088 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2089 signal_monitor_assert_is_empty (fixture->monitor);
2091 signal_monitor_append_signal_reordered (fixture->monitor,
2094 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2095 signal_monitor_assert_is_empty (fixture->monitor);
2097 gtk_tree_path_free (path);
2101 filtered_rows_reordered_root_level_middle_hidden (FilterTest *fixture,
2102 gconstpointer user_data)
2104 int order0[] = { 1, 2, 3, 0 };
2105 int order1[] = { 0, 2, 1, 3 };
2106 int order2[] = { 3, 0, 1, 2 };
2107 GtkTreeIter iter0, iter1, iter3, iter4;
2110 /* Hide middle path */
2111 signal_monitor_append_signal (fixture->monitor,
2113 set_path_visibility (fixture, "2", FALSE);
2114 signal_monitor_assert_is_empty (fixture->monitor);
2116 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2118 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2120 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2122 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2125 path = gtk_tree_path_new ();
2126 signal_monitor_append_signal_reordered (fixture->monitor,
2129 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2130 signal_monitor_assert_is_empty (fixture->monitor);
2132 signal_monitor_append_signal_reordered (fixture->monitor,
2135 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2136 signal_monitor_assert_is_empty (fixture->monitor);
2138 signal_monitor_append_signal_reordered (fixture->monitor,
2141 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2142 signal_monitor_assert_is_empty (fixture->monitor);
2144 gtk_tree_path_free (path);
2148 filtered_rows_reordered_child_level_first_hidden (FilterTest *fixture,
2149 gconstpointer user_data)
2151 int order0[] = { 1, 2, 3, 0 };
2152 int order1[] = { 0, 2, 1, 3 };
2153 int order2[] = { 3, 0, 1, 2 };
2154 GtkTreeIter iter1, iter2, iter3, iter4;
2158 path = gtk_tree_path_new_from_indices (0, -1);
2159 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, TRUE);
2161 /* Hide middle path */
2162 signal_monitor_append_signal (fixture->monitor,
2163 ROW_DELETED, "0:0");
2164 set_path_visibility (fixture, "0:0", FALSE);
2165 signal_monitor_assert_is_empty (fixture->monitor);
2167 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2169 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2171 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2173 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2176 signal_monitor_append_signal_reordered (fixture->monitor,
2179 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2180 signal_monitor_assert_is_empty (fixture->monitor);
2182 signal_monitor_append_signal_reordered (fixture->monitor,
2185 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2186 signal_monitor_assert_is_empty (fixture->monitor);
2188 signal_monitor_append_signal_reordered (fixture->monitor,
2191 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2192 signal_monitor_assert_is_empty (fixture->monitor);
2194 gtk_tree_path_free (path);
2198 filtered_rows_reordered_child_level_middle_hidden (FilterTest *fixture,
2199 gconstpointer user_data)
2201 int order0[] = { 1, 2, 3, 0 };
2202 int order1[] = { 0, 2, 1, 3 };
2203 int order2[] = { 3, 0, 1, 2 };
2204 GtkTreeIter iter0, iter1, iter3, iter4;
2208 path = gtk_tree_path_new_from_indices (0, -1);
2209 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2211 /* Hide middle path */
2212 signal_monitor_append_signal (fixture->monitor,
2213 ROW_DELETED, "0:2");
2214 set_path_visibility (fixture, "0:2", FALSE);
2215 signal_monitor_assert_is_empty (fixture->monitor);
2217 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2219 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2221 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2223 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2226 signal_monitor_append_signal_reordered (fixture->monitor,
2229 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2230 signal_monitor_assert_is_empty (fixture->monitor);
2232 signal_monitor_append_signal_reordered (fixture->monitor,
2235 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2236 signal_monitor_assert_is_empty (fixture->monitor);
2238 signal_monitor_append_signal_reordered (fixture->monitor,
2241 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2242 signal_monitor_assert_is_empty (fixture->monitor);
2244 gtk_tree_path_free (path);
2248 filtered_rows_reordered_child_level_4_hidden (FilterTest *fixture,
2249 gconstpointer user_data)
2251 int order0[] = { 0 };
2252 GtkTreeIter iter1, iter4;
2256 path = gtk_tree_path_new_from_indices (0, -1);
2257 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2259 /* Hide last 4 paths */
2260 signal_monitor_append_signal (fixture->monitor,
2261 ROW_DELETED, "0:4");
2262 signal_monitor_append_signal (fixture->monitor,
2263 ROW_DELETED, "0:3");
2264 signal_monitor_append_signal (fixture->monitor,
2265 ROW_DELETED, "0:2");
2266 signal_monitor_append_signal (fixture->monitor,
2267 ROW_DELETED, "0:0");
2268 set_path_visibility (fixture, "0:4", FALSE);
2269 set_path_visibility (fixture, "0:3", FALSE);
2270 set_path_visibility (fixture, "0:2", FALSE);
2271 set_path_visibility (fixture, "0:0", FALSE);
2272 signal_monitor_assert_is_empty (fixture->monitor);
2274 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2276 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2279 signal_monitor_append_signal_reordered (fixture->monitor,
2282 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2283 signal_monitor_assert_is_empty (fixture->monitor);
2285 gtk_tree_path_free (path);
2289 filtered_rows_reordered_child_level_all_hidden (FilterTest *fixture,
2290 gconstpointer user_data)
2292 GtkTreeIter iter1, iter4;
2296 path = gtk_tree_path_new_from_indices (0, -1);
2297 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2298 gtk_tree_path_free (path);
2300 /* Hide last 4 paths */
2301 signal_monitor_append_signal (fixture->monitor,
2302 ROW_DELETED, "0:4");
2303 signal_monitor_append_signal (fixture->monitor,
2304 ROW_DELETED, "0:3");
2305 signal_monitor_append_signal (fixture->monitor,
2306 ROW_DELETED, "0:2");
2307 signal_monitor_append_signal (fixture->monitor,
2308 ROW_DELETED, "0:1");
2309 signal_monitor_append_signal (fixture->monitor,
2310 ROW_DELETED, "0:0");
2311 signal_monitor_append_signal (fixture->monitor,
2312 ROW_HAS_CHILD_TOGGLED, "0");
2313 set_path_visibility (fixture, "0:4", FALSE);
2314 set_path_visibility (fixture, "0:3", FALSE);
2315 set_path_visibility (fixture, "0:2", FALSE);
2316 set_path_visibility (fixture, "0:1", FALSE);
2317 set_path_visibility (fixture, "0:0", FALSE);
2318 signal_monitor_assert_is_empty (fixture->monitor);
2320 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2322 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2325 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2326 signal_monitor_assert_is_empty (fixture->monitor);
2330 insert_before (void)
2332 GtkTreeStore *store;
2333 GtkTreeModel *filter;
2334 GtkWidget *tree_view;
2335 SignalMonitor *monitor;
2337 GtkTreeIter last_iter;
2340 /* This tests two aspects of the row-inserted handling:
2341 * 1) If the newly inserted node was already handled by building
2342 * the root level, don't handle it a second time.
2343 * 2) Offsets of existing nodes must be updated when a new
2347 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2348 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2349 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2352 tree_view = gtk_tree_view_new_with_model (filter);
2353 monitor = signal_monitor_new (filter);
2355 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 0);
2358 path = gtk_tree_path_new_from_indices (0, -1);
2359 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2360 gtk_tree_path_free (path);
2362 gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
2363 0, "Foo", 1, TRUE, -1);
2365 signal_monitor_assert_is_empty (monitor);
2366 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2369 path = gtk_tree_path_new_from_indices (1, -1);
2370 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2371 gtk_tree_path_free (path);
2373 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2374 0, "Foo", 1, TRUE, -1);
2377 signal_monitor_assert_is_empty (monitor);
2378 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2380 /* Insert on 1 again -- invisible */
2381 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2382 0, "Foo", 1, FALSE, -1);
2384 signal_monitor_assert_is_empty (monitor);
2385 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2387 /* Insert on 1 again -- visible */
2388 path = gtk_tree_path_new_from_indices (1, -1);
2389 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2390 gtk_tree_path_free (path);
2392 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2393 0, "Foo", 1, TRUE, -1);
2395 signal_monitor_assert_is_empty (monitor);
2396 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2398 /* Modify the iter that should be at the last position and check the
2401 path = gtk_tree_path_new_from_indices (2, -1);
2402 signal_monitor_append_signal_path (monitor, ROW_CHANGED, path);
2403 gtk_tree_path_free (path);
2405 gtk_tree_store_set (store, &last_iter, 0, "Foo changed", -1);
2407 signal_monitor_assert_is_empty (monitor);
2408 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2414 GtkTreeStore *store;
2415 GtkTreeModel *filter;
2416 GtkWidget *tree_view;
2417 SignalMonitor *monitor;
2418 GtkTreeIter parent, iter;
2421 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2423 gtk_tree_store_insert_with_values (store, &parent, NULL, 0,
2424 0, "Parent", 1, TRUE, -1);
2427 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2428 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2431 tree_view = gtk_tree_view_new_with_model (filter);
2432 monitor = signal_monitor_new (filter);
2434 /* Insert child -- invisible */
2435 path = gtk_tree_path_new_from_indices (0, -1);
2436 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2437 /* The signal is received twice, once a pass through from GtkTreeStore
2438 * and one generated by GtkTreeModelFilter. Not accurate, but cannot
2441 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2442 gtk_tree_path_free (path);
2444 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2445 0, "Child", 1, FALSE, -1);
2447 signal_monitor_assert_is_empty (monitor);
2448 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2451 path = gtk_tree_path_new_from_indices (0, 0, -1);
2452 gtk_tree_path_up (path); /* 0 */
2453 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2454 gtk_tree_path_free (path);
2456 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
2457 0, "Child", 1, TRUE, -1);
2459 signal_monitor_assert_is_empty (monitor);
2460 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2462 /* Insert child -- invisible */
2463 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2464 0, "Child", 1, FALSE, -1);
2466 signal_monitor_assert_is_empty (monitor);
2467 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2475 GtkTreeIter iter, iter1, iter2, iter3;
2477 GtkTreeModel *filter;
2478 GtkWidget *view G_GNUC_UNUSED;
2480 list = gtk_list_store_new (1, G_TYPE_INT);
2481 gtk_list_store_insert_with_values (list, &iter1, 0, 0, 1, -1);
2482 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
2483 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
2484 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
2485 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
2486 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
2487 gtk_list_store_insert_with_values (list, &iter2, 6, 0, 7, -1);
2488 gtk_list_store_insert_with_values (list, &iter3, 7, 0, 8, -1);
2490 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
2491 view = gtk_tree_view_new_with_model (filter);
2493 gtk_list_store_remove (list, &iter1);
2494 gtk_list_store_remove (list, &iter3);
2495 gtk_list_store_remove (list, &iter2);
2497 gtk_widget_destroy (view);
2498 g_object_unref (filter);
2499 g_object_unref (list);
2503 remove_node_vroot (void)
2505 GtkTreeIter parent, root;
2506 GtkTreeIter iter, iter1, iter2, iter3;
2508 GtkTreeModel *filter;
2510 GtkWidget *view G_GNUC_UNUSED;
2512 tree = gtk_tree_store_new (1, G_TYPE_INT);
2513 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2514 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2516 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2517 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2518 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2519 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2520 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2521 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2522 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2523 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2525 path = gtk_tree_path_new_from_indices (0, 0, -1);
2526 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2527 gtk_tree_path_free (path);
2529 view = gtk_tree_view_new_with_model (filter);
2531 gtk_tree_store_remove (tree, &iter1);
2532 gtk_tree_store_remove (tree, &iter3);
2533 gtk_tree_store_remove (tree, &iter2);
2535 gtk_widget_destroy (view);
2536 g_object_unref (filter);
2537 g_object_unref (tree);
2541 remove_vroot_ancestor (void)
2543 GtkTreeIter parent, root;
2544 GtkTreeIter iter, iter1, iter2, iter3;
2546 GtkTreeModel *filter;
2548 GtkWidget *view G_GNUC_UNUSED;
2550 tree = gtk_tree_store_new (1, G_TYPE_INT);
2551 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2552 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2554 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2555 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2556 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2557 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2558 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2559 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2560 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2561 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2563 path = gtk_tree_path_new_from_indices (0, 0, -1);
2564 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2565 gtk_tree_path_free (path);
2567 view = gtk_tree_view_new_with_model (filter);
2569 gtk_tree_store_remove (tree, &parent);
2571 gtk_widget_destroy (view);
2572 g_object_unref (filter);
2573 g_object_unref (tree);
2577 ref_count_single_level (void)
2579 GtkTreeIter iter[5];
2580 GtkTreeModel *model;
2581 GtkTreeModelRefCount *ref_model;
2582 GtkTreeModel *filter_model;
2583 GtkWidget *tree_view;
2585 model = gtk_tree_model_ref_count_new ();
2586 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2588 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[0], NULL);
2589 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[1], NULL);
2590 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[2], NULL);
2591 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[3], NULL);
2592 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[4], NULL);
2594 assert_root_level_unreferenced (ref_model);
2596 filter_model = gtk_tree_model_filter_new (model, NULL);
2597 tree_view = gtk_tree_view_new_with_model (filter_model);
2599 assert_node_ref_count (ref_model, &iter[0], 2);
2600 assert_node_ref_count (ref_model, &iter[1], 1);
2601 assert_node_ref_count (ref_model, &iter[2], 1);
2602 assert_node_ref_count (ref_model, &iter[3], 1);
2603 assert_node_ref_count (ref_model, &iter[4], 1);
2605 gtk_widget_destroy (tree_view);
2607 assert_node_ref_count (ref_model, &iter[0], 1);
2608 assert_node_ref_count (ref_model, &iter[1], 0);
2609 assert_node_ref_count (ref_model, &iter[2], 0);
2610 assert_node_ref_count (ref_model, &iter[3], 0);
2611 assert_node_ref_count (ref_model, &iter[4], 0);
2613 g_object_unref (filter_model);
2615 assert_node_ref_count (ref_model, &iter[0], 0);
2617 g_object_unref (ref_model);
2621 ref_count_two_levels (void)
2623 GtkTreeIter parent1, parent2, iter, iter_first;
2624 GtkTreeModel *model;
2625 GtkTreeModelRefCount *ref_model;
2626 GtkTreeModel *filter_model;
2627 GtkWidget *tree_view;
2629 model = gtk_tree_model_ref_count_new ();
2630 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2632 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL);
2633 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
2634 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_first, &parent2);
2635 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2636 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2638 assert_entire_model_unreferenced (ref_model);
2640 filter_model = gtk_tree_model_filter_new (model, NULL);
2641 tree_view = gtk_tree_view_new_with_model (filter_model);
2643 /* This is quite confusing:
2644 * - node 0 has a ref count of 2 because it is referenced as the
2645 * first node in a level and by the tree view.
2646 * - node 1 has a ref count of 2 because it is referenced by its
2647 * child level and by the tree view.
2649 assert_root_level_referenced (ref_model, 2);
2650 assert_node_ref_count (ref_model, &iter_first, 1);
2651 assert_node_ref_count (ref_model, &iter, 0);
2653 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
2655 assert_node_ref_count (ref_model, &parent1, 2);
2656 assert_node_ref_count (ref_model, &parent2, 2);
2657 assert_node_ref_count (ref_model, &iter_first, 2);
2658 assert_node_ref_count (ref_model, &iter, 1);
2660 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2662 /* The child level is not destroyed because its parent is visible */
2663 assert_node_ref_count (ref_model, &parent1, 2);
2664 assert_node_ref_count (ref_model, &parent2, 2);
2665 assert_node_ref_count (ref_model, &iter_first, 1);
2666 assert_node_ref_count (ref_model, &iter, 0);
2668 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2670 assert_node_ref_count (ref_model, &parent1, 2);
2671 assert_node_ref_count (ref_model, &parent2, 2);
2672 assert_node_ref_count (ref_model, &iter_first, 1);
2673 assert_node_ref_count (ref_model, &iter, 0);
2675 gtk_widget_destroy (tree_view);
2677 assert_root_level_referenced (ref_model, 1);
2678 assert_node_ref_count (ref_model, &iter_first, 1);
2679 assert_node_ref_count (ref_model, &iter, 0);
2681 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2683 /* Only the reference on the first node of the root level is kept. */
2684 assert_node_ref_count (ref_model, &parent1, 1);
2685 assert_node_ref_count (ref_model, &parent2, 0);
2686 assert_node_ref_count (ref_model, &iter_first, 0);
2687 assert_node_ref_count (ref_model, &iter, 0);
2689 g_object_unref (filter_model);
2690 g_object_unref (ref_model);
2694 ref_count_three_levels (void)
2696 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2697 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2698 GtkTreeModel *model;
2699 GtkTreeModelRefCount *ref_model;
2700 GtkTreeModel *filter_model;
2702 GtkWidget *tree_view;
2704 model = gtk_tree_model_ref_count_new ();
2705 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2712 * + iter_parent2_first
2716 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2717 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2718 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2719 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2720 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2721 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2722 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2724 assert_entire_model_unreferenced (ref_model);
2726 filter_model = gtk_tree_model_filter_new (model, NULL);
2727 tree_view = gtk_tree_view_new_with_model (filter_model);
2729 /* This is quite confusing:
2730 * - node 0 has a ref count of 2 because it is referenced as the
2731 * first node in a level and by the tree view.
2732 * - node 1 has a ref count of 2 because it is referenced by its
2733 * child level and by the tree view.
2735 assert_root_level_referenced (ref_model, 2);
2736 assert_node_ref_count (ref_model, &parent1, 1);
2737 assert_node_ref_count (ref_model, &parent2, 0);
2738 assert_level_unreferenced (ref_model, &parent1);
2739 assert_level_unreferenced (ref_model, &parent2);
2741 path = gtk_tree_path_new_from_indices (1, -1);
2742 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2744 assert_node_ref_count (ref_model, &grandparent1, 2);
2745 assert_node_ref_count (ref_model, &grandparent2, 2);
2746 assert_node_ref_count (ref_model, &parent1, 3);
2747 assert_node_ref_count (ref_model, &parent2, 2);
2748 assert_node_ref_count (ref_model, &iter_parent1, 1);
2749 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2750 assert_node_ref_count (ref_model, &iter_parent2, 0);
2752 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2754 assert_node_ref_count (ref_model, &grandparent1, 2);
2755 assert_node_ref_count (ref_model, &grandparent2, 2);
2756 assert_node_ref_count (ref_model, &parent1, 3);
2757 assert_node_ref_count (ref_model, &parent2, 2);
2758 assert_node_ref_count (ref_model, &iter_parent1, 2);
2759 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2760 assert_node_ref_count (ref_model, &iter_parent2, 1);
2762 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2764 assert_node_ref_count (ref_model, &grandparent1, 2);
2765 assert_node_ref_count (ref_model, &grandparent2, 2);
2766 assert_node_ref_count (ref_model, &parent1, 2);
2767 assert_node_ref_count (ref_model, &parent2, 1);
2768 assert_node_ref_count (ref_model, &iter_parent1, 1);
2769 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2770 assert_node_ref_count (ref_model, &iter_parent2, 0);
2772 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2774 assert_node_ref_count (ref_model, &grandparent1, 2);
2775 assert_node_ref_count (ref_model, &grandparent2, 2);
2776 assert_node_ref_count (ref_model, &parent1, 1);
2777 assert_node_ref_count (ref_model, &parent2, 0);
2778 assert_node_ref_count (ref_model, &iter_parent1, 0);
2779 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2780 assert_node_ref_count (ref_model, &iter_parent2, 0);
2782 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2784 assert_node_ref_count (ref_model, &grandparent1, 2);
2785 assert_node_ref_count (ref_model, &grandparent2, 2);
2786 assert_node_ref_count (ref_model, &parent1, 3);
2787 assert_node_ref_count (ref_model, &parent2, 2);
2788 assert_node_ref_count (ref_model, &iter_parent1, 1);
2789 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2790 assert_node_ref_count (ref_model, &iter_parent2, 0);
2792 gtk_tree_path_append_index (path, 1);
2793 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2795 assert_node_ref_count (ref_model, &grandparent1, 2);
2796 assert_node_ref_count (ref_model, &grandparent2, 2);
2797 assert_node_ref_count (ref_model, &parent1, 3);
2798 assert_node_ref_count (ref_model, &parent2, 2);
2799 assert_node_ref_count (ref_model, &iter_parent1, 1);
2800 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2801 assert_node_ref_count (ref_model, &iter_parent2, 1);
2803 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2805 assert_node_ref_count (ref_model, &grandparent1, 2);
2806 assert_node_ref_count (ref_model, &grandparent2, 2);
2807 assert_node_ref_count (ref_model, &parent1, 3);
2808 assert_node_ref_count (ref_model, &parent2, 2);
2809 assert_node_ref_count (ref_model, &iter_parent1, 1);
2810 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2811 assert_node_ref_count (ref_model, &iter_parent2, 0);
2813 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2815 assert_node_ref_count (ref_model, &grandparent1, 2);
2816 assert_node_ref_count (ref_model, &grandparent2, 2);
2817 assert_node_ref_count (ref_model, &parent1, 3);
2818 assert_node_ref_count (ref_model, &parent2, 2);
2819 assert_node_ref_count (ref_model, &iter_parent1, 1);
2820 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2821 assert_node_ref_count (ref_model, &iter_parent2, 0);
2823 gtk_tree_path_up (path);
2824 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2825 gtk_tree_path_free (path);
2827 assert_node_ref_count (ref_model, &grandparent1, 2);
2828 assert_node_ref_count (ref_model, &grandparent2, 2);
2829 assert_node_ref_count (ref_model, &parent1, 2);
2830 assert_node_ref_count (ref_model, &parent2, 1);
2831 assert_node_ref_count (ref_model, &iter_parent1, 1);
2832 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2833 assert_node_ref_count (ref_model, &iter_parent2, 0);
2835 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2837 assert_node_ref_count (ref_model, &grandparent1, 2);
2838 assert_node_ref_count (ref_model, &grandparent2, 2);
2839 assert_node_ref_count (ref_model, &parent1, 1);
2840 assert_node_ref_count (ref_model, &parent2, 0);
2841 assert_node_ref_count (ref_model, &iter_parent1, 0);
2842 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2843 assert_node_ref_count (ref_model, &iter_parent2, 0);
2845 gtk_widget_destroy (tree_view);
2847 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2849 /* Only the reference on the first node of the root level is kept. */
2850 assert_node_ref_count (ref_model, &grandparent1, 1);
2851 assert_node_ref_count (ref_model, &grandparent2, 0);
2852 assert_node_ref_count (ref_model, &parent1, 0);
2853 assert_node_ref_count (ref_model, &parent2, 0);
2854 assert_node_ref_count (ref_model, &iter_parent1, 0);
2855 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2856 assert_node_ref_count (ref_model, &iter_parent2, 0);
2858 g_object_unref (filter_model);
2859 g_object_unref (ref_model);
2863 ref_count_delete_row (void)
2865 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2866 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2867 GtkTreeModel *model;
2868 GtkTreeModelRefCount *ref_model;
2869 GtkTreeModel *filter_model;
2871 GtkWidget *tree_view;
2873 model = gtk_tree_model_ref_count_new ();
2874 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2881 * + iter_parent2_first
2885 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2886 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2887 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2888 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2889 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2890 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2891 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2893 assert_entire_model_unreferenced (ref_model);
2895 filter_model = gtk_tree_model_filter_new (model, NULL);
2896 tree_view = gtk_tree_view_new_with_model (filter_model);
2898 assert_root_level_referenced (ref_model, 2);
2899 assert_node_ref_count (ref_model, &parent1, 1);
2900 assert_node_ref_count (ref_model, &parent2, 0);
2901 assert_level_unreferenced (ref_model, &parent1);
2902 assert_level_unreferenced (ref_model, &parent2);
2904 path = gtk_tree_path_new_from_indices (1, -1);
2905 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2907 assert_node_ref_count (ref_model, &grandparent1, 2);
2908 assert_node_ref_count (ref_model, &grandparent2, 2);
2909 assert_node_ref_count (ref_model, &parent1, 3);
2910 assert_node_ref_count (ref_model, &parent2, 2);
2911 assert_node_ref_count (ref_model, &iter_parent1, 2);
2912 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2913 assert_node_ref_count (ref_model, &iter_parent2, 1);
2915 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter_parent2);
2917 assert_node_ref_count (ref_model, &grandparent1, 2);
2918 assert_node_ref_count (ref_model, &grandparent2, 2);
2919 assert_node_ref_count (ref_model, &parent1, 3);
2920 assert_node_ref_count (ref_model, &parent2, 2);
2921 assert_node_ref_count (ref_model, &iter_parent1, 2);
2922 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2924 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1);
2926 assert_node_ref_count (ref_model, &grandparent1, 2);
2927 assert_node_ref_count (ref_model, &grandparent2, 2);
2928 assert_node_ref_count (ref_model, &parent2, 3);
2929 assert_level_referenced (ref_model, 2, &parent2);
2931 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
2933 assert_node_ref_count (ref_model, &grandparent1, 2);
2935 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2937 assert_node_ref_count (ref_model, &grandparent1, 2);
2939 gtk_widget_destroy (tree_view);
2940 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2942 assert_node_ref_count (ref_model, &grandparent1, 1);
2944 g_object_unref (filter_model);
2946 assert_node_ref_count (ref_model, &grandparent1, 0);
2948 g_object_unref (ref_model);
2952 ref_count_cleanup (void)
2954 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2955 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2956 GtkTreeModel *model;
2957 GtkTreeModelRefCount *ref_model;
2958 GtkTreeModel *filter_model;
2959 GtkWidget *tree_view;
2961 model = gtk_tree_model_ref_count_new ();
2962 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2969 * + iter_parent2_first
2973 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2974 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2975 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2976 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2977 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2978 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2979 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2981 filter_model = gtk_tree_model_filter_new (model, NULL);
2982 tree_view = gtk_tree_view_new_with_model (filter_model);
2984 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
2986 assert_node_ref_count (ref_model, &grandparent1, 2);
2987 assert_node_ref_count (ref_model, &grandparent2, 2);
2988 assert_node_ref_count (ref_model, &parent1, 3);
2989 assert_node_ref_count (ref_model, &parent2, 2);
2990 assert_node_ref_count (ref_model, &iter_parent1, 2);
2991 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2992 assert_node_ref_count (ref_model, &iter_parent2, 1);
2994 gtk_widget_destroy (tree_view);
2996 assert_node_ref_count (ref_model, &grandparent1, 1);
2997 assert_node_ref_count (ref_model, &grandparent2, 1);
2998 assert_node_ref_count (ref_model, &parent1, 2);
2999 assert_node_ref_count (ref_model, &parent2, 1);
3000 assert_node_ref_count (ref_model, &iter_parent1, 1);
3001 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3002 assert_node_ref_count (ref_model, &iter_parent2, 0);
3004 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3006 /* Only the reference on the first node of the root level is kept. */
3007 assert_node_ref_count (ref_model, &grandparent1, 1);
3008 assert_node_ref_count (ref_model, &grandparent2, 0);
3009 assert_node_ref_count (ref_model, &parent1, 0);
3010 assert_node_ref_count (ref_model, &parent2, 0);
3011 assert_node_ref_count (ref_model, &iter_parent1, 0);
3012 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
3013 assert_node_ref_count (ref_model, &iter_parent2, 0);
3015 g_object_unref (filter_model);
3016 g_object_unref (ref_model);
3020 ref_count_row_ref (void)
3022 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
3023 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
3024 GtkTreeModel *model;
3025 GtkTreeModelRefCount *ref_model;
3026 GtkTreeModel *filter_model;
3027 GtkWidget *tree_view;
3029 GtkTreeRowReference *row_ref;
3031 model = gtk_tree_model_ref_count_new ();
3032 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3043 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3044 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3045 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
3046 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
3047 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
3048 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
3049 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
3051 filter_model = gtk_tree_model_filter_new (model, NULL);
3052 tree_view = gtk_tree_view_new_with_model (filter_model);
3054 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3055 row_ref = gtk_tree_row_reference_new (filter_model, path);
3056 gtk_tree_path_free (path);
3058 assert_node_ref_count (ref_model, &grandparent1, 2);
3059 assert_node_ref_count (ref_model, &grandparent2, 3);
3060 assert_node_ref_count (ref_model, &parent1, 1);
3061 assert_node_ref_count (ref_model, &parent2, 2);
3062 assert_node_ref_count (ref_model, &iter_parent1, 0);
3063 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3064 assert_node_ref_count (ref_model, &iter_parent2, 1);
3066 gtk_tree_row_reference_free (row_ref);
3068 assert_node_ref_count (ref_model, &grandparent1, 2);
3069 assert_node_ref_count (ref_model, &grandparent2, 2);
3070 assert_node_ref_count (ref_model, &parent1, 1);
3071 assert_node_ref_count (ref_model, &parent2, 1);
3072 assert_node_ref_count (ref_model, &iter_parent1, 0);
3073 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3074 assert_node_ref_count (ref_model, &iter_parent2, 0);
3076 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3077 row_ref = gtk_tree_row_reference_new (filter_model, path);
3078 gtk_tree_path_free (path);
3080 assert_node_ref_count (ref_model, &grandparent1, 2);
3081 assert_node_ref_count (ref_model, &grandparent2, 3);
3082 assert_node_ref_count (ref_model, &parent1, 1);
3083 assert_node_ref_count (ref_model, &parent2, 2);
3084 assert_node_ref_count (ref_model, &iter_parent1, 0);
3085 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3086 assert_node_ref_count (ref_model, &iter_parent2, 1);
3088 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
3090 assert_node_ref_count (ref_model, &grandparent1, 2);
3091 assert_node_ref_count (ref_model, &grandparent2, 2);
3092 assert_node_ref_count (ref_model, &parent1, 1);
3093 assert_node_ref_count (ref_model, &iter_parent1, 0);
3095 gtk_tree_row_reference_free (row_ref);
3097 assert_node_ref_count (ref_model, &grandparent1, 2);
3098 assert_node_ref_count (ref_model, &grandparent2, 2);
3099 assert_node_ref_count (ref_model, &parent1, 1);
3100 assert_node_ref_count (ref_model, &iter_parent1, 0);
3102 gtk_widget_destroy (tree_view);
3104 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3106 /* Only the reference on the first node of the root level is kept. */
3107 assert_node_ref_count (ref_model, &grandparent1, 1);
3108 assert_node_ref_count (ref_model, &grandparent2, 0);
3109 assert_node_ref_count (ref_model, &parent1, 0);
3111 g_object_unref (filter_model);
3112 g_object_unref (ref_model);
3116 ref_count_transfer_root_level_insert (void)
3118 GtkTreeIter grandparent1, grandparent2, grandparent3;
3119 GtkTreeIter new_node;
3120 GtkTreeModel *model;
3121 GtkTreeModelRefCount *ref_model;
3122 GtkTreeModel *filter_model;
3123 GtkWidget *tree_view;
3125 model = gtk_tree_model_ref_count_new ();
3126 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3133 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3134 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3135 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3137 filter_model = gtk_tree_model_filter_new (model, NULL);
3138 tree_view = gtk_tree_view_new_with_model (filter_model);
3140 assert_node_ref_count (ref_model, &grandparent1, 2);
3141 assert_node_ref_count (ref_model, &grandparent2, 1);
3142 assert_node_ref_count (ref_model, &grandparent3, 1);
3144 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
3146 assert_node_ref_count (ref_model, &new_node, 2);
3147 assert_node_ref_count (ref_model, &grandparent1, 1);
3148 assert_node_ref_count (ref_model, &grandparent2, 1);
3149 assert_node_ref_count (ref_model, &grandparent3, 1);
3151 gtk_widget_destroy (tree_view);
3152 g_object_unref (filter_model);
3153 g_object_unref (ref_model);
3157 ref_count_transfer_root_level_reordered (void)
3159 GtkTreeIter grandparent1, grandparent2, grandparent3;
3160 GtkTreeModel *model;
3161 GtkTreeModelRefCount *ref_model;
3162 GtkTreeModel *filter_model;
3163 GtkWidget *tree_view;
3165 model = gtk_tree_model_ref_count_new ();
3166 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3173 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3174 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3175 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3177 filter_model = gtk_tree_model_filter_new (model, NULL);
3178 tree_view = gtk_tree_view_new_with_model (filter_model);
3180 assert_node_ref_count (ref_model, &grandparent1, 2);
3181 assert_node_ref_count (ref_model, &grandparent2, 1);
3182 assert_node_ref_count (ref_model, &grandparent3, 1);
3184 /* gtk_tree_store_move() will emit rows-reordered */
3185 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3186 &grandparent1, &grandparent3);
3188 assert_node_ref_count (ref_model, &grandparent2, 2);
3189 assert_node_ref_count (ref_model, &grandparent3, 1);
3190 assert_node_ref_count (ref_model, &grandparent1, 1);
3192 gtk_widget_destroy (tree_view);
3193 g_object_unref (filter_model);
3194 g_object_unref (ref_model);
3198 ref_count_transfer_child_level_insert (void)
3200 GtkTreeIter grandparent1;
3201 GtkTreeIter parent1, parent2, parent3;
3202 GtkTreeIter new_node;
3203 GtkTreeModel *model;
3204 GtkTreeModelRefCount *ref_model;
3205 GtkTreeModel *filter_model;
3206 GtkWidget *tree_view;
3208 model = gtk_tree_model_ref_count_new ();
3209 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3217 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3218 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
3219 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
3220 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
3222 filter_model = gtk_tree_model_filter_new (model, NULL);
3223 tree_view = gtk_tree_view_new_with_model (filter_model);
3225 assert_node_ref_count (ref_model, &grandparent1, 3);
3226 assert_node_ref_count (ref_model, &parent1, 1);
3227 assert_node_ref_count (ref_model, &parent2, 0);
3228 assert_node_ref_count (ref_model, &parent3, 0);
3230 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &grandparent1);
3232 assert_node_ref_count (ref_model, &grandparent1, 3);
3233 assert_node_ref_count (ref_model, &new_node, 1);
3234 assert_node_ref_count (ref_model, &parent1, 0);
3235 assert_node_ref_count (ref_model, &parent2, 0);
3236 assert_node_ref_count (ref_model, &parent3, 0);
3238 gtk_widget_destroy (tree_view);
3239 g_object_unref (filter_model);
3240 g_object_unref (ref_model);
3244 ref_count_transfer_child_level_reordered (void)
3246 GtkTreeIter grandparent1;
3247 GtkTreeIter parent1, parent2, parent3;
3248 GtkTreeModel *model;
3249 GtkTreeModelRefCount *ref_model;
3250 GtkTreeModel *filter_model;
3251 GtkWidget *tree_view;
3253 model = gtk_tree_model_ref_count_new ();
3254 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3262 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3263 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
3264 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
3265 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
3267 filter_model = gtk_tree_model_filter_new (model, NULL);
3268 tree_view = gtk_tree_view_new_with_model (filter_model);
3270 assert_node_ref_count (ref_model, &grandparent1, 3);
3271 assert_node_ref_count (ref_model, &parent1, 1);
3272 assert_node_ref_count (ref_model, &parent2, 0);
3273 assert_node_ref_count (ref_model, &parent3, 0);
3275 /* gtk_tree_store_move() will emit rows-reordered */
3276 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3277 &parent1, &parent3);
3279 assert_node_ref_count (ref_model, &grandparent1, 3);
3280 assert_node_ref_count (ref_model, &parent2, 1);
3281 assert_node_ref_count (ref_model, &parent3, 0);
3282 assert_node_ref_count (ref_model, &parent1, 0);
3284 gtk_widget_destroy (tree_view);
3285 g_object_unref (filter_model);
3286 g_object_unref (ref_model);
3291 specific_path_dependent_filter_func (GtkTreeModel *model,
3297 path = gtk_tree_model_get_path (model, iter);
3298 if (gtk_tree_path_get_indices (path)[0] < 4)
3305 specific_path_dependent_filter (void)
3311 GtkTreeModel *filter;
3313 list = gtk_list_store_new (1, G_TYPE_INT);
3314 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
3315 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
3316 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
3317 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
3318 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
3319 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
3320 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
3321 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
3323 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (list));
3324 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (sort), NULL);
3325 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
3326 specific_path_dependent_filter_func,
3329 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort), 0,
3330 GTK_SORT_DESCENDING);
3332 for (i = 0; i < 4; i++)
3334 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
3336 gtk_list_store_remove (list, &iter);
3338 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
3340 gtk_list_store_remove (list, &iter);
3343 g_object_unref (filter);
3344 g_object_unref (sort);
3345 g_object_unref (list);
3350 specific_append_after_collapse_visible_func (GtkTreeModel *model,
3355 gboolean hide_negative_numbers;
3357 gtk_tree_model_get (model, iter, 1, &number, -1);
3358 hide_negative_numbers = GPOINTER_TO_INT (g_object_get_data (data, "private-hide-negative-numbers"));
3360 return (number >= 0 || !hide_negative_numbers);
3364 specific_append_after_collapse (void)
3366 /* This test is based on one of the test cases I found in my
3367 * old test cases directory. I unfortunately do not have a record
3368 * from who this test case originated. -Kris.
3372 * - Show tree, expand, collapse.
3377 GtkTreeIter child_iter;
3378 GtkTreeIter child_iter2;
3379 GtkTreePath *append_path;
3380 GtkTreeStore *store;
3381 GtkTreeModel *filter;
3385 GtkWidget *tree_view;
3387 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT);
3389 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
3390 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
3391 GINT_TO_POINTER (FALSE));
3392 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
3393 specific_append_after_collapse_visible_func,
3396 sort = gtk_tree_model_sort_new_with_model (filter);
3398 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3399 tree_view = gtk_tree_view_new_with_model (sort);
3400 gtk_container_add (GTK_CONTAINER (window), tree_view);
3401 gtk_widget_realize (tree_view);
3403 while (gtk_events_pending ())
3404 gtk_main_iteration ();
3406 gtk_tree_store_prepend (store, &iter, NULL);
3407 gtk_tree_store_set (store, &iter,
3408 0, "hallo", 1, 1, -1);
3410 gtk_tree_store_append (store, &child_iter, &iter);
3411 gtk_tree_store_set (store, &child_iter,
3412 0, "toemaar", 1, 1, -1);
3414 gtk_tree_store_append (store, &child_iter2, &child_iter);
3415 gtk_tree_store_set (store, &child_iter2,
3416 0, "very deep", 1, 1, -1);
3418 append_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &child_iter2);
3420 gtk_tree_store_append (store, &child_iter, &iter);
3421 gtk_tree_store_set (store, &child_iter,
3422 0, "sja", 1, 1, -1);
3424 gtk_tree_store_append (store, &child_iter, &iter);
3425 gtk_tree_store_set (store, &child_iter,
3426 0, "some word", 1, -1, -1);
3428 /* Expand and collapse the tree */
3429 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
3430 while (gtk_events_pending ())
3431 gtk_main_iteration ();
3433 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
3434 while (gtk_events_pending ())
3435 gtk_main_iteration ();
3437 /* Add another it */
3438 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
3439 GINT_TO_POINTER (TRUE));
3441 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, append_path))
3443 gtk_tree_store_append (store, &child_iter, &iter);
3444 gtk_tree_store_set (store, &child_iter,
3445 0, "new new new !!", 1, 1, -1);
3447 gtk_tree_path_free (append_path);
3450 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
3451 while (gtk_events_pending ())
3452 gtk_main_iteration ();
3457 specific_sort_filter_remove_node_compare_func (GtkTreeModel *model,
3466 specific_sort_filter_remove_node_visible_func (GtkTreeModel *model,
3472 /* Do reference the model */
3473 gtk_tree_model_get (model, iter, 0, &item, -1);
3480 specific_sort_filter_remove_node (void)
3482 /* This test is based on one of the test cases I found in my
3483 * old test cases directory. I unfortunately do not have a record
3484 * from who this test case originated. -Kris.
3487 * - Create tree store, sort, filter models. The sort model has
3488 * a default sort func that is enabled, filter model a visible func
3489 * that defaults to returning FALSE.
3490 * - Remove a node from the tree store.
3494 GtkTreeStore *store;
3495 GtkTreeModel *filter;
3499 GtkWidget *tree_view;
3501 store = gtk_tree_store_new (1, G_TYPE_STRING);
3502 gtk_tree_store_append (store, &iter, NULL);
3503 gtk_tree_store_set (store, &iter, 0, "Hello1", -1);
3505 gtk_tree_store_append (store, &iter, NULL);
3506 gtk_tree_store_set (store, &iter, 0, "Hello2", -1);
3508 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
3509 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
3510 specific_sort_filter_remove_node_compare_func, NULL, NULL);
3512 filter = gtk_tree_model_filter_new (sort, NULL);
3513 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
3514 specific_sort_filter_remove_node_visible_func,
3518 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3519 tree_view = gtk_tree_view_new_with_model (filter);
3520 gtk_container_add (GTK_CONTAINER (window), tree_view);
3521 gtk_widget_realize (tree_view);
3523 while (gtk_events_pending ())
3524 gtk_main_iteration ();
3527 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
3528 gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
3529 gtk_tree_store_remove (store, &iter);
3531 while (gtk_events_pending ())
3532 gtk_main_iteration ();
3537 specific_sort_filter_remove_root (void)
3539 /* This test is based on one of the test cases I found in my
3540 * old test cases directory. I unfortunately do not have a record
3541 * from who this test case originated. -Kris.
3544 GtkTreeModel *model, *sort, *filter;
3545 GtkTreeIter root, mid, leaf;
3548 model = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
3549 gtk_tree_store_append (GTK_TREE_STORE (model), &root, NULL);
3550 gtk_tree_store_append (GTK_TREE_STORE (model), &mid, &root);
3551 gtk_tree_store_append (GTK_TREE_STORE (model), &leaf, &mid);
3553 path = gtk_tree_model_get_path (model, &mid);
3555 sort = gtk_tree_model_sort_new_with_model (model);
3556 filter = gtk_tree_model_filter_new (sort, path);
3558 gtk_tree_path_free (path);
3560 gtk_tree_store_remove (GTK_TREE_STORE (model), &root);
3562 g_object_unref (filter);
3563 g_object_unref (sort);
3564 g_object_unref (model);
3569 specific_root_mixed_visibility (void)
3572 GtkTreeModel *filter;
3573 /* A bit nasty, apologies */
3576 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
3578 for (i = 0; i < LEVEL_LENGTH; i++)
3582 gtk_tree_store_insert (fixture.store, &iter, NULL, i);
3584 create_tree_store_set_values (fixture.store, &iter, TRUE);
3586 create_tree_store_set_values (fixture.store, &iter, FALSE);
3589 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
3590 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
3591 fixture.monitor = NULL;
3593 gtk_tree_model_filter_set_visible_column (fixture.filter, 1);
3595 /* In order to trigger the potential bug, we should not access
3596 * the filter model here (so don't call the check functions).
3599 /* Change visibility of an odd row to TRUE */
3600 set_path_visibility (&fixture, "3", TRUE);
3601 check_filter_model (&fixture);
3602 check_level_length (fixture.filter, NULL, 4);
3608 specific_has_child_filter_filter_func (GtkTreeModel *model,
3612 return gtk_tree_model_iter_has_child (model, iter);
3616 specific_has_child_filter (void)
3618 GtkTreeModel *filter;
3619 GtkTreeIter iter, root;
3620 FilterTest fixture; /* This is not how it should be done */
3621 GtkWidget *tree_view;
3623 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
3624 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
3625 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
3626 fixture.monitor = signal_monitor_new (filter);
3628 tree_view = gtk_tree_view_new_with_model (filter);
3630 /* We will filter on parent state using a filter function. We will
3631 * manually keep the boolean column in sync, so that we can use
3632 * check_filter_model() to check the consistency of the model.
3634 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
3635 * to be able to check the structure here. We keep the calls to
3636 * check_filter_model() commented out until then.
3638 gtk_tree_model_filter_set_visible_func (fixture.filter,
3639 specific_has_child_filter_filter_func,
3642 /* The first node will be initially invisible: no signals */
3643 gtk_tree_store_append (fixture.store, &root, NULL);
3644 create_tree_store_set_values (fixture.store, &root, FALSE);
3646 /* check_filter_model (&fixture); */
3647 check_level_length (fixture.filter, NULL, 0);
3648 signal_monitor_assert_is_empty (fixture.monitor);
3650 /* Insert a child node. This will cause the parent to become visible
3651 * since there is a child now.
3653 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
3654 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3655 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3657 gtk_tree_store_append (fixture.store, &iter, &root);
3658 create_tree_store_set_values (fixture.store, &iter, TRUE);
3660 /* Parent must now be visible. Do the level length check first,
3661 * to avoid modifying the child model triggering a row-changed to
3664 check_level_length (fixture.filter, NULL, 1);
3665 check_level_length (fixture.filter, "0", 0);
3666 signal_monitor_assert_is_empty (fixture.monitor);
3668 /* This should propagate row-changed */
3669 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
3670 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3672 set_path_visibility (&fixture, "0", TRUE);
3673 /* check_filter_model (&fixture); */
3674 signal_monitor_assert_is_empty (fixture.monitor);
3676 /* New root node, no child, so no signal */
3677 gtk_tree_store_append (fixture.store, &root, NULL);
3678 check_level_length (fixture.filter, NULL, 1);
3679 signal_monitor_assert_is_empty (fixture.monitor);
3681 /* When the child comes in, this node will become visible */
3682 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
3683 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3684 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3685 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
3686 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3688 gtk_tree_store_append (fixture.store, &iter, &root);
3689 check_level_length (fixture.filter, NULL, 2);
3690 check_level_length (fixture.filter, "1", 0);
3692 create_tree_store_set_values (fixture.store, &root, TRUE);
3693 create_tree_store_set_values (fixture.store, &iter, TRUE);
3695 /* check_filter_model (&fixture); */
3696 signal_monitor_assert_is_empty (fixture.monitor);
3698 /* Add another child for 1 */
3699 gtk_tree_store_append (fixture.store, &iter, &root);
3700 create_tree_store_set_values (fixture.store, &iter, TRUE);
3701 check_level_length (fixture.filter, NULL, 2);
3702 check_level_length (fixture.filter, "0", 0);
3703 check_level_length (fixture.filter, "1", 0);
3704 signal_monitor_assert_is_empty (fixture.monitor);
3706 /* Now remove one of the remaining child rows */
3707 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
3709 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
3711 gtk_tree_store_remove (fixture.store, &iter);
3713 check_level_length (fixture.filter, NULL, 1);
3714 check_level_length (fixture.filter, "0", 0);
3716 set_path_visibility (&fixture, "0", FALSE);
3717 /* check_filter_model (&fixture); */
3718 signal_monitor_assert_is_empty (fixture.monitor);
3723 specific_root_has_child_filter_filter_func (GtkTreeModel *model,
3730 path = gtk_tree_model_get_path (model, iter);
3731 depth = gtk_tree_path_get_depth (path);
3732 gtk_tree_path_free (path);
3737 return gtk_tree_model_iter_has_child (model, iter);
3741 specific_root_has_child_filter (void)
3743 GtkTreeModel *filter;
3744 GtkTreeIter iter, root;
3745 FilterTest fixture; /* This is not how it should be done ... */
3746 GtkWidget *tree_view;
3748 /* This is a variation on the above test case, specific has-child-filter,
3749 * herein the has-child check for visibility only applies to root level
3750 * nodes. In this test, children are always visible because we
3751 * only filter based on the "has child" criterion.
3754 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
3755 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
3756 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
3757 fixture.monitor = signal_monitor_new (filter);
3759 tree_view = gtk_tree_view_new_with_model (filter);
3761 /* We will filter on parent state using a filter function. We will
3762 * manually keep the boolean column in sync, so that we can use
3763 * check_filter_model() to check the consistency of the model.
3765 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
3766 * to be able to check the structure here. We keep the calls to
3767 * check_filter_model() commented out until then.
3769 gtk_tree_model_filter_set_visible_func (fixture.filter,
3770 specific_root_has_child_filter_filter_func,
3773 /* Add a first node, this will be invisible initially, so no signal
3774 * should be emitted.
3776 gtk_tree_store_append (fixture.store, &root, NULL);
3777 create_tree_store_set_values (fixture.store, &root, FALSE);
3779 signal_monitor_assert_is_empty (fixture.monitor);
3780 /* check_filter_model (&fixture); */
3781 check_level_length (fixture.filter, NULL, 0);
3783 /* Add a child node. This will cause the parent to become visible,
3784 * so we expect row-inserted signals for both.
3786 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
3787 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3788 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3790 gtk_tree_store_append (fixture.store, &iter, &root);
3791 signal_monitor_assert_is_empty (fixture.monitor);
3793 check_level_length (fixture.filter, NULL, 1);
3794 check_level_length (fixture.filter, "0", 1);
3796 /* Modify the content of iter, no signals because the parent is not
3799 create_tree_store_set_values (fixture.store, &iter, TRUE);
3800 signal_monitor_assert_is_empty (fixture.monitor);
3802 /* Parent must now be visible. Do the level length check first,
3803 * to avoid modifying the child model triggering a row-changed to
3806 check_level_length (fixture.filter, NULL, 1);
3807 check_level_length (fixture.filter, "0", 1);
3810 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
3811 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3813 set_path_visibility (&fixture, "0", TRUE);
3814 /* check_filter_model (&fixture); */
3816 signal_monitor_assert_is_empty (fixture.monitor);
3818 /* Insert another node in the root level. Initially invisible, so
3819 * not expecting any signal.
3821 gtk_tree_store_append (fixture.store, &root, NULL);
3822 check_level_length (fixture.filter, NULL, 1);
3824 signal_monitor_assert_is_empty (fixture.monitor);
3826 /* Adding a child node which also makes parent at path 1 visible. */
3827 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
3828 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3829 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3831 gtk_tree_store_append (fixture.store, &iter, &root);
3832 check_level_length (fixture.filter, NULL, 2);
3833 check_level_length (fixture.filter, "1", 1);
3835 signal_monitor_assert_is_empty (fixture.monitor);
3837 /* Check if row-changed is propagated */
3838 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
3839 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3841 create_tree_store_set_values (fixture.store, &root, TRUE);
3842 create_tree_store_set_values (fixture.store, &iter, TRUE);
3843 /* check_filter_model (&fixture); */
3844 signal_monitor_assert_is_empty (fixture.monitor);
3846 /* Insert another child under node 1 */
3847 gtk_tree_store_append (fixture.store, &iter, &root);
3848 create_tree_store_set_values (fixture.store, &iter, TRUE);
3849 check_level_length (fixture.filter, NULL, 2);
3850 check_level_length (fixture.filter, "0", 1);
3851 check_level_length (fixture.filter, "1", 2);
3852 signal_monitor_assert_is_empty (fixture.monitor);
3854 /* Set a child node to invisible. This should not yield any
3855 * change, because filtering is only done on whether the root
3856 * node has a child, which it still has.
3858 set_path_visibility (&fixture, "0:0", FALSE);
3859 signal_monitor_assert_is_empty (fixture.monitor);
3861 /* Now remove one of the remaining child rows */
3862 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3863 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
3865 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
3867 gtk_tree_store_remove (fixture.store, &iter);
3869 check_level_length (fixture.filter, NULL, 1);
3870 check_level_length (fixture.filter, "0", 2);
3871 signal_monitor_assert_is_empty (fixture.monitor);
3873 /* Set visibility of 0 to FALSE, no-op for filter model since
3874 * the child 0:0 is already gone
3876 set_path_visibility (&fixture, "0", FALSE);
3877 /* check_filter_model (&fixture); */
3878 signal_monitor_assert_is_empty (fixture.monitor);
3882 specific_has_child_filter_on_sort_model (void)
3884 GtkTreeModel *filter;
3885 GtkTreeModel *sort_model;
3886 GtkTreeIter iter, root;
3887 FilterTest fixture; /* This is not how it should be done */
3888 GtkWidget *tree_view;
3890 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
3891 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
3892 filter = gtk_tree_model_filter_new (sort_model, NULL);
3893 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
3894 fixture.monitor = signal_monitor_new (filter);
3896 tree_view = gtk_tree_view_new_with_model (filter);
3898 /* We will filter on parent state using a filter function. We will
3899 * manually keep the boolean column in sync, so that we can use
3900 * check_filter_model() to check the consistency of the model.
3902 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
3903 * to be able to check the structure here. We keep the calls to
3904 * check_filter_model() commented out until then.
3906 gtk_tree_model_filter_set_visible_func (fixture.filter,
3907 specific_has_child_filter_filter_func,
3910 /* The first node will be initially invisible: no signals */
3911 gtk_tree_store_append (fixture.store, &root, NULL);
3912 create_tree_store_set_values (fixture.store, &root, FALSE);
3914 /* check_filter_model (&fixture); */
3915 check_level_length (fixture.filter, NULL, 0);
3916 signal_monitor_assert_is_empty (fixture.monitor);
3918 /* Insert a child node. This will cause the parent to become visible
3919 * since there is a child now.
3921 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
3922 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3924 gtk_tree_store_append (fixture.store, &iter, &root);
3925 create_tree_store_set_values (fixture.store, &iter, TRUE);
3927 /* Parent must now be visible. Do the level length check first,
3928 * to avoid modifying the child model triggering a row-changed to
3931 check_level_length (fixture.filter, NULL, 1);
3932 check_level_length (fixture.filter, "0", 0);
3933 signal_monitor_assert_is_empty (fixture.monitor);
3935 /* This should propagate row-changed */
3936 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
3937 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
3939 set_path_visibility (&fixture, "0", TRUE);
3940 /* check_filter_model (&fixture); */
3941 signal_monitor_assert_is_empty (fixture.monitor);
3943 /* New root node, no child, so no signal */
3944 gtk_tree_store_append (fixture.store, &root, NULL);
3945 check_level_length (fixture.filter, NULL, 1);
3946 signal_monitor_assert_is_empty (fixture.monitor);
3948 /* When the child comes in, this node will become visible */
3949 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
3950 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3951 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
3952 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
3954 gtk_tree_store_append (fixture.store, &iter, &root);
3955 check_level_length (fixture.filter, NULL, 2);
3956 check_level_length (fixture.filter, "1", 0);
3958 create_tree_store_set_values (fixture.store, &root, TRUE);
3959 create_tree_store_set_values (fixture.store, &iter, TRUE);
3961 /* check_filter_model (&fixture); */
3962 signal_monitor_assert_is_empty (fixture.monitor);
3964 /* Add another child for 1 */
3965 gtk_tree_store_append (fixture.store, &iter, &root);
3966 create_tree_store_set_values (fixture.store, &iter, TRUE);
3967 check_level_length (fixture.filter, NULL, 2);
3968 check_level_length (fixture.filter, "0", 0);
3969 check_level_length (fixture.filter, "1", 0);
3970 signal_monitor_assert_is_empty (fixture.monitor);
3972 /* Now remove one of the remaining child rows */
3973 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
3975 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
3977 gtk_tree_store_remove (fixture.store, &iter);
3979 check_level_length (fixture.filter, NULL, 1);
3980 check_level_length (fixture.filter, "0", 0);
3982 set_path_visibility (&fixture, "0", FALSE);
3983 /* check_filter_model (&fixture); */
3984 signal_monitor_assert_is_empty (fixture.monitor);
3988 specific_at_least_2_children_filter_filter_func (GtkTreeModel *model,
3992 return gtk_tree_model_iter_n_children (model, iter) >= 2;
3996 specific_at_least_2_children_filter (void)
3998 GtkTreeModel *filter;
3999 GtkTreeIter iter, root;
4000 FilterTest fixture; /* This is not how it should be done */
4001 GtkWidget *tree_view;
4003 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4004 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
4005 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4006 fixture.monitor = signal_monitor_new (filter);
4008 tree_view = gtk_tree_view_new_with_model (filter);
4010 gtk_tree_model_filter_set_visible_func (fixture.filter,
4011 specific_at_least_2_children_filter_filter_func,
4014 /* The first node will be initially invisible: no signals */
4015 gtk_tree_store_append (fixture.store, &root, NULL);
4016 create_tree_store_set_values (fixture.store, &root, FALSE);
4018 /* check_filter_model (&fixture); */
4019 check_level_length (fixture.filter, NULL, 0);
4020 signal_monitor_assert_is_empty (fixture.monitor);
4022 /* Insert a child node. Nothing should happen.
4024 gtk_tree_store_append (fixture.store, &iter, &root);
4025 create_tree_store_set_values (fixture.store, &iter, TRUE);
4027 check_level_length (fixture.filter, NULL, 0);
4028 signal_monitor_assert_is_empty (fixture.monitor);
4030 /* Insert a second child node. This will cause the parent to become
4033 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
4034 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4036 gtk_tree_store_append (fixture.store, &iter, &root);
4037 create_tree_store_set_values (fixture.store, &iter, TRUE);
4039 /* Parent must now be visible. Do the level length check first,
4040 * to avoid modifying the child model triggering a row-changed to
4043 check_level_length (fixture.filter, NULL, 1);
4044 check_level_length (fixture.filter, "0", 0);
4045 signal_monitor_assert_is_empty (fixture.monitor);
4047 /* This should propagate row-changed */
4048 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
4049 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4051 set_path_visibility (&fixture, "0", TRUE);
4052 /* check_filter_model (&fixture); */
4053 signal_monitor_assert_is_empty (fixture.monitor);
4055 /* New root node, no child, so no signal */
4056 gtk_tree_store_append (fixture.store, &root, NULL);
4057 check_level_length (fixture.filter, NULL, 1);
4058 signal_monitor_assert_is_empty (fixture.monitor);
4060 /* First child, no signal, no change */
4061 gtk_tree_store_append (fixture.store, &iter, &root);
4062 check_level_length (fixture.filter, NULL, 1);
4063 signal_monitor_assert_is_empty (fixture.monitor);
4065 /* When the second child comes in, this node will become visible */
4066 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
4067 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4068 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
4069 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4071 gtk_tree_store_append (fixture.store, &iter, &root);
4072 check_level_length (fixture.filter, NULL, 2);
4073 check_level_length (fixture.filter, "1", 0);
4075 create_tree_store_set_values (fixture.store, &root, TRUE);
4076 create_tree_store_set_values (fixture.store, &iter, TRUE);
4078 /* check_filter_model (&fixture); */
4079 signal_monitor_assert_is_empty (fixture.monitor);
4081 /* Add another child for 1 */
4082 gtk_tree_store_append (fixture.store, &iter, &root);
4083 create_tree_store_set_values (fixture.store, &iter, TRUE);
4084 check_level_length (fixture.filter, NULL, 2);
4085 check_level_length (fixture.filter, "0", 0);
4086 check_level_length (fixture.filter, "1", 0);
4087 signal_monitor_assert_is_empty (fixture.monitor);
4089 /* Now remove one of the remaining child rows */
4090 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
4092 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
4094 gtk_tree_store_remove (fixture.store, &iter);
4096 check_level_length (fixture.filter, NULL, 1);
4097 check_level_length (fixture.filter, "0", 0);
4099 set_path_visibility (&fixture, "0", FALSE);
4100 /* check_filter_model (&fixture); */
4101 signal_monitor_assert_is_empty (fixture.monitor);
4105 specific_at_least_2_children_filter_on_sort_model (void)
4107 GtkTreeModel *filter;
4108 GtkTreeModel *sort_model;
4109 GtkTreeIter iter, root;
4110 FilterTest fixture; /* This is not how it should be done */
4111 GtkWidget *tree_view;
4113 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4114 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
4115 filter = gtk_tree_model_filter_new (sort_model, NULL);
4116 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4117 fixture.monitor = signal_monitor_new (filter);
4119 tree_view = gtk_tree_view_new_with_model (filter);
4121 gtk_tree_model_filter_set_visible_func (fixture.filter,
4122 specific_at_least_2_children_filter_filter_func,
4125 /* The first node will be initially invisible: no signals */
4126 gtk_tree_store_append (fixture.store, &root, NULL);
4127 create_tree_store_set_values (fixture.store, &root, FALSE);
4129 /* check_filter_model (&fixture); */
4130 check_level_length (fixture.filter, NULL, 0);
4131 signal_monitor_assert_is_empty (fixture.monitor);
4133 /* Insert a child node. Nothing should happen.
4135 gtk_tree_store_append (fixture.store, &iter, &root);
4136 create_tree_store_set_values (fixture.store, &iter, TRUE);
4138 check_level_length (fixture.filter, NULL, 0);
4139 signal_monitor_assert_is_empty (fixture.monitor);
4142 GtkTreePath *path = gtk_tree_path_new_from_indices (0, 0, -1);
4143 GtkTreeRowReference *ref;
4145 ref = gtk_tree_row_reference_new (sort_model, path);
4146 gtk_tree_path_free (path);
4149 /* Insert a second child node. This will cause the parent to become
4152 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
4153 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4155 gtk_tree_store_append (fixture.store, &iter, &root);
4156 create_tree_store_set_values (fixture.store, &iter, TRUE);
4158 /* Parent must now be visible. Do the level length check first,
4159 * to avoid modifying the child model triggering a row-changed to
4162 check_level_length (fixture.filter, NULL, 1);
4163 check_level_length (fixture.filter, "0", 0);
4164 signal_monitor_assert_is_empty (fixture.monitor);
4166 /* This should propagate row-changed */
4167 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
4168 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4170 set_path_visibility (&fixture, "0", TRUE);
4171 /* check_filter_model (&fixture); */
4172 signal_monitor_assert_is_empty (fixture.monitor);
4174 /* New root node, no child, so no signal */
4175 gtk_tree_store_append (fixture.store, &root, NULL);
4176 check_level_length (fixture.filter, NULL, 1);
4177 signal_monitor_assert_is_empty (fixture.monitor);
4182 specific_filter_add_child (void)
4184 /* This test is based on one of the test cases I found in my
4185 * old test cases directory. I unfortunately do not have a record
4186 * from who this test case originated. -Kris.
4190 GtkTreeIter iter_first;
4192 GtkTreeStore *store;
4193 GtkTreeModel *filter G_GNUC_UNUSED;
4195 store = gtk_tree_store_new (1, G_TYPE_STRING);
4197 gtk_tree_store_append (store, &iter_first, NULL);
4198 gtk_tree_store_set (store, &iter_first, 0, "Hello", -1);
4200 gtk_tree_store_append (store, &iter, NULL);
4201 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
4203 gtk_tree_store_append (store, &iter, NULL);
4204 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
4206 gtk_tree_store_append (store, &iter, NULL);
4207 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
4209 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4211 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
4212 gtk_tree_store_append (store, &child, &iter_first);
4213 gtk_tree_store_set (store, &child, 0, "Hello", -1);
4217 specific_list_store_clear (void)
4221 GtkTreeModel *filter;
4222 GtkWidget *view G_GNUC_UNUSED;
4224 list = gtk_list_store_new (1, G_TYPE_INT);
4225 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
4226 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
4227 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
4228 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
4229 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
4230 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
4231 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
4232 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
4234 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
4235 view = gtk_tree_view_new_with_model (filter);
4237 gtk_list_store_clear (list);
4241 specific_sort_ref_leaf_and_remove_ancestor (void)
4243 GtkTreeIter iter, child, child2, child3;
4247 GtkTreeRowReference *rowref;
4248 GtkWidget *view G_GNUC_UNUSED;
4250 tree = gtk_tree_store_new (1, G_TYPE_INT);
4251 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
4252 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
4253 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
4254 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
4256 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
4257 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
4258 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
4260 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
4261 view = gtk_tree_view_new_with_model (sort);
4262 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
4264 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
4265 rowref = gtk_tree_row_reference_new (sort, path);
4266 gtk_tree_path_free (path);
4268 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
4269 rowref = gtk_tree_row_reference_new (sort, path);
4270 gtk_tree_path_free (path);
4272 path = gtk_tree_path_new_from_indices (3, 0, -1);
4273 rowref = gtk_tree_row_reference_new (sort, path);
4274 gtk_tree_path_free (path);
4276 path = gtk_tree_path_new_from_indices (3, -1);
4277 rowref = gtk_tree_row_reference_new (sort, path);
4278 gtk_tree_path_free (path);
4280 /* Deleting a parent */
4281 path = gtk_tree_path_new_from_indices (3, 0, -1);
4282 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
4283 gtk_tree_store_remove (tree, &iter);
4284 gtk_tree_path_free (path);
4286 gtk_tree_row_reference_free (rowref);
4290 specific_ref_leaf_and_remove_ancestor (void)
4292 GtkTreeIter iter, child, child2, child3;
4294 GtkTreeModel *filter;
4296 GtkTreeRowReference *rowref;
4297 GtkWidget *view G_GNUC_UNUSED;
4299 tree = gtk_tree_store_new (1, G_TYPE_INT);
4300 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
4301 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
4302 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
4303 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
4305 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
4306 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
4307 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
4309 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), NULL);
4310 view = gtk_tree_view_new_with_model (filter);
4311 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
4313 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
4314 rowref = gtk_tree_row_reference_new (filter, path);
4315 gtk_tree_path_free (path);
4317 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
4318 rowref = gtk_tree_row_reference_new (filter, path);
4319 gtk_tree_path_free (path);
4321 path = gtk_tree_path_new_from_indices (3, 0, -1);
4322 rowref = gtk_tree_row_reference_new (filter, path);
4323 gtk_tree_path_free (path);
4325 path = gtk_tree_path_new_from_indices (3, -1);
4326 rowref = gtk_tree_row_reference_new (filter, path);
4327 gtk_tree_path_free (path);
4329 /* Deleting a parent */
4330 path = gtk_tree_path_new_from_indices (3, 0, -1);
4331 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
4332 gtk_tree_store_remove (tree, &iter);
4333 gtk_tree_path_free (path);
4335 gtk_tree_row_reference_free (rowref);
4339 specific_virtual_ref_leaf_and_remove_ancestor (void)
4341 GtkTreeIter iter, child, child2, child3;
4343 GtkTreeModel *filter;
4345 GtkTreeRowReference *rowref;
4346 GtkWidget *view G_GNUC_UNUSED;
4348 tree = gtk_tree_store_new (1, G_TYPE_INT);
4349 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
4350 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
4351 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
4352 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
4354 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
4355 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
4356 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
4358 /* Set a virtual root of 3:0 */
4359 path = gtk_tree_path_new_from_indices (3, 0, -1);
4360 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
4361 gtk_tree_path_free (path);
4363 view = gtk_tree_view_new_with_model (filter);
4364 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
4366 path = gtk_tree_path_new_from_indices (0, 0, -1);
4367 rowref = gtk_tree_row_reference_new (filter, path);
4368 gtk_tree_path_free (path);
4370 path = gtk_tree_path_new_from_indices (0, 0, -1);
4371 rowref = gtk_tree_row_reference_new (filter, path);
4372 gtk_tree_path_free (path);
4374 path = gtk_tree_path_new_from_indices (0, -1);
4375 rowref = gtk_tree_row_reference_new (filter, path);
4376 gtk_tree_path_free (path);
4378 /* Deleting the virtual root */
4379 path = gtk_tree_path_new_from_indices (3, 0, -1);
4380 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
4381 gtk_tree_store_remove (tree, &iter);
4382 gtk_tree_path_free (path);
4384 gtk_tree_row_reference_free (rowref);
4389 specific_bug_301558_sort_func (GtkTreeModel *model,
4396 gtk_tree_model_get (model, a, 0, &i, -1);
4397 gtk_tree_model_get (model, b, 0, &j, -1);
4403 specific_bug_301558 (void)
4405 /* Test case for GNOME Bugzilla bug 301558 provided by
4409 GtkTreeModel *filter;
4411 GtkTreeIter root, iter, iter2;
4412 GtkWidget *view G_GNUC_UNUSED;
4416 g_test_bug ("301558");
4418 tree = gtk_tree_store_new (2, G_TYPE_INT, G_TYPE_BOOLEAN);
4419 gtk_tree_store_append (tree, &iter, NULL);
4420 gtk_tree_store_set (tree, &iter, 0, 123, 1, TRUE, -1);
4421 gtk_tree_store_append (tree, &iter2, &iter);
4422 gtk_tree_store_set (tree, &iter2, 0, 73, 1, TRUE, -1);
4424 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
4425 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
4426 specific_bug_301558_sort_func,
4429 filter = gtk_tree_model_filter_new (sort, NULL);
4430 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter), 1);
4432 view = gtk_tree_view_new_with_model (filter);
4434 while (gtk_events_pending ())
4435 gtk_main_iteration ();
4439 for (i = 0; i < 10; i++)
4441 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tree), &root))
4442 g_assert_not_reached ();
4446 gtk_tree_store_append (tree, &iter, &root);
4447 gtk_tree_store_set (tree, &iter, 0, 456, 1, TRUE, -1);
4452 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tree), &root);
4453 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tree), &iter,
4455 gtk_tree_store_remove (tree, &iter);
4464 specific_bug_311955_filter_func (GtkTreeModel *model,
4470 gtk_tree_model_get (model, iter, 0, &value, -1);
4472 return (value != 0);
4476 specific_bug_311955 (void)
4478 /* This is a test case for GNOME Bugzilla bug 311955. It was written
4481 GtkTreeIter iter, child, root;
4482 GtkTreeStore *store;
4484 GtkTreeModel *filter;
4486 GtkWidget *window G_GNUC_UNUSED;
4487 GtkWidget *tree_view;
4492 g_test_bug ("311955");
4494 store = gtk_tree_store_new (1, G_TYPE_INT);
4496 gtk_tree_store_append (store, &root, NULL);
4497 gtk_tree_store_set (store, &root, 0, 33, -1);
4499 gtk_tree_store_append (store, &iter, &root);
4500 gtk_tree_store_set (store, &iter, 0, 50, -1);
4502 gtk_tree_store_append (store, &iter, NULL);
4503 gtk_tree_store_set (store, &iter, 0, 22, -1);
4505 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
4506 filter = gtk_tree_model_filter_new (sort, NULL);
4508 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4509 specific_bug_311955_filter_func,
4512 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4513 tree_view = gtk_tree_view_new_with_model (filter);
4514 g_object_unref (store);
4516 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4518 while (gtk_events_pending ())
4519 gtk_main_iteration ();
4521 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
4522 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
4525 for (i = 0; i < 4; i++)
4527 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
4529 gtk_tree_store_append (store, &iter, &root);
4532 gtk_tree_store_set (store, &iter, 0, i, -1);
4536 gtk_tree_store_append (store, &child, &iter);
4537 gtk_tree_store_set (store, &child, 0, 10, -1);
4541 while (gtk_events_pending ())
4542 gtk_main_iteration ();
4544 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
4545 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 1);
4547 /* Remove bottommost child from the tree. */
4548 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
4549 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), &root);
4551 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter, &root, n - 2))
4553 if (gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &child, &iter))
4554 gtk_tree_store_remove (store, &child);
4557 g_assert_not_reached ();
4559 path = gtk_tree_path_new_from_indices (0, 2, -1);
4560 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
4561 gtk_tree_path_free (path);
4563 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
4564 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
4568 specific_bug_311955_clean (void)
4570 /* Cleaned up version of the test case for GNOME Bugzilla bug 311955,
4571 * which is easier to understand.
4573 GtkTreeIter iter, child, grandchild;
4574 GtkTreeStore *store;
4576 GtkTreeModel *filter;
4578 GtkWidget *tree_view;
4581 store = gtk_tree_store_new (1, G_TYPE_INT);
4583 gtk_tree_store_append (store, &iter, NULL);
4584 gtk_tree_store_set (store, &iter, 0, 1, -1);
4586 gtk_tree_store_append (store, &child, &iter);
4587 gtk_tree_store_set (store, &child, 0, 1, -1);
4589 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
4590 filter = gtk_tree_model_filter_new (sort, NULL);
4592 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4593 specific_bug_311955_filter_func,
4596 tree_view = gtk_tree_view_new_with_model (filter);
4597 g_object_unref (store);
4599 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4601 while (gtk_events_pending ())
4602 gtk_main_iteration ();
4604 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
4605 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
4607 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
4609 gtk_tree_store_append (store, &child, &iter);
4610 gtk_tree_store_set (store, &child, 0, 0, -1);
4612 gtk_tree_store_append (store, &child, &iter);
4613 gtk_tree_store_set (store, &child, 0, 1, -1);
4615 gtk_tree_store_append (store, &child, &iter);
4616 gtk_tree_store_set (store, &child, 0, 1, -1);
4618 gtk_tree_store_append (store, &grandchild, &child);
4619 gtk_tree_store_set (store, &grandchild, 0, 1, -1);
4621 gtk_tree_store_append (store, &child, &iter);
4622 /* Don't set a value: assume 0 */
4624 /* Remove leaf node, check trigger row-has-child-toggled */
4625 path = gtk_tree_path_new_from_indices (0, 3, 0, -1);
4626 gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
4627 gtk_tree_path_free (path);
4628 gtk_tree_store_remove (store, &iter);
4630 path = gtk_tree_path_new_from_indices (0, 2, -1);
4631 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
4632 gtk_tree_path_free (path);
4634 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
4635 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
4637 gtk_widget_destroy (tree_view);
4641 specific_bug_346800 (void)
4643 /* This is a test case for GNOME Bugzilla bug 346800. It was written
4644 * by Jonathan Matthew.
4647 GtkTreeIter node_iters[50];
4648 GtkTreeIter child_iters[50];
4649 GtkTreeModel *model;
4650 GtkTreeModelFilter *filter;
4651 GtkTreeStore *store;
4655 columns = g_new (GType, 2);
4656 columns[0] = G_TYPE_STRING;
4657 columns[1] = G_TYPE_BOOLEAN;
4658 store = gtk_tree_store_newv (2, columns);
4659 model = GTK_TREE_MODEL (store);
4661 g_test_bug ("346800");
4663 filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
4664 gtk_tree_model_filter_set_visible_column (filter, 1);
4666 for (i=0; i<items; i++)
4668 /* allocate random amounts of junk, otherwise the filter model's arrays can expand without moving */
4671 gtk_tree_store_append (store, &node_iters[i], NULL);
4672 gtk_tree_store_set (store, &node_iters[i],
4674 1, ((i%6) == 0) ? FALSE : TRUE,
4678 gtk_tree_store_append (store, &child_iters[i], &node_iters[i]);
4679 gtk_tree_store_set (store, &child_iters[i],
4680 0, "something else",
4683 gtk_tree_model_filter_refilter (filter);
4687 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-1], 1,
4688 (i & 1) ? TRUE : FALSE, -1);
4689 gtk_tree_model_filter_refilter (filter);
4691 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-2], 1,
4692 (i & 1) ? FALSE: TRUE, -1);
4693 gtk_tree_model_filter_refilter (filter);
4699 specific_bug_464173_visible_func (GtkTreeModel *model,
4703 gboolean *visible = (gboolean *)data;
4709 specific_bug_464173 (void)
4711 /* Test case for GNOME Bugzilla bug 464173, test case written
4712 * by Andreas Koehler.
4714 GtkTreeStore *model;
4715 GtkTreeModelFilter *f_model;
4716 GtkTreeIter iter1, iter2;
4717 GtkWidget *view G_GNUC_UNUSED;
4718 gboolean visible = TRUE;
4720 g_test_bug ("464173");
4722 model = gtk_tree_store_new (1, G_TYPE_STRING);
4723 gtk_tree_store_append (model, &iter1, NULL);
4724 gtk_tree_store_set (model, &iter1, 0, "Foo", -1);
4725 gtk_tree_store_append (model, &iter2, &iter1);
4726 gtk_tree_store_set (model, &iter2, 0, "Bar", -1);
4728 f_model = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL(model), NULL));
4729 gtk_tree_model_filter_set_visible_func (f_model,
4730 specific_bug_464173_visible_func,
4733 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (f_model));
4736 gtk_tree_model_filter_refilter (f_model);
4741 specific_bug_540201_filter_func (GtkTreeModel *model,
4745 gboolean has_children;
4747 has_children = gtk_tree_model_iter_has_child (model, iter);
4749 return has_children;
4753 specific_bug_540201 (void)
4755 /* Test case for GNOME Bugzilla bug 540201, steps provided by
4758 GtkTreeIter iter, root;
4759 GtkTreeStore *store;
4760 GtkTreeModel *filter;
4762 GtkWidget *tree_view G_GNUC_UNUSED;
4764 g_test_bug ("540201");
4766 store = gtk_tree_store_new (1, G_TYPE_INT);
4768 gtk_tree_store_append (store, &root, NULL);
4769 gtk_tree_store_set (store, &root, 0, 33, -1);
4771 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4772 tree_view = gtk_tree_view_new_with_model (filter);
4774 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4775 specific_bug_540201_filter_func,
4778 gtk_tree_store_append (store, &iter, &root);
4779 gtk_tree_store_set (store, &iter, 0, 50, -1);
4781 gtk_tree_store_append (store, &iter, &root);
4782 gtk_tree_store_set (store, &iter, 0, 22, -1);
4785 gtk_tree_store_append (store, &root, NULL);
4786 gtk_tree_store_set (store, &root, 0, 33, -1);
4788 gtk_tree_store_append (store, &iter, &root);
4789 gtk_tree_store_set (store, &iter, 0, 22, -1);
4794 specific_bug_549287_visible_func (GtkTreeModel *model,
4798 gboolean result = FALSE;
4800 result = gtk_tree_model_iter_has_child (model, iter);
4806 specific_bug_549287 (void)
4808 /* Test case for GNOME Bugzilla bug 529287, provided by Julient Puydt */
4811 GtkTreeStore *store;
4812 GtkTreeModel *filtered;
4813 GtkWidget *view G_GNUC_UNUSED;
4815 GtkTreeIter *swap, *parent, *child;
4817 g_test_bug ("529287");
4819 store = gtk_tree_store_new (1, G_TYPE_STRING);
4820 filtered = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4821 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filtered),
4822 specific_bug_549287_visible_func,
4825 view = gtk_tree_view_new_with_model (filtered);
4827 for (i = 0; i < 4; i++)
4829 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
4831 parent = gtk_tree_iter_copy (&iter);
4832 child = gtk_tree_iter_copy (&iter);
4834 while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store),
4843 gtk_tree_store_append (store, child, parent);
4844 gtk_tree_store_set (store, child,
4848 gtk_tree_iter_free (parent);
4849 gtk_tree_iter_free (child);
4853 gtk_tree_store_append (store, &iter, NULL);
4854 gtk_tree_store_set (store, &iter,
4859 /* since we inserted something, we changed the visibility conditions: */
4860 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filtered));
4865 specific_bug_621076_visible_func (GtkTreeModel *model,
4869 gboolean visible = FALSE;
4872 gtk_tree_model_get (model, iter, 0, &str, -1);
4873 if (str != NULL && g_str_has_prefix (str, "visible"))
4879 GtkTreeIter child_iter;
4882 /* Recursively check if we have a visible child */
4883 for (valid = gtk_tree_model_iter_children (model, &child_iter, iter);
4884 valid; valid = gtk_tree_model_iter_next (model, &child_iter))
4886 if (specific_bug_621076_visible_func (model, &child_iter, data))
4901 specific_bug_621076 (void)
4903 /* Test case for GNOME Bugzilla bug 621076, provided by Xavier Claessens */
4905 /* This test case differs from has-child-filter and root-has-child-filter
4906 * in that the visible function both filters on content and model
4907 * structure. Also, it is recursive.
4910 GtkTreeStore *store;
4911 GtkTreeModel *filter;
4913 GtkTreeIter group_iter;
4914 GtkTreeIter item_iter;
4915 SignalMonitor *monitor;
4917 g_test_bug ("621076");
4919 store = gtk_tree_store_new (1, G_TYPE_STRING);
4920 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4921 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4922 specific_bug_621076_visible_func,
4925 view = gtk_tree_view_new_with_model (filter);
4926 g_object_ref_sink (view);
4928 monitor = signal_monitor_new (filter);
4930 signal_monitor_append_signal (monitor, ROW_INSERTED, "0");
4931 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
4932 0, "visible-group-0",
4934 signal_monitor_assert_is_empty (monitor);
4936 /* visible-group-0 is not expanded, so ROW_INSERTED should not be emitted
4937 * for its children. However, ROW_HAS_CHILD_TOGGLED should be emitted on
4938 * visible-group-0 to tell the view that row can be expanded. */
4939 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
4940 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
4941 group_iter = item_iter;
4942 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
4945 signal_monitor_assert_is_empty (monitor);
4947 signal_monitor_append_signal (monitor, ROW_INSERTED, "1");
4948 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
4949 0, "visible-group-1",
4951 signal_monitor_assert_is_empty (monitor);
4953 /* We are adding an hidden item inside visible-group-1, so
4954 * ROW_HAS_CHILD_TOGGLED should not be emitted. It is emitted though,
4955 * because the signal originating at TreeStore will be propagated,
4956 * as well a generated signal because the state of the parent *could*
4957 * change by a change in the model.
4959 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
4960 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
4961 group_iter = item_iter;
4962 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
4965 signal_monitor_assert_is_empty (monitor);
4967 /* This group is invisible and its parent too. Nothing should be emitted */
4968 group_iter = item_iter;
4969 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
4972 signal_monitor_assert_is_empty (monitor);
4974 /* Adding a visible item in this group hierarchy will make all nodes
4975 * in this path visible. The first level should simply tell the view
4976 * that it now has a child, and the view will load the tree if needed
4977 * (depends on the expanded state).
4979 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
4980 group_iter = item_iter;
4981 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
4982 0, "visible-1:0:0:0",
4984 signal_monitor_assert_is_empty (monitor);
4986 check_level_length (GTK_TREE_MODEL_FILTER (filter), "1", 1);
4988 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
4991 signal_monitor_assert_is_empty (monitor);
4993 /* Parent is invisible, and adding this invisible item won't change that,
4994 * so no signal should be emitted. */
4995 group_iter = item_iter;
4996 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
4999 signal_monitor_assert_is_empty (monitor);
5001 /* This makes group-2 visible, so it gets inserted and tells it has
5004 signal_monitor_append_signal (monitor, ROW_INSERTED, "2");
5005 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
5006 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
5009 signal_monitor_assert_is_empty (monitor);
5011 /* group-2 is already visible, so this time it is a normal insertion */
5012 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
5015 signal_monitor_assert_is_empty (monitor);
5018 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
5021 signal_monitor_assert_is_empty (monitor);
5023 /* Parent is invisible, and adding this invisible item won't change that,
5024 * so no signal should be emitted. */
5025 group_iter = item_iter;
5026 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
5029 signal_monitor_assert_is_empty (monitor);
5031 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
5034 signal_monitor_assert_is_empty (monitor);
5036 /* This will make group 3 visible. */
5037 signal_monitor_append_signal (monitor, ROW_INSERTED, "3");
5038 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
5039 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
5040 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
5041 signal_monitor_assert_is_empty (monitor);
5043 /* Make sure all groups are expanded, so the filter has the tree cached */
5044 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5045 while (gtk_events_pending ())
5046 gtk_main_iteration ();
5048 /* Should only yield a row-changed */
5049 signal_monitor_append_signal (monitor, ROW_CHANGED, "3:0");
5050 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
5051 signal_monitor_assert_is_empty (monitor);
5053 /* Now remove/hide some items. If a group loses its last item, the group
5054 * should be deleted instead of the item.
5057 signal_monitor_append_signal (monitor, ROW_DELETED, "2:1");
5058 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:2");
5059 gtk_tree_store_remove (store, &item_iter);
5060 signal_monitor_assert_is_empty (monitor);
5062 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
5063 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
5064 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
5065 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:1");
5066 gtk_tree_store_set (store, &item_iter, 0, "invisible-2:1", -1);
5067 signal_monitor_assert_is_empty (monitor);
5069 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0:0:0");
5070 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1:0:0");
5071 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0");
5072 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
5073 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "1:0:0:0");
5074 gtk_tree_store_remove (store, &item_iter);
5075 signal_monitor_assert_is_empty (monitor);
5077 /* Hide a group using row-changed instead of row-deleted */
5078 /* Caution: group 2 is gone, so offsets of the signals have moved. */
5079 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
5080 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
5081 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
5082 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter,
5084 gtk_tree_store_set (store, &item_iter, 0, "invisible-3:1", -1);
5085 signal_monitor_assert_is_empty (monitor);
5090 GtkTreeViewColumn *col;
5092 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5094 col = gtk_tree_view_column_new_with_attributes ("foo",
5095 gtk_cell_renderer_text_new (),
5097 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
5099 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
5100 g_signal_connect (window, "delete-event",
5101 G_CALLBACK (gtk_widget_destroy), NULL);
5102 g_signal_connect (window, "destroy",
5103 G_CALLBACK (gtk_main_quit), NULL);
5105 gtk_container_add (GTK_CONTAINER (window), view);
5107 gtk_widget_show (view);
5108 gtk_widget_show (window);
5115 signal_monitor_free (monitor);
5116 g_object_unref (view);
5117 g_object_unref (store);
5118 g_object_unref (filter);
5124 register_filter_model_tests (void)
5126 g_test_add ("/TreeModelFilter/self/verify-test-suite",
5130 filter_test_teardown);
5132 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-1",
5133 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5135 verify_test_suite_vroot,
5136 filter_test_teardown);
5137 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-2",
5138 FilterTest, gtk_tree_path_new_from_indices (2, 3, -1),
5140 verify_test_suite_vroot,
5141 filter_test_teardown);
5144 g_test_add ("/TreeModelFilter/filled/hide-root-level",
5147 filled_hide_root_level,
5148 filter_test_teardown);
5149 g_test_add ("/TreeModelFilter/filled/hide-child-levels",
5152 filled_hide_child_levels,
5153 filter_test_teardown);
5154 g_test_add ("/TreeModelFilter/filled/hide-child-levels/root-expanded",
5157 filled_hide_child_levels_root_expanded,
5158 filter_test_teardown);
5160 g_test_add ("/TreeModelFilter/filled/hide-root-level/vroot",
5161 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5163 filled_vroot_hide_root_level,
5164 filter_test_teardown);
5165 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot",
5166 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5168 filled_vroot_hide_child_levels,
5169 filter_test_teardown);
5170 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot-root-expanded",
5171 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5173 filled_vroot_hide_child_levels_root_expanded,
5174 filter_test_teardown);
5177 g_test_add ("/TreeModelFilter/empty/show-nodes",
5179 filter_test_setup_empty,
5181 filter_test_teardown);
5182 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes",
5184 filter_test_setup_empty,
5185 empty_show_multiple_nodes,
5186 filter_test_teardown);
5188 g_test_add ("/TreeModelFilter/empty/show-nodes/vroot",
5189 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5190 filter_test_setup_empty,
5191 empty_vroot_show_nodes,
5192 filter_test_teardown);
5193 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes/vroot",
5194 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5195 filter_test_setup_empty,
5196 empty_vroot_show_multiple_nodes,
5197 filter_test_teardown);
5200 g_test_add ("/TreeModelFilter/unfiltered/hide-single",
5202 filter_test_setup_unfiltered,
5203 unfiltered_hide_single,
5204 filter_test_teardown);
5205 g_test_add ("/TreeModelFilter/unfiltered/hide-single/root-expanded",
5207 filter_test_setup_unfiltered_root_expanded,
5208 unfiltered_hide_single_root_expanded,
5209 filter_test_teardown);
5210 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child",
5212 filter_test_setup_unfiltered,
5213 unfiltered_hide_single_child,
5214 filter_test_teardown);
5215 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/root-expanded",
5217 filter_test_setup_unfiltered_root_expanded,
5218 unfiltered_hide_single_child_root_expanded,
5219 filter_test_teardown);
5220 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level",
5222 filter_test_setup_unfiltered,
5223 unfiltered_hide_single_multi_level,
5224 filter_test_teardown);
5225 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/root-expanded",
5227 filter_test_setup_unfiltered_root_expanded,
5228 unfiltered_hide_single_multi_level_root_expanded,
5229 filter_test_teardown);
5231 g_test_add ("/TreeModelFilter/unfiltered/hide-single/vroot",
5232 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5233 filter_test_setup_unfiltered,
5234 unfiltered_vroot_hide_single,
5235 filter_test_teardown);
5236 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot",
5237 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5238 filter_test_setup_unfiltered,
5239 unfiltered_vroot_hide_single_child,
5240 filter_test_teardown);
5241 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot/root-expanded",
5242 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5243 filter_test_setup_unfiltered_root_expanded,
5244 unfiltered_vroot_hide_single_child_root_expanded,
5245 filter_test_teardown);
5246 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot",
5247 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5248 filter_test_setup_unfiltered,
5249 unfiltered_vroot_hide_single_multi_level,
5250 filter_test_teardown);
5251 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot/root-expanded",
5252 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5253 filter_test_setup_unfiltered_root_expanded,
5254 unfiltered_vroot_hide_single_multi_level_root_expanded,
5255 filter_test_teardown);
5259 g_test_add ("/TreeModelFilter/unfiltered/show-single",
5261 filter_test_setup_empty_unfiltered,
5262 unfiltered_show_single,
5263 filter_test_teardown);
5264 g_test_add ("/TreeModelFilter/unfiltered/show-single-child",
5266 filter_test_setup_empty_unfiltered,
5267 unfiltered_show_single_child,
5268 filter_test_teardown);
5269 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/root-expanded",
5271 filter_test_setup_empty_unfiltered_root_expanded,
5272 unfiltered_show_single_child_root_expanded,
5273 filter_test_teardown);
5274 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level",
5276 filter_test_setup_empty_unfiltered,
5277 unfiltered_show_single_multi_level,
5278 filter_test_teardown);
5279 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/root-expanded",
5281 filter_test_setup_empty_unfiltered_root_expanded,
5282 unfiltered_show_single_multi_level_root_expanded,
5283 filter_test_teardown);
5285 g_test_add ("/TreeModelFilter/unfiltered/show-single/vroot",
5286 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5287 filter_test_setup_empty_unfiltered,
5288 unfiltered_vroot_show_single,
5289 filter_test_teardown);
5290 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot",
5291 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5292 filter_test_setup_empty_unfiltered,
5293 unfiltered_vroot_show_single_child,
5294 filter_test_teardown);
5295 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot/root-expanded",
5296 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5297 filter_test_setup_empty_unfiltered_root_expanded,
5298 unfiltered_vroot_show_single_child_root_expanded,
5299 filter_test_teardown);
5300 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot",
5301 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5302 filter_test_setup_empty_unfiltered,
5303 unfiltered_vroot_show_single_multi_level,
5304 filter_test_teardown);
5305 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot/root-expanded",
5306 FilterTest, gtk_tree_path_new_from_indices (2, -1),
5307 filter_test_setup_empty_unfiltered_root_expanded,
5308 unfiltered_vroot_show_single_multi_level_root_expanded,
5309 filter_test_teardown);
5312 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/root-level",
5314 filter_test_setup_unfiltered,
5315 unfiltered_rows_reordered_root_level,
5316 filter_test_teardown);
5317 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/child-level",
5319 filter_test_setup_unfiltered,
5320 unfiltered_rows_reordered_child_level,
5321 filter_test_teardown);
5323 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/first-hidden",
5326 filtered_rows_reordered_root_level_first_hidden,
5327 filter_test_teardown);
5328 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/middle-hidden",
5331 filtered_rows_reordered_root_level_middle_hidden,
5332 filter_test_teardown);
5333 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/first-hidden",
5336 filtered_rows_reordered_child_level_first_hidden,
5337 filter_test_teardown);
5338 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/middle-hidden",
5341 filtered_rows_reordered_child_level_middle_hidden,
5342 filter_test_teardown);
5343 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/4-hidden",
5346 filtered_rows_reordered_child_level_4_hidden,
5347 filter_test_teardown);
5348 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/all-hidden",
5351 filtered_rows_reordered_child_level_all_hidden,
5352 filter_test_teardown);
5354 /* Inserts in child models after creation of filter model */
5355 g_test_add_func ("/TreeModelFilter/insert/before",
5357 g_test_add_func ("/TreeModelFilter/insert/child",
5360 /* Removals from child model after creating of filter model */
5361 g_test_add_func ("/TreeModelFilter/remove/node",
5363 g_test_add_func ("/TreeModelFilter/remove/node-vroot",
5365 g_test_add_func ("/TreeModelFilter/remove/vroot-ancestor",
5366 remove_vroot_ancestor);
5368 /* Reference counting */
5369 g_test_add_func ("/TreeModelFilter/ref-count/single-level",
5370 ref_count_single_level);
5371 g_test_add_func ("/TreeModelFilter/ref-count/two-levels",
5372 ref_count_two_levels);
5373 g_test_add_func ("/TreeModelFilter/ref-count/three-levels",
5374 ref_count_three_levels);
5375 g_test_add_func ("/TreeModelFilter/ref-count/delete-row",
5376 ref_count_delete_row);
5377 g_test_add_func ("/TreeModelFilter/ref-count/cleanup",
5379 g_test_add_func ("/TreeModelFilter/ref-count/row-ref",
5382 /* Reference counting, transfer of first reference on
5383 * first node in level. This is a GtkTreeModelFilter-specific
5386 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/insert",
5387 ref_count_transfer_root_level_insert);
5388 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered",
5389 ref_count_transfer_root_level_reordered);
5390 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/insert",
5391 ref_count_transfer_child_level_insert);
5392 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered",
5393 ref_count_transfer_child_level_reordered);
5395 g_test_add_func ("/TreeModelFilter/specific/path-dependent-filter",
5396 specific_path_dependent_filter);
5397 g_test_add_func ("/TreeModelFilter/specific/append-after-collapse",
5398 specific_append_after_collapse);
5399 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-node",
5400 specific_sort_filter_remove_node);
5401 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-root",
5402 specific_sort_filter_remove_root);
5403 g_test_add_func ("/TreeModelFilter/specific/root-mixed-visibility",
5404 specific_root_mixed_visibility);
5405 g_test_add_func ("/TreeModelFilter/specific/has-child-filter",
5406 specific_has_child_filter);
5407 g_test_add_func ("/TreeModelFilter/specific/has-child-filter-on-sort-model",
5408 specific_has_child_filter_on_sort_model);
5409 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter",
5410 specific_at_least_2_children_filter);
5411 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter-on-sort-model",
5412 specific_at_least_2_children_filter_on_sort_model);
5413 g_test_add_func ("/TreeModelFilter/specific/root-has-child-filter",
5414 specific_root_has_child_filter);
5415 g_test_add_func ("/TreeModelFilter/specific/filter-add-child",
5416 specific_filter_add_child);
5417 g_test_add_func ("/TreeModelFilter/specific/list-store-clear",
5418 specific_list_store_clear);
5419 g_test_add_func ("/TreeModelFilter/specific/sort-ref-leaf-and-remove-ancestor",
5420 specific_sort_ref_leaf_and_remove_ancestor);
5421 g_test_add_func ("/TreeModelFilter/specific/ref-leaf-and-remove-ancestor",
5422 specific_ref_leaf_and_remove_ancestor);
5423 g_test_add_func ("/TreeModelFilter/specific/virtual-ref-leaf-and-remove-ancestor",
5424 specific_virtual_ref_leaf_and_remove_ancestor);
5426 g_test_add_func ("/TreeModelFilter/specific/bug-301558",
5427 specific_bug_301558);
5428 g_test_add_func ("/TreeModelFilter/specific/bug-311955",
5429 specific_bug_311955);
5430 g_test_add_func ("/TreeModelFilter/specific/bug-311955-clean",
5431 specific_bug_311955_clean);
5432 g_test_add_func ("/TreeModelFilter/specific/bug-346800",
5433 specific_bug_346800);
5434 g_test_add_func ("/TreeModelFilter/specific/bug-464173",
5435 specific_bug_464173);
5436 g_test_add_func ("/TreeModelFilter/specific/bug-540201",
5437 specific_bug_540201);
5438 g_test_add_func ("/TreeModelFilter/specific/bug-549287",
5439 specific_bug_549287);
5440 g_test_add_func ("/TreeModelFilter/specific/bug-621076",
5441 specific_bug_621076);