diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-06-11 15:15:53 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-06-11 15:15:53 +0000 |
commit | d88e9353983c03bfdc722c5120616585fa874cb1 (patch) | |
tree | fadb7c52b92a974719b5489ba673f91a77b31d3e /testsuite | |
parent | c7c8b37e4c776879a434edbf487bbe22614b1c29 (diff) | |
parent | efd9aac3fa4fc56b7acb5181ec93add7c1a1bc84 (diff) | |
download | gtk+-d88e9353983c03bfdc722c5120616585fa874cb1.tar.gz |
Merge branch 'wip/otte/listmodels' into 'main'
19 listmodels: Add ::item-type and ::n-items
See merge request GNOME/gtk!4807
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/gtk/defaultvalue.c | 4 | ||||
-rw-r--r-- | testsuite/gtk/filterlistmodel-exhaustive.c | 28 | ||||
-rw-r--r-- | testsuite/gtk/filterlistmodel.c | 29 | ||||
-rw-r--r-- | testsuite/gtk/flattenlistmodel.c | 27 | ||||
-rw-r--r-- | testsuite/gtk/maplistmodel.c | 13 | ||||
-rw-r--r-- | testsuite/gtk/multiselection.c | 50 | ||||
-rw-r--r-- | testsuite/gtk/propertylookuplistmodel.c | 19 | ||||
-rw-r--r-- | testsuite/gtk/singleselection.c | 39 | ||||
-rw-r--r-- | testsuite/gtk/slicelistmodel.c | 23 | ||||
-rw-r--r-- | testsuite/gtk/sortlistmodel-exhaustive.c | 30 | ||||
-rw-r--r-- | testsuite/gtk/sortlistmodel.c | 29 | ||||
-rw-r--r-- | testsuite/gtk/treelistmodel.c | 21 |
12 files changed, 227 insertions, 85 deletions
diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c index d55e6d5381..455c2b3b25 100644 --- a/testsuite/gtk/defaultvalue.c +++ b/testsuite/gtk/defaultvalue.c @@ -298,6 +298,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS strcmp (pspec->name, "model") == 0) check = FALSE; + if (g_type_is_a (type, GTK_TYPE_TREE_LIST_MODEL) && + (strcmp (pspec->name, "item-type") == 0)) /* might be a treelistrow */ + check = FALSE; + /* This is set in init() */ if (g_type_is_a (type, GTK_TYPE_FONT_CHOOSER_WIDGET) && strcmp (pspec->name, "tweak-action") == 0) diff --git a/testsuite/gtk/filterlistmodel-exhaustive.c b/testsuite/gtk/filterlistmodel-exhaustive.c index b7366f4fb6..084f1d301d 100644 --- a/testsuite/gtk/filterlistmodel-exhaustive.c +++ b/testsuite/gtk/filterlistmodel-exhaustive.c @@ -75,6 +75,9 @@ assert_items_changed_correctly (GListModel *model, { guint i, n_items; + //sanity check that we got all notifies + g_assert_cmpuint (g_list_model_get_n_items (compare), ==, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items"))); + //g_print ("%s => %u -%u +%u => %s\n", model_to_string (compare), position, removed, added, model_to_string (model)); g_assert_cmpint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added); @@ -127,6 +130,21 @@ assert_items_changed_correctly (GListModel *model, } } +static void +assert_n_items_notified_properly (GListModel *model, + GParamSpec *pspec, + GListModel *compare) +{ + g_assert_cmpuint (g_list_model_get_n_items (model), !=, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items"))); + + /* These should hve been updated in items-changed, which should have been emitted first */ + g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare)); + + g_object_set_data (G_OBJECT (compare), + "last-notified-n-items", + GUINT_TO_POINTER (g_list_model_get_n_items (model))); +} + static GtkFilterListModel * filter_list_model_new (GListModel *source, GtkFilter *filter) @@ -154,6 +172,16 @@ filter_list_model_new (GListModel *source, (GClosureNotify) g_object_unref, 0); + g_object_set_data (G_OBJECT (check), + "last-notified-n-items", + GUINT_TO_POINTER (g_list_model_get_n_items (G_LIST_MODEL (check)))); + g_signal_connect_data (model, + "notify::n-items", + G_CALLBACK (assert_n_items_notified_properly), + g_object_ref (check), + (GClosureNotify) g_object_unref, + 0); + return model; } diff --git a/testsuite/gtk/filterlistmodel.c b/testsuite/gtk/filterlistmodel.c index cd109c2e0b..d35b73f74b 100644 --- a/testsuite/gtk/filterlistmodel.c +++ b/testsuite/gtk/filterlistmodel.c @@ -144,6 +144,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -171,6 +179,7 @@ new_model (guint size, changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -248,7 +257,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "1 2 3 4 5 6"); - assert_changes (filter, "6-4"); + assert_changes (filter, "6-4*"); g_object_unref (filter); filter = new_model (10, NULL, NULL); @@ -256,7 +265,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, ""); - assert_changes (filter, "0-10"); + assert_changes (filter, "0-10*"); g_object_unref (filter); filter = new_model (10, NULL, NULL); @@ -272,7 +281,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "4 5 6 7 8 9 10"); - assert_changes (filter, "0-3"); + assert_changes (filter, "0-3*"); g_object_unref (filter); filter = new_model (10, NULL, NULL); @@ -280,7 +289,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, ""); - assert_changes (filter, "0-10"); + assert_changes (filter, "0-10*"); g_object_unref (filter); filter = new_model (10, NULL, NULL); @@ -288,7 +297,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "3 4 5 6 7"); - assert_changes (filter, "0-10+5"); + assert_changes (filter, "0-10+5*"); g_object_unref (filter); filter = new_model (10, NULL, NULL); @@ -296,7 +305,7 @@ test_empty_set_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "1 2 8 9 10"); - assert_changes (filter, "2-5"); + assert_changes (filter, "2-5*"); g_object_unref (filter); } @@ -320,19 +329,19 @@ test_change_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "1 2 3 4 5 6"); - assert_changes (filter, "3-2+3"); + assert_changes (filter, "3-2+3*"); custom = GTK_FILTER (gtk_custom_filter_new (is_smaller_than, GUINT_TO_POINTER (6), NULL)); gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "1 2 3 4 5"); - assert_changes (filter, "-5"); + assert_changes (filter, "-5*"); custom = GTK_FILTER (gtk_custom_filter_new (is_larger_than, GUINT_TO_POINTER (4), NULL)); gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "5 6 7 8 9 10"); - assert_changes (filter, "0-5+6"); + assert_changes (filter, "0-5+6*"); custom = GTK_FILTER (gtk_custom_filter_new (is_not_near, GUINT_TO_POINTER (2), NULL)); gtk_filter_list_model_set_filter (filter, custom); @@ -344,7 +353,7 @@ test_change_filter (void) gtk_filter_list_model_set_filter (filter, custom); g_object_unref (custom); assert_model (filter, "1 7 8 9 10"); - assert_changes (filter, "0-2+1"); + assert_changes (filter, "0-2+1*"); g_object_unref (filter); } diff --git a/testsuite/gtk/flattenlistmodel.c b/testsuite/gtk/flattenlistmodel.c index 9144eac64a..4a310956fd 100644 --- a/testsuite/gtk/flattenlistmodel.c +++ b/testsuite/gtk/flattenlistmodel.c @@ -194,6 +194,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -216,6 +224,7 @@ new_model (GListStore *store) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -271,7 +280,7 @@ test_model_add (void) add_store (model, 8, 10, 1); assert_model (flat, "1 2 3 4 5 6 7 8 9 10"); - assert_changes (flat, "0+3, +3, 4+3, 7+3"); + assert_changes (flat, "0+3*, +3*, 4+3*, 7+3*"); g_object_unref (model); g_object_unref (flat); @@ -293,13 +302,13 @@ test_submodel_add (void) store[2] = add_store (model, 5, 4, 1); store[3] = add_store (model, 8, 8, 1); assert_model (flat, "2 3 4 8"); - assert_changes (flat, "0+2, +2, +3"); + assert_changes (flat, "0+2*, +2*, +3*"); insert (store[0], 0, 1); splice (store[2], 0, 0, (guint[3]) { 5, 6, 7 }, 3); splice (store[3], 1, 0, (guint[2]) { 9, 10 }, 2); assert_model (flat, "1 2 3 4 5 6 7 8 9 10"); - assert_changes (flat, "+0, 4+3, 8+2"); + assert_changes (flat, "+0*, 4+3*, 8+2*"); g_object_unref (model); g_object_unref (flat); @@ -325,19 +334,19 @@ test_submodel_add2 (void) add (store[0], 1); assert_model (flat, "1"); - assert_changes (flat, "+0"); + assert_changes (flat, "+0*"); add (store[1], 3); assert_model (flat, "1 3"); - assert_changes (flat, "+1"); + assert_changes (flat, "+1*"); add (store[0], 2); assert_model (flat, "1 2 3"); - assert_changes (flat, "+1"); + assert_changes (flat, "+1*"); add (store[1], 4); assert_model (flat, "1 2 3 4"); - assert_changes (flat, "+3"); + assert_changes (flat, "+3*"); g_object_unref (model); g_object_unref (flat); @@ -363,7 +372,7 @@ test_model_remove (void) g_list_store_remove (model, 0); g_object_unref (model); assert_model (flat, ""); - assert_changes (flat, "3-4, 3-3, 0-3"); + assert_changes (flat, "3-4*, 3-3*, 0-3*"); g_object_unref (flat); } @@ -389,7 +398,7 @@ test_submodel_remove (void) g_object_unref (model); assert_model (flat, "2 3 4 8"); - assert_changes (flat, "-0, 3-3, 4-2"); + assert_changes (flat, "-0*, 3-3*, 4-2*"); g_object_unref (flat); } diff --git a/testsuite/gtk/maplistmodel.c b/testsuite/gtk/maplistmodel.c index 6e42479624..2ee0c4cc64 100644 --- a/testsuite/gtk/maplistmodel.c +++ b/testsuite/gtk/maplistmodel.c @@ -165,6 +165,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -202,6 +210,7 @@ new_model (GListStore *store) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -249,11 +258,11 @@ test_set_model (void) store = new_store (1, 5, 1); gtk_map_list_model_set_model (map, G_LIST_MODEL (store)); assert_model (map, "2 4 6 8 10"); - assert_changes (map, "0+5"); + assert_changes (map, "0+5*"); gtk_map_list_model_set_model (map, NULL); assert_model (map, ""); - assert_changes (map, "0-5"); + assert_changes (map, "0-5*"); g_object_unref (store); g_object_unref (map); diff --git a/testsuite/gtk/multiselection.c b/testsuite/gtk/multiselection.c index 7117efb4e7..5825ede9ac 100644 --- a/testsuite/gtk/multiselection.c +++ b/testsuite/gtk/multiselection.c @@ -225,6 +225,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void selection_changed (GListModel *model, guint position, guint n_items, @@ -258,6 +266,7 @@ new_model (GListStore *store) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes); @@ -277,6 +286,7 @@ new_filter_model (GtkSelectionModel *model) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -331,19 +341,19 @@ test_changes (void) g_list_store_remove (store, 3); assert_model (selection, "1 2 3 5"); - assert_changes (selection, "-3"); + assert_changes (selection, "-3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); insert (store, 3, 99); assert_model (selection, "1 2 3 99 5"); - assert_changes (selection, "+3"); + assert_changes (selection, "+3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); splice (store, 3, 2, (guint[]) { 97 }, 1); assert_model (selection, "1 2 3 97"); - assert_changes (selection, "3-2+1"); + assert_changes (selection, "3-2+1*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); @@ -354,7 +364,7 @@ test_changes (void) insert (store, 2, 22); assert_model (selection, "1 2 22 3 97"); - assert_changes (selection, "+2"); + assert_changes (selection, "+2*"); assert_selection (selection, "2 3"); assert_selection_changes (selection, ""); @@ -543,74 +553,74 @@ test_selection_filter (void) assert_selection (selection, "4"); assert_selection_changes (selection, "3:1"); assert_model (filter, "4"); - assert_changes (filter, "+0"); + assert_changes (filter, "+0*"); ret = gtk_selection_model_unselect_item (selection, 3); g_assert_true (ret); assert_selection (selection, ""); assert_selection_changes (selection, "3:1"); assert_model (filter, ""); - assert_changes (filter, "-0"); + assert_changes (filter, "-0*"); ret = gtk_selection_model_select_item (selection, 1, FALSE); g_assert_true (ret); assert_selection (selection, "2"); assert_selection_changes (selection, "1:1"); assert_model (filter, "2"); - assert_changes (filter, "+0"); + assert_changes (filter, "+0*"); ret = gtk_selection_model_select_item (selection, 0, FALSE); g_assert_true (ret); assert_selection (selection, "1 2"); assert_selection_changes (selection, "0:1"); assert_model (filter, "1 2"); - assert_changes (filter, "+0"); + assert_changes (filter, "+0*"); ret = gtk_selection_model_unselect_item (selection, 0); g_assert_true (ret); assert_selection (selection, "2"); assert_selection_changes (selection, "0:1"); assert_model (filter, "2"); - assert_changes (filter, "-0"); + assert_changes (filter, "-0*"); ret = gtk_selection_model_select_range (selection, 3, 2, FALSE); g_assert_true (ret); assert_selection (selection, "2 4 5"); assert_selection_changes (selection, "3:2"); assert_model (filter, "2 4 5"); - assert_changes (filter, "1+2"); + assert_changes (filter, "1+2*"); ret = gtk_selection_model_unselect_range (selection, 3, 2); g_assert_true (ret); assert_selection (selection, "2"); assert_selection_changes (selection, "3:2"); assert_model (filter, "2"); - assert_changes (filter, "1-2"); + assert_changes (filter, "1-2*"); ret = gtk_selection_model_select_all (selection); g_assert_true (ret); assert_selection (selection, "1 2 3 4 5"); assert_selection_changes (selection, "0:5"); assert_model (filter, "1 2 3 4 5"); - assert_changes (filter, "0-1+5"); + assert_changes (filter, "0-1+5*"); ret = gtk_selection_model_unselect_all (selection); g_assert_true (ret); assert_selection (selection, ""); assert_selection_changes (selection, "0:5"); assert_model (filter, ""); - assert_changes (filter, "0-5"); + assert_changes (filter, "0-5*"); ret = gtk_selection_model_select_range (selection, 1, 3, FALSE); g_assert_true (ret); assert_selection (selection, "2 3 4"); assert_selection_changes (selection, "1:3"); assert_model (filter, "2 3 4"); - assert_changes (filter, "0+3"); + assert_changes (filter, "0+3*"); insert (store, 2, 22); assert_model (selection, "1 2 22 3 4 5"); - assert_changes (selection, "+2"); + assert_changes (selection, "+2*"); assert_selection (selection, "2 3 4"); assert_selection_changes (selection, ""); assert_model (filter, "2 3 4"); @@ -618,7 +628,7 @@ test_selection_filter (void) g_list_store_remove (store, 2); assert_model (selection, "1 2 3 4 5"); - assert_changes (selection, "-2"); + assert_changes (selection, "-2*"); assert_selection (selection, "2 3 4"); assert_selection_changes (selection, ""); assert_model (filter, "2 3 4"); @@ -651,17 +661,17 @@ test_set_model (void) /* we retain the selected item across model changes */ gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2); - assert_changes (selection, "0-5+3"); + assert_changes (selection, "0-5+3*"); assert_selection (selection, "2 3"); assert_selection_changes (selection, ""); gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), NULL); - assert_changes (selection, "0-3"); + assert_changes (selection, "0-3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2); - assert_changes (selection, "0+3"); + assert_changes (selection, "0+3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); @@ -672,7 +682,7 @@ test_set_model (void) /* we retain no selected item across model changes */ gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m1); - assert_changes (selection, "0-3+5"); + assert_changes (selection, "0-3+5*"); assert_selection (selection, "1 2 3"); assert_selection_changes (selection, ""); diff --git a/testsuite/gtk/propertylookuplistmodel.c b/testsuite/gtk/propertylookuplistmodel.c index df0f78a415..ea83357bf8 100644 --- a/testsuite/gtk/propertylookuplistmodel.c +++ b/testsuite/gtk/propertylookuplistmodel.c @@ -91,6 +91,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -145,6 +153,7 @@ new_model (gboolean fill) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -185,14 +194,14 @@ test_set_object (void) model = new_model (FALSE); gtk_property_lookup_list_model_set_object (model, widget); assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow"); - assert_changes (model, "+0"); + assert_changes (model, "+0*"); g_object_unref (model); model = new_model (FALSE); assert_model (model, ""); gtk_property_lookup_list_model_set_object (model, widget); assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow"); - assert_changes (model, "0+4"); + assert_changes (model, "0+4*"); g_object_unref (model); destroy_widgets (); @@ -212,15 +221,15 @@ test_change_property (void) assert_model (model, ""); /* make sure the model has a definite size */ gtk_property_lookup_list_model_set_object (model, widget); assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow"); - assert_changes (model, "0+4"); + assert_changes (model, "0+4*"); gtk_grid_remove (GTK_GRID (parent), widget); assert_model (model, "GtkLabel"); - assert_changes (model, "1-3"); + assert_changes (model, "1-3*"); gtk_box_append (GTK_BOX (grandparent), widget); assert_model (model, "GtkLabel GtkBox GtkWindow"); - assert_changes (model, "1+2"); + assert_changes (model, "1+2*"); g_object_unref (model); destroy_widgets (); diff --git a/testsuite/gtk/singleselection.c b/testsuite/gtk/singleselection.c index bb6462cd97..4465879d82 100644 --- a/testsuite/gtk/singleselection.c +++ b/testsuite/gtk/singleselection.c @@ -221,6 +221,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void selection_changed (GListModel *model, guint position, guint n_items, @@ -265,6 +273,7 @@ new_model (GListStore *store, gboolean autoselect, gboolean can_unselect) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes); @@ -336,19 +345,19 @@ test_changes (void) g_list_store_remove (store, 3); assert_model (selection, "1 2 3 5"); - assert_changes (selection, "-3"); + assert_changes (selection, "-3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); insert (store, 3, 99); assert_model (selection, "1 2 3 99 5"); - assert_changes (selection, "+3"); + assert_changes (selection, "+3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); splice (store, 3, 2, (guint[]) { 97 }, 1); assert_model (selection, "1 2 3 97"); - assert_changes (selection, "3-2+1"); + assert_changes (selection, "3-2+1*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); @@ -434,31 +443,31 @@ test_autoselect (void) add (store, 1); assert_model (selection, "1"); - assert_changes (selection, "+0"); + assert_changes (selection, "+0*"); assert_selection (selection, "1"); assert_selection_changes (selection, ""); splice (store, 0, 1, (guint[]) { 7, 8, 9 }, 3); assert_model (selection, "7 8 9"); - assert_changes (selection, "0-1+3"); + assert_changes (selection, "0-1+3*"); assert_selection (selection, "7"); assert_selection_changes (selection, ""); splice (store, 0, 0, (guint[]) { 5, 6 }, 2); assert_model (selection, "5 6 7 8 9"); - assert_changes (selection, "0+2"); + assert_changes (selection, "0+2*"); assert_selection (selection, "7"); assert_selection_changes (selection, ""); g_list_store_remove (store, 2); assert_model (selection, "5 6 8 9"); - assert_changes (selection, "2-2+1"); + assert_changes (selection, "2-2+1*"); assert_selection (selection, "8"); assert_selection_changes (selection, ""); splice (store, 2, 2, NULL, 0); assert_model (selection, "5 6"); - assert_changes (selection, "1-3+1"); + assert_changes (selection, "1-3+1*"); assert_selection (selection, "6"); assert_selection_changes (selection, ""); @@ -470,13 +479,13 @@ test_autoselect (void) g_list_store_remove (store, 0); assert_model (selection, "2"); - assert_changes (selection, "-0"); + assert_changes (selection, "-0*"); assert_selection (selection, "2"); assert_selection_changes (selection, ""); g_list_store_remove (store, 0); assert_model (selection, ""); - assert_changes (selection, "-0"); + assert_changes (selection, "-0*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); @@ -671,24 +680,24 @@ test_set_model (void) /* we retain the selected item across model changes */ gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2); - assert_changes (selection, "0-5+3"); + assert_changes (selection, "0-5+3*"); assert_selection (selection, "1"); assert_selection_changes (selection, ""); gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), NULL); - assert_changes (selection, "0-3"); + assert_changes (selection, "0-3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE); gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2); - assert_changes (selection, "0+3"); + assert_changes (selection, "0+3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); /* we retain no selected item across model changes */ gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m1); - assert_changes (selection, "0-3+5"); + assert_changes (selection, "0-3+5*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); @@ -697,7 +706,7 @@ test_set_model (void) assert_selection_changes (selection, "4:1"); gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2); - assert_changes (selection, "0-5+3"); + assert_changes (selection, "0-5+3*"); assert_selection (selection, ""); assert_selection_changes (selection, ""); diff --git a/testsuite/gtk/slicelistmodel.c b/testsuite/gtk/slicelistmodel.c index eab5bfec56..da87c8bd30 100644 --- a/testsuite/gtk/slicelistmodel.c +++ b/testsuite/gtk/slicelistmodel.c @@ -175,6 +175,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -198,6 +206,7 @@ new_model (GListStore *store, guint offset, guint size) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -245,11 +254,11 @@ test_set_model (void) store = new_store (1, 7, 2); gtk_slice_list_model_set_model (slice, G_LIST_MODEL (store)); assert_model (slice, "1 3"); - assert_changes (slice, "0+2"); + assert_changes (slice, "0+2*"); gtk_slice_list_model_set_model (slice, NULL); assert_model (slice, ""); - assert_changes (slice, "0-2"); + assert_changes (slice, "0-2*"); g_object_unref (store); g_object_unref (slice); @@ -272,11 +281,11 @@ test_set_slice (void) gtk_slice_list_model_set_size (slice, 2); assert_model (slice, "3 5"); - assert_changes (slice, "-2"); + assert_changes (slice, "-2*"); gtk_slice_list_model_set_size (slice, 10); assert_model (slice, "3 5 7"); - assert_changes (slice, "+2"); + assert_changes (slice, "+2*"); g_object_unref (store); g_object_unref (slice); @@ -306,15 +315,15 @@ test_changes (void) splice (store, 13, 6, (guint[]) { 97 }, 1); assert_model (slice, "12 13 99 97"); - assert_changes (slice, "3-2+1"); + assert_changes (slice, "3-2+1*"); splice (store, 13, 1, (guint[]) { 36, 37, 38 }, 3); assert_model (slice, "12 13 99 36 37"); - assert_changes (slice, "3-1+2"); + assert_changes (slice, "3-1+2*"); g_list_store_remove_all (store); assert_model (slice, ""); - assert_changes (slice, "0-5"); + assert_changes (slice, "0-5*"); g_object_unref (store); g_object_unref (slice); diff --git a/testsuite/gtk/sortlistmodel-exhaustive.c b/testsuite/gtk/sortlistmodel-exhaustive.c index 76aa8bfa2f..0ca2c68f5e 100644 --- a/testsuite/gtk/sortlistmodel-exhaustive.c +++ b/testsuite/gtk/sortlistmodel-exhaustive.c @@ -84,9 +84,12 @@ assert_items_changed_correctly (GListModel *model, { guint i, n_items; + //sanity check that we got all notifies + g_assert_cmpuint (g_list_model_get_n_items (compare), ==, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items"))); + //g_print ("%s => %u -%u +%u => %s\n", model_to_string (compare), position, removed, added, model_to_string (model)); - g_assert_cmpint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added); + g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added); n_items = g_list_model_get_n_items (model); if (position != 0 || removed != n_items) @@ -139,6 +142,21 @@ assert_items_changed_correctly (GListModel *model, } } +static void +assert_n_items_notified_properly (GListModel *model, + GParamSpec *pspec, + GListModel *compare) +{ + g_assert_cmpuint (g_list_model_get_n_items (model), !=, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items"))); + + /* These should hve been updated in items-changed, which should have been emitted first */ + g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare)); + + g_object_set_data (G_OBJECT (compare), + "last-notified-n-items", + GUINT_TO_POINTER (g_list_model_get_n_items (model))); +} + static GtkSortListModel * sort_list_model_new (GListModel *source, GtkSorter *sorter) @@ -162,6 +180,16 @@ sort_list_model_new (GListModel *source, (GClosureNotify) g_object_unref, 0); + g_object_set_data (G_OBJECT (check), + "last-notified-n-items", + GUINT_TO_POINTER (g_list_model_get_n_items (G_LIST_MODEL (check)))); + g_signal_connect_data (model, + "notify::n-items", + G_CALLBACK (assert_n_items_notified_properly), + g_object_ref (check), + (GClosureNotify) g_object_unref, + 0); + return model; } diff --git a/testsuite/gtk/sortlistmodel.c b/testsuite/gtk/sortlistmodel.c index 515d7a2e10..fa8915df8f 100644 --- a/testsuite/gtk/sortlistmodel.c +++ b/testsuite/gtk/sortlistmodel.c @@ -177,6 +177,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -228,6 +236,7 @@ new_model (gpointer model) changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes); g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes); return result; } @@ -275,11 +284,11 @@ test_set_model (void) store = new_store ((guint[]) { 4, 8, 2, 6, 10, 0 }); gtk_sort_list_model_set_model (sort, G_LIST_MODEL (store)); assert_model (sort, "4 8 2 6 10"); - assert_changes (sort, "0+5"); + assert_changes (sort, "0+5*"); gtk_sort_list_model_set_model (sort, NULL); assert_model (sort, ""); - assert_changes (sort, "0-5"); + assert_changes (sort, "0-5*"); g_object_unref (sort); @@ -290,11 +299,11 @@ test_set_model (void) gtk_sort_list_model_set_model (sort, NULL); assert_model (sort, ""); - assert_changes (sort, "0-5"); + assert_changes (sort, "0-5*"); gtk_sort_list_model_set_model (sort, G_LIST_MODEL (store)); assert_model (sort, "2 4 6 8 10"); - assert_changes (sort, "0+5"); + assert_changes (sort, "0+5*"); g_object_unref (store); g_object_unref (sort); @@ -345,7 +354,7 @@ test_add_items (void) assert_changes (sort, ""); splice (store, 4, 0, (guint[]) { 1, 2 }, 2); assert_model (sort, "1 2 49 50 51 99 100"); - assert_changes (sort, "0+2"); + assert_changes (sort, "0+2*"); g_object_unref (store); g_object_unref (sort); @@ -356,7 +365,7 @@ test_add_items (void) assert_changes (sort, ""); splice (store, 2, 0, (guint[]) { 49, 50, 51 }, 3); assert_model (sort, "1 2 49 50 51 99 100"); - assert_changes (sort, "2+3"); + assert_changes (sort, "2+3*"); g_object_unref (store); g_object_unref (sort); @@ -367,7 +376,7 @@ test_add_items (void) assert_changes (sort, ""); splice (store, 1, 0, (guint[]) { 99, 100 }, 2); assert_model (sort, "1 2 49 50 51 99 100"); - assert_changes (sort, "5+2"); + assert_changes (sort, "5+2*"); g_object_unref (store); g_object_unref (sort); } @@ -385,7 +394,7 @@ test_remove_items (void) assert_changes (sort, ""); splice (store, 4, 2, NULL, 0); assert_model (sort, "49 50 51 99 100"); - assert_changes (sort, "0-2"); + assert_changes (sort, "0-2*"); g_object_unref (store); g_object_unref (sort); @@ -396,7 +405,7 @@ test_remove_items (void) assert_changes (sort, ""); splice (store, 2, 3, NULL, 0); assert_model (sort, "1 2 99 100"); - assert_changes (sort, "2-3"); + assert_changes (sort, "2-3*"); g_object_unref (store); g_object_unref (sort); @@ -407,7 +416,7 @@ test_remove_items (void) assert_changes (sort, ""); splice (store, 1, 2, NULL, 0); assert_model (sort, "1 2 49 50 51"); - assert_changes (sort, "5-2"); + assert_changes (sort, "5-2*"); g_object_unref (store); g_object_unref (sort); } diff --git a/testsuite/gtk/treelistmodel.c b/testsuite/gtk/treelistmodel.c index 0ea7a37b6c..bf3f12caf3 100644 --- a/testsuite/gtk/treelistmodel.c +++ b/testsuite/gtk/treelistmodel.c @@ -143,6 +143,14 @@ items_changed (GListModel *model, } static void +notify_n_items (GObject *object, + GParamSpec *pspec, + GString *changes) +{ + g_string_append_c (changes, '*'); +} + +static void free_changes (gpointer data) { GString *changes = data; @@ -174,6 +182,7 @@ new_model (guint size, changes = g_string_new (""); g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes); g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes); + g_signal_connect (tree, "notify::n-items", G_CALLBACK (notify_n_items), changes); return tree; } @@ -193,7 +202,7 @@ test_expand (void) g_object_unref (row); } assert_model (tree, "100 100 90 80 70 60 50 40 30 20 10"); - assert_changes (tree, "1+10"); + assert_changes (tree, "1+10*"); for (i = g_list_model_get_n_items (G_LIST_MODEL (tree)); i > 0; i--) { @@ -202,7 +211,7 @@ test_expand (void) g_object_unref (row); } assert_model (tree, "100 100 100 99 98 97 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1"); - assert_changes (tree, "11+10, 10+10, 9+10, 8+10, 7+10, 6+10, 5+10, 4+10, 3+10, 2+10"); + assert_changes (tree, "11+10*, 10+10*, 9+10*, 8+10*, 7+10*, 6+10*, 5+10*, 4+10*, 3+10*, 2+10*"); for (i = g_list_model_get_n_items (G_LIST_MODEL (tree)); i > 0; i--) { @@ -229,25 +238,25 @@ test_remove_some (void) g_assert_true (G_IS_LIST_MODEL (item)); g_list_store_remove (item, 3); assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1"); - assert_changes (tree, "-5"); + assert_changes (tree, "-5*"); item = g_list_model_get_item (G_LIST_MODEL (tree), 0); g_assert_true (G_IS_LIST_MODEL (item)); g_list_store_remove (item, 3); assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1"); - assert_changes (tree, "33-11"); + assert_changes (tree, "33-11*"); item = g_list_model_get_item (G_LIST_MODEL (tree), 88); g_assert_true (G_IS_LIST_MODEL (item)); g_list_store_remove (item, 9); assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2"); - assert_changes (tree, "-98"); + assert_changes (tree, "-98*"); item = g_list_model_get_item (G_LIST_MODEL (tree), 0); g_assert_true (G_IS_LIST_MODEL (item)); g_list_store_remove (item, 8); assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11"); - assert_changes (tree, "88-10"); + assert_changes (tree, "88-10*"); g_object_unref (tree); } |