PATH:
usr
/
lib64
/
python2.7
/
ctypes
/
test
from ctypes import * import unittest class SimpleTestCase(unittest.TestCase): def test_cint(self): x = c_int() self.assertEqual(x._objects, None) x.value = 42 self.assertEqual(x._objects, None) x = c_int(99) self.assertEqual(x._objects, None) def test_ccharp(self): x = c_char_p() self.assertEqual(x._objects, None) x.value = "abc" self.assertEqual(x._objects, "abc") x = c_char_p("spam") self.assertEqual(x._objects, "spam") class StructureTestCase(unittest.TestCase): def test_cint_struct(self): class X(Structure): _fields_ = [("a", c_int), ("b", c_int)] x = X() self.assertEqual(x._objects, None) x.a = 42 x.b = 99 self.assertEqual(x._objects, None) def test_ccharp_struct(self): class X(Structure): _fields_ = [("a", c_char_p), ("b", c_char_p)] x = X() self.assertEqual(x._objects, None) x.a = "spam" x.b = "foo" self.assertEqual(x._objects, {"0": "spam", "1": "foo"}) def test_struct_struct(self): class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] class RECT(Structure): _fields_ = [("ul", POINT), ("lr", POINT)] r = RECT() r.ul.x = 0 r.ul.y = 1 r.lr.x = 2 r.lr.y = 3 self.assertEqual(r._objects, None) r = RECT() pt = POINT(1, 2) r.ul = pt self.assertEqual(r._objects, {'0': {}}) r.ul.x = 22 r.ul.y = 44 self.assertEqual(r._objects, {'0': {}}) r.lr = POINT() self.assertEqual(r._objects, {'0': {}, '1': {}}) class ArrayTestCase(unittest.TestCase): def test_cint_array(self): INTARR = c_int * 3 ia = INTARR() self.assertEqual(ia._objects, None) ia[0] = 1 ia[1] = 2 ia[2] = 3 self.assertEqual(ia._objects, None) class X(Structure): _fields_ = [("x", c_int), ("a", INTARR)] x = X() x.x = 1000 x.a[0] = 42 x.a[1] = 96 self.assertEqual(x._objects, None) x.a = ia self.assertEqual(x._objects, {'1': {}}) class PointerTestCase(unittest.TestCase): def test_p_cint(self): i = c_int(42) x = pointer(i) self.assertEqual(x._objects, {'1': i}) class DeletePointerTestCase(unittest.TestCase): @unittest.skip('test disabled') def test_X(self): class X(Structure): _fields_ = [("p", POINTER(c_char_p))] x = X() i = c_char_p("abc def") from sys import getrefcount as grc print "2?", grc(i) x.p = pointer(i) print "3?", grc(i) for i in range(320): c_int(99) x.p[0] print x.p[0] ## del x ## print "2?", grc(i) ## del i import gc gc.collect() for i in range(320): c_int(99) x.p[0] print x.p[0] print x.p.contents ## print x._objects x.p[0] = "spam spam" ## print x.p[0] print "+" * 42 print x._objects class PointerToStructure(unittest.TestCase): def test(self): class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] class RECT(Structure): _fields_ = [("a", POINTER(POINT)), ("b", POINTER(POINT))] r = RECT() p1 = POINT(1, 2) r.a = pointer(p1) r.b = pointer(p1) ## from pprint import pprint as pp ## pp(p1._objects) ## pp(r._objects) r.a[0].x = 42 r.a[0].y = 99 # to avoid leaking when tests are run several times # clean up the types left in the cache. from ctypes import _pointer_type_cache del _pointer_type_cache[POINT] 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]