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 FROM: alien.c-types => short ;
6 IN: alien.c-types.tests
10 [ 492 ] [ { int xyz } heap-size ] unit-test
16 [ t ] [ pointer: void c-type void* c-type = ] unit-test
17 [ t ] [ pointer: int c-type void* c-type = ] unit-test
18 [ t ] [ pointer: int* c-type void* c-type = ] unit-test
19 [ f ] [ pointer: foo c-type void* c-type = ] unit-test
20 [ t ] [ pointer: foo* c-type void* c-type = ] unit-test
22 [ t ] [ c-string c-type c-string c-type = ] unit-test
24 [ t ] [ foo heap-size int heap-size = ] unit-test
28 [ t ] [ int c-type MyInt c-type = ] unit-test
29 [ t ] [ void* c-type pointer: MyInt c-type = ] unit-test
31 [ 32 ] [ { int 8 } heap-size ] unit-test
33 [ ] [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
37 [ t ] [ pointer: void c-type pointer: MyChar c-type = ] unit-test
39 TYPEDEF: { c-string ascii } MyFunkyString
41 [ { c-string ascii } ] [ MyFunkyString c-type ] unit-test
43 TYPEDEF: c-string MyString
45 [ t ] [ c-string c-type MyString c-type = ] unit-test
46 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
48 TYPEDEF: int* MyIntArray
50 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
52 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
53 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
54 [ -10 ] [ -10 char c-type-clamp ] unit-test
55 [ 127 ] [ 230 char c-type-clamp ] unit-test
56 [ t ] [ pi dup float c-type-clamp = ] unit-test
60 [ t ] [ void* c-type pointer: opaque c-type = ] unit-test
61 [ opaque c-type ] [ no-c-type? ] must-fail-with
65 IN: alien.c-types.tests
66 FUNCTION: opaque return_opaque ( ) ;
67 """ eval( -- ) ] [ no-c-type? ] must-fail-with
70 STRUCT: backward { x forward* } ;
71 STRUCT: forward { x backward* } ;
73 [ t ] [ forward c-type struct-c-type? ] unit-test
74 [ t ] [ backward c-type struct-c-type? ] unit-test
76 DEFER: struct-redefined
82 USING: alien.c-types classes.struct ;
83 IN: alien.c-types.tests
85 STRUCT: struct-redefined { x int } ;
90 IN: alien.c-types.tests
92 C-TYPE: struct-redefined
95 \ struct-redefined class?
99 "IN: alien.c-types.tests
102 TYPEDEF: int type-redefinition-test
103 TYPEDEF: int type-redefinition-test" eval( -- )
105 [ error>> error>> redefine-error? ]