1 USING: continuations io.sockets io.sockets.private sequences math
2 tools.test namespaces accessors kernel destructors calendar io.timeouts
3 io.encodings.utf8 io concurrency.promises threads
4 io.streams.string present system ;
8 [ T{ local f "/tmp/foo" } ] [ "/tmp/foo" <local> ] unit-test
11 [ T{ inet4 f f 0 } ] [ f 0 <inet4> ] unit-test
12 [ T{ inet6 f f 0 1 } ] [ f 1 <inet6> ] unit-test
14 [ T{ inet f "google.com" f } ] [ "google.com" f <inet> ] unit-test
16 [ T{ inet f "google.com" 0 } ] [ "google.com" 0 <inet> ] unit-test
17 [ T{ inet f "google.com" 80 } ] [ "google.com" 0 <inet> 80 with-port ] unit-test
18 [ T{ inet4 f "8.8.8.8" 0 } ] [ "8.8.8.8" 0 <inet4> ] unit-test
19 [ T{ inet4 f "8.8.8.8" 53 } ] [ "8.8.8.8" 0 <inet4> 53 with-port ] unit-test
20 [ T{ inet6 f "5:5:5:5:6:6:6:6" 0 12 } ] [ "5:5:5:5:6:6:6:6" 0 <inet6> 12 with-port ] unit-test
21 [ T{ inet6 f "fe80::1" 1 80 } ] [ T{ ipv6 f "fe80::1" 1 } 80 with-port ] unit-test
23 : test-sockaddr ( addrspec -- )
24 [ dup make-sockaddr ] keep parse-sockaddr assert= ;
26 [ ] [ T{ inet4 f "8.8.8.8" 53 } test-sockaddr ] unit-test
27 [ ] [ T{ inet6 f "5:5:5:5:6:6:6:6" 0 12 } test-sockaddr ] unit-test
28 [ ] [ T{ inet6 f "fe80:0:0:0:0:0:0:1" 1 80 } test-sockaddr ] unit-test
30 [ T{ inet f "google.com" 80 } ] [ "google.com" 80 with-port ] unit-test
33 [ "google.com" f <inet4> ] must-fail
34 [ "a.b.c.d" f <inet4> ] must-fail
35 [ "google.com" f <inet6> ] must-fail
36 [ "a.b.c.d" f <inet6> ] must-fail
38 ! Test present on addrspecs
39 [ "4.4.4.4:12" ] [ "4.4.4.4" 12 <inet4> present ] unit-test
40 [ "::1:12" ] [ "::1" 12 <inet6> present ] unit-test
41 [ "fe80::1%1:12" ] [ "fe80::1" 1 12 inet6 boa present ] unit-test
44 [ "1.2.3.4" T{ inet4 } inet-pton ] unit-test
47 [ B{ 1 2 3 4 } T{ inet4 } inet-ntop ] unit-test
50 [ B{ 255 255 255 255 } T{ inet4 } inet-ntop ] unit-test
52 [ B{ 255 255 255 255 } ]
53 [ "255.255.255.255" T{ inet4 } inet-pton ] unit-test
55 [ B{ 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 } ]
56 [ "1:2:3:4:5:6:7:8" T{ inet6 } inet-pton ] unit-test
59 [ B{ 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 } T{ inet6 } inet-ntop ] unit-test
61 [ B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } ]
62 [ "::" T{ inet6 } inet-pton ] unit-test
65 [ B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } T{ inet6 } inet-ntop ] unit-test
67 [ B{ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } ]
68 [ "1::" T{ inet6 } inet-pton ] unit-test
70 [ B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } ]
71 [ "::1" T{ inet6 } inet-pton ] unit-test
73 [ B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 } ]
74 [ "::100" T{ inet6 } inet-pton ] unit-test
76 [ B{ 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 } ]
77 [ "1::2" T{ inet6 } inet-pton ] unit-test
79 [ B{ 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 3 } ]
80 [ "1::2:3" T{ inet6 } inet-pton ] unit-test
82 [ B{ 0 1 0 2 0 0 0 0 0 0 0 0 0 3 0 4 } ]
83 [ "1:2::3:4" T{ inet6 } inet-pton ] unit-test
86 [ B{ 0 1 0 2 0 0 0 0 0 0 0 0 0 3 0 4 } T{ inet6 } inet-ntop ] unit-test
88 [ B{ 0 0 0 0 0 0 0 0 0 127 0 0 0 0 0 1 } ]
89 [ "::127.0.0.1" T{ inet6 } inet-pton ] unit-test
91 [ B{ 0 2 0 0 0 0 0 9 0 127 0 0 0 0 0 1 } ]
92 [ "2::9:127.0.0.1" T{ inet6 } inet-pton ] unit-test
94 [ "2001:6f8:37a:5:0:0:0:1" ]
95 [ "2001:6f8:37a:5::1" T{ inet6 } [ inet-pton ] [ inet-ntop ] bi ] unit-test
98 "localhost" 80 <inet> resolve-host
100 [ [ [ inet4? ] [ inet6? ] bi or ] all? ] bi
104 "localhost" resolve-host
106 [ [ [ ipv4? ] [ ipv6? ] bi or ] all? ] bi
112 [ [ [ ipv4? ] [ ipv6? ] bi or ] all? ] bi
116 f 0 <inet> resolve-host
118 [ [ [ ipv4? ] [ ipv6? ] bi or ] all? ] bi
122 [ ] [ "127.0.0.1" 0 <inet4> <datagram> "datagram1" set ] unit-test
123 [ ] [ "datagram1" get addr>> "addr1" set ] unit-test
124 [ f ] [ "addr1" get port>> 0 = ] unit-test
126 [ ] [ "127.0.0.1" 0 <inet4> <datagram> "datagram2" set ] unit-test
127 [ ] [ "datagram2" get addr>> "addr2" set ] unit-test
128 [ f ] [ "addr2" get port>> 0 = ] unit-test
130 [ ] [ B{ 1 2 3 4 } "addr2" get "datagram1" get send ] unit-test
131 [ B{ 1 2 3 4 } ] [ "datagram2" get receive "from" set ] unit-test
132 [ ] [ B{ 4 3 2 1 } "from" get "datagram2" get send ] unit-test
133 [ B{ 4 3 2 1 } t ] [ "datagram1" get receive "addr2" get = ] unit-test
135 [ ] [ "datagram1" get dispose ] unit-test
136 [ ] [ "datagram2" get dispose ] unit-test
139 [ ] [ "127.0.0.1" 0 <inet4> <datagram> "datagram3" set ] unit-test
141 [ ] [ 1 seconds "datagram3" get set-timeout ] unit-test
142 [ "datagram3" get receive ] must-fail
144 ! See what happens if other end is closed
145 [ ] [ <promise> "port" set ] unit-test
147 [ ] [ "datagram3" get dispose ] unit-test
151 "127.0.0.1" 0 <inet4> utf8 <server>
152 dup addr>> "port" get fulfill
155 dup stream-readln drop
156 "hello" <string-reader> swap stream-copy
158 ] "Socket close test" spawn drop
162 "port" get ?promise utf8 [
163 1 seconds input-stream get set-timeout
164 1 seconds output-stream get set-timeout
165 "hi\n" write flush readln readln
169 ! Binding to all interfaces should work
170 [ ] [ f 0 <inet4> <datagram> dispose ] unit-test
171 [ ] [ f 0 <inet6> <datagram> dispose ] unit-test
173 [ 80 ] [ "http" protocol-port ] unit-test
174 [ f ] [ f protocol-port ] unit-test
176 [ "you-cant-resolve-me!" resolve-host ] [ addrinfo-error? ] must-fail-with