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 IN: alien.c-types.tests
8 { 492 } [ { int xyz } heap-size ] unit-test
14 { t } [ pointer: void lookup-c-type void* lookup-c-type = ] unit-test
15 { t } [ pointer: int lookup-c-type void* lookup-c-type = ] unit-test
16 { t } [ pointer: int* lookup-c-type void* lookup-c-type = ] unit-test
17 { f } [ pointer: foo lookup-c-type void* lookup-c-type = ] unit-test
18 { t } [ pointer: foo* lookup-c-type void* lookup-c-type = ] unit-test
20 { t } [ c-string lookup-c-type c-string lookup-c-type = ] unit-test
22 { t } [ foo heap-size int heap-size = ] unit-test
26 { t } [ int lookup-c-type MyInt lookup-c-type = ] unit-test
27 { t } [ void* lookup-c-type pointer: MyInt lookup-c-type = ] unit-test
29 { 32 } [ { int 8 } heap-size ] unit-test
31 { } [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
35 { t } [ pointer: void lookup-c-type pointer: MyChar lookup-c-type = ] unit-test
37 TYPEDEF: { c-string ascii } MyFunkyString
39 { { c-string ascii } } [ MyFunkyString lookup-c-type ] unit-test
41 TYPEDEF: c-string MyString
43 { t } [ c-string lookup-c-type MyString lookup-c-type = ] unit-test
44 { t } [ void* lookup-c-type pointer: MyString lookup-c-type = ] unit-test
46 TYPEDEF: int* MyIntArray
48 { t } [ void* lookup-c-type MyIntArray lookup-c-type = ] unit-test
50 { 0 } [ -10 uchar c-type-clamp ] unit-test
51 { 12 } [ 12 uchar c-type-clamp ] unit-test
52 { -10 } [ -10 char c-type-clamp ] unit-test
53 { 127 } [ 230 char c-type-clamp ] unit-test
54 { t } [ pi dup float c-type-clamp = ] unit-test
58 { t } [ void* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
59 [ opaque lookup-c-type ] [ no-c-type? ] must-fail-with
70 { c-string ascii } c-type-string
71 pointer: foo c-type-string
72 { int 5 } c-type-string
73 pointer: pointer: int c-type-string
74 pointer: MyFunkyString c-type-string
75 pointer: opaque c-type-string
80 IN: alien.c-types.tests
81 FUNCTION: opaque return_opaque ( ) ;
82 " eval( -- ) ] [ no-c-type? ] must-fail-with
85 STRUCT: backward { x forward* } ;
86 STRUCT: forward { x backward* } ;
88 { t } [ forward lookup-c-type struct-c-type? ] unit-test
89 { t } [ backward lookup-c-type struct-c-type? ] unit-test
91 DEFER: struct-redefined
97 USING: alien.c-types classes.struct ;
98 IN: alien.c-types.tests
100 STRUCT: struct-redefined { x int } ;
104 USING: alien.syntax ;
105 IN: alien.c-types.tests
107 C-TYPE: struct-redefined
110 \ struct-redefined class?
114 "IN: alien.c-types.tests
117 TYPEDEF: int type-redefinition-test
118 TYPEDEF: int type-redefinition-test" eval( -- )
120 [ error>> error>> redefine-error? ]
124 "IN: alien.c-types.tests
127 CALLBACK: void cb987 ( )
128 CALLBACK: void cb987 ( )" eval( -- )
130 [ error>> error>> redefine-error? ]
134 "IN: alien.c-types.tests
137 FUNCTION: void func987 ( )
138 FUNCTION: void func987 ( )" eval( -- )
140 [ error>> error>> redefine-error? ]
143 ! generic -> callback
144 "IN: alien.c-types.tests
147 GENERIC: foo-func ( x -- )
150 "IN: alien.c-types.tests
153 CALLBACK: void foo-func ( )
157 "IN: alien.c-types.tests
160 GENERIC: foo-func ( x -- )
163 "IN: alien.c-types.tests
166 TYPEDEF: void* foo-func
169 [ void resolve-typedef ] [ T{ no-c-type f void } = ] must-fail-with