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

Unified Diff: tests/standalone/src/ListInputStreamTest.dart

Issue 9029001: Add close to input stream and cleanup socket and streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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/ListInputStreamTest.dart
diff --git a/tests/standalone/src/ListInputStreamTest.dart b/tests/standalone/src/ListInputStreamTest.dart
index b9df1a5a2e5e5815cf55a00bbc9f0bf4dc481fdd..b38b2d80662792b421095ad2b5d5bce64d4008f8 100644
--- a/tests/standalone/src/ListInputStreamTest.dart
+++ b/tests/standalone/src/ListInputStreamTest.dart
@@ -136,7 +136,49 @@ void testListInputStreamPipe2() {
donePort.receive((x,y) => donePort.close());
}
-void testDynamicListInputStream1() {
+void testListInputClose1() {
+ List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ InputStream stream = new ListInputStream(data);
+ ReceivePort donePort = new ReceivePort();
+
+ void onData() {
+ throw "No data expected";
+ }
+
+ void onClose() {
+ donePort.toSendPort().send(null);
+ }
+
+ stream.dataHandler = onData;
+ stream.closeHandler = onClose;
+ stream.close();
+
+ donePort.receive((x,y) => donePort.close());
+}
+
+void testListInputClose2() {
+ List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ InputStream stream = new ListInputStream(data);
+ ReceivePort donePort = new ReceivePort();
+ int count = 0;
+
+ void onData() {
+ count += stream.read(2).length;
+ stream.close();
+ }
+
+ void onClose() {
+ Expect.equals(2, count);
+ donePort.toSendPort().send(count);
+ }
+
+ stream.dataHandler = onData;
+ stream.closeHandler = onClose;
+
+ donePort.receive((x,y) => donePort.close());
+}
+
+void testDynamicListInputStream() {
List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
InputStream stream = new DynamicListInputStream();
int count = 0;
@@ -167,6 +209,54 @@ void testDynamicListInputStream1() {
donePort.receive((x,y) => donePort.close());
}
+void testDynamicListInputClose1() {
+ List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ InputStream stream = new DynamicListInputStream();
+ ReceivePort donePort = new ReceivePort();
+
+ void onData() {
+ throw "No data expected";
+ }
+
+ void onClose() {
+ donePort.toSendPort().send(null);
+ }
+
+ stream.write(data);
+ stream.dataHandler = onData;
+ stream.closeHandler = onClose;
+ stream.close();
+ Expect.throws(() => stream.write(data), (e) => e is StreamException);
+
+ donePort.receive((x,y) => donePort.close());
+}
+
+void testDynamicListInputClose2() {
+ List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ InputStream stream = new DynamicListInputStream();
+ ReceivePort donePort = new ReceivePort();
+ int count = 0;
+
+ void onData() {
+ count += stream.read(15).length;
+ stream.close();
+ Expect.throws(() => stream.write(data), (e) => e is StreamException);
+ }
+
+ void onClose() {
+ Expect.equals(15, count);
+ donePort.toSendPort().send(null);
+ }
+
+ stream.write(data);
+ stream.write(data);
+ stream.write(data);
+ stream.dataHandler = onData;
+ stream.closeHandler = onClose;
+
+ donePort.receive((x,y) => donePort.close());
+}
+
main() {
testEmptyListInputStream();
testEmptyDynamicListInputStream();
@@ -174,5 +264,9 @@ main() {
testListInputStream2();
testListInputStreamPipe1();
testListInputStreamPipe2();
- testDynamicListInputStream1();
+ testListInputClose1();
+ testListInputClose2();
+ testDynamicListInputStream();
+ testDynamicListInputClose1();
+ testDynamicListInputClose2();
}

Powered by Google App Engine
This is Rietveld 408576698