]> gitweb.factorcode.org Git - factor.git/blob - basis/io/ports/ports-tests.factor
factor: second stab at [ ] [ ] unit-test -> { } [ ] unit-test
[factor.git] / basis / io / ports / ports-tests.factor
1 USING: accessors alien.c-types alien.data destructors io
2 io.directories io.encodings.ascii io.encodings.binary
3 io.encodings.string io.encodings.utf8 io.files io.files.temp
4 io.pipes io.sockets kernel libc math namespaces sequences
5 tools.test ;
6 IN: io.ports.tests
7
8 ! Make sure that writing malloced storage to a file works, and
9 ! also make sure that writes larger than the buffer size work
10
11 { } [
12     "test.txt" temp-file 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     "test.txt" temp-file binary [
23         100,000 4 * read int cast-array 100,000 iota sequence=
24     ] with-file-reader
25 ] unit-test
26
27 { } [ "test.txt" temp-file delete-file ] unit-test
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