]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/c/c-tests.factor
specialized-arrays: performed some cleanup.
[factor.git] / core / io / streams / c / c-tests.factor
1 USING: tools.test io.files io.files.temp io io.streams.c
2 io.encodings.ascii strings destructors kernel specialized-arrays
3 alien.c-types math alien.data ;
4 SPECIALIZED-ARRAY: int
5 IN: io.streams.c.tests
6
7 [ "hello world" ] [
8     "hello world" "test.txt" temp-file ascii set-file-contents
9
10     "test.txt" temp-file "rb" fopen <c-reader> stream-contents
11     >string
12 ] unit-test
13
14 [ 0 ]
15 [ "test.txt" temp-file "rb" fopen <c-reader> [ stream-tell ] [ dispose ] bi ] unit-test
16
17 [ 3 ] [
18     "test.txt" temp-file "rb" fopen <c-reader>
19     3 over stream-read drop
20     [ stream-tell ] [ dispose ] bi
21 ] unit-test
22
23 ! Writing specialized arrays to binary streams
24 [ ] [
25     "test.txt" temp-file "wb" fopen <c-writer> [
26         int-array{ 1 2 3 } write
27     ] with-output-stream
28 ] unit-test
29
30 [ int-array{ 1 2 3 } ] [
31     "test.txt" temp-file "rb" fopen <c-reader> [
32         3 4 * read
33     ] with-input-stream
34     int cast-array
35 ] unit-test
36
37 ! Writing strings to binary streams should fail
38 [
39     "test.txt" temp-file "wb" fopen <c-writer> [
40         "OMGFAIL" write
41     ] with-output-stream
42 ] must-fail