summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2012-06-01 02:54:46 -0400
committerMartin Pitt <martinpitt@gnome.org>2012-06-01 15:46:37 +0200
commitbb83f34bebdd3581a01f521f8e6fda5a724ae0de (patch)
tree75f5cb68b3d6fda8953896f7366c453c0308ffd4
parent932bf2a700368e46b30b58ec9b6beb3ff09a081c (diff)
downloadgobject-introspection-bb83f34bebdd3581a01f521f8e6fda5a724ae0de.tar.gz
tests: Add a refcounting boxed
https://bugzilla.gnome.org/show_bug.cgi?id=677249
-rw-r--r--tests/scanner/Regress-1.0-expected.gir17
-rw-r--r--tests/scanner/regress.c32
-rw-r--r--tests/scanner/regress.h11
3 files changed, 60 insertions, 0 deletions
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index b1fd124e..e774948b 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -171,6 +171,23 @@ use it should be.</doc>
</return-value>
</method>
</record>
+ <record name="TestBoxedC"
+ c:type="RegressTestBoxedC"
+ glib:type-name="RegressTestBoxedC"
+ glib:get-type="regress_test_boxed_c_get_type"
+ c:symbol-prefix="test_boxed_c">
+ <field name="refcount" writable="1">
+ <type name="guint" c:type="guint"/>
+ </field>
+ <field name="another_thing" writable="1">
+ <type name="guint" c:type="guint"/>
+ </field>
+ <constructor name="new" c:identifier="regress_test_boxed_c_new">
+ <return-value transfer-ownership="full">
+ <type name="TestBoxedC" c:type="RegressTestBoxedC*"/>
+ </return-value>
+ </constructor>
+ </record>
<record name="TestBoxedPrivate"
c:type="RegressTestBoxedPrivate"
disguised="1">
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index ca8d6ef8..13b18887 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1825,6 +1825,38 @@ G_DEFINE_BOXED_TYPE(RegressTestBoxedB,
regress_test_boxed_b_copy,
regress_test_boxed_b_free);
+RegressTestBoxedC *
+regress_test_boxed_c_new (void)
+{
+ RegressTestBoxedC *boxed;
+
+ boxed = g_slice_new (RegressTestBoxedC);
+ boxed->refcount = 1;
+ boxed->another_thing = 42; /* what else */
+
+ return boxed;
+}
+
+static RegressTestBoxedC *
+regress_test_boxed_c_ref (RegressTestBoxedC *boxed)
+{
+ g_atomic_int_inc (&boxed->refcount);
+ return boxed;
+}
+
+static void
+regress_test_boxed_c_unref (RegressTestBoxedC *boxed)
+{
+ if (g_atomic_int_dec_and_test (&boxed->refcount)) {
+ g_slice_free (RegressTestBoxedC, boxed);
+ }
+}
+
+G_DEFINE_BOXED_TYPE(RegressTestBoxedC,
+ regress_test_boxed_c,
+ regress_test_boxed_c_ref,
+ regress_test_boxed_c_unref);
+
G_DEFINE_TYPE(RegressTestObj, regress_test_obj, G_TYPE_OBJECT);
enum
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index eeab81be..4d47430f 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -328,6 +328,17 @@ GType regress_test_boxed_b_get_type (void);
RegressTestBoxedB *regress_test_boxed_b_new (gint8 some_int8, glong some_long);
RegressTestBoxedB *regress_test_boxed_b_copy (RegressTestBoxedB *boxed);
+typedef struct _RegressTestBoxedC RegressTestBoxedC;
+
+struct _RegressTestBoxedC
+{
+ guint refcount;
+ guint another_thing;
+};
+
+GType regress_test_boxed_c_get_type (void);
+RegressTestBoxedC *regress_test_boxed_c_new (void);
+
/* gobject */
#define REGRESS_TEST_TYPE_OBJ (regress_test_obj_get_type ())
#define REGRESS_TEST_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), REGRESS_TEST_TYPE_OBJ, RegressTestObj))