1 /* Extensive GtkTreeModelFilter tests.
2 * Copyright (C) 2009,2011 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "treemodel.h"
24 #include "gtktreemodelrefcount.h"
27 * - Proper coverage checking to see if the unit tests cover
29 * - Check if the iterator stamp is incremented at the correct times.
31 * For more thorough testing:
32 * - Test with randomized models.
33 * - Extensively test a filter model wrapping a sort model,
34 * or a sort model wrapping a filter model by:
35 * # Checking structure.
36 * # Checking for correct signals emissions.
37 * # Checking correct reference counting.
38 * # Tests should be done with the sort and filter model
39 * in various filtering and sorting states.
47 #define LEVEL_LENGTH 5
50 create_tree_store_set_values (GtkTreeStore *store,
57 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
58 path_string = gtk_tree_path_to_string (path);
60 gtk_tree_store_set (store, iter,
65 gtk_tree_path_free (path);
70 create_tree_store_recurse (int depth,
77 for (i = 0; i < LEVEL_LENGTH; i++)
81 gtk_tree_store_insert (store, &iter, parent, i);
82 create_tree_store_set_values (store, &iter, visible);
85 create_tree_store_recurse (depth - 1, store, &iter, visible);
90 create_tree_store (int depth,
95 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
97 create_tree_store_recurse (depth, store, NULL, visible);
108 GtkWidget *tree_view;
111 GtkTreeModelFilter *filter;
113 SignalMonitor *monitor;
115 guint block_signals : 1;
120 filter_test_store_signal (FilterTest *fixture)
122 if (fixture->block_signals)
123 g_signal_stop_emission_by_name (fixture->store, "row-changed");
128 filter_test_setup_generic (FilterTest *fixture,
129 gconstpointer test_data,
134 const GtkTreePath *vroot = test_data;
135 GtkTreeModel *filter;
137 fixture->store = create_tree_store (depth, !empty);
139 g_signal_connect_swapped (fixture->store, "row-changed",
140 G_CALLBACK (filter_test_store_signal), fixture);
142 /* Please forgive me for casting const away. */
143 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture->store),
144 (GtkTreePath *)vroot);
145 fixture->filter = GTK_TREE_MODEL_FILTER (filter);
148 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
150 /* We need a tree view that's listening to get ref counting from that
153 fixture->tree_view = gtk_tree_view_new_with_model (filter);
155 fixture->monitor = signal_monitor_new (filter);
159 filter_test_setup_expand_root (FilterTest *fixture)
164 path = gtk_tree_path_new_from_indices (0, -1);
166 for (i = 0; i < LEVEL_LENGTH; i++)
168 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view),
170 gtk_tree_path_next (path);
172 gtk_tree_path_free (path);
176 filter_test_setup (FilterTest *fixture,
177 gconstpointer test_data)
179 filter_test_setup_generic (fixture, test_data, 3, FALSE, FALSE);
183 filter_test_setup_empty (FilterTest *fixture,
184 gconstpointer test_data)
186 filter_test_setup_generic (fixture, test_data, 3, TRUE, FALSE);
190 filter_test_setup_unfiltered (FilterTest *fixture,
191 gconstpointer test_data)
193 filter_test_setup_generic (fixture, test_data, 3, FALSE, TRUE);
197 filter_test_setup_unfiltered_root_expanded (FilterTest *fixture,
198 gconstpointer test_data)
200 filter_test_setup_unfiltered (fixture, test_data);
201 filter_test_setup_expand_root (fixture);
205 filter_test_setup_empty_unfiltered (FilterTest *fixture,
206 gconstpointer test_data)
208 filter_test_setup_generic (fixture, test_data, 3, TRUE, TRUE);
212 filter_test_setup_empty_unfiltered_root_expanded (FilterTest *fixture,
213 gconstpointer test_data)
215 filter_test_setup_empty_unfiltered (fixture, test_data);
216 filter_test_setup_expand_root (fixture);
220 strip_virtual_root (GtkTreePath *path,
221 GtkTreePath *root_path)
223 GtkTreePath *real_path;
228 int depth = gtk_tree_path_get_depth (path);
229 int root_depth = gtk_tree_path_get_depth (root_path);
231 real_path = gtk_tree_path_new ();
233 for (j = 0; j < depth - root_depth; j++)
234 gtk_tree_path_append_index (real_path,
235 gtk_tree_path_get_indices (path)[root_depth + j]);
238 real_path = gtk_tree_path_copy (path);
244 count_visible (FilterTest *fixture,
245 GtkTreePath *store_path)
251 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
254 for (i = 0; i < LEVEL_LENGTH; i++)
258 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
270 filter_test_append_refilter_signals_recurse (FilterTest *fixture,
271 GtkTreePath *store_path,
272 GtkTreePath *filter_path,
274 GtkTreePath *root_path)
277 int rows_deleted = 0;
280 gtk_tree_path_down (store_path);
281 gtk_tree_path_down (filter_path);
283 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
286 for (i = 0; i < LEVEL_LENGTH; i++)
289 GtkTreePath *real_path;
291 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store), &iter,
296 (!gtk_tree_path_is_descendant (store_path, root_path)
297 || !gtk_tree_path_compare (store_path, root_path)))
299 if (!gtk_tree_path_compare (store_path, root_path))
302 && gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
305 GtkTreePath *store_copy;
306 GtkTreePath *filter_copy;
308 store_copy = gtk_tree_path_copy (store_path);
309 filter_copy = gtk_tree_path_copy (filter_path);
310 filter_test_append_refilter_signals_recurse (fixture,
315 gtk_tree_path_free (store_copy);
316 gtk_tree_path_free (filter_copy);
320 gtk_tree_path_next (store_path);
321 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
324 gtk_tree_path_next (filter_path);
329 real_path = strip_virtual_root (filter_path, root_path);
333 /* This row will be inserted */
334 signal_monitor_append_signal_path (fixture->monitor, ROW_CHANGED,
337 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store),
340 signal_monitor_append_signal_path (fixture->monitor,
341 ROW_HAS_CHILD_TOGGLED,
346 GtkTreePath *store_copy;
347 GtkTreePath *filter_copy;
349 store_copy = gtk_tree_path_copy (store_path);
350 filter_copy = gtk_tree_path_copy (filter_path);
351 filter_test_append_refilter_signals_recurse (fixture,
356 gtk_tree_path_free (store_copy);
357 gtk_tree_path_free (filter_copy);
361 GtkTreePath *tmp_path;
363 /* If all child rows are invisible, then the last row to
364 * become invisible will emit row-has-child-toggled on the
368 tmp_path = gtk_tree_path_copy (store_path);
369 gtk_tree_path_append_index (tmp_path, 0);
371 if (count_visible (fixture, tmp_path) == 0)
372 signal_monitor_append_signal_path (fixture->monitor,
373 ROW_HAS_CHILD_TOGGLED,
376 gtk_tree_path_free (tmp_path);
380 gtk_tree_path_next (filter_path);
384 /* This row will be deleted */
386 signal_monitor_append_signal_path (fixture->monitor, ROW_DELETED,
390 gtk_tree_path_free (real_path);
392 gtk_tree_path_next (store_path);
393 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
396 if (rows_deleted == LEVEL_LENGTH
397 && gtk_tree_path_get_depth (filter_path) > 1)
399 GtkTreePath *real_path;
401 gtk_tree_path_up (store_path);
402 gtk_tree_path_up (filter_path);
404 /* A row-has-child-toggled will be emitted on the parent */
407 && gtk_tree_path_is_descendant (store_path, root_path)
408 && gtk_tree_path_compare (store_path, root_path)))
410 real_path = strip_virtual_root (filter_path, root_path);
411 signal_monitor_append_signal_path (fixture->monitor,
412 ROW_HAS_CHILD_TOGGLED,
415 gtk_tree_path_free (real_path);
421 filter_test_append_refilter_signals (FilterTest *fixture,
424 /* A special function that walks the tree store like the
425 * model validation functions below.
428 GtkTreePath *filter_path;
430 path = gtk_tree_path_new ();
431 filter_path = gtk_tree_path_new ();
432 filter_test_append_refilter_signals_recurse (fixture,
437 gtk_tree_path_free (path);
438 gtk_tree_path_free (filter_path);
442 filter_test_append_refilter_signals_with_vroot (FilterTest *fixture,
444 GtkTreePath *root_path)
446 /* A special function that walks the tree store like the
447 * model validation functions below.
450 GtkTreePath *filter_path;
452 path = gtk_tree_path_new ();
453 filter_path = gtk_tree_path_new ();
454 filter_test_append_refilter_signals_recurse (fixture,
459 gtk_tree_path_free (path);
460 gtk_tree_path_free (filter_path);
464 filter_test_enable_filter (FilterTest *fixture)
466 gtk_tree_model_filter_set_visible_column (fixture->filter, 1);
467 gtk_tree_model_filter_refilter (fixture->filter);
471 filter_test_block_signals (FilterTest *fixture)
473 fixture->block_signals = TRUE;
477 filter_test_unblock_signals (FilterTest *fixture)
479 fixture->block_signals = FALSE;
483 filter_test_teardown (FilterTest *fixture,
484 gconstpointer test_data)
486 signal_monitor_free (fixture->monitor);
488 gtk_widget_destroy (fixture->tree_view);
490 g_object_unref (fixture->filter);
491 g_object_unref (fixture->store);
495 * Model structure validation
499 check_filter_model_recurse (FilterTest *fixture,
500 GtkTreePath *store_parent_path,
501 GtkTreePath *filter_parent_path)
504 GtkTreeIter store_iter;
505 GtkTreeIter filter_iter;
506 gboolean store_has_next, filter_has_next;
508 gtk_tree_path_down (store_parent_path);
509 gtk_tree_path_down (filter_parent_path);
511 store_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
512 &store_iter, store_parent_path);
513 filter_has_next = gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->filter),
514 &filter_iter, filter_parent_path);
516 for (i = 0; i < LEVEL_LENGTH; i++)
520 g_return_if_fail (store_has_next == TRUE);
522 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
530 gchar *filter_str, *store_str;
532 g_return_if_fail (filter_has_next == TRUE);
535 tmp = gtk_tree_model_get_path (GTK_TREE_MODEL (fixture->filter),
537 g_return_if_fail (gtk_tree_path_compare (tmp, filter_parent_path) == 0);
539 /* Verify model content */
540 gtk_tree_model_get (GTK_TREE_MODEL (fixture->store),
544 gtk_tree_model_get (GTK_TREE_MODEL (fixture->filter),
549 g_return_if_fail (g_strcmp0 (store_str, filter_str) == 0);
554 if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->filter),
557 g_return_if_fail (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (fixture->store), &store_iter));
559 check_filter_model_recurse (fixture,
560 gtk_tree_path_copy (store_parent_path),
564 /* Only when we do not recurse we need to free tmp */
565 gtk_tree_path_free (tmp);
567 gtk_tree_path_next (filter_parent_path);
568 filter_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->filter), &filter_iter);
571 gtk_tree_path_next (store_parent_path);
572 store_has_next = gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &store_iter);
575 /* Both models should have no more content! */
576 g_return_if_fail (store_has_next == FALSE);
577 g_return_if_fail (filter_has_next == FALSE);
579 gtk_tree_path_free (store_parent_path);
580 gtk_tree_path_free (filter_parent_path);
584 check_filter_model (FilterTest *fixture)
588 if (fixture->monitor)
589 signal_monitor_assert_is_empty (fixture->monitor);
591 path = gtk_tree_path_new ();
593 check_filter_model_recurse (fixture, path, gtk_tree_path_copy (path));
597 check_filter_model_with_root (FilterTest *fixture,
600 if (fixture->monitor)
601 signal_monitor_assert_is_empty (fixture->monitor);
603 check_filter_model_recurse (fixture,
604 gtk_tree_path_copy (path),
605 gtk_tree_path_new ());
611 check_level_length (GtkTreeModelFilter *filter,
613 const int expected_length)
619 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), NULL);
620 g_assert_cmpint (model_length, ==, expected_length);
625 gboolean retrieved_iter = FALSE;
628 retrieved_iter = gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (filter),
630 g_return_if_fail (retrieved_iter);
631 model_length = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (filter), &iter);
632 g_assert_cmpint (model_length, ==, expected_length);
637 set_path_visibility (FilterTest *fixture,
641 GtkTreeIter store_iter;
643 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
645 gtk_tree_store_set (fixture->store, &store_iter,
652 insert_path_with_visibility (FilterTest *fixture,
653 const gchar *path_string,
658 GtkTreeIter parent, iter;
660 path = gtk_tree_path_new_from_string (path_string);
661 position = gtk_tree_path_get_indices (path)[gtk_tree_path_get_depth (path)];
662 gtk_tree_path_up (path);
664 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store), &parent, path))
666 gtk_tree_store_insert (fixture->store, &iter, &parent, position);
667 create_tree_store_set_values (fixture->store, &iter, visible);
669 gtk_tree_path_free (path);
678 verify_test_suite (FilterTest *fixture,
679 gconstpointer user_data)
681 check_filter_model (fixture);
685 verify_test_suite_vroot (FilterTest *fixture,
686 gconstpointer user_data)
688 check_filter_model_with_root (fixture, (GtkTreePath *)user_data);
693 filled_hide_root_level (FilterTest *fixture,
694 gconstpointer user_data)
696 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
697 set_path_visibility (fixture, "2", FALSE);
698 check_filter_model (fixture);
699 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
701 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
702 set_path_visibility (fixture, "0", FALSE);
703 check_filter_model (fixture);
704 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
706 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
707 set_path_visibility (fixture, "4", FALSE);
708 check_filter_model (fixture);
709 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
713 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
714 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
716 set_path_visibility (fixture, "1", FALSE);
717 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
719 set_path_visibility (fixture, "3", FALSE);
720 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 5);
722 check_filter_model (fixture);
725 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
726 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
727 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
728 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
730 set_path_visibility (fixture, "1", TRUE);
731 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
733 set_path_visibility (fixture, "3", TRUE);
734 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 3);
736 check_filter_model (fixture);
740 filled_hide_child_levels (FilterTest *fixture,
741 gconstpointer user_data)
743 set_path_visibility (fixture, "0:2", FALSE);
744 check_filter_model (fixture);
745 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
746 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
748 set_path_visibility (fixture, "0:4", FALSE);
749 check_filter_model (fixture);
750 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
751 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
753 set_path_visibility (fixture, "0:4:3", FALSE);
754 check_filter_model (fixture);
755 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
756 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
758 set_path_visibility (fixture, "0:4:0", FALSE);
759 set_path_visibility (fixture, "0:4:1", FALSE);
760 set_path_visibility (fixture, "0:4:2", FALSE);
761 set_path_visibility (fixture, "0:4:4", FALSE);
762 check_filter_model (fixture);
763 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
764 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
766 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
767 set_path_visibility (fixture, "0:4", TRUE);
768 check_filter_model (fixture);
769 check_level_length (fixture->filter, "0:3", 0);
771 set_path_visibility (fixture, "0:2", TRUE);
772 check_filter_model (fixture);
773 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
774 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
775 check_level_length (fixture->filter, "0:4", 0);
777 /* Once 0:4:0 got inserted, 0:4 became a parent. Because 0:4 is
778 * not visible, not signals are emitted.
780 set_path_visibility (fixture, "0:4:2", TRUE);
781 set_path_visibility (fixture, "0:4:4", TRUE);
782 signal_monitor_assert_is_empty (fixture->monitor);
783 check_level_length (fixture->filter, "0:4", 2);
787 filled_hide_child_levels_root_expanded (FilterTest *fixture,
788 gconstpointer user_data)
792 path = gtk_tree_path_new_from_indices (0, -1);
793 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
794 gtk_tree_path_free (path);
796 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
797 set_path_visibility (fixture, "0:2", FALSE);
798 check_filter_model (fixture);
799 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
800 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
802 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
803 set_path_visibility (fixture, "0:4", FALSE);
804 check_filter_model (fixture);
805 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
806 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
808 set_path_visibility (fixture, "0:4:3", FALSE);
809 check_filter_model (fixture);
810 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
811 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
813 set_path_visibility (fixture, "0:4:0", FALSE);
814 set_path_visibility (fixture, "0:4:1", FALSE);
815 set_path_visibility (fixture, "0:4:2", FALSE);
816 set_path_visibility (fixture, "0:4:4", FALSE);
817 check_filter_model (fixture);
818 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
819 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
821 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
822 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
823 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
824 set_path_visibility (fixture, "0:4", TRUE);
825 check_filter_model (fixture);
826 check_level_length (fixture->filter, "0:3", 0);
828 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
829 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
830 set_path_visibility (fixture, "0:2", TRUE);
831 check_filter_model (fixture);
832 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
833 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
834 check_level_length (fixture->filter, "0:4", 0);
836 /* has-child-toggled for 0:4 is required. */
837 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
838 set_path_visibility (fixture, "0:4:2", TRUE);
839 set_path_visibility (fixture, "0:4:4", TRUE);
840 signal_monitor_assert_is_empty (fixture->monitor);
841 check_level_length (fixture->filter, "0:4", 2);
846 filled_vroot_hide_root_level (FilterTest *fixture,
847 gconstpointer user_data)
849 GtkTreePath *path = (GtkTreePath *)user_data;
851 /* These changes do not affect the filter's root level */
852 set_path_visibility (fixture, "0", FALSE);
853 check_filter_model_with_root (fixture, path);
854 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
855 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
857 set_path_visibility (fixture, "4", FALSE);
858 check_filter_model_with_root (fixture, path);
859 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
860 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
862 /* Even though we set the virtual root parent node to FALSE,
863 * the virtual root contents remain.
865 set_path_visibility (fixture, "2", FALSE);
866 check_filter_model_with_root (fixture, path);
867 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
868 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
871 set_path_visibility (fixture, "1", FALSE);
872 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
873 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
875 set_path_visibility (fixture, "3", FALSE);
876 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
877 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
879 check_filter_model_with_root (fixture, path);
882 set_path_visibility (fixture, "2", TRUE);
883 check_filter_model_with_root (fixture, path);
884 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
885 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
887 set_path_visibility (fixture, "1", TRUE);
888 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
889 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
891 set_path_visibility (fixture, "3", TRUE);
892 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
893 check_level_length (fixture->filter, "0", LEVEL_LENGTH);
895 check_filter_model_with_root (fixture, path);
897 /* Now test changes in the virtual root level */
898 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "2");
899 set_path_visibility (fixture, "2:2", FALSE);
900 check_filter_model_with_root (fixture, path);
901 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
903 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "3");
904 set_path_visibility (fixture, "2:4", FALSE);
905 check_filter_model_with_root (fixture, path);
906 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
908 set_path_visibility (fixture, "1:4", FALSE);
909 check_filter_model_with_root (fixture, path);
910 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
912 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "3");
913 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "3");
914 set_path_visibility (fixture, "2:4", TRUE);
915 check_filter_model_with_root (fixture, path);
916 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
918 set_path_visibility (fixture, "2", FALSE);
919 check_filter_model_with_root (fixture, path);
920 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
922 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
923 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
924 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
925 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
926 set_path_visibility (fixture, "2:0", FALSE);
927 set_path_visibility (fixture, "2:1", FALSE);
928 set_path_visibility (fixture, "2:2", FALSE);
929 set_path_visibility (fixture, "2:3", FALSE);
930 set_path_visibility (fixture, "2:4", FALSE);
931 check_filter_model_with_root (fixture, path);
932 check_level_length (fixture->filter, NULL, 0);
934 set_path_visibility (fixture, "2", TRUE);
935 check_filter_model_with_root (fixture, path);
936 check_level_length (fixture->filter, NULL, 0);
938 set_path_visibility (fixture, "1:4", FALSE);
939 check_filter_model_with_root (fixture, path);
940 check_level_length (fixture->filter, NULL, 0);
942 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
943 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
944 set_path_visibility (fixture, "2:4", TRUE);
945 check_filter_model_with_root (fixture, path);
946 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 4);
948 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
949 set_path_visibility (fixture, "2:4", FALSE);
950 check_filter_model_with_root (fixture, path);
951 check_level_length (fixture->filter, NULL, 0);
953 set_path_visibility (fixture, "2", FALSE);
954 check_filter_model_with_root (fixture, path);
955 check_level_length (fixture->filter, NULL, 0);
957 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
958 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
959 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
960 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
961 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2");
962 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
963 set_path_visibility (fixture, "2:0", TRUE);
964 set_path_visibility (fixture, "2:1", TRUE);
965 set_path_visibility (fixture, "2:2", TRUE);
966 check_filter_model_with_root (fixture, path);
967 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
969 set_path_visibility (fixture, "2", TRUE);
970 check_filter_model_with_root (fixture, path);
971 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 2);
975 filled_vroot_hide_child_levels (FilterTest *fixture,
976 gconstpointer user_data)
978 GtkTreePath *path = (GtkTreePath *)user_data;
980 set_path_visibility (fixture, "2:0:2", FALSE);
981 check_filter_model_with_root (fixture, path);
982 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
983 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
985 set_path_visibility (fixture, "2:0:4", FALSE);
986 check_filter_model_with_root (fixture, path);
987 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
988 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
990 set_path_visibility (fixture, "2:0:4:3", FALSE);
991 check_filter_model_with_root (fixture, path);
992 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
993 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
995 set_path_visibility (fixture, "2:0:4:0", FALSE);
996 set_path_visibility (fixture, "2:0:4:1", FALSE);
997 set_path_visibility (fixture, "2:0:4:2", FALSE);
998 set_path_visibility (fixture, "2:0:4:4", FALSE);
999 check_filter_model_with_root (fixture, path);
1000 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1001 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1003 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
1004 set_path_visibility (fixture, "2:0:4", TRUE);
1005 check_filter_model_with_root (fixture, path);
1006 check_level_length (fixture->filter, "0:3", 0);
1008 set_path_visibility (fixture, "2:0:2", TRUE);
1009 check_filter_model_with_root (fixture, path);
1010 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1011 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1012 check_level_length (fixture->filter, "0:4", 0);
1014 /* Once 0:4:0 got inserted, 0:4 became a parent. However, 0:4 is not
1015 * visible, so no signal should be emitted.
1017 set_path_visibility (fixture, "2:0:4:2", TRUE);
1018 set_path_visibility (fixture, "2:0:4:4", TRUE);
1019 check_level_length (fixture->filter, "0:4", 2);
1020 signal_monitor_assert_is_empty (fixture->monitor);
1024 filled_vroot_hide_child_levels_root_expanded (FilterTest *fixture,
1025 gconstpointer user_data)
1027 GtkTreePath *path = (GtkTreePath *)user_data;
1028 GtkTreePath *tmp_path;
1030 tmp_path = gtk_tree_path_new_from_indices (0, -1);
1031 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), tmp_path, FALSE);
1032 gtk_tree_path_free (tmp_path);
1034 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:2");
1035 set_path_visibility (fixture, "2:0:2", FALSE);
1036 check_filter_model_with_root (fixture, path);
1037 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1038 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 1);
1040 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0:3");
1041 set_path_visibility (fixture, "2:0:4", FALSE);
1042 check_filter_model_with_root (fixture, path);
1043 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1044 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1046 set_path_visibility (fixture, "2:0:4:3", FALSE);
1047 check_filter_model_with_root (fixture, path);
1048 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1049 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1051 set_path_visibility (fixture, "2:0:4:0", FALSE);
1052 set_path_visibility (fixture, "2:0:4:1", FALSE);
1053 set_path_visibility (fixture, "2:0:4:2", FALSE);
1054 set_path_visibility (fixture, "2:0:4:4", FALSE);
1055 check_filter_model_with_root (fixture, path);
1056 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1057 check_level_length (fixture->filter, "0", LEVEL_LENGTH - 2);
1059 /* Since "0:2" is hidden, "0:4" must be "0:3" in the filter model */
1060 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:3");
1061 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:3");
1062 set_path_visibility (fixture, "2:0:4", TRUE);
1063 check_filter_model_with_root (fixture, path);
1064 check_level_length (fixture->filter, "0:3", 0);
1066 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0:2");
1067 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:2");
1068 set_path_visibility (fixture, "2:0:2", TRUE);
1069 check_filter_model_with_root (fixture, path);
1070 check_level_length (fixture->filter, "0:2", LEVEL_LENGTH);
1071 check_level_length (fixture->filter, "0:3", LEVEL_LENGTH);
1072 check_level_length (fixture->filter, "0:4", 0);
1074 /* Once 0:4:0 got inserted, 0:4 became a parent */
1075 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0:4");
1076 set_path_visibility (fixture, "2:0:4:2", TRUE);
1077 set_path_visibility (fixture, "2:0:4:4", TRUE);
1078 check_level_length (fixture->filter, "0:4", 2);
1079 signal_monitor_assert_is_empty (fixture->monitor);
1083 empty_show_nodes (FilterTest *fixture,
1084 gconstpointer user_data)
1086 check_filter_model (fixture);
1087 check_level_length (fixture->filter, NULL, 0);
1089 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1090 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1091 set_path_visibility (fixture, "3", TRUE);
1092 check_filter_model (fixture);
1093 check_level_length (fixture->filter, NULL, 1);
1094 check_level_length (fixture->filter, "0", 0);
1096 set_path_visibility (fixture, "3:2:2", TRUE);
1097 check_filter_model (fixture);
1098 check_level_length (fixture->filter, NULL, 1);
1099 check_level_length (fixture->filter, "0", 0);
1101 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1102 set_path_visibility (fixture, "3:2", TRUE);
1103 check_filter_model (fixture);
1104 check_level_length (fixture->filter, NULL, 1);
1105 check_level_length (fixture->filter, "0", 1);
1106 check_level_length (fixture->filter, "0:0", 1);
1107 check_level_length (fixture->filter, "0:0:0", 0);
1109 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1110 set_path_visibility (fixture, "3", FALSE);
1111 check_filter_model (fixture);
1112 check_level_length (fixture->filter, NULL, 0);
1114 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1115 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1116 set_path_visibility (fixture, "3:2:1", TRUE);
1117 set_path_visibility (fixture, "3", TRUE);
1118 check_filter_model (fixture);
1119 check_level_length (fixture->filter, NULL, 1);
1120 check_level_length (fixture->filter, "0", 1);
1121 check_level_length (fixture->filter, "0:0", 2);
1122 check_level_length (fixture->filter, "0:0:0", 0);
1126 empty_show_multiple_nodes (FilterTest *fixture,
1127 gconstpointer user_data)
1130 GtkTreePath *changed_path;
1132 check_filter_model (fixture);
1133 check_level_length (fixture->filter, NULL, 0);
1135 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1136 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1137 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1138 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1140 /* We simulate a change in visible func condition with this. The
1141 * visibility state of multiple nodes changes at once, we emit row-changed
1142 * for these nodes (and others) after that.
1144 filter_test_block_signals (fixture);
1145 set_path_visibility (fixture, "3", TRUE);
1146 set_path_visibility (fixture, "4", TRUE);
1147 filter_test_unblock_signals (fixture);
1149 changed_path = gtk_tree_path_new ();
1150 gtk_tree_path_append_index (changed_path, 2);
1151 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1152 &iter, changed_path);
1153 /* Invisible node - so no signals expected */
1154 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1155 changed_path, &iter);
1157 gtk_tree_path_next (changed_path);
1158 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1159 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1160 changed_path, &iter);
1162 gtk_tree_path_next (changed_path);
1163 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1164 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1165 changed_path, &iter);
1167 gtk_tree_path_free (changed_path);
1169 check_filter_model (fixture);
1170 check_level_length (fixture->filter, NULL, 2);
1171 check_level_length (fixture->filter, "0", 0);
1173 set_path_visibility (fixture, "3:2:2", TRUE);
1174 check_filter_model (fixture);
1175 check_level_length (fixture->filter, NULL, 2);
1176 check_level_length (fixture->filter, "0", 0);
1178 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1179 set_path_visibility (fixture, "3:2", TRUE);
1180 check_filter_model (fixture);
1181 check_level_length (fixture->filter, NULL, 2);
1182 check_level_length (fixture->filter, "0", 1);
1183 check_level_length (fixture->filter, "0:0", 1);
1184 check_level_length (fixture->filter, "0:0:0", 0);
1186 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1187 set_path_visibility (fixture, "3", FALSE);
1188 check_filter_model (fixture);
1189 check_level_length (fixture->filter, NULL, 1);
1191 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1192 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1193 set_path_visibility (fixture, "3:2:1", TRUE);
1194 set_path_visibility (fixture, "3", TRUE);
1195 check_filter_model (fixture);
1196 check_level_length (fixture->filter, NULL, 2);
1197 check_level_length (fixture->filter, "0", 1);
1198 check_level_length (fixture->filter, "0:0", 2);
1199 check_level_length (fixture->filter, "0:0:0", 0);
1203 empty_vroot_show_nodes (FilterTest *fixture,
1204 gconstpointer user_data)
1206 GtkTreePath *path = (GtkTreePath *)user_data;
1208 check_filter_model_with_root (fixture, path);
1209 check_level_length (fixture->filter, NULL, 0);
1211 set_path_visibility (fixture, "2", TRUE);
1212 check_filter_model_with_root (fixture, path);
1213 check_level_length (fixture->filter, NULL, 0);
1215 set_path_visibility (fixture, "2:2:2", TRUE);
1216 check_filter_model_with_root (fixture, path);
1217 check_level_length (fixture->filter, NULL, 0);
1219 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1220 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1221 set_path_visibility (fixture, "2:2", TRUE);
1222 check_filter_model_with_root (fixture, path);
1223 check_level_length (fixture->filter, NULL, 1);
1224 check_level_length (fixture->filter, "0", 1);
1225 check_level_length (fixture->filter, "0:0", 0);
1227 set_path_visibility (fixture, "3", TRUE);
1228 check_filter_model_with_root (fixture, path);
1229 check_level_length (fixture->filter, NULL, 1);
1231 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1232 set_path_visibility (fixture, "2:2", FALSE);
1233 check_filter_model_with_root (fixture, path);
1234 check_level_length (fixture->filter, NULL, 0);
1236 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1237 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1238 set_path_visibility (fixture, "2:2:1", TRUE);
1239 set_path_visibility (fixture, "2:2", TRUE);
1240 check_filter_model_with_root (fixture, path);
1241 check_level_length (fixture->filter, NULL, 1);
1242 check_level_length (fixture->filter, "0", 2);
1243 check_level_length (fixture->filter, "0:1", 0);
1247 empty_vroot_show_multiple_nodes (FilterTest *fixture,
1248 gconstpointer user_data)
1251 GtkTreePath *changed_path;
1252 GtkTreePath *path = (GtkTreePath *)user_data;
1254 check_filter_model_with_root (fixture, path);
1255 check_level_length (fixture->filter, NULL, 0);
1257 /* We simulate a change in visible func condition with this. The
1258 * visibility state of multiple nodes changes at once, we emit row-changed
1259 * for these nodes (and others) after that.
1261 filter_test_block_signals (fixture);
1262 set_path_visibility (fixture, "2", TRUE);
1263 set_path_visibility (fixture, "3", TRUE);
1264 filter_test_unblock_signals (fixture);
1266 changed_path = gtk_tree_path_new ();
1267 gtk_tree_path_append_index (changed_path, 1);
1268 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1269 &iter, changed_path);
1270 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1271 changed_path, &iter);
1273 gtk_tree_path_next (changed_path);
1274 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1275 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1276 changed_path, &iter);
1278 gtk_tree_path_next (changed_path);
1279 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1280 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1281 changed_path, &iter);
1283 gtk_tree_path_next (changed_path);
1284 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1285 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1286 changed_path, &iter);
1288 gtk_tree_path_free (changed_path);
1290 check_filter_model_with_root (fixture, path);
1291 check_level_length (fixture->filter, NULL, 0);
1293 set_path_visibility (fixture, "2:2:2", TRUE);
1294 check_filter_model_with_root (fixture, path);
1295 check_level_length (fixture->filter, NULL, 0);
1297 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1298 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1299 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "1");
1300 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "1");
1302 /* Again, we simulate a call to refilter */
1303 filter_test_block_signals (fixture);
1304 set_path_visibility (fixture, "2:2", TRUE);
1305 set_path_visibility (fixture, "2:3", TRUE);
1306 filter_test_unblock_signals (fixture);
1308 changed_path = gtk_tree_path_new ();
1309 gtk_tree_path_append_index (changed_path, 2);
1310 gtk_tree_path_append_index (changed_path, 1);
1311 gtk_tree_model_get_iter (GTK_TREE_MODEL (fixture->store),
1312 &iter, changed_path);
1313 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1314 changed_path, &iter);
1316 gtk_tree_path_next (changed_path);
1317 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1318 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1319 changed_path, &iter);
1321 gtk_tree_path_next (changed_path);
1322 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1323 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1324 changed_path, &iter);
1326 gtk_tree_path_next (changed_path);
1327 gtk_tree_model_iter_next (GTK_TREE_MODEL (fixture->store), &iter);
1328 gtk_tree_model_row_changed (GTK_TREE_MODEL (fixture->store),
1329 changed_path, &iter);
1331 gtk_tree_path_free (changed_path);
1333 check_filter_model_with_root (fixture, path);
1334 check_level_length (fixture->filter, NULL, 2);
1335 check_level_length (fixture->filter, "0", 1);
1336 check_level_length (fixture->filter, "0:0", 0);
1338 set_path_visibility (fixture, "3", TRUE);
1339 check_filter_model_with_root (fixture, path);
1340 check_level_length (fixture->filter, NULL, 2);
1342 signal_monitor_append_signal (fixture->monitor, ROW_DELETED, "0");
1343 set_path_visibility (fixture, "2:2", FALSE);
1344 check_filter_model_with_root (fixture, path);
1345 check_level_length (fixture->filter, NULL, 1);
1347 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1348 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1349 set_path_visibility (fixture, "2:2:1", TRUE);
1350 set_path_visibility (fixture, "2:2", TRUE);
1351 check_filter_model_with_root (fixture, path);
1352 check_level_length (fixture->filter, NULL, 2);
1353 check_level_length (fixture->filter, "0", 2);
1354 check_level_length (fixture->filter, "0:1", 0);
1359 unfiltered_hide_single (FilterTest *fixture,
1360 gconstpointer user_data)
1363 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1364 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1365 set_path_visibility (fixture, "2", FALSE);
1367 signal_monitor_assert_is_empty (fixture->monitor);
1368 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1370 /* The view only shows the root level, so we only expect signals
1371 * for the root level.
1373 filter_test_append_refilter_signals (fixture, 1);
1374 filter_test_enable_filter (fixture);
1376 check_filter_model (fixture);
1377 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1381 unfiltered_hide_single_root_expanded (FilterTest *fixture,
1382 gconstpointer user_data)
1385 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1386 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1387 set_path_visibility (fixture, "2", FALSE);
1389 signal_monitor_assert_is_empty (fixture->monitor);
1390 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1392 filter_test_append_refilter_signals (fixture, 2);
1393 filter_test_enable_filter (fixture);
1395 check_filter_model (fixture);
1396 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1400 unfiltered_hide_single_child (FilterTest *fixture,
1401 gconstpointer user_data)
1404 /* This row is not shown, so its signal is not propagated */
1405 set_path_visibility (fixture, "2:2", FALSE);
1407 signal_monitor_assert_is_empty (fixture->monitor);
1408 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1409 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1411 /* The view only shows the root level, so we only expect signals
1412 * for the root level.
1414 filter_test_append_refilter_signals (fixture, 0);
1415 filter_test_enable_filter (fixture);
1417 check_filter_model (fixture);
1418 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1419 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1423 unfiltered_hide_single_child_root_expanded (FilterTest *fixture,
1424 gconstpointer user_data)
1427 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1428 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1429 set_path_visibility (fixture, "2:2", FALSE);
1431 signal_monitor_assert_is_empty (fixture->monitor);
1432 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1433 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1435 filter_test_append_refilter_signals (fixture, 2);
1436 filter_test_enable_filter (fixture);
1438 check_filter_model (fixture);
1439 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1440 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1444 unfiltered_hide_single_multi_level (FilterTest *fixture,
1445 gconstpointer user_data)
1448 /* This row is not shown, so its signal is not propagated */
1449 set_path_visibility (fixture, "2:2:2", FALSE);
1451 /* This row is not shown, so its signal is not propagated */
1452 set_path_visibility (fixture, "2:2", FALSE);
1454 signal_monitor_assert_is_empty (fixture->monitor);
1455 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1456 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1457 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1459 /* The view only shows the root level, so we only expect signals
1460 * for the root level.
1462 filter_test_append_refilter_signals (fixture, 1);
1463 filter_test_enable_filter (fixture);
1465 check_filter_model (fixture);
1466 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1467 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1469 set_path_visibility (fixture, "2:2", TRUE);
1471 check_filter_model (fixture);
1472 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1473 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1474 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1478 unfiltered_hide_single_multi_level_root_expanded (FilterTest *fixture,
1479 gconstpointer user_data)
1482 /* This row is not shown, so its signal is not propagated */
1483 set_path_visibility (fixture, "2:2:2", FALSE);
1485 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1486 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1487 set_path_visibility (fixture, "2:2", FALSE);
1489 signal_monitor_assert_is_empty (fixture->monitor);
1490 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1491 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1492 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1494 filter_test_append_refilter_signals (fixture, 2);
1495 filter_test_enable_filter (fixture);
1497 check_filter_model (fixture);
1498 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1499 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1501 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1502 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1503 set_path_visibility (fixture, "2:2", TRUE);
1505 check_filter_model (fixture);
1506 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1507 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1508 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1514 unfiltered_vroot_hide_single (FilterTest *fixture,
1515 gconstpointer user_data)
1518 GtkTreePath *path = (GtkTreePath *)user_data;
1520 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1521 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1522 set_path_visibility (fixture, "2:2", FALSE);
1524 signal_monitor_assert_is_empty (fixture->monitor);
1525 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1527 /* The view only shows the root level, so we only expect signals
1528 * for the root level. (Though for the depth argument, we have to
1529 * take the virtual root into account).
1531 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1532 filter_test_enable_filter (fixture);
1534 check_filter_model_with_root (fixture, path);
1535 check_level_length (fixture->filter, NULL, LEVEL_LENGTH - 1);
1539 unfiltered_vroot_hide_single_child (FilterTest *fixture,
1540 gconstpointer user_data)
1543 GtkTreePath *path = (GtkTreePath *)user_data;
1545 /* Not visible, so no signal will be received. */
1546 set_path_visibility (fixture, "2:2:2", FALSE);
1548 signal_monitor_assert_is_empty (fixture->monitor);
1549 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1550 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1552 /* The view only shows the root level, so we only expect signals
1553 * for the root level. (Though for the depth argument, we have to
1554 * take the virtual root into account).
1556 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1557 filter_test_enable_filter (fixture);
1559 check_filter_model_with_root (fixture, path);
1560 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1561 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1565 unfiltered_vroot_hide_single_child_root_expanded (FilterTest *fixture,
1566 gconstpointer user_data)
1569 GtkTreePath *path = (GtkTreePath *)user_data;
1571 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1572 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1573 set_path_visibility (fixture, "2:2:2", FALSE);
1575 signal_monitor_assert_is_empty (fixture->monitor);
1576 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1577 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1579 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1580 filter_test_enable_filter (fixture);
1582 check_filter_model_with_root (fixture, path);
1583 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1584 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1588 unfiltered_vroot_hide_single_multi_level (FilterTest *fixture,
1589 gconstpointer user_data)
1592 GtkTreePath *path = (GtkTreePath *)user_data;
1594 /* This row is not shown, so its signal is not propagated */
1595 set_path_visibility (fixture, "2:2:2:2", FALSE);
1597 /* Not shown, so no signal */
1598 set_path_visibility (fixture, "2:2:2", FALSE);
1600 signal_monitor_assert_is_empty (fixture->monitor);
1601 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1602 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1603 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1605 /* We only expect signals for the root level. The depth is 2
1606 * because we have to take the virtual root into account.
1608 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1609 filter_test_enable_filter (fixture);
1611 check_filter_model_with_root (fixture, path);
1612 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1613 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1615 /* Not shown, so no signal */
1616 set_path_visibility (fixture, "2:2:2", TRUE);
1618 check_filter_model_with_root (fixture, path);
1619 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1620 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1621 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1625 unfiltered_vroot_hide_single_multi_level_root_expanded (FilterTest *fixture,
1626 gconstpointer user_data)
1629 GtkTreePath *path = (GtkTreePath *)user_data;
1631 /* This row is not shown, so its signal is not propagated */
1632 set_path_visibility (fixture, "2:2:2:2", FALSE);
1634 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1635 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1636 set_path_visibility (fixture, "2:2:2", FALSE);
1638 signal_monitor_assert_is_empty (fixture->monitor);
1639 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1640 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1641 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1643 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1644 filter_test_enable_filter (fixture);
1646 check_filter_model_with_root (fixture, path);
1647 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1648 check_level_length (fixture->filter, "2", LEVEL_LENGTH - 1);
1650 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "2:2");
1651 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1652 set_path_visibility (fixture, "2:2:2", TRUE);
1654 check_filter_model_with_root (fixture, path);
1655 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1656 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1657 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH - 1);
1661 unfiltered_show_single (FilterTest *fixture,
1662 gconstpointer user_data)
1665 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1666 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1667 set_path_visibility (fixture, "2", TRUE);
1669 signal_monitor_assert_is_empty (fixture->monitor);
1670 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1672 /* We only expect signals for the root level */
1673 filter_test_append_refilter_signals (fixture, 1);
1674 filter_test_enable_filter (fixture);
1676 check_filter_model (fixture);
1677 check_level_length (fixture->filter, NULL, 1);
1681 unfiltered_show_single_child (FilterTest *fixture,
1682 gconstpointer user_data)
1685 set_path_visibility (fixture, "2:2", TRUE);
1687 signal_monitor_assert_is_empty (fixture->monitor);
1688 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1689 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1691 /* We only expect signals for the root level */
1692 filter_test_append_refilter_signals (fixture, 1);
1693 filter_test_enable_filter (fixture);
1695 check_filter_model (fixture);
1696 check_level_length (fixture->filter, NULL, 0);
1698 /* From here we are filtered, "2" in the real model is "0" in the filter
1701 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1702 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1703 set_path_visibility (fixture, "2", TRUE);
1704 signal_monitor_assert_is_empty (fixture->monitor);
1705 check_level_length (fixture->filter, NULL, 1);
1706 check_level_length (fixture->filter, "0", 1);
1710 unfiltered_show_single_child_root_expanded (FilterTest *fixture,
1711 gconstpointer user_data)
1714 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1715 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1716 set_path_visibility (fixture, "2:2", TRUE);
1718 signal_monitor_assert_is_empty (fixture->monitor);
1719 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1720 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1722 filter_test_append_refilter_signals (fixture, 2);
1723 filter_test_enable_filter (fixture);
1725 check_filter_model (fixture);
1726 check_level_length (fixture->filter, NULL, 0);
1728 /* From here we are filtered, "2" in the real model is "0" in the filter
1731 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1732 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1733 set_path_visibility (fixture, "2", TRUE);
1734 signal_monitor_assert_is_empty (fixture->monitor);
1735 check_level_length (fixture->filter, NULL, 1);
1736 check_level_length (fixture->filter, "0", 1);
1740 unfiltered_show_single_multi_level (FilterTest *fixture,
1741 gconstpointer user_data)
1744 /* The view is not showing these rows (collapsed state), so it is not
1745 * referenced. The signal should not go through.
1747 set_path_visibility (fixture, "2:2:2", TRUE);
1748 set_path_visibility (fixture, "2:2", TRUE);
1750 signal_monitor_assert_is_empty (fixture->monitor);
1751 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1752 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1753 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1755 /* We only expect signals for the first level */
1756 filter_test_append_refilter_signals (fixture, 1);
1757 filter_test_enable_filter (fixture);
1759 check_filter_model (fixture);
1760 check_level_length (fixture->filter, NULL, 0);
1762 /* From here we are filtered, "2" in the real model is "0" in the filter
1765 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1766 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1767 set_path_visibility (fixture, "2", TRUE);
1768 check_filter_model (fixture);
1769 check_level_length (fixture->filter, NULL, 1);
1770 check_level_length (fixture->filter, "0", 1);
1771 check_level_length (fixture->filter, "0:0", 1);
1775 unfiltered_show_single_multi_level_root_expanded (FilterTest *fixture,
1776 gconstpointer user_data)
1779 /* The view is not showing this row (collapsed state), so it is not
1780 * referenced. The signal should not go through.
1782 set_path_visibility (fixture, "2:2:2", TRUE);
1784 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1785 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1786 set_path_visibility (fixture, "2:2", TRUE);
1788 signal_monitor_assert_is_empty (fixture->monitor);
1789 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1790 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1791 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1793 filter_test_append_refilter_signals (fixture, 2);
1794 filter_test_enable_filter (fixture);
1796 check_filter_model (fixture);
1797 check_level_length (fixture->filter, NULL, 0);
1799 /* From here we are filtered, "2" in the real model is "0" in the filter
1802 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1803 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1804 set_path_visibility (fixture, "2", TRUE);
1805 check_filter_model (fixture);
1806 check_level_length (fixture->filter, NULL, 1);
1807 check_level_length (fixture->filter, "0", 1);
1808 check_level_length (fixture->filter, "0:0", 1);
1812 unfiltered_vroot_show_single (FilterTest *fixture,
1813 gconstpointer user_data)
1816 GtkTreePath *path = (GtkTreePath *)user_data;
1818 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2");
1819 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2");
1820 set_path_visibility (fixture, "2:2", TRUE);
1822 signal_monitor_assert_is_empty (fixture->monitor);
1823 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1825 /* The view only shows the root level, so the filter model only has
1826 * the first two levels cached.
1828 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1829 filter_test_enable_filter (fixture);
1831 check_filter_model_with_root (fixture, path);
1832 check_level_length (fixture->filter, NULL, 1);
1836 unfiltered_vroot_show_single_child (FilterTest *fixture,
1837 gconstpointer user_data)
1840 GtkTreePath *path = (GtkTreePath *)user_data;
1842 set_path_visibility (fixture, "2:2:2", TRUE);
1844 signal_monitor_assert_is_empty (fixture->monitor);
1845 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1846 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1848 /* The view only shows the root level, so the filter model only has
1849 * the first two levels cached.
1851 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1852 filter_test_enable_filter (fixture);
1854 check_filter_model_with_root (fixture, path);
1855 check_level_length (fixture->filter, NULL, 0);
1857 /* From here we are filtered, "2" in the real model is "0" in the filter
1860 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1861 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1862 set_path_visibility (fixture, "2:2", TRUE);
1863 signal_monitor_assert_is_empty (fixture->monitor);
1864 check_level_length (fixture->filter, NULL, 1);
1865 check_level_length (fixture->filter, "0", 1);
1869 unfiltered_vroot_show_single_child_root_expanded (FilterTest *fixture,
1870 gconstpointer user_data)
1873 GtkTreePath *path = (GtkTreePath *)user_data;
1875 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1876 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1877 set_path_visibility (fixture, "2:2:2", TRUE);
1879 signal_monitor_assert_is_empty (fixture->monitor);
1880 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1881 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1883 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1884 filter_test_enable_filter (fixture);
1886 check_filter_model_with_root (fixture, path);
1887 check_level_length (fixture->filter, NULL, 0);
1889 /* From here we are filtered, "2" in the real model is "0" in the filter
1892 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1893 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1894 set_path_visibility (fixture, "2:2", TRUE);
1895 signal_monitor_assert_is_empty (fixture->monitor);
1896 check_level_length (fixture->filter, NULL, 1);
1897 check_level_length (fixture->filter, "0", 1);
1902 unfiltered_vroot_show_single_multi_level (FilterTest *fixture,
1903 gconstpointer user_data)
1906 GtkTreePath *path = (GtkTreePath *)user_data;
1908 /* The view is not showing this row (collapsed state), so it is not
1909 * referenced. The signal should not go through.
1911 set_path_visibility (fixture, "2:2:2:2", TRUE);
1913 set_path_visibility (fixture, "2:2:2", TRUE);
1915 signal_monitor_assert_is_empty (fixture->monitor);
1916 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1917 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1918 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1920 /* We only expect signals for the root level */
1921 filter_test_append_refilter_signals_with_vroot (fixture, 2, path);
1922 filter_test_enable_filter (fixture);
1924 check_filter_model_with_root (fixture, path);
1925 check_level_length (fixture->filter, NULL, 0);
1927 /* From here we are filtered, "2" in the real model is "0" in the filter
1930 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1931 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1932 set_path_visibility (fixture, "2:2", TRUE);
1933 check_filter_model_with_root (fixture, path);
1934 check_level_length (fixture->filter, NULL, 1);
1935 check_level_length (fixture->filter, "0", 1);
1936 check_level_length (fixture->filter, "0:0", 1);
1940 unfiltered_vroot_show_single_multi_level_root_expanded (FilterTest *fixture,
1941 gconstpointer user_data)
1944 GtkTreePath *path = (GtkTreePath *)user_data;
1946 /* The view is not showing this row (collapsed state), so it is not
1947 * referenced. The signal should not go through.
1949 set_path_visibility (fixture, "2:2:2:2", TRUE);
1951 signal_monitor_append_signal (fixture->monitor, ROW_CHANGED, "2:2");
1952 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "2:2");
1953 set_path_visibility (fixture, "2:2:2", TRUE);
1955 signal_monitor_assert_is_empty (fixture->monitor);
1956 check_level_length (fixture->filter, NULL, LEVEL_LENGTH);
1957 check_level_length (fixture->filter, "2", LEVEL_LENGTH);
1958 check_level_length (fixture->filter, "2:2", LEVEL_LENGTH);
1960 filter_test_append_refilter_signals_with_vroot (fixture, 3, path);
1961 filter_test_enable_filter (fixture);
1963 check_filter_model_with_root (fixture, path);
1964 check_level_length (fixture->filter, NULL, 0);
1966 /* From here we are filtered, "2" in the real model is "0" in the filter
1969 signal_monitor_append_signal (fixture->monitor, ROW_INSERTED, "0");
1970 signal_monitor_append_signal (fixture->monitor, ROW_HAS_CHILD_TOGGLED, "0");
1971 set_path_visibility (fixture, "2:2", TRUE);
1972 check_filter_model_with_root (fixture, path);
1973 check_level_length (fixture->filter, NULL, 1);
1974 check_level_length (fixture->filter, "0", 1);
1975 check_level_length (fixture->filter, "0:0", 1);
1979 unfiltered_rows_reordered_root_level (FilterTest *fixture,
1980 gconstpointer user_data)
1982 int order0[] = { 1, 2, 3, 4, 0 };
1983 int order1[] = { 0, 2, 1, 3, 4 };
1984 int order2[] = { 4, 0, 1, 2, 3 };
1985 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
1988 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1990 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1992 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1994 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1996 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
1999 path = gtk_tree_path_new ();
2000 signal_monitor_append_signal_reordered (fixture->monitor,
2003 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2004 signal_monitor_assert_is_empty (fixture->monitor);
2006 signal_monitor_append_signal_reordered (fixture->monitor,
2009 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
2010 signal_monitor_assert_is_empty (fixture->monitor);
2012 signal_monitor_append_signal_reordered (fixture->monitor,
2015 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2016 signal_monitor_assert_is_empty (fixture->monitor);
2018 gtk_tree_path_free (path);
2022 unfiltered_rows_reordered_child_level (FilterTest *fixture,
2023 gconstpointer user_data)
2025 int order0[] = { 1, 2, 3, 4, 0 };
2026 int order1[] = { 0, 2, 1, 3, 4 };
2027 int order2[] = { 4, 0, 1, 2, 3 };
2028 GtkTreeIter iter0, iter1, iter2, iter3, iter4;
2032 path = gtk_tree_path_new_from_indices (0, -1);
2033 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2035 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2037 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2039 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2041 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2043 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2046 signal_monitor_append_signal_reordered (fixture->monitor,
2049 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2050 signal_monitor_assert_is_empty (fixture->monitor);
2052 signal_monitor_append_signal_reordered (fixture->monitor,
2055 gtk_tree_store_move_after (fixture->store, &iter2, &iter3);
2056 signal_monitor_assert_is_empty (fixture->monitor);
2058 signal_monitor_append_signal_reordered (fixture->monitor,
2061 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2062 signal_monitor_assert_is_empty (fixture->monitor);
2064 gtk_tree_path_free (path);
2068 filtered_rows_reordered_root_level_first_hidden (FilterTest *fixture,
2069 gconstpointer user_data)
2071 int order0[] = { 1, 2, 3, 0 };
2072 int order1[] = { 0, 2, 1, 3 };
2073 int order2[] = { 3, 0, 1, 2 };
2074 GtkTreeIter iter1, iter2, iter3, iter4;
2077 /* Hide middle path */
2078 signal_monitor_append_signal (fixture->monitor,
2080 set_path_visibility (fixture, "0", FALSE);
2081 signal_monitor_assert_is_empty (fixture->monitor);
2083 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2085 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2087 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2089 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2092 path = gtk_tree_path_new ();
2093 signal_monitor_append_signal_reordered (fixture->monitor,
2096 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2097 signal_monitor_assert_is_empty (fixture->monitor);
2099 signal_monitor_append_signal_reordered (fixture->monitor,
2102 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2103 signal_monitor_assert_is_empty (fixture->monitor);
2105 signal_monitor_append_signal_reordered (fixture->monitor,
2108 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2109 signal_monitor_assert_is_empty (fixture->monitor);
2111 gtk_tree_path_free (path);
2115 filtered_rows_reordered_root_level_middle_hidden (FilterTest *fixture,
2116 gconstpointer user_data)
2118 int order0[] = { 1, 2, 3, 0 };
2119 int order1[] = { 0, 2, 1, 3 };
2120 int order2[] = { 3, 0, 1, 2 };
2121 GtkTreeIter iter0, iter1, iter3, iter4;
2124 /* Hide middle path */
2125 signal_monitor_append_signal (fixture->monitor,
2127 set_path_visibility (fixture, "2", FALSE);
2128 signal_monitor_assert_is_empty (fixture->monitor);
2130 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2132 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2134 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2136 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2139 path = gtk_tree_path_new ();
2140 signal_monitor_append_signal_reordered (fixture->monitor,
2143 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2144 signal_monitor_assert_is_empty (fixture->monitor);
2146 signal_monitor_append_signal_reordered (fixture->monitor,
2149 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2150 signal_monitor_assert_is_empty (fixture->monitor);
2152 signal_monitor_append_signal_reordered (fixture->monitor,
2155 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2156 signal_monitor_assert_is_empty (fixture->monitor);
2158 gtk_tree_path_free (path);
2162 filtered_rows_reordered_child_level_first_hidden (FilterTest *fixture,
2163 gconstpointer user_data)
2165 int order0[] = { 1, 2, 3, 0 };
2166 int order1[] = { 0, 2, 1, 3 };
2167 int order2[] = { 3, 0, 1, 2 };
2168 GtkTreeIter iter1, iter2, iter3, iter4;
2172 path = gtk_tree_path_new_from_indices (0, -1);
2173 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, TRUE);
2175 /* Hide middle path */
2176 signal_monitor_append_signal (fixture->monitor,
2177 ROW_DELETED, "0:0");
2178 set_path_visibility (fixture, "0:0", FALSE);
2179 signal_monitor_assert_is_empty (fixture->monitor);
2181 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2183 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2185 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2187 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2190 signal_monitor_append_signal_reordered (fixture->monitor,
2193 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2194 signal_monitor_assert_is_empty (fixture->monitor);
2196 signal_monitor_append_signal_reordered (fixture->monitor,
2199 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2200 signal_monitor_assert_is_empty (fixture->monitor);
2202 signal_monitor_append_signal_reordered (fixture->monitor,
2205 gtk_tree_store_move_before (fixture->store, &iter1, &iter2);
2206 signal_monitor_assert_is_empty (fixture->monitor);
2208 gtk_tree_path_free (path);
2212 filtered_rows_reordered_child_level_middle_hidden (FilterTest *fixture,
2213 gconstpointer user_data)
2215 int order0[] = { 1, 2, 3, 0 };
2216 int order1[] = { 0, 2, 1, 3 };
2217 int order2[] = { 3, 0, 1, 2 };
2218 GtkTreeIter iter0, iter1, iter3, iter4;
2222 path = gtk_tree_path_new_from_indices (0, -1);
2223 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2225 /* Hide middle path */
2226 signal_monitor_append_signal (fixture->monitor,
2227 ROW_DELETED, "0:2");
2228 set_path_visibility (fixture, "0:2", FALSE);
2229 signal_monitor_assert_is_empty (fixture->monitor);
2231 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2233 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2235 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2237 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2240 signal_monitor_append_signal_reordered (fixture->monitor,
2243 gtk_tree_store_move_after (fixture->store, &iter0, &iter4);
2244 signal_monitor_assert_is_empty (fixture->monitor);
2246 signal_monitor_append_signal_reordered (fixture->monitor,
2249 gtk_tree_store_move_after (fixture->store, &iter3, &iter4);
2250 signal_monitor_assert_is_empty (fixture->monitor);
2252 signal_monitor_append_signal_reordered (fixture->monitor,
2255 gtk_tree_store_move_before (fixture->store, &iter0, &iter1);
2256 signal_monitor_assert_is_empty (fixture->monitor);
2258 gtk_tree_path_free (path);
2262 filtered_rows_reordered_child_level_4_hidden (FilterTest *fixture,
2263 gconstpointer user_data)
2265 int order0[] = { 0 };
2266 GtkTreeIter iter1, iter4;
2270 path = gtk_tree_path_new_from_indices (0, -1);
2271 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2273 /* Hide last 4 paths */
2274 signal_monitor_append_signal (fixture->monitor,
2275 ROW_DELETED, "0:4");
2276 signal_monitor_append_signal (fixture->monitor,
2277 ROW_DELETED, "0:3");
2278 signal_monitor_append_signal (fixture->monitor,
2279 ROW_DELETED, "0:2");
2280 signal_monitor_append_signal (fixture->monitor,
2281 ROW_DELETED, "0:0");
2282 set_path_visibility (fixture, "0:4", FALSE);
2283 set_path_visibility (fixture, "0:3", FALSE);
2284 set_path_visibility (fixture, "0:2", FALSE);
2285 set_path_visibility (fixture, "0:0", FALSE);
2286 signal_monitor_assert_is_empty (fixture->monitor);
2288 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2290 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2293 signal_monitor_append_signal_reordered (fixture->monitor,
2296 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2297 signal_monitor_assert_is_empty (fixture->monitor);
2299 gtk_tree_path_free (path);
2303 filtered_rows_reordered_child_level_all_hidden (FilterTest *fixture,
2304 gconstpointer user_data)
2306 GtkTreeIter iter1, iter4;
2310 path = gtk_tree_path_new_from_indices (0, -1);
2311 gtk_tree_view_expand_row (GTK_TREE_VIEW (fixture->tree_view), path, FALSE);
2312 gtk_tree_path_free (path);
2314 /* Hide last 4 paths */
2315 signal_monitor_append_signal (fixture->monitor,
2316 ROW_DELETED, "0:4");
2317 signal_monitor_append_signal (fixture->monitor,
2318 ROW_DELETED, "0:3");
2319 signal_monitor_append_signal (fixture->monitor,
2320 ROW_DELETED, "0:2");
2321 signal_monitor_append_signal (fixture->monitor,
2322 ROW_DELETED, "0:1");
2323 signal_monitor_append_signal (fixture->monitor,
2324 ROW_DELETED, "0:0");
2325 signal_monitor_append_signal (fixture->monitor,
2326 ROW_HAS_CHILD_TOGGLED, "0");
2327 set_path_visibility (fixture, "0:4", FALSE);
2328 set_path_visibility (fixture, "0:3", FALSE);
2329 set_path_visibility (fixture, "0:2", FALSE);
2330 set_path_visibility (fixture, "0:1", FALSE);
2331 set_path_visibility (fixture, "0:0", FALSE);
2332 signal_monitor_assert_is_empty (fixture->monitor);
2334 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2336 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture->store),
2339 gtk_tree_store_move_after (fixture->store, &iter1, &iter4);
2340 signal_monitor_assert_is_empty (fixture->monitor);
2344 insert_before (void)
2346 GtkTreeStore *store;
2347 GtkTreeModel *filter;
2348 GtkWidget *tree_view;
2349 SignalMonitor *monitor;
2351 GtkTreeIter last_iter;
2354 /* This tests two aspects of the row-inserted handling:
2355 * 1) If the newly inserted node was already handled by building
2356 * the root level, don't handle it a second time.
2357 * 2) Offsets of existing nodes must be updated when a new
2361 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2362 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2363 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2366 tree_view = gtk_tree_view_new_with_model (filter);
2367 monitor = signal_monitor_new (filter);
2369 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 0);
2372 path = gtk_tree_path_new_from_indices (0, -1);
2373 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2374 gtk_tree_path_free (path);
2376 gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
2377 0, "Foo", 1, TRUE, -1);
2379 signal_monitor_assert_is_empty (monitor);
2380 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2383 path = gtk_tree_path_new_from_indices (1, -1);
2384 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2385 gtk_tree_path_free (path);
2387 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2388 0, "Foo", 1, TRUE, -1);
2391 signal_monitor_assert_is_empty (monitor);
2392 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2394 /* Insert on 1 again -- invisible */
2395 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2396 0, "Foo", 1, FALSE, -1);
2398 signal_monitor_assert_is_empty (monitor);
2399 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
2401 /* Insert on 1 again -- visible */
2402 path = gtk_tree_path_new_from_indices (1, -1);
2403 signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
2404 gtk_tree_path_free (path);
2406 gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
2407 0, "Foo", 1, TRUE, -1);
2409 signal_monitor_assert_is_empty (monitor);
2410 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2412 /* Modify the iter that should be at the last position and check the
2415 path = gtk_tree_path_new_from_indices (2, -1);
2416 signal_monitor_append_signal_path (monitor, ROW_CHANGED, path);
2417 gtk_tree_path_free (path);
2419 gtk_tree_store_set (store, &last_iter, 0, "Foo changed", -1);
2421 signal_monitor_assert_is_empty (monitor);
2422 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
2424 g_object_unref (filter);
2425 g_object_unref (store);
2426 g_object_unref (tree_view);
2432 GtkTreeStore *store;
2433 GtkTreeModel *filter;
2434 GtkWidget *tree_view;
2435 SignalMonitor *monitor;
2436 GtkTreeIter parent, iter;
2439 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
2441 gtk_tree_store_insert_with_values (store, &parent, NULL, 0,
2442 0, "Parent", 1, TRUE, -1);
2445 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
2446 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
2449 tree_view = gtk_tree_view_new_with_model (filter);
2450 monitor = signal_monitor_new (filter);
2452 /* Insert child -- invisible */
2453 path = gtk_tree_path_new_from_indices (0, -1);
2454 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2455 /* The signal is received twice, once a pass through from GtkTreeStore
2456 * and one generated by GtkTreeModelFilter. Not accurate, but cannot
2459 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2460 gtk_tree_path_free (path);
2462 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2463 0, "Child", 1, FALSE, -1);
2465 signal_monitor_assert_is_empty (monitor);
2466 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2469 path = gtk_tree_path_new_from_indices (0, 0, -1);
2470 gtk_tree_path_up (path); /* 0 */
2471 signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
2472 gtk_tree_path_free (path);
2474 gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
2475 0, "Child", 1, TRUE, -1);
2477 signal_monitor_assert_is_empty (monitor);
2478 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2480 /* Insert child -- invisible */
2481 gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
2482 0, "Child", 1, FALSE, -1);
2484 signal_monitor_assert_is_empty (monitor);
2485 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
2487 g_object_unref (filter);
2488 g_object_unref (store);
2489 g_object_unref (tree_view);
2497 GtkTreeIter iter, iter1, iter2, iter3;
2499 GtkTreeModel *filter;
2500 GtkWidget *view G_GNUC_UNUSED;
2502 list = gtk_list_store_new (1, G_TYPE_INT);
2503 gtk_list_store_insert_with_values (list, &iter1, 0, 0, 1, -1);
2504 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
2505 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
2506 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
2507 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
2508 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
2509 gtk_list_store_insert_with_values (list, &iter2, 6, 0, 7, -1);
2510 gtk_list_store_insert_with_values (list, &iter3, 7, 0, 8, -1);
2512 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
2513 view = gtk_tree_view_new_with_model (filter);
2515 gtk_list_store_remove (list, &iter1);
2516 gtk_list_store_remove (list, &iter3);
2517 gtk_list_store_remove (list, &iter2);
2519 gtk_widget_destroy (view);
2520 g_object_unref (filter);
2521 g_object_unref (list);
2525 remove_node_vroot (void)
2527 GtkTreeIter parent, root;
2528 GtkTreeIter iter, iter1, iter2, iter3;
2530 GtkTreeModel *filter;
2532 GtkWidget *view G_GNUC_UNUSED;
2534 tree = gtk_tree_store_new (1, G_TYPE_INT);
2535 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2536 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2538 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2539 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2540 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2541 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2542 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2543 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2544 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2545 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2547 path = gtk_tree_path_new_from_indices (0, 0, -1);
2548 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2549 gtk_tree_path_free (path);
2551 view = gtk_tree_view_new_with_model (filter);
2553 gtk_tree_store_remove (tree, &iter1);
2554 gtk_tree_store_remove (tree, &iter3);
2555 gtk_tree_store_remove (tree, &iter2);
2557 gtk_widget_destroy (view);
2558 g_object_unref (filter);
2559 g_object_unref (tree);
2563 remove_vroot_ancestor (void)
2565 GtkTreeIter parent, root;
2566 GtkTreeIter iter, iter1, iter2, iter3;
2568 GtkTreeModel *filter;
2570 GtkWidget *view G_GNUC_UNUSED;
2572 tree = gtk_tree_store_new (1, G_TYPE_INT);
2573 gtk_tree_store_insert_with_values (tree, &parent, NULL, 0, 0, 0, -1);
2574 gtk_tree_store_insert_with_values (tree, &root, &parent, 0, 0, 0, -1);
2576 gtk_tree_store_insert_with_values (tree, &iter1, &root, 0, 0, 1, -1);
2577 gtk_tree_store_insert_with_values (tree, &iter, &root, 1, 0, 2, -1);
2578 gtk_tree_store_insert_with_values (tree, &iter, &root, 2, 0, 3, -1);
2579 gtk_tree_store_insert_with_values (tree, &iter, &root, 3, 0, 4, -1);
2580 gtk_tree_store_insert_with_values (tree, &iter, &root, 4, 0, 5, -1);
2581 gtk_tree_store_insert_with_values (tree, &iter, &root, 5, 0, 6, -1);
2582 gtk_tree_store_insert_with_values (tree, &iter2, &root, 6, 0, 7, -1);
2583 gtk_tree_store_insert_with_values (tree, &iter3, &root, 7, 0, 8, -1);
2585 path = gtk_tree_path_new_from_indices (0, 0, -1);
2586 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
2587 gtk_tree_path_free (path);
2589 view = gtk_tree_view_new_with_model (filter);
2591 gtk_tree_store_remove (tree, &parent);
2593 gtk_widget_destroy (view);
2594 g_object_unref (filter);
2595 g_object_unref (tree);
2599 ref_count_single_level (void)
2601 GtkTreeIter iter[5];
2602 GtkTreeModel *model;
2603 GtkTreeModelRefCount *ref_model;
2604 GtkTreeModel *filter_model;
2605 GtkWidget *tree_view;
2607 model = gtk_tree_model_ref_count_new ();
2608 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2610 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[0], NULL);
2611 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[1], NULL);
2612 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[2], NULL);
2613 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[3], NULL);
2614 gtk_tree_store_append (GTK_TREE_STORE (model), &iter[4], NULL);
2616 assert_root_level_unreferenced (ref_model);
2618 filter_model = gtk_tree_model_filter_new (model, NULL);
2619 tree_view = gtk_tree_view_new_with_model (filter_model);
2621 assert_node_ref_count (ref_model, &iter[0], 2);
2622 assert_node_ref_count (ref_model, &iter[1], 1);
2623 assert_node_ref_count (ref_model, &iter[2], 1);
2624 assert_node_ref_count (ref_model, &iter[3], 1);
2625 assert_node_ref_count (ref_model, &iter[4], 1);
2627 gtk_widget_destroy (tree_view);
2629 assert_node_ref_count (ref_model, &iter[0], 1);
2630 assert_node_ref_count (ref_model, &iter[1], 0);
2631 assert_node_ref_count (ref_model, &iter[2], 0);
2632 assert_node_ref_count (ref_model, &iter[3], 0);
2633 assert_node_ref_count (ref_model, &iter[4], 0);
2635 g_object_unref (filter_model);
2637 assert_node_ref_count (ref_model, &iter[0], 0);
2639 g_object_unref (ref_model);
2643 ref_count_two_levels (void)
2645 GtkTreeIter parent1, parent2, iter, iter_first;
2646 GtkTreeModel *model;
2647 GtkTreeModelRefCount *ref_model;
2648 GtkTreeModel *filter_model;
2649 GtkWidget *tree_view;
2651 model = gtk_tree_model_ref_count_new ();
2652 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2654 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL);
2655 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
2656 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_first, &parent2);
2657 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2658 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2);
2660 assert_entire_model_unreferenced (ref_model);
2662 filter_model = gtk_tree_model_filter_new (model, NULL);
2663 tree_view = gtk_tree_view_new_with_model (filter_model);
2665 /* This is quite confusing:
2666 * - node 0 has a ref count of 2 because it is referenced as the
2667 * first node in a level and by the tree view.
2668 * - node 1 has a ref count of 2 because it is referenced by its
2669 * child level and by the tree view.
2671 assert_root_level_referenced (ref_model, 2);
2672 assert_node_ref_count (ref_model, &iter_first, 1);
2673 assert_node_ref_count (ref_model, &iter, 0);
2675 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
2677 assert_node_ref_count (ref_model, &parent1, 2);
2678 assert_node_ref_count (ref_model, &parent2, 2);
2679 assert_node_ref_count (ref_model, &iter_first, 2);
2680 assert_node_ref_count (ref_model, &iter, 1);
2682 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2684 /* The child level is not destroyed because its parent is visible */
2685 assert_node_ref_count (ref_model, &parent1, 2);
2686 assert_node_ref_count (ref_model, &parent2, 2);
2687 assert_node_ref_count (ref_model, &iter_first, 1);
2688 assert_node_ref_count (ref_model, &iter, 0);
2690 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2692 assert_node_ref_count (ref_model, &parent1, 2);
2693 assert_node_ref_count (ref_model, &parent2, 2);
2694 assert_node_ref_count (ref_model, &iter_first, 1);
2695 assert_node_ref_count (ref_model, &iter, 0);
2697 gtk_widget_destroy (tree_view);
2699 assert_root_level_referenced (ref_model, 1);
2700 assert_node_ref_count (ref_model, &iter_first, 1);
2701 assert_node_ref_count (ref_model, &iter, 0);
2703 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2705 /* The root level and first level remain cached, only the references on the
2706 * first nodes of these levels are kept.
2708 assert_node_ref_count (ref_model, &parent1, 1);
2709 assert_node_ref_count (ref_model, &parent2, 1);
2710 assert_node_ref_count (ref_model, &iter_first, 1);
2711 assert_node_ref_count (ref_model, &iter, 0);
2713 g_object_unref (filter_model);
2714 g_object_unref (ref_model);
2718 ref_count_three_levels (void)
2720 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2721 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2722 GtkTreeModel *model;
2723 GtkTreeModelRefCount *ref_model;
2724 GtkTreeModel *filter_model;
2726 GtkWidget *tree_view;
2728 model = gtk_tree_model_ref_count_new ();
2729 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2736 * + iter_parent2_first
2740 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2741 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2742 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2743 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2744 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2745 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2746 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2748 assert_entire_model_unreferenced (ref_model);
2750 filter_model = gtk_tree_model_filter_new (model, NULL);
2751 tree_view = gtk_tree_view_new_with_model (filter_model);
2753 /* This is quite confusing:
2754 * - node 0 has a ref count of 2 because it is referenced as the
2755 * first node in a level and by the tree view.
2756 * - node 1 has a ref count of 2 because it is referenced by its
2757 * child level and by the tree view.
2759 assert_root_level_referenced (ref_model, 2);
2760 assert_node_ref_count (ref_model, &parent1, 1);
2761 assert_node_ref_count (ref_model, &parent2, 0);
2762 assert_level_unreferenced (ref_model, &parent1);
2763 assert_level_unreferenced (ref_model, &parent2);
2765 path = gtk_tree_path_new_from_indices (1, -1);
2766 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2768 assert_node_ref_count (ref_model, &grandparent1, 2);
2769 assert_node_ref_count (ref_model, &grandparent2, 2);
2770 assert_node_ref_count (ref_model, &parent1, 3);
2771 assert_node_ref_count (ref_model, &parent2, 2);
2772 assert_node_ref_count (ref_model, &iter_parent1, 1);
2773 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2774 assert_node_ref_count (ref_model, &iter_parent2, 0);
2776 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2778 assert_node_ref_count (ref_model, &grandparent1, 2);
2779 assert_node_ref_count (ref_model, &grandparent2, 2);
2780 assert_node_ref_count (ref_model, &parent1, 3);
2781 assert_node_ref_count (ref_model, &parent2, 2);
2782 assert_node_ref_count (ref_model, &iter_parent1, 2);
2783 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2784 assert_node_ref_count (ref_model, &iter_parent2, 1);
2786 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
2788 assert_node_ref_count (ref_model, &grandparent1, 2);
2789 assert_node_ref_count (ref_model, &grandparent2, 2);
2790 assert_node_ref_count (ref_model, &parent1, 2);
2791 assert_node_ref_count (ref_model, &parent2, 1);
2792 assert_node_ref_count (ref_model, &iter_parent1, 1);
2793 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2794 assert_node_ref_count (ref_model, &iter_parent2, 0);
2796 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2798 assert_node_ref_count (ref_model, &grandparent1, 2);
2799 assert_node_ref_count (ref_model, &grandparent2, 2);
2800 assert_node_ref_count (ref_model, &parent1, 1);
2801 assert_node_ref_count (ref_model, &parent2, 0);
2802 assert_node_ref_count (ref_model, &iter_parent1, 0);
2803 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2804 assert_node_ref_count (ref_model, &iter_parent2, 0);
2806 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2808 assert_node_ref_count (ref_model, &grandparent1, 2);
2809 assert_node_ref_count (ref_model, &grandparent2, 2);
2810 assert_node_ref_count (ref_model, &parent1, 3);
2811 assert_node_ref_count (ref_model, &parent2, 2);
2812 assert_node_ref_count (ref_model, &iter_parent1, 1);
2813 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2814 assert_node_ref_count (ref_model, &iter_parent2, 0);
2816 gtk_tree_path_append_index (path, 1);
2817 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
2819 assert_node_ref_count (ref_model, &grandparent1, 2);
2820 assert_node_ref_count (ref_model, &grandparent2, 2);
2821 assert_node_ref_count (ref_model, &parent1, 3);
2822 assert_node_ref_count (ref_model, &parent2, 2);
2823 assert_node_ref_count (ref_model, &iter_parent1, 1);
2824 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2825 assert_node_ref_count (ref_model, &iter_parent2, 1);
2827 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2829 assert_node_ref_count (ref_model, &grandparent1, 2);
2830 assert_node_ref_count (ref_model, &grandparent2, 2);
2831 assert_node_ref_count (ref_model, &parent1, 3);
2832 assert_node_ref_count (ref_model, &parent2, 2);
2833 assert_node_ref_count (ref_model, &iter_parent1, 1);
2834 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2835 assert_node_ref_count (ref_model, &iter_parent2, 0);
2837 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2839 assert_node_ref_count (ref_model, &grandparent1, 2);
2840 assert_node_ref_count (ref_model, &grandparent2, 2);
2841 assert_node_ref_count (ref_model, &parent1, 3);
2842 assert_node_ref_count (ref_model, &parent2, 2);
2843 assert_node_ref_count (ref_model, &iter_parent1, 1);
2844 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2845 assert_node_ref_count (ref_model, &iter_parent2, 0);
2847 gtk_tree_path_up (path);
2848 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path);
2849 gtk_tree_path_free (path);
2851 assert_node_ref_count (ref_model, &grandparent1, 2);
2852 assert_node_ref_count (ref_model, &grandparent2, 2);
2853 assert_node_ref_count (ref_model, &parent1, 2);
2854 assert_node_ref_count (ref_model, &parent2, 1);
2855 assert_node_ref_count (ref_model, &iter_parent1, 1);
2856 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
2857 assert_node_ref_count (ref_model, &iter_parent2, 0);
2859 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2861 assert_node_ref_count (ref_model, &grandparent1, 2);
2862 assert_node_ref_count (ref_model, &grandparent2, 2);
2863 assert_node_ref_count (ref_model, &parent1, 1);
2864 assert_node_ref_count (ref_model, &parent2, 0);
2865 assert_node_ref_count (ref_model, &iter_parent1, 0);
2866 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2867 assert_node_ref_count (ref_model, &iter_parent2, 0);
2869 gtk_widget_destroy (tree_view);
2871 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2873 /* The root level and first level remain cached, only the references on the
2874 * first nodes of these levels are kept. Grandparent2 is the parent
2875 * of the first level with parent1, so grandparent2 keeps a reference
2878 assert_node_ref_count (ref_model, &grandparent1, 1);
2879 assert_node_ref_count (ref_model, &grandparent2, 1);
2880 assert_node_ref_count (ref_model, &parent1, 1);
2881 assert_node_ref_count (ref_model, &parent2, 0);
2882 assert_node_ref_count (ref_model, &iter_parent1, 0);
2883 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
2884 assert_node_ref_count (ref_model, &iter_parent2, 0);
2886 g_object_unref (filter_model);
2887 g_object_unref (ref_model);
2891 ref_count_delete_row (void)
2893 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
2894 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
2895 GtkTreeModel *model;
2896 GtkTreeModelRefCount *ref_model;
2897 GtkTreeModel *filter_model;
2899 GtkWidget *tree_view;
2901 model = gtk_tree_model_ref_count_new ();
2902 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2909 * + iter_parent2_first
2913 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
2914 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
2915 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
2916 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
2917 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
2918 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
2919 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
2921 assert_entire_model_unreferenced (ref_model);
2923 filter_model = gtk_tree_model_filter_new (model, NULL);
2924 tree_view = gtk_tree_view_new_with_model (filter_model);
2926 assert_root_level_referenced (ref_model, 2);
2927 assert_node_ref_count (ref_model, &parent1, 1);
2928 assert_node_ref_count (ref_model, &parent2, 0);
2929 assert_level_unreferenced (ref_model, &parent1);
2930 assert_level_unreferenced (ref_model, &parent2);
2932 path = gtk_tree_path_new_from_indices (1, -1);
2933 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
2934 gtk_tree_path_free (path);
2936 assert_node_ref_count (ref_model, &grandparent1, 2);
2937 assert_node_ref_count (ref_model, &grandparent2, 2);
2938 assert_node_ref_count (ref_model, &parent1, 3);
2939 assert_node_ref_count (ref_model, &parent2, 2);
2940 assert_node_ref_count (ref_model, &iter_parent1, 2);
2941 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2942 assert_node_ref_count (ref_model, &iter_parent2, 1);
2944 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter_parent2);
2946 assert_node_ref_count (ref_model, &grandparent1, 2);
2947 assert_node_ref_count (ref_model, &grandparent2, 2);
2948 assert_node_ref_count (ref_model, &parent1, 3);
2949 assert_node_ref_count (ref_model, &parent2, 2);
2950 assert_node_ref_count (ref_model, &iter_parent1, 2);
2951 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
2953 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1);
2955 assert_node_ref_count (ref_model, &grandparent1, 2);
2956 assert_node_ref_count (ref_model, &grandparent2, 2);
2957 assert_node_ref_count (ref_model, &parent2, 3);
2958 assert_level_referenced (ref_model, 2, &parent2);
2960 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
2962 assert_node_ref_count (ref_model, &grandparent1, 2);
2964 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2966 assert_node_ref_count (ref_model, &grandparent1, 2);
2968 gtk_widget_destroy (tree_view);
2969 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
2971 assert_node_ref_count (ref_model, &grandparent1, 1);
2973 g_object_unref (filter_model);
2975 assert_node_ref_count (ref_model, &grandparent1, 0);
2977 g_object_unref (ref_model);
2981 ref_count_filter_row_length_1 (void)
2983 GtkTreeIter level1_1;
2984 GtkTreeIter level2_1;
2985 GtkTreeIter level3_1;
2986 GtkTreeIter level4_1;
2987 GtkTreeModel *model;
2988 GtkTreeModelRefCount *ref_model;
2989 GtkTreeModel *filter_model;
2991 GtkWidget *tree_view;
2992 GType column_types[] = { G_TYPE_BOOLEAN };
2994 model = gtk_tree_model_ref_count_new ();
2995 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
2997 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3006 * Node level1_1 is expanded. This makes that levels 1 and 2 are
3007 * visible. Level 3 is cached because its parent is visible. Level 4
3011 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3012 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3013 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3014 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3016 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3017 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3018 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3019 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3021 assert_entire_model_unreferenced (ref_model);
3023 filter_model = gtk_tree_model_filter_new (model, NULL);
3024 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3025 tree_view = gtk_tree_view_new_with_model (filter_model);
3027 assert_node_ref_count (ref_model, &level1_1, 3);
3028 assert_node_ref_count (ref_model, &level2_1, 1);
3029 assert_node_ref_count (ref_model, &level3_1, 0);
3030 assert_node_ref_count (ref_model, &level4_1, 0);
3032 path = gtk_tree_path_new_from_indices (0, -1);
3033 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
3034 gtk_tree_path_free (path);
3036 assert_node_ref_count (ref_model, &level1_1, 3);
3037 assert_node_ref_count (ref_model, &level2_1, 3);
3038 assert_node_ref_count (ref_model, &level3_1, 1);
3039 assert_node_ref_count (ref_model, &level4_1, 0);
3041 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, FALSE, -1);
3043 assert_node_ref_count (ref_model, &level1_1, 3);
3044 assert_node_ref_count (ref_model, &level2_1, 3);
3045 assert_node_ref_count (ref_model, &level3_1, 1);
3046 assert_node_ref_count (ref_model, &level4_1, 0);
3048 /* level3_1 has a visible parent, so the node is kept in the cache. */
3049 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, FALSE, -1);
3051 assert_node_ref_count (ref_model, &level1_1, 3);
3052 assert_node_ref_count (ref_model, &level2_1, 3);
3053 assert_node_ref_count (ref_model, &level3_1, 1);
3054 assert_node_ref_count (ref_model, &level4_1, 0);
3056 /* level2_1 has a visible parent, so is kept in the cache. However,
3057 * the external reference should be released.
3059 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, FALSE, -1);
3061 assert_node_ref_count (ref_model, &level1_1, 3);
3062 assert_node_ref_count (ref_model, &level2_1, 1);
3063 assert_node_ref_count (ref_model, &level3_1, 0);
3064 assert_node_ref_count (ref_model, &level4_1, 0);
3066 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, FALSE, -1);
3068 assert_node_ref_count (ref_model, &level1_1, 2);
3069 assert_node_ref_count (ref_model, &level2_1, 1);
3070 assert_node_ref_count (ref_model, &level3_1, 0);
3071 assert_node_ref_count (ref_model, &level4_1, 0);
3073 gtk_widget_destroy (tree_view);
3074 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3076 assert_node_ref_count (ref_model, &level1_1, 2);
3077 assert_node_ref_count (ref_model, &level2_1, 1);
3079 g_object_unref (filter_model);
3081 assert_node_ref_count (ref_model, &level1_1, 0);
3083 g_object_unref (ref_model);
3087 ref_count_filter_row_length_1_remove_in_root_level (void)
3089 GtkTreeIter level1_1;
3090 GtkTreeIter level2_1;
3091 GtkTreeIter level3_1;
3092 GtkTreeIter level4_1;
3093 GtkTreeModel *model;
3094 GtkTreeModelRefCount *ref_model;
3095 GtkTreeModel *filter_model;
3097 GtkWidget *tree_view;
3098 GType column_types[] = { G_TYPE_BOOLEAN };
3100 model = gtk_tree_model_ref_count_new ();
3101 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3103 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3113 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3114 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3115 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3116 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3118 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3119 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3120 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3121 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3123 assert_entire_model_unreferenced (ref_model);
3125 filter_model = gtk_tree_model_filter_new (model, NULL);
3126 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3127 tree_view = gtk_tree_view_new_with_model (filter_model);
3129 assert_node_ref_count (ref_model, &level1_1, 3);
3130 assert_node_ref_count (ref_model, &level2_1, 1);
3131 assert_node_ref_count (ref_model, &level3_1, 0);
3132 assert_node_ref_count (ref_model, &level4_1, 0);
3134 path = gtk_tree_path_new_from_indices (0, -1);
3135 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3136 gtk_tree_path_free (path);
3138 assert_node_ref_count (ref_model, &level1_1, 3);
3139 assert_node_ref_count (ref_model, &level2_1, 3);
3140 assert_node_ref_count (ref_model, &level3_1, 3);
3141 assert_node_ref_count (ref_model, &level4_1, 2);
3143 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, FALSE, -1);
3145 assert_node_ref_count (ref_model, &level1_1, 2);
3146 assert_node_ref_count (ref_model, &level2_1, 1);
3147 assert_node_ref_count (ref_model, &level3_1, 0);
3148 assert_node_ref_count (ref_model, &level4_1, 0);
3150 gtk_widget_destroy (tree_view);
3151 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3153 assert_node_ref_count (ref_model, &level1_1, 2);
3154 assert_node_ref_count (ref_model, &level2_1, 1);
3155 assert_node_ref_count (ref_model, &level3_1, 0);
3156 assert_node_ref_count (ref_model, &level4_1, 0);
3158 g_object_unref (filter_model);
3160 assert_node_ref_count (ref_model, &level1_1, 0);
3161 assert_node_ref_count (ref_model, &level2_1, 0);
3162 assert_node_ref_count (ref_model, &level3_1, 0);
3163 assert_node_ref_count (ref_model, &level4_1, 0);
3165 g_object_unref (ref_model);
3169 ref_count_filter_row_length_1_remove_in_child_level (void)
3171 GtkTreeIter level1_1;
3172 GtkTreeIter level2_1;
3173 GtkTreeIter level3_1;
3174 GtkTreeIter level4_1;
3175 GtkTreeModel *model;
3176 GtkTreeModelRefCount *ref_model;
3177 GtkTreeModel *filter_model;
3179 GtkWidget *tree_view;
3180 GType column_types[] = { G_TYPE_BOOLEAN };
3182 model = gtk_tree_model_ref_count_new ();
3183 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3185 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3195 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3196 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_1);
3197 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_1);
3198 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_1);
3200 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3201 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3202 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3203 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3205 assert_entire_model_unreferenced (ref_model);
3207 filter_model = gtk_tree_model_filter_new (model, NULL);
3208 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3209 tree_view = gtk_tree_view_new_with_model (filter_model);
3211 assert_node_ref_count (ref_model, &level1_1, 3);
3212 assert_node_ref_count (ref_model, &level2_1, 1);
3213 assert_node_ref_count (ref_model, &level3_1, 0);
3214 assert_node_ref_count (ref_model, &level4_1, 0);
3216 path = gtk_tree_path_new_from_indices (0, -1);
3217 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3218 gtk_tree_path_free (path);
3220 assert_node_ref_count (ref_model, &level1_1, 3);
3221 assert_node_ref_count (ref_model, &level2_1, 3);
3222 assert_node_ref_count (ref_model, &level3_1, 3);
3223 assert_node_ref_count (ref_model, &level4_1, 2);
3225 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, FALSE, -1);
3227 assert_node_ref_count (ref_model, &level1_1, 3);
3228 assert_node_ref_count (ref_model, &level2_1, 1);
3229 assert_node_ref_count (ref_model, &level3_1, 0);
3230 assert_node_ref_count (ref_model, &level4_1, 0);
3232 gtk_widget_destroy (tree_view);
3233 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3235 assert_node_ref_count (ref_model, &level1_1, 2);
3236 assert_node_ref_count (ref_model, &level2_1, 1);
3237 assert_node_ref_count (ref_model, &level3_1, 0);
3238 assert_node_ref_count (ref_model, &level4_1, 0);
3240 g_object_unref (filter_model);
3242 assert_node_ref_count (ref_model, &level1_1, 0);
3243 assert_node_ref_count (ref_model, &level2_1, 0);
3244 assert_node_ref_count (ref_model, &level3_1, 0);
3245 assert_node_ref_count (ref_model, &level4_1, 0);
3247 g_object_unref (ref_model);
3251 ref_count_filter_row_length_gt_1 (void)
3253 GtkTreeIter level1_1, level1_2;
3254 GtkTreeIter level2_1, level2_2;
3255 GtkTreeIter level3_1, level3_2;
3256 GtkTreeIter level4_1, level4_2;
3257 GtkTreeModel *model;
3258 GtkTreeModelRefCount *ref_model;
3259 GtkTreeModel *filter_model;
3261 GtkWidget *tree_view;
3262 GType column_types[] = { G_TYPE_BOOLEAN };
3264 model = gtk_tree_model_ref_count_new ();
3265 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3267 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3280 * Node level1_2 is expanded. This makes that levels 1 and 2 are
3281 * visible. Level 3 is cached because its parent is visible. Level 4
3285 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3286 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_2, NULL);
3287 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_2);
3288 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_2, &level1_2);
3289 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_2);
3290 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_2, &level2_2);
3291 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_2);
3292 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_2, &level3_2);
3294 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3295 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, TRUE, -1);
3296 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3297 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, TRUE, -1);
3298 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3299 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_2, 0, TRUE, -1);
3300 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3301 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_2, 0, TRUE, -1);
3303 assert_entire_model_unreferenced (ref_model);
3305 filter_model = gtk_tree_model_filter_new (model, NULL);
3306 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3307 tree_view = gtk_tree_view_new_with_model (filter_model);
3309 assert_node_ref_count (ref_model, &level1_1, 2);
3310 assert_node_ref_count (ref_model, &level1_2, 2);
3311 assert_node_ref_count (ref_model, &level2_1, 1);
3312 assert_node_ref_count (ref_model, &level2_2, 0);
3313 assert_node_ref_count (ref_model, &level3_1, 0);
3314 assert_node_ref_count (ref_model, &level3_2, 0);
3315 assert_node_ref_count (ref_model, &level4_1, 0);
3316 assert_node_ref_count (ref_model, &level4_2, 0);
3318 path = gtk_tree_path_new_from_indices (1, -1);
3319 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
3320 gtk_tree_path_free (path);
3322 assert_node_ref_count (ref_model, &level1_1, 2);
3323 assert_node_ref_count (ref_model, &level1_2, 2);
3324 assert_node_ref_count (ref_model, &level2_1, 2);
3325 assert_node_ref_count (ref_model, &level2_2, 2);
3326 assert_node_ref_count (ref_model, &level3_1, 1);
3327 assert_node_ref_count (ref_model, &level3_2, 0);
3328 assert_node_ref_count (ref_model, &level4_1, 0);
3329 assert_node_ref_count (ref_model, &level4_2, 0);
3331 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, FALSE, -1);
3333 assert_node_ref_count (ref_model, &level1_1, 2);
3334 assert_node_ref_count (ref_model, &level1_2, 2);
3335 assert_node_ref_count (ref_model, &level2_1, 2);
3336 assert_node_ref_count (ref_model, &level2_2, 2);
3337 assert_node_ref_count (ref_model, &level3_1, 1);
3338 assert_node_ref_count (ref_model, &level3_2, 0);
3339 assert_node_ref_count (ref_model, &level4_1, 0);
3340 assert_node_ref_count (ref_model, &level4_2, 0);
3342 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, FALSE, -1);
3344 assert_node_ref_count (ref_model, &level1_1, 2);
3345 assert_node_ref_count (ref_model, &level1_2, 2);
3346 assert_node_ref_count (ref_model, &level2_1, 2);
3347 assert_node_ref_count (ref_model, &level2_2, 2);
3348 assert_node_ref_count (ref_model, &level3_1, 0);
3349 assert_node_ref_count (ref_model, &level3_2, 1);
3350 assert_node_ref_count (ref_model, &level4_1, 0);
3351 assert_node_ref_count (ref_model, &level4_2, 0);
3353 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, FALSE, -1);
3355 assert_node_ref_count (ref_model, &level1_1, 2);
3356 assert_node_ref_count (ref_model, &level1_2, 2);
3357 assert_node_ref_count (ref_model, &level2_1, 2);
3358 assert_node_ref_count (ref_model, &level2_2, 0);
3359 assert_node_ref_count (ref_model, &level3_1, 0);
3360 assert_node_ref_count (ref_model, &level3_2, 0);
3361 assert_node_ref_count (ref_model, &level4_1, 0);
3362 assert_node_ref_count (ref_model, &level4_2, 0);
3364 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, FALSE, -1);
3366 assert_node_ref_count (ref_model, &level1_1, 2);
3367 assert_node_ref_count (ref_model, &level1_2, 0);
3368 assert_node_ref_count (ref_model, &level2_1, 0);
3369 assert_node_ref_count (ref_model, &level2_2, 0);
3370 assert_node_ref_count (ref_model, &level3_1, 0);
3371 assert_node_ref_count (ref_model, &level3_2, 0);
3372 assert_node_ref_count (ref_model, &level4_1, 0);
3373 assert_node_ref_count (ref_model, &level4_2, 0);
3375 gtk_widget_destroy (tree_view);
3376 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3378 assert_node_ref_count (ref_model, &level1_1, 1);
3380 g_object_unref (filter_model);
3382 assert_node_ref_count (ref_model, &level1_1, 0);
3384 g_object_unref (ref_model);
3388 ref_count_filter_row_length_gt_1_visible_children (void)
3390 GtkTreeIter level1_1, level1_2;
3391 GtkTreeIter level2_1, level2_2;
3392 GtkTreeIter level3_1, level3_2;
3393 GtkTreeIter level4_1, level4_2;
3394 GtkTreeModel *model;
3395 GtkTreeModelRefCount *ref_model;
3396 GtkTreeModel *filter_model;
3398 GtkWidget *tree_view;
3399 GType column_types[] = { G_TYPE_BOOLEAN };
3401 model = gtk_tree_model_ref_count_new ();
3402 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3404 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3418 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_1, NULL);
3419 gtk_tree_store_append (GTK_TREE_STORE (model), &level1_2, NULL);
3420 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_1, &level1_2);
3421 gtk_tree_store_append (GTK_TREE_STORE (model), &level2_2, &level1_2);
3422 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_1, &level2_2);
3423 gtk_tree_store_append (GTK_TREE_STORE (model), &level3_2, &level2_2);
3424 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_1, &level3_2);
3425 gtk_tree_store_append (GTK_TREE_STORE (model), &level4_2, &level3_2);
3427 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_1, 0, TRUE, -1);
3428 gtk_tree_store_set (GTK_TREE_STORE (model), &level1_2, 0, TRUE, -1);
3429 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_1, 0, TRUE, -1);
3430 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, TRUE, -1);
3431 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_1, 0, TRUE, -1);
3432 gtk_tree_store_set (GTK_TREE_STORE (model), &level3_2, 0, TRUE, -1);
3433 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_1, 0, TRUE, -1);
3434 gtk_tree_store_set (GTK_TREE_STORE (model), &level4_2, 0, TRUE, -1);
3436 assert_entire_model_unreferenced (ref_model);
3438 filter_model = gtk_tree_model_filter_new (model, NULL);
3439 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3440 tree_view = gtk_tree_view_new_with_model (filter_model);
3442 assert_node_ref_count (ref_model, &level1_1, 2);
3443 assert_node_ref_count (ref_model, &level1_2, 2);
3444 assert_node_ref_count (ref_model, &level2_1, 1);
3445 assert_node_ref_count (ref_model, &level2_2, 0);
3446 assert_node_ref_count (ref_model, &level3_1, 0);
3447 assert_node_ref_count (ref_model, &level3_2, 0);
3448 assert_node_ref_count (ref_model, &level4_1, 0);
3449 assert_node_ref_count (ref_model, &level4_2, 0);
3451 path = gtk_tree_path_new_from_indices (1, -1);
3452 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE);
3453 gtk_tree_path_free (path);
3455 assert_node_ref_count (ref_model, &level1_1, 2);
3456 assert_node_ref_count (ref_model, &level1_2, 2);
3457 assert_node_ref_count (ref_model, &level2_1, 2);
3458 assert_node_ref_count (ref_model, &level2_2, 2);
3459 assert_node_ref_count (ref_model, &level3_1, 2);
3460 assert_node_ref_count (ref_model, &level3_2, 2);
3461 assert_node_ref_count (ref_model, &level4_1, 2);
3462 assert_node_ref_count (ref_model, &level4_2, 1);
3464 gtk_tree_store_set (GTK_TREE_STORE (model), &level2_2, 0, FALSE, -1);
3466 assert_node_ref_count (ref_model, &level1_1, 2);
3467 assert_node_ref_count (ref_model, &level1_2, 2);
3468 assert_node_ref_count (ref_model, &level2_1, 2);
3469 assert_node_ref_count (ref_model, &level2_2, 0);
3470 assert_node_ref_count (ref_model, &level3_1, 0);
3471 assert_node_ref_count (ref_model, &level3_2, 0);
3472 assert_node_ref_count (ref_model, &level4_1, 0);
3473 assert_node_ref_count (ref_model, &level4_2, 0);
3475 gtk_widget_destroy (tree_view);
3476 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3478 assert_node_ref_count (ref_model, &level1_1, 1);
3479 assert_node_ref_count (ref_model, &level1_2, 1);
3480 assert_node_ref_count (ref_model, &level2_1, 1);
3481 assert_node_ref_count (ref_model, &level2_2, 0);
3482 assert_node_ref_count (ref_model, &level3_1, 0);
3483 assert_node_ref_count (ref_model, &level3_2, 0);
3484 assert_node_ref_count (ref_model, &level4_1, 0);
3485 assert_node_ref_count (ref_model, &level4_2, 0);
3487 g_object_unref (filter_model);
3489 assert_node_ref_count (ref_model, &level1_1, 0);
3490 assert_node_ref_count (ref_model, &level1_2, 0);
3491 assert_node_ref_count (ref_model, &level2_1, 0);
3492 assert_node_ref_count (ref_model, &level2_2, 0);
3493 assert_node_ref_count (ref_model, &level3_1, 0);
3494 assert_node_ref_count (ref_model, &level3_2, 0);
3495 assert_node_ref_count (ref_model, &level4_1, 0);
3496 assert_node_ref_count (ref_model, &level4_2, 0);
3498 g_object_unref (ref_model);
3502 ref_count_cleanup (void)
3504 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
3505 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
3506 GtkTreeModel *model;
3507 GtkTreeModelRefCount *ref_model;
3508 GtkTreeModel *filter_model;
3509 GtkWidget *tree_view;
3511 model = gtk_tree_model_ref_count_new ();
3512 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3519 * + iter_parent2_first
3523 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3524 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3525 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
3526 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
3527 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
3528 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
3529 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
3531 filter_model = gtk_tree_model_filter_new (model, NULL);
3532 tree_view = gtk_tree_view_new_with_model (filter_model);
3534 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
3536 assert_node_ref_count (ref_model, &grandparent1, 2);
3537 assert_node_ref_count (ref_model, &grandparent2, 2);
3538 assert_node_ref_count (ref_model, &parent1, 3);
3539 assert_node_ref_count (ref_model, &parent2, 2);
3540 assert_node_ref_count (ref_model, &iter_parent1, 2);
3541 assert_node_ref_count (ref_model, &iter_parent2_first, 2);
3542 assert_node_ref_count (ref_model, &iter_parent2, 1);
3544 gtk_widget_destroy (tree_view);
3546 assert_node_ref_count (ref_model, &grandparent1, 1);
3547 assert_node_ref_count (ref_model, &grandparent2, 1);
3548 assert_node_ref_count (ref_model, &parent1, 2);
3549 assert_node_ref_count (ref_model, &parent2, 1);
3550 assert_node_ref_count (ref_model, &iter_parent1, 1);
3551 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3552 assert_node_ref_count (ref_model, &iter_parent2, 0);
3554 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3556 /* The root level and first level remain cached, only the references on the
3557 * first nodes of these levels are kept. Grandparent2 is the parent
3558 * of the first level with parent1, so grandparent2 keeps a reference
3561 assert_node_ref_count (ref_model, &grandparent1, 1);
3562 assert_node_ref_count (ref_model, &grandparent2, 1);
3563 assert_node_ref_count (ref_model, &parent1, 1);
3564 assert_node_ref_count (ref_model, &parent2, 0);
3565 assert_node_ref_count (ref_model, &iter_parent1, 0);
3566 assert_node_ref_count (ref_model, &iter_parent2_first, 0);
3567 assert_node_ref_count (ref_model, &iter_parent2, 0);
3569 g_object_unref (filter_model);
3570 g_object_unref (ref_model);
3574 ref_count_row_ref (void)
3576 GtkTreeIter grandparent1, grandparent2, parent1, parent2;
3577 GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first;
3578 GtkTreeModel *model;
3579 GtkTreeModelRefCount *ref_model;
3580 GtkTreeModel *filter_model;
3581 GtkWidget *tree_view;
3583 GtkTreeRowReference *row_ref;
3585 model = gtk_tree_model_ref_count_new ();
3586 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3597 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3598 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3599 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2);
3600 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1);
3601 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2);
3602 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2);
3603 gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2);
3605 filter_model = gtk_tree_model_filter_new (model, NULL);
3606 tree_view = gtk_tree_view_new_with_model (filter_model);
3608 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3609 row_ref = gtk_tree_row_reference_new (filter_model, path);
3610 gtk_tree_path_free (path);
3612 assert_node_ref_count (ref_model, &grandparent1, 2);
3613 assert_node_ref_count (ref_model, &grandparent2, 3);
3614 assert_node_ref_count (ref_model, &parent1, 1);
3615 assert_node_ref_count (ref_model, &parent2, 2);
3616 assert_node_ref_count (ref_model, &iter_parent1, 0);
3617 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3618 assert_node_ref_count (ref_model, &iter_parent2, 1);
3620 gtk_tree_row_reference_free (row_ref);
3622 assert_node_ref_count (ref_model, &grandparent1, 2);
3623 assert_node_ref_count (ref_model, &grandparent2, 2);
3624 assert_node_ref_count (ref_model, &parent1, 1);
3625 assert_node_ref_count (ref_model, &parent2, 1);
3626 assert_node_ref_count (ref_model, &iter_parent1, 0);
3627 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3628 assert_node_ref_count (ref_model, &iter_parent2, 0);
3630 path = gtk_tree_path_new_from_indices (1, 1, 1, -1);
3631 row_ref = gtk_tree_row_reference_new (filter_model, path);
3632 gtk_tree_path_free (path);
3634 assert_node_ref_count (ref_model, &grandparent1, 2);
3635 assert_node_ref_count (ref_model, &grandparent2, 3);
3636 assert_node_ref_count (ref_model, &parent1, 1);
3637 assert_node_ref_count (ref_model, &parent2, 2);
3638 assert_node_ref_count (ref_model, &iter_parent1, 0);
3639 assert_node_ref_count (ref_model, &iter_parent2_first, 1);
3640 assert_node_ref_count (ref_model, &iter_parent2, 1);
3642 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
3644 assert_node_ref_count (ref_model, &grandparent1, 2);
3645 assert_node_ref_count (ref_model, &grandparent2, 2);
3646 assert_node_ref_count (ref_model, &parent1, 1);
3647 assert_node_ref_count (ref_model, &iter_parent1, 0);
3649 gtk_tree_row_reference_free (row_ref);
3651 assert_node_ref_count (ref_model, &grandparent1, 2);
3652 assert_node_ref_count (ref_model, &grandparent2, 2);
3653 assert_node_ref_count (ref_model, &parent1, 1);
3654 assert_node_ref_count (ref_model, &iter_parent1, 0);
3656 gtk_widget_destroy (tree_view);
3658 gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model));
3660 /* The root level and first level remain cached, only the references on the
3661 * first nodes of these levels are kept. Grandparent2 is the parent
3662 * of the first level with parent1, so grandparent2 keeps a reference
3665 assert_node_ref_count (ref_model, &grandparent1, 1);
3666 assert_node_ref_count (ref_model, &grandparent2, 1);
3667 assert_node_ref_count (ref_model, &parent1, 1);
3669 g_object_unref (filter_model);
3670 g_object_unref (ref_model);
3674 ref_count_transfer_root_level_insert (void)
3676 GtkTreeIter grandparent1, grandparent2, grandparent3;
3677 GtkTreeIter new_node;
3678 GtkTreeModel *model;
3679 GtkTreeModelRefCount *ref_model;
3680 GtkTreeModel *filter_model;
3681 GtkWidget *tree_view;
3683 model = gtk_tree_model_ref_count_new ();
3684 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3691 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3692 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3693 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3695 filter_model = gtk_tree_model_filter_new (model, NULL);
3696 tree_view = gtk_tree_view_new_with_model (filter_model);
3698 assert_node_ref_count (ref_model, &grandparent1, 2);
3699 assert_node_ref_count (ref_model, &grandparent2, 1);
3700 assert_node_ref_count (ref_model, &grandparent3, 1);
3702 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
3704 assert_node_ref_count (ref_model, &new_node, 2);
3705 assert_node_ref_count (ref_model, &grandparent1, 1);
3706 assert_node_ref_count (ref_model, &grandparent2, 1);
3707 assert_node_ref_count (ref_model, &grandparent3, 1);
3709 gtk_widget_destroy (tree_view);
3710 g_object_unref (filter_model);
3711 g_object_unref (ref_model);
3715 ref_count_transfer_root_level_remove (void)
3717 GtkTreeIter grandparent1, grandparent2, grandparent3;
3718 GtkTreeModel *model;
3719 GtkTreeModelRefCount *ref_model;
3720 GtkTreeModel *filter_model;
3721 GtkWidget *tree_view;
3723 model = gtk_tree_model_ref_count_new ();
3724 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3731 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3732 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3733 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3735 filter_model = gtk_tree_model_filter_new (model, NULL);
3736 tree_view = gtk_tree_view_new_with_model (filter_model);
3738 assert_node_ref_count (ref_model, &grandparent1, 2);
3739 assert_node_ref_count (ref_model, &grandparent2, 1);
3740 assert_node_ref_count (ref_model, &grandparent3, 1);
3742 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent1);
3744 assert_node_ref_count (ref_model, &grandparent2, 2);
3745 assert_node_ref_count (ref_model, &grandparent3, 1);
3747 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
3749 assert_node_ref_count (ref_model, &grandparent3, 2);
3751 gtk_widget_destroy (tree_view);
3752 g_object_unref (filter_model);
3753 g_object_unref (ref_model);
3757 ref_count_transfer_root_level_remove_filtered (void)
3759 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
3760 GtkTreeModel *model;
3761 GtkTreeModelRefCount *ref_model;
3762 GtkTreeModel *filter_model;
3763 GtkWidget *tree_view;
3764 GType column_types[] = { G_TYPE_BOOLEAN };
3766 model = gtk_tree_model_ref_count_new ();
3767 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3769 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3778 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3779 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3780 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3781 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, NULL);
3783 /* Filter first node */
3784 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
3785 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3786 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
3787 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
3789 filter_model = gtk_tree_model_filter_new (model, NULL);
3790 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3791 tree_view = gtk_tree_view_new_with_model (filter_model);
3793 assert_node_ref_count (ref_model, &grandparent1, 0);
3794 assert_node_ref_count (ref_model, &grandparent2, 2);
3795 assert_node_ref_count (ref_model, &grandparent3, 1);
3796 assert_node_ref_count (ref_model, &grandparent4, 1);
3798 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
3800 assert_node_ref_count (ref_model, &grandparent1, 0);
3801 assert_node_ref_count (ref_model, &grandparent3, 2);
3802 assert_node_ref_count (ref_model, &grandparent4, 1);
3804 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent3);
3806 assert_node_ref_count (ref_model, &grandparent1, 0);
3807 assert_node_ref_count (ref_model, &grandparent4, 2);
3809 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent4);
3811 /* Check level length to get root level cached again */
3812 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), NULL, 0);
3814 assert_node_ref_count (ref_model, &grandparent1, 1);
3816 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3818 assert_node_ref_count (ref_model, &grandparent1, 1);
3819 assert_node_ref_count (ref_model, &grandparent2, 0);
3821 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3823 assert_node_ref_count (ref_model, &grandparent1, 1);
3824 assert_node_ref_count (ref_model, &grandparent2, 1);
3826 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), NULL, 1);
3828 gtk_widget_destroy (tree_view);
3829 g_object_unref (filter_model);
3830 g_object_unref (ref_model);
3834 ref_count_transfer_root_level_reordered (void)
3836 GtkTreeIter grandparent1, grandparent2, grandparent3;
3837 GtkTreeModel *model;
3838 GtkTreeModelRefCount *ref_model;
3839 GtkTreeModel *filter_model;
3840 GtkWidget *tree_view;
3842 model = gtk_tree_model_ref_count_new ();
3843 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3850 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3851 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3852 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3854 filter_model = gtk_tree_model_filter_new (model, NULL);
3855 tree_view = gtk_tree_view_new_with_model (filter_model);
3857 assert_node_ref_count (ref_model, &grandparent1, 2);
3858 assert_node_ref_count (ref_model, &grandparent2, 1);
3859 assert_node_ref_count (ref_model, &grandparent3, 1);
3861 /* gtk_tree_store_move() will emit rows-reordered */
3862 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3863 &grandparent1, &grandparent3);
3865 assert_node_ref_count (ref_model, &grandparent2, 2);
3866 assert_node_ref_count (ref_model, &grandparent3, 1);
3867 assert_node_ref_count (ref_model, &grandparent1, 1);
3869 gtk_widget_destroy (tree_view);
3870 g_object_unref (filter_model);
3871 g_object_unref (ref_model);
3875 ref_count_transfer_root_level_reordered_filtered (void)
3877 GtkTreeIter grandparent1, grandparent2, grandparent3;
3878 GtkTreeModel *model;
3879 GtkTreeModelRefCount *ref_model;
3880 GtkTreeModel *filter_model;
3881 GtkWidget *tree_view;
3882 GType column_types[] = { G_TYPE_BOOLEAN };
3884 model = gtk_tree_model_ref_count_new ();
3885 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3887 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3895 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3896 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
3897 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
3899 /* Test with 1 node filtered */
3900 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
3901 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
3903 filter_model = gtk_tree_model_filter_new (model, NULL);
3904 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
3905 tree_view = gtk_tree_view_new_with_model (filter_model);
3907 assert_node_ref_count (ref_model, &grandparent1, 0);
3908 assert_node_ref_count (ref_model, &grandparent2, 2);
3909 assert_node_ref_count (ref_model, &grandparent3, 1);
3911 /* Move the invisible node grandparent1 */
3913 /* gtk_tree_store_move() will emit rows-reordered */
3914 gtk_tree_store_move_after (GTK_TREE_STORE (model),
3915 &grandparent1, &grandparent3);
3917 assert_node_ref_count (ref_model, &grandparent2, 2);
3918 assert_node_ref_count (ref_model, &grandparent3, 1);
3919 assert_node_ref_count (ref_model, &grandparent1, 0);
3921 /* Move the invisible node grandparent1 */
3923 /* gtk_tree_store_move() will emit rows-reordered */
3924 gtk_tree_store_move_before (GTK_TREE_STORE (model),
3925 &grandparent1, &grandparent2);
3927 assert_node_ref_count (ref_model, &grandparent1, 0);
3928 assert_node_ref_count (ref_model, &grandparent2, 2);
3929 assert_node_ref_count (ref_model, &grandparent3, 1);
3931 /* Now swap grandparent2 and grandparent3, first reference must transfer */
3932 /* gtk_tree_store_swap() will emit rows-reordered */
3933 gtk_tree_store_swap (GTK_TREE_STORE (model),
3934 &grandparent2, &grandparent3);
3936 assert_node_ref_count (ref_model, &grandparent1, 0);
3937 assert_node_ref_count (ref_model, &grandparent3, 2);
3938 assert_node_ref_count (ref_model, &grandparent2, 1);
3941 gtk_tree_store_swap (GTK_TREE_STORE (model),
3942 &grandparent2, &grandparent3);
3944 assert_node_ref_count (ref_model, &grandparent1, 0);
3945 assert_node_ref_count (ref_model, &grandparent2, 2);
3946 assert_node_ref_count (ref_model, &grandparent3, 1);
3948 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
3950 assert_node_ref_count (ref_model, &grandparent1, 2);
3951 assert_node_ref_count (ref_model, &grandparent2, 1);
3952 assert_node_ref_count (ref_model, &grandparent3, 1);
3954 /* Test with two nodes filtered */
3955 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
3956 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
3958 assert_node_ref_count (ref_model, &grandparent1, 0);
3959 assert_node_ref_count (ref_model, &grandparent2, 0);
3960 assert_node_ref_count (ref_model, &grandparent3, 2);
3962 /* gtk_tree_store_move() will emit rows-reordered */
3963 gtk_tree_store_move_before (GTK_TREE_STORE (model),
3964 &grandparent3, &grandparent1);
3966 assert_node_ref_count (ref_model, &grandparent3, 2);
3967 assert_node_ref_count (ref_model, &grandparent2, 0);
3968 assert_node_ref_count (ref_model, &grandparent1, 0);
3970 gtk_widget_destroy (tree_view);
3971 g_object_unref (filter_model);
3972 g_object_unref (ref_model);
3976 ref_count_transfer_root_level_filter (void)
3978 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
3979 GtkTreeIter new_node;
3980 GtkTreeModel *model;
3981 GtkTreeModelRefCount *ref_model;
3982 GtkTreeModel *filter_model;
3983 GtkWidget *tree_view;
3984 GType column_types[] = { G_TYPE_BOOLEAN };
3986 model = gtk_tree_model_ref_count_new ();
3987 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
3989 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
3998 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
3999 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL);
4000 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, NULL);
4001 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, NULL);
4003 /* Filter first node */
4004 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4005 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4006 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
4007 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4009 filter_model = gtk_tree_model_filter_new (model, NULL);
4010 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4011 tree_view = gtk_tree_view_new_with_model (filter_model);
4013 assert_node_ref_count (ref_model, &grandparent1, 0);
4014 assert_node_ref_count (ref_model, &grandparent2, 2);
4015 assert_node_ref_count (ref_model, &grandparent3, 1);
4016 assert_node_ref_count (ref_model, &grandparent4, 1);
4018 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4020 assert_node_ref_count (ref_model, &grandparent1, 0);
4021 assert_node_ref_count (ref_model, &grandparent2, 0);
4022 assert_node_ref_count (ref_model, &grandparent3, 2);
4023 assert_node_ref_count (ref_model, &grandparent4, 1);
4025 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, FALSE, -1);
4027 assert_node_ref_count (ref_model, &grandparent1, 0);
4028 assert_node_ref_count (ref_model, &grandparent2, 0);
4029 assert_node_ref_count (ref_model, &grandparent3, 0);
4030 assert_node_ref_count (ref_model, &grandparent4, 2);
4032 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, FALSE, -1);
4034 assert_node_ref_count (ref_model, &grandparent1, 0);
4035 assert_node_ref_count (ref_model, &grandparent2, 0);
4036 assert_node_ref_count (ref_model, &grandparent3, 0);
4037 assert_node_ref_count (ref_model, &grandparent4, 1);
4039 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4041 assert_node_ref_count (ref_model, &grandparent1, 0);
4042 assert_node_ref_count (ref_model, &grandparent2, 2);
4043 assert_node_ref_count (ref_model, &grandparent3, 0);
4044 assert_node_ref_count (ref_model, &grandparent4, 0);
4046 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4048 assert_node_ref_count (ref_model, &grandparent1, 0);
4049 assert_node_ref_count (ref_model, &grandparent2, 0);
4050 assert_node_ref_count (ref_model, &grandparent3, 0);
4051 assert_node_ref_count (ref_model, &grandparent4, 1);
4053 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4055 assert_node_ref_count (ref_model, &grandparent1, 2);
4056 assert_node_ref_count (ref_model, &grandparent2, 0);
4057 assert_node_ref_count (ref_model, &grandparent3, 0);
4058 assert_node_ref_count (ref_model, &grandparent4, 0);
4060 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
4062 assert_node_ref_count (ref_model, &new_node, 0);
4063 assert_node_ref_count (ref_model, &grandparent1, 2);
4064 assert_node_ref_count (ref_model, &grandparent2, 0);
4065 assert_node_ref_count (ref_model, &grandparent3, 0);
4066 assert_node_ref_count (ref_model, &grandparent4, 0);
4068 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4070 assert_node_ref_count (ref_model, &new_node, 0);
4071 assert_node_ref_count (ref_model, &grandparent1, 0);
4072 assert_node_ref_count (ref_model, &grandparent2, 0);
4073 assert_node_ref_count (ref_model, &grandparent3, 0);
4074 assert_node_ref_count (ref_model, &grandparent4, 1);
4076 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4077 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, NULL);
4079 assert_node_ref_count (ref_model, &new_node, 0);
4080 assert_node_ref_count (ref_model, &grandparent1, 0);
4081 assert_node_ref_count (ref_model, &grandparent2, 0);
4082 assert_node_ref_count (ref_model, &grandparent3, 0);
4083 assert_node_ref_count (ref_model, &grandparent4, 1);
4085 gtk_tree_store_set (GTK_TREE_STORE (model), &new_node, 0, TRUE, -1);
4087 assert_node_ref_count (ref_model, &new_node, 2);
4088 assert_node_ref_count (ref_model, &grandparent1, 0);
4089 assert_node_ref_count (ref_model, &grandparent2, 0);
4090 assert_node_ref_count (ref_model, &grandparent3, 0);
4091 assert_node_ref_count (ref_model, &grandparent4, 0);
4093 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4094 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4096 assert_node_ref_count (ref_model, &grandparent1, 0);
4097 assert_node_ref_count (ref_model, &grandparent2, 2);
4098 assert_node_ref_count (ref_model, &grandparent3, 0);
4099 assert_node_ref_count (ref_model, &grandparent4, 0);
4101 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4102 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
4104 gtk_widget_destroy (tree_view);
4105 g_object_unref (filter_model);
4106 g_object_unref (ref_model);
4110 ref_count_transfer_child_level_insert (void)
4112 GtkTreeIter grandparent1;
4113 GtkTreeIter parent1, parent2, parent3;
4114 GtkTreeIter new_node;
4115 GtkTreeModel *model;
4116 GtkTreeModelRefCount *ref_model;
4117 GtkTreeModel *filter_model;
4118 GtkWidget *tree_view;
4120 model = gtk_tree_model_ref_count_new ();
4121 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4129 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4130 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4131 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4132 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4134 filter_model = gtk_tree_model_filter_new (model, NULL);
4135 tree_view = gtk_tree_view_new_with_model (filter_model);
4137 assert_node_ref_count (ref_model, &grandparent1, 3);
4138 assert_node_ref_count (ref_model, &parent1, 1);
4139 assert_node_ref_count (ref_model, &parent2, 0);
4140 assert_node_ref_count (ref_model, &parent3, 0);
4142 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &grandparent1);
4144 assert_node_ref_count (ref_model, &grandparent1, 3);
4145 assert_node_ref_count (ref_model, &new_node, 1);
4146 assert_node_ref_count (ref_model, &parent1, 0);
4147 assert_node_ref_count (ref_model, &parent2, 0);
4148 assert_node_ref_count (ref_model, &parent3, 0);
4150 gtk_widget_destroy (tree_view);
4151 g_object_unref (filter_model);
4152 g_object_unref (ref_model);
4156 ref_count_transfer_child_level_remove (void)
4158 GtkTreeIter grandparent1;
4159 GtkTreeIter parent1, parent2, parent3;
4160 GtkTreeModel *model;
4161 GtkTreeModelRefCount *ref_model;
4162 GtkTreeModel *filter_model;
4163 GtkWidget *tree_view;
4165 model = gtk_tree_model_ref_count_new ();
4166 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4174 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4175 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4176 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4177 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4179 filter_model = gtk_tree_model_filter_new (model, NULL);
4180 tree_view = gtk_tree_view_new_with_model (filter_model);
4182 assert_node_ref_count (ref_model, &grandparent1, 3);
4183 assert_node_ref_count (ref_model, &parent1, 1);
4184 assert_node_ref_count (ref_model, &parent2, 0);
4185 assert_node_ref_count (ref_model, &parent3, 0);
4187 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1);
4189 assert_node_ref_count (ref_model, &grandparent1, 3);
4190 assert_node_ref_count (ref_model, &parent2, 1);
4191 assert_node_ref_count (ref_model, &parent3, 0);
4193 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
4195 assert_node_ref_count (ref_model, &grandparent1, 3);
4196 assert_node_ref_count (ref_model, &parent3, 1);
4198 gtk_widget_destroy (tree_view);
4199 g_object_unref (filter_model);
4200 g_object_unref (ref_model);
4204 ref_count_transfer_child_level_remove_filtered (void)
4206 GtkTreeIter grandparent1;
4207 GtkTreeIter parent1, parent2, parent3, parent4;
4208 GtkTreeModel *model;
4209 GtkTreeModelRefCount *ref_model;
4210 GtkTreeModel *filter_model;
4211 GtkWidget *tree_view;
4212 GType column_types[] = { G_TYPE_BOOLEAN };
4214 model = gtk_tree_model_ref_count_new ();
4215 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4217 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4227 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4228 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4229 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4230 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4231 gtk_tree_store_append (GTK_TREE_STORE (model), &parent4, &grandparent1);
4233 /* Filter first node */
4234 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4235 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, FALSE, -1);
4236 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4237 gtk_tree_store_set (GTK_TREE_STORE (model), &parent3, 0, TRUE, -1);
4238 gtk_tree_store_set (GTK_TREE_STORE (model), &parent4, 0, TRUE, -1);
4240 filter_model = gtk_tree_model_filter_new (model, NULL);
4241 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4242 tree_view = gtk_tree_view_new_with_model (filter_model);
4244 assert_node_ref_count (ref_model, &grandparent1, 3);
4245 assert_node_ref_count (ref_model, &parent1, 0);
4246 assert_node_ref_count (ref_model, &parent2, 1);
4247 assert_node_ref_count (ref_model, &parent3, 0);
4248 assert_node_ref_count (ref_model, &parent4, 0);
4250 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
4252 assert_node_ref_count (ref_model, &grandparent1, 3);
4253 assert_node_ref_count (ref_model, &parent1, 0);
4254 assert_node_ref_count (ref_model, &parent3, 1);
4255 assert_node_ref_count (ref_model, &parent4, 0);
4257 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent3);
4259 assert_node_ref_count (ref_model, &grandparent1, 3);
4260 assert_node_ref_count (ref_model, &parent1, 0);
4261 assert_node_ref_count (ref_model, &parent4, 1);
4263 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent4);
4265 /* Check level length to get level cached again */
4266 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), "0", 0);
4268 assert_node_ref_count (ref_model, &grandparent1, 3);
4269 assert_node_ref_count (ref_model, &parent1, 1);
4271 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4273 assert_node_ref_count (ref_model, &grandparent1, 3);
4274 assert_node_ref_count (ref_model, &parent1, 1);
4275 assert_node_ref_count (ref_model, &parent2, 0);
4277 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4279 assert_node_ref_count (ref_model, &grandparent1, 3);
4280 assert_node_ref_count (ref_model, &parent1, 1);
4281 assert_node_ref_count (ref_model, &parent2, 0);
4283 check_level_length (GTK_TREE_MODEL_FILTER (filter_model), "0", 1);
4285 gtk_widget_destroy (tree_view);
4286 g_object_unref (filter_model);
4287 g_object_unref (ref_model);
4291 ref_count_transfer_child_level_reordered (void)
4293 GtkTreeIter grandparent1;
4294 GtkTreeIter parent1, parent2, parent3;
4295 GtkTreeModel *model;
4296 GtkTreeModelRefCount *ref_model;
4297 GtkTreeModel *filter_model;
4298 GtkWidget *tree_view;
4300 model = gtk_tree_model_ref_count_new ();
4301 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4309 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4310 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4311 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4312 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4314 filter_model = gtk_tree_model_filter_new (model, NULL);
4315 tree_view = gtk_tree_view_new_with_model (filter_model);
4317 assert_node_ref_count (ref_model, &grandparent1, 3);
4318 assert_node_ref_count (ref_model, &parent1, 1);
4319 assert_node_ref_count (ref_model, &parent2, 0);
4320 assert_node_ref_count (ref_model, &parent3, 0);
4322 /* gtk_tree_store_move() will emit rows-reordered */
4323 gtk_tree_store_move_after (GTK_TREE_STORE (model),
4324 &parent1, &parent3);
4326 assert_node_ref_count (ref_model, &grandparent1, 3);
4327 assert_node_ref_count (ref_model, &parent2, 1);
4328 assert_node_ref_count (ref_model, &parent3, 0);
4329 assert_node_ref_count (ref_model, &parent1, 0);
4331 gtk_widget_destroy (tree_view);
4332 g_object_unref (filter_model);
4333 g_object_unref (ref_model);
4337 ref_count_transfer_child_level_reordered_filtered (void)
4339 GtkTreeIter grandparent1;
4340 GtkTreeIter parent1, parent2, parent3;
4341 GtkTreeModel *model;
4342 GtkTreeModelRefCount *ref_model;
4343 GtkTreeModel *filter_model;
4344 GtkWidget *tree_view;
4345 GType column_types[] = { G_TYPE_BOOLEAN };
4347 model = gtk_tree_model_ref_count_new ();
4348 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4350 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4359 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
4360 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
4361 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
4362 gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
4364 /* Test with 1 node filtered (parent1) */
4365 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4366 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
4367 gtk_tree_store_set (GTK_TREE_STORE (model), &parent3, 0, TRUE, -1);
4369 filter_model = gtk_tree_model_filter_new (model, NULL);
4370 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4371 tree_view = gtk_tree_view_new_with_model (filter_model);
4373 assert_node_ref_count (ref_model, &grandparent1, 3);
4374 assert_node_ref_count (ref_model, &parent1, 0);
4375 assert_node_ref_count (ref_model, &parent2, 1);
4376 assert_node_ref_count (ref_model, &parent3, 0);
4378 /* Move invisible node parent 1 */
4380 /* gtk_tree_store_move() will emit rows-reordered */
4381 gtk_tree_store_move_after (GTK_TREE_STORE (model),
4382 &parent1, &parent3);
4384 assert_node_ref_count (ref_model, &grandparent1, 3);
4385 assert_node_ref_count (ref_model, &parent2, 1);
4386 assert_node_ref_count (ref_model, &parent3, 0);
4387 assert_node_ref_count (ref_model, &parent1, 0);
4389 /* Move invisible node parent 1 */
4391 /* gtk_tree_store_move() will emit rows-reordered */
4392 gtk_tree_store_move_before (GTK_TREE_STORE (model),
4393 &parent1, &parent2);
4395 assert_node_ref_count (ref_model, &grandparent1, 3);
4396 assert_node_ref_count (ref_model, &parent1, 0);
4397 assert_node_ref_count (ref_model, &parent2, 1);
4398 assert_node_ref_count (ref_model, &parent3, 0);
4400 /* Now swap parent2 and parent2, first reference must transfer */
4401 /* gtk_tree_store_swap() will emit rows-reordered */
4402 gtk_tree_store_swap (GTK_TREE_STORE (model),
4403 &parent2, &parent3);
4405 assert_node_ref_count (ref_model, &grandparent1, 3);
4406 assert_node_ref_count (ref_model, &parent1, 0);
4407 assert_node_ref_count (ref_model, &parent3, 1);
4408 assert_node_ref_count (ref_model, &parent2, 0);
4411 gtk_tree_store_swap (GTK_TREE_STORE (model),
4412 &parent2, &parent3);
4414 assert_node_ref_count (ref_model, &grandparent1, 3);
4415 assert_node_ref_count (ref_model, &parent1, 0);
4416 assert_node_ref_count (ref_model, &parent2, 1);
4417 assert_node_ref_count (ref_model, &parent3, 0);
4419 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, TRUE, -1);
4421 assert_node_ref_count (ref_model, &parent1, 1);
4422 assert_node_ref_count (ref_model, &parent2, 0);
4423 assert_node_ref_count (ref_model, &parent3, 0);
4425 /* Test with two nodes filtered */
4426 gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, FALSE, -1);
4427 gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, FALSE, -1);
4429 assert_node_ref_count (ref_model, &parent1, 0);
4430 assert_node_ref_count (ref_model, &parent2, 0);
4431 assert_node_ref_count (ref_model, &parent3, 1);
4433 /* gtk_tree_store_move() will emit rows-reordered */
4434 gtk_tree_store_move_before (GTK_TREE_STORE (model),
4435 &parent3, &parent1);
4437 assert_node_ref_count (ref_model, &parent3, 1);
4438 assert_node_ref_count (ref_model, &parent2, 0);
4439 assert_node_ref_count (ref_model, &parent1, 0);
4441 gtk_widget_destroy (tree_view);
4442 g_object_unref (filter_model);
4443 g_object_unref (ref_model);
4447 ref_count_transfer_child_level_filter (void)
4450 GtkTreeIter grandparent1, grandparent2, grandparent3, grandparent4;
4451 GtkTreeIter new_node;
4452 GtkTreeModel *model;
4453 GtkTreeModelRefCount *ref_model;
4454 GtkTreeModel *filter_model;
4455 GtkWidget *tree_view;
4456 GType column_types[] = { G_TYPE_BOOLEAN };
4458 model = gtk_tree_model_ref_count_new ();
4459 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
4461 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
4471 gtk_tree_store_append (GTK_TREE_STORE (model), &root, NULL);
4472 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, &root);
4473 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, &root);
4474 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent3, &root);
4475 gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent4, &root);
4477 /* Filter first node */
4478 gtk_tree_store_set (GTK_TREE_STORE (model), &root, 0, TRUE, -1);
4479 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4480 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4481 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
4482 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4484 filter_model = gtk_tree_model_filter_new (model, NULL);
4485 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
4486 tree_view = gtk_tree_view_new_with_model (filter_model);
4488 assert_node_ref_count (ref_model, &grandparent1, 0);
4489 assert_node_ref_count (ref_model, &grandparent2, 1);
4490 assert_node_ref_count (ref_model, &grandparent3, 0);
4491 assert_node_ref_count (ref_model, &grandparent4, 0);
4493 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4495 assert_node_ref_count (ref_model, &grandparent1, 0);
4496 assert_node_ref_count (ref_model, &grandparent2, 0);
4497 assert_node_ref_count (ref_model, &grandparent3, 1);
4498 assert_node_ref_count (ref_model, &grandparent4, 0);
4500 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, FALSE, -1);
4502 assert_node_ref_count (ref_model, &grandparent1, 0);
4503 assert_node_ref_count (ref_model, &grandparent2, 0);
4504 assert_node_ref_count (ref_model, &grandparent3, 0);
4505 assert_node_ref_count (ref_model, &grandparent4, 1);
4507 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, FALSE, -1);
4509 assert_node_ref_count (ref_model, &grandparent1, 0);
4510 assert_node_ref_count (ref_model, &grandparent2, 0);
4511 assert_node_ref_count (ref_model, &grandparent3, 0);
4512 assert_node_ref_count (ref_model, &grandparent4, 1);
4514 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4516 assert_node_ref_count (ref_model, &grandparent1, 0);
4517 assert_node_ref_count (ref_model, &grandparent2, 1);
4518 assert_node_ref_count (ref_model, &grandparent3, 0);
4519 assert_node_ref_count (ref_model, &grandparent4, 0);
4521 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
4523 assert_node_ref_count (ref_model, &grandparent1, 0);
4524 assert_node_ref_count (ref_model, &grandparent2, 0);
4525 assert_node_ref_count (ref_model, &grandparent3, 0);
4526 assert_node_ref_count (ref_model, &grandparent4, 1);
4528 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
4530 assert_node_ref_count (ref_model, &grandparent1, 1);
4531 assert_node_ref_count (ref_model, &grandparent2, 0);
4532 assert_node_ref_count (ref_model, &grandparent3, 0);
4533 assert_node_ref_count (ref_model, &grandparent4, 0);
4535 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &root);
4537 assert_node_ref_count (ref_model, &new_node, 0);
4538 assert_node_ref_count (ref_model, &grandparent1, 1);
4539 assert_node_ref_count (ref_model, &grandparent2, 0);
4540 assert_node_ref_count (ref_model, &grandparent3, 0);
4541 assert_node_ref_count (ref_model, &grandparent4, 0);
4543 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
4545 assert_node_ref_count (ref_model, &new_node, 0);
4546 assert_node_ref_count (ref_model, &grandparent1, 0);
4547 assert_node_ref_count (ref_model, &grandparent2, 0);
4548 assert_node_ref_count (ref_model, &grandparent3, 0);
4549 assert_node_ref_count (ref_model, &grandparent4, 1);
4551 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4552 gtk_tree_store_prepend (GTK_TREE_STORE (model), &new_node, &root);
4554 assert_node_ref_count (ref_model, &new_node, 0);
4555 assert_node_ref_count (ref_model, &grandparent1, 0);
4556 assert_node_ref_count (ref_model, &grandparent2, 0);
4557 assert_node_ref_count (ref_model, &grandparent3, 0);
4558 assert_node_ref_count (ref_model, &grandparent4, 1);
4560 gtk_tree_store_set (GTK_TREE_STORE (model), &new_node, 0, TRUE, -1);
4562 assert_node_ref_count (ref_model, &new_node, 1);
4563 assert_node_ref_count (ref_model, &grandparent1, 0);
4564 assert_node_ref_count (ref_model, &grandparent2, 0);
4565 assert_node_ref_count (ref_model, &grandparent3, 0);
4566 assert_node_ref_count (ref_model, &grandparent4, 0);
4568 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
4569 gtk_tree_store_remove (GTK_TREE_STORE (model), &new_node);
4571 assert_node_ref_count (ref_model, &grandparent1, 0);
4572 assert_node_ref_count (ref_model, &grandparent2, 1);
4573 assert_node_ref_count (ref_model, &grandparent3, 0);
4574 assert_node_ref_count (ref_model, &grandparent4, 0);
4576 gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent4, 0, TRUE, -1);
4577 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2);
4579 gtk_widget_destroy (tree_view);
4580 g_object_unref (filter_model);
4581 g_object_unref (ref_model);
4586 specific_path_dependent_filter_func (GtkTreeModel *model,
4592 path = gtk_tree_model_get_path (model, iter);
4593 if (gtk_tree_path_get_indices (path)[0] < 4)
4600 specific_path_dependent_filter (void)
4606 GtkTreeModel *filter;
4608 list = gtk_list_store_new (1, G_TYPE_INT);
4609 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
4610 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
4611 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
4612 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
4613 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
4614 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
4615 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
4616 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
4618 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (list));
4619 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (sort), NULL);
4620 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4621 specific_path_dependent_filter_func,
4624 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort), 0,
4625 GTK_SORT_DESCENDING);
4627 for (i = 0; i < 4; i++)
4629 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
4631 gtk_list_store_remove (list, &iter);
4633 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (list), &iter,
4635 gtk_list_store_remove (list, &iter);
4638 g_object_unref (filter);
4639 g_object_unref (sort);
4640 g_object_unref (list);
4645 specific_append_after_collapse_visible_func (GtkTreeModel *model,
4650 gboolean hide_negative_numbers;
4652 gtk_tree_model_get (model, iter, 1, &number, -1);
4653 hide_negative_numbers = GPOINTER_TO_INT (g_object_get_data (data, "private-hide-negative-numbers"));
4655 return (number >= 0 || !hide_negative_numbers);
4659 specific_append_after_collapse (void)
4661 /* This test is based on one of the test cases I found in my
4662 * old test cases directory. I unfortunately do not have a record
4663 * from who this test case originated. -Kris.
4667 * - Show tree, expand, collapse.
4672 GtkTreeIter child_iter;
4673 GtkTreeIter child_iter2;
4674 GtkTreePath *append_path;
4675 GtkTreeStore *store;
4676 GtkTreeModel *filter;
4680 GtkWidget *tree_view;
4682 store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT);
4684 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
4685 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
4686 GINT_TO_POINTER (FALSE));
4687 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4688 specific_append_after_collapse_visible_func,
4691 sort = gtk_tree_model_sort_new_with_model (filter);
4693 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4694 tree_view = gtk_tree_view_new_with_model (sort);
4695 gtk_container_add (GTK_CONTAINER (window), tree_view);
4696 gtk_widget_realize (tree_view);
4698 while (gtk_events_pending ())
4699 gtk_main_iteration ();
4701 gtk_tree_store_prepend (store, &iter, NULL);
4702 gtk_tree_store_set (store, &iter,
4703 0, "hallo", 1, 1, -1);
4705 gtk_tree_store_append (store, &child_iter, &iter);
4706 gtk_tree_store_set (store, &child_iter,
4707 0, "toemaar", 1, 1, -1);
4709 gtk_tree_store_append (store, &child_iter2, &child_iter);
4710 gtk_tree_store_set (store, &child_iter2,
4711 0, "very deep", 1, 1, -1);
4713 append_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &child_iter2);
4715 gtk_tree_store_append (store, &child_iter, &iter);
4716 gtk_tree_store_set (store, &child_iter,
4717 0, "sja", 1, 1, -1);
4719 gtk_tree_store_append (store, &child_iter, &iter);
4720 gtk_tree_store_set (store, &child_iter,
4721 0, "some word", 1, -1, -1);
4723 /* Expand and collapse the tree */
4724 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4725 while (gtk_events_pending ())
4726 gtk_main_iteration ();
4728 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
4729 while (gtk_events_pending ())
4730 gtk_main_iteration ();
4732 /* Add another it */
4733 g_object_set_data (G_OBJECT (filter), "private-hide-negative-numbers",
4734 GINT_TO_POINTER (TRUE));
4736 if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, append_path))
4738 gtk_tree_store_append (store, &child_iter, &iter);
4739 gtk_tree_store_set (store, &child_iter,
4740 0, "new new new !!", 1, 1, -1);
4742 gtk_tree_path_free (append_path);
4745 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
4746 while (gtk_events_pending ())
4747 gtk_main_iteration ();
4752 specific_sort_filter_remove_node_compare_func (GtkTreeModel *model,
4761 specific_sort_filter_remove_node_visible_func (GtkTreeModel *model,
4767 /* Do reference the model */
4768 gtk_tree_model_get (model, iter, 0, &item, -1);
4775 specific_sort_filter_remove_node (void)
4777 /* This test is based on one of the test cases I found in my
4778 * old test cases directory. I unfortunately do not have a record
4779 * from who this test case originated. -Kris.
4782 * - Create tree store, sort, filter models. The sort model has
4783 * a default sort func that is enabled, filter model a visible func
4784 * that defaults to returning FALSE.
4785 * - Remove a node from the tree store.
4789 GtkTreeStore *store;
4790 GtkTreeModel *filter;
4794 GtkWidget *tree_view;
4796 store = gtk_tree_store_new (1, G_TYPE_STRING);
4797 gtk_tree_store_append (store, &iter, NULL);
4798 gtk_tree_store_set (store, &iter, 0, "Hello1", -1);
4800 gtk_tree_store_append (store, &iter, NULL);
4801 gtk_tree_store_set (store, &iter, 0, "Hello2", -1);
4803 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
4804 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
4805 specific_sort_filter_remove_node_compare_func, NULL, NULL);
4807 filter = gtk_tree_model_filter_new (sort, NULL);
4808 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
4809 specific_sort_filter_remove_node_visible_func,
4813 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4814 tree_view = gtk_tree_view_new_with_model (filter);
4815 gtk_container_add (GTK_CONTAINER (window), tree_view);
4816 gtk_widget_realize (tree_view);
4818 while (gtk_events_pending ())
4819 gtk_main_iteration ();
4822 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
4823 gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
4824 gtk_tree_store_remove (store, &iter);
4826 while (gtk_events_pending ())
4827 gtk_main_iteration ();
4832 specific_sort_filter_remove_root (void)
4834 /* This test is based on one of the test cases I found in my
4835 * old test cases directory. I unfortunately do not have a record
4836 * from who this test case originated. -Kris.
4839 GtkTreeModel *model, *sort, *filter;
4840 GtkTreeIter root, mid, leaf;
4843 model = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_INT));
4844 gtk_tree_store_append (GTK_TREE_STORE (model), &root, NULL);
4845 gtk_tree_store_append (GTK_TREE_STORE (model), &mid, &root);
4846 gtk_tree_store_append (GTK_TREE_STORE (model), &leaf, &mid);
4848 path = gtk_tree_model_get_path (model, &mid);
4850 sort = gtk_tree_model_sort_new_with_model (model);
4851 filter = gtk_tree_model_filter_new (sort, path);
4853 gtk_tree_path_free (path);
4855 gtk_tree_store_remove (GTK_TREE_STORE (model), &root);
4857 g_object_unref (filter);
4858 g_object_unref (sort);
4859 g_object_unref (model);
4864 specific_root_mixed_visibility (void)
4867 GtkTreeModel *filter;
4868 /* A bit nasty, apologies */
4871 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4873 for (i = 0; i < LEVEL_LENGTH; i++)
4877 gtk_tree_store_insert (fixture.store, &iter, NULL, i);
4879 create_tree_store_set_values (fixture.store, &iter, TRUE);
4881 create_tree_store_set_values (fixture.store, &iter, FALSE);
4884 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
4885 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4886 fixture.monitor = NULL;
4888 gtk_tree_model_filter_set_visible_column (fixture.filter, 1);
4890 /* In order to trigger the potential bug, we should not access
4891 * the filter model here (so don't call the check functions).
4894 /* Change visibility of an odd row to TRUE */
4895 set_path_visibility (&fixture, "3", TRUE);
4896 check_filter_model (&fixture);
4897 check_level_length (fixture.filter, NULL, 4);
4903 specific_has_child_filter_filter_func (GtkTreeModel *model,
4907 return gtk_tree_model_iter_has_child (model, iter);
4911 specific_has_child_filter (void)
4913 GtkTreeModel *filter;
4914 GtkTreeIter iter, root;
4915 FilterTest fixture; /* This is not how it should be done */
4916 GtkWidget *tree_view;
4918 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
4919 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
4920 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
4921 fixture.monitor = signal_monitor_new (filter);
4923 tree_view = gtk_tree_view_new_with_model (filter);
4925 /* We will filter on parent state using a filter function. We will
4926 * manually keep the boolean column in sync, so that we can use
4927 * check_filter_model() to check the consistency of the model.
4929 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
4930 * to be able to check the structure here. We keep the calls to
4931 * check_filter_model() commented out until then.
4933 gtk_tree_model_filter_set_visible_func (fixture.filter,
4934 specific_has_child_filter_filter_func,
4937 /* The first node will be initially invisible: no signals */
4938 gtk_tree_store_append (fixture.store, &root, NULL);
4939 create_tree_store_set_values (fixture.store, &root, FALSE);
4941 /* check_filter_model (&fixture); */
4942 check_level_length (fixture.filter, NULL, 0);
4943 signal_monitor_assert_is_empty (fixture.monitor);
4945 /* Insert a child node. This will cause the parent to become visible
4946 * since there is a child now.
4948 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
4949 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4950 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4952 gtk_tree_store_append (fixture.store, &iter, &root);
4953 create_tree_store_set_values (fixture.store, &iter, TRUE);
4955 /* Parent must now be visible. Do the level length check first,
4956 * to avoid modifying the child model triggering a row-changed to
4959 check_level_length (fixture.filter, NULL, 1);
4960 check_level_length (fixture.filter, "0", 0);
4961 signal_monitor_assert_is_empty (fixture.monitor);
4963 /* This should propagate row-changed */
4964 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
4965 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
4967 set_path_visibility (&fixture, "0", TRUE);
4968 /* check_filter_model (&fixture); */
4969 signal_monitor_assert_is_empty (fixture.monitor);
4971 /* New root node, no child, so no signal */
4972 gtk_tree_store_append (fixture.store, &root, NULL);
4973 check_level_length (fixture.filter, NULL, 1);
4974 signal_monitor_assert_is_empty (fixture.monitor);
4976 /* When the child comes in, this node will become visible */
4977 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
4978 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4979 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4980 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
4981 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
4983 gtk_tree_store_append (fixture.store, &iter, &root);
4984 check_level_length (fixture.filter, NULL, 2);
4985 check_level_length (fixture.filter, "1", 0);
4987 create_tree_store_set_values (fixture.store, &root, TRUE);
4988 create_tree_store_set_values (fixture.store, &iter, TRUE);
4990 /* check_filter_model (&fixture); */
4991 signal_monitor_assert_is_empty (fixture.monitor);
4993 /* Add another child for 1 */
4994 gtk_tree_store_append (fixture.store, &iter, &root);
4995 create_tree_store_set_values (fixture.store, &iter, TRUE);
4996 check_level_length (fixture.filter, NULL, 2);
4997 check_level_length (fixture.filter, "0", 0);
4998 check_level_length (fixture.filter, "1", 0);
4999 signal_monitor_assert_is_empty (fixture.monitor);
5001 /* Now remove one of the remaining child rows */
5002 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5004 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5006 gtk_tree_store_remove (fixture.store, &iter);
5008 check_level_length (fixture.filter, NULL, 1);
5009 check_level_length (fixture.filter, "0", 0);
5011 set_path_visibility (&fixture, "0", FALSE);
5012 /* check_filter_model (&fixture); */
5013 signal_monitor_assert_is_empty (fixture.monitor);
5015 g_object_unref (fixture.filter);
5016 g_object_unref (fixture.store);
5017 g_object_unref (tree_view);
5022 specific_root_has_child_filter_filter_func (GtkTreeModel *model,
5029 path = gtk_tree_model_get_path (model, iter);
5030 depth = gtk_tree_path_get_depth (path);
5031 gtk_tree_path_free (path);
5036 return gtk_tree_model_iter_has_child (model, iter);
5040 specific_root_has_child_filter (void)
5042 GtkTreeModel *filter;
5043 GtkTreeIter iter, root;
5044 FilterTest fixture; /* This is not how it should be done ... */
5045 GtkWidget *tree_view;
5047 /* This is a variation on the above test case, specific has-child-filter,
5048 * herein the has-child check for visibility only applies to root level
5049 * nodes. In this test, children are always visible because we
5050 * only filter based on the "has child" criterion.
5053 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5054 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
5055 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5056 fixture.monitor = signal_monitor_new (filter);
5058 tree_view = gtk_tree_view_new_with_model (filter);
5060 /* We will filter on parent state using a filter function. We will
5061 * manually keep the boolean column in sync, so that we can use
5062 * check_filter_model() to check the consistency of the model.
5064 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
5065 * to be able to check the structure here. We keep the calls to
5066 * check_filter_model() commented out until then.
5068 gtk_tree_model_filter_set_visible_func (fixture.filter,
5069 specific_root_has_child_filter_filter_func,
5072 /* Add a first node, this will be invisible initially, so no signal
5073 * should be emitted.
5075 gtk_tree_store_append (fixture.store, &root, NULL);
5076 create_tree_store_set_values (fixture.store, &root, FALSE);
5078 signal_monitor_assert_is_empty (fixture.monitor);
5079 /* check_filter_model (&fixture); */
5080 check_level_length (fixture.filter, NULL, 0);
5082 /* Add a child node. This will cause the parent to become visible,
5083 * so we expect row-inserted signals for both.
5085 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5086 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5087 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5089 gtk_tree_store_append (fixture.store, &iter, &root);
5090 signal_monitor_assert_is_empty (fixture.monitor);
5092 check_level_length (fixture.filter, NULL, 1);
5093 check_level_length (fixture.filter, "0", 1);
5095 /* Modify the content of iter, no signals because the parent is not
5098 create_tree_store_set_values (fixture.store, &iter, TRUE);
5099 signal_monitor_assert_is_empty (fixture.monitor);
5101 /* Parent must now be visible. Do the level length check first,
5102 * to avoid modifying the child model triggering a row-changed to
5105 check_level_length (fixture.filter, NULL, 1);
5106 check_level_length (fixture.filter, "0", 1);
5109 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5110 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5112 set_path_visibility (&fixture, "0", TRUE);
5113 /* check_filter_model (&fixture); */
5115 signal_monitor_assert_is_empty (fixture.monitor);
5117 /* Insert another node in the root level. Initially invisible, so
5118 * not expecting any signal.
5120 gtk_tree_store_append (fixture.store, &root, NULL);
5121 check_level_length (fixture.filter, NULL, 1);
5123 signal_monitor_assert_is_empty (fixture.monitor);
5125 /* Adding a child node which also makes parent at path 1 visible. */
5126 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5127 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5128 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5130 gtk_tree_store_append (fixture.store, &iter, &root);
5131 check_level_length (fixture.filter, NULL, 2);
5132 check_level_length (fixture.filter, "1", 1);
5134 signal_monitor_assert_is_empty (fixture.monitor);
5136 /* Check if row-changed is propagated */
5137 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5138 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5140 create_tree_store_set_values (fixture.store, &root, TRUE);
5141 create_tree_store_set_values (fixture.store, &iter, TRUE);
5142 /* check_filter_model (&fixture); */
5143 signal_monitor_assert_is_empty (fixture.monitor);
5145 /* Insert another child under node 1 */
5146 gtk_tree_store_append (fixture.store, &iter, &root);
5147 create_tree_store_set_values (fixture.store, &iter, TRUE);
5148 check_level_length (fixture.filter, NULL, 2);
5149 check_level_length (fixture.filter, "0", 1);
5150 check_level_length (fixture.filter, "1", 2);
5151 signal_monitor_assert_is_empty (fixture.monitor);
5153 /* Set a child node to invisible. This should not yield any
5154 * change, because filtering is only done on whether the root
5155 * node has a child, which it still has.
5157 set_path_visibility (&fixture, "0:0", FALSE);
5158 signal_monitor_assert_is_empty (fixture.monitor);
5160 /* Now remove one of the remaining child rows */
5161 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5162 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5164 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5166 gtk_tree_store_remove (fixture.store, &iter);
5168 check_level_length (fixture.filter, NULL, 1);
5169 check_level_length (fixture.filter, "0", 2);
5170 signal_monitor_assert_is_empty (fixture.monitor);
5172 /* Set visibility of 0 to FALSE, no-op for filter model since
5173 * the child 0:0 is already gone
5175 set_path_visibility (&fixture, "0", FALSE);
5176 /* check_filter_model (&fixture); */
5177 signal_monitor_assert_is_empty (fixture.monitor);
5179 g_object_unref (fixture.filter);
5180 g_object_unref (fixture.store);
5181 g_object_unref (tree_view);
5185 specific_has_child_filter_on_sort_model (void)
5187 GtkTreeModel *filter;
5188 GtkTreeModel *sort_model;
5189 GtkTreeIter iter, root;
5190 FilterTest fixture; /* This is not how it should be done */
5191 GtkWidget *tree_view;
5193 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5194 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
5195 filter = gtk_tree_model_filter_new (sort_model, NULL);
5196 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5197 fixture.monitor = signal_monitor_new (filter);
5199 tree_view = gtk_tree_view_new_with_model (filter);
5201 /* We will filter on parent state using a filter function. We will
5202 * manually keep the boolean column in sync, so that we can use
5203 * check_filter_model() to check the consistency of the model.
5205 /* FIXME: We need a check_filter_model() that is not tied to LEVEL_LENGTH
5206 * to be able to check the structure here. We keep the calls to
5207 * check_filter_model() commented out until then.
5209 gtk_tree_model_filter_set_visible_func (fixture.filter,
5210 specific_has_child_filter_filter_func,
5213 /* The first node will be initially invisible: no signals */
5214 gtk_tree_store_append (fixture.store, &root, NULL);
5215 create_tree_store_set_values (fixture.store, &root, FALSE);
5217 /* check_filter_model (&fixture); */
5218 check_level_length (fixture.filter, NULL, 0);
5219 signal_monitor_assert_is_empty (fixture.monitor);
5221 /* Insert a child node. This will cause the parent to become visible
5222 * since there is a child now.
5224 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5225 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5227 gtk_tree_store_append (fixture.store, &iter, &root);
5228 create_tree_store_set_values (fixture.store, &iter, TRUE);
5230 /* Parent must now be visible. Do the level length check first,
5231 * to avoid modifying the child model triggering a row-changed to
5234 check_level_length (fixture.filter, NULL, 1);
5235 check_level_length (fixture.filter, "0", 0);
5236 signal_monitor_assert_is_empty (fixture.monitor);
5238 /* This should propagate row-changed */
5239 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5240 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5242 set_path_visibility (&fixture, "0", TRUE);
5243 /* check_filter_model (&fixture); */
5244 signal_monitor_assert_is_empty (fixture.monitor);
5246 /* New root node, no child, so no signal */
5247 gtk_tree_store_append (fixture.store, &root, NULL);
5248 check_level_length (fixture.filter, NULL, 1);
5249 signal_monitor_assert_is_empty (fixture.monitor);
5251 /* When the child comes in, this node will become visible */
5252 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5253 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5254 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5255 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5257 gtk_tree_store_append (fixture.store, &iter, &root);
5258 check_level_length (fixture.filter, NULL, 2);
5259 check_level_length (fixture.filter, "1", 0);
5261 create_tree_store_set_values (fixture.store, &root, TRUE);
5262 create_tree_store_set_values (fixture.store, &iter, TRUE);
5264 /* check_filter_model (&fixture); */
5265 signal_monitor_assert_is_empty (fixture.monitor);
5267 /* Add another child for 1 */
5268 gtk_tree_store_append (fixture.store, &iter, &root);
5269 create_tree_store_set_values (fixture.store, &iter, TRUE);
5270 check_level_length (fixture.filter, NULL, 2);
5271 check_level_length (fixture.filter, "0", 0);
5272 check_level_length (fixture.filter, "1", 0);
5273 signal_monitor_assert_is_empty (fixture.monitor);
5275 /* Now remove one of the remaining child rows */
5276 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5278 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5280 gtk_tree_store_remove (fixture.store, &iter);
5282 check_level_length (fixture.filter, NULL, 1);
5283 check_level_length (fixture.filter, "0", 0);
5285 set_path_visibility (&fixture, "0", FALSE);
5286 /* check_filter_model (&fixture); */
5287 signal_monitor_assert_is_empty (fixture.monitor);
5289 g_object_unref (fixture.filter);
5290 g_object_unref (fixture.store);
5291 g_object_unref (tree_view);
5295 specific_at_least_2_children_filter_filter_func (GtkTreeModel *model,
5299 return gtk_tree_model_iter_n_children (model, iter) >= 2;
5303 specific_at_least_2_children_filter (void)
5305 GtkTreeModel *filter;
5306 GtkTreeIter iter, root;
5307 FilterTest fixture; /* This is not how it should be done */
5308 GtkWidget *tree_view;
5310 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5311 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fixture.store), NULL);
5312 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5313 fixture.monitor = signal_monitor_new (filter);
5315 tree_view = gtk_tree_view_new_with_model (filter);
5317 gtk_tree_model_filter_set_visible_func (fixture.filter,
5318 specific_at_least_2_children_filter_filter_func,
5321 /* The first node will be initially invisible: no signals */
5322 gtk_tree_store_append (fixture.store, &root, NULL);
5323 create_tree_store_set_values (fixture.store, &root, FALSE);
5325 /* check_filter_model (&fixture); */
5326 check_level_length (fixture.filter, NULL, 0);
5327 signal_monitor_assert_is_empty (fixture.monitor);
5329 /* Insert a child node. Nothing should happen.
5331 gtk_tree_store_append (fixture.store, &iter, &root);
5332 create_tree_store_set_values (fixture.store, &iter, TRUE);
5334 check_level_length (fixture.filter, NULL, 0);
5335 signal_monitor_assert_is_empty (fixture.monitor);
5337 /* Insert a second child node. This will cause the parent to become
5340 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5341 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5343 gtk_tree_store_append (fixture.store, &iter, &root);
5344 create_tree_store_set_values (fixture.store, &iter, TRUE);
5346 /* Parent must now be visible. Do the level length check first,
5347 * to avoid modifying the child model triggering a row-changed to
5350 check_level_length (fixture.filter, NULL, 1);
5351 check_level_length (fixture.filter, "0", 0);
5352 signal_monitor_assert_is_empty (fixture.monitor);
5354 /* This should propagate row-changed */
5355 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5356 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5358 set_path_visibility (&fixture, "0", TRUE);
5359 /* check_filter_model (&fixture); */
5360 signal_monitor_assert_is_empty (fixture.monitor);
5362 /* New root node, no child, so no signal */
5363 gtk_tree_store_append (fixture.store, &root, NULL);
5364 check_level_length (fixture.filter, NULL, 1);
5365 signal_monitor_assert_is_empty (fixture.monitor);
5367 /* First child, no signal, no change */
5368 gtk_tree_store_append (fixture.store, &iter, &root);
5369 check_level_length (fixture.filter, NULL, 1);
5370 signal_monitor_assert_is_empty (fixture.monitor);
5372 /* When the second child comes in, this node will become visible */
5373 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "1");
5374 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5375 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "1");
5376 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "1");
5378 gtk_tree_store_append (fixture.store, &iter, &root);
5379 check_level_length (fixture.filter, NULL, 2);
5380 check_level_length (fixture.filter, "1", 0);
5382 create_tree_store_set_values (fixture.store, &root, TRUE);
5383 create_tree_store_set_values (fixture.store, &iter, TRUE);
5385 /* check_filter_model (&fixture); */
5386 signal_monitor_assert_is_empty (fixture.monitor);
5388 /* Add another child for 1 */
5389 gtk_tree_store_append (fixture.store, &iter, &root);
5390 create_tree_store_set_values (fixture.store, &iter, TRUE);
5391 check_level_length (fixture.filter, NULL, 2);
5392 check_level_length (fixture.filter, "0", 0);
5393 check_level_length (fixture.filter, "1", 0);
5394 signal_monitor_assert_is_empty (fixture.monitor);
5396 /* Now remove one of the remaining child rows */
5397 signal_monitor_append_signal (fixture.monitor, ROW_DELETED, "0");
5399 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (fixture.store),
5401 gtk_tree_store_remove (fixture.store, &iter);
5403 check_level_length (fixture.filter, NULL, 1);
5404 check_level_length (fixture.filter, "0", 0);
5406 set_path_visibility (&fixture, "0", FALSE);
5407 /* check_filter_model (&fixture); */
5408 signal_monitor_assert_is_empty (fixture.monitor);
5410 g_object_unref (fixture.filter);
5411 g_object_unref (fixture.store);
5412 g_object_unref (tree_view);
5416 specific_at_least_2_children_filter_on_sort_model (void)
5418 GtkTreeRowReference *ref;
5419 GtkTreeModel *filter;
5420 GtkTreeModel *sort_model;
5421 GtkTreeIter iter, root;
5422 FilterTest fixture; /* This is not how it should be done */
5423 GtkWidget *tree_view;
5425 fixture.store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
5426 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (fixture.store));
5427 filter = gtk_tree_model_filter_new (sort_model, NULL);
5428 fixture.filter = GTK_TREE_MODEL_FILTER (filter);
5429 fixture.monitor = signal_monitor_new (filter);
5431 tree_view = gtk_tree_view_new_with_model (filter);
5433 gtk_tree_model_filter_set_visible_func (fixture.filter,
5434 specific_at_least_2_children_filter_filter_func,
5437 /* The first node will be initially invisible: no signals */
5438 gtk_tree_store_append (fixture.store, &root, NULL);
5439 create_tree_store_set_values (fixture.store, &root, FALSE);
5441 /* check_filter_model (&fixture); */
5442 check_level_length (fixture.filter, NULL, 0);
5443 signal_monitor_assert_is_empty (fixture.monitor);
5445 /* Insert a child node. Nothing should happen.
5447 gtk_tree_store_append (fixture.store, &iter, &root);
5448 create_tree_store_set_values (fixture.store, &iter, TRUE);
5450 check_level_length (fixture.filter, NULL, 0);
5451 signal_monitor_assert_is_empty (fixture.monitor);
5454 GtkTreePath *path = gtk_tree_path_new_from_indices (0, 0, -1);
5456 ref = gtk_tree_row_reference_new (sort_model, path);
5457 gtk_tree_path_free (path);
5460 /* Insert a second child node. This will cause the parent to become
5463 signal_monitor_append_signal (fixture.monitor, ROW_INSERTED, "0");
5464 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5466 gtk_tree_store_append (fixture.store, &iter, &root);
5467 create_tree_store_set_values (fixture.store, &iter, TRUE);
5469 /* Parent must now be visible. Do the level length check first,
5470 * to avoid modifying the child model triggering a row-changed to
5473 check_level_length (fixture.filter, NULL, 1);
5474 check_level_length (fixture.filter, "0", 0);
5475 signal_monitor_assert_is_empty (fixture.monitor);
5477 /* This should propagate row-changed */
5478 signal_monitor_append_signal (fixture.monitor, ROW_CHANGED, "0");
5479 signal_monitor_append_signal (fixture.monitor, ROW_HAS_CHILD_TOGGLED, "0");
5481 set_path_visibility (&fixture, "0", TRUE);
5482 /* check_filter_model (&fixture); */
5483 signal_monitor_assert_is_empty (fixture.monitor);
5485 /* New root node, no child, so no signal */
5486 gtk_tree_store_append (fixture.store, &root, NULL);
5487 check_level_length (fixture.filter, NULL, 1);
5488 signal_monitor_assert_is_empty (fixture.monitor);
5490 gtk_tree_row_reference_free (ref);
5491 g_object_unref (fixture.filter);
5492 g_object_unref (fixture.store);
5493 g_object_unref (tree_view);
5498 specific_filter_add_child (void)
5500 /* This test is based on one of the test cases I found in my
5501 * old test cases directory. I unfortunately do not have a record
5502 * from who this test case originated. -Kris.
5506 GtkTreeIter iter_first;
5508 GtkTreeStore *store;
5509 GtkTreeModel *filter G_GNUC_UNUSED;
5511 store = gtk_tree_store_new (1, G_TYPE_STRING);
5513 gtk_tree_store_append (store, &iter_first, NULL);
5514 gtk_tree_store_set (store, &iter_first, 0, "Hello", -1);
5516 gtk_tree_store_append (store, &iter, NULL);
5517 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5519 gtk_tree_store_append (store, &iter, NULL);
5520 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5522 gtk_tree_store_append (store, &iter, NULL);
5523 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5525 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
5527 gtk_tree_store_set (store, &iter, 0, "Hello", -1);
5528 gtk_tree_store_append (store, &child, &iter_first);
5529 gtk_tree_store_set (store, &child, 0, "Hello", -1);
5533 specific_list_store_clear (void)
5537 GtkTreeModel *filter;
5538 GtkWidget *view G_GNUC_UNUSED;
5540 list = gtk_list_store_new (1, G_TYPE_INT);
5541 gtk_list_store_insert_with_values (list, &iter, 0, 0, 1, -1);
5542 gtk_list_store_insert_with_values (list, &iter, 1, 0, 2, -1);
5543 gtk_list_store_insert_with_values (list, &iter, 2, 0, 3, -1);
5544 gtk_list_store_insert_with_values (list, &iter, 3, 0, 4, -1);
5545 gtk_list_store_insert_with_values (list, &iter, 4, 0, 5, -1);
5546 gtk_list_store_insert_with_values (list, &iter, 5, 0, 6, -1);
5547 gtk_list_store_insert_with_values (list, &iter, 6, 0, 7, -1);
5548 gtk_list_store_insert_with_values (list, &iter, 7, 0, 8, -1);
5550 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (list), NULL);
5551 view = gtk_tree_view_new_with_model (filter);
5553 gtk_list_store_clear (list);
5557 specific_sort_ref_leaf_and_remove_ancestor (void)
5559 GtkTreeIter iter, child, child2, child3;
5563 GtkTreeRowReference *rowref;
5564 GtkWidget *view G_GNUC_UNUSED;
5566 tree = gtk_tree_store_new (1, G_TYPE_INT);
5567 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5568 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5569 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5570 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5572 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5573 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5574 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5576 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
5577 view = gtk_tree_view_new_with_model (sort);
5578 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5580 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5581 rowref = gtk_tree_row_reference_new (sort, path);
5582 gtk_tree_path_free (path);
5584 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5585 rowref = gtk_tree_row_reference_new (sort, path);
5586 gtk_tree_path_free (path);
5588 path = gtk_tree_path_new_from_indices (3, 0, -1);
5589 rowref = gtk_tree_row_reference_new (sort, path);
5590 gtk_tree_path_free (path);
5592 path = gtk_tree_path_new_from_indices (3, -1);
5593 rowref = gtk_tree_row_reference_new (sort, path);
5594 gtk_tree_path_free (path);
5596 /* Deleting a parent */
5597 path = gtk_tree_path_new_from_indices (3, 0, -1);
5598 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5599 gtk_tree_store_remove (tree, &iter);
5600 gtk_tree_path_free (path);
5602 gtk_tree_row_reference_free (rowref);
5606 specific_ref_leaf_and_remove_ancestor (void)
5608 GtkTreeIter iter, child, child2, child3;
5610 GtkTreeModel *filter;
5612 GtkTreeRowReference *rowref;
5613 GtkWidget *view G_GNUC_UNUSED;
5615 tree = gtk_tree_store_new (1, G_TYPE_INT);
5616 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5617 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5618 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5619 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5621 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5622 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5623 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5625 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), NULL);
5626 view = gtk_tree_view_new_with_model (filter);
5627 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5629 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5630 rowref = gtk_tree_row_reference_new (filter, path);
5631 gtk_tree_path_free (path);
5633 path = gtk_tree_path_new_from_indices (3, 0, 0, 0, -1);
5634 rowref = gtk_tree_row_reference_new (filter, path);
5635 gtk_tree_path_free (path);
5637 path = gtk_tree_path_new_from_indices (3, 0, -1);
5638 rowref = gtk_tree_row_reference_new (filter, path);
5639 gtk_tree_path_free (path);
5641 path = gtk_tree_path_new_from_indices (3, -1);
5642 rowref = gtk_tree_row_reference_new (filter, path);
5643 gtk_tree_path_free (path);
5645 /* Deleting a parent */
5646 path = gtk_tree_path_new_from_indices (3, 0, -1);
5647 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5648 gtk_tree_store_remove (tree, &iter);
5649 gtk_tree_path_free (path);
5651 gtk_tree_row_reference_free (rowref);
5655 specific_virtual_ref_leaf_and_remove_ancestor (void)
5657 GtkTreeIter iter, child, child2, child3;
5659 GtkTreeModel *filter;
5661 GtkTreeRowReference *rowref;
5662 GtkWidget *view G_GNUC_UNUSED;
5664 tree = gtk_tree_store_new (1, G_TYPE_INT);
5665 gtk_tree_store_insert_with_values (tree, &iter, NULL, 0, 0, 1, -1);
5666 gtk_tree_store_insert_with_values (tree, &iter, NULL, 1, 0, 2, -1);
5667 gtk_tree_store_insert_with_values (tree, &iter, NULL, 2, 0, 3, -1);
5668 gtk_tree_store_insert_with_values (tree, &iter, NULL, 3, 0, 4, -1);
5670 gtk_tree_store_insert_with_values (tree, &child, &iter, 0, 0, 50, -1);
5671 gtk_tree_store_insert_with_values (tree, &child2, &child, 0, 0, 6, -1);
5672 gtk_tree_store_insert_with_values (tree, &child3, &child2, 0, 0, 7, -1);
5674 /* Set a virtual root of 3:0 */
5675 path = gtk_tree_path_new_from_indices (3, 0, -1);
5676 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (tree), path);
5677 gtk_tree_path_free (path);
5679 view = gtk_tree_view_new_with_model (filter);
5680 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
5682 path = gtk_tree_path_new_from_indices (0, 0, -1);
5683 rowref = gtk_tree_row_reference_new (filter, path);
5684 gtk_tree_path_free (path);
5686 path = gtk_tree_path_new_from_indices (0, 0, -1);
5687 rowref = gtk_tree_row_reference_new (filter, path);
5688 gtk_tree_path_free (path);
5690 path = gtk_tree_path_new_from_indices (0, -1);
5691 rowref = gtk_tree_row_reference_new (filter, path);
5692 gtk_tree_path_free (path);
5694 /* Deleting the virtual root */
5695 path = gtk_tree_path_new_from_indices (3, 0, -1);
5696 gtk_tree_model_get_iter (GTK_TREE_MODEL (tree), &iter, path);
5697 gtk_tree_store_remove (tree, &iter);
5698 gtk_tree_path_free (path);
5700 gtk_tree_row_reference_free (rowref);
5705 specific_bug_301558_sort_func (GtkTreeModel *model,
5712 gtk_tree_model_get (model, a, 0, &i, -1);
5713 gtk_tree_model_get (model, b, 0, &j, -1);
5719 specific_bug_301558 (void)
5721 /* Test case for GNOME Bugzilla bug 301558 provided by
5725 GtkTreeModel *filter;
5727 GtkTreeIter root, iter, iter2;
5728 GtkWidget *view G_GNUC_UNUSED;
5732 g_test_bug ("301558");
5734 tree = gtk_tree_store_new (2, G_TYPE_INT, G_TYPE_BOOLEAN);
5735 gtk_tree_store_append (tree, &iter, NULL);
5736 gtk_tree_store_set (tree, &iter, 0, 123, 1, TRUE, -1);
5737 gtk_tree_store_append (tree, &iter2, &iter);
5738 gtk_tree_store_set (tree, &iter2, 0, 73, 1, TRUE, -1);
5740 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree));
5741 gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (sort),
5742 specific_bug_301558_sort_func,
5745 filter = gtk_tree_model_filter_new (sort, NULL);
5746 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter), 1);
5748 view = gtk_tree_view_new_with_model (filter);
5750 while (gtk_events_pending ())
5751 gtk_main_iteration ();
5755 for (i = 0; i < 10; i++)
5757 if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (tree), &root))
5758 g_assert_not_reached ();
5762 gtk_tree_store_append (tree, &iter, &root);
5763 gtk_tree_store_set (tree, &iter, 0, 456, 1, TRUE, -1);
5768 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tree), &root);
5769 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tree), &iter,
5771 gtk_tree_store_remove (tree, &iter);
5780 specific_bug_311955_filter_func (GtkTreeModel *model,
5786 gtk_tree_model_get (model, iter, 0, &value, -1);
5788 return (value != 0);
5792 specific_bug_311955 (void)
5794 /* This is a test case for GNOME Bugzilla bug 311955. It was written
5797 GtkTreeIter iter, child, root;
5798 GtkTreeStore *store;
5800 GtkTreeModel *filter;
5802 GtkWidget *window G_GNUC_UNUSED;
5803 GtkWidget *tree_view;
5808 g_test_bug ("311955");
5810 store = gtk_tree_store_new (1, G_TYPE_INT);
5812 gtk_tree_store_append (store, &root, NULL);
5813 gtk_tree_store_set (store, &root, 0, 33, -1);
5815 gtk_tree_store_append (store, &iter, &root);
5816 gtk_tree_store_set (store, &iter, 0, 50, -1);
5818 gtk_tree_store_append (store, &iter, NULL);
5819 gtk_tree_store_set (store, &iter, 0, 22, -1);
5821 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
5822 filter = gtk_tree_model_filter_new (sort, NULL);
5824 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
5825 specific_bug_311955_filter_func,
5828 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
5829 tree_view = gtk_tree_view_new_with_model (filter);
5830 g_object_unref (store);
5832 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
5834 while (gtk_events_pending ())
5835 gtk_main_iteration ();
5837 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
5838 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
5841 for (i = 0; i < 4; i++)
5843 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
5845 gtk_tree_store_append (store, &iter, &root);
5848 gtk_tree_store_set (store, &iter, 0, i, -1);
5852 gtk_tree_store_append (store, &child, &iter);
5853 gtk_tree_store_set (store, &child, 0, 10, -1);
5857 while (gtk_events_pending ())
5858 gtk_main_iteration ();
5860 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5861 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 1);
5863 /* Remove bottommost child from the tree. */
5864 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &root);
5865 n = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), &root);
5867 if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store), &iter, &root, n - 2))
5869 if (gtk_tree_model_iter_children (GTK_TREE_MODEL (store), &child, &iter))
5870 gtk_tree_store_remove (store, &child);
5873 g_assert_not_reached ();
5875 path = gtk_tree_path_new_from_indices (0, 2, -1);
5876 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
5877 gtk_tree_path_free (path);
5879 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5880 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
5884 specific_bug_311955_clean (void)
5886 /* Cleaned up version of the test case for GNOME Bugzilla bug 311955,
5887 * which is easier to understand.
5889 GtkTreeIter iter, child, grandchild;
5890 GtkTreeStore *store;
5892 GtkTreeModel *filter;
5894 GtkWidget *tree_view;
5897 store = gtk_tree_store_new (1, G_TYPE_INT);
5899 gtk_tree_store_append (store, &iter, NULL);
5900 gtk_tree_store_set (store, &iter, 0, 1, -1);
5902 gtk_tree_store_append (store, &child, &iter);
5903 gtk_tree_store_set (store, &child, 0, 1, -1);
5905 sort = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
5906 filter = gtk_tree_model_filter_new (sort, NULL);
5908 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
5909 specific_bug_311955_filter_func,
5912 tree_view = gtk_tree_view_new_with_model (filter);
5913 g_object_unref (store);
5915 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
5917 while (gtk_events_pending ())
5918 gtk_main_iteration ();
5920 check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
5921 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 1);
5923 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
5925 gtk_tree_store_append (store, &child, &iter);
5926 gtk_tree_store_set (store, &child, 0, 0, -1);
5928 gtk_tree_store_append (store, &child, &iter);
5929 gtk_tree_store_set (store, &child, 0, 1, -1);
5931 gtk_tree_store_append (store, &child, &iter);
5932 gtk_tree_store_set (store, &child, 0, 1, -1);
5934 gtk_tree_store_append (store, &grandchild, &child);
5935 gtk_tree_store_set (store, &grandchild, 0, 1, -1);
5937 gtk_tree_store_append (store, &child, &iter);
5938 /* Don't set a value: assume 0 */
5940 /* Remove leaf node, check trigger row-has-child-toggled */
5941 path = gtk_tree_path_new_from_indices (0, 3, 0, -1);
5942 gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
5943 gtk_tree_path_free (path);
5944 gtk_tree_store_remove (store, &iter);
5946 path = gtk_tree_path_new_from_indices (0, 2, -1);
5947 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE);
5948 gtk_tree_path_free (path);
5950 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0", 3);
5951 check_level_length (GTK_TREE_MODEL_FILTER (filter), "0:2", 0);
5953 gtk_widget_destroy (tree_view);
5957 specific_bug_346800 (void)
5959 /* This is a test case for GNOME Bugzilla bug 346800. It was written
5960 * by Jonathan Matthew.
5963 GtkTreeIter node_iters[50];
5964 GtkTreeIter child_iters[50];
5965 GtkTreeModel *model;
5966 GtkTreeModelFilter *filter;
5967 GtkTreeStore *store;
5971 columns = g_new (GType, 2);
5972 columns[0] = G_TYPE_STRING;
5973 columns[1] = G_TYPE_BOOLEAN;
5974 store = gtk_tree_store_newv (2, columns);
5975 model = GTK_TREE_MODEL (store);
5977 g_test_bug ("346800");
5979 filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
5980 gtk_tree_model_filter_set_visible_column (filter, 1);
5982 for (i=0; i<items; i++)
5984 /* allocate random amounts of junk, otherwise the filter model's arrays can expand without moving */
5987 gtk_tree_store_append (store, &node_iters[i], NULL);
5988 gtk_tree_store_set (store, &node_iters[i],
5990 1, ((i%6) == 0) ? FALSE : TRUE,
5994 gtk_tree_store_append (store, &child_iters[i], &node_iters[i]);
5995 gtk_tree_store_set (store, &child_iters[i],
5996 0, "something else",
5999 gtk_tree_model_filter_refilter (filter);
6003 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-1], 1,
6004 (i & 1) ? TRUE : FALSE, -1);
6005 gtk_tree_model_filter_refilter (filter);
6007 gtk_tree_store_set (GTK_TREE_STORE (model), &child_iters[i-2], 1,
6008 (i & 1) ? FALSE: TRUE, -1);
6009 gtk_tree_model_filter_refilter (filter);
6015 specific_bug_464173_visible_func (GtkTreeModel *model,
6019 gboolean *visible = (gboolean *)data;
6025 specific_bug_464173 (void)
6027 /* Test case for GNOME Bugzilla bug 464173, test case written
6028 * by Andreas Koehler.
6030 GtkTreeStore *model;
6031 GtkTreeModelFilter *f_model;
6032 GtkTreeIter iter1, iter2;
6033 GtkWidget *view G_GNUC_UNUSED;
6034 gboolean visible = TRUE;
6036 g_test_bug ("464173");
6038 model = gtk_tree_store_new (1, G_TYPE_STRING);
6039 gtk_tree_store_append (model, &iter1, NULL);
6040 gtk_tree_store_set (model, &iter1, 0, "Foo", -1);
6041 gtk_tree_store_append (model, &iter2, &iter1);
6042 gtk_tree_store_set (model, &iter2, 0, "Bar", -1);
6044 f_model = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (GTK_TREE_MODEL(model), NULL));
6045 gtk_tree_model_filter_set_visible_func (f_model,
6046 specific_bug_464173_visible_func,
6049 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (f_model));
6052 gtk_tree_model_filter_refilter (f_model);
6057 specific_bug_540201_filter_func (GtkTreeModel *model,
6061 gboolean has_children;
6063 has_children = gtk_tree_model_iter_has_child (model, iter);
6065 return has_children;
6069 specific_bug_540201 (void)
6071 /* Test case for GNOME Bugzilla bug 540201, steps provided by
6074 GtkTreeIter iter, root;
6075 GtkTreeStore *store;
6076 GtkTreeModel *filter;
6078 GtkWidget *tree_view G_GNUC_UNUSED;
6080 g_test_bug ("540201");
6082 store = gtk_tree_store_new (1, G_TYPE_INT);
6084 gtk_tree_store_append (store, &root, NULL);
6085 gtk_tree_store_set (store, &root, 0, 33, -1);
6087 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6088 tree_view = gtk_tree_view_new_with_model (filter);
6090 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6091 specific_bug_540201_filter_func,
6094 gtk_tree_store_append (store, &iter, &root);
6095 gtk_tree_store_set (store, &iter, 0, 50, -1);
6097 gtk_tree_store_append (store, &iter, &root);
6098 gtk_tree_store_set (store, &iter, 0, 22, -1);
6101 gtk_tree_store_append (store, &root, NULL);
6102 gtk_tree_store_set (store, &root, 0, 33, -1);
6104 gtk_tree_store_append (store, &iter, &root);
6105 gtk_tree_store_set (store, &iter, 0, 22, -1);
6110 specific_bug_549287_visible_func (GtkTreeModel *model,
6114 gboolean result = FALSE;
6116 result = gtk_tree_model_iter_has_child (model, iter);
6122 specific_bug_549287 (void)
6124 /* Test case for GNOME Bugzilla bug 529287, provided by Julient Puydt */
6127 GtkTreeStore *store;
6128 GtkTreeModel *filtered;
6129 GtkWidget *view G_GNUC_UNUSED;
6131 GtkTreeIter *swap, *parent, *child;
6133 g_test_bug ("529287");
6135 store = gtk_tree_store_new (1, G_TYPE_STRING);
6136 filtered = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6137 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filtered),
6138 specific_bug_549287_visible_func,
6141 view = gtk_tree_view_new_with_model (filtered);
6143 for (i = 0; i < 4; i++)
6145 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
6147 parent = gtk_tree_iter_copy (&iter);
6148 child = gtk_tree_iter_copy (&iter);
6150 while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (store),
6159 gtk_tree_store_append (store, child, parent);
6160 gtk_tree_store_set (store, child,
6164 gtk_tree_iter_free (parent);
6165 gtk_tree_iter_free (child);
6169 gtk_tree_store_append (store, &iter, NULL);
6170 gtk_tree_store_set (store, &iter,
6175 /* since we inserted something, we changed the visibility conditions: */
6176 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filtered));
6181 specific_bug_621076_visible_func (GtkTreeModel *model,
6185 gboolean visible = FALSE;
6188 gtk_tree_model_get (model, iter, 0, &str, -1);
6189 if (str != NULL && g_str_has_prefix (str, "visible"))
6195 GtkTreeIter child_iter;
6198 /* Recursively check if we have a visible child */
6199 for (valid = gtk_tree_model_iter_children (model, &child_iter, iter);
6200 valid; valid = gtk_tree_model_iter_next (model, &child_iter))
6202 if (specific_bug_621076_visible_func (model, &child_iter, data))
6217 specific_bug_621076 (void)
6219 /* Test case for GNOME Bugzilla bug 621076, provided by Xavier Claessens */
6221 /* This test case differs from has-child-filter and root-has-child-filter
6222 * in that the visible function both filters on content and model
6223 * structure. Also, it is recursive.
6226 GtkTreeStore *store;
6227 GtkTreeModel *filter;
6229 GtkTreeIter group_iter;
6230 GtkTreeIter item_iter;
6231 SignalMonitor *monitor;
6233 g_test_bug ("621076");
6235 store = gtk_tree_store_new (1, G_TYPE_STRING);
6236 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
6237 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6238 specific_bug_621076_visible_func,
6241 view = gtk_tree_view_new_with_model (filter);
6242 g_object_ref_sink (view);
6244 monitor = signal_monitor_new (filter);
6246 signal_monitor_append_signal (monitor, ROW_INSERTED, "0");
6247 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6248 0, "visible-group-0",
6250 signal_monitor_assert_is_empty (monitor);
6252 /* visible-group-0 is not expanded, so ROW_INSERTED should not be emitted
6253 * for its children. However, ROW_HAS_CHILD_TOGGLED should be emitted on
6254 * visible-group-0 to tell the view that row can be expanded. */
6255 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
6256 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "0");
6257 group_iter = item_iter;
6258 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6261 signal_monitor_assert_is_empty (monitor);
6263 signal_monitor_append_signal (monitor, ROW_INSERTED, "1");
6264 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6265 0, "visible-group-1",
6267 signal_monitor_assert_is_empty (monitor);
6269 /* We are adding an hidden item inside visible-group-1, so
6270 * ROW_HAS_CHILD_TOGGLED should not be emitted. It is emitted though,
6271 * because the signal originating at TreeStore will be propagated,
6272 * as well a generated signal because the state of the parent *could*
6273 * change by a change in the model.
6275 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6276 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6277 group_iter = item_iter;
6278 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6281 signal_monitor_assert_is_empty (monitor);
6283 /* This group is invisible and its parent too. Nothing should be emitted */
6284 group_iter = item_iter;
6285 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6288 signal_monitor_assert_is_empty (monitor);
6290 /* Adding a visible item in this group hierarchy will make all nodes
6291 * in this path visible. The first level should simply tell the view
6292 * that it now has a child, and the view will load the tree if needed
6293 * (depends on the expanded state).
6295 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6296 group_iter = item_iter;
6297 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6298 0, "visible-1:0:0:0",
6300 signal_monitor_assert_is_empty (monitor);
6302 check_level_length (GTK_TREE_MODEL_FILTER (filter), "1", 1);
6304 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6307 signal_monitor_assert_is_empty (monitor);
6309 /* Parent is invisible, and adding this invisible item won't change that,
6310 * so no signal should be emitted. */
6311 group_iter = item_iter;
6312 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6315 signal_monitor_assert_is_empty (monitor);
6317 /* This makes group-2 visible, so it gets inserted and tells it has
6320 signal_monitor_append_signal (monitor, ROW_INSERTED, "2");
6321 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6322 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6325 signal_monitor_assert_is_empty (monitor);
6327 /* group-2 is already visible, so this time it is a normal insertion */
6328 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6331 signal_monitor_assert_is_empty (monitor);
6334 gtk_tree_store_insert_with_values (store, &item_iter, NULL, -1,
6337 signal_monitor_assert_is_empty (monitor);
6339 /* Parent is invisible, and adding this invisible item won't change that,
6340 * so no signal should be emitted. */
6341 group_iter = item_iter;
6342 gtk_tree_store_insert_with_values (store, NULL, &group_iter, -1,
6345 signal_monitor_assert_is_empty (monitor);
6347 gtk_tree_store_insert_with_values (store, &item_iter, &group_iter, -1,
6350 signal_monitor_assert_is_empty (monitor);
6352 /* This will make group 3 visible. */
6353 signal_monitor_append_signal (monitor, ROW_INSERTED, "3");
6354 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
6355 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "3");
6356 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
6357 signal_monitor_assert_is_empty (monitor);
6359 /* Make sure all groups are expanded, so the filter has the tree cached */
6360 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
6361 while (gtk_events_pending ())
6362 gtk_main_iteration ();
6364 /* Should only yield a row-changed */
6365 signal_monitor_append_signal (monitor, ROW_CHANGED, "3:0");
6366 gtk_tree_store_set (store, &item_iter, 0, "visible-3:1", -1);
6367 signal_monitor_assert_is_empty (monitor);
6369 /* Now remove/hide some items. If a group loses its last item, the group
6370 * should be deleted instead of the item.
6373 signal_monitor_append_signal (monitor, ROW_DELETED, "2:1");
6374 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:2");
6375 gtk_tree_store_remove (store, &item_iter);
6376 signal_monitor_assert_is_empty (monitor);
6378 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
6379 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6380 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
6381 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "2:1");
6382 gtk_tree_store_set (store, &item_iter, 0, "invisible-2:1", -1);
6383 signal_monitor_assert_is_empty (monitor);
6385 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0:0:0");
6386 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1:0:0");
6387 signal_monitor_append_signal (monitor, ROW_DELETED, "1:0");
6388 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "1");
6389 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter, "1:0:0:0");
6390 gtk_tree_store_remove (store, &item_iter);
6391 signal_monitor_assert_is_empty (monitor);
6393 /* Hide a group using row-changed instead of row-deleted */
6394 /* Caution: group 2 is gone, so offsets of the signals have moved. */
6395 signal_monitor_append_signal (monitor, ROW_DELETED, "2:0");
6396 signal_monitor_append_signal (monitor, ROW_HAS_CHILD_TOGGLED, "2");
6397 signal_monitor_append_signal (monitor, ROW_DELETED, "2");
6398 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &item_iter,
6400 gtk_tree_store_set (store, &item_iter, 0, "invisible-3:1", -1);
6401 signal_monitor_assert_is_empty (monitor);
6406 GtkTreeViewColumn *col;
6408 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
6410 col = gtk_tree_view_column_new_with_attributes ("foo",
6411 gtk_cell_renderer_text_new (),
6413 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
6415 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
6416 g_signal_connect (window, "delete-event",
6417 G_CALLBACK (gtk_widget_destroy), NULL);
6418 g_signal_connect (window, "destroy",
6419 G_CALLBACK (gtk_main_quit), NULL);
6421 gtk_container_add (GTK_CONTAINER (window), view);
6423 gtk_widget_show (view);
6424 gtk_widget_show (window);
6431 signal_monitor_free (monitor);
6432 g_object_unref (view);
6433 g_object_unref (store);
6434 g_object_unref (filter);
6438 specific_bug_657353_related (void)
6440 GtkTreeIter node1, node2, node3, node4;
6441 GtkTreeModel *model;
6442 GtkTreeModelRefCount *ref_model;
6443 GtkTreeModel *filter_model;
6444 GtkWidget *tree_view;
6445 GType column_types[] = { G_TYPE_BOOLEAN };
6447 /* gtk_tree_model_filter_rows_reordered() used to have a problem to
6448 * not properly transfer the first ref count when the first node in
6449 * the level does not have elt->offset == 0. This test checks for
6450 * that. This bug could cause the faulty condition
6451 * elt->ext_ref_count > elt->ref_count
6455 model = gtk_tree_model_ref_count_new ();
6456 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
6458 gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
6461 gtk_tree_store_append (GTK_TREE_STORE (model), &node1, NULL);
6462 gtk_tree_store_append (GTK_TREE_STORE (model), &node2, NULL);
6463 gtk_tree_store_append (GTK_TREE_STORE (model), &node3, NULL);
6464 gtk_tree_store_append (GTK_TREE_STORE (model), &node4, NULL);
6466 /* Hide the first node */
6467 gtk_tree_store_set (GTK_TREE_STORE (model), &node1, 0, FALSE, -1);
6468 gtk_tree_store_set (GTK_TREE_STORE (model), &node2, 0, TRUE, -1);
6469 gtk_tree_store_set (GTK_TREE_STORE (model), &node3, 0, TRUE, -1);
6470 gtk_tree_store_set (GTK_TREE_STORE (model), &node4, 0, TRUE, -1);
6472 filter_model = gtk_tree_model_filter_new (model, NULL);
6473 gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
6474 tree_view = gtk_tree_view_new_with_model (filter_model);
6476 assert_node_ref_count (ref_model, &node1, 0);
6477 assert_node_ref_count (ref_model, &node2, 2);
6478 assert_node_ref_count (ref_model, &node3, 1);
6479 assert_node_ref_count (ref_model, &node4, 1);
6481 /* Swap nodes 2 and 3 */
6483 /* gtk_tree_store_swap() will emit rows-reordered */
6484 gtk_tree_store_swap (GTK_TREE_STORE (model),
6487 assert_node_ref_count (ref_model, &node1, 0);
6488 assert_node_ref_count (ref_model, &node3, 2);
6489 assert_node_ref_count (ref_model, &node2, 1);
6490 assert_node_ref_count (ref_model, &node4, 1);
6493 gtk_tree_store_set (GTK_TREE_STORE (model), &node3, 0, FALSE, -1);
6495 assert_node_ref_count (ref_model, &node1, 0);
6496 assert_node_ref_count (ref_model, &node3, 0);
6497 assert_node_ref_count (ref_model, &node2, 2);
6498 assert_node_ref_count (ref_model, &node4, 1);
6500 gtk_widget_destroy (tree_view);
6501 g_object_unref (filter_model);
6502 g_object_unref (ref_model);
6506 specific_bug_657353_visible_func (GtkTreeModel *model,
6511 gboolean ret = FALSE;
6513 gtk_tree_model_get (model, iter, 0, &str, -1);
6514 ret = strstr (str, "hidden") ? FALSE : TRUE;
6521 specific_bug_657353 (void)
6523 GtkListStore *store;
6524 GtkTreeModel *sort_model;
6525 GtkTreeModel *filter_model;
6526 GtkTreeIter iter, iter_a, iter_b, iter_c;
6527 GtkWidget *tree_view;
6529 /* This is a very carefully crafted test case that is triggering the
6530 * situation described in bug 657353.
6532 * GtkListStore acts like EphyCompletionModel
6533 * GtkTreeModelSort acts like the sort model added in
6534 * ephy_location_entry_set_completion.
6535 * GtkTreeModelFilter acts like the filter model in
6536 * GtkEntryCompletion.
6539 /* Set up a model that's wrapped in a GtkTreeModelSort. The first item
6542 store = gtk_list_store_new (1, G_TYPE_STRING);
6543 gtk_list_store_insert_with_values (store, &iter_b, 0, 0, "BBB hidden", -1);
6544 gtk_list_store_insert_with_values (store, &iter, 1, 0, "EEE", -1);
6545 gtk_list_store_insert_with_values (store, &iter, 2, 0, "DDD", -1);
6546 gtk_list_store_insert_with_values (store, &iter_c, 3, 0, "CCC", -1);
6548 sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
6550 filter_model = gtk_tree_model_filter_new (sort_model, NULL);
6551 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model),
6552 specific_bug_657353_visible_func,
6553 filter_model, NULL);
6555 tree_view = gtk_tree_view_new_with_model (filter_model);
6557 /* This triggers emission of rows-reordered. The elt with offset == 0
6558 * is hidden, which used to cause misbehavior. (The first reference should
6559 * have moved to CCC, which did not happen).
6561 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
6562 0, GTK_SORT_ASCENDING);
6564 /* By inserting another item that will appear at the first position, a
6565 * reference transfer is done from CCC (which failed to get this reference
6566 * earlier) to AAA. At this point, the rule
6567 * elt->ref_count >= elt->ext_ref_count is broken for CCC.
6569 gtk_list_store_insert_with_values (store, &iter_a, 6, 0, "AAA", -1);
6571 /* When we hide CCC, the references cannot be correctly released, because
6572 * CCC failed to get a reference during rows-reordered. The faulty condition
6573 * only manifests itself here with MODEL_FILTER_DEBUG disabled (as is usual
6576 gtk_list_store_set (store, &iter_c, 0, "CCC hidden", -1);
6578 gtk_widget_destroy (tree_view);
6579 g_object_unref (filter_model);
6580 g_object_unref (sort_model);
6581 g_object_unref (store);
6585 specific_bug_658696 (void)
6587 GtkTreeStore *store;
6588 GtkTreeModel *filter;
6592 store = create_tree_store (4, TRUE);
6594 vroot = gtk_tree_path_new_from_indices (0, 0, -1);
6595 filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), vroot);
6596 gtk_tree_path_free (vroot);
6598 /* This used to cause a crash in gtk_tree_model_filter_check_ancestors() */
6599 gtk_tree_store_append (store, &iter, NULL);
6601 g_object_unref (store);
6602 g_object_unref (filter);
6606 specific_bug_659022_visible_func (GtkTreeModel *model,
6612 if (!gtk_tree_model_iter_parent (model, &tmp, iter))
6614 if (gtk_tree_model_iter_n_children (model, iter) >= 2)
6624 specific_bug_659022_row_changed_emission (void)
6626 GtkTreeModel *filter;
6627 GtkTreeModel *model;
6628 GtkTreeModelRefCount *ref_model;
6629 GtkTreeIter parent, child, child2;
6631 GtkWidget *tree_view;
6633 model = gtk_tree_model_ref_count_new ();
6634 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
6636 filter = gtk_tree_model_filter_new (model, NULL);
6637 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6638 specific_bug_659022_visible_func,
6641 tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (filter));
6643 gtk_tree_store_insert (GTK_TREE_STORE (model), &parent, NULL, 0);
6644 gtk_tree_store_insert (GTK_TREE_STORE (model), &child, &parent, 0);
6645 gtk_tree_store_insert (GTK_TREE_STORE (model), &child2, &parent, 0);
6647 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
6649 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter));
6651 gtk_tree_store_remove (GTK_TREE_STORE (model), &child2);
6653 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter));
6655 path = gtk_tree_model_get_path (model, &child);
6656 gtk_tree_model_row_changed (model, path, &child);
6657 gtk_tree_path_free (path);
6659 gtk_widget_destroy (tree_view);
6660 g_object_unref (filter);
6661 g_object_unref (model);
6665 specific_bug_659022_row_deleted_node_invisible (void)
6667 GtkTreeModel *filter;
6668 GtkTreeModel *model;
6669 GtkTreeModelRefCount *ref_model;
6670 GtkTreeIter parent, child;
6671 GtkTreeIter parent2, child2, child3;
6672 GtkWidget *tree_view;
6674 model = gtk_tree_model_ref_count_new ();
6675 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
6677 filter = gtk_tree_model_filter_new (model, NULL);
6678 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6679 specific_bug_659022_visible_func,
6682 tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (filter));
6684 gtk_tree_store_insert (GTK_TREE_STORE (model), &parent, NULL, 0);
6685 gtk_tree_store_insert (GTK_TREE_STORE (model), &child, &parent, 0);
6687 gtk_tree_store_insert (GTK_TREE_STORE (model), &parent2, NULL, 0);
6688 gtk_tree_store_insert (GTK_TREE_STORE (model), &child2, &parent2, 0);
6689 gtk_tree_store_insert (GTK_TREE_STORE (model), &child3, &parent2, 0);
6691 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
6693 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter));
6695 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent);
6697 gtk_widget_destroy (tree_view);
6698 g_object_unref (filter);
6699 g_object_unref (model);
6703 specific_bug_659022_row_deleted_free_level (void)
6705 GtkTreeModel *filter;
6706 GtkTreeModel *model;
6707 GtkTreeModelRefCount *ref_model;
6708 GtkTreeIter parent, child;
6709 GtkTreeIter parent2, child2, child3;
6710 GtkWidget *tree_view;
6712 model = gtk_tree_model_ref_count_new ();
6713 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
6715 filter = gtk_tree_model_filter_new (model, NULL);
6716 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter),
6717 specific_bug_659022_visible_func,
6720 tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (filter));
6722 /* Carefully construct a model */
6723 gtk_tree_store_insert (GTK_TREE_STORE (model), &parent, NULL, 0);
6724 gtk_tree_store_insert (GTK_TREE_STORE (model), &child, &parent, 0);
6726 gtk_tree_store_insert (GTK_TREE_STORE (model), &parent2, NULL, 0);
6727 gtk_tree_store_insert (GTK_TREE_STORE (model), &child2, &parent2, 0);
6728 gtk_tree_store_insert (GTK_TREE_STORE (model), &child3, &parent2, 0);
6730 /* Only parent2 is visible, child3 holds first ref count for that level
6731 * (Note that above, both child2 as child3 are inserted at position 0).
6733 assert_node_ref_count (ref_model, &parent, 0);
6734 assert_node_ref_count (ref_model, &child, 0);
6735 assert_node_ref_count (ref_model, &parent2, 3);
6736 assert_node_ref_count (ref_model, &child3, 1);
6737 assert_node_ref_count (ref_model, &child2, 0);
6739 /* Make sure child level is cached */
6740 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
6742 assert_node_ref_count (ref_model, &parent, 0);
6743 assert_node_ref_count (ref_model, &child, 0);
6744 assert_node_ref_count (ref_model, &parent2, 3);
6745 assert_node_ref_count (ref_model, &child3, 2);
6746 assert_node_ref_count (ref_model, &child2, 1);
6748 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
6750 assert_node_ref_count (ref_model, &parent, 0);
6751 assert_node_ref_count (ref_model, &child, 0);
6752 assert_node_ref_count (ref_model, &parent2, 3);
6753 assert_node_ref_count (ref_model, &child3, 1);
6754 assert_node_ref_count (ref_model, &child2, 0);
6756 /* Remove node with longer child level first */
6757 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2);
6758 gtk_tree_store_remove (GTK_TREE_STORE (model), &parent);
6760 gtk_widget_destroy (tree_view);
6761 g_object_unref (filter);
6762 g_object_unref (model);
6768 register_filter_model_tests (void)
6770 g_test_add ("/TreeModelFilter/self/verify-test-suite",
6774 filter_test_teardown);
6776 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-1",
6777 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6779 verify_test_suite_vroot,
6780 filter_test_teardown);
6781 g_test_add ("/TreeModelFilter/self/verify-test-suite/vroot/depth-2",
6782 FilterTest, gtk_tree_path_new_from_indices (2, 3, -1),
6784 verify_test_suite_vroot,
6785 filter_test_teardown);
6788 g_test_add ("/TreeModelFilter/filled/hide-root-level",
6791 filled_hide_root_level,
6792 filter_test_teardown);
6793 g_test_add ("/TreeModelFilter/filled/hide-child-levels",
6796 filled_hide_child_levels,
6797 filter_test_teardown);
6798 g_test_add ("/TreeModelFilter/filled/hide-child-levels/root-expanded",
6801 filled_hide_child_levels_root_expanded,
6802 filter_test_teardown);
6804 g_test_add ("/TreeModelFilter/filled/hide-root-level/vroot",
6805 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6807 filled_vroot_hide_root_level,
6808 filter_test_teardown);
6809 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot",
6810 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6812 filled_vroot_hide_child_levels,
6813 filter_test_teardown);
6814 g_test_add ("/TreeModelFilter/filled/hide-child-levels/vroot-root-expanded",
6815 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6817 filled_vroot_hide_child_levels_root_expanded,
6818 filter_test_teardown);
6821 g_test_add ("/TreeModelFilter/empty/show-nodes",
6823 filter_test_setup_empty,
6825 filter_test_teardown);
6826 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes",
6828 filter_test_setup_empty,
6829 empty_show_multiple_nodes,
6830 filter_test_teardown);
6832 g_test_add ("/TreeModelFilter/empty/show-nodes/vroot",
6833 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6834 filter_test_setup_empty,
6835 empty_vroot_show_nodes,
6836 filter_test_teardown);
6837 g_test_add ("/TreeModelFilter/empty/show-multiple-nodes/vroot",
6838 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6839 filter_test_setup_empty,
6840 empty_vroot_show_multiple_nodes,
6841 filter_test_teardown);
6844 g_test_add ("/TreeModelFilter/unfiltered/hide-single",
6846 filter_test_setup_unfiltered,
6847 unfiltered_hide_single,
6848 filter_test_teardown);
6849 g_test_add ("/TreeModelFilter/unfiltered/hide-single/root-expanded",
6851 filter_test_setup_unfiltered_root_expanded,
6852 unfiltered_hide_single_root_expanded,
6853 filter_test_teardown);
6854 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child",
6856 filter_test_setup_unfiltered,
6857 unfiltered_hide_single_child,
6858 filter_test_teardown);
6859 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/root-expanded",
6861 filter_test_setup_unfiltered_root_expanded,
6862 unfiltered_hide_single_child_root_expanded,
6863 filter_test_teardown);
6864 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level",
6866 filter_test_setup_unfiltered,
6867 unfiltered_hide_single_multi_level,
6868 filter_test_teardown);
6869 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/root-expanded",
6871 filter_test_setup_unfiltered_root_expanded,
6872 unfiltered_hide_single_multi_level_root_expanded,
6873 filter_test_teardown);
6875 g_test_add ("/TreeModelFilter/unfiltered/hide-single/vroot",
6876 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6877 filter_test_setup_unfiltered,
6878 unfiltered_vroot_hide_single,
6879 filter_test_teardown);
6880 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot",
6881 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6882 filter_test_setup_unfiltered,
6883 unfiltered_vroot_hide_single_child,
6884 filter_test_teardown);
6885 g_test_add ("/TreeModelFilter/unfiltered/hide-single-child/vroot/root-expanded",
6886 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6887 filter_test_setup_unfiltered_root_expanded,
6888 unfiltered_vroot_hide_single_child_root_expanded,
6889 filter_test_teardown);
6890 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot",
6891 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6892 filter_test_setup_unfiltered,
6893 unfiltered_vroot_hide_single_multi_level,
6894 filter_test_teardown);
6895 g_test_add ("/TreeModelFilter/unfiltered/hide-single-multi-level/vroot/root-expanded",
6896 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6897 filter_test_setup_unfiltered_root_expanded,
6898 unfiltered_vroot_hide_single_multi_level_root_expanded,
6899 filter_test_teardown);
6903 g_test_add ("/TreeModelFilter/unfiltered/show-single",
6905 filter_test_setup_empty_unfiltered,
6906 unfiltered_show_single,
6907 filter_test_teardown);
6908 g_test_add ("/TreeModelFilter/unfiltered/show-single-child",
6910 filter_test_setup_empty_unfiltered,
6911 unfiltered_show_single_child,
6912 filter_test_teardown);
6913 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/root-expanded",
6915 filter_test_setup_empty_unfiltered_root_expanded,
6916 unfiltered_show_single_child_root_expanded,
6917 filter_test_teardown);
6918 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level",
6920 filter_test_setup_empty_unfiltered,
6921 unfiltered_show_single_multi_level,
6922 filter_test_teardown);
6923 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/root-expanded",
6925 filter_test_setup_empty_unfiltered_root_expanded,
6926 unfiltered_show_single_multi_level_root_expanded,
6927 filter_test_teardown);
6929 g_test_add ("/TreeModelFilter/unfiltered/show-single/vroot",
6930 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6931 filter_test_setup_empty_unfiltered,
6932 unfiltered_vroot_show_single,
6933 filter_test_teardown);
6934 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot",
6935 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6936 filter_test_setup_empty_unfiltered,
6937 unfiltered_vroot_show_single_child,
6938 filter_test_teardown);
6939 g_test_add ("/TreeModelFilter/unfiltered/show-single-child/vroot/root-expanded",
6940 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6941 filter_test_setup_empty_unfiltered_root_expanded,
6942 unfiltered_vroot_show_single_child_root_expanded,
6943 filter_test_teardown);
6944 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot",
6945 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6946 filter_test_setup_empty_unfiltered,
6947 unfiltered_vroot_show_single_multi_level,
6948 filter_test_teardown);
6949 g_test_add ("/TreeModelFilter/unfiltered/show-single-multi-level/vroot/root-expanded",
6950 FilterTest, gtk_tree_path_new_from_indices (2, -1),
6951 filter_test_setup_empty_unfiltered_root_expanded,
6952 unfiltered_vroot_show_single_multi_level_root_expanded,
6953 filter_test_teardown);
6956 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/root-level",
6958 filter_test_setup_unfiltered,
6959 unfiltered_rows_reordered_root_level,
6960 filter_test_teardown);
6961 g_test_add ("/TreeModelFilter/unfiltered/rows-reordered/child-level",
6963 filter_test_setup_unfiltered,
6964 unfiltered_rows_reordered_child_level,
6965 filter_test_teardown);
6967 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/first-hidden",
6970 filtered_rows_reordered_root_level_first_hidden,
6971 filter_test_teardown);
6972 g_test_add ("/TreeModelFilter/filtered/rows-reordered/root-level/middle-hidden",
6975 filtered_rows_reordered_root_level_middle_hidden,
6976 filter_test_teardown);
6977 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/first-hidden",
6980 filtered_rows_reordered_child_level_first_hidden,
6981 filter_test_teardown);
6982 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/middle-hidden",
6985 filtered_rows_reordered_child_level_middle_hidden,
6986 filter_test_teardown);
6987 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/4-hidden",
6990 filtered_rows_reordered_child_level_4_hidden,
6991 filter_test_teardown);
6992 g_test_add ("/TreeModelFilter/filtered/rows-reordered/child-level/all-hidden",
6995 filtered_rows_reordered_child_level_all_hidden,
6996 filter_test_teardown);
6998 /* Inserts in child models after creation of filter model */
6999 g_test_add_func ("/TreeModelFilter/insert/before",
7001 g_test_add_func ("/TreeModelFilter/insert/child",
7004 /* Removals from child model after creating of filter model */
7005 g_test_add_func ("/TreeModelFilter/remove/node",
7007 g_test_add_func ("/TreeModelFilter/remove/node-vroot",
7009 g_test_add_func ("/TreeModelFilter/remove/vroot-ancestor",
7010 remove_vroot_ancestor);
7012 /* Reference counting */
7013 g_test_add_func ("/TreeModelFilter/ref-count/single-level",
7014 ref_count_single_level);
7015 g_test_add_func ("/TreeModelFilter/ref-count/two-levels",
7016 ref_count_two_levels);
7017 g_test_add_func ("/TreeModelFilter/ref-count/three-levels",
7018 ref_count_three_levels);
7019 g_test_add_func ("/TreeModelFilter/ref-count/delete-row",
7020 ref_count_delete_row);
7021 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1",
7022 ref_count_filter_row_length_1);
7023 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1-remove-in-root-level",
7024 ref_count_filter_row_length_1_remove_in_root_level);
7025 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-1-remove-in-child-level",
7026 ref_count_filter_row_length_1_remove_in_child_level);
7027 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-gt-1",
7028 ref_count_filter_row_length_gt_1);
7029 g_test_add_func ("/TreeModelFilter/ref-count/filter-row/length-gt-1-visible-children",
7030 ref_count_filter_row_length_gt_1_visible_children);
7031 g_test_add_func ("/TreeModelFilter/ref-count/cleanup",
7033 g_test_add_func ("/TreeModelFilter/ref-count/row-ref",
7036 /* Reference counting, transfer of first reference on
7037 * first node in level. This is a GtkTreeModelFilter-specific
7040 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/insert",
7041 ref_count_transfer_root_level_insert);
7042 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/remove",
7043 ref_count_transfer_root_level_remove);
7044 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/remove/filtered",
7045 ref_count_transfer_root_level_remove_filtered);
7046 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered",
7047 ref_count_transfer_root_level_reordered);
7048 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered/filtered",
7049 ref_count_transfer_root_level_reordered_filtered);
7050 g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/filter",
7051 ref_count_transfer_root_level_filter);
7052 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/insert",
7053 ref_count_transfer_child_level_insert);
7054 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/remove",
7055 ref_count_transfer_child_level_remove);
7056 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/remove/filtered",
7057 ref_count_transfer_child_level_remove_filtered);
7058 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered",
7059 ref_count_transfer_child_level_reordered);
7060 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered/filtered",
7061 ref_count_transfer_child_level_reordered_filtered);
7062 g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/filter",
7063 ref_count_transfer_child_level_filter);
7065 g_test_add_func ("/TreeModelFilter/specific/path-dependent-filter",
7066 specific_path_dependent_filter);
7067 g_test_add_func ("/TreeModelFilter/specific/append-after-collapse",
7068 specific_append_after_collapse);
7069 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-node",
7070 specific_sort_filter_remove_node);
7071 g_test_add_func ("/TreeModelFilter/specific/sort-filter-remove-root",
7072 specific_sort_filter_remove_root);
7073 g_test_add_func ("/TreeModelFilter/specific/root-mixed-visibility",
7074 specific_root_mixed_visibility);
7075 g_test_add_func ("/TreeModelFilter/specific/has-child-filter",
7076 specific_has_child_filter);
7077 g_test_add_func ("/TreeModelFilter/specific/has-child-filter-on-sort-model",
7078 specific_has_child_filter_on_sort_model);
7079 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter",
7080 specific_at_least_2_children_filter);
7081 g_test_add_func ("/TreeModelFilter/specific/at-least-2-children-filter-on-sort-model",
7082 specific_at_least_2_children_filter_on_sort_model);
7083 g_test_add_func ("/TreeModelFilter/specific/root-has-child-filter",
7084 specific_root_has_child_filter);
7085 g_test_add_func ("/TreeModelFilter/specific/filter-add-child",
7086 specific_filter_add_child);
7087 g_test_add_func ("/TreeModelFilter/specific/list-store-clear",
7088 specific_list_store_clear);
7089 g_test_add_func ("/TreeModelFilter/specific/sort-ref-leaf-and-remove-ancestor",
7090 specific_sort_ref_leaf_and_remove_ancestor);
7091 g_test_add_func ("/TreeModelFilter/specific/ref-leaf-and-remove-ancestor",
7092 specific_ref_leaf_and_remove_ancestor);
7093 g_test_add_func ("/TreeModelFilter/specific/virtual-ref-leaf-and-remove-ancestor",
7094 specific_virtual_ref_leaf_and_remove_ancestor);
7096 g_test_add_func ("/TreeModelFilter/specific/bug-301558",
7097 specific_bug_301558);
7098 g_test_add_func ("/TreeModelFilter/specific/bug-311955",
7099 specific_bug_311955);
7100 g_test_add_func ("/TreeModelFilter/specific/bug-311955-clean",
7101 specific_bug_311955_clean);
7102 g_test_add_func ("/TreeModelFilter/specific/bug-346800",
7103 specific_bug_346800);
7104 g_test_add_func ("/TreeModelFilter/specific/bug-464173",
7105 specific_bug_464173);
7106 g_test_add_func ("/TreeModelFilter/specific/bug-540201",
7107 specific_bug_540201);
7108 g_test_add_func ("/TreeModelFilter/specific/bug-549287",
7109 specific_bug_549287);
7110 g_test_add_func ("/TreeModelFilter/specific/bug-621076",
7111 specific_bug_621076);
7112 g_test_add_func ("/TreeModelFilter/specific/bug-657353-related",
7113 specific_bug_657353_related);
7114 g_test_add_func ("/TreeModelFilter/specific/bug-657353",
7115 specific_bug_657353);
7116 g_test_add_func ("/TreeModelFilter/specific/bug-658696",
7117 specific_bug_658696);
7118 g_test_add_func ("/TreeModelFilter/specific/bug-659022/row-changed-emission",
7119 specific_bug_659022_row_changed_emission);
7120 g_test_add_func ("/TreeModelFilter/specific/bug-659022/row-deleted-node-invisible",
7121 specific_bug_659022_row_deleted_node_invisible);
7122 g_test_add_func ("/TreeModelFilter/specific/bug-659022/row-deleted-free-level",
7123 specific_bug_659022_row_deleted_free_level);