1 USING: alien alien.syntax alien.c-types alien.parser
2 eval kernel tools.test sequences system libc alien.strings
3 io.encodings.ascii 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 [ t ] [ pointer: void c-type void* c-type = ] unit-test
20 [ t ] [ pointer: int c-type void* c-type = ] unit-test
21 [ t ] [ pointer: int* c-type void* c-type = ] unit-test
22 [ f ] [ pointer: foo c-type void* c-type = ] unit-test
23 [ t ] [ pointer: foo* c-type void* c-type = ] unit-test
25 [ t ] [ pointer: char c-type char* c-type = ] unit-test
27 [ t ] [ foo heap-size int heap-size = ] unit-test
31 [ t ] [ int c-type MyInt c-type = ] unit-test
32 [ t ] [ void* c-type pointer: MyInt c-type = ] unit-test
34 [ 32 ] [ { int 8 } heap-size ] unit-test
38 [ t ] [ pointer: char c-type pointer: MyChar c-type = ] unit-test
39 [ t ] [ char* c-type pointer: MyChar c-type = ] unit-test
41 TYPEDEF: char MyFunkyChar
42 { char* ascii } pointer: MyFunkyChar typedef
44 [ f ] [ pointer: char c-type pointer: MyFunkyChar c-type = ] unit-test
45 [ { char* ascii } ] [ pointer: MyFunkyChar c-type ] unit-test
47 TYPEDEF: char* MyString
49 [ t ] [ char* c-type MyString c-type = ] unit-test
50 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
52 TYPEDEF: int* MyIntArray
54 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
56 TYPEDEF: char* MyLPBYTE
58 [ t ] [ { char* utf8 } c-type MyLPBYTE c-type = ] unit-test
61 0 B{ 1 2 3 4 } <displaced-alien> <void*>
64 os windows? cpu x86.64? and [
65 [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
68 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
69 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
70 [ -10 ] [ -10 char c-type-clamp ] unit-test
71 [ 127 ] [ 230 char c-type-clamp ] unit-test
72 [ t ] [ pi dup float c-type-clamp = ] unit-test
76 [ t ] [ void* c-type pointer: opaque c-type = ] unit-test
77 [ opaque c-type ] [ no-c-type? ] must-fail-with
81 IN: alien.c-types.tests
82 FUNCTION: opaque return_opaque ( ) ;
83 """ eval( -- ) ] [ no-c-type? ] must-fail-with
86 STRUCT: backward { x forward* } ;
87 STRUCT: forward { x backward* } ;
89 [ t ] [ forward c-type struct-c-type? ] unit-test
90 [ t ] [ backward c-type struct-c-type? ] unit-test
92 DEFER: struct-redefined
98 USING: alien.c-types classes.struct ;
99 IN: alien.c-types.tests
101 STRUCT: struct-redefined { x int } ;
105 USING: alien.syntax ;
106 IN: alien.c-types.tests
108 C-TYPE: struct-redefined
111 \ struct-redefined class?
115 "IN: alien.c-types.tests
118 TYPEDEF: int type-redefinition-test
119 TYPEDEF: int type-redefinition-test" eval( -- )
121 [ error>> error>> redefine-error? ]