[glib/bad-liststore] Add a test that shows liststore messing up



commit 149c2c007781818d78cb24269d46a98634857fbc
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 6 14:09:46 2019 -0500

    Add a test that shows liststore messing up
    
    Calling
    g_list_model_get_item (store, 0);
    g_list_model_get_item (store, -1u);
    does not return NULL for the second call
    as it should.

 gio/tests/glistmodel.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gio/tests/glistmodel.c b/gio/tests/glistmodel.c
index 533e2e47d..2ed2fbd9c 100644
--- a/gio/tests/glistmodel.c
+++ b/gio/tests/glistmodel.c
@@ -778,6 +778,29 @@ test_store_signal_items_changed (void)
   g_object_unref (store);
 }
 
+static void
+test_store_past_end (void)
+{
+  GListStore *store;
+  GListModel *model;
+  GSimpleAction *item;
+
+  store = g_list_store_new (G_TYPE_SIMPLE_ACTION);
+  model = G_LIST_MODEL (store);
+
+  item = g_simple_action_new ("2", NULL);
+  g_list_store_append (store, item);
+  g_object_unref (item);
+
+  g_assert_cmpint (g_list_model_get_n_items (model), ==, 1);
+  item = g_list_model_get_item (model, 0);
+  g_assert_nonnull (item);
+  item = g_list_model_get_item (model, G_MAXUINT);
+  g_assert_null (item);
+
+  g_object_unref (store);
+}
+
 int main (int argc, char *argv[])
 {
   g_test_init (&argc, &argv, NULL);
@@ -809,6 +832,7 @@ int main (int argc, char *argv[])
                    test_store_get_item_cache);
   g_test_add_func ("/glistmodel/store/items-changed",
                    test_store_signal_items_changed);
+  g_test_add_func ("/glistmodel/store/past-end", test_store_past_end);
 
   return g_test_run ();
 }


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