summaryrefslogtreecommitdiff
path: root/tests/invoke
diff options
context:
space:
mode:
authorJohan Bilien <jobi@via.ecp.fr>2008-10-27 15:03:18 +0000
committerJohan Bilien <jobi@src.gnome.org>2008-10-27 15:03:18 +0000
commit98da4ca45e09945440ee42112e6b808ea0c89bfc (patch)
tree7692559d990e14663460ccbb2e502f8d3f626cca /tests/invoke
parentfa1fa9c5e7a02f3efa8a623acec9bba2a119469b (diff)
downloadgobject-introspection-98da4ca45e09945440ee42112e6b808ea0c89bfc.tar.gz
Bug 558068 – when invoking a method, offset the in arguments by one, not
2008-10-27 Johan Bilien <jobi@via.ecp.fr> Bug 558068 – when invoking a method, offset the in arguments by one, not the out * tests/invoke/invoke.c, tests/invoke/testfns.c, tests/invoke/testfns-1.0.gir: Add testing of method and constructor. * girepository/ginvoke.c: do not offset the index of given out arguments by one for methods, "this" is provided as in argument only. svn path=/trunk/; revision=820
Diffstat (limited to 'tests/invoke')
-rw-r--r--tests/invoke/invoke.c61
-rw-r--r--tests/invoke/testfns-1.0.gir23
-rw-r--r--tests/invoke/testfns.c19
3 files changed, 103 insertions, 0 deletions
diff --git a/tests/invoke/invoke.c b/tests/invoke/invoke.c
index 27337e7f..a41a025f 100644
--- a/tests/invoke/invoke.c
+++ b/tests/invoke/invoke.c
@@ -4,6 +4,12 @@
#include <glib.h>
#include <girepository.h>
+typedef struct
+{
+ int foo;
+} TestStruct;
+
+
int
main (int argc, char *argv[])
{
@@ -12,6 +18,7 @@ main (int argc, char *argv[])
GIRepository *rep;
GIBaseInfo *info;
GIFunctionInfo *function;
+ GIStructInfo *record;
GArgument in_args[3];
GArgument out_args[3];
GArgument retval;
@@ -20,6 +27,7 @@ main (int argc, char *argv[])
gint len;
GError *error = NULL;
const gchar *name;
+ TestStruct *s;
g_type_init ();
@@ -185,6 +193,59 @@ main (int argc, char *argv[])
g_base_info_unref (info);
g_clear_error (&error);
+ g_print("Test 8\n");
+ info = g_irepository_find_by_name (rep, "test", "TestStruct");
+ g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_STRUCT);
+ record = (GIStructInfo *)info;
+ info = g_struct_info_find_method (record, "test8");
+ g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
+ function = (GIFunctionInfo *)info;
+ g_assert (g_function_info_get_flags (info) & GI_FUNCTION_IS_CONSTRUCTOR);
+
+ {
+ in_args[0].v_int = 42;
+ retval.v_pointer = NULL;
+
+ if (!g_function_info_invoke (function, in_args, 1, NULL, 0, &retval, &error))
+ g_print ("Invocation of %s failed: %s\n",
+ g_base_info_get_name (info),
+ error->message);
+
+ s = (TestStruct *)retval.v_pointer;
+
+ g_assert(s->foo == 42);
+
+ }
+
+ g_base_info_unref (info);
+ g_clear_error (&error);
+
+ g_print("Test 9\n");
+ info = g_struct_info_find_method (record, "test9");
+ g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
+ function = (GIFunctionInfo *)info;
+ g_assert (g_function_info_get_flags (info) & GI_FUNCTION_IS_METHOD);
+
+ {
+ TestStruct s = { 42 };
+ int out_i;
+
+ retval.v_pointer = NULL;
+ in_args[0].v_pointer = &s;
+ out_args[0].v_pointer = &out_i;
+ if (!g_function_info_invoke (function, in_args, 1, out_args, 1, &retval, &error))
+ g_print ("Invocation of %s failed: %s\n",
+ g_base_info_get_name (info),
+ error->message);
+
+ g_assert(out_i == 42);
+ }
+
+ g_base_info_unref (info);
+ g_base_info_unref (record);
+ g_clear_error (&error);
+
+
/* test error handling */
#if 0
diff --git a/tests/invoke/testfns-1.0.gir b/tests/invoke/testfns-1.0.gir
index 5218fa87..0398236e 100644
--- a/tests/invoke/testfns-1.0.gir
+++ b/tests/invoke/testfns-1.0.gir
@@ -88,6 +88,29 @@
</parameters>
</function>
+ <record name="TestStruct" c:type="TestStruct">
+ <constructor name="test8" c:identifier="test8">
+ <return-value transfer-ownership="full">
+ <type name="TestStruct" c:type="TestStruct*"/>
+ </return-value>
+ <parameters>
+ <parameter name="foo" direction="in" transfer-ownership="full">
+ <type name="int" c:type="int"/>
+ </parameter>
+ </parameters>
+ </constructor>
+ <method name="test9" c:identifier="test9">
+ <return-value transfer-ownership="full">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="out" direction="out" transfer-ownership="full">
+ <type name="int" c:type="int*"/>
+ </parameter>
+ </parameters>
+ </method>
+ </record>
+
<function name="broken" c:identifier="broken">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
diff --git a/tests/invoke/testfns.c b/tests/invoke/testfns.c
index 06aa3def..c5e47ce9 100644
--- a/tests/invoke/testfns.c
+++ b/tests/invoke/testfns.c
@@ -3,6 +3,10 @@
#include <glib.h>
#include <glib/gprintf.h>
+typedef struct {
+ int foo;
+} TestStruct;
+
gint test1 (gint in)
{
return in + 4;
@@ -45,3 +49,18 @@ char *test7 (GList *list)
}
return g_string_free (string, FALSE);
}
+
+/* constructor */
+TestStruct * test8 (int foo)
+{
+ TestStruct *ret;
+
+ ret = g_new(TestStruct, 1);
+ ret->foo = foo;
+ return ret;
+}
+
+void test9 (TestStruct *test_struct, int *out)
+{
+ *out = test_struct->foo;
+}