<s> import unittest <EOL> from ctypes import * <EOL> from sys import getrefcount as grc <EOL> """<STR_LIT>""" <EOL> class ObjectsTestCase ( unittest . TestCase ) : <EOL> def failUnlessSame ( self , a , b ) : <EOL> self . failUnlessEqual ( id ( a ) , id ( b ) ) <EOL> def test_ints ( self ) : <EOL> i = <NUM_LIT> <EOL> self . failUnlessEqual ( <NUM_LIT:3> , grc ( i ) ) <EOL> ci = c_int ( i ) <EOL> self . failUnlessEqual ( <NUM_LIT:3> , grc ( i ) ) <EOL> self . failUnlessEqual ( ci . _objects , None ) <EOL> def test_c_char_p ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . failUnlessEqual ( <NUM_LIT:3> , grc ( s ) ) <EOL> cs = c_char_p ( s ) <EOL> self . failUnlessEqual ( <NUM_LIT:4> , grc ( s ) ) <EOL> self . failUnlessSame ( cs . _objects , s ) <EOL> def test_simple_struct ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_int ) , ( "<STR_LIT:b>" , c_int ) ] <EOL> a = <NUM_LIT> <EOL> b = <NUM_LIT> <EOL> x = X ( ) <EOL> self . failUnlessEqual ( x . _objects , None ) <EOL> x . a = a <EOL> x . b = b <EOL> self . failUnlessEqual ( x . _objects , None ) <EOL> def test_embedded_structs ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_int ) , ( "<STR_LIT:b>" , c_int ) ] <EOL> class Y ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:x>" , X ) , ( "<STR_LIT:y>" , X ) ] <EOL> y = Y ( ) <EOL> self . failUnlessEqual ( y . _objects , None ) <EOL> x1 , x2 = X ( ) , X ( ) <EOL> y . x , y . y = x1 , x2 <EOL> self . failUnlessEqual ( y . _objects , { "<STR_LIT:0>" : { } , "<STR_LIT:1>" : { } } ) <EOL> x1 . a , x2 . b = <NUM_LIT> , <NUM_LIT> <EOL> self . failUnlessEqual ( y . _objects , { "<STR_LIT:0>" : { } , "<STR_LIT:1>" : { } } ) <EOL> def test_xxx ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_char_p ) , ( "<STR_LIT:b>" , c_char_p ) ] <EOL> class Y ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:x>" , X ) , ( "<STR_LIT:y>" , X ) ] <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> x = X ( ) <EOL> x . a = s1 <EOL> x . b = s2 <EOL> self . failUnlessEqual ( x . _objects , { "<STR_LIT:0>" : s1 , "<STR_LIT:1>" : s2 } ) <EOL> y = Y ( ) <EOL> y . x = x <EOL> self . failUnlessEqual ( y . _objects , { "<STR_LIT:0>" : { "<STR_LIT:0>" : s1 , "<STR_LIT:1>" : s2 } } ) <EOL> def test_ptr_struct ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:data>" , POINTER ( c_int ) ) ] <EOL> A = c_int * <NUM_LIT:4> <EOL> a = A ( <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . failUnlessEqual ( a . _objects , None ) <EOL> x = X ( ) <EOL> x . data = a <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
