[gtk/wip/otte/for-master: 1/3] filterlistmodel: Don't filter out every 513th element
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/for-master: 1/3] filterlistmodel: Don't filter out every 513th element
- Date: Thu, 9 Jul 2020 20:34:58 +0000 (UTC)
commit 986f721938781edbc04f9a6fb83dc8f7263b2336
Author: Benjamin Otte <otte redhat com>
Date: Thu Jul 9 22:22:04 2020 +0200
filterlistmodel: Don't filter out every 513th element
Incremental filtering would skip every 513th element due to an
off-by-one error.
Test included
gtk/gtkfilterlistmodel.c | 2 +-
testsuite/gtk/filterlistmodel.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkfilterlistmodel.c b/gtk/gtkfilterlistmodel.c
index bd486bf9bf..a1a667190b 100644
--- a/gtk/gtkfilterlistmodel.c
+++ b/gtk/gtkfilterlistmodel.c
@@ -178,7 +178,7 @@ gtk_filter_list_model_run_filter (GtkFilterListModel *self,
}
if (more)
- gtk_bitset_remove_range_closed (self->pending, 0, pos);
+ gtk_bitset_remove_range_closed (self->pending, 0, pos - 1);
else
g_clear_pointer (&self->pending, gtk_bitset_unref);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PENDING]);
diff --git a/testsuite/gtk/filterlistmodel.c b/testsuite/gtk/filterlistmodel.c
index 0e29cf501c..d0e55c57bf 100644
--- a/testsuite/gtk/filterlistmodel.c
+++ b/testsuite/gtk/filterlistmodel.c
@@ -88,6 +88,11 @@ add (GListStore *store,
g_string_set_size (changes, 0); \
}G_STMT_END
+#define ignore_changes(model) G_STMT_START{ \
+ GString *changes = g_object_get_qdata (G_OBJECT (model), changes_quark); \
+ g_string_set_size (changes, 0); \
+}G_STMT_END
+
static GListStore *
new_empty_store (void)
{
@@ -345,6 +350,33 @@ test_change_filter (void)
g_object_unref (filter);
}
+static void
+test_incremental (void)
+{
+ GtkFilterListModel *filter;
+ GtkFilter *custom;
+
+ /* everything is filtered */
+ filter = new_model (1000, is_larger_than, GUINT_TO_POINTER (10000));
+ gtk_filter_list_model_set_incremental (filter, TRUE);
+ assert_model (filter, "");
+ assert_changes (filter, "");
+
+ custom = gtk_custom_filter_new (is_near, GUINT_TO_POINTER (512), NULL);
+ gtk_filter_list_model_set_filter (filter, custom);
+ g_object_unref (custom);
+ assert_model (filter, "");
+ assert_changes (filter, "");
+
+ while (g_main_context_pending (NULL))
+ g_main_context_iteration (NULL, TRUE);
+ assert_model (filter, "510 511 512 513 514");
+ /* implementation detail */
+ ignore_changes (filter);
+
+ g_object_unref (filter);
+}
+
int
main (int argc, char *argv[])
{
@@ -357,6 +389,7 @@ main (int argc, char *argv[])
g_test_add_func ("/filterlistmodel/create", test_create);
g_test_add_func ("/filterlistmodel/empty_set_filter", test_empty_set_filter);
g_test_add_func ("/filterlistmodel/change_filter", test_change_filter);
+ g_test_add_func ("/filterlistmodel/incremental", test_incremental);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]