PATH:
opt
/
bitninja-python-dojo
/
embedded
/
lib
/
python3.9
/
ctypes
/
test
from ctypes import * from ctypes.test import need_symbol import unittest class StringBufferTestCase(unittest.TestCase): def test_buffer(self): b = create_string_buffer(32) self.assertEqual(len(b), 32) self.assertEqual(sizeof(b), 32 * sizeof(c_char)) self.assertIs(type(b[0]), bytes) b = create_string_buffer(b"abc") self.assertEqual(len(b), 4) # trailing nul char self.assertEqual(sizeof(b), 4 * sizeof(c_char)) self.assertIs(type(b[0]), bytes) self.assertEqual(b[0], b"a") self.assertEqual(b[:], b"abc\0") self.assertEqual(b[::], b"abc\0") self.assertEqual(b[::-1], b"\0cba") self.assertEqual(b[::2], b"ac") self.assertEqual(b[::5], b"a") self.assertRaises(TypeError, create_string_buffer, "abc") def test_buffer_interface(self): self.assertEqual(len(bytearray(create_string_buffer(0))), 0) self.assertEqual(len(bytearray(create_string_buffer(1))), 1) @need_symbol('c_wchar') def test_unicode_buffer(self): b = create_unicode_buffer(32) self.assertEqual(len(b), 32) self.assertEqual(sizeof(b), 32 * sizeof(c_wchar)) self.assertIs(type(b[0]), str) b = create_unicode_buffer("abc") self.assertEqual(len(b), 4) # trailing nul char self.assertEqual(sizeof(b), 4 * sizeof(c_wchar)) self.assertIs(type(b[0]), str) self.assertEqual(b[0], "a") self.assertEqual(b[:], "abc\0") self.assertEqual(b[::], "abc\0") self.assertEqual(b[::-1], "\0cba") self.assertEqual(b[::2], "ac") self.assertEqual(b[::5], "a") self.assertRaises(TypeError, create_unicode_buffer, b"abc") @need_symbol('c_wchar') def test_unicode_conversion(self): b = create_unicode_buffer("abc") self.assertEqual(len(b), 4) # trailing nul char self.assertEqual(sizeof(b), 4 * sizeof(c_wchar)) self.assertIs(type(b[0]), str) self.assertEqual(b[0], "a") self.assertEqual(b[:], "abc\0") self.assertEqual(b[::], "abc\0") self.assertEqual(b[::-1], "\0cba") self.assertEqual(b[::2], "ac") self.assertEqual(b[::5], "a") @need_symbol('c_wchar') def test_create_unicode_buffer_non_bmp(self): expected = 5 if sizeof(c_wchar) == 2 else 3 for s in '\U00010000\U00100000', '\U00010000\U0010ffff': b = create_unicode_buffer(s) self.assertEqual(len(b), expected) self.assertEqual(b[-1], '\0') 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]