]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/c-types/c-types-tests.factor
Move <ref>, deref and little-endian? from alien.c-types to alien.data, remove <c...
[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 c-type void* c-type = ] unit-test
17 [ t ] [ pointer: int  c-type void* c-type = ] unit-test
18 [ t ] [ pointer: int* c-type void* c-type = ] unit-test
19 [ f ] [ pointer: foo  c-type void* c-type = ] unit-test
20 [ t ] [ pointer: foo* c-type void* c-type = ] unit-test
21
22 [ t ] [ c-string c-type c-string c-type = ] unit-test
23
24 [ t ] [ foo heap-size int heap-size = ] unit-test
25
26 TYPEDEF: int MyInt
27
28 [ t ] [ int   c-type          MyInt c-type = ] unit-test
29 [ t ] [ void* c-type pointer: MyInt 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 c-type pointer: MyChar c-type = ] unit-test
38
39 TYPEDEF: { c-string ascii } MyFunkyString
40
41 [ { c-string ascii } ] [ MyFunkyString c-type ] unit-test
42
43 TYPEDEF: c-string MyString
44
45 [ t ] [ c-string c-type MyString          c-type = ] unit-test
46 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
47
48 TYPEDEF: int* MyIntArray
49
50 [ t ] [ void* c-type MyIntArray 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* c-type pointer: opaque c-type = ] unit-test
61 [ opaque 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 c-type struct-c-type? ] unit-test
74 [ t ] [ backward 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