Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Unified Diff: tests/standalone/src/io/SocketExceptionTest.dart

Issue 9699017: Start better error reporting for sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed bug Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/standalone/src/io/SocketExceptionTest.dart
diff --git a/tests/standalone/src/io/SocketExceptionTest.dart b/tests/standalone/src/io/SocketExceptionTest.dart
index edc78d0723169e6b9e0d902903e01c931dc7987e..b2b941a9067316e03a92cf58a3e54de0f08b28fb 100644
--- a/tests/standalone/src/io/SocketExceptionTest.dart
+++ b/tests/standalone/src/io/SocketExceptionTest.dart
@@ -1,9 +1,10 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// Tests socket exceptions.
+#import("dart:isolate");
#import("dart:io");
class SocketExceptionTest {
@@ -37,75 +38,77 @@ class SocketExceptionTest {
Expect.equals(true, server !== null);
int port = server.port;
Socket client = new Socket(HOST, port);
- Expect.equals(true, client !== null);
- InputStream input = client.inputStream;
- OutputStream output = client.outputStream;
- client.close();
- try {
+ client.onConnect = () {
+ Expect.equals(true, client !== null);
+ InputStream input = client.inputStream;
+ OutputStream output = client.outputStream;
client.close();
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(false, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
- try {
- client.available();
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
- try {
- List<int> buffer = new List<int>(10);
- client.readList(buffer, 0 , 10);
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
- try {
- List<int> buffer = new List<int>(10);
- client.writeList(buffer, 0, 10);
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
- try {
- List<int> buffer = new List<int>(42);
- bool readDone = input.readInto(buffer, 0, 12);
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
- try {
- List<int> buffer = new List<int>(42);
- output.writeFrom(buffer, 0, 12);
- } catch (SocketIOException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
+ try {
+ client.close();
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(false, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+ try {
+ client.available();
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+ try {
+ List<int> buffer = new List<int>(10);
+ client.readList(buffer, 0 , 10);
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+ try {
+ List<int> buffer = new List<int>(10);
+ client.writeList(buffer, 0, 10);
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+ try {
+ List<int> buffer = new List<int>(42);
+ bool readDone = input.readInto(buffer, 0, 12);
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+ try {
+ List<int> buffer = new List<int>(42);
+ output.writeFrom(buffer, 0, 12);
+ } catch (SocketIOException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
- server.close();
+ server.close();
+ };
}
static void indexOutOfRangeExceptionTest() {
@@ -116,62 +119,86 @@ class SocketExceptionTest {
Expect.equals(true, server !== null);
int port = server.port;
Socket client = new Socket(HOST, port);
- Expect.equals(true, client !== null);
- try {
- List<int> buffer = new List<int>(10);
- client.readList(buffer, -1, 1);
- } catch (IndexOutOfRangeException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
+ client.onConnect = () {
+ Expect.equals(true, client !== null);
+ try {
+ List<int> buffer = new List<int>(10);
+ client.readList(buffer, -1, 1);
+ } catch (IndexOutOfRangeException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+
+ try {
+ List<int> buffer = new List<int>(10);
+ client.readList(buffer, 0, -1);
+ } catch (IndexOutOfRangeException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+
+ try {
+ List<int> buffer = new List<int>(10);
+ client.writeList(buffer, -1, 1);
+ } catch (IndexOutOfRangeException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
+ exceptionCaught = false;
+
+ try {
+ List<int> buffer = new List<int>(10);
+ client.writeList(buffer, 0, -1);
+ } catch (IndexOutOfRangeException ex) {
+ exceptionCaught = true;
+ } catch (Exception ex) {
+ wrongExceptionCaught = true;
+ }
+ Expect.equals(true, exceptionCaught);
+ Expect.equals(true, !wrongExceptionCaught);
- try {
- List<int> buffer = new List<int>(10);
- client.readList(buffer, 0, -1);
- } catch (IndexOutOfRangeException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
+ server.close();
+ client.close();
+ };
+ }
- try {
- List<int> buffer = new List<int>(10);
- client.writeList(buffer, -1, 1);
- } catch (IndexOutOfRangeException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
- exceptionCaught = false;
+ static void unknownHostTest() {
+ // Port to verify that the test completes.
+ var port = new ReceivePort();
+ port.receive((message, replyTo) => null);
- try {
- List<int> buffer = new List<int>(10);
- client.writeList(buffer, 0, -1);
- } catch (IndexOutOfRangeException ex) {
- exceptionCaught = true;
- } catch (Exception ex) {
- wrongExceptionCaught = true;
- }
- Expect.equals(true, exceptionCaught);
- Expect.equals(true, !wrongExceptionCaught);
+ Socket s = new Socket("hede.hule.hest", 1234);
+ s.onError = (e) => port.close();
+ s.onConnect = () => Expect.fail("Connection completed");
+ }
- server.close();
- client.close();
+ static void unresponsiveHostTest() {
+ // Port to keep the VM alive until test completes.
+ var port = new ReceivePort();
+ port.receive((message, replyTo) => null);
+
+ Socket s = new Socket("127.0.0.1", 65535);
+ s.onError = (e) => port.close();
+ s.onConnect = () => Expect.fail("Connection completed");
}
static void testMain() {
serverSocketExceptionTest();
clientSocketExceptionTest();
indexOutOfRangeExceptionTest();
+ unknownHostTest();
+ unresponsiveHostTest();
}
}
« no previous file with comments | « tests/standalone/src/io/SocketCloseTest.dart ('k') | tests/standalone/src/io/SocketManyConnectionsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698