]> gitweb.factorcode.org Git - factor.git/blob - basis/io/ports/ports-tests.factor
7d8c799017c7dfaf5c7a3b21a2ca2edfdb6fbf04
[factor.git] / basis / io / ports / ports-tests.factor
1 USING: destructors io io.encodings.binary io.files io.directories
2 io.files.temp io.ports kernel sequences math
3 specialized-arrays.instances.alien.c-types.int tools.test
4 specialized-arrays alien.c-types classes.struct alien ;
5 IN: io.ports.tests
6
7 ! Make sure that writing malloced storage to a file works, and
8 ! also make sure that writes larger than the buffer size work
9
10 [ ] [
11     "test.txt" temp-file binary [
12         100,000 iota
13         0
14         100,000 malloc-int-array &dispose [ copy ] keep write
15     ] with-file-writer
16 ] unit-test
17
18 [ t ] [
19     "test.txt" temp-file binary [
20         100,000 4 * read byte-array>int-array 100,000 iota sequence=
21     ] with-file-reader
22 ] unit-test
23
24 USE: multiline
25 /*
26 [ ] [
27     BV{ 0 1 2 } "test.txt" temp-file binary set-file-contents
28 ] unit-test
29
30 [ t ] [
31     "test.txt" temp-file binary file-contents
32     B{ 0 1 2 } =
33 ] unit-test
34
35 STRUCT: pt { x uint } { y uint } ;
36 SPECIALIZED-ARRAY: pt
37
38 CONSTANT: pt-array-1
39     pt-array{ S{ pt f 1 1 } S{ pt f 2 2 } S{ pt f 3 3 } }
40
41 [ ] [
42     pt-array-1
43     "test.txt" temp-file binary set-file-contents
44 ] unit-test
45
46 [ t ] [
47     "test.txt" temp-file binary file-contents
48     pt-array-1 >c-ptr sequence=
49 ] unit-test
50
51 [ ] [
52     pt-array-1 rest-slice 
53     "test.txt" temp-file binary set-file-contents
54 ] unit-test
55
56 [ t ] [
57     "test.txt" temp-file binary file-contents
58     pt-array-1 rest-slice >c-ptr sequence=
59 ] unit-test
60
61 */
62
63 [ ] [ "test.txt" temp-file delete-file ] unit-test