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
10 [ 492 ] [ { int xyz } heap-size ] unit-test
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
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
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
35 [ t ] [ c-string c-type c-string c-type = ] unit-test
37 [ t ] [ foo heap-size int heap-size = ] unit-test
41 [ t ] [ int c-type MyInt c-type = ] unit-test
42 [ t ] [ void* c-type pointer: MyInt c-type = ] unit-test
44 [ 32 ] [ { int 8 } heap-size ] unit-test
46 [ ] [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
50 [ t ] [ pointer: void c-type pointer: MyChar c-type = ] unit-test
52 TYPEDEF: { c-string ascii } MyFunkyString
54 [ { c-string ascii } ] [ MyFunkyString c-type ] unit-test
56 TYPEDEF: c-string MyString
58 [ t ] [ c-string c-type MyString c-type = ] unit-test
59 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
61 TYPEDEF: int* MyIntArray
63 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
66 0 B{ 1 2 3 4 } <displaced-alien> <void*>
69 os windows? cpu x86.64? and [
70 [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
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
81 [ t ] [ void* c-type pointer: opaque c-type = ] unit-test
82 [ opaque c-type ] [ no-c-type? ] must-fail-with
86 IN: alien.c-types.tests
87 FUNCTION: opaque return_opaque ( ) ;
88 """ eval( -- ) ] [ no-c-type? ] must-fail-with
91 STRUCT: backward { x forward* } ;
92 STRUCT: forward { x backward* } ;
94 [ t ] [ forward c-type struct-c-type? ] unit-test
95 [ t ] [ backward c-type struct-c-type? ] unit-test
97 DEFER: struct-redefined
103 USING: alien.c-types classes.struct ;
104 IN: alien.c-types.tests
106 STRUCT: struct-redefined { x int } ;
110 USING: alien.syntax ;
111 IN: alien.c-types.tests
113 C-TYPE: struct-redefined
116 \ struct-redefined class?
120 "IN: alien.c-types.tests
123 TYPEDEF: int type-redefinition-test
124 TYPEDEF: int type-redefinition-test" eval( -- )
126 [ error>> error>> redefine-error? ]