]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/c-types/c-types-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / alien / c-types / c-types-tests.factor
1 USING: alien alien.syntax alien.c-types kernel tools.test
2 sequences system libc alien.strings io.encodings.utf8
3 math.constants ;
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 C-UNION: foo
15     "int"
16     "int" ;
17
18 [ f ] [ "char*" c-type "void*" c-type eq? ] unit-test
19 [ t ] [ "char**" 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*" 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*" c-type eq? ] unit-test
32 [ t ] [ "char*" c-type "MyChar*" 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*" 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