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

Side by Side 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: Addressed review comments from ager@ 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/src/ListInputStreamTest.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 void testEmptyListOutputStream1() {
6 OutputStream stream = new ListOutputStream();
7 Expect.equals(null, stream.contents());
8 stream.close();
9 Expect.equals(null, stream.contents());
10 Expect.throws(() { stream.write([0]); });
11 }
12
13
14 void testEmptyListOutputStream2() {
15 OutputStream stream = new ListOutputStream();
16 ReceivePort donePort = new ReceivePort();
17
18 void onNoPendingWrite() {
19 stream.close();
20 }
21
22 void onClose() {
23 Expect.equals(null, stream.contents());
24 donePort.toSendPort().send(null);
25 }
26
27 stream.noPendingWriteHandler = onNoPendingWrite;
28 stream.closeHandler = onClose;
29
30 donePort.receive((x,y) => donePort.close());
31 }
32
33
34 void testListOutputStream1() {
35 OutputStream stream = new ListOutputStream();
36 Expect.equals(null, stream.contents());
37 stream.write([1, 2]);
38 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
39 stream.write([5]);
40 stream.close();
41 var contents = stream.contents();
42 Expect.equals(5, contents.length);
43 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
44 Expect.equals(null, stream.contents());
45 }
46
47
48 void testListOutputStream2() {
49 OutputStream stream = new ListOutputStream();
50 ReceivePort donePort = new ReceivePort();
51 int stage = 0;
52 void onNoPendingWrite() {
53 switch (stage) {
54 case 0:
55 stream.write([1, 2]);
56 break;
57 case 1:
58 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
59 break;
60 case 2:
61 stream.write([5]);
62 break;
63 case 3:
64 stream.close();
65 break;
66 }
67 stage++;
68 }
69
70 void onClose() {
71 Expect.equals(4, stage);
72 var contents = stream.contents();
73 Expect.equals(5, contents.length);
74 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
75 Expect.equals(null, stream.contents());
76 donePort.toSendPort().send(null);
77 }
78
79 stream.noPendingWriteHandler = onNoPendingWrite;
80 stream.closeHandler = onClose;
81
82 donePort.receive((x,y) => donePort.close());
83 }
84
85 main() {
86 testEmptyListOutputStream1();
87 testEmptyListOutputStream2();
88 testListOutputStream1();
89 testListOutputStream2();
90 }
OLDNEW
« no previous file with comments | « tests/standalone/src/ListInputStreamTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698