diff options
author | Benjamin Otte <otte@redhat.com> | 2011-11-25 20:56:07 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-11-29 20:44:57 +0100 |
commit | b843aa14c46a8b287e0fed4df15df1dbbf71b711 (patch) | |
tree | 3c79a0282b6464f4a2f2ad4dd9de46f449a8398a /tests/testtreechanging.c | |
parent | caa9ca94cc98029ca9db16ea169462e6ae83b5ad (diff) | |
download | gtk+-b843aa14c46a8b287e0fed4df15df1dbbf71b711.tar.gz |
tests: Add automatic expanding/collapsing
Makes the test test even more stuff.
Diffstat (limited to 'tests/testtreechanging.c')
-rw-r--r-- | tests/testtreechanging.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/testtreechanging.c b/tests/testtreechanging.c index 27a9d4aab1..cb29f8493a 100644 --- a/tests/testtreechanging.c +++ b/tests/testtreechanging.c @@ -155,6 +155,68 @@ add_or_delete (GtkTreeView *treeview) delete (treeview); } +/* XXX: We only expand/collapse from the top and not randomly */ +static void +expand (GtkTreeView *treeview) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gboolean valid; + + model = gtk_tree_view_get_model (treeview); + + for (valid = gtk_tree_model_get_iter_first (model, &iter); + valid; + valid = tree_model_iter_step (model, &iter)) + { + if (gtk_tree_model_iter_has_child (model, &iter)) + { + path = gtk_tree_model_get_path (model, &iter); + if (!gtk_tree_view_row_expanded (treeview, path)) + { + gtk_tree_view_expand_row (treeview, path, FALSE); + gtk_tree_path_free (path); + return; + } + gtk_tree_path_free (path); + } + } +} + +static void +collapse (GtkTreeView *treeview) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *last, *path; + gboolean valid; + + model = gtk_tree_view_get_model (treeview); + last = NULL; + + for (valid = gtk_tree_model_get_iter_first (model, &iter); + valid; + valid = tree_model_iter_step (model, &iter)) + { + path = gtk_tree_model_get_path (model, &iter); + if (gtk_tree_view_row_expanded (treeview, path)) + { + if (last) + gtk_tree_path_free (last); + last = path; + } + else + gtk_tree_path_free (path); + } + + if (last) + { + gtk_tree_view_collapse_row (treeview, last); + gtk_tree_path_free (last); + } +} + static void check_cursor (GtkTreeView *treeview) { @@ -193,7 +255,9 @@ dance (gpointer treeview) { static const DoStuffFunc funcs[] = { add_or_delete, - add_or_delete + add_or_delete, + expand, + collapse }; funcs[g_random_int_range (0, G_N_ELEMENTS(funcs))] (treeview); |