From 2912b22236bf25a3236a0465b7e790d8dbdd6dbd Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Thu, 26 Feb 2009 23:12:19 +0000 Subject: Additions to "Everything" test namespace Add a signal and a "bare" member (i.e. a member without getter/setter) to TestObj. Signed-off-by: Andreas Rottmann --- diff --git a/tests/everything/everything.c b/tests/everything/everything.c index 7d8a020..75842bf 100644 --- a/tests/everything/everything.c +++ b/tests/everything/everything.c @@ -726,14 +726,105 @@ test_boxed_get_type (void) G_DEFINE_TYPE(TestObj, test_obj, G_TYPE_OBJECT); +enum +{ + PROP_TEST_OBJ_BARE = 1 +}; + +static void +test_obj_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + TestObj *self = TEST_OBJECT (object); + + switch (property_id) + { + case PROP_TEST_OBJ_BARE: + test_obj_set_bare (self, g_value_get_object (value)); + break; + + default: + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +test_obj_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + TestObj *self = TEST_OBJECT (object); + + switch (property_id) + { + case PROP_TEST_OBJ_BARE: + g_value_set_object (value, self->bare); + break; + + default: + /* We don't have any other property... */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +test_obj_dispose (GObject *gobject) +{ + TestObj *self = TEST_OBJECT (gobject); + + if (self->bare) + { + g_object_unref (self->bare); + + self->bare = NULL; + } + + /* Chain up to the parent class */ + G_OBJECT_CLASS (test_obj_parent_class)->dispose (gobject); +} + static void test_obj_class_init (TestObjClass *klass) { + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + klass->test_signal = + g_signal_newv ("test", + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + NULL /* closure */, + NULL /* accumulator */, + NULL /* accumulator data */, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE /* return_type */, + 0 /* n_params */, + NULL /* param_types */); + + gobject_class->set_property = test_obj_set_property; + gobject_class->get_property = test_obj_get_property; + gobject_class->dispose = test_obj_dispose; + + pspec = g_param_spec_object ("bare", + "Bare property", + "A contained object", + G_TYPE_OBJECT, + G_PARAM_READWRITE); + g_object_class_install_property (gobject_class, + PROP_TEST_OBJ_BARE, + pspec); } static void test_obj_init (TestObj *obj) { + obj->bare = NULL; } TestObj * @@ -742,6 +833,20 @@ test_obj_new_from_file (const char *x, GError **error) return g_object_new (TEST_TYPE_OBJ, NULL); } +/** + * test_obj_set_bare: + * @bare: (allow-none): + */ +void +test_obj_set_bare (TestObj *obj, GObject *bare) +{ + if (obj->bare) + g_object_unref (obj->bare); + obj->bare = bare; + if (obj->bare) + g_object_ref (obj->bare); +} + double test_obj_static_method (int x) { diff --git a/tests/everything/everything.h b/tests/everything/everything.h index 6347c63..448c74d 100644 --- a/tests/everything/everything.h +++ b/tests/everything/everything.h @@ -107,6 +107,7 @@ struct _TestStructA gint8 some_int8; gdouble some_double; TestEnum some_enum; + GObject *some_obj; }; void test_struct_a_clone (TestStructA *a, @@ -174,18 +175,28 @@ gboolean test_boxed_equals (TestBoxed *boxed, typedef struct _TestObj TestObj; typedef struct _TestObjClass TestObjClass; + +/** + * TestObj: + * @bare: (allow-none): + */ struct _TestObj { GObject parent_instance; + + GObject *bare; }; struct _TestObjClass { GObjectClass parent_class; + + guint test_signal; }; GType test_obj_get_type (void); TestObj* test_obj_new_from_file (const char *x, GError **error); +void test_obj_set_bare (TestObj *obj, GObject *bare); double test_obj_static_method (int x); /* callback */ -- cgit v0.9.1