]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/c-types/c-types-tests.factor
Remove many uses of <int> and *int etc
[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 [ -1 ] [ -1 char <ref> char deref ] unit-test
13 [ -1 ] [ -1 short <ref> short deref ] unit-test
14 [ -1 ] [ -1 int <ref> int deref ] unit-test
15
16 ! I don't care if this throws an error or works, but at least
17 ! it should be consistent between platforms
18 [ -1 ] [ -1.0 int <ref> int deref ] unit-test
19 [ -1 ] [ -1.0 long <ref> long deref ] unit-test
20 [ -1 ] [ -1.0 longlong <ref> longlong deref ] unit-test
21 [ 1 ] [ 1.0 uint <ref> uint deref ] unit-test
22 [ 1 ] [ 1.0 ulong <ref> ulong deref ] unit-test
23 [ 1 ] [ 1.0 ulonglong <ref> ulonglong deref ] unit-test
24
25 UNION-STRUCT: foo
26     { a int }
27     { b int } ;
28
29 [ t ] [ pointer: void c-type void* c-type = ] unit-test
30 [ t ] [ pointer: int  c-type void* c-type = ] unit-test
31 [ t ] [ pointer: int* c-type void* c-type = ] unit-test
32 [ f ] [ pointer: foo  c-type void* c-type = ] unit-test
33 [ t ] [ pointer: foo* c-type void* c-type = ] unit-test
34
35 [ t ] [ c-string c-type c-string c-type = ] unit-test
36
37 [ t ] [ foo heap-size int heap-size = ] unit-test
38
39 TYPEDEF: int MyInt
40
41 [ t ] [ int   c-type          MyInt c-type = ] unit-test
42 [ t ] [ void* c-type pointer: MyInt c-type = ] unit-test
43
44 [ 32 ] [ { int 8 } heap-size ] unit-test
45
46 [ ] [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
47
48 TYPEDEF: char MyChar
49
50 [ t ] [ pointer: void c-type pointer: MyChar c-type = ] unit-test
51
52 TYPEDEF: { c-string ascii } MyFunkyString
53
54 [ { c-string ascii } ] [ MyFunkyString c-type ] unit-test
55
56 TYPEDEF: c-string MyString
57
58 [ t ] [ c-string c-type MyString          c-type = ] unit-test
59 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
60
61 TYPEDEF: int* MyIntArray
62
63 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
64
65 [
66     0 B{ 1 2 3 4 } <displaced-alien> <void*>
67 ] must-fail
68
69 os windows? cpu x86.64? and [
70     [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
71 ] when
72
73 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
74 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
75 [ -10 ] [ -10 char c-type-clamp ] unit-test
76 [ 127 ] [ 230 char c-type-clamp ] unit-test
77 [ t ] [ pi dup float c-type-clamp = ] unit-test
78
79 C-TYPE: opaque
80
81 [ t ] [ void* c-type pointer: opaque c-type = ] unit-test
82 [ opaque c-type ] [ no-c-type? ] must-fail-with
83
84 [ """
85     USING: alien.syntax ;
86     IN: alien.c-types.tests
87     FUNCTION: opaque return_opaque ( ) ;
88 """ eval( -- ) ] [ no-c-type? ] must-fail-with
89
90 C-TYPE: forward
91 STRUCT: backward { x forward* } ;
92 STRUCT: forward { x backward* } ;
93
94 [ t ] [ forward c-type struct-c-type? ] unit-test
95 [ t ] [ backward c-type struct-c-type? ] unit-test
96
97 DEFER: struct-redefined
98
99 [ f ]
100 [
101
102     """
103     USING: alien.c-types classes.struct ;
104     IN: alien.c-types.tests
105
106     STRUCT: struct-redefined { x int } ;
107     """ eval( -- )
108
109     """
110     USING: alien.syntax ;
111     IN: alien.c-types.tests
112
113     C-TYPE: struct-redefined
114     """ eval( -- )
115
116     \ struct-redefined class?
117 ] unit-test
118
119 [
120     "IN: alien.c-types.tests
121     USE: alien.syntax
122     USE: alien.c-types
123     TYPEDEF: int type-redefinition-test
124     TYPEDEF: int type-redefinition-test" eval( -- )
125 ]
126 [ error>> error>> redefine-error? ]
127 must-fail-with