]> gitweb.factorcode.org Git - factor.git/blob - core/alien/structs/structs-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / core / alien / structs / structs-tests.factor
1 IN: alien.structs.tests
2 USING: alien alien.syntax alien.c-types kernel tools.test
3 sequences system libc words vocabs namespaces layouts ;
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 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 : 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     "help" "help" lookup "help" set
42     [ ] [ \ foox-x "help" get execute ] unit-test
43     [ ] [ \ set-foox-x "help" get execute ] unit-test
44 ] when