1 USING: accessors alien.c-types alien.syntax classes
2 classes.struct compiler.units eval io.encodings.ascii kernel
3 math.constants tools.test ;
4 FROM: alien.c-types => short ;
5 IN: alien.c-types.tests
9 { 492 } [ { int xyz } heap-size ] unit-test
15 { t } [ pointer: void lookup-c-type void* lookup-c-type = ] unit-test
16 { t } [ pointer: int lookup-c-type void* lookup-c-type = ] unit-test
17 { t } [ pointer: int* lookup-c-type void* lookup-c-type = ] unit-test
18 { f } [ pointer: foo lookup-c-type void* lookup-c-type = ] unit-test
19 { t } [ pointer: foo* lookup-c-type void* lookup-c-type = ] unit-test
21 { t } [ c-string lookup-c-type c-string lookup-c-type = ] unit-test
23 { t } [ foo heap-size int heap-size = ] unit-test
27 { t } [ int lookup-c-type MyInt lookup-c-type = ] unit-test
28 { t } [ void* lookup-c-type pointer: MyInt lookup-c-type = ] unit-test
30 { 32 } [ { int 8 } heap-size ] unit-test
32 { } [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
36 { t } [ pointer: void lookup-c-type pointer: MyChar lookup-c-type = ] unit-test
38 TYPEDEF: { c-string ascii } MyFunkyString
40 { { c-string ascii } } [ MyFunkyString lookup-c-type ] unit-test
42 TYPEDEF: c-string MyString
44 { t } [ c-string lookup-c-type MyString lookup-c-type = ] unit-test
45 { t } [ void* lookup-c-type pointer: MyString lookup-c-type = ] unit-test
47 TYPEDEF: int* MyIntArray
49 { t } [ void* lookup-c-type MyIntArray lookup-c-type = ] unit-test
51 { 0 } [ -10 uchar c-type-clamp ] unit-test
52 { 12 } [ 12 uchar c-type-clamp ] unit-test
53 { -10 } [ -10 char c-type-clamp ] unit-test
54 { 127 } [ 230 char c-type-clamp ] unit-test
55 { t } [ pi dup float c-type-clamp = ] unit-test
59 { t } [ void* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
60 [ opaque lookup-c-type ] [ no-c-type? ] must-fail-with
71 { c-string ascii } c-type-string
72 pointer: foo c-type-string
73 { int 5 } c-type-string
74 pointer: pointer: int c-type-string
75 pointer: MyFunkyString c-type-string
76 pointer: opaque c-type-string
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 lookup-c-type struct-c-type? ] unit-test
90 { t } [ backward lookup-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? ]
125 "IN: alien.c-types.tests
128 CALLBACK: void cb987 ( )
129 CALLBACK: void cb987 ( )" eval( -- )
131 [ error>> error>> redefine-error? ]
135 "IN: alien.c-types.tests
138 FUNCTION: void func987 ( )
139 FUNCTION: void func987 ( )" eval( -- )
141 [ error>> error>> redefine-error? ]
144 ! generic -> callback
145 "IN: alien.c-types.tests
148 GENERIC: foo-func ( x -- )
151 "IN: alien.c-types.tests
154 CALLBACK: void foo-func ( )
158 "IN: alien.c-types.tests
161 GENERIC: foo-func ( x -- )
164 "IN: alien.c-types.tests
167 TYPEDEF: void* foo-func