]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/structs/structs-tests.factor
3f84377d5c8164a22e2ac4518b826d8620832132
[factor.git] / basis / alien / structs / structs-tests.factor
1 USING: alien alien.syntax alien.c-types kernel tools.test
2 sequences system libc words vocabs namespaces layouts ;
3 IN: alien.structs.tests
4
5 C-STRUCT: bar
6     { "int" "x" }
7     { { "int" 8 } "y" } ;
8
9 [ 36 ] [ "bar" heap-size ] unit-test
10 [ t ] [ \ <displaced-alien> "bar" c-type-getter memq? ] unit-test
11
12 C-STRUCT: align-test
13     { "int" "x" }
14     { "double" "y" } ;
15
16 os winnt? cpu x86? and [
17     [ 16 ] [ "align-test" heap-size ] unit-test
18     
19     cell 4 = [
20         C-STRUCT: one
21         { "long" "a" } { "double" "b" } { "int" "c" } ;
22     
23         [ 24 ] [ "one" heap-size ] unit-test
24     ] when
25 ] when
26
27 CONSTANT: MAX_FOOS 30
28
29 C-STRUCT: foox
30     { { "int" MAX_FOOS } "x" } ;
31
32 [ 120 ] [ "foox" heap-size ] unit-test
33
34 C-UNION: barx
35     { "int" MAX_FOOS }
36     "float" ;
37
38 [ 120 ] [ "barx" heap-size ] unit-test
39
40 "help" vocab [
41     "print-topic" "help" lookup "help" set
42     [ ] [ \ foox-x "help" get execute ] unit-test
43     [ ] [ \ set-foox-x "help" get execute ] unit-test
44 ] when
45
46 C-STRUCT: nested
47     { "int" "x" } ;
48
49 C-STRUCT: nested-2
50     { "nested" "y" } ;
51
52 [ 4 ] [
53     "nested-2" <c-object>
54     "nested" <c-object>
55     4 over set-nested-x
56     over set-nested-2-y
57     nested-2-y
58     nested-x
59 ] unit-test