From 714a0aa47d9b1d9b7c878441d477508e7161ffe8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 9 Jun 2022 18:20:06 +0100 Subject: [PATCH 1/2] gbinding: Remove some duplicated code for checking property names GObject already exports a public symbol for this with identical code. Signed-off-by: Philip Withnall --- gobject/gbinding.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/gobject/gbinding.c b/gobject/gbinding.c index a0b5de102..eede10bdc 100644 --- a/gobject/gbinding.c +++ b/gobject/gbinding.c @@ -699,30 +699,6 @@ is_canonical (const gchar *key) return (strchr (key, '_') == NULL); } -static gboolean -is_valid_property_name (const gchar *key) -{ - const gchar *p; - - /* First character must be a letter. */ - if ((key[0] < 'A' || key[0] > 'Z') && - (key[0] < 'a' || key[0] > 'z')) - return FALSE; - - for (p = key; *p != 0; p++) - { - const gchar c = *p; - - if (c != '-' && c != '_' && - (c < '0' || c > '9') && - (c < 'A' || c > 'Z') && - (c < 'a' || c > 'z')) - return FALSE; - } - - return TRUE; -} - static void g_binding_set_property (GObject *gobject, guint prop_id, @@ -1268,10 +1244,10 @@ g_object_bind_property_full (gpointer source, g_return_val_if_fail (G_IS_OBJECT (source), NULL); g_return_val_if_fail (source_property != NULL, NULL); - g_return_val_if_fail (is_valid_property_name (source_property), NULL); + g_return_val_if_fail (g_param_spec_is_valid_name (source_property), NULL); g_return_val_if_fail (G_IS_OBJECT (target), NULL); g_return_val_if_fail (target_property != NULL, NULL); - g_return_val_if_fail (is_valid_property_name (target_property), NULL); + g_return_val_if_fail (g_param_spec_is_valid_name (target_property), NULL); if (source == target && g_strcmp0 (source_property, target_property) == 0) { From 67a168c5d100ce90c9ac6d746e36aa9af2d99251 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 9 Jun 2022 18:20:29 +0100 Subject: [PATCH 2/2] tests: Test g_binding_get_source() and g_binding_get_target() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are deprecated, but it’s easy enough to test them anyway. This bumps up code coverage a bit and hopefully ensures we don’t accidentally regress on them in future. Signed-off-by: Philip Withnall --- gobject/tests/binding.c | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c index e63dd1e6e..b8373e345 100644 --- a/gobject/tests/binding.c +++ b/gobject/tests/binding.c @@ -2,6 +2,30 @@ #include #include +#define assert_cmpsource(binding, op, expected_source) G_STMT_START { \ + GObject *tmp, *tmp2; \ + tmp = g_binding_dup_source ((binding)); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + tmp2 = g_binding_get_source ((binding)); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + g_assert_nonnull (tmp); \ + g_assert_true ((gpointer) tmp op (gpointer) (expected_source)); \ + g_assert_true (tmp == tmp2); \ + g_object_unref (tmp); \ +} G_STMT_END + +#define assert_cmptarget(binding, op, expected_target) G_STMT_START { \ + GObject *tmp, *tmp2; \ + tmp = g_binding_dup_target ((binding)); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + tmp2 = g_binding_get_target ((binding)); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + g_assert_nonnull (tmp); \ + g_assert_true ((gpointer) tmp op (gpointer) (expected_target)); \ + g_assert_true (tmp == tmp2); \ + g_object_unref (tmp); \ +} G_STMT_END + typedef struct { GTypeInterface g_iface; } FooInterface; @@ -353,7 +377,6 @@ binding_default (void) { BindingSource *source = g_object_new (binding_source_get_type (), NULL); BindingTarget *target = g_object_new (binding_target_get_type (), NULL); - GObject *tmp; GBinding *binding; binding = g_object_bind_property (source, "foo", @@ -361,14 +384,10 @@ binding_default (void) G_BINDING_DEFAULT); g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding); - tmp = g_binding_dup_source (binding); - g_assert_nonnull (tmp); - g_assert_true ((BindingSource *) tmp == source); - g_object_unref (tmp); - tmp = g_binding_dup_target (binding); - g_assert_nonnull (tmp); - g_assert_true ((BindingTarget *) tmp == target); - g_object_unref (tmp); + + assert_cmpsource (binding, ==, source); + assert_cmptarget (binding, ==, target); + g_assert_cmpstr (g_binding_get_source_property (binding), ==, "foo"); g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar"); g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT); @@ -395,7 +414,6 @@ binding_canonicalisation (void) BindingSource *source = g_object_new (binding_source_get_type (), NULL); BindingTarget *target = g_object_new (binding_target_get_type (), NULL); GBinding *binding; - GObject *tmp; g_test_summary ("Test that bindings set up with non-canonical property names work"); @@ -404,14 +422,10 @@ binding_canonicalisation (void) G_BINDING_DEFAULT); g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding); - tmp = g_binding_dup_source (binding); - g_assert_nonnull (tmp); - g_assert_true ((BindingSource *) tmp == source); - g_object_unref (tmp); - tmp = g_binding_dup_target (binding); - g_assert_nonnull (tmp); - g_assert_true ((BindingTarget *) tmp == target); - g_object_unref (tmp); + + assert_cmpsource (binding, ==, source); + assert_cmptarget (binding, ==, target); + g_assert_cmpstr (g_binding_get_source_property (binding), ==, "double-value"); g_assert_cmpstr (g_binding_get_target_property (binding), ==, "double-value"); g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);