diff --git a/testsuite/gtk/singleselection.c b/testsuite/gtk/singleselection.c index 24de458e1c..95c6339f93 100644 --- a/testsuite/gtk/singleselection.c +++ b/testsuite/gtk/singleselection.c @@ -642,6 +642,49 @@ test_query_range (void) g_object_unref (selection); } +static void +selection_changed_cb (GtkSelectionModel *model, + guint position, + guint n_items, + gpointer data) +{ + int *counter = data; + + (*counter)++; +} + +/* Test that the selection emits selection-changed when an item + * is autoselected due to the underlying store going from empty + * to non-empty. + */ +static void +test_empty (void) +{ + GListStore *store; + GtkSingleSelection *selection; + int counter; + GtkFilter *filter; + + store = g_list_store_new (GTK_TYPE_FILTER); + + counter = 0; + selection = gtk_single_selection_new (G_LIST_MODEL (store)); + g_signal_connect (selection, "selection-changed", G_CALLBACK (selection_changed_cb), &counter); + + g_assert_cmpint (gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (selection)), ==, GTK_INVALID_LIST_POSITION); + + filter = gtk_string_filter_new (); + g_list_store_append (store, filter); + g_object_unref (filter); + + g_assert_cmpint (gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (selection)), ==, 0); + + g_assert_cmpint (counter, ==, 1); + + g_object_unref (selection); + g_object_unref (store); +} + int main (int argc, char *argv[]) { @@ -660,6 +703,7 @@ main (int argc, char *argv[]) g_test_add_func ("/singleselection/persistence", test_persistence); g_test_add_func ("/singleselection/query-range", test_query_range); g_test_add_func ("/singleselection/changes", test_changes); + g_test_add_func ("/singleselection/empty", test_empty); return g_test_run (); }