[gtk+] Add two unit tests for gtk_tree_model_filter_row_inserted
- From: Kristian Rietveld <kristian src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add two unit tests for gtk_tree_model_filter_row_inserted
- Date: Mon, 22 Aug 2011 19:40:18 +0000 (UTC)
commit 3452b0493dbe9a3159ec109e12f321035ed141f4
Author: Kristian Rietveld <kris gtk org>
Date: Sat May 14 14:47:39 2011 +0200
Add two unit tests for gtk_tree_model_filter_row_inserted
gtk/tests/filtermodel.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 150 insertions(+), 0 deletions(-)
---
diff --git a/gtk/tests/filtermodel.c b/gtk/tests/filtermodel.c
index 88fe123..ce75ec4 100644
--- a/gtk/tests/filtermodel.c
+++ b/gtk/tests/filtermodel.c
@@ -1824,6 +1824,150 @@ unfiltered_vroot_show_single_multi_level (FilterTest *fixture,
static void
+insert_before (void)
+{
+ GtkTreeStore *store;
+ GtkTreeModel *filter;
+ GtkWidget *tree_view;
+ SignalMonitor *monitor;
+ GtkTreeIter iter;
+ GtkTreeIter last_iter;
+ GtkTreePath *path;
+
+ /* This tests two aspects of the row-inserted handling:
+ * 1) If the newly inserted node was already handled by building
+ * the root level, don't handle it a second time.
+ * 2) Offsets of existing nodes must be updated when a new
+ * node is inserted.
+ */
+
+ store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
+ filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
+ 1);
+
+ tree_view = gtk_tree_view_new_with_model (filter);
+ monitor = signal_monitor_new (filter);
+
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 0);
+
+ /* Insert 0 */
+ path = gtk_tree_path_new_from_indices (0, -1);
+ signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_insert_with_values (store, &iter, NULL, 0,
+ 0, "Foo", 1, TRUE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
+
+ /* Insert 1 */
+ path = gtk_tree_path_new_from_indices (1, -1);
+ signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
+ 0, "Foo", 1, TRUE, -1);
+ last_iter = iter;
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
+
+ /* Insert on 1 again -- invisible */
+ gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
+ 0, "Foo", 1, FALSE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 2);
+
+ /* Insert on 1 again -- visible */
+ path = gtk_tree_path_new_from_indices (1, -1);
+ signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_insert_with_values (store, &iter, NULL, 1,
+ 0, "Foo", 1, TRUE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
+
+ /* Modify the iter that should be at the last position and check the
+ * signal we get.
+ */
+ path = gtk_tree_path_new_from_indices (2, -1);
+ signal_monitor_append_signal_path (monitor, ROW_CHANGED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_set (store, &last_iter, 0, "Foo changed", -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 3);
+}
+
+static void
+insert_child (void)
+{
+ GtkTreeStore *store;
+ GtkTreeModel *filter;
+ GtkWidget *tree_view;
+ SignalMonitor *monitor;
+ GtkTreeIter parent, iter;
+ GtkTreePath *path;
+
+ store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+ gtk_tree_store_insert_with_values (store, &parent, NULL, 0,
+ 0, "Parent", 1, TRUE, -1);
+
+
+ filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
+ 1);
+
+ tree_view = gtk_tree_view_new_with_model (filter);
+ monitor = signal_monitor_new (filter);
+
+ /* Insert child -- invisible */
+ path = gtk_tree_path_new_from_indices (0, -1);
+ signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
+ /* The signal is received twice, once a pass through from GtkTreeStore
+ * and one generated by GtkTreeModelFilter. Not accurate, but cannot
+ * hurt.
+ */
+ signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
+ 0, "Child", 1, FALSE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
+
+ /* Insert child */
+ path = gtk_tree_path_new_from_indices (0, 0, -1);
+ signal_monitor_append_signal_path (monitor, ROW_INSERTED, path);
+ gtk_tree_path_up (path); /* 0 */
+ signal_monitor_append_signal_path (monitor, ROW_HAS_CHILD_TOGGLED, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_store_insert_with_values (store, &iter, &parent, 0,
+ 0, "Child", 1, TRUE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
+
+ /* Insert child -- invisible */
+ gtk_tree_store_insert_with_values (store, &iter, &parent, 1,
+ 0, "Child", 1, FALSE, -1);
+
+ signal_monitor_assert_is_empty (monitor);
+ check_level_length (GTK_TREE_MODEL_FILTER (filter), NULL, 1);
+}
+
+
+
+static void
specific_remove_node (void)
{
GtkTreeIter iter, iter1, iter2, iter3;
@@ -3138,6 +3282,12 @@ register_filter_model_tests (void)
unfiltered_vroot_show_single_multi_level,
filter_test_teardown);
+ /* Inserts in child models after creation of filter model */
+ g_test_add_func ("/TreeModelFilter/insert/before",
+ insert_before);
+ g_test_add_func ("/TreeModelFilter/insert/child",
+ insert_child);
+
g_test_add_func ("/TreeModelFilter/specific/remove-node",
specific_remove_node);
g_test_add_func ("/TreeModelFilter/specific/remove-node-vroot",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]