forked from AuroraMiddleware/gtk
Add tests for empty list models
Test that all our models return NULL for out-of-range get_item calls, as expected.
This commit is contained in:
parent
a526daf310
commit
007cdf8787
@ -376,6 +376,35 @@ test_incremental (void)
|
|||||||
g_object_unref (filter);
|
g_object_unref (filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_empty (void)
|
||||||
|
{
|
||||||
|
GtkFilterListModel *filter;
|
||||||
|
GListStore *store;
|
||||||
|
GtkFilter *f;
|
||||||
|
|
||||||
|
filter = gtk_filter_list_model_new (NULL, NULL);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (filter)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 11));
|
||||||
|
|
||||||
|
store = g_list_store_new (G_TYPE_OBJECT);
|
||||||
|
gtk_filter_list_model_set_model (filter, G_LIST_MODEL (store));
|
||||||
|
g_object_unref (store);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (filter)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 11));
|
||||||
|
|
||||||
|
f = GTK_FILTER (gtk_every_filter_new ());
|
||||||
|
gtk_filter_list_model_set_filter (filter, f);
|
||||||
|
g_object_unref (f);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (filter)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (filter), 11));
|
||||||
|
|
||||||
|
g_object_unref (filter);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -389,6 +418,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/filterlistmodel/empty_set_filter", test_empty_set_filter);
|
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/change_filter", test_change_filter);
|
||||||
g_test_add_func ("/filterlistmodel/incremental", test_incremental);
|
g_test_add_func ("/filterlistmodel/incremental", test_incremental);
|
||||||
|
g_test_add_func ("/filterlistmodel/empty", test_empty);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
@ -681,6 +681,47 @@ test_set_model (void)
|
|||||||
g_object_unref (selection);
|
g_object_unref (selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_empty (void)
|
||||||
|
{
|
||||||
|
GtkMultiSelection *selection;
|
||||||
|
GListStore *store;
|
||||||
|
|
||||||
|
selection = gtk_multi_selection_new (NULL);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (selection), 11));
|
||||||
|
|
||||||
|
store = g_list_store_new (G_TYPE_OBJECT);
|
||||||
|
gtk_multi_selection_set_model (selection, G_LIST_MODEL (store));
|
||||||
|
g_object_unref (store);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (selection), 11));
|
||||||
|
|
||||||
|
g_object_unref (selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_empty_filter (void)
|
||||||
|
{
|
||||||
|
GtkStringList *stringlist;
|
||||||
|
GtkMultiSelection *selection;
|
||||||
|
GtkSelectionFilterModel *selection_filter;
|
||||||
|
|
||||||
|
stringlist = gtk_string_list_new (NULL);
|
||||||
|
gtk_string_list_append (stringlist, "first item");
|
||||||
|
|
||||||
|
selection = gtk_multi_selection_new (G_LIST_MODEL (stringlist));
|
||||||
|
selection_filter = gtk_selection_filter_model_new (GTK_SELECTION_MODEL (selection));
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (selection_filter)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (selection_filter), 11));
|
||||||
|
|
||||||
|
g_object_unref (selection_filter);
|
||||||
|
g_object_unref (selection);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -703,6 +744,8 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/multiselection/set_selection", test_set_selection);
|
g_test_add_func ("/multiselection/set_selection", test_set_selection);
|
||||||
g_test_add_func ("/multiselection/selection-filter", test_selection_filter);
|
g_test_add_func ("/multiselection/selection-filter", test_selection_filter);
|
||||||
g_test_add_func ("/multiselection/set-model", test_set_model);
|
g_test_add_func ("/multiselection/set-model", test_set_model);
|
||||||
|
g_test_add_func ("/multiselection/empty", test_empty);
|
||||||
|
g_test_add_func ("/multiselection/selection-filter/empty", test_empty_filter);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
@ -706,6 +706,27 @@ test_set_model (void)
|
|||||||
g_object_unref (selection);
|
g_object_unref (selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_empty (void)
|
||||||
|
{
|
||||||
|
GtkSingleSelection *selection;
|
||||||
|
GListStore *store;
|
||||||
|
|
||||||
|
selection = gtk_single_selection_new (NULL);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (selection), 11));
|
||||||
|
|
||||||
|
store = g_list_store_new (G_TYPE_OBJECT);
|
||||||
|
gtk_single_selection_set_model (selection, G_LIST_MODEL (store));
|
||||||
|
g_object_unref (store);
|
||||||
|
|
||||||
|
g_assert_cmpuint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
|
||||||
|
g_assert_null (g_list_model_get_item (G_LIST_MODEL (selection), 11));
|
||||||
|
|
||||||
|
g_object_unref (selection);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -726,6 +747,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/singleselection/query-range", test_query_range);
|
g_test_add_func ("/singleselection/query-range", test_query_range);
|
||||||
g_test_add_func ("/singleselection/changes", test_changes);
|
g_test_add_func ("/singleselection/changes", test_changes);
|
||||||
g_test_add_func ("/singleselection/set-model", test_set_model);
|
g_test_add_func ("/singleselection/set-model", test_set_model);
|
||||||
|
g_test_add_func ("/singleselection/empty", test_empty);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user