mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-19 04:01:57 +02:00
test: add test for explicit-notify properties
https://bugzilla.gnome.org/show_bug.cgi?id=731200
This commit is contained in:
parent
bbdb2345fc
commit
0208861a13
@ -7,13 +7,14 @@ typedef struct _TestObject {
|
|||||||
gint foo;
|
gint foo;
|
||||||
gboolean bar;
|
gboolean bar;
|
||||||
gchar *baz;
|
gchar *baz;
|
||||||
|
gchar *quux;
|
||||||
} TestObject;
|
} TestObject;
|
||||||
|
|
||||||
typedef struct _TestObjectClass {
|
typedef struct _TestObjectClass {
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
} TestObjectClass;
|
} TestObjectClass;
|
||||||
|
|
||||||
enum { PROP_0, PROP_FOO, PROP_BAR, PROP_BAZ, N_PROPERTIES };
|
enum { PROP_0, PROP_FOO, PROP_BAR, PROP_BAZ, PROP_QUUX, N_PROPERTIES };
|
||||||
|
|
||||||
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
|
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
|
||||||
|
|
||||||
@ -62,6 +63,20 @@ test_object_set_baz (TestObject *obj,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_object_set_quux (TestObject *obj,
|
||||||
|
const gchar *quux)
|
||||||
|
{
|
||||||
|
if (g_strcmp0 (obj->quux, quux) != 0)
|
||||||
|
{
|
||||||
|
g_free (obj->quux);
|
||||||
|
obj->quux = g_strdup (quux);
|
||||||
|
|
||||||
|
g_assert (properties[PROP_QUUX] != NULL);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (obj), properties[PROP_QUUX]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_object_finalize (GObject *gobject)
|
test_object_finalize (GObject *gobject)
|
||||||
{
|
{
|
||||||
@ -103,6 +118,10 @@ test_object_set_property (GObject *gobject,
|
|||||||
test_object_set_baz (tobj, g_value_get_string (value));
|
test_object_set_baz (tobj, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_QUUX:
|
||||||
|
test_object_set_quux (tobj, g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
@ -134,6 +153,10 @@ test_object_get_property (GObject *gobject,
|
|||||||
g_value_set_string (value, tobj->baz);
|
g_value_set_string (value, tobj->baz);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_QUUX:
|
||||||
|
g_value_set_string (value, tobj->quux);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
@ -154,6 +177,9 @@ test_object_class_init (TestObjectClass *klass)
|
|||||||
properties[PROP_BAZ] = g_param_spec_string ("baz", "Baz", "Baz",
|
properties[PROP_BAZ] = g_param_spec_string ("baz", "Baz", "Baz",
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE);
|
G_PARAM_READWRITE);
|
||||||
|
properties[PROP_QUUX] = g_param_spec_string ("quux", "quux", "quux",
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
gobject_class->set_property = test_object_set_property;
|
gobject_class->set_property = test_object_set_property;
|
||||||
gobject_class->get_property = test_object_get_property;
|
gobject_class->get_property = test_object_get_property;
|
||||||
@ -168,6 +194,7 @@ test_object_init (TestObject *self)
|
|||||||
self->foo = 42;
|
self->foo = 42;
|
||||||
self->bar = TRUE;
|
self->bar = TRUE;
|
||||||
self->baz = g_strdup ("Hello");
|
self->baz = g_strdup ("Hello");
|
||||||
|
self->quux = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -187,6 +214,7 @@ properties_install (void)
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
GParamSpec *pspec;
|
GParamSpec *pspec;
|
||||||
|
gboolean fired;
|
||||||
} TestNotifyClosure;
|
} TestNotifyClosure;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -196,6 +224,7 @@ on_notify (GObject *gobject,
|
|||||||
{
|
{
|
||||||
g_assert (clos->pspec == pspec);
|
g_assert (clos->pspec == pspec);
|
||||||
g_assert_cmpstr (clos->name, ==, pspec->name);
|
g_assert_cmpstr (clos->name, ==, pspec->name);
|
||||||
|
clos->fired = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -205,12 +234,41 @@ properties_notify (void)
|
|||||||
TestNotifyClosure clos;
|
TestNotifyClosure clos;
|
||||||
|
|
||||||
g_assert (properties[PROP_FOO] != NULL);
|
g_assert (properties[PROP_FOO] != NULL);
|
||||||
|
g_assert (properties[PROP_QUUX] != NULL);
|
||||||
|
g_signal_connect (obj, "notify", G_CALLBACK (on_notify), &clos);
|
||||||
|
|
||||||
clos.name = "foo";
|
clos.name = "foo";
|
||||||
clos.pspec = properties[PROP_FOO];
|
clos.pspec = properties[PROP_FOO];
|
||||||
|
|
||||||
g_signal_connect (obj, "notify", G_CALLBACK (on_notify), &clos);
|
clos.fired = FALSE;
|
||||||
g_object_set (obj, "foo", 47, NULL);
|
g_object_set (obj, "foo", 47, NULL);
|
||||||
|
g_assert (clos.fired);
|
||||||
|
|
||||||
|
clos.name = "baz";
|
||||||
|
clos.pspec = properties[PROP_BAZ];
|
||||||
|
|
||||||
|
clos.fired = FALSE;
|
||||||
|
g_object_set (obj, "baz", "something new", NULL);
|
||||||
|
g_assert (clos.fired);
|
||||||
|
|
||||||
|
/* baz lacks explicit notify, so we will see this twice */
|
||||||
|
clos.fired = FALSE;
|
||||||
|
g_object_set (obj, "baz", "something new", NULL);
|
||||||
|
g_assert (clos.fired);
|
||||||
|
|
||||||
|
/* quux on the other hand, ... */
|
||||||
|
clos.name = "quux";
|
||||||
|
clos.pspec = properties[PROP_QUUX];
|
||||||
|
|
||||||
|
clos.fired = FALSE;
|
||||||
|
g_object_set (obj, "quux", "something new", NULL);
|
||||||
|
g_assert (clos.fired);
|
||||||
|
|
||||||
|
/* no change; no notify */
|
||||||
|
clos.fired = FALSE;
|
||||||
|
g_object_set (obj, "quux", "something new", NULL);
|
||||||
|
g_assert (!clos.fired);
|
||||||
|
|
||||||
|
|
||||||
g_object_unref (obj);
|
g_object_unref (obj);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user