[gobject-introspection] tests: Add regression test for out array of struct



commit b20ac732d096c1140d856d99f4cf64f6c708de50
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Feb 6 20:59:11 2016 -0800

    tests: Add regression test for out array of struct
    
    This is a regression test for returning out arrays of structs, like
    gdk_keymap_get_entries_for_keyval() for example.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761658

 .../Regress.test_array_struct_out.page             |   47 ++++++++++++++++++++
 .../Regress.test_array_struct_out.page             |   32 +++++++++++++
 .../Regress.test_array_struct_out.page             |   45 +++++++++++++++++++
 tests/scanner/Regress-1.0-expected.gir             |   23 ++++++++++
 tests/scanner/Regress-1.0-sections-expected.txt    |    1 +
 tests/scanner/regress.c                            |   17 +++++++
 tests/scanner/regress.h                            |    3 +
 7 files changed, 168 insertions(+), 0 deletions(-)
---
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.test_array_struct_out.page 
b/tests/scanner/Regress-1.0-C-expected/Regress.test_array_struct_out.page
new file mode 100644
index 0000000..84aee10
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.test_array_struct_out.page
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_struct_out"
+      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>void</api:type>
+      </api:returns>
+      <api:name>regress_test_array_struct_out</api:name>
+      <api:arg>
+        <api:type>RegressTestStructA**</api:type>
+        <api:name>arr</api:name>
+      </api:arg>
+      <api:arg>
+        <api:type>int*</api:type>
+        <api:name>len</api:name>
+      </api:arg>
+    </api:function>
+  </info>
+  <title>regress_test_array_struct_out</title>
+  <synopsis><code mime="text/x-csrc">
+void regress_test_array_struct_out (RegressTestStructA** arr,
+                                    int* len);
+  </code></synopsis>
+<p>This is similar to gdk_keymap_get_entries_for_keyval().</p>
+
+<terms>
+<item>
+<title><code>arr</code></title>
+
+</item>
+<item>
+<title><code>len</code></title>
+
+</item>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_struct_out.page 
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_struct_out.page
new file mode 100644
index 0000000..46c7c13
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_array_struct_out.page
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_struct_out"
+      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>void</api:type>
+      </api:returns>
+      <api:name>regress_test_array_struct_out</api:name>
+    </api:function>
+  </info>
+  <title>Regress.test_array_struct_out</title>
+  <synopsis><code mime="text/x-gjs">
+function test_array_struct_out(): Array(<link xref="Regress.TestStructA">Regress.TestStructA</link>) {
+    // Gjs wrapper for regress_test_array_struct_out()
+}
+  </code></synopsis>
+<p>This is similar to gdk_keymap_get_entries_for_keyval().</p>
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_struct_out.page 
b/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_struct_out.page
new file mode 100644
index 0000000..5ca1363
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.test_array_struct_out.page
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<page id="Regress.test_array_struct_out"
+      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>none</api:type>
+      </api:returns>
+      <api:name>regress_test_array_struct_out</api:name>
+      <api:arg>
+        <api:type>[Regress.TestStructA]</api:type>
+        <api:name>arr</api:name>
+      </api:arg>
+      <api:arg>
+        <api:type>int</api:type>
+        <api:name>len</api:name>
+      </api:arg>
+    </api:function>
+  </info>
+  <title>Regress.test_array_struct_out</title>
+  <synopsis><code mime="text/x-python">
+ accepts([Regress.TestStructA], int)
+ returns(none)
+def test_array_struct_out(arr, len):
+    # Python wrapper for regress_test_array_struct_out()
+  </code></synopsis>
+<p>This is similar to gdk_keymap_get_entries_for_keyval().</p>
+
+<terms>
+<item>
+<title><code>arr</code></title>
+
+</item>
+<item>
+<title><code>len</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 06aff1d..321a7c6 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -5291,6 +5291,29 @@ libgnome-keyring.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="test_array_struct_out"
+              c:identifier="regress_test_array_struct_out">
+      <doc xml:space="preserve">This is similar to gdk_keymap_get_entries_for_keyval().</doc>
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="arr"
+                   direction="out"
+                   caller-allocates="0"
+                   transfer-ownership="full">
+          <array length="1" zero-terminated="0" c:type="RegressTestStructA**">
+            <type name="TestStructA" c:type="RegressTestStructA*"/>
+          </array>
+        </parameter>
+        <parameter name="len"
+                   direction="out"
+                   caller-allocates="0"
+                   transfer-ownership="full">
+          <type name="gint" c:type="int*"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_async_ready_callback"
               c:identifier="regress_test_async_ready_callback">
       <return-value transfer-ownership="none">
diff --git a/tests/scanner/Regress-1.0-sections-expected.txt b/tests/scanner/Regress-1.0-sections-expected.txt
index c7ba75c..26ace9a 100644
--- a/tests/scanner/Regress-1.0-sections-expected.txt
+++ b/tests/scanner/Regress-1.0-sections-expected.txt
@@ -73,6 +73,7 @@ regress_test_array_int_none_out
 regress_test_array_int_null_in
 regress_test_array_int_null_out
 regress_test_array_int_out
+regress_test_array_struct_out
 regress_test_async_ready_callback
 regress_test_boolean
 regress_test_boolean_false
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index fa48105..6eac6f7 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1740,6 +1740,23 @@ regress_test_struct_a_parse (RegressTestStructA *a_out,
 }
 
 /**
+ * regress_test_array_struct_out:
+ * @arr: (out) (array length=len) (transfer full):
+ * @len: (out)
+ *
+ * This is similar to gdk_keymap_get_entries_for_keyval().
+ */
+void
+regress_test_array_struct_out (RegressTestStructA **arr, int *len)
+{
+  *arr = g_new0(RegressTestStructA, 3);
+  (*arr)[0].some_int = 22;
+  (*arr)[1].some_int = 33;
+  (*arr)[2].some_int = 44;
+  *len = 3;
+}
+
+/**
  * regress_test_struct_b_clone:
  * @b: the structure
  * @b_out: (out): the cloned structure
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 99cd311..780f8e2 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -541,6 +541,9 @@ void regress_test_struct_a_clone (RegressTestStructA *a,
 _GI_TEST_EXTERN
 void regress_test_struct_a_parse (RegressTestStructA *a_out, const gchar *string);
 
+_GI_TEST_EXTERN
+void regress_test_array_struct_out (RegressTestStructA **arr, int *len);
+
 struct _RegressTestStructB
 {
   gint8 some_int8;


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