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

Side by Side Diff: tests/standalone/src/ListInputStreamTest.dart

Issue 8953030: Add input streams based on supplying data from lists (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
(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 testEmptyListInputStream() {
6 InputStream stream = new ListInputStream([]);
7 ReceivePort donePort = new ReceivePort();
8
9 void onData() {
10 throw "On data expected";
11 }
12
13 void onClose() {
14 donePort.toSendPort().send(null);
15 }
16
17 stream.dataHandler = onData;
18 stream.closeHandler = onClose;
19
20 donePort.receive((x,y) => donePort.close());
21 }
22
23 void testEmptyDynamicListInputStream() {
24 InputStream stream = new DynamicListInputStream();
25 ReceivePort donePort = new ReceivePort();
26
27 void onData() {
28 throw "On data expected";
29 }
30
31 void onClose() {
32 donePort.toSendPort().send(null);
33 }
34
35 stream.dataHandler = onData;
36 stream.closeHandler = onClose;
37 stream.markEndOfStream();
38
39 donePort.receive((x,y) => donePort.close());
40 }
41
42 void testListInputStream1() {
43 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
44 InputStream stream = new ListInputStream(data);
45 int count = 0;
46 ReceivePort donePort = new ReceivePort();
47
48 void onData() {
49 List<int> x = stream.read(1);
50 Expect.equals(1, x.length);
51 Expect.equals(data[count++], x[0]);
52 }
53
54 void onClose() {
55 Expect.equals(data.length, count);
56 donePort.toSendPort().send(count);
57 }
58
59 stream.dataHandler = onData;
60 stream.closeHandler = onClose;
61
62 donePort.receive((x,y) => donePort.close());
63 }
64
65 void testListInputStream2() {
66 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
67 InputStream stream = new ListInputStream(data);
68 int count = 0;
69 ReceivePort donePort = new ReceivePort();
70
71 void onData() {
72 List<int> x = new List<int>(2);
73 var bytesRead = stream.readInto(x);
74 Expect.equals(2, bytesRead);
75 Expect.equals(data[count++], x[0]);
76 Expect.equals(data[count++], x[1]);
77 }
78
79 void onClose() {
80 Expect.equals(data.length, count);
81 donePort.toSendPort().send(count);
82 }
83
84 stream.dataHandler = onData;
85 stream.closeHandler = onClose;
86
87 donePort.receive((x,y) => donePort.close());
88 }
89
90 void testDynamicListInputStream1() {
91 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff];
92 InputStream stream = new DynamicListInputStream();
93 int count = 0;
94 ReceivePort donePort = new ReceivePort();
95
96 void onData() {
97 List<int> x = stream.read(1);
98 Expect.equals(1, x.length);
99 x = stream.read();
100 Expect.equals(9, x.length);
101 count++;
102 if (count < 10) {
103 stream.write(data);
104 } else {
105 stream.markEndOfStream();
106 }
107 }
108
109 void onClose() {
110 Expect.equals(data.length, count);
111 donePort.toSendPort().send(count);
112 }
113
114 stream.write(data);
115 stream.dataHandler = onData;
116 stream.closeHandler = onClose;
117
118 donePort.receive((x,y) => donePort.close());
119 }
120
121 main() {
122 testEmptyListInputStream();
123 testEmptyDynamicListInputStream();
124 testListInputStream1();
125 testListInputStream2();
126 testDynamicListInputStream1();
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698