[gtk/prop-list: 69/96] Add a selection model test
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 69/96] Add a selection model test
- Date: Tue, 24 Dec 2019 20:42:43 +0000 (UTC)
commit ee76623e54a91deeb4b9db18d484bd71713e41ef
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 21 20:31:52 2019 -0500
Add a selection model test
The test shows that we are failing to emit
::selection-changed in some circumstances.
testsuite/gtk/singleselection.c | 44 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
---
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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]