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