[gtk+/gtk-3-4] treemodelsort: fix iter_previous so it can go back to the first item



commit d6fc987f2e3fedd2276704df54ba743b68e3ab64
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Apr 22 22:32:46 2012 +0200

    treemodelsort: fix iter_previous so it can go back to the first item
    
    It was getting the previous element, then checking whether it was the
    first one, that has to be inverted so it doesn't stop on the second
    item.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674587

 gtk/gtktreemodelsort.c |    5 ++-
 gtk/tests/sortmodel.c  |   61 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktreemodelsort.c b/gtk/gtktreemodelsort.c
index 0e89679..b2046c2 100644
--- a/gtk/gtktreemodelsort.c
+++ b/gtk/gtktreemodelsort.c
@@ -1406,12 +1406,13 @@ gtk_tree_model_sort_iter_previous (GtkTreeModel *tree_model,
 
   elt = iter->user_data2;
 
-  siter = g_sequence_iter_prev (elt->siter);
-  if (g_sequence_iter_is_begin (siter))
+  if (g_sequence_iter_is_begin (elt->siter))
     {
       iter->stamp = 0;
       return FALSE;
     }
+
+  siter = g_sequence_iter_prev (elt->siter);
   iter->user_data2 = GET_ELT (siter);
 
   return TRUE;
diff --git a/gtk/tests/sortmodel.c b/gtk/tests/sortmodel.c
index 484e2a8..147db53 100644
--- a/gtk/tests/sortmodel.c
+++ b/gtk/tests/sortmodel.c
@@ -1113,6 +1113,64 @@ specific_bug_364946 (void)
   gtk_tree_model_sort_clear_cache (GTK_TREE_MODEL_SORT (s_model));
 }
 
+static void
+iter_test (GtkTreeModel *model)
+{
+  GtkTreeIter a, b;
+
+  g_assert (gtk_tree_model_get_iter_first (model, &a));
+
+  g_assert (gtk_tree_model_iter_next (model, &a));
+  g_assert (gtk_tree_model_iter_next (model, &a));
+  b = a;
+  g_assert (!gtk_tree_model_iter_next (model, &b));
+
+  g_assert (gtk_tree_model_iter_previous (model, &a));
+  g_assert (gtk_tree_model_iter_previous (model, &a));
+  b = a;
+  g_assert (!gtk_tree_model_iter_previous (model, &b));
+}
+
+static void
+specific_bug_674587 (void)
+{
+  GtkListStore *l;
+  GtkTreeStore *t;
+  GtkTreeModel *m;
+  GtkTreeIter a;
+
+  l = gtk_list_store_new (1, G_TYPE_STRING);
+
+  gtk_list_store_append (l, &a);
+  gtk_list_store_set (l, &a, 0, "0", -1);
+  gtk_list_store_append (l, &a);
+  gtk_list_store_set (l, &a, 0, "1", -1);
+  gtk_list_store_append (l, &a);
+  gtk_list_store_set (l, &a, 0, "2", -1);
+
+  iter_test (GTK_TREE_MODEL (l));
+
+  g_object_unref (l);
+
+  t = gtk_tree_store_new (1, G_TYPE_STRING);
+
+  gtk_tree_store_append (t, &a, NULL);
+  gtk_tree_store_set (t, &a, 0, "0", -1);
+  gtk_tree_store_append (t, &a, NULL);
+  gtk_tree_store_set (t, &a, 0, "1", -1);
+  gtk_tree_store_append (t, &a, NULL);
+  gtk_tree_store_set (t, &a, 0, "2", -1);
+
+  iter_test (GTK_TREE_MODEL (t));
+
+  m = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (t));
+
+  iter_test (m);
+
+  g_object_unref (t);
+  g_object_unref (m);
+}
+
 /* main */
 
 void
@@ -1146,4 +1204,7 @@ register_sort_model_tests (void)
                    specific_bug_300089);
   g_test_add_func ("/TreeModelSort/specific/bug-364946",
                    specific_bug_364946);
+  g_test_add_func ("/TreeModelSort/specific/bug-674587",
+                   specific_bug_674587);
 }
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]