From ac54caf4440e0a09ce1aa7935bee71512c7ca329 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Sat, 18 Jul 2020 23:56:43 +0200 Subject: Extra tests for using a 3-bytes struct as a return type --- testing/cffi0/test_function.py | 17 +++++++++++++++++ testing/cffi0/test_ownlib.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'testing') 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 -- cgit v1.2.1