[glib/fix-freeze-count-underflow: 1/2] Add a testcase
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/fix-freeze-count-underflow: 1/2] Add a testcase
- Date: Thu, 9 Jun 2022 15:35:51 +0000 (UTC)
commit 94c557ac86712a4dbbd38b4ba2c943c868c917ce
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jun 9 11:34:39 2022 -0400
Add a testcase
Beef up the singleton testcase to reproduce a
freeze count underflow when setting properties
at construction time, with a custom constructor.
See: #2666
gobject/tests/singleton.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
---
diff --git a/gobject/tests/singleton.c b/gobject/tests/singleton.c
index db024f18c4..f978396528 100644
--- a/gobject/tests/singleton.c
+++ b/gobject/tests/singleton.c
@@ -20,6 +20,7 @@
/* --- MySingleton class --- */
typedef struct {
GObject parent_instance;
+ int myint;
} MySingleton;
typedef struct {
GObjectClass parent_class;
@@ -61,10 +62,43 @@ my_singleton_init (MySingleton *self)
the_one_and_only = self;
}
+static void
+set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MySingleton *sobj = (MySingleton *) gobject;
+
+ g_assert (prop_id == 1);
+
+ sobj->myint = g_value_get_int (value);
+}
+
+static void
+get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MySingleton *sobj = (MySingleton *) gobject;
+
+ g_assert (prop_id == 1);
+
+ g_value_set_int (value, sobj->myint);
+}
+
static void
my_singleton_class_init (MySingletonClass *klass)
{
G_OBJECT_CLASS (klass)->constructor = my_singleton_constructor;
+ G_OBJECT_CLASS (klass)->set_property = set_property;
+ G_OBJECT_CLASS (klass)->get_property = get_property;
+
+ g_object_class_install_property (G_OBJECT_CLASS (klass), 1,
+ g_param_spec_int ("foo", NULL, NULL,
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
}
/* --- test program --- */
@@ -75,11 +109,11 @@ main (int argc,
MySingleton *singleton, *obj;
/* create the singleton */
- singleton = g_object_new (MY_TYPE_SINGLETON, NULL);
+ singleton = g_object_new (MY_TYPE_SINGLETON, "foo", 1, NULL);
g_assert_nonnull (singleton);
/* assert _singleton_ creation */
- obj = g_object_new (MY_TYPE_SINGLETON, NULL);
+ obj = g_object_new (MY_TYPE_SINGLETON, "foo", 2, NULL);
g_assert_true (singleton == obj);
g_object_unref (obj);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]