Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class SocketExceptionTest { | 7 class SocketExceptionTest { |
| 8 | 8 |
| 9 static final PORT = 0; | 9 static final PORT = 0; |
| 10 static final HOST = "127.0.0.1"; | 10 static final HOST = "127.0.0.1"; |
| 11 | 11 |
| 12 static void serverSocketExceptionTest() { | 12 static void serverSocketExceptionTest() { |
| 13 bool exceptionCaught = false; | 13 bool exceptionCaught = false; |
| 14 bool wrongExceptionCaught = false; | 14 bool wrongExceptionCaught = false; |
| 15 | 15 |
| 16 ServerSocket server = new ServerSocket(HOST, PORT, 10); | 16 ServerSocket server = new ServerSocket(HOST, PORT, 10); |
| 17 Expect.equals(true, server !== null); | 17 Expect.equals(true, server !== null); |
| 18 server.close(); | 18 server.close(); |
| 19 try { | 19 try { |
| 20 server.close(); | 20 server.close(); |
| 21 } catch (SocketIOException ex) { | 21 } catch (SocketIOException ex) { |
| 22 exceptionCaught = true; | 22 exceptionCaught = true; |
| 23 } catch (Exception ex) { | 23 } catch (Exception ex) { |
| 24 wrongExceptionCaught = true; | 24 wrongExceptionCaught = true; |
| 25 } | 25 } |
| 26 Expect.equals(false, exceptionCaught); | 26 Expect.equals(false, exceptionCaught); |
| 27 Expect.equals(true, !wrongExceptionCaught); | 27 Expect.equals(true, !wrongExceptionCaught); |
| 28 exceptionCaught = false; | |
| 29 try { | |
| 30 server.accept(); | |
|
Søren Gjesse
2011/12/01 11:15:43
Maybe put this back replacing accept with listen.
Mads Ager (google)
2011/12/01 11:43:59
Listen is implicit. There is get port but that nee
| |
| 31 } catch (SocketIOException ex) { | |
| 32 exceptionCaught = true; | |
| 33 } catch (Exception ex) { | |
| 34 wrongExceptionCaught = true; | |
| 35 } | |
| 36 Expect.equals(true, exceptionCaught); | |
| 37 Expect.equals(true, !wrongExceptionCaught); | |
| 38 } | 28 } |
| 39 | 29 |
| 40 static void clientSocketExceptionTest() { | 30 static void clientSocketExceptionTest() { |
| 41 bool exceptionCaught = false; | 31 bool exceptionCaught = false; |
| 42 bool wrongExceptionCaught = false; | 32 bool wrongExceptionCaught = false; |
| 43 | 33 |
| 44 ServerSocket server = new ServerSocket(HOST, PORT, 10); | 34 ServerSocket server = new ServerSocket(HOST, PORT, 10); |
| 45 Expect.equals(true, server !== null); | 35 Expect.equals(true, server !== null); |
| 46 int port = server.port; | 36 int port = server.port; |
| 47 Socket client = new Socket(HOST, port); | 37 Socket client = new Socket(HOST, port); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 static void testMain() { | 169 static void testMain() { |
| 180 serverSocketExceptionTest(); | 170 serverSocketExceptionTest(); |
| 181 clientSocketExceptionTest(); | 171 clientSocketExceptionTest(); |
| 182 indexOutOfRangeExceptionTest(); | 172 indexOutOfRangeExceptionTest(); |
| 183 } | 173 } |
| 184 } | 174 } |
| 185 | 175 |
| 186 main() { | 176 main() { |
| 187 SocketExceptionTest.testMain(); | 177 SocketExceptionTest.testMain(); |
| 188 } | 178 } |
| OLD | NEW |