diff options
author | Armin Rigo <arigo@tunes.org> | 2013-07-18 22:06:56 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2013-07-18 22:06:56 +0200 |
commit | f0c75e3ae1b7e5e94ac2be35f0e39a008ad92afd (patch) | |
tree | 69170a6caa3cb4824489851b4e5c86f8db1883a1 | |
parent | 0ead5db1db33a57f7dedd644c55b77ad5e98d565 (diff) | |
download | cffi-f0c75e3ae1b7e5e94ac2be35f0e39a008ad92afd.tar.gz |
Add three tests about callbacks receiving inlined structure arguments
-rw-r--r-- | c/test_c.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/c/test_c.py b/c/test_c.py index 2690a2d..02a4d03 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -1230,6 +1230,21 @@ def test_a_lot_of_callbacks(): 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 @@ def test_callback_returning_tiny_struct(): 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 @@ def test_callback_returning_struct(): 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") |