<s> import unittest <EOL> from ctypes import * <EOL> from test import test_support <EOL> class StringArrayTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> BUF = c_char * <NUM_LIT:4> <EOL> buf = BUF ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ) <EOL> self . assertEqual ( buf . value , "<STR_LIT:abc>" ) <EOL> self . assertEqual ( buf . raw , "<STR_LIT>" ) <EOL> buf . value = "<STR_LIT>" <EOL> self . assertEqual ( buf . value , "<STR_LIT>" ) <EOL> self . assertEqual ( buf . raw , "<STR_LIT>" ) <EOL> buf . value = "<STR_LIT:x>" <EOL> self . assertEqual ( buf . value , "<STR_LIT:x>" ) <EOL> self . assertEqual ( buf . raw , "<STR_LIT>" ) <EOL> buf [ <NUM_LIT:1> ] = "<STR_LIT>" <EOL> self . assertEqual ( buf . value , "<STR_LIT>" ) <EOL> self . assertEqual ( buf . raw , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , setattr , buf , "<STR_LIT:value>" , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , setattr , buf , "<STR_LIT:value>" , <NUM_LIT> ) <EOL> def test_c_buffer_value ( self , memoryview = memoryview ) : <EOL> buf = c_buffer ( <NUM_LIT:32> ) <EOL> buf . value = "<STR_LIT>" <EOL> self . assertEqual ( buf . value , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , setattr , buf , "<STR_LIT:value>" , memoryview ( "<STR_LIT>" ) ) <EOL> self . assertRaises ( TypeError , setattr , buf , "<STR_LIT:value>" , memoryview ( "<STR_LIT:abc>" ) ) <EOL> self . assertRaises ( ValueError , setattr , buf , "<STR_LIT>" , memoryview ( "<STR_LIT:x>" * <NUM_LIT:100> ) ) <EOL> def test_c_buffer_raw ( self , memoryview = memoryview ) : <EOL> buf = c_buffer ( <NUM_LIT:32> ) <EOL> buf . raw = memoryview ( "<STR_LIT>" ) <EOL> self . assertEqual ( buf . value , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , setattr , buf , "<STR_LIT:value>" , memoryview ( "<STR_LIT:abc>" ) ) <EOL> self . assertRaises ( ValueError , setattr , buf , "<STR_LIT>" , memoryview ( "<STR_LIT:x>" * <NUM_LIT:100> ) ) <EOL> def test_c_buffer_deprecated ( self ) : <EOL> with test_support . check_py3k_warnings ( ) : <EOL> self . test_c_buffer_value ( buffer ) <EOL> self . test_c_buffer_raw ( buffer ) <EOL> def test_param_1 ( self ) : <EOL> BUF = c_char * <NUM_LIT:4> <EOL> buf = BUF ( ) <EOL> def test_param_2 ( self ) : <EOL> BUF = c_char * <NUM_LIT:4> <EOL> buf = BUF ( ) <EOL> try : <EOL> c_wchar <EOL> except NameError : <EOL> pass <EOL> else : <EOL> class WStringArrayTestCase ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> BUF = c_wchar * <NUM_LIT:4> <EOL> buf = BUF ( u"<STR_LIT:a>" , u"<STR_LIT:b>" , u"<STR_LIT:c>" ) <EOL> self . assertEqual ( buf . value , u"<STR_LIT:abc>" ) <EOL> buf . value = u"<STR_LIT>" <EOL> self . assertEqual ( buf . value , u"<STR_LIT>" ) <EOL> buf . value = u"<STR_LIT:x>" <EOL> self . assertEqual ( buf . value , u"<STR_LIT:x>" ) <EOL> buf [ <NUM_LIT:1> ] = u"<STR_LIT>" <EOL> self . assertEqual ( buf . value , u"<STR_LIT>" ) <EOL> class StringTestCase ( unittest . TestCase ) : <EOL> def XX_test_basic_strings ( self ) : <EOL> cs = c_string ( "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , len , cs ) <EOL> self . assertEqual ( sizeof ( cs ) , <NUM_LIT:7> ) <EOL> self . assertEqual ( cs . value , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" ) . value , "<STR_LIT:abc>" ) <EOL> self . assertEqual ( cs . raw , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" ) . raw , "<STR_LIT>" ) <EOL> cs . value = "<STR_LIT>" <EOL> self . assertEqual ( cs . value , "<STR_LIT>" ) <EOL> self . assertEqual ( cs . raw , "<STR_LIT>" ) <EOL> cs . raw = "<STR_LIT>" <EOL> self . assertEqual ( cs . value , "<STR_LIT>" ) <EOL> self . assertEqual ( cs . raw , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , c_string , u"<STR_LIT>" ) <EOL> def XX_test_sized_strings ( self ) : <EOL> self . assertRaises ( TypeError , c_string , None ) <EOL> self . assertEqual ( len ( c_string ( <NUM_LIT:32> ) . raw ) , <NUM_LIT:32> ) <EOL> self . assertRaises ( ValueError , c_string , - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , c_string , <NUM_LIT:0> ) <EOL> self . assertEqual ( c_string ( <NUM_LIT:2> ) . raw [ - <NUM_LIT:1> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( c_string ( <NUM_LIT:2> ) . raw ) , <NUM_LIT:2> ) <EOL> def XX_test_initialized_strings ( self ) : <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:4> ) . raw [ : <NUM_LIT:2> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:4> ) . raw [ : <NUM_LIT:2> : ] , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:4> ) . raw [ : <NUM_LIT:2> : - <NUM_LIT:1> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:4> ) . raw [ : <NUM_LIT:2> : <NUM_LIT:2> ] , "<STR_LIT:a>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:4> ) . raw [ - <NUM_LIT:1> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( c_string ( "<STR_LIT>" , <NUM_LIT:2> ) . raw , "<STR_LIT>" ) <EOL> def XX_test_toolong ( self ) : <EOL> cs = c_string ( "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , setattr , cs , "<STR_LIT:value>" , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , setattr , cs , "<STR_LIT:value>" , "<STR_LIT>" ) <EOL> try : <EOL> c_wchar <EOL> except NameError : <EOL> pass <EOL> else : <EOL> class WStringTestCase ( unittest . TestCase ) : <EOL> def test_wchar ( self ) : <EOL> c_wchar ( u"<STR_LIT:x>" ) <EOL> repr ( byref ( c_wchar ( u"<STR_LIT:x>" ) ) ) <EOL> c_wchar ( "<STR_LIT:x>" ) <EOL> def X_test_basic_wstrings ( self ) : <EOL> cs = c_wstring ( u"<STR_LIT>" ) <EOL> self . assertEqual ( sizeof ( cs ) , <NUM_LIT> ) <EOL> self . assertEqual ( cs . value , u"<STR_LIT>" ) <EOL> self . assertEqual ( c_wstring ( u"<STR_LIT>" ) . value , u"<STR_LIT:abc>" ) <EOL> self . assertEqual ( c_wstring ( u"<STR_LIT>" ) . value , u"<STR_LIT:abc>" ) <EOL> self . assertEqual ( cs . raw , u"<STR_LIT>" ) <EOL> self . assertEqual ( c_wstring ( u"<STR_LIT>" ) . raw , u"<STR_LIT>" ) <EOL> cs . value = u"<STR_LIT>" <EOL> self . assertEqual ( cs . value , u"<STR_LIT>" ) <EOL> self . assertEqual ( cs . raw , u"<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , c_wstring , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , c_wstring , <NUM_LIT:0> ) <EOL> def X_test_toolong ( self ) : <EOL> cs = c_wstring ( u"<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , setattr , cs , "<STR_LIT:value>" , u"<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , setattr , cs , "<STR_LIT:value>" , u"<STR_LIT>" ) <EOL> def run_test ( rep , msg , func , arg ) : <EOL> items = range ( rep ) <EOL> from time import clock <EOL> start = clock ( ) <EOL> for i in items : <EOL> func ( arg ) ; func ( arg ) ; func ( arg ) ; func ( arg ) ; func ( arg ) <EOL> stop = clock ( ) <EOL> print "<STR_LIT>" % ( msg , ( ( stop - start ) * <NUM_LIT> / <NUM_LIT:5> / rep ) ) <EOL> def check_perf ( ) : <EOL> REP = <NUM_LIT> <EOL> run_test ( REP , "<STR_LIT>" , c_string , None ) <EOL> run_test ( REP , "<STR_LIT>" , c_string , '<STR_LIT:abc>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
