PATH:
opt
/
bitninja-python-dojo
/
embedded
/
lib
/
python3.9
/
ctypes
/
test
import unittest import ctypes from ctypes.test import need_symbol import _ctypes_test @need_symbol('c_wchar') class UnicodeTestCase(unittest.TestCase): def test_wcslen(self): dll = ctypes.CDLL(_ctypes_test.__file__) wcslen = dll.my_wcslen wcslen.argtypes = [ctypes.c_wchar_p] self.assertEqual(wcslen("abc"), 3) self.assertEqual(wcslen("ab\u2070"), 3) self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4") def test_buffers(self): buf = ctypes.create_unicode_buffer("abc") self.assertEqual(len(buf), 3+1) buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc") self.assertEqual(buf[:], "ab\xe4\xf6\xfc\0") self.assertEqual(buf[::], "ab\xe4\xf6\xfc\0") self.assertEqual(buf[::-1], '\x00\xfc\xf6\xe4ba') self.assertEqual(buf[::2], 'a\xe4\xfc') self.assertEqual(buf[6:5:-1], "") def test_embedded_null(self): class TestStruct(ctypes.Structure): _fields_ = [("unicode", ctypes.c_wchar_p)] t = TestStruct() # This would raise a ValueError: t.unicode = "foo\0bar\0\0" func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p class StringTestCase(UnicodeTestCase): def setUp(self): func.argtypes = [ctypes.c_char_p] func.restype = ctypes.c_char_p def tearDown(self): func.argtypes = None func.restype = ctypes.c_int def test_func(self): self.assertEqual(func(b"abc\xe4"), b"abc\xe4") def test_buffers(self): buf = ctypes.create_string_buffer(b"abc") self.assertEqual(len(buf), 3+1) buf = ctypes.create_string_buffer(b"ab\xe4\xf6\xfc") self.assertEqual(buf[:], b"ab\xe4\xf6\xfc\0") self.assertEqual(buf[::], b"ab\xe4\xf6\xfc\0") self.assertEqual(buf[::-1], b'\x00\xfc\xf6\xe4ba') self.assertEqual(buf[::2], b'a\xe4\xfc') self.assertEqual(buf[6:5:-1], b"") if __name__ == '__main__': unittest.main()
[-] test_win32.py
[edit]
[-] test_bitfields.py
[edit]
[-] test_libc.py
[edit]
[-] test_array_in_pointer.py
[edit]
[-] test_varsize_struct.py
[edit]
[-] test_arrays.py
[edit]
[-] test_random_things.py
[edit]
[-] test_callbacks.py
[edit]
[-] test_init.py
[edit]
[-] test_numbers.py
[edit]
[-] test_stringptr.py
[edit]
[-] test_sizes.py
[edit]
[-] test_internals.py
[edit]
[+]
..
[-] test_errno.py
[edit]
[-] test_wintypes.py
[edit]
[-] test_struct_fields.py
[edit]
[-] test_unicode.py
[edit]
[-] test_checkretval.py
[edit]
[-] test_bytes.py
[edit]
[-] test_returnfuncptrs.py
[edit]
[-] test_python_api.py
[edit]
[-] test_parameters.py
[edit]
[-] __main__.py
[edit]
[-] test_strings.py
[edit]
[-] test_values.py
[edit]
[-] test_pointers.py
[edit]
[-] test_repr.py
[edit]
[-] test_delattr.py
[edit]
[-] test_pep3118.py
[edit]
[-] test_buffers.py
[edit]
[-] test_objects.py
[edit]
[+]
__pycache__
[-] test_cast.py
[edit]
[-] test_prototypes.py
[edit]
[-] test_keeprefs.py
[edit]
[-] test_incomplete.py
[edit]
[-] test_slicing.py
[edit]
[-] test_cfuncs.py
[edit]
[-] test_structures.py
[edit]
[-] test_funcptr.py
[edit]
[-] test_refcounts.py
[edit]
[-] test_byteswap.py
[edit]
[-] test_unaligned_structures.py
[edit]
[-] test_loading.py
[edit]
[-] test_frombuffer.py
[edit]
[-] test_anon.py
[edit]
[-] test_macholib.py
[edit]
[-] test_as_parameter.py
[edit]
[-] test_find.py
[edit]
[-] __init__.py
[edit]
[-] test_functions.py
[edit]
[-] test_pickling.py
[edit]
[-] test_memfunctions.py
[edit]
[-] test_simplesubclasses.py
[edit]