<s> from ctypes import * <EOL> import unittest <EOL> class SimpleTestCase ( unittest . TestCase ) : <EOL> def test_cint ( self ) : <EOL> x = c_int ( ) <EOL> self . assertEqual ( x . _objects , None ) <EOL> x . value = <NUM_LIT> <EOL> self . assertEqual ( x . _objects , None ) <EOL> x = c_int ( <NUM_LIT> ) <EOL> self . assertEqual ( x . _objects , None ) <EOL> def test_ccharp ( self ) : <EOL> x = c_char_p ( ) <EOL> self . assertEqual ( x . _objects , None ) <EOL> x . value = "<STR_LIT:abc>" <EOL> self . assertEqual ( x . _objects , "<STR_LIT:abc>" ) <EOL> x = c_char_p ( "<STR_LIT>" ) <EOL> self . assertEqual ( x . _objects , "<STR_LIT>" ) <EOL> class StructureTestCase ( unittest . TestCase ) : <EOL> def test_cint_struct ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_int ) , <EOL> ( "<STR_LIT:b>" , c_int ) ] <EOL> x = X ( ) <EOL> self . assertEqual ( x . _objects , None ) <EOL> x . a = <NUM_LIT> <EOL> x . b = <NUM_LIT> <EOL> self . assertEqual ( x . _objects , None ) <EOL> def test_ccharp_struct ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_char_p ) , <EOL> ( "<STR_LIT:b>" , c_char_p ) ] <EOL> x = X ( ) <EOL> self . assertEqual ( x . _objects , None ) <EOL> x . a = "<STR_LIT>" <EOL> x . b = "<STR_LIT:foo>" <EOL> self . assertEqual ( x . _objects , { "<STR_LIT:0>" : "<STR_LIT>" , "<STR_LIT:1>" : "<STR_LIT:foo>" } ) <EOL> def test_struct_struct ( self ) : <EOL> class POINT ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:x>" , c_int ) , ( "<STR_LIT:y>" , c_int ) ] <EOL> class RECT ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , POINT ) , ( "<STR_LIT>" , POINT ) ] <EOL> r = RECT ( ) <EOL> r . ul . x = <NUM_LIT:0> <EOL> r . ul . y = <NUM_LIT:1> <EOL> r . lr . x = <NUM_LIT:2> <EOL> r . lr . y = <NUM_LIT:3> <EOL> self . assertEqual ( r . _objects , None ) <EOL> r = RECT ( ) <EOL> pt = POINT ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> r . ul = pt <EOL> self . assertEqual ( r . _objects , { '<STR_LIT:0>' : { } } ) <EOL> r . ul . x = <NUM_LIT> <EOL> r . ul . y = <NUM_LIT> <EOL> self . assertEqual ( r . _objects , { '<STR_LIT:0>' : { } } ) <EOL> r . lr = POINT ( ) <EOL> self . assertEqual ( r . _objects , { '<STR_LIT:0>' : { } , '<STR_LIT:1>' : { } } ) <EOL> class ArrayTestCase ( unittest . TestCase ) : <EOL> def test_cint_array ( self ) : <EOL> INTARR = c_int * <NUM_LIT:3> <EOL> ia = INTARR ( ) <EOL> self . assertEqual ( ia . _objects , None ) <EOL> ia [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> ia [ <NUM_LIT:1> ] = <NUM_LIT:2> <EOL> ia [ <NUM_LIT:2> ] = <NUM_LIT:3> <EOL> self . assertEqual ( ia . _objects , None ) <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:x>" , c_int ) , <EOL> ( "<STR_LIT:a>" , INTARR ) ] <EOL> x = X ( ) <EOL> x . x = <NUM_LIT:1000> <EOL> x . a [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> x . a [ <NUM_LIT:1> ] = <NUM_LIT> <EOL> self . assertEqual ( x . _objects , None ) <EOL> x . a = ia <EOL> self . assertEqual ( x . _objects , { '<STR_LIT:1>' : { } } ) <EOL> class PointerTestCase ( unittest . TestCase ) : <EOL> def test_p_cint ( self ) : <EOL> i = c_int ( <NUM_LIT> ) <EOL> x = pointer ( i ) <EOL> self . assertEqual ( x . _objects , { '<STR_LIT:1>' : i } ) <EOL> class DeletePointerTestCase ( unittest . TestCase ) : <EOL> def X_test ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:p>" , POINTER ( c_char_p ) ) ] <EOL> x = X ( ) <EOL> i = c_char_p ( "<STR_LIT>" ) <EOL> from sys import getrefcount as grc <EOL> print "<STR_LIT>" , grc ( i ) <EOL> x . p = pointer ( i ) <EOL> print "<STR_LIT>" , grc ( i ) <EOL> for i in range ( <NUM_LIT> ) : <EOL> c_int ( <NUM_LIT> ) <EOL> x . p [ <NUM_LIT:0> ] <EOL> print x . p [ <NUM_LIT:0> ] <EOL> import gc <EOL> gc . collect ( ) <EOL> for i in range ( <NUM_LIT> ) : <EOL> c_int ( <NUM_LIT> ) <EOL> x . p [ <NUM_LIT:0> ] <EOL> print x . p [ <NUM_LIT:0> ] <EOL> print x . p . contents <EOL> x . p [ <NUM_LIT:0> ] = "<STR_LIT>" <EOL> print "<STR_LIT:+>" * <NUM_LIT> <EOL> print x . _objects <EOL> class PointerToStructure ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> class POINT ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:x>" , c_int ) , ( "<STR_LIT:y>" , c_int ) ] <EOL> class RECT ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , POINTER ( POINT ) ) , <EOL> ( "<STR_LIT:b>" , POINTER ( POINT ) ) ] <EOL> r = RECT ( ) <EOL> p1 = POINT ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> r . a = pointer ( p1 ) <EOL> r . b = pointer ( p1 ) <EOL> r . a [ <NUM_LIT:0> ] . x = <NUM_LIT> <EOL> r . a [ <NUM_LIT:0> ] . y = <NUM_LIT> <EOL> from ctypes import _pointer_type_cache <EOL> del _pointer_type_cache [ POINT ] <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
