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

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

Issue 8989019: Implement list based output stream and add pipe to list based input 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/ListOutputStreamTest.dart
diff --git a/tests/standalone/src/ListOutputStreamTest.dart b/tests/standalone/src/ListOutputStreamTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3d34af7cf1ae9613915ae9ac9e0efe85a2f94c4d
--- /dev/null
+++ b/tests/standalone/src/ListOutputStreamTest.dart
@@ -0,0 +1,90 @@
+// Copyright (c) 2011, 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.
+
+void testEmptyListOutputStream1() {
+ OutputStream stream = new ListOutputStream();
+ Expect.equals(null, stream.content());
+ stream.close();
+ Expect.equals(null, stream.content());
+ Expect.throws(() { stream.write([0]); });
+}
+
+
+void testEmptyListOutputStream2() {
+ OutputStream stream = new ListOutputStream();
+ ReceivePort donePort = new ReceivePort();
+
+ void onNoPendingWrite() {
+ stream.close();
+ }
+
+ void onClose() {
+ Expect.equals(null, stream.content());
+ donePort.toSendPort().send(null);
+ }
+
+ stream.noPendingWriteHandler = onNoPendingWrite;
+ stream.closeHandler = onClose;
+
+ donePort.receive((x,y) => donePort.close());
+}
+
+
+void testListOutputStream1() {
+ OutputStream stream = new ListOutputStream();
+ Expect.equals(null, stream.content());
+ stream.write([1, 2]);
+ stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
+ stream.write([5]);
+ stream.close();
+ var content = stream.content();
+ Expect.equals(5, content.length);
+ for (var i = 0; i < content.length; i++) Expect.equals(i + 1, content[i]);
+ Expect.equals(null, stream.content());
+}
+
+
+void testListOutputStream2() {
+ OutputStream stream = new ListOutputStream();
+ ReceivePort donePort = new ReceivePort();
+ int stage = 0;
+ void onNoPendingWrite() {
+ switch (stage) {
+ case 0:
+ stream.write([1, 2]);
+ break;
+ case 1:
+ stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
+ break;
+ case 2:
+ stream.write([5]);
+ break;
+ case 3:
+ stream.close();
+ break;
+ }
+ stage++;
+ }
+
+ void onClose() {
+ Expect.equals(4, stage);
+ var content = stream.content();
+ Expect.equals(5, content.length);
+ for (var i = 0; i < content.length; i++) Expect.equals(i + 1, content[i]);
+ Expect.equals(null, stream.content());
+ donePort.toSendPort().send(null);
+ }
+
+ stream.noPendingWriteHandler = onNoPendingWrite;
+ stream.closeHandler = onClose;
+
+ donePort.receive((x,y) => donePort.close());
+}
+
+main() {
+ testEmptyListOutputStream1();
+ testEmptyListOutputStream2();
+ testListOutputStream1();
+ testListOutputStream2();
+}
« runtime/bin/list_stream.dart ('K') | « tests/standalone/src/ListInputStreamTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698