Merge branch 'matthiasc/for-main' into 'main'

filterlistmodel: Add a test

See merge request GNOME/gtk!4884
This commit is contained in:
Matthias Clasen 2022-07-17 10:50:22 +00:00
commit 1d94c75a78
3 changed files with 64 additions and 0 deletions

View File

@ -414,6 +414,36 @@ test_empty (void)
g_object_unref (filter);
}
static void
test_add_remove_item (void)
{
GtkFilterListModel *filter;
GListStore *store;
filter = new_model (10, is_smaller_than, GUINT_TO_POINTER (7));
assert_model (filter, "1 2 3 4 5 6");
assert_changes (filter, "");
store = G_LIST_STORE (gtk_filter_list_model_get_model (filter));
add (store, 9);
assert_model (filter, "1 2 3 4 5 6");
assert_changes (filter, "");
add (store, 1);
assert_model (filter, "1 2 3 4 5 6 1");
assert_changes (filter, "+6*");
g_list_store_remove (store, 10);
assert_model (filter, "1 2 3 4 5 6 1");
assert_changes (filter, "");
g_list_store_remove (store, 10);
assert_model (filter, "1 2 3 4 5 6");
assert_changes (filter, "-6*");
g_object_unref (filter);
}
int
main (int argc, char *argv[])
{
@ -428,6 +458,7 @@ main (int argc, char *argv[])
g_test_add_func ("/filterlistmodel/change_filter", test_change_filter);
g_test_add_func ("/filterlistmodel/incremental", test_incremental);
g_test_add_func ("/filterlistmodel/empty", test_empty);
g_test_add_func ("/filterlistmodel/add_remove_item", test_add_remove_item);
return g_test_run ();
}

View File

@ -305,6 +305,15 @@ test_changes (void)
g_list_store_remove (store, 19);
assert_changes (slice, "");
splice (store, 1, 1, (guint[]) { 111 }, 1);
assert_changes (slice, "");
splice (store, 18, 1, (guint[]) { 19, 20 }, 2);
assert_changes (slice, "");
g_list_store_remove (store, 19);
assert_changes (slice, "");
g_list_store_remove (store, 1);
assert_model (slice, "12 13 14 15 16");
assert_changes (slice, "0-5+5");

View File

@ -543,6 +543,29 @@ test_out_of_bounds_access (void)
g_object_unref (sort);
}
static void
test_add_remove_item (void)
{
GtkSortListModel *sort;
GListStore *store;
store = new_store ((guint[]) { 4, 8, 2, 6, 10, 0 });
sort = new_model (store);
assert_model (sort, "2 4 6 8 10");
assert_changes (sort, "");
add (store, 3);
assert_model (sort, "2 3 4 6 8 10");
assert_changes (sort, "+1*");
g_list_store_remove (store, 5);
assert_model (sort, "2 4 6 8 10");
assert_changes (sort, "-1*");
g_object_unref (store);
g_object_unref (sort);
}
int
main (int argc, char *argv[])
{
@ -563,6 +586,7 @@ main (int argc, char *argv[])
g_test_add_func ("/sortlistmodel/stability", test_stability);
g_test_add_func ("/sortlistmodel/incremental/remove", test_incremental_remove);
g_test_add_func ("/sortlistmodel/oob-access", test_out_of_bounds_access);
g_test_add_func ("/sortlistmodel/add-remove-item", test_add_remove_item);
return g_test_run ();
}