diff options
author | Armin Rigo <arigo@tunes.org> | 2017-05-31 16:05:22 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-05-31 16:05:22 +0200 |
commit | b97cf3fb65cb3469576bdfeb2b2c34002ee87994 (patch) | |
tree | 5dfe94191452b87d121d737618bb8836390d7ffa /testing | |
parent | 5c408aba5fc53e553ad87dd0079fd1cb2edd25b1 (diff) | |
download | cffi-b97cf3fb65cb3469576bdfeb2b2c34002ee87994.tar.gz |
more tests
Diffstat (limited to 'testing')
-rw-r--r-- | testing/cffi0/test_ownlib.py | 25 | ||||
-rw-r--r-- | testing/cffi0/test_verify.py | 6 | ||||
-rw-r--r-- | testing/cffi1/test_new_ffi_1.py | 2 | ||||
-rw-r--r-- | testing/cffi1/test_verify1.py | 2 |
4 files changed, 33 insertions, 2 deletions
diff --git a/testing/cffi0/test_ownlib.py b/testing/cffi0/test_ownlib.py index 0572a9a..d6a66e3 100644 --- a/testing/cffi0/test_ownlib.py +++ b/testing/cffi0/test_ownlib.py @@ -2,6 +2,7 @@ import py, sys import subprocess, weakref from cffi import FFI from cffi.backend_ctypes import CTypesBackend +from testing.support import u SOURCE = """\ @@ -92,6 +93,15 @@ EXPORT RECT ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr, } EXPORT int my_array[7] = {0, 1, 2, 3, 4, 5, 6}; + +EXPORT unsigned short foo_2bytes(unsigned short a) +{ + return (unsigned short)(a + 42); +} +EXPORT unsigned int foo_4bytes(unsigned int a) +{ + return (unsigned int)(a + 42); +} """ class TestOwnLib(object): @@ -300,3 +310,18 @@ class TestOwnLib(object): pfn = ffi.addressof(lib, "test_getting_errno") assert ffi.typeof(pfn) == ffi.typeof("int(*)(void)") assert pfn == lib.test_getting_errno + + def test_char16_char32_t(self): + if self.module is None: + py.test.skip("fix the auto-generation of the tiny test lib") + if self.Backend is CTypesBackend: + py.test.skip("not implemented with the ctypes backend") + ffi = FFI(backend=self.Backend()) + ffi.cdef(""" + char16_t foo_2bytes(char16_t); + char32_t foo_4bytes(char32_t); + """) + lib = ffi.dlopen(self.module) + assert lib.foo_2bytes(u+'\u1234') == u+'\u125e' + assert lib.foo_4bytes(u+'\u1234') == u+'\u125e' + assert lib.foo_4bytes(u+'\U00012345') == u+'\U0001236f' diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py index 4b9e6d9..03e06fd 100644 --- a/testing/cffi0/test_verify.py +++ b/testing/cffi0/test_verify.py @@ -241,7 +241,7 @@ def test_primitive_category(): F = tp.is_float_type() X = tp.is_complex_type() I = tp.is_integer_type() - assert C == (typename in ('char', 'wchar_t')) + assert C == (typename in ('char', 'wchar_t', 'char16_t', 'char32_t')) assert F == (typename in ('float', 'double', 'long double')) assert X == (typename in ('float _Complex', 'double _Complex')) assert I + F + C + X == 1 # one and only one of them is true @@ -384,6 +384,10 @@ def test_wchar_type(): lib = ffi.verify("wchar_t foo(wchar_t x) { return x+1; }") assert lib.foo(uniexample1) == uniexample2 +def test_char16_char32_type(): + py.test.skip("XXX test or fully prevent char16_t and char32_t from " + "working in ffi.verify() mode") + def test_no_argument(): ffi = FFI() ffi.cdef("int foo(void);") diff --git a/testing/cffi1/test_new_ffi_1.py b/testing/cffi1/test_new_ffi_1.py index 6e42571..ab12974 100644 --- a/testing/cffi1/test_new_ffi_1.py +++ b/testing/cffi1/test_new_ffi_1.py @@ -1672,6 +1672,8 @@ class TestNewFFI1: "double", "long double", "wchar_t", + "char16_t", + "char32_t", "_Bool", "int8_t", "uint8_t", diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py index 0137802..2ed3ccb 100644 --- a/testing/cffi1/test_verify1.py +++ b/testing/cffi1/test_verify1.py @@ -221,7 +221,7 @@ def test_primitive_category(): F = tp.is_float_type() X = tp.is_complex_type() I = tp.is_integer_type() - assert C == (typename in ('char', 'wchar_t')) + assert C == (typename in ('char', 'wchar_t', 'char16_t', 'char32_t')) assert F == (typename in ('float', 'double', 'long double')) assert X == (typename in ('float _Complex', 'double _Complex')) assert I + F + C + X == 1 # one and only one of them is true |