diff --git a/gtk/tests/filtermodel.c b/gtk/tests/filtermodel.c index 04f3307450..9834fb520e 100644 --- a/gtk/tests/filtermodel.c +++ b/gtk/tests/filtermodel.c @@ -19,14 +19,12 @@ #include +#include "treemodel.h" +#include "gtktreemodelrefcount.h" /* Left to do: * - Proper coverage checking to see if the unit tests cover * all possible cases. - * - Verify if the ref counting is done properly for both the - * normal ref_count and the zero_ref_count. One way to test - * this area is by collapsing/expanding branches on the view - * that is connected to the filter model. * - Check if the iterator stamp is incremented at the correct times. */ @@ -2483,6 +2481,552 @@ remove_vroot_ancestor (void) g_object_unref (tree); } +static void +ref_count_single_level (void) +{ + GtkTreeIter iter[5]; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkWidget *tree_view; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + gtk_tree_store_append (GTK_TREE_STORE (model), &iter[0], NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter[1], NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter[2], NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter[3], NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter[4], NULL); + + assert_root_level_unreferenced (ref_model); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + assert_node_ref_count (ref_model, &iter[0], 2); + assert_node_ref_count (ref_model, &iter[1], 1); + assert_node_ref_count (ref_model, &iter[2], 1); + assert_node_ref_count (ref_model, &iter[3], 1); + assert_node_ref_count (ref_model, &iter[4], 1); + + gtk_widget_destroy (tree_view); + + assert_node_ref_count (ref_model, &iter[0], 1); + assert_node_ref_count (ref_model, &iter[1], 0); + assert_node_ref_count (ref_model, &iter[2], 0); + assert_node_ref_count (ref_model, &iter[3], 0); + assert_node_ref_count (ref_model, &iter[4], 0); + + g_object_unref (filter_model); + + assert_node_ref_count (ref_model, &iter[0], 0); + + g_object_unref (ref_model); +} + +static void +ref_count_two_levels (void) +{ + GtkTreeIter parent1, parent2, iter, iter_first; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkWidget *tree_view; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_first, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent2); + + assert_entire_model_unreferenced (ref_model); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + /* This is quite confusing: + * - node 0 has a ref count of 2 because it is referenced as the + * first node in a level and by the tree view. + * - node 1 has a ref count of 2 because it is referenced by its + * child level and by the tree view. + */ + assert_root_level_referenced (ref_model, 2); + assert_node_ref_count (ref_model, &iter_first, 1); + assert_node_ref_count (ref_model, &iter, 0); + + gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); + + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_first, 2); + assert_node_ref_count (ref_model, &iter, 1); + + gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view)); + + /* The child level is not destroyed because its parent is visible */ + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_first, 1); + assert_node_ref_count (ref_model, &iter, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_first, 1); + assert_node_ref_count (ref_model, &iter, 0); + + gtk_widget_destroy (tree_view); + + assert_root_level_referenced (ref_model, 1); + assert_node_ref_count (ref_model, &iter_first, 1); + assert_node_ref_count (ref_model, &iter, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + /* The first two levels should not be cleared, these are used to + * monitor whether or not the parent must become (in)visible. + */ + assert_root_level_referenced (ref_model, 1); + assert_node_ref_count (ref_model, &iter_first, 1); + assert_node_ref_count (ref_model, &iter, 0); + + g_object_unref (filter_model); + g_object_unref (ref_model); +} + +static void +ref_count_three_levels (void) +{ + GtkTreeIter grandparent1, grandparent2, parent1, parent2; + GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkTreePath *path; + GtkWidget *tree_view; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + /* + grandparent1 + * + grandparent2 + * + parent1 + * + iter_parent1 + * + parent2 + * + iter_parent2_first + * + iter_parent2 + */ + + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2); + + assert_entire_model_unreferenced (ref_model); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + /* This is quite confusing: + * - node 0 has a ref count of 2 because it is referenced as the + * first node in a level and by the tree view. + * - node 1 has a ref count of 2 because it is referenced by its + * child level and by the tree view. + */ + assert_root_level_referenced (ref_model, 2); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 0); + assert_level_unreferenced (ref_model, &parent1); + assert_level_unreferenced (ref_model, &parent2); + + path = gtk_tree_path_new_from_indices (1, -1); + gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 2); + assert_node_ref_count (ref_model, &iter_parent2_first, 2); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_path_append_index (path, 1); + gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, FALSE); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 2); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_path_up (path); + gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path); + gtk_tree_path_free (path); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_widget_destroy (tree_view); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + /* The first two levels should not be cleared, these are used to + * monitor whether or not the parent must become (in)visible. + */ + assert_node_ref_count (ref_model, &grandparent1, 1); + assert_node_ref_count (ref_model, &grandparent2, 1); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 0); + assert_node_ref_count (ref_model, &iter_parent1, 0); + assert_node_ref_count (ref_model, &iter_parent2_first, 0); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + g_object_unref (filter_model); + g_object_unref (ref_model); +} + +static void +ref_count_delete_row (void) +{ + GtkTreeIter grandparent1, grandparent2, parent1, parent2; + GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkTreePath *path; + GtkWidget *tree_view; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + /* + grandparent1 + * + grandparent2 + * + parent1 + * + iter_parent1 + * + parent2 + * + iter_parent2_first + * + iter_parent2 + */ + + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2); + + assert_entire_model_unreferenced (ref_model); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + assert_root_level_referenced (ref_model, 2); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 0); + assert_level_unreferenced (ref_model, &parent1); + assert_level_unreferenced (ref_model, &parent2); + + path = gtk_tree_path_new_from_indices (1, -1); + gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path, TRUE); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 2); + assert_node_ref_count (ref_model, &iter_parent2_first, 2); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_tree_store_remove (GTK_TREE_STORE (model), &iter_parent2); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 2); + assert_node_ref_count (ref_model, &iter_parent2_first, 2); + + gtk_tree_store_remove (GTK_TREE_STORE (model), &parent1); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent2, 3); + assert_level_referenced (ref_model, 2, &parent2); + + gtk_tree_store_remove (GTK_TREE_STORE (model), &grandparent2); + + assert_node_ref_count (ref_model, &grandparent1, 2); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + + gtk_widget_destroy (tree_view); + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + assert_node_ref_count (ref_model, &grandparent1, 1); + + g_object_unref (filter_model); + + assert_node_ref_count (ref_model, &grandparent1, 0); + + g_object_unref (ref_model); +} + +static void +ref_count_cleanup (void) +{ + GtkTreeIter grandparent1, grandparent2, parent1, parent2; + GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkWidget *tree_view; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + /* + grandparent1 + * + grandparent2 + * + parent1 + * + iter_parent1 + * + parent2 + * + iter_parent2_first + * + iter_parent2 + */ + + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 3); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 2); + assert_node_ref_count (ref_model, &iter_parent2_first, 2); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_widget_destroy (tree_view); + + assert_node_ref_count (ref_model, &grandparent1, 1); + assert_node_ref_count (ref_model, &grandparent2, 1); + assert_node_ref_count (ref_model, &parent1, 2); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 1); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + /* The first two levels should not be cleared, these are used to + * monitor whether or not the parent must become (in)visible. + */ + assert_node_ref_count (ref_model, &grandparent1, 1); + assert_node_ref_count (ref_model, &grandparent2, 1); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 0); + assert_node_ref_count (ref_model, &iter_parent1, 0); + assert_node_ref_count (ref_model, &iter_parent2_first, 0); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + g_object_unref (filter_model); + g_object_unref (ref_model); +} + +static void +ref_count_row_ref (void) +{ + GtkTreeIter grandparent1, grandparent2, parent1, parent2; + GtkTreeIter iter_parent1, iter_parent2, iter_parent2_first; + GtkTreeModel *model; + GtkTreeModelRefCount *ref_model; + GtkTreeModel *filter_model; + GtkWidget *tree_view; + GtkTreePath *path; + GtkTreeRowReference *row_ref; + + model = gtk_tree_model_ref_count_new (); + ref_model = GTK_TREE_MODEL_REF_COUNT (model); + + /* + grandparent1 + * + grandparent2 + * + parent1 + * + iter_parent1 + * + parent2 + * + iter_parent2 + * + iter_parent2 + */ + + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent2, NULL); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent1, &parent1); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2_first, &parent2); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter_parent2, &parent2); + + filter_model = gtk_tree_model_filter_new (model, NULL); + tree_view = gtk_tree_view_new_with_model (filter_model); + + path = gtk_tree_path_new_from_indices (1, 1, 1, -1); + row_ref = gtk_tree_row_reference_new (filter_model, path); + gtk_tree_path_free (path); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 3); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 0); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_tree_row_reference_free (row_ref); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 1); + assert_node_ref_count (ref_model, &iter_parent1, 0); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 0); + + path = gtk_tree_path_new_from_indices (1, 1, 1, -1); + row_ref = gtk_tree_row_reference_new (filter_model, path); + gtk_tree_path_free (path); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 3); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &parent2, 2); + assert_node_ref_count (ref_model, &iter_parent1, 0); + assert_node_ref_count (ref_model, &iter_parent2_first, 1); + assert_node_ref_count (ref_model, &iter_parent2, 1); + + gtk_tree_store_remove (GTK_TREE_STORE (model), &parent2); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &iter_parent1, 0); + + gtk_tree_row_reference_free (row_ref); + + assert_node_ref_count (ref_model, &grandparent1, 2); + assert_node_ref_count (ref_model, &grandparent2, 2); + assert_node_ref_count (ref_model, &parent1, 1); + assert_node_ref_count (ref_model, &iter_parent1, 0); + + gtk_widget_destroy (tree_view); + + gtk_tree_model_filter_clear_cache (GTK_TREE_MODEL_FILTER (filter_model)); + + /* The first two levels should not be cleared, these are used to + * monitor whether or not the parent must become (in)visible. + */ + assert_node_ref_count (ref_model, &grandparent1, 1); + assert_node_ref_count (ref_model, &grandparent2, 1); + assert_node_ref_count (ref_model, &parent1, 1); + + g_object_unref (filter_model); + g_object_unref (ref_model); +} + static gboolean specific_path_dependent_filter_func (GtkTreeModel *model, @@ -4519,6 +5063,19 @@ register_filter_model_tests (void) g_test_add_func ("/TreeModelFilter/remove/vroot-ancestor", remove_vroot_ancestor); + /* Reference counting */ + g_test_add_func ("/TreeModelFilter/ref-count/single-level", + ref_count_single_level); + g_test_add_func ("/TreeModelFilter/ref-count/two-levels", + ref_count_two_levels); + g_test_add_func ("/TreeModelFilter/ref-count/three-levels", + ref_count_three_levels); + g_test_add_func ("/TreeModelFilter/ref-count/delete-row", + ref_count_delete_row); + g_test_add_func ("/TreeModelFilter/ref-count/cleanup", + ref_count_cleanup); + g_test_add_func ("/TreeModelFilter/ref-count/row-ref", + ref_count_row_ref); g_test_add_func ("/TreeModelFilter/specific/path-dependent-filter", specific_path_dependent_filter);