1 USING: alien alien.syntax alien.c-types alien.parser
2 eval kernel tools.test sequences system libc alien.strings
3 io.encodings.utf8 math.constants classes.struct classes
4 accessors compiler.units ;
5 IN: alien.c-types.tests
9 [ 492 ] [ { int xyz } heap-size ] unit-test
11 [ -1 ] [ -1 <char> *char ] unit-test
12 [ -1 ] [ -1 <short> *short ] unit-test
13 [ -1 ] [ -1 <int> *int ] unit-test
19 [ f ] [ char resolve-pointer-type c-type void* c-type eq? ] unit-test
20 [ t ] [ char* resolve-pointer-type c-type void* c-type eq? ] unit-test
22 [ t ] [ foo heap-size int heap-size = ] unit-test
26 [ t ] [ int c-type MyInt c-type eq? ] unit-test
27 [ t ] [ void* c-type MyInt resolve-pointer-type c-type eq? ] unit-test
31 [ t ] [ char c-type MyChar c-type eq? ] unit-test
32 [ f ] [ void* c-type MyChar resolve-pointer-type c-type eq? ] unit-test
33 [ t ] [ char* c-type MyChar resolve-pointer-type c-type eq? ] unit-test
35 [ 32 ] [ { int 8 } heap-size ] unit-test
37 TYPEDEF: char* MyString
39 [ t ] [ char* c-type MyString c-type eq? ] unit-test
40 [ t ] [ void* c-type MyString resolve-pointer-type c-type eq? ] unit-test
42 TYPEDEF: int* MyIntArray
44 [ t ] [ void* c-type MyIntArray c-type eq? ] unit-test
46 TYPEDEF: uchar* MyLPBYTE
48 [ t ] [ { char* utf8 } c-type MyLPBYTE c-type = ] unit-test
51 0 B{ 1 2 3 4 } <displaced-alien> <void*>
54 os windows? cpu x86.64? and [
55 [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
58 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
59 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
60 [ -10 ] [ -10 char c-type-clamp ] unit-test
61 [ 127 ] [ 230 char c-type-clamp ] unit-test
62 [ t ] [ pi dup float c-type-clamp = ] unit-test
66 [ t ] [ void* c-type opaque resolve-pointer-type c-type eq? ] unit-test
67 [ opaque c-type ] [ no-c-type? ] must-fail-with
71 IN: alien.c-types.tests
72 FUNCTION: opaque return_opaque ( ) ;
73 """ eval( -- ) ] [ no-c-type? ] must-fail-with
76 STRUCT: backward { x forward* } ;
77 STRUCT: forward { x backward* } ;
79 [ t ] [ forward c-type struct-c-type? ] unit-test
80 [ t ] [ backward c-type struct-c-type? ] unit-test
82 DEFER: struct-redefined
88 USING: alien.c-types classes.struct ;
89 IN: alien.c-types.tests
91 STRUCT: struct-redefined { x int } ;
96 IN: alien.c-types.tests
98 C-TYPE: struct-redefined
101 \ struct-redefined class?
105 "IN: alien.c-types.tests
108 TYPEDEF: int type-redefinition-test
109 TYPEDEF: int type-redefinition-test" eval( -- )
111 [ error>> error>> redefine-error? ]