[gobject-introspection] Add regress test methods for callbacks taking GError and GHashTable



commit df4a6ff72eb51de034c8e70af94c1a709d1e8dc7
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Mon Jan 23 08:53:44 2012 +0100

    Add regress test methods for callbacks taking GError and GHashTable
    
    This covers both "transfer none" and "transfer full" cases.
    
    This is a requisite for writing a pygobject test case for
    https://bugzilla.gnome.org/show_bug.cgi?id=666270

 tests/scanner/Regress-1.0-expected.gir |   79 ++++++++++++++++++++++++++++++++
 tests/scanner/regress.c                |   42 +++++++++++++++++
 tests/scanner/regress.h                |   14 ++++++
 3 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 7d01ef4..ebdacf5 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -169,6 +169,43 @@ use it should be.</doc>
         </parameter>
       </parameters>
     </callback>
+    <callback name="TestCallbackGError" c:type="RegressTestCallbackGError">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="error" transfer-ownership="none">
+          <type name="GLib.Error" c:type="GError*"/>
+        </parameter>
+      </parameters>
+    </callback>
+    <callback name="TestCallbackHashtable"
+              c:type="RegressTestCallbackHashtable">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="data" transfer-ownership="none">
+          <doc xml:whitespace="preserve">a hash table; will be modified</doc>
+          <type name="GLib.HashTable" c:type="GHashTable*">
+            <type name="utf8"/>
+            <type name="gint"/>
+          </type>
+        </parameter>
+      </parameters>
+    </callback>
+    <callback name="TestCallbackOwnedGError"
+              c:type="RegressTestCallbackOwnedGError">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="error" transfer-ownership="full">
+          <doc xml:whitespace="preserve">GError instance; must be freed by the callback</doc>
+          <type name="GLib.Error" c:type="GError*"/>
+        </parameter>
+      </parameters>
+    </callback>
     <callback name="TestCallbackUserData" c:type="RegressTestCallbackUserData">
       <return-value transfer-ownership="none">
         <type name="gint" c:type="int"/>
@@ -2036,6 +2073,17 @@ call and can be released on return.</doc>
         </array>
       </return-value>
     </function>
+    <function name="test_gerror_callback"
+              c:identifier="regress_test_gerror_callback">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="callback" transfer-ownership="none" scope="call">
+          <type name="TestCallbackGError" c:type="RegressTestCallbackGError"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_ghash_container_return"
               c:identifier="regress_test_ghash_container_return">
       <return-value transfer-ownership="container">
@@ -2385,6 +2433,25 @@ element-type annotation.</doc>
         <type name="GLib.Variant" c:type="GVariant*"/>
       </return-value>
     </function>
+    <function name="test_hash_table_callback"
+              c:identifier="regress_test_hash_table_callback">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="data" transfer-ownership="none">
+          <doc xml:whitespace="preserve">GHashTable that gets passed to callback</doc>
+          <type name="GLib.HashTable" c:type="GHashTable*">
+            <type name="utf8"/>
+            <type name="gint"/>
+          </type>
+        </parameter>
+        <parameter name="callback" transfer-ownership="none" scope="call">
+          <type name="TestCallbackHashtable"
+                c:type="RegressTestCallbackHashtable"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_int" c:identifier="regress_test_int">
       <return-value transfer-ownership="none">
         <type name="gint" c:type="gint"/>
@@ -2563,6 +2630,18 @@ What we're testing here is that the scanner ignores the @a nested inside XML.</d
         </parameter>
       </parameters>
     </function>
+    <function name="test_owned_gerror_callback"
+              c:identifier="regress_test_owned_gerror_callback">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="callback" transfer-ownership="none" scope="call">
+          <type name="TestCallbackOwnedGError"
+                c:type="RegressTestCallbackOwnedGError"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_short" c:identifier="regress_test_short">
       <return-value transfer-ownership="none">
         <type name="gshort" c:type="gshort"/>
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 4b35604..0f00ec8 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -3026,6 +3026,48 @@ regress_test_obj_new_callback (RegressTestCallbackUserData callback, gpointer us
   return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
 }
 
+/**
+ * regress_test_hash_table_callback:
+ * @data: (element-type utf8 gint): GHashTable that gets passed to callback
+ * @callback: (scope call):
+ **/
+void
+regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback)
+{
+  callback (data);
+}
+
+/**
+ * regress_test_gerror_callback:
+ * @callback: (scope call):
+ **/
+void
+regress_test_gerror_callback (RegressTestCallbackGError callback)
+{
+  GError *error;
+
+  error = g_error_new_literal (G_IO_ERROR,
+                               G_IO_ERROR_NOT_SUPPORTED,
+                               "regression test error");
+  callback (error);
+  g_error_free (error);
+}
+
+/**
+ * regress_test_owned_gerror_callback:
+ * @callback: (scope call):
+ **/
+void
+regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback)
+{
+  GError *error;
+
+  error = g_error_new_literal (G_IO_ERROR,
+                               G_IO_ERROR_PERMISSION_DENIED,
+                               "regression test owned error");
+  callback (error);
+}
+
 /* interface */
 
 static void
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 91d1471..8fe44e2 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -521,6 +521,17 @@ typedef void (*RegressTestSimpleCallback) (void);
 typedef int (*RegressTestCallback) (void);
 typedef int (*RegressTestCallbackUserData) (gpointer user_data);
 /**
+ * RegressTestCallbackHashtable:
+ * @data: (element-type utf8 gint): a hash table; will be modified
+ */
+typedef void (*RegressTestCallbackHashtable) (GHashTable *data);
+typedef void (*RegressTestCallbackGError) (const GError *error);
+/**
+ * RegressTestCallbackOwnedGError:
+ * @error: (transfer full): GError instance; must be freed by the callback
+ */
+typedef void (*RegressTestCallbackOwnedGError) (GError *error);
+/**
  * RegressTestCallbackFull:
  * @foo: the investment rate
  * @bar: how much money
@@ -548,6 +559,9 @@ void regress_test_obj_static_method_callback (RegressTestCallback callback);
 RegressTestObj *regress_test_obj_new_callback (RegressTestCallbackUserData callback,
                                 gpointer user_data,
                                 GDestroyNotify notify);
+void regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback);
+void regress_test_gerror_callback (RegressTestCallbackGError callback);
+void regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback);
 
 typedef struct _RegressTestInterface RegressTestInterface;
 



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