[gtk+] tests: Fix the iter stepping code
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] tests: Fix the iter stepping code
- Date: Tue, 29 Nov 2011 19:51:22 +0000 (UTC)
commit caa9ca94cc98029ca9db16ea169462e6ae83b5ad
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 25 20:54:48 2011 +0100
tests: Fix the iter stepping code
The old code actually was wrong and could cause assertions and crashes,
in particular when stepping out of a deep tree back onto the highest
layer.
tests/testtreechanging.c | 35 ++++++++++++++++++++++++++++-------
1 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/tests/testtreechanging.c b/tests/testtreechanging.c
index e5ab82b..27a9d4a 100644
--- a/tests/testtreechanging.c
+++ b/tests/testtreechanging.c
@@ -57,31 +57,52 @@ get_rows (GtkTreeView *treeview)
return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (treeview), "rows"));
}
+/* moves iter to the next iter in the model in the display order
+ * inside a treeview. Returns FALSE if no more rows exist.
+ */
+static gboolean
+tree_model_iter_step (GtkTreeModel *model,
+ GtkTreeIter *iter)
+{
+ GtkTreeIter tmp;
+
+ if (gtk_tree_model_iter_children (model, &tmp, iter))
+ {
+ *iter = tmp;
+ return TRUE;
+ }
+
+ do {
+ tmp = *iter;
+
+ if (gtk_tree_model_iter_next (model, iter))
+ return TRUE;
+ }
+ while (gtk_tree_model_iter_parent (model, iter, &tmp));
+
+ return FALSE;
+}
+
static void
delete (GtkTreeView *treeview)
{
guint n_rows = get_rows (treeview);
guint i = g_random_int_range (0, n_rows);
GtkTreeModel *model;
- GtkTreeIter iter, next;
+ GtkTreeIter iter;
model = gtk_tree_view_get_model (treeview);
if (!gtk_tree_model_get_iter_first (model, &iter))
return;
-
while (i-- > 0)
{
- next = iter;
- if (!gtk_tree_model_iter_children (model, &iter, &next) &&
- !gtk_tree_model_iter_next (model, &next) &&
- !gtk_tree_model_iter_parent (model, &next, &iter))
+ if (!tree_model_iter_step (model, &iter))
{
g_assert_not_reached ();
return;
}
- iter = next;
}
n_rows -= count_children (model, &iter) + 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]