<s> """<STR_LIT>""" <EOL> import py <EOL> from ctypes import * <EOL> from support import BaseCTypesTestChecker <EOL> class TestExtra ( BaseCTypesTestChecker ) : <EOL> def test_primitive_pointer ( self ) : <EOL> x = c_int ( <NUM_LIT:5> ) <EOL> assert x . value == <NUM_LIT:5> <EOL> x . value = <NUM_LIT:6> <EOL> assert x . value == <NUM_LIT:6> <EOL> p = pointer ( x ) <EOL> assert isinstance ( p . contents , c_int ) <EOL> p . contents . value += <NUM_LIT:1> <EOL> assert x . value == <NUM_LIT:7> <EOL> y = c_int ( <NUM_LIT:12> ) <EOL> p . contents = y <EOL> p . contents . value += <NUM_LIT:2> <EOL> assert y . value == <NUM_LIT> <EOL> assert x . value == <NUM_LIT:7> <EOL> pp = pointer ( p ) <EOL> pp . contents . contents = x <EOL> p . contents . value += <NUM_LIT:2> <EOL> assert x . value == <NUM_LIT:9> <EOL> assert isinstance ( p [ <NUM_LIT:0> ] , int ) <EOL> p [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> assert x . value == <NUM_LIT:10> <EOL> z = c_int ( <NUM_LIT> ) <EOL> p [ <NUM_LIT:0> ] = z <EOL> assert x . value == <NUM_LIT> <EOL> z . value = <NUM_LIT> <EOL> assert x . value == <NUM_LIT> <EOL> assert isinstance ( pp [ <NUM_LIT:0> ] , POINTER ( c_int ) ) <EOL> assert pp [ <NUM_LIT:0> ] . contents . value == x . value == <NUM_LIT> <EOL> pp [ <NUM_LIT:0> ] . contents = z <EOL> assert p . contents . value == z . value == <NUM_LIT> <EOL> def test_char_p ( self ) : <EOL> x = c_char_p ( "<STR_LIT>" ) <EOL> assert x . value == "<STR_LIT:hello>" <EOL> x . value = "<STR_LIT>" <EOL> assert x . value == "<STR_LIT>" <EOL> p = pointer ( x ) <EOL> assert p [ <NUM_LIT:0> ] == x . value == "<STR_LIT>" <EOL> p [ <NUM_LIT:0> ] = "<STR_LIT>" <EOL> assert x . value == p . contents . value == p [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> myarray = ( c_char_p * <NUM_LIT:10> ) ( ) <EOL> myarray [ <NUM_LIT:7> ] = "<STR_LIT:hello>" <EOL> assert isinstance ( myarray [ <NUM_LIT:7> ] , str ) <EOL> assert myarray [ <NUM_LIT:7> ] == "<STR_LIT:hello>" <EOL> def test_struct ( self ) : <EOL> class tagpoint ( Structure ) : <EOL> _fields_ = [ ( '<STR_LIT:x>' , c_int ) , <EOL> ( '<STR_LIT:p>' , POINTER ( c_short ) ) ] <EOL> y = c_short ( <NUM_LIT> ) <EOL> z = c_short ( - <NUM_LIT> ) <EOL> s = tagpoint ( ) <EOL> s . p . contents = z <EOL> assert s . p . contents . value == - <NUM_LIT> <EOL> s . p = pointer ( y ) <EOL> assert s . p . contents . value == <NUM_LIT> <EOL> s . p . contents . value = <NUM_LIT> <EOL> assert y . value == <NUM_LIT> <EOL> s = tagpoint ( x = <NUM_LIT:12> ) <EOL> assert s . x == <NUM_LIT:12> <EOL> s = tagpoint ( <NUM_LIT> , p = pointer ( z ) ) <EOL> assert s . x == <NUM_LIT> <EOL> assert s . p . contents . value == - <NUM_LIT> <EOL> def test_ptr_array ( self ) : <EOL> a = ( POINTER ( c_ushort ) * <NUM_LIT:5> ) ( ) <EOL> x = c_ushort ( <NUM_LIT> ) <EOL> y = c_ushort ( <NUM_LIT:1000> ) <EOL> a [ <NUM_LIT:2> ] = pointer ( x ) <EOL> assert a [ <NUM_LIT:2> ] . contents . value == <NUM_LIT> <EOL> a [ <NUM_LIT:2> ] . contents . value += <NUM_LIT:1> <EOL> assert x . value == <NUM_LIT> <EOL> a [ <NUM_LIT:3> ] . contents = y <EOL> assert a [ <NUM_LIT:3> ] . contents . value == <NUM_LIT:1000> <EOL> a [ <NUM_LIT:3> ] . contents . value += <NUM_LIT:1> <EOL> assert y . value == <NUM_LIT> <EOL> def test_void_p ( self ) : <EOL> x = c_int ( <NUM_LIT:12> ) <EOL> p1 = cast ( pointer ( x ) , c_void_p ) <EOL> p2 = cast ( p1 , POINTER ( c_int ) ) <EOL> assert p2 . contents . value == <NUM_LIT:12> <EOL> def test_char_array ( self ) : <EOL> a = ( c_char * <NUM_LIT:3> ) ( ) <EOL> a [ <NUM_LIT:0> ] = '<STR_LIT:x>' <EOL> a [ <NUM_LIT:1> ] = '<STR_LIT:y>' <EOL> assert a . value == '<STR_LIT>' <EOL> a [ <NUM_LIT:2> ] = '<STR_LIT:z>' <EOL> assert a . value == '<STR_LIT>' <EOL> b = create_string_buffer ( <NUM_LIT:3> ) <EOL> assert type ( b ) is type ( a ) <EOL> assert len ( b ) == <NUM_LIT:3> <EOL> b . value = "<STR_LIT>" <EOL> assert b [ <NUM_LIT:0> ] == '<STR_LIT:n>' <EOL> assert b [ <NUM_LIT:1> ] == '<STR_LIT:x>' <EOL> assert b [ <NUM_LIT:2> ] == '<STR_LIT:w>' <EOL> b . value = "<STR_LIT:?>" <EOL> assert b [ <NUM_LIT:0> ] == '<STR_LIT:?>' <EOL> assert b [ <NUM_LIT:1> ] == '<STR_LIT:\x00>' <EOL> assert b [ <NUM_LIT:2> ] == '<STR_LIT:w>' <EOL> class S ( Structure ) : <EOL> _fields_ = [ ( '<STR_LIT:p>' , POINTER ( c_char ) ) ] <EOL> s = S ( ) <EOL> s . p = b <EOL> s . p . contents . value = '<STR_LIT:!>' <EOL> assert b . value == '<STR_LIT:!>' <EOL> assert len ( create_string_buffer ( <NUM_LIT:0> ) ) == <NUM_LIT:0> <EOL> def test_array ( self ) : <EOL> a = ( c_int * <NUM_LIT:10> ) ( ) <EOL> class S ( Structure ) : <EOL> _fields_ = [ ( '<STR_LIT:p>' , POINTER ( c_int ) ) ] <EOL> s = S ( ) <EOL> s . p = a <EOL> s . p . contents . value = <NUM_LIT> <EOL> assert a [ <NUM_LIT:0> ] == <NUM_LIT> <EOL> a = ( c_int * <NUM_LIT:5> ) ( <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ) <EOL> assert list ( a ) == [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> def test_truth_value ( self ) : <EOL> p = POINTER ( c_int ) ( ) <EOL> assert not p <EOL> p . contents = c_int ( <NUM_LIT:12> ) <EOL> assert p <EOL> assert c_int ( <NUM_LIT:12> ) <EOL> assert not c_int ( <NUM_LIT:0> ) <EOL> assert c_int ( - <NUM_LIT:1> ) <EOL> assert not c_byte ( <NUM_LIT:0> ) <EOL> assert not c_char ( '<STR_LIT:\x00>' ) <EOL> assert not c_float ( <NUM_LIT:0.0> ) <EOL> assert not c_double ( <NUM_LIT:0.0> ) <EOL> assert not c_ulonglong ( <NUM_LIT:0> ) <EOL> assert c_ulonglong ( <NUM_LIT:2> L ** <NUM_LIT> ) <EOL> assert c_char_p ( "<STR_LIT:hello>" ) <EOL> assert c_char_p ( "<STR_LIT>" ) <EOL> assert not c_char_p ( None ) <EOL> assert not c_void_p ( ) <EOL> def test_sizeof ( self ) : <EOL> x = create_string_buffer ( <NUM_LIT> ) <EOL> assert sizeof ( x ) == <NUM_LIT> <EOL> x = ( c_int * <NUM_LIT> ) ( ) <EOL> assert sizeof ( x ) == <NUM_LIT> * sizeof ( c_int ) <EOL> def test_convert_pointers ( self ) : <EOL> import conftest <EOL> _ctypes_test = str ( conftest . sofile ) <EOL> dll = CDLL ( _ctypes_test ) <EOL> func = dll . _testfunc_p_p <EOL> func . restype = c_char_p <EOL> func . argtypes = [ c_char_p ] <EOL> assert func ( "<STR_LIT:hello>" ) == "<STR_LIT:hello>" <EOL> assert func ( c_char_p ( "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> assert func ( ( c_char * <NUM_LIT:6> ) ( * "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> assert func ( create_string_buffer ( "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> func . argtypes = [ c_void_p ] <EOL> assert func ( "<STR_LIT:hello>" ) == "<STR_LIT:hello>" <EOL> assert func ( c_char_p ( "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> assert func ( ( c_char * <NUM_LIT:6> ) ( * "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> assert func ( ( c_byte * <NUM_LIT:6> ) ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) == "<STR_LIT:hello>" <EOL> assert func ( create_string_buffer ( "<STR_LIT:hello>" ) ) == "<STR_LIT:hello>" <EOL> def test_varsize_cast ( self ) : <EOL> import struct <EOL> N = struct . calcsize ( "<STR_LIT:l>" ) <EOL> x = c_long ( ) <EOL> p = cast ( pointer ( x ) , POINTER ( c_ubyte * N ) ) <EOL> for i , c in enumerate ( struct . pack ( "<STR_LIT:l>" , <NUM_LIT> ) ) : <EOL> p . contents [ i ] = ord ( c ) <EOL> assert x . value == <NUM_LIT> <EOL> def test_cfunctype_inspection ( self ) : <EOL> T = CFUNCTYPE ( c_int , c_ubyte ) <EOL> assert list ( T ( ) . argtypes ) == [ c_ubyte ] <EOL> assert T ( ) . restype == c_int <EOL> def test_from_param ( self ) : <EOL> assert isinstance ( c_void_p . from_param ( ( c_int * <NUM_LIT:4> ) ( ) ) , c_int * <NUM_LIT:4> ) <EOL> def test_array_mul ( self ) : <EOL> assert c_int * <NUM_LIT:10> == <NUM_LIT:10> * c_int == c_int * <NUM_LIT:10> L == <NUM_LIT:10> L * c_int <EOL> py . test . raises ( TypeError , '<STR_LIT>' ) <EOL> py . test . raises ( TypeError , '<STR_LIT>' ) <EOL> py . test . raises ( TypeError , '<STR_LIT>' ) <EOL> py . test . raises ( TypeError , '<STR_LIT>' ) <EOL> py . test . raises ( TypeError , '<STR_LIT>' ) <EOL> def test_cast_none ( self ) : <EOL> def check ( P ) : <EOL> x = cast ( None , P ) <EOL> assert isinstance ( x , P ) <EOL> assert not x <EOL> check ( c_void_p ) <EOL> check ( c_char_p ) <EOL> check ( POINTER ( c_int ) ) <EOL> check ( POINTER ( c_int * <NUM_LIT:10> ) ) </s>
