forked from AuroraMiddleware/gtk
Add unit test for ref tranfer in rows-reordered with filtered rows
This commit is contained in:
parent
057a50d58e
commit
0bedb51b33
@ -3208,6 +3208,86 @@ ref_count_transfer_root_level_reordered (void)
|
||||
g_object_unref (ref_model);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user