[gobject-introspection] tests: Add regression test for callbacks with an inout array



commit e2b96aaa46ce73812fd41e46d996cd21da18f7be
Author: Garrett Regier <Garrett Regier riftio com>
Date:   Thu Aug 7 12:23:54 2014 -0400

    tests: Add regression test for callbacks with an inout array
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702508

 .../Regress.TestCallbackArrayInOut.page            |   33 ++++++++++++++++
 .../Regress.test_array_inout_callback.page         |   38 ++++++++++++++++++
 .../Regress.TestCallbackArrayInOut.page            |   29 ++++++++++++++
 .../Regress.test_array_inout_callback.page         |   40 +++++++++++++++++++
 .../Regress.TestCallbackArrayInOut.page            |   30 ++++++++++++++
 .../Regress.test_array_inout_callback.page         |   41 ++++++++++++++++++++
 tests/scanner/Regress-1.0-expected.gir             |   34 ++++++++++++++++
 tests/scanner/regress.c                            |   31 +++++++++++++++
 tests/scanner/regress.h                            |    7 +++
 9 files changed, 283 insertions(+), 0 deletions(-)
---
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.TestCallbackArrayInOut.page 
b/tests/scanner/Regress-1.0-C-expected/Regress.TestCallbackArrayInOut.page
new file mode 100644
index 0000000..0c8be37
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.TestCallbackArrayInOut.page
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<page id="Regress.TestCallbackArrayInOut"
+      type="topic"
+      style="callback"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="callback" type="guide"/>
+    </info>
+  <title>Regress.TestCallbackArrayInOut</title>
+  <synopsis><code mime="text/x-csrc">
+void TestCallbackArrayInOut (int** ints,
+                             int* length);
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>ints</code></title>
+
+</item>
+<item>
+<title><code>length</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.test_array_inout_callback.page 
b/tests/scanner/Regress-1.0-C-expected/Regress.test_array_inout_callback.page
new file mode 100644
index 0000000..9da453a
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.test_array_inout_callback.page
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_inout_callback"
+      type="topic"
+      style="function"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="function" type="guide"/>
+    <api:function>
+      <api:returns>
+        <api:type>int</api:type>
+      </api:returns>
+      <api:name>regress_test_array_inout_callback</api:name>
+      <api:arg>
+        <api:type>RegressTestCallbackArrayInOut</api:type>
+        <api:name>callback</api:name>
+      </api:arg>
+    </api:function>
+  </info>
+  <title>regress_test_array_inout_callback</title>
+  <synopsis><code mime="text/x-csrc">
+int regress_test_array_inout_callback (RegressTestCallbackArrayInOut callback);
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>callback</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestCallbackArrayInOut.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestCallbackArrayInOut.page
new file mode 100644
index 0000000..8b77cbb
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.TestCallbackArrayInOut.page
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<page id="Regress.TestCallbackArrayInOut"
+      type="topic"
+      style="callback"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="callback" type="guide"/>
+  </info>
+  <title>Regress.TestCallbackArrayInOut</title>
+  <synopsis><code mime="text/x-gjs">
+function onTestCallbackArrayInOut(ints: Array(Number(gint))): Array(Number(gint)) {
+}
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+<item>
+<title><code>Returns (out)</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_inout_callback.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_inout_callback.page
new file mode 100644
index 0000000..e02c96d
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_inout_callback.page
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_inout_callback"
+      type="topic"
+      style="function"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="function" type="guide"/>
+    <api:function>
+      <api:returns>
+        <api:type>Number(gint)</api:type>
+      </api:returns>
+      <api:name>regress_test_array_inout_callback</api:name>
+      <api:arg>
+        <api:type>Regress.TestCallbackArrayInOut</api:type>
+        <api:name>callback</api:name>
+      </api:arg>
+    </api:function>
+  </info>
+  <title>Regress.test_array_inout_callback</title>
+  <synopsis><code mime="text/x-gjs">
+function test_array_inout_callback(callback: <link 
xref="Regress.TestCallbackArrayInOut">Regress.TestCallbackArrayInOut</link>): Number(gint) {
+    // Gjs wrapper for regress_test_array_inout_callback()
+}
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>callback</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.TestCallbackArrayInOut.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.TestCallbackArrayInOut.page
new file mode 100644
index 0000000..0b4dd60
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.TestCallbackArrayInOut.page
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<page id="Regress.TestCallbackArrayInOut"
+      type="topic"
+      style="callback"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="callback" type="guide"/>
+  </info>
+  <title>Regress.TestCallbackArrayInOut</title>
+  <synopsis><code mime="text/x-python">
+ accepts([int], int)
+ returns(none)
+def on_TestCallbackArrayInOut(ints, length):
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>ints</code></title>
+
+</item>
+<item>
+<title><code>length</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_inout_callback.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_inout_callback.page
new file mode 100644
index 0000000..aea60c6
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_inout_callback.page
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_inout_callback"
+      type="topic"
+      style="function"
+      xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
+      xmlns:ui="http://projectmallard.org/1.0/ui/";>
+  <info>
+    <link xref="index" group="function" type="guide"/>
+    <api:function>
+      <api:returns>
+        <api:type>int</api:type>
+      </api:returns>
+      <api:name>regress_test_array_inout_callback</api:name>
+      <api:arg>
+        <api:type>Regress.TestCallbackArrayInOut</api:type>
+        <api:name>callback</api:name>
+      </api:arg>
+    </api:function>
+  </info>
+  <title>Regress.test_array_inout_callback</title>
+  <synopsis><code mime="text/x-python">
+ accepts(Regress.TestCallbackArrayInOut)
+ returns(int)
+def test_array_inout_callback(callback):
+    # Python wrapper for regress_test_array_inout_callback()
+  </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>callback</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+{formatter.format(node, node.retval.doc)}
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 89ecaa4..a907b30 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -2313,6 +2313,28 @@ use it should be.</doc>
         </parameter>
       </parameters>
     </callback>
+    <callback name="TestCallbackArrayInOut"
+              c:type="RegressTestCallbackArrayInOut">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="ints"
+                   direction="inout"
+                   caller-allocates="0"
+                   transfer-ownership="full">
+          <array length="1" zero-terminated="0" c:type="int**">
+            <type name="gint" c:type="int*"/>
+          </array>
+        </parameter>
+        <parameter name="length"
+                   direction="inout"
+                   caller-allocates="0"
+                   transfer-ownership="none">
+          <type name="gint" c:type="int*"/>
+        </parameter>
+      </parameters>
+    </callback>
     <callback name="TestCallbackFull" c:type="RegressTestCallbackFull">
       <return-value transfer-ownership="none">
         <type name="gint" c:type="int"/>
@@ -4977,6 +4999,18 @@ libgnome-keyring.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="test_array_inout_callback"
+              c:identifier="regress_test_array_inout_callback">
+      <return-value transfer-ownership="none">
+        <type name="gint" c:type="int"/>
+      </return-value>
+      <parameters>
+        <parameter name="callback" transfer-ownership="none" scope="call">
+          <type name="TestCallbackArrayInOut"
+                c:type="RegressTestCallbackArrayInOut"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_array_int_full_out"
               c:identifier="regress_test_array_int_full_out">
       <return-value transfer-ownership="full">
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index b42e0cd..e60b8e1 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -3363,6 +3363,37 @@ int regress_test_array_callback (RegressTestCallbackArray callback)
 }
 
 /**
+ * regress_test_array_inout_callback:
+ * @callback: (scope call):
+ *
+ */
+int
+regress_test_array_inout_callback (RegressTestCallbackArrayInOut callback)
+{
+  int *ints;
+  int length;
+
+  ints = g_new (int, 5);
+  for (length = 0; length < 5; ++length)
+    ints[length] = length - 2;
+
+  callback (&ints, &length);
+
+  g_assert_cmpint (length, ==, 4);
+  for (length = 0; length < 4; ++length)
+    g_assert_cmpint (ints[length], ==, length - 1);
+
+  callback (&ints, &length);
+
+  g_assert_cmpint (length, ==, 3);
+  for (length = 0; length < 3; ++length)
+    g_assert_cmpint (ints[length], ==, length);
+
+  g_free (ints);
+  return length;
+}
+
+/**
  * regress_test_simple_callback:
  * @callback: (scope call) (allow-none):
  *
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 667f129..3bbcb99 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -713,11 +713,18 @@ typedef int (*RegressTestCallbackFull) (int foo, double bar, char *path);
  * @two_length:
  */
 typedef int (*RegressTestCallbackArray) (int *one, gsize one_length, const char** two, int two_length);
+/**
+ * RegressTestCallbackArrayInOut:
+ * @ints: (inout) (array length=length):
+ * @length: (inout):
+ */
+typedef void (* RegressTestCallbackArrayInOut) (int **ints, int *length);
 
 void regress_test_simple_callback (RegressTestSimpleCallback callback);
 int regress_test_callback (RegressTestCallback callback);
 int regress_test_multi_callback (RegressTestCallback callback);
 int regress_test_array_callback (RegressTestCallbackArray callback);
+int regress_test_array_inout_callback (RegressTestCallbackArrayInOut callback);
 int regress_test_callback_user_data (RegressTestCallbackUserData callback,
                              gpointer user_data);
 int regress_test_callback_destroy_notify (RegressTestCallbackUserData callback,


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