OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Tests socket exceptions. | 5 // Tests socket exceptions. |
6 | 6 |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 | 9 |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
(...skipping 22 matching lines...) Expand all Loading... |
33 ServerSocket.bind("__INVALID_HOST__", 0) | 33 ServerSocket.bind("__INVALID_HOST__", 0) |
34 .then((server) { }) | 34 .then((server) { }) |
35 .catchError((e) => e is SocketException); | 35 .catchError((e) => e is SocketException); |
36 }); | 36 }); |
37 } | 37 } |
38 | 38 |
39 static void serverSocketCloseListenTest() { | 39 static void serverSocketCloseListenTest() { |
40 asyncStart(); | 40 asyncStart(); |
41 ServerSocket.bind("127.0.0.1", 0).then((server) { | 41 ServerSocket.bind("127.0.0.1", 0).then((server) { |
42 Socket.connect("127.0.0.1", server.port).then((socket) { | 42 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 43 socket.destroy(); |
43 server.close(); | 44 server.close(); |
44 server.listen( | 45 server.listen( |
45 (incoming) => Expect.fail("Unexpected socket"), | 46 (incoming) => Expect.fail("Unexpected socket"), |
46 onDone: asyncEnd); | 47 onDone: asyncEnd); |
47 }); | 48 }); |
48 }); | 49 }); |
49 } | 50 } |
50 | 51 |
51 static void serverSocketListenCloseTest() { | 52 static void serverSocketListenCloseTest() { |
52 asyncStart(); | 53 asyncStart(); |
53 ServerSocket.bind("127.0.0.1", 0).then((server) { | 54 ServerSocket.bind("127.0.0.1", 0).then((server) { |
54 Socket.connect("127.0.0.1", server.port).then((socket) { | 55 Socket.connect("127.0.0.1", server.port).then((socket) { |
55 server.listen( | 56 server.listen( |
56 (incoming) => server.close(), | 57 (incoming) { |
57 onDone: asyncEnd); | 58 incoming.destroy(); |
| 59 socket.destroy(); |
| 60 server.close(); |
| 61 }, onDone: asyncEnd); |
58 }); | 62 }); |
59 }); | 63 }); |
60 } | 64 } |
61 | 65 |
62 static void clientSocketExceptionTest() { | 66 static void clientSocketExceptionTest() { |
63 bool exceptionCaught = false; | 67 bool exceptionCaught = false; |
64 bool wrongExceptionCaught = false; | 68 bool wrongExceptionCaught = false; |
65 | 69 |
66 ServerSocket.bind("127.0.0.1", 0).then((server) { | 70 ServerSocket.bind("127.0.0.1", 0).then((server) { |
67 Expect.isNotNull(server); | 71 Expect.isNotNull(server); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 unknownHostTest(); | 237 unknownHostTest(); |
234 } | 238 } |
235 } | 239 } |
236 | 240 |
237 main() { | 241 main() { |
238 asyncStart(); | 242 asyncStart(); |
239 SocketExceptionTest.testMain(); | 243 SocketExceptionTest.testMain(); |
240 asyncEnd(); | 244 asyncEnd(); |
241 } | 245 } |
242 | 246 |
OLD | NEW |