[gobject-introspection] Add some tests to Everything for testing callbacks as constructor args



commit ffc28a47400e06b39e05be4f7e4c8dccef4bd8ea
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Mon May 3 19:15:54 2010 +0200

    Add some tests to Everything for testing callbacks as constructor args

 gir/Everything-1.0-expected.gir |   48 +++++++++++++++++++++++++++++++++++++++
 gir/everything.c                |   47 ++++++++++++++++++++++++++++++++++++++
 gir/everything.h                |    6 +++++
 3 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/gir/Everything-1.0-expected.gir b/gir/Everything-1.0-expected.gir
index ff85439..24c9ff9 100644
--- a/gir/Everything-1.0-expected.gir
+++ b/gir/Everything-1.0-expected.gir
@@ -169,6 +169,26 @@ and/or use gtk-doc annotations.  -->
           </parameter>
         </parameters>
       </constructor>
+      <constructor name="new_callback" c:identifier="test_obj_new_callback">
+        <return-value transfer-ownership="full">
+          <type name="TestObj" c:type="TestObj*"/>
+        </return-value>
+        <parameters>
+          <parameter name="callback"
+                     transfer-ownership="none"
+                     scope="notified"
+                     closure="1"
+                     destroy="2">
+            <type name="TestCallbackUserData" c:type="TestCallbackUserData"/>
+          </parameter>
+          <parameter name="user_data" transfer-ownership="none">
+            <type name="any" c:type="gpointer"/>
+          </parameter>
+          <parameter name="notify" transfer-ownership="none" scope="call">
+            <type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
+          </parameter>
+        </parameters>
+      </constructor>
       <function name="static_method" c:identifier="test_obj_static_method">
         <return-value transfer-ownership="none">
           <type name="double" c:type="double"/>
@@ -179,6 +199,20 @@ and/or use gtk-doc annotations.  -->
           </parameter>
         </parameters>
       </function>
+      <function name="static_method_callback"
+                c:identifier="test_obj_static_method_callback">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="callback"
+                     transfer-ownership="none"
+                     allow-none="1"
+                     scope="call">
+            <type name="TestCallback" c:type="TestCallback"/>
+          </parameter>
+        </parameters>
+      </function>
       <virtual-method name="matrix" invoker="do_matrix">
         <return-value transfer-ownership="none">
           <type name="int" c:type="int"/>
@@ -272,6 +306,20 @@ case.">
           </parameter>
         </parameters>
       </method>
+      <method name="instance_method_callback"
+              c:identifier="test_obj_instance_method_callback">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="callback"
+                     transfer-ownership="none"
+                     allow-none="1"
+                     scope="call">
+            <type name="TestCallback" c:type="TestCallback"/>
+          </parameter>
+        </parameters>
+      </method>
       <property name="bare" writable="1">
         <type name="GObject.Object" c:type="GObject"/>
       </property>
diff --git a/gir/everything.c b/gir/everything.c
index b4cfc75..169d05c 100644
--- a/gir/everything.c
+++ b/gir/everything.c
@@ -2004,6 +2004,53 @@ test_async_ready_callback (GAsyncReadyCallback callback)
   g_simple_async_result_complete_in_idle (result);
 }
 
+/**
+ * test_obj_instance_method_callback:
+ * @callback: (scope call) (allow-none):
+ *
+ **/
+void
+test_obj_instance_method_callback (TestObj *obj, TestCallback callback)
+{
+    if (callback != NULL)
+        callback();
+}
+
+/**
+ * test_obj_static_method_callback:
+ * @callback: (scope call) (allow-none):
+ *
+ **/
+void
+test_obj_static_method_callback (TestCallback callback)
+{
+    if (callback != NULL)
+        callback();
+}
+
+/**
+ * test_obj_new_callback:
+ * @callback: (scope notified):
+ *
+ **/
+TestObj *
+test_obj_new_callback (TestCallbackUserData callback, gpointer user_data,
+                       GDestroyNotify notify)
+{
+  CallbackInfo *info;
+
+  callback(user_data);
+
+  info = g_slice_new(CallbackInfo);
+  info->callback = callback;
+  info->notify = notify;
+  info->user_data = user_data;
+
+  notified_callbacks = g_slist_prepend(notified_callbacks, info);
+
+  return g_object_new (TEST_TYPE_OBJ, NULL);
+}
+
 /* interface */
 
 static void
diff --git a/gir/everything.h b/gir/everything.h
index 63b2ec1..8afe8fa 100644
--- a/gir/everything.h
+++ b/gir/everything.h
@@ -352,6 +352,12 @@ int test_callback_infinite (TestCallbackUserData callback,
 
 void test_async_ready_callback (GAsyncReadyCallback callback);
 
+void test_obj_instance_method_callback (TestObj *obj, TestCallback callback);
+void test_obj_static_method_callback (TestCallback callback);
+TestObj *test_obj_new_callback (TestCallbackUserData callback,
+                                gpointer user_data,
+                                GDestroyNotify notify);
+
 /* interface */
 #define TEST_TYPE_INTERFACE              (test_interface_get_type ())
 #define TEST_INTERFACE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), TEST_TYPE_INTERFACE, TestInterface))



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