[pypy-commit] cffi default: Add a passing test about callbacks returning structs.

arigo noreply at buildbot.pypy.org
Fri Jun 29 10:50:02 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r563:c3e818533793
Date: 2012-06-29 10:49 +0200
http://bitbucket.org/cffi/cffi/changeset/c3e818533793/

Log:	Add a passing test about callbacks returning structs.

diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -878,6 +878,24 @@
     for i, f in enumerate(flist):
         assert f(-142) == -142 + i
 
+def test_callback_returning_struct():
+    BSChar = new_primitive_type("signed char")
+    BInt = new_primitive_type("int")
+    BDouble = new_primitive_type("double")
+    BStruct = new_struct_type("foo")
+    BStructPtr = new_pointer_type(BStruct)
+    complete_struct_or_union(BStruct, [('a', BSChar, -1),
+                                       ('b', BDouble, -1)])
+    def cb(n):
+        return newp(BStructPtr, [-n, 1E-42])[0]
+    BFunc = new_function_type((BInt,), BStruct)
+    f = callback(BFunc, cb)
+    s = f(10)
+    assert typeof(s) is BStruct
+    assert repr(s).startswith("<cdata 'struct foo' owning ")
+    assert s.a == -10
+    assert s.b == 1E-42
+
 def test_enum_type():
     BEnum = new_enum_type("foo", (), ())
     assert repr(BEnum) == "<ctype 'enum foo'>"


More information about the pypy-commit mailing list