summaryrefslogtreecommitdiff
path: root/gtk/tests
diff options
context:
space:
mode:
authorKristian Rietveld <kris@gtk.org>2011-08-29 10:16:41 +0200
committerKristian Rietveld <kris@gtk.org>2011-09-07 22:25:29 +0200
commit0bedb51b33c6aff8d5f444f1bcf2f67206c7fd20 (patch)
treecf75cf9bdee4114e13f2cb7aa223698f0e29f31e /gtk/tests
parent057a50d58e940056c6f5407812a67405308aa983 (diff)
downloadgtk+-0bedb51b33c6aff8d5f444f1bcf2f67206c7fd20.tar.gz
Add unit test for ref tranfer in rows-reordered with filtered rows
Diffstat (limited to 'gtk/tests')
-rw-r--r--gtk/tests/filtermodel.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/gtk/tests/filtermodel.c b/gtk/tests/filtermodel.c
index a0c11a8994..0749eabc76 100644
--- a/gtk/tests/filtermodel.c
+++ b/gtk/tests/filtermodel.c
@@ -3209,6 +3209,86 @@ ref_count_transfer_root_level_reordered (void)
}
static void
+ref_count_transfer_root_level_reordered_filtered (void)
+{
+ GtkTreeIter grandparent1, grandparent2, grandparent3;
+ GtkTreeModel *model;
+ GtkTreeModelRefCount *ref_model;
+ GtkTreeModel *filter_model;
+ GtkWidget *tree_view;
+ GType column_types[] = { G_TYPE_BOOLEAN };
+
+ model = gtk_tree_model_ref_count_new ();
+ ref_model = GTK_TREE_MODEL_REF_COUNT (model);
+
+ gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
+ column_types);
+
+ /* + grandparent1
+ * + grandparent2
+ * + grandparent3
+ */
+
+ 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), &grandparent3, NULL);
+
+ /* Test with 1 node filtered */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, TRUE, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent3, 0, TRUE, -1);
+
+ filter_model = gtk_tree_model_filter_new (model, NULL);
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
+ tree_view = gtk_tree_view_new_with_model (filter_model);
+
+ assert_node_ref_count (ref_model, &grandparent1, 0);
+ assert_node_ref_count (ref_model, &grandparent2, 2);
+ assert_node_ref_count (ref_model, &grandparent3, 1);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_after (GTK_TREE_STORE (model),
+ &grandparent1, &grandparent3);
+
+ assert_node_ref_count (ref_model, &grandparent2, 2);
+ assert_node_ref_count (ref_model, &grandparent3, 1);
+ assert_node_ref_count (ref_model, &grandparent1, 0);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_before (GTK_TREE_STORE (model),
+ &grandparent1, &grandparent2);
+
+ assert_node_ref_count (ref_model, &grandparent1, 0);
+ assert_node_ref_count (ref_model, &grandparent2, 2);
+ assert_node_ref_count (ref_model, &grandparent3, 1);
+
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
+
+ assert_node_ref_count (ref_model, &grandparent1, 2);
+ assert_node_ref_count (ref_model, &grandparent2, 1);
+ assert_node_ref_count (ref_model, &grandparent3, 1);
+
+ /* Test with two nodes filtered */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, FALSE, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent2, 0, FALSE, -1);
+
+ assert_node_ref_count (ref_model, &grandparent1, 0);
+ assert_node_ref_count (ref_model, &grandparent2, 0);
+ assert_node_ref_count (ref_model, &grandparent3, 2);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_before (GTK_TREE_STORE (model),
+ &grandparent3, &grandparent1);
+
+ assert_node_ref_count (ref_model, &grandparent3, 2);
+ assert_node_ref_count (ref_model, &grandparent2, 0);
+ assert_node_ref_count (ref_model, &grandparent1, 0);
+
+ gtk_widget_destroy (tree_view);
+ g_object_unref (filter_model);
+ g_object_unref (ref_model);
+}
+
+static void
ref_count_transfer_child_level_insert (void)
{
GtkTreeIter grandparent1;
@@ -3300,6 +3380,92 @@ ref_count_transfer_child_level_reordered (void)
g_object_unref (ref_model);
}
+static void
+ref_count_transfer_child_level_reordered_filtered (void)
+{
+ GtkTreeIter grandparent1;
+ GtkTreeIter parent1, parent2, parent3;
+ GtkTreeModel *model;
+ GtkTreeModelRefCount *ref_model;
+ GtkTreeModel *filter_model;
+ GtkWidget *tree_view;
+ GType column_types[] = { G_TYPE_BOOLEAN };
+
+ model = gtk_tree_model_ref_count_new ();
+ ref_model = GTK_TREE_MODEL_REF_COUNT (model);
+
+ gtk_tree_store_set_column_types (GTK_TREE_STORE (model), 1,
+ column_types);
+
+ /* + grandparent1
+ * + parent1
+ * + parent2
+ * + parent3
+ */
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &grandparent1, NULL);
+ gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, &grandparent1);
+ gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, &grandparent1);
+ gtk_tree_store_append (GTK_TREE_STORE (model), &parent3, &grandparent1);
+
+ /* Test with 1 node filtered (parent1) */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &grandparent1, 0, TRUE, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, TRUE, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &parent3, 0, TRUE, -1);
+
+ filter_model = gtk_tree_model_filter_new (model, NULL);
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter_model), 0);
+ tree_view = gtk_tree_view_new_with_model (filter_model);
+
+ assert_node_ref_count (ref_model, &grandparent1, 3);
+ assert_node_ref_count (ref_model, &parent1, 0);
+ assert_node_ref_count (ref_model, &parent2, 1);
+ assert_node_ref_count (ref_model, &parent3, 0);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_after (GTK_TREE_STORE (model),
+ &parent1, &parent3);
+
+ assert_node_ref_count (ref_model, &grandparent1, 3);
+ assert_node_ref_count (ref_model, &parent2, 1);
+ assert_node_ref_count (ref_model, &parent3, 0);
+ assert_node_ref_count (ref_model, &parent1, 0);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_before (GTK_TREE_STORE (model),
+ &parent1, &parent2);
+
+ assert_node_ref_count (ref_model, &grandparent1, 3);
+ assert_node_ref_count (ref_model, &parent1, 0);
+ assert_node_ref_count (ref_model, &parent2, 1);
+ assert_node_ref_count (ref_model, &parent3, 0);
+
+ gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, TRUE, -1);
+
+ assert_node_ref_count (ref_model, &parent1, 1);
+ assert_node_ref_count (ref_model, &parent2, 0);
+ assert_node_ref_count (ref_model, &parent3, 0);
+
+ /* Test with two nodes filtered */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &parent1, 0, FALSE, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (model), &parent2, 0, FALSE, -1);
+
+ assert_node_ref_count (ref_model, &parent1, 0);
+ assert_node_ref_count (ref_model, &parent2, 0);
+ assert_node_ref_count (ref_model, &parent3, 1);
+
+ /* gtk_tree_store_move() will emit rows-reordered */
+ gtk_tree_store_move_before (GTK_TREE_STORE (model),
+ &parent3, &parent1);
+
+ assert_node_ref_count (ref_model, &parent3, 1);
+ assert_node_ref_count (ref_model, &parent2, 0);
+ assert_node_ref_count (ref_model, &parent1, 0);
+
+ gtk_widget_destroy (tree_view);
+ g_object_unref (filter_model);
+ g_object_unref (ref_model);
+}
static gboolean
specific_path_dependent_filter_func (GtkTreeModel *model,
@@ -5401,10 +5567,14 @@ register_filter_model_tests (void)
ref_count_transfer_root_level_insert);
g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered",
ref_count_transfer_root_level_reordered);
+ g_test_add_func ("/TreeModelFilter/ref-count/transfer/root-level/reordered/filtered",
+ ref_count_transfer_root_level_reordered_filtered);
g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/insert",
ref_count_transfer_child_level_insert);
g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered",
ref_count_transfer_child_level_reordered);
+ g_test_add_func ("/TreeModelFilter/ref-count/transfer/child-level/reordered/filtered",
+ ref_count_transfer_child_level_reordered_filtered);
g_test_add_func ("/TreeModelFilter/specific/path-dependent-filter",
specific_path_dependent_filter);