]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/c-types/c-types-tests.factor
Factor source files should not be executable
[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.utf8 math.constants classes.struct classes ;
4 IN: alien.c-types.tests
5
6 CONSTANT: xyz 123
7
8 [ 492 ] [ { int xyz } heap-size ] unit-test
9
10 [ -1 ] [ -1 <char> *char ] unit-test
11 [ -1 ] [ -1 <short> *short ] unit-test
12 [ -1 ] [ -1 <int> *int ] unit-test
13
14 UNION-STRUCT: foo
15     { a int }
16     { b int } ;
17
18 [ f ] [ char  resolve-pointer-type c-type void* c-type eq? ] unit-test
19 [ t ] [ char* resolve-pointer-type c-type void* c-type eq? ] unit-test
20
21 [ t ] [ foo heap-size int heap-size = ] unit-test
22
23 TYPEDEF: int MyInt
24
25 [ t ] [ int   c-type MyInt                      c-type eq? ] unit-test
26 [ t ] [ void* c-type MyInt resolve-pointer-type c-type eq? ] unit-test
27
28 TYPEDEF: char MyChar
29
30 [ t ] [ char  c-type MyChar                      c-type eq? ] unit-test
31 [ f ] [ void* c-type MyChar resolve-pointer-type c-type eq? ] unit-test
32 [ t ] [ char* c-type MyChar resolve-pointer-type c-type eq? ] unit-test
33
34 [ 32 ] [ { int 8 } heap-size ] unit-test
35
36 TYPEDEF: char* MyString
37
38 [ t ] [ char* c-type MyString                      c-type eq? ] unit-test
39 [ t ] [ void* c-type MyString resolve-pointer-type c-type eq? ] unit-test
40
41 TYPEDEF: int* MyIntArray
42
43 [ t ] [ void* c-type MyIntArray c-type eq? ] unit-test
44
45 TYPEDEF: uchar* MyLPBYTE
46
47 [ t ] [ { char* utf8 } c-type MyLPBYTE c-type = ] unit-test
48
49 [
50     0 B{ 1 2 3 4 } <displaced-alien> <void*>
51 ] must-fail
52
53 os windows? cpu x86.64? and [
54     [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
55 ] when
56
57 [ 0 ] [ -10 uchar c-type-clamp ] unit-test
58 [ 12 ] [ 12 uchar c-type-clamp ] unit-test
59 [ -10 ] [ -10 char c-type-clamp ] unit-test
60 [ 127 ] [ 230 char c-type-clamp ] unit-test
61 [ t ] [ pi dup float c-type-clamp = ] unit-test
62
63 C-TYPE: opaque
64
65 [ t ] [ void* c-type opaque resolve-pointer-type c-type eq? ] unit-test
66 [ opaque c-type ] [ no-c-type? ] must-fail-with
67
68 [ """
69     USING: alien.syntax ;
70     IN: alien.c-types.tests
71     FUNCTION: opaque return_opaque ( ) ;
72 """ eval( -- ) ] [ no-c-type? ] must-fail-with
73
74 C-TYPE: forward
75 STRUCT: backward { x forward* } ;
76 STRUCT: forward { x backward* } ;
77
78 [ t ] [ forward c-type struct-c-type? ] unit-test
79 [ t ] [ backward c-type struct-c-type? ] unit-test
80
81 DEFER: struct-redefined
82
83 [ f ]
84 [
85
86     """
87     USING: alien.c-types classes.struct ;
88     IN: alien.c-types.tests
89
90     STRUCT: struct-redefined { x int } ;
91     """ eval( -- )
92
93     """
94     USING: alien.syntax ;
95     IN: alien.c-types.tests
96
97     C-TYPE: struct-redefined
98     """ eval( -- )
99
100     \ struct-redefined class?
101 ] unit-test
102