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 IN: alien.c-types.tests
9 [ 492 ] [ { int xyz } heap-size ] unit-test
11 [ -1 ] [ -1 <char> *char ] unit-test
12 [ -1 ] [ -1 <short> *short ] unit-test
13 [ -1 ] [ -1 <int> *int ] unit-test
19 [ t ] [ pointer: void c-type void* c-type = ] unit-test
20 [ t ] [ pointer: int c-type void* c-type = ] unit-test
21 [ t ] [ pointer: int* c-type void* c-type = ] unit-test
22 [ f ] [ pointer: foo c-type void* c-type = ] unit-test
23 [ t ] [ pointer: foo* c-type void* c-type = ] unit-test
25 [ t ] [ c-string c-type c-string c-type = ] unit-test
27 [ t ] [ foo heap-size int heap-size = ] unit-test
31 [ t ] [ int c-type MyInt c-type = ] unit-test
32 [ t ] [ void* c-type pointer: MyInt c-type = ] unit-test
34 [ 32 ] [ { int 8 } heap-size ] unit-test
38 [ t ] [ pointer: void c-type pointer: MyChar c-type = ] unit-test
40 TYPEDEF: { c-string ascii } MyFunkyString
42 [ { c-string ascii } ] [ MyFunkyString c-type ] unit-test
44 TYPEDEF: c-string MyString
46 [ t ] [ c-string c-type MyString c-type = ] unit-test
47 [ t ] [ void* c-type pointer: MyString c-type = ] unit-test
49 TYPEDEF: int* MyIntArray
51 [ t ] [ void* c-type MyIntArray c-type = ] unit-test
54 0 B{ 1 2 3 4 } <displaced-alien> <void*>
57 os windows? cpu x86.64? and [
58 [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
61 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
62 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
63 [ -10 ] [ -10 char c-type-clamp ] unit-test
64 [ 127 ] [ 230 char c-type-clamp ] unit-test
65 [ t ] [ pi dup float c-type-clamp = ] unit-test
69 [ t ] [ void* c-type pointer: opaque c-type = ] unit-test
70 [ opaque c-type ] [ no-c-type? ] must-fail-with
74 IN: alien.c-types.tests
75 FUNCTION: opaque return_opaque ( ) ;
76 """ eval( -- ) ] [ no-c-type? ] must-fail-with
79 STRUCT: backward { x forward* } ;
80 STRUCT: forward { x backward* } ;
82 [ t ] [ forward c-type struct-c-type? ] unit-test
83 [ t ] [ backward c-type struct-c-type? ] unit-test
85 DEFER: struct-redefined
91 USING: alien.c-types classes.struct ;
92 IN: alien.c-types.tests
94 STRUCT: struct-redefined { x int } ;
99 IN: alien.c-types.tests
101 C-TYPE: struct-redefined
104 \ struct-redefined class?
108 "IN: alien.c-types.tests
111 TYPEDEF: int type-redefinition-test
112 TYPEDEF: int type-redefinition-test" eval( -- )
114 [ error>> error>> redefine-error? ]