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

Side by Side Diff: tests/standalone/io/string_stream_test.dart

Issue 10945004: Make it possible to read a specific number of characters from a string input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/websocket_impl.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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #import("dart:io"); 5 #import("dart:io");
6 6
7 void testUtf8() { 7 void testUtf8() {
8 List<int> data = [0x01, 8 List<int> data = [0x01,
9 0x7f, 9 0x7f,
10 0xc2, 0x80, 10 0xc2, 0x80,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void streamClosed() { 158 void streamClosed() {
159 Expect.equals(4, stage); 159 Expect.equals(4, stage);
160 Expect.equals(true, stream.closed); 160 Expect.equals(true, stream.closed);
161 } 161 }
162 162
163 stream.onLine = stringData; 163 stream.onLine = stringData;
164 stream.onClosed = streamClosed; 164 stream.onClosed = streamClosed;
165 s.write("Line1\nLine2\r\nLine3\rLi".charCodes()); 165 s.write("Line1\nLine2\r\nLine3\rLi".charCodes());
166 } 166 }
167 167
168 void testReadChunks() {
169 ListInputStream s = new ListInputStream();
170 StringInputStream stream = new StringInputStream(s);
171
172 void stringData() {
173 var data;
174 Expect.equals(8, stream.available());
175 data = stream.read(1);
176 Expect.equals("A", data);
177 Expect.equals(7, stream.available());
178 data = stream.read(2);
179 Expect.equals("BC", data);
180 Expect.equals(5, stream.available());
181 data = stream.read(3);
182 Expect.equals("D12", data);
183 Expect.equals(2, stream.available());
184 data = stream.read();
185 Expect.equals("34", data);
186 Expect.equals(0, stream.available());
187 data = stream.read(1);
188 Expect.equals(null, data);
189 Expect.equals(0, stream.available());
190 data = stream.read(2);
191 Expect.equals(null, data);
192 Expect.equals(0, stream.available());
193 data = stream.read(3);
194 Expect.equals(null, data);
195 Expect.equals(0, stream.available());
196 data = stream.read();
197 Expect.equals(null, data);
198 Expect.equals(0, stream.available());
199 }
200
201 s.write("ABCD1234".charCodes());
202 stream.onData = stringData;
203 }
204
205 void testReadMixed() {
206 ListInputStream s = new ListInputStream();
207 StringInputStream stream = new StringInputStream(s);
208 var stage = 0;
209
210 void stringData() {
211 var data;
212 if (stage == 0) {
213 Expect.equals(11, stream.available());
214 data = stream.read(2);
215 Expect.equals("A\r", data);
216 Expect.equals(9, stream.available());
217 data = stream.readLine();
218 Expect.equals("", data);
219 Expect.equals(8, stream.available());
220 data = stream.read(4);
221 Expect.equals("BCD\n", data);
222 Expect.equals(4, stream.available());
223 data = stream.readLine();
224 Expect.equals(null, data);
225 data = stream.read(4);
226 Expect.equals("1234", data);
227 s.write("A\r\nBCD\n1234".charCodes());
228 stage++;
229 } else if (stage == 1) {
230 Expect.equals(11, stream.available());
231 data = stream.read(1);
232 Expect.equals("A", data);
233 Expect.equals(10, stream.available());
234 data = stream.read(1);
235 Expect.equals("\r", data);
236 Expect.equals(9, stream.available());
237 data = stream.read(1);
238 Expect.equals("\n", data);
239 Expect.equals(8, stream.available());
240 data = stream.readLine();
241 Expect.equals("BCD", data);
242 data = stream.readLine();
243 Expect.equals(null, data);
244 data = stream.read(4);
245 Expect.equals("1234", data);
246 s.write("A\r\nBCD\n1234".charCodes());
247 stage++;
248 } else if (stage == 2) {
249 Expect.equals(11, stream.available());
250 data = stream.read(7);
251 Expect.equals("A\r\nBCD\n", data);
252 Expect.equals(4, stream.available());
253 data = stream.readLine();
254 Expect.equals(null, data);
255 data = stream.read();
256 Expect.equals("1234", data);
257 stage++;
258 s.markEndOfStream();
259 }
260 }
261
262 void streamClosed() {
263 Expect.equals(3, stage);
264 Expect.equals(true, stream.closed);
265 }
266
267 s.write("A\r\nBCD\n1234".charCodes());
268 stream.onData = stringData;
269 stream.onClosed = streamClosed;
270 }
271
168 class TestException implements Exception { 272 class TestException implements Exception {
169 TestException(); 273 TestException();
170 } 274 }
171 275
172 class ErrorInputStream implements InputStream { 276 class ErrorInputStream implements InputStream {
173 ErrorInputStream(); 277 ErrorInputStream();
174 List<int> read([int len]) => null; 278 List<int> read([int len]) => null;
175 int readInto(List<int> buffer, [int offset, int len]) => 0; 279 int readInto(List<int> buffer, [int offset, int len]) => 0;
176 int available() => 0; 280 int available() => 0;
177 void pipe(OutputStream output, [bool close]){ } 281 void pipe(OutputStream output, [bool close]){ }
(...skipping 15 matching lines...) Expand all
193 }; 297 };
194 Expect.equals(1, errors); 298 Expect.equals(1, errors);
195 } 299 }
196 300
197 main() { 301 main() {
198 testUtf8(); 302 testUtf8();
199 testLatin1(); 303 testLatin1();
200 testAscii(); 304 testAscii();
201 testReadLine1(); 305 testReadLine1();
202 testReadLine2(); 306 testReadLine2();
307 testReadChunks();
308 testReadMixed();
203 testErrorHandler(); 309 testErrorHandler();
204 } 310 }
OLDNEW
« no previous file with comments | « runtime/bin/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698