OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 | 7 |
8 testAddressParse() async { | |
9 print(new InternetAddress("1.0.2.3").rawAddress); | |
10 print(new InternetAddress("1.0.2.3").type); | |
11 | |
12 print(new InternetAddress("::1").rawAddress); | |
13 print(new InternetAddress("::1").type); | |
14 | |
15 try { | |
16 print(new InternetAddress("localhost")); | |
17 } catch (e) { | |
18 print(e); | |
19 } | |
20 } | |
21 | |
8 testSimpleBind() async { | 22 testSimpleBind() async { |
9 var s = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); | 23 var s = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
10 print("port = ${s.port}"); | 24 print("port = ${s.port}"); |
11 await s.close(); | 25 await s.close(); |
12 } | 26 } |
13 | 27 |
14 testSimpleConnect() async { | 28 testSimpleConnect() async { |
15 var server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); | 29 var server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
16 print("server port = ${server.port}"); | 30 print("server port = ${server.port}"); |
17 server.listen((socket) { | 31 server.listen((socket) { |
18 print("listen socket port = ${socket.port}"); | 32 print("listen socket port = ${socket.port}"); |
19 socket.close(); | 33 socket.close(); |
20 }); | 34 }); |
21 var socket = await RawSocket.connect("127.0.0.1", server.port); | 35 var socket = await RawSocket.connect("127.0.0.1", server.port); |
22 print("socket port = ${socket.port}"); | 36 print("socket port = ${socket.port}"); |
37 if (socket.remoteAddress.address != "127.0.0.1" || | |
38 socket.remoteAddress.type != InternetAddressType.IP_V4) { | |
39 throw "Bad remote address ${socket.remoteAddress}"; | |
40 } | |
41 if (socket.remotePort is! int) { | |
42 throw "Bad remote port ${socket.remotePort}"; | |
43 } | |
23 await server.close(); | 44 await server.close(); |
24 await socket.close(); | 45 await socket.close(); |
25 } | 46 } |
26 | 47 |
27 testSimpleReadWrite({bool dropReads}) async { | 48 testSimpleReadWrite({bool dropReads}) async { |
28 // This test creates a server and a client connects. The client then | 49 // This test creates a server and a client connects. The client then |
29 // writes and the server echos. When the server has finished its | 50 // writes and the server echos. When the server has finished its |
30 // echo it half-closes. When the client gets the close event is | 51 // echo it half-closes. When the client gets the close event is |
31 // closes fully. | 52 // closes fully. |
32 | 53 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 // Lookup failed or connection failed. Don't report a failure. | 211 // Lookup failed or connection failed. Don't report a failure. |
191 print("SocketException: $e"); | 212 print("SocketException: $e"); |
192 } finally { | 213 } finally { |
193 client.close(); | 214 client.close(); |
194 } | 215 } |
195 } | 216 } |
196 | 217 |
197 main() async { | 218 main() async { |
198 print("Hello, Fuchsia!"); | 219 print("Hello, Fuchsia!"); |
199 | 220 |
221 print("testAddressParse"); | |
222 await testAddressParse(); | |
223 print("testAddressParse done"); | |
224 | |
200 print("testSimpleBind"); | 225 print("testSimpleBind"); |
201 await testSimpleBind(); | 226 await testSimpleBind(); |
202 print("testSimpleBind done"); | 227 print("testSimpleBind done"); |
203 | 228 |
204 print("testSimpleConnect"); | 229 print("testSimpleConnect"); |
205 await testSimpleConnect(); | 230 await testSimpleConnect(); |
206 print("testSimpleConnect done"); | 231 print("testSimpleConnect done"); |
207 | 232 |
233 // TODO(US-81): Enable. | |
208 // print("testSimpleReadWrite"); | 234 // print("testSimpleReadWrite"); |
209 // await testSimpleReadWrite(dropReads: false); | 235 // await testSimpleReadWrite(dropReads: false); |
210 // print("testSimpleReadWrite done"); | 236 // print("testSimpleReadWrite done"); |
siva
2016/11/22 20:32:43
Why is this still commented out, we should be able
rmacnak
2016/11/22 20:46:46
The test needs other changes so the process will e
| |
211 | 237 |
212 // print("testGoogleUrl"); | 238 print("testGoogleUrl"); |
213 // await testGoogleUrl(null, 'pass'); | 239 await testGoogleUrl(null, 'pass'); |
214 // print("testGoogleUrl done"); | 240 print("testGoogleUrl done"); |
215 | 241 |
216 print("Goodbyte, Fuchsia!"); | 242 print("Goodbyte, Fuchsia!"); |
217 } | 243 } |
OLD | NEW |