mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 21:33:09 +02:00
Merge branch 'binding-code-duplication' into 'main'
gbinding: Remove some duplicated code for checking property names and improve tests slightly See merge request GNOME/glib!2740
This commit is contained in:
commit
edd497fc99
@ -699,30 +699,6 @@ is_canonical (const gchar *key)
|
|||||||
return (strchr (key, '_') == NULL);
|
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
|
static void
|
||||||
g_binding_set_property (GObject *gobject,
|
g_binding_set_property (GObject *gobject,
|
||||||
guint prop_id,
|
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 (G_IS_OBJECT (source), NULL);
|
||||||
g_return_val_if_fail (source_property != NULL, 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 (G_IS_OBJECT (target), NULL);
|
||||||
g_return_val_if_fail (target_property != NULL, 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)
|
if (source == target && g_strcmp0 (source_property, target_property) == 0)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,30 @@
|
|||||||
#include <gstdio.h>
|
#include <gstdio.h>
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
#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 {
|
typedef struct {
|
||||||
GTypeInterface g_iface;
|
GTypeInterface g_iface;
|
||||||
} FooInterface;
|
} FooInterface;
|
||||||
@ -353,7 +377,6 @@ binding_default (void)
|
|||||||
{
|
{
|
||||||
BindingSource *source = g_object_new (binding_source_get_type (), NULL);
|
BindingSource *source = g_object_new (binding_source_get_type (), NULL);
|
||||||
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
|
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
|
||||||
GObject *tmp;
|
|
||||||
GBinding *binding;
|
GBinding *binding;
|
||||||
|
|
||||||
binding = g_object_bind_property (source, "foo",
|
binding = g_object_bind_property (source, "foo",
|
||||||
@ -361,14 +384,10 @@ binding_default (void)
|
|||||||
G_BINDING_DEFAULT);
|
G_BINDING_DEFAULT);
|
||||||
|
|
||||||
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
|
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
|
||||||
tmp = g_binding_dup_source (binding);
|
|
||||||
g_assert_nonnull (tmp);
|
assert_cmpsource (binding, ==, source);
|
||||||
g_assert_true ((BindingSource *) tmp == source);
|
assert_cmptarget (binding, ==, target);
|
||||||
g_object_unref (tmp);
|
|
||||||
tmp = g_binding_dup_target (binding);
|
|
||||||
g_assert_nonnull (tmp);
|
|
||||||
g_assert_true ((BindingTarget *) tmp == target);
|
|
||||||
g_object_unref (tmp);
|
|
||||||
g_assert_cmpstr (g_binding_get_source_property (binding), ==, "foo");
|
g_assert_cmpstr (g_binding_get_source_property (binding), ==, "foo");
|
||||||
g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar");
|
g_assert_cmpstr (g_binding_get_target_property (binding), ==, "bar");
|
||||||
g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);
|
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);
|
BindingSource *source = g_object_new (binding_source_get_type (), NULL);
|
||||||
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
|
BindingTarget *target = g_object_new (binding_target_get_type (), NULL);
|
||||||
GBinding *binding;
|
GBinding *binding;
|
||||||
GObject *tmp;
|
|
||||||
|
|
||||||
g_test_summary ("Test that bindings set up with non-canonical property names work");
|
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_BINDING_DEFAULT);
|
||||||
|
|
||||||
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
|
g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding);
|
||||||
tmp = g_binding_dup_source (binding);
|
|
||||||
g_assert_nonnull (tmp);
|
assert_cmpsource (binding, ==, source);
|
||||||
g_assert_true ((BindingSource *) tmp == source);
|
assert_cmptarget (binding, ==, target);
|
||||||
g_object_unref (tmp);
|
|
||||||
tmp = g_binding_dup_target (binding);
|
|
||||||
g_assert_nonnull (tmp);
|
|
||||||
g_assert_true ((BindingTarget *) tmp == target);
|
|
||||||
g_object_unref (tmp);
|
|
||||||
g_assert_cmpstr (g_binding_get_source_property (binding), ==, "double-value");
|
g_assert_cmpstr (g_binding_get_source_property (binding), ==, "double-value");
|
||||||
g_assert_cmpstr (g_binding_get_target_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);
|
g_assert_cmpint (g_binding_get_flags (binding), ==, G_BINDING_DEFAULT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user