PATH:
opt
/
bitninja-python-dojo
/
embedded
/
lib
/
python3.9
/
ctypes
/
test
import sys from test import support import unittest from ctypes import * from ctypes.test import need_symbol class MemFunctionsTest(unittest.TestCase): @unittest.skip('test disabled') def test_overflow(self): # string_at and wstring_at must use the Python calling # convention (which acquires the GIL and checks the Python # error flag). Provoke an error and catch it; see also issue # #3554: <http://bugs.python.org/issue3554> self.assertRaises((OverflowError, MemoryError, SystemError), lambda: wstring_at(u"foo", sys.maxint - 1)) self.assertRaises((OverflowError, MemoryError, SystemError), lambda: string_at("foo", sys.maxint - 1)) def test_memmove(self): # large buffers apparently increase the chance that the memory # is allocated in high address space. a = create_string_buffer(1000000) p = b"Hello, World" result = memmove(a, p, len(p)) self.assertEqual(a.value, b"Hello, World") self.assertEqual(string_at(result), b"Hello, World") self.assertEqual(string_at(result, 5), b"Hello") self.assertEqual(string_at(result, 16), b"Hello, World\0\0\0\0") self.assertEqual(string_at(result, 0), b"") def test_memset(self): a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) self.assertEqual(a.value, b"xxxxxxxxxxxxxxxx") self.assertEqual(string_at(result), b"xxxxxxxxxxxxxxxx") self.assertEqual(string_at(a), b"xxxxxxxxxxxxxxxx") self.assertEqual(string_at(a, 20), b"xxxxxxxxxxxxxxxx\0\0\0\0") def test_cast(self): a = (c_ubyte * 32)(*map(ord, "abcdef")) self.assertEqual(cast(a, c_char_p).value, b"abcdef") self.assertEqual(cast(a, POINTER(c_byte))[:7], [97, 98, 99, 100, 101, 102, 0]) self.assertEqual(cast(a, POINTER(c_byte))[:7:], [97, 98, 99, 100, 101, 102, 0]) self.assertEqual(cast(a, POINTER(c_byte))[6:-1:-1], [0, 102, 101, 100, 99, 98, 97]) self.assertEqual(cast(a, POINTER(c_byte))[:7:2], [97, 99, 101, 0]) self.assertEqual(cast(a, POINTER(c_byte))[:7:7], [97]) @support.refcount_test def test_string_at(self): s = string_at(b"foo bar") # XXX The following may be wrong, depending on how Python # manages string instances self.assertEqual(2, sys.getrefcount(s)) self.assertTrue(s, "foo bar") self.assertEqual(string_at(b"foo bar", 7), b"foo bar") self.assertEqual(string_at(b"foo bar", 3), b"foo") @need_symbol('create_unicode_buffer') def test_wstring_at(self): p = create_unicode_buffer("Hello, World") a = create_unicode_buffer(1000000) result = memmove(a, p, len(p) * sizeof(c_wchar)) self.assertEqual(a.value, "Hello, World") self.assertEqual(wstring_at(a), "Hello, World") self.assertEqual(wstring_at(a, 5), "Hello") self.assertEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") self.assertEqual(wstring_at(a, 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]