[pypy-commit] cffi default: Add a test
arigo
noreply at buildbot.pypy.org
Thu Jul 18 21:59:07 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1288:2a9609999f81
Date: 2013-07-18 21:58 +0200
http://bitbucket.org/cffi/cffi/changeset/2a9609999f81/
Log: Add a test
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1230,6 +1230,23 @@
for i, f in enumerate(flist):
assert f(-142) == -142 + i
+def test_callback_returning_tiny_struct():
+ BSChar = new_primitive_type("signed char")
+ BInt = new_primitive_type("int")
+ BStruct = new_struct_type("struct foo")
+ BStructPtr = new_pointer_type(BStruct)
+ complete_struct_or_union(BStruct, [('a', BSChar, -1),
+ ('b', BSChar, -1)])
+ def cb(n):
+ return newp(BStructPtr, [-n, -3*n])[0]
+ BFunc = new_function_type((BInt,), BStruct)
+ f = callback(BFunc, cb)
+ s = f(10)
+ assert typeof(s) is BStruct
+ assert repr(s) == "<cdata 'struct foo' owning 2 bytes>"
+ assert s.a == -10
+ assert s.b == -30
+
def test_callback_returning_struct():
BSChar = new_primitive_type("signed char")
BInt = new_primitive_type("int")
More information about the pypy-commit
mailing list