]> gitweb.factorcode.org Git - factor.git/blob - basis/io/ports/ports-tests.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / basis / io / ports / ports-tests.factor
1 USING: accessors alien.c-types alien.data destructors io
2 io.encodings.ascii io.encodings.binary io.encodings.string
3 io.encodings.utf8 io.files io.pipes io.sockets kernel libc
4 locals math namespaces sequences tools.test ;
5
6 ! Make sure that writing malloced storage to a file works, and
7 ! also make sure that writes larger than the buffer size work
8
9 [| path |
10
11     { } [
12         path binary [
13             [
14                 100,000 <iota>
15                 0
16                 100,000 int malloc-array &free [ copy ] keep write
17             ] with-destructors
18         ] with-file-writer
19     ] unit-test
20
21     { t } [
22         path binary [
23             100,000 4 * read int cast-array 100,000 <iota> sequence=
24         ] with-file-reader
25     ] unit-test
26
27 ] with-test-file
28
29 ! Getting the stream-element-type of an output-port was broken
30 { +byte+ } [ binary <pipe> [ stream-element-type ] with-disposal ] unit-test
31 { +byte+ } [ binary <pipe> [ out>> stream-element-type ] with-disposal ] unit-test
32 { +character+ } [ ascii <pipe> [ stream-element-type ] with-disposal ] unit-test
33 { +character+ } [ ascii <pipe> [ out>> stream-element-type ] with-disposal ] unit-test
34
35 ! Issue #1256 regression test
36 ! Port length would be zero before data is received
37 { f } [
38     "google.com" 80 <inet> binary [
39         "GET /\n" utf8 encode write flush
40         input-stream get stream-contents
41     ] with-client empty?
42 ] unit-test