Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1289:b3729934bf48
Date: 2013-07-18 22:06 +0200
http://bitbucket.org/cffi/cffi/changeset/b3729934bf48/
Log: Add three tests about callbacks receiving inlined structure
arguments
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,21 @@
for i, f in enumerate(flist):
assert f(-142) == -142 + i
+def test_callback_receiving_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(s):
+ return s.a + 10 * s.b
+ BFunc = new_function_type((BStruct,), BInt)
+ f = callback(BFunc, cb)
+ p = newp(BStructPtr, [-2, -4])
+ n = f(p[0])
+ assert n == -42
+
def test_callback_returning_tiny_struct():
BSChar = new_primitive_type("signed char")
BInt = new_primitive_type("int")
@@ -1247,6 +1262,22 @@
assert s.a == -10
assert s.b == -30
+def test_callback_receiving_struct():
+ BSChar = new_primitive_type("signed char")
+ BInt = new_primitive_type("int")
+ BDouble = new_primitive_type("double")
+ BStruct = new_struct_type("struct foo")
+ BStructPtr = new_pointer_type(BStruct)
+ complete_struct_or_union(BStruct, [('a', BSChar, -1),
+ ('b', BDouble, -1)])
+ def cb(s):
+ return s.a + int(s.b)
+ BFunc = new_function_type((BStruct,), BInt)
+ f = callback(BFunc, cb)
+ p = newp(BStructPtr, [-2, 44.444])
+ n = f(p[0])
+ assert n == 42
+
def test_callback_returning_struct():
BSChar = new_primitive_type("signed char")
BInt = new_primitive_type("int")
@@ -1266,6 +1297,30 @@
assert s.a == -10
assert s.b == 1E-42
+def test_callback_receiving_big_struct():
+ BInt = new_primitive_type("int")
+ BStruct = new_struct_type("struct foo")
+ BStructPtr = new_pointer_type(BStruct)
+ complete_struct_or_union(BStruct, [('a', BInt, -1),
+ ('b', BInt, -1),
+ ('c', BInt, -1),
+ ('d', BInt, -1),
+ ('e', BInt, -1),
+ ('f', BInt, -1),
+ ('g', BInt, -1),
+ ('h', BInt, -1),
+ ('i', BInt, -1),
+ ('j', BInt, -1)])
+ def cb(s):
+ for i, name in enumerate("abcdefghij"):
+ assert getattr(s, name) == 13 - i
+ return 42
+ BFunc = new_function_type((BStruct,), BInt)
+ f = callback(BFunc, cb)
+ p = newp(BStructPtr, list(range(13, 3, -1)))
+ n = f(p[0])
+ assert n == 42
+
def test_callback_returning_big_struct():
BInt = new_primitive_type("int")
BStruct = new_struct_type("struct foo")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit