]> gitweb.factorcode.org Git - factor.git/blob - basis/struct-arrays/struct-arrays-tests.factor
Merge branch 'master' into experimental
[factor.git] / basis / struct-arrays / struct-arrays-tests.factor
1 IN: struct-arrays.tests
2 USING: struct-arrays tools.test kernel math sequences
3 alien.syntax alien.c-types destructors libc accessors
4 destructors ;
5
6 C-STRUCT: test-struct
7 { "int" "x" }
8 { "int" "y" } ;
9
10 : make-point ( x y -- struct )
11     "test-struct" <c-object>
12     [ set-test-struct-y ] keep
13     [ set-test-struct-x ] keep ;
14
15 [ 5/4 ] [
16     2 "test-struct" <struct-array>
17     1 2 make-point over set-first
18     3 4 make-point over set-second
19     0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
20 ] unit-test
21
22 [ 5/4 ] [
23     [
24         2 "test-struct" malloc-struct-array
25         dup underlying>> &free drop
26         1 2 make-point over set-first
27         3 4 make-point over set-second
28         0 [ [ test-struct-x ] [ test-struct-y ] bi / + ] reduce
29     ] with-destructors
30 ] unit-test
31
32 [ ] [ ALIEN: 123 10 "test-struct" <direct-struct-array> drop ] unit-test
33
34 [ ] [
35     [
36         10 "test-struct" malloc-struct-array
37         underlying>> &free drop
38     ] with-destructors
39 ] unit-test