summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2014-05-06 18:53:21 +0200
committerGiovanni Campagna <gcampagna@src.gnome.org>2014-07-03 10:31:17 +0200
commita4c9d09d7a89d3c80b4465a5c2ae0efa24158b24 (patch)
treef56b061a761dd45ed64d9015c8a7cf00b46be710 /tests
parentb2bf49eae922bffddc952fcc22e4acbd7d40c5f3 (diff)
downloadgobject-introspection-a4c9d09d7a89d3c80b4465a5c2ae0efa24158b24.tar.gz
Parse and expose ownership transfer for instance parameters
Knowing the ownership transfer for instance parameters is necessary for correct memory management of functions which "eat" their instance argument, such as g_dbus_method_invocation_return_*. Parse this information from the gir file and store in the typelib, and then provide new API on GICallableInfo to retrieve this. https://bugzilla.gnome.org/show_bug.cgi?id=729662
Diffstat (limited to 'tests')
-rw-r--r--tests/repository/gitypelibtest.c29
-rw-r--r--tests/scanner/Regress-1.0-C-expected/Regress.TestObj.instance_method_full.page38
-rw-r--r--tests/scanner/Regress-1.0-Gjs-expected/Regress.TestObj.instance_method_full.page26
-rw-r--r--tests/scanner/Regress-1.0-Python-expected/Regress.TestObj.instance_method_full.page37
-rw-r--r--tests/scanner/Regress-1.0-expected.gir11
-rw-r--r--tests/scanner/Regress-1.0-sections-expected.txt1
-rw-r--r--tests/scanner/regress.c11
-rw-r--r--tests/scanner/regress.h1
8 files changed, 154 insertions, 0 deletions
diff --git a/tests/repository/gitypelibtest.c b/tests/repository/gitypelibtest.c
index 565c95c3..7b9cb357 100644
--- a/tests/repository/gitypelibtest.c
+++ b/tests/repository/gitypelibtest.c
@@ -276,6 +276,34 @@ test_signal_array_len (GIRepository * repo)
g_base_info_unref (testobj_info);
}
+static void
+test_instance_transfer_ownership (GIRepository * repo)
+{
+ GIObjectInfo *testobj_info;
+ GIFunctionInfo *func_info;
+ GITransfer transfer;
+
+ g_assert (g_irepository_require (repo, "Regress", NULL, 0, NULL));
+ testobj_info = g_irepository_find_by_name (repo, "Regress", "TestObj");
+ g_assert (testobj_info != NULL);
+
+ func_info = g_object_info_find_method (testobj_info, "instance_method");
+ g_assert (func_info != NULL);
+ transfer = g_callable_info_get_instance_ownership_transfer ((GICallableInfo*) func_info);
+ g_assert_cmpint (GI_TRANSFER_NOTHING, ==, transfer);
+
+ g_base_info_unref (func_info);
+
+ func_info = g_object_info_find_method (testobj_info, "instance_method_full");
+ g_assert (func_info != NULL);
+ transfer = g_callable_info_get_instance_ownership_transfer ((GICallableInfo*) func_info);
+ g_assert_cmpint (GI_TRANSFER_EVERYTHING, ==, transfer);
+
+ g_base_info_unref (func_info);
+
+ g_base_info_unref (testobj_info);
+}
+
int
main (int argc, char **argv)
{
@@ -292,6 +320,7 @@ main (int argc, char **argv)
test_hash_with_cairo_typelib (repo);
test_char_types (repo);
test_signal_array_len (repo);
+ test_instance_transfer_ownership (repo);
exit (0);
}
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.TestObj.instance_method_full.page b/tests/scanner/Regress-1.0-C-expected/Regress.TestObj.instance_method_full.page
new file mode 100644
index 00000000..2222becb
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.TestObj.instance_method_full.page
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<page id="Regress.TestObj.instance_method_full"
+ type="topic"
+ style="method"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="Regress.TestObj" group="method" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>void</api:type>
+ </api:returns>
+ <api:name>regress_test_obj_instance_method_full</api:name>
+ <api:arg>
+ <api:type>RegressTestObj*</api:type>
+ <api:name>obj</api:name>
+ </api:arg>
+ </api:function>
+ </info>
+ <title>regress_test_obj_instance_method_full</title>
+ <synopsis><code mime="text/x-csrc">
+void regress_test_obj_instance_method_full (RegressTestObj* obj);
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>obj</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestObj.instance_method_full.page b/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestObj.instance_method_full.page
new file mode 100644
index 00000000..5b7e1c93
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestObj.instance_method_full.page
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<page id="Regress.TestObj.instance_method_full"
+ type="topic"
+ style="method"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="Regress.TestObj" group="method" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>void</api:type>
+ </api:returns>
+ <api:name>regress_test_obj_instance_method_full</api:name>
+ </api:function>
+ </info>
+ <title>Regress.TestObj.prototype.instance_method_full</title>
+ <synopsis><code mime="text/x-gjs">
+function instance_method_full(): void {
+ // Gjs wrapper for regress_test_obj_instance_method_full()
+}
+ </code></synopsis>
+
+
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.TestObj.instance_method_full.page b/tests/scanner/Regress-1.0-Python-expected/Regress.TestObj.instance_method_full.page
new file mode 100644
index 00000000..2b5c1dcf
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.TestObj.instance_method_full.page
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<page id="Regress.TestObj.instance_method_full"
+ type="topic"
+ style="method"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="Regress.TestObj" group="method" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>none</api:type>
+ </api:returns>
+ <api:name>regress_test_obj_instance_method_full</api:name>
+ <api:arg>
+ <api:type>Regress.TestObj</api:type>
+ <api:name>self</api:name>
+ </api:arg>
+ </api:function>
+ </info>
+ <title>Regress.TestObj.instance_method_full</title>
+ <synopsis><code mime="text/x-python">
+@accepts(Regress.TestObj)
+@returns(none)
+def instance_method_full(self):
+ # Python wrapper for regress_test_obj_instance_method_full()
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>self</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 1c9c300f..89ecaa45 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -3057,6 +3057,17 @@ case.</doc>
</parameter>
</parameters>
</method>
+ <method name="instance_method_full"
+ c:identifier="regress_test_obj_instance_method_full">
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <instance-parameter name="obj" transfer-ownership="full">
+ <type name="TestObj" c:type="RegressTestObj*"/>
+ </instance-parameter>
+ </parameters>
+ </method>
<method name="set_bare" c:identifier="regress_test_obj_set_bare">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
diff --git a/tests/scanner/Regress-1.0-sections-expected.txt b/tests/scanner/Regress-1.0-sections-expected.txt
index c9ff60a3..187aa16d 100644
--- a/tests/scanner/Regress-1.0-sections-expected.txt
+++ b/tests/scanner/Regress-1.0-sections-expected.txt
@@ -334,6 +334,7 @@ regress_test_obj_emit_sig_with_uint64
regress_forced_method
regress_test_obj_instance_method
regress_test_obj_instance_method_callback
+regress_test_obj_instance_method_full
regress_test_obj_set_bare
regress_test_obj_skip_inout_param
regress_test_obj_skip_out_param
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 1bad36e3..b42e0cd0 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -2679,6 +2679,17 @@ regress_test_obj_instance_method (RegressTestObj *obj)
return -1;
}
+/**
+ * regress_test_obj_instance_method_full:
+ * @obj: (transfer full):
+ *
+ */
+void
+regress_test_obj_instance_method_full (RegressTestObj *obj)
+{
+ g_object_unref (obj);
+}
+
double
regress_test_obj_static_method (int x)
{
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index e2e645ba..667f1298 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -527,6 +527,7 @@ void regress_test_obj_emit_sig_with_foreign_struct (RegressTestObj *obj);
void regress_test_obj_emit_sig_with_int64 (RegressTestObj *obj);
void regress_test_obj_emit_sig_with_uint64 (RegressTestObj *obj);
int regress_test_obj_instance_method (RegressTestObj *obj);
+void regress_test_obj_instance_method_full (RegressTestObj *obj);
double regress_test_obj_static_method (int x);
void regress_forced_method (RegressTestObj *obj);