[gtk: 1/2] gtk: Allow selection models to take null list model during construction
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] gtk: Allow selection models to take null list model during construction
- Date: Wed, 17 Mar 2021 14:09:39 +0000 (UTC)
commit cd7748519391fabc7cd8ddc34783b6ad858ac5d1
Author: Jason Francis <jason@cycles.network>
Date: Mon Mar 15 09:30:33 2021 -0400
gtk: Allow selection models to take null list model during construction
This brings it in line with the documentation, and with the respective
set_model() functions.
gtk/gtkmultiselection.c | 2 +-
gtk/gtknoselection.c | 2 +-
gtk/gtksingleselection.c | 2 +-
testsuite/gtk/multiselection.c | 12 ++++++++++++
testsuite/gtk/singleselection.c | 12 ++++++++++++
5 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c
index 2b60ab8302..3df394d1d1 100644
--- a/gtk/gtkmultiselection.c
+++ b/gtk/gtkmultiselection.c
@@ -378,7 +378,7 @@ gtk_multi_selection_new (GListModel *model)
{
GtkMultiSelection *self;
- g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_MULTI_SELECTION,
"model", model,
diff --git a/gtk/gtknoselection.c b/gtk/gtknoselection.c
index 36d4de008d..bc7363bbb8 100644
--- a/gtk/gtknoselection.c
+++ b/gtk/gtknoselection.c
@@ -224,7 +224,7 @@ gtk_no_selection_new (GListModel *model)
{
GtkNoSelection *self;
- g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_NO_SELECTION,
"model", model,
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c
index ad1cba6486..fcdd911503 100644
--- a/gtk/gtksingleselection.c
+++ b/gtk/gtksingleselection.c
@@ -460,7 +460,7 @@ gtk_single_selection_new (GListModel *model)
{
GtkSingleSelection *self;
- g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
self = g_object_new (GTK_TYPE_SINGLE_SELECTION,
"model", model,
diff --git a/testsuite/gtk/multiselection.c b/testsuite/gtk/multiselection.c
index bbfaa2330f..c1457488e3 100644
--- a/testsuite/gtk/multiselection.c
+++ b/testsuite/gtk/multiselection.c
@@ -304,6 +304,17 @@ test_create (void)
g_object_unref (selection);
}
+static void
+test_create_empty (void)
+{
+ GtkMultiSelection *selection;
+
+ selection = gtk_multi_selection_new (NULL);
+ g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
+
+ g_object_unref (selection);
+}
+
static void
test_changes (void)
{
@@ -682,6 +693,7 @@ main (int argc, char *argv[])
selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
g_test_add_func ("/multiselection/create", test_create);
+ g_test_add_func ("/multiselection/create-empty", test_create_empty);
#if GLIB_CHECK_VERSION (2, 58, 0) /* g_list_store_splice() is broken before 2.58 */
g_test_add_func ("/multiselection/changes", test_changes);
#endif
diff --git a/testsuite/gtk/singleselection.c b/testsuite/gtk/singleselection.c
index b94b38091f..85e1f4163b 100644
--- a/testsuite/gtk/singleselection.c
+++ b/testsuite/gtk/singleselection.c
@@ -304,6 +304,17 @@ test_create (void)
g_object_unref (selection);
}
+static void
+test_create_empty (void)
+{
+ GtkSingleSelection *selection;
+
+ selection = gtk_single_selection_new (NULL);
+ g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (selection)), ==, 0);
+
+ g_object_unref (selection);
+}
+
static void
test_changes (void)
{
@@ -706,6 +717,7 @@ main (int argc, char *argv[])
selection_quark = g_quark_from_static_string ("Mana mana, badibidibi");
g_test_add_func ("/singleselection/create", test_create);
+ g_test_add_func ("/singleselection/create-empty", test_create_empty);
g_test_add_func ("/singleselection/autoselect", test_autoselect);
g_test_add_func ("/singleselection/autoselect-toggle", test_autoselect_toggle);
g_test_add_func ("/singleselection/selection", test_selection);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]