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
64 IN: alien.c-types.tests
65 FUNCTION: opaque return_opaque ( ) ;
66 " eval( -- ) ] [ no-c-type? ] must-fail-with
69 STRUCT: backward { x forward* } ;
70 STRUCT: forward { x backward* } ;
72 { t } [ forward lookup-c-type struct-c-type? ] unit-test
73 { t } [ backward lookup-c-type struct-c-type? ] unit-test
75 DEFER: struct-redefined
81 USING: alien.c-types classes.struct ;
82 IN: alien.c-types.tests
84 STRUCT: struct-redefined { x int } ;
89 IN: alien.c-types.tests
91 C-TYPE: struct-redefined
94 \ struct-redefined class?
98 "IN: alien.c-types.tests
101 TYPEDEF: int type-redefinition-test
102 TYPEDEF: int type-redefinition-test" eval( -- )
104 [ error>> error>> redefine-error? ]