]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/c-types/c-types-tests.factor
basis: Cleaning up tests using lists and IN: forms.
[factor.git] / basis / alien / c-types / c-types-tests.factor
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
6
7 CONSTANT: xyz 123
8
9 { 492 } [ { int xyz } heap-size ] unit-test
10
11 UNION-STRUCT: foo
12     { a int }
13     { b int } ;
14
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
20
21 { t } [ c-string lookup-c-type c-string lookup-c-type = ] unit-test
22
23 { t } [ foo heap-size int heap-size = ] unit-test
24
25 TYPEDEF: int MyInt
26
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
29
30 { 32 } [ { int 8 } heap-size ] unit-test
31
32 { } [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
33
34 TYPEDEF: char MyChar
35
36 { t } [ pointer: void lookup-c-type pointer: MyChar lookup-c-type = ] unit-test
37
38 TYPEDEF: { c-string ascii } MyFunkyString
39
40 { { c-string ascii } } [ MyFunkyString lookup-c-type ] unit-test
41
42 TYPEDEF: c-string MyString
43
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
46
47 TYPEDEF: int* MyIntArray
48
49 { t } [ void* lookup-c-type MyIntArray lookup-c-type = ] unit-test
50
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
56
57 C-TYPE: opaque
58
59 { t } [ void* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
60 [ opaque lookup-c-type ] [ no-c-type? ] must-fail-with
61
62 [ "
63     USING: alien.syntax ;
64     IN: alien.c-types.tests
65     FUNCTION: opaque return_opaque ( ) ;
66 " eval( -- ) ] [ no-c-type? ] must-fail-with
67
68 C-TYPE: forward
69 STRUCT: backward { x forward* } ;
70 STRUCT: forward { x backward* } ;
71
72 { t } [ forward lookup-c-type struct-c-type? ] unit-test
73 { t } [ backward lookup-c-type struct-c-type? ] unit-test
74
75 DEFER: struct-redefined
76
77 { f }
78 [
79
80     "
81     USING: alien.c-types classes.struct ;
82     IN: alien.c-types.tests
83
84     STRUCT: struct-redefined { x int } ;
85     " eval( -- )
86
87     "
88     USING: alien.syntax ;
89     IN: alien.c-types.tests
90
91     C-TYPE: struct-redefined
92     " eval( -- )
93
94     \ struct-redefined class?
95 ] unit-test
96
97 [
98     "IN: alien.c-types.tests
99     USE: alien.syntax
100     USE: alien.c-types
101     TYPEDEF: int type-redefinition-test
102     TYPEDEF: int type-redefinition-test" eval( -- )
103 ]
104 [ error>> error>> redefine-error? ]
105 must-fail-with