Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:isolate"); | 7 #import("dart:isolate"); |
| 8 #import("dart:io"); | 8 #import("dart:io"); |
| 9 | 9 |
| 10 class SocketExceptionTest { | 10 class SocketExceptionTest { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 server.close(); | 21 server.close(); |
| 22 try { | 22 try { |
| 23 server.close(); | 23 server.close(); |
| 24 } on SocketIOException catch(ex) { | 24 } on SocketIOException catch(ex) { |
| 25 exceptionCaught = true; | 25 exceptionCaught = true; |
| 26 } on Exception catch (ex) { | 26 } on Exception catch (ex) { |
| 27 wrongExceptionCaught = true; | 27 wrongExceptionCaught = true; |
| 28 } | 28 } |
| 29 Expect.equals(false, exceptionCaught); | 29 Expect.equals(false, exceptionCaught); |
| 30 Expect.equals(true, !wrongExceptionCaught); | 30 Expect.equals(true, !wrongExceptionCaught); |
| 31 | |
| 32 // Test invalid host. | |
| 33 Expect.throws(() => new ServerSocket("__INVALID_HOST__", PORT, 10)); | |
|
Søren Gjesse
2012/09/03 13:56:44
Maybe do some checking on the actual exception (is
Anders Johnsen
2012/09/03 14:34:38
Turns out it's a SocketIOException. Check added.
| |
| 31 } | 34 } |
| 32 | 35 |
| 33 static void clientSocketExceptionTest() { | 36 static void clientSocketExceptionTest() { |
| 34 bool exceptionCaught = false; | 37 bool exceptionCaught = false; |
| 35 bool wrongExceptionCaught = false; | 38 bool wrongExceptionCaught = false; |
| 36 | 39 |
| 37 ServerSocket server = new ServerSocket(HOST, PORT, 10); | 40 ServerSocket server = new ServerSocket(HOST, PORT, 10); |
| 38 Expect.equals(true, server !== null); | 41 Expect.equals(true, server !== null); |
| 39 int port = server.port; | 42 int port = server.port; |
| 40 Socket client = new Socket(HOST, port); | 43 Socket client = new Socket(HOST, port); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 Socket s = new Socket("127.0.0.1", 65535); | 194 Socket s = new Socket("127.0.0.1", 65535); |
| 192 s.onError = (e) => port.close(); | 195 s.onError = (e) => port.close(); |
| 193 s.onConnect = () => Expect.fail("Connection completed"); | 196 s.onConnect = () => Expect.fail("Connection completed"); |
| 194 } | 197 } |
| 195 | 198 |
| 196 static void testMain() { | 199 static void testMain() { |
| 197 serverSocketExceptionTest(); | 200 serverSocketExceptionTest(); |
| 198 clientSocketExceptionTest(); | 201 clientSocketExceptionTest(); |
| 199 indexOutOfRangeExceptionTest(); | 202 indexOutOfRangeExceptionTest(); |
| 200 unknownHostTest(); | 203 unknownHostTest(); |
| 204 | |
| 201 // TODO(sgjesse): This test seems to fail on the buildbot. | 205 // TODO(sgjesse): This test seems to fail on the buildbot. |
| 202 //unresponsiveHostTest(); | 206 //unresponsiveHostTest(); |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 main() { | 210 main() { |
| 207 SocketExceptionTest.testMain(); | 211 SocketExceptionTest.testMain(); |
| 208 } | 212 } |
| OLD | NEW |