PATH:
lib64
/
python2.7
/
ctypes
/
test
import sys 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 = "Hello, World" result = memmove(a, p, len(p)) self.assertEqual(a.value, "Hello, World") self.assertEqual(string_at(result), "Hello, World") self.assertEqual(string_at(result, 5), "Hello") self.assertEqual(string_at(result, 16), "Hello, World\0\0\0\0") self.assertEqual(string_at(result, 0), "") def test_memset(self): a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) self.assertEqual(a.value, "xxxxxxxxxxxxxxxx") self.assertEqual(string_at(result), "xxxxxxxxxxxxxxxx") self.assertEqual(string_at(a), "xxxxxxxxxxxxxxxx") self.assertEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0") def test_cast(self): a = (c_ubyte * 32)(*map(ord, "abcdef")) self.assertEqual(cast(a, c_char_p).value, "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]) def test_string_at(self): s = string_at("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("foo bar", 8), "foo bar\0") self.assertEqual(string_at("foo bar", 3), "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_values.pyc
[open]
[-] runtests.pyc
[open]
[-] test_objects.pyc
[open]
[-] test_checkretval.pyc
[open]
[-] test_find.pyo
[open]
[-] test_macholib.py
[open]
[-] test_loading.pyo
[open]
[-] test_wintypes.pyo
[open]
[-] test_win32.py
[open]
[-] test_loading.pyc
[open]
[-] test_frombuffer.pyo
[open]
[-] test_returnfuncptrs.py
[open]
[-] test_sizes.pyc
[open]
[-] test_libc.pyc
[open]
[-] test_libc.pyo
[open]
[-] test_random_things.py
[open]
[-] test_as_parameter.pyo
[open]
[-] test_refcounts.pyo
[open]
[-] test_random_things.pyc
[open]
[-] test_numbers.py
[open]
[-] test_pickling.pyo
[open]
[-] test_values.pyo
[open]
[-] test_simplesubclasses.pyo
[open]
[-] test_repr.py
[open]
[-] test_cfuncs.pyc
[open]
[-] test_structures.pyo
[open]
[-] test_incomplete.pyo
[open]
[-] test_frombuffer.pyc
[open]
[-] test_byteswap.py
[open]
[-] test_pickling.pyc
[open]
[-] test_parameters.py
[open]
[-] test_macholib.pyc
[open]
[-] test_array_in_pointer.pyo
[open]
[-] test_repr.pyo
[open]
[-] test_delattr.pyo
[open]
[-] test_callbacks.pyc
[open]
[-] test_strings.pyo
[open]
[-] test_funcptr.pyc
[open]
[-] test_byteswap.pyo
[open]
[-] test_frombuffer.py
[open]
[-] test_find.py
[open]
[-] test_anon.pyc
[open]
[-] test_errno.pyc
[open]
[-] test_pep3118.pyo
[open]
[-] test_funcptr.py
[open]
[-] test_strings.pyc
[open]
[-] test_cfuncs.py
[open]
[-] test_array_in_pointer.py
[open]
[-] test_bitfields.pyc
[open]
[-] test_python_api.pyc
[open]
[-] test_unicode.pyo
[open]
[-] test_anon.pyo
[open]
[-] test_slicing.pyc
[open]
[-] test_refcounts.pyc
[open]
[-] runtests.pyo
[open]
[-] test_pointers.pyo
[open]
[-] test_delattr.pyc
[open]
[-] __init__.pyc
[open]
[-] test_prototypes.pyc
[open]
[-] test_cast.pyo
[open]
[-] test_checkretval.pyo
[open]
[-] test_pep3118.py
[open]
[-] test_wintypes.pyc
[open]
[-] test_sizes.py
[open]
[-] test_numbers.pyc
[open]
[-] test_varsize_struct.pyo
[open]
[-] test_internals.py
[open]
[-] test_objects.py
[open]
[-] test_anon.py
[open]
[-] test_struct_fields.py
[open]
[-] test_functions.pyo
[open]
[-] test_libc.py
[open]
[-] test_struct_fields.pyc
[open]
[-] test_random_things.pyo
[open]
[-] test_arrays.pyc
[open]
[-] test_memfunctions.py
[open]
[-] test_python_api.pyo
[open]
[-] test_incomplete.pyc
[open]
[-] test_returnfuncptrs.pyo
[open]
[-] test_array_in_pointer.pyc
[open]
[-] test_structures.pyc
[open]
[-] test_errno.py
[open]
[-] test_returnfuncptrs.pyc
[open]
[-] test_as_parameter.pyc
[open]
[-] test_keeprefs.pyo
[open]
[-] test_memfunctions.pyc
[open]
[-] test_pep3118.pyc
[open]
[-] test_parameters.pyo
[open]
[-] test_cast.pyc
[open]
[-] test_simplesubclasses.py
[open]
[-] test_internals.pyc
[open]
[-] test_keeprefs.py
[open]
[-] test_pointers.py
[open]
[-] test_bitfields.pyo
[open]
[-] test_macholib.pyo
[open]
[-] test_refcounts.py
[open]
[-] test_values.py
[open]
[-] test_checkretval.py
[open]
[-] test_arrays.py
[open]
[-] test_buffers.pyc
[open]
[-] test_python_api.py
[open]
[-] test_strings.py
[open]
[-] test_unicode.pyc
[open]
[-] test_parameters.pyc
[open]
[-] test_buffers.pyo
[open]
[-] test_cfuncs.pyo
[open]
[-] test_prototypes.pyo
[open]
[-] test_keeprefs.pyc
[open]
[-] test_stringptr.pyc
[open]
[-] test_unicode.py
[open]
[-] test_struct_fields.pyo
[open]
[-] test_cast.py
[open]
[-] test_slicing.pyo
[open]
[-] test_buffers.py
[open]
[-] test_prototypes.py
[open]
[-] test_internals.pyo
[open]
[-] test_unaligned_structures.py
[open]
[-] test_functions.pyc
[open]
[-] test_stringptr.pyo
[open]
[-] test_repr.pyc
[open]
[-] __init__.py
[open]
[-] test_numbers.pyo
[open]
[-] test_init.pyc
[open]
[-] test_errno.pyo
[open]
[-] test_structures.py
[open]
[-] test_win32.pyo
[open]
[-] test_varsize_struct.pyc
[open]
[-] test_byteswap.pyc
[open]
[-] test_stringptr.py
[open]
[-] test_arrays.pyo
[open]
[-] test_slicing.py
[open]
[-] test_loading.py
[open]
[-] test_delattr.py
[open]
[-] test_objects.pyo
[open]
[-] test_init.pyo
[open]
[-] test_varsize_struct.py
[open]
[-] test_init.py
[open]
[-] test_memfunctions.pyo
[open]
[-] test_as_parameter.py
[open]
[-] test_incomplete.py
[open]
[-] test_simplesubclasses.pyc
[open]
[-] test_bitfields.py
[open]
[-] test_callbacks.py
[open]
[-] test_win32.pyc
[open]
[-] test_unaligned_structures.pyo
[open]
[-] test_unaligned_structures.pyc
[open]
[-] test_sizes.pyo
[open]
[-] test_funcptr.pyo
[open]
[-] __init__.pyo
[open]
[-] test_pointers.pyc
[open]
[-] runtests.py
[open]
[-] test_find.pyc
[open]
[-] test_callbacks.pyo
[open]
[-] test_wintypes.py
[open]
[-] test_functions.py
[open]
[-] test_pickling.py
[open]