gobject-introspection r820 - in trunk: . girepository tests/invoke



Author: jobi
Date: Mon Oct 27 15:03:18 2008
New Revision: 820
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=820&view=rev

Log:

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.



Modified:
   trunk/ChangeLog
   trunk/girepository/ginvoke.c
   trunk/tests/invoke/invoke.c
   trunk/tests/invoke/testfns-1.0.gir
   trunk/tests/invoke/testfns.c

Modified: trunk/girepository/ginvoke.c
==============================================================================
--- trunk/girepository/ginvoke.c	(original)
+++ trunk/girepository/ginvoke.c	Mon Oct 27 15:03:18 2008
@@ -254,7 +254,7 @@
 	      goto out;
 	    }
 
-	  args[i+offset] = (gpointer)&out_args[out_pos+offset];
+	  args[i+offset] = (gpointer)&out_args[out_pos];
 	  out_pos++;	  
 	  break;
 	case GI_DIRECTION_INOUT:

Modified: trunk/tests/invoke/invoke.c
==============================================================================
--- trunk/tests/invoke/invoke.c	(original)
+++ trunk/tests/invoke/invoke.c	Mon Oct 27 15:03:18 2008
@@ -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 @@
   GIRepository *rep;
   GIBaseInfo *info;
   GIFunctionInfo *function;
+  GIStructInfo *record;
   GArgument in_args[3];
   GArgument out_args[3];
   GArgument retval;
@@ -20,6 +27,7 @@
   gint len;
   GError *error = NULL;
   const gchar *name;
+  TestStruct *s;
   
   g_type_init ();
 
@@ -185,6 +193,59 @@
   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

Modified: trunk/tests/invoke/testfns-1.0.gir
==============================================================================
--- trunk/tests/invoke/testfns-1.0.gir	(original)
+++ trunk/tests/invoke/testfns-1.0.gir	Mon Oct 27 15:03:18 2008
@@ -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"/>

Modified: trunk/tests/invoke/testfns.c
==============================================================================
--- trunk/tests/invoke/testfns.c	(original)
+++ trunk/tests/invoke/testfns.c	Mon Oct 27 15:03:18 2008
@@ -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 @@
     }
   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;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]