diff options
author | Armin Rigo <arigo@tunes.org> | 2017-05-31 16:42:16 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-05-31 16:42:16 +0200 |
commit | 73b89aa81ec2ab379f27cdeb75cdb710fb4b24eb (patch) | |
tree | b81522194c40f9199cd2dfe45c9477f4fa8d2985 /testing | |
parent | b97cf3fb65cb3469576bdfeb2b2c34002ee87994 (diff) | |
download | cffi-73b89aa81ec2ab379f27cdeb75cdb710fb4b24eb.tar.gz |
in-progress
Diffstat (limited to 'testing')
-rw-r--r-- | testing/cffi1/test_new_ffi_1.py | 27 | ||||
-rw-r--r-- | testing/cffi1/test_recompiler.py | 20 |
2 files changed, 46 insertions, 1 deletions
diff --git a/testing/cffi1/test_new_ffi_1.py b/testing/cffi1/test_new_ffi_1.py index ab12974..6839b9e 100644 --- a/testing/cffi1/test_new_ffi_1.py +++ b/testing/cffi1/test_new_ffi_1.py @@ -1744,3 +1744,30 @@ class TestNewFFI1: exec("from _test_import_from_lib import *", d) assert (sorted([x for x in d.keys() if not x.startswith('__')]) == ['ffi', 'lib']) + + def test_char16_t(self): + x = ffi.new("char16_t[]", 5) + assert len(x) == 5 and ffi.sizeof(x) == 10 + x[2] = u+'\u1324' + assert x[2] == u+'\u1324' + y = ffi.new("char16_t[]", u+'\u1234\u5678') + assert len(y) == 3 + assert list(y) == [u+'\u1234', u+'\u5678', u+'\x00'] + assert ffi.string(y) == u+'\u1234\u5678' + z = ffi.new("char16_t[]", u+'\U00012345') + assert len(z) == 3 + assert list(z) == [u+'\ud808', u+'\udf45', u+'\x00'] + assert ffi.string(z) == u+'\U00012345' + + def test_char32_t(self): + x = ffi.new("char32_t[]", 5) + assert len(x) == 5 and ffi.sizeof(x) == 20 + x[3] = u+'\U00013245' + assert x[3] == u+'\U00013245' + y = ffi.new("char32_t[]", u+'\u1234\u5678') + assert len(y) == 3 + assert list(y) == [u+'\u1234', u+'\u5678', u+'\x00'] + z = ffi.new("char32_t[]", u+'\U00012345') + assert len(z) == 2 + assert list(z) == [u+'\U00012345', u+'\x00'] # maybe a 2-unichars strin + assert ffi.string(z) == u+'\U00012345' diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py index d87fd35..fbc0316 100644 --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -24,10 +24,11 @@ def check_type_table(input, expected_output, included=None): assert ''.join(map(str, recomp.cffi_types)) == expected_output def verify(ffi, module_name, source, *args, **kwds): + no_cpp = kwds.pop('no_cpp', False) kwds.setdefault('undef_macros', ['NDEBUG']) module_name = '_CFFI_' + module_name ffi.set_source(module_name, source) - if not os.environ.get('NO_CPP'): # test the .cpp mode too + if not os.environ.get('NO_CPP') and not no_cpp: # test the .cpp mode too kwds.setdefault('source_extension', '.cpp') source = 'extern "C" {\n%s\n}' % (source,) else: @@ -2256,3 +2257,20 @@ def test_override_default_definition(): ffi.cdef("typedef long int16_t, char16_t;") lib = verify(ffi, "test_override_default_definition", "") assert ffi.typeof("int16_t") is ffi.typeof("char16_t") is ffi.typeof("long") + +def test_char16_char32_type(no_cpp=False): + ffi = FFI() + ffi.cdef(""" + char16_t foo_2bytes(char16_t); + char32_t foo_4bytes(char32_t); + """) + lib = verify(ffi, "test_char16_char32_type" + no_cpp * "_nocpp", """ + char16_t foo_2bytes(char16_t a) { return (char16_t)(a + 42); } + char32_t foo_4bytes(char32_t a) { return (char32_t)(a + 42); } + """, no_cpp=no_cpp) + assert lib.foo_2bytes(u+'\u1234') == u+'\u125e' + assert lib.foo_4bytes(u+'\u1234') == u+'\u125e' + assert lib.foo_4bytes(u+'\U00012345') == u+'\U0001236f' + +def test_char16_char32_plain_c(): + test_char16_char32_type(no_cpp=True) |