Commit 3cbc4d97 authored by Christian Hergert's avatar Christian Hergert
Browse files

list-model-filter: relax bound requirements on get_item()

This tries to be more flexible in allowing a request past the end of the
available items. Such is described as allowed behavior in the GListModel
documentation.
parent e2a19f36
......@@ -347,10 +347,10 @@ dzl_list_model_filter_get_item (GListModel *model,
guint child_position;
g_assert (DZL_IS_LIST_MODEL_FILTER (self));
g_assert (position < (guint)g_sequence_get_length (priv->filter_seq));
iter = g_sequence_get_iter_at_pos (priv->filter_seq, position);
g_assert (!g_sequence_iter_is_end (iter));
if (g_sequence_iter_is_end (iter))
return NULL;
item = g_sequence_get (iter);
g_assert (item != NULL);
......
......@@ -61,6 +61,10 @@ test_basic (void)
filter = dzl_list_model_filter_new (G_LIST_MODEL (model));
g_assert (filter);
/* Test requesting past boundary */
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 0));
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 1));
for (i = 0; i < 1000; i++)
{
g_autoptr(TestItem) val = test_item_new (i);
......@@ -68,6 +72,9 @@ test_basic (void)
g_list_store_append (model, val);
}
/* Test requesting past boundary */
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 1000));
g_assert_cmpint (1000, ==, g_list_model_get_n_items (G_LIST_MODEL (model)));
g_assert_cmpint (1000, ==, g_list_model_get_n_items (G_LIST_MODEL (filter)));
......@@ -79,6 +86,7 @@ test_basic (void)
{
g_autoptr(TestItem) ele = g_list_model_get_item (G_LIST_MODEL (filter), i);
g_assert_nonnull (ele);
g_assert (TEST_IS_ITEM (ele));
g_assert (filter_func1 (G_OBJECT (ele), NULL));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment