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 lookup-c-type void* lookup-c-type = ] unit-test
17 [ t ] [ pointer: int lookup-c-type void* lookup-c-type = ] unit-test
18 [ t ] [ pointer: int* lookup-c-type void* lookup-c-type = ] unit-test
19 [ f ] [ pointer: foo lookup-c-type void* lookup-c-type = ] unit-test
20 [ t ] [ pointer: foo* lookup-c-type void* lookup-c-type = ] unit-test
22 [ t ] [ c-string lookup-c-type c-string lookup-c-type = ] unit-test
24 [ t ] [ foo heap-size int heap-size = ] unit-test
28 [ t ] [ int lookup-c-type MyInt lookup-c-type = ] unit-test
29 [ t ] [ void* lookup-c-type pointer: MyInt lookup-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 lookup-c-type pointer: MyChar lookup-c-type = ] unit-test
39 TYPEDEF: { c-string ascii } MyFunkyString
41 [ { c-string ascii } ] [ MyFunkyString lookup-c-type ] unit-test
43 TYPEDEF: c-string MyString
45 [ t ] [ c-string lookup-c-type MyString lookup-c-type = ] unit-test
46 [ t ] [ void* lookup-c-type pointer: MyString lookup-c-type = ] unit-test
48 TYPEDEF: int* MyIntArray
50 [ t ] [ void* lookup-c-type MyIntArray lookup-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* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
61 [ opaque lookup-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 lookup-c-type struct-c-type? ] unit-test
74 [ t ] [ backward lookup-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? ]