io.streams.c: use unique-file

locals-and-roots
Doug Coleman 2016-03-30 16:59:40 -07:00
parent fe7d6ea76e
commit 9e9b7fe367
1 changed files with 38 additions and 29 deletions

View File

@ -1,33 +1,42 @@
USING: tools.test io.files io.files.temp io io.streams.c
io.encodings.ascii strings destructors kernel specialized-arrays
alien.c-types math alien.data ;
USING: alien.c-types alien.data io io.encodings.ascii io.files
io.files.temp io.files.unique io.streams.c kernel locals math
specialized-arrays strings tools.test ;
SPECIALIZED-ARRAY: int
IN: io.streams.c.tests
{ "hello world" } [
"hello world" "test.txt" temp-file ascii set-file-contents
"test.txt" temp-file "rb" fopen <c-reader> stream-contents
>string
] unit-test
! Writing specialized arrays to binary streams
{ } [
"test.txt" temp-file "wb" fopen <c-writer> [
int-array{ 1 2 3 } write
] with-output-stream
] unit-test
{ int-array{ 1 2 3 } } [
"test.txt" temp-file "rb" fopen <c-reader> [
3 4 * read
] with-input-stream
int cast-array
] unit-test
! Writing strings to binary streams should fail
[
"test.txt" temp-file "wb" fopen <c-writer> [
"OMGFAIL" write
] with-output-stream
] must-fail
"io-streams-c-tests-hello-world" ".txt" [| path |
{ "hello world" } [
"hello world" path ascii set-file-contents
path "rb" fopen <c-reader> stream-contents >string
] unit-test
] cleanup-unique-file
! Writing specialized arrays to binary streams
"io-streams-c-tests-int" ".txt" [| path |
{ } [
path "wb" fopen <c-writer> [
int-array{ 1 2 3 } write
] with-output-stream
] unit-test
{ int-array{ 1 2 3 } } [
path "rb" fopen <c-reader> [
3 4 * read
] with-input-stream
int cast-array
] unit-test
] cleanup-unique-file
! Writing strings to binary streams should fail
"test-omgfail" ".txt" [| path |
[
path "wb" fopen <c-writer> [
"OMGFAIL" write
] with-output-stream
] must-fail
] cleanup-unique-file
] with-temp-directory