diff options
author | Benjamin Otte <otte@redhat.com> | 2011-11-25 16:31:34 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-11-29 20:44:57 +0100 |
commit | 64ff56e7187fdeeacec717429db39575e411f777 (patch) | |
tree | 6a73060d07ec69bbd9f3fc29237be0fedc39a28d /tests/testtreechanging.c | |
parent | 763e4b9f45703397b5d703b1c757facc2cfacc45 (diff) | |
download | gtk+-64ff56e7187fdeeacec717429db39575e411f777.tar.gz |
tests: Check that the cursor keeps up to date
This actually demonstrates a bug where the treeview doesn't emit a
cursor-changed signal when the cursor row is deleted.
Diffstat (limited to 'tests/testtreechanging.c')
-rw-r--r-- | tests/testtreechanging.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/testtreechanging.c b/tests/testtreechanging.c index 3dd4192925..e5ab82b5a6 100644 --- a/tests/testtreechanging.c +++ b/tests/testtreechanging.c @@ -134,6 +134,39 @@ add_or_delete (GtkTreeView *treeview) delete (treeview); } +static void +check_cursor (GtkTreeView *treeview) +{ + GtkTreeRowReference *ref = g_object_get_data (G_OBJECT (treeview), "cursor"); + GtkTreePath *expected, *cursor; + + gtk_tree_view_get_cursor (treeview, &cursor, NULL); + if (ref == NULL) + { + g_assert (cursor == NULL); + } + else + { + g_assert (cursor != NULL); + g_assert (gtk_tree_row_reference_valid (ref)); + + expected = gtk_tree_row_reference_get_path (ref); + g_assert (expected != NULL); + g_assert (gtk_tree_path_compare (expected, cursor) == 0); + + gtk_tree_path_free (expected); + } + + if (cursor) + gtk_tree_path_free (cursor); +} + +static void +check_sanity (GtkTreeView *treeview) +{ + check_cursor (treeview); +} + static gboolean dance (gpointer treeview) { @@ -144,9 +177,37 @@ dance (gpointer treeview) funcs[g_random_int_range (0, G_N_ELEMENTS(funcs))] (treeview); + check_sanity (treeview); + return TRUE; } +static void +cursor_changed_cb (GtkTreeView *treeview, + gpointer unused) +{ + GtkTreePath *path; + GtkTreeRowReference *ref; + + gtk_tree_view_get_cursor (treeview, &path, NULL); + if (path) + { + ref = gtk_tree_row_reference_new (gtk_tree_view_get_model (treeview), + path); + gtk_tree_path_free (path); + } + else + ref = NULL; + g_object_set_data_full (G_OBJECT (treeview), "cursor", ref, (GDestroyNotify) gtk_tree_row_reference_free); +} + +static void +setup_sanity_checks (GtkTreeView *treeview) +{ + g_signal_connect (treeview, "cursor-changed", G_CALLBACK (cursor_changed_cb), NULL); + cursor_changed_cb (treeview, NULL); +} + int main (int argc, char **argv) @@ -177,6 +238,7 @@ main (int argc, model = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_UINT)); treeview = gtk_tree_view_new_with_model (model); g_object_unref (model); + setup_sanity_checks (GTK_TREE_VIEW (treeview)); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), 0, "Counter", |