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

Side by Side Diff: tests/standalone/src/ListInputStreamTest.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 void testEmptyListInputStream() { 5 void testEmptyListInputStream() {
6 InputStream stream = new ListInputStream([]); 6 InputStream stream = new ListInputStream([]);
7 ReceivePort donePort = new ReceivePort(); 7 ReceivePort donePort = new ReceivePort();
8 8
9 void onData() { 9 void onData() {
10 throw "On data expected"; 10 throw "No data expected";
11 } 11 }
12 12
13 void onClose() { 13 void onClose() {
14 donePort.toSendPort().send(null); 14 donePort.toSendPort().send(null);
15 } 15 }
16 16
17 stream.dataHandler = onData; 17 stream.dataHandler = onData;
18 stream.closeHandler = onClose; 18 stream.closeHandler = onClose;
19 19
20 donePort.receive((x,y) => donePort.close()); 20 donePort.receive((x,y) => donePort.close());
21 } 21 }
22 22
23 void testEmptyDynamicListInputStream() { 23 void testEmptyDynamicListInputStream() {
24 InputStream stream = new DynamicListInputStream(); 24 InputStream stream = new DynamicListInputStream();
25 ReceivePort donePort = new ReceivePort(); 25 ReceivePort donePort = new ReceivePort();
26 26
27 void onData() { 27 void onData() {
28 throw "On data expected"; 28 throw "No data expected";
29 } 29 }
30 30
31 void onClose() { 31 void onClose() {
32 donePort.toSendPort().send(null); 32 donePort.toSendPort().send(null);
33 } 33 }
34 34
35 stream.dataHandler = onData; 35 stream.dataHandler = onData;
36 stream.closeHandler = onClose; 36 stream.closeHandler = onClose;
37 stream.markEndOfStream(); 37 stream.markEndOfStream();
38 38
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Expect.equals(data.length, count); 80 Expect.equals(data.length, count);
81 donePort.toSendPort().send(count); 81 donePort.toSendPort().send(count);
82 } 82 }
83 83
84 stream.dataHandler = onData; 84 stream.dataHandler = onData;
85 stream.closeHandler = onClose; 85 stream.closeHandler = onClose;
86 86
87 donePort.receive((x,y) => donePort.close()); 87 donePort.receive((x,y) => donePort.close());
88 } 88 }
89 89
90 void testListInputStreamPipe1() {
91 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
92 InputStream input = new ListInputStream(data);
93 OutputStream output = new ListOutputStream();
94 ReceivePort donePort = new ReceivePort();
95
96 void onClose() {
97 var content = output.content();
98 Expect.equals(data.length, content.length);
99 donePort.toSendPort().send(null);
100 }
101
102 input.closeHandler = onClose;
103 input.pipe(output);
104
105 donePort.receive((x,y) => donePort.close());
106 }
107
108 void testListInputStreamPipe2() {
109 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
110 OutputStream output = new ListOutputStream();
111 ReceivePort donePort = new ReceivePort();
112 int count = 0;
113
114 void onClose() {
115 if (count < 10) {
116 InputStream input = new ListInputStream(data);
117 input.closeHandler = onClose;
118 if (count < 9) {
119 input.pipe(output, close: false);
120 } else {
121 input.pipe(output);
122 }
123 count++;
124 } else {
125 var content = output.content();
126 Expect.equals(data.length * 10, content.length);
127 donePort.toSendPort().send(null);
128 }
129 }
130
131 InputStream input = new ListInputStream(data);
132 input.closeHandler = onClose;
133 input.pipe(output, close: false);
134 count++;
135
136 donePort.receive((x,y) => donePort.close());
137 }
138
90 void testDynamicListInputStream1() { 139 void testDynamicListInputStream1() {
91 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; 140 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
92 InputStream stream = new DynamicListInputStream(); 141 InputStream stream = new DynamicListInputStream();
93 int count = 0; 142 int count = 0;
94 ReceivePort donePort = new ReceivePort(); 143 ReceivePort donePort = new ReceivePort();
95 144
96 void onData() { 145 void onData() {
97 List<int> x = stream.read(1); 146 List<int> x = stream.read(1);
98 Expect.equals(1, x.length); 147 Expect.equals(1, x.length);
99 x = stream.read(); 148 x = stream.read();
(...skipping 16 matching lines...) Expand all
116 stream.closeHandler = onClose; 165 stream.closeHandler = onClose;
117 166
118 donePort.receive((x,y) => donePort.close()); 167 donePort.receive((x,y) => donePort.close());
119 } 168 }
120 169
121 main() { 170 main() {
122 testEmptyListInputStream(); 171 testEmptyListInputStream();
123 testEmptyDynamicListInputStream(); 172 testEmptyDynamicListInputStream();
124 testListInputStream1(); 173 testListInputStream1();
125 testListInputStream2(); 174 testListInputStream2();
175 testListInputStreamPipe1();
176 testListInputStreamPipe2();
126 testDynamicListInputStream1(); 177 testDynamicListInputStream1();
127 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698