summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-07-18 23:56:43 +0200
committerArmin Rigo <arigo@tunes.org>2020-07-18 23:56:43 +0200
commitac54caf4440e0a09ce1aa7935bee71512c7ca329 (patch)
treedf31af5ebf26e7cd3f4658f3bd225d85bdace72b /testing
parentc421c605a3fd6dd2d96f5969d4ca368b4fd12b20 (diff)
downloadcffi-ac54caf4440e0a09ce1aa7935bee71512c7ca329.tar.gz
Extra tests for using a 3-bytes struct as a return type
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi0/test_function.py17
-rw-r--r--testing/cffi0/test_ownlib.py30
2 files changed, 47 insertions, 0 deletions
diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py
index 6312707..4f2c864 100644
--- a/testing/cffi0/test_function.py
+++ b/testing/cffi0/test_function.py
@@ -240,6 +240,23 @@ class TestFunction(object):
else:
assert "None" in printed
+ def test_callback_returning_struct_three_bytes(self):
+ if self.Backend is CTypesBackend:
+ py.test.skip("not supported with the ctypes backend")
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ typedef struct {
+ unsigned char a, b, c;
+ } THREEBYTES;
+ """)
+ def cb():
+ return (12, 34, 56)
+ fptr = ffi.callback("THREEBYTES(*)(void)", cb)
+ tb = fptr()
+ assert tb.a == 12
+ assert tb.b == 34
+ assert tb.c == 56
+
def test_passing_array(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("""
diff --git a/testing/cffi0/test_ownlib.py b/testing/cffi0/test_ownlib.py
index 990f259..6a69cf6 100644
--- a/testing/cffi0/test_ownlib.py
+++ b/testing/cffi0/test_ownlib.py
@@ -35,6 +35,10 @@ typedef struct {
long bottom;
} RECT;
+typedef struct {
+ unsigned char a, b, c;
+} THREEBYTES;
+
EXPORT int PointInRect(RECT *prc, POINT pt)
{
@@ -107,6 +111,15 @@ EXPORT void modify_struct_value(RECT r)
{
r.left = r.right = r.top = r.bottom = 500;
}
+
+EXPORT THREEBYTES return_three_bytes(void)
+{
+ THREEBYTES result;
+ result.a = 12;
+ result.b = 34;
+ result.c = 56;
+ return result;
+}
"""
class TestOwnLib(object):
@@ -397,3 +410,20 @@ class TestOwnLib(object):
err = lib1.dlclose(handle)
assert err == 0
+
+ def test_return_three_bytes(self):
+ if self.module is None:
+ py.test.skip("fix the auto-generation of the tiny test lib")
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ typedef struct {
+ unsigned char a, b, c;
+ } THREEBYTES;
+
+ THREEBYTES return_three_bytes(void);
+ """)
+ lib = ffi.dlopen(self.module)
+ tb = lib.return_three_bytes()
+ assert tb.a == 12
+ assert tb.b == 34
+ assert tb.c == 56