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

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

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:io';
7 import 'dart:isolate';
8
9 void testEmptyListOutputStream1() {
10 ListOutputStream stream = new ListOutputStream();
11 Expect.equals(null, stream.read());
12 stream.close();
13 Expect.equals(null, stream.read());
14 Expect.throws(() { stream.write([0]); });
15 }
16
17
18 void testEmptyListOutputStream2() {
19 ListOutputStream stream = new ListOutputStream();
20 ReceivePort donePort = new ReceivePort();
21
22 void onNoPendingWrites() {
23 stream.close();
24 }
25
26 void onClosed() {
27 Expect.equals(null, stream.read());
28 donePort.toSendPort().send(null);
29 }
30
31 stream.onNoPendingWrites = onNoPendingWrites;
32 stream.onClosed = onClosed;
33
34 donePort.receive((x,y) => donePort.close());
35 }
36
37
38 void testListOutputStream1() {
39 ListOutputStream stream = new ListOutputStream();
40 Expect.equals(null, stream.read());
41 stream.write([1, 2]);
42 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
43 stream.write([5]);
44 stream.close();
45 var contents = stream.read();
46 Expect.equals(5, contents.length);
47 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
48 Expect.equals(null, stream.read());
49 }
50
51
52 void testListOutputStream2() {
53 ListOutputStream stream = new ListOutputStream();
54 ReceivePort donePort = new ReceivePort();
55 int stage = 0;
56 void onNoPendingWrites() {
57 switch (stage) {
58 case 0:
59 stream.write([1, 2]);
60 break;
61 case 1:
62 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
63 break;
64 case 2:
65 stream.write([5]);
66 break;
67 case 3:
68 stream.close();
69 break;
70 }
71 stage++;
72 }
73
74 void onClosed() {
75 Expect.equals(4, stage);
76 var contents = stream.read();
77 Expect.equals(5, contents.length);
78 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
79 Expect.equals(null, stream.read());
80 donePort.toSendPort().send(null);
81 }
82
83 stream.onNoPendingWrites = onNoPendingWrites;
84 stream.onClosed = onClosed;
85
86 donePort.receive((x,y) => donePort.close());
87 }
88
89 void testListOutputStream3() {
90 ListOutputStream stream = new ListOutputStream();
91 ReceivePort donePort = new ReceivePort();
92 void onNoPendingWrites() {
93 stream.writeString("abcdABCD");
94 stream.writeString("abcdABCD", Encoding.UTF_8);
95 stream.writeString("abcdABCD", Encoding.ISO_8859_1);
96 stream.writeString("abcdABCD", Encoding.ASCII);
97 stream.writeString("æøå", Encoding.UTF_8);
98 stream.close();
99 }
100
101 void onClosed() {
102 var contents = stream.read();
103 Expect.equals(38, contents.length);
104 donePort.toSendPort().send(null);
105 }
106
107 stream.onNoPendingWrites = onNoPendingWrites;
108 stream.onClosed = onClosed;
109
110 donePort.receive((x,y) => donePort.close());
111 }
112
113 void testListOutputStream4() {
114 ListOutputStream stream = new ListOutputStream();
115 ReceivePort donePort = new ReceivePort();
116 List result = <int>[];
117
118 void onData() => result.addAll(stream.read());
119
120 void onClosed() {
121 Expect.equals(4, result.length);
122 for (var i = 0; i < result.length; i++) Expect.equals(i + 1, result[i]);
123 donePort.toSendPort().send(null);
124 }
125
126 stream.onData = onData;
127 stream.onClosed = onClosed;
128
129 Timer.run(() {
130 result.add(1);
131 stream.write([2]);
132
133 Timer.run(() {
134 result.add(3);
135 stream.write([4]);
136 stream.close();
137 });
138 });
139
140 donePort.receive((x,y) => donePort.close());
141 }
142
143 void testListOutputStream5() {
144 ListOutputStream stream = new ListOutputStream();
145 ReceivePort donePort = new ReceivePort();
146
147 stream.onClosed = () {
148 Expect.isTrue(stream.closed);
149 var contents = stream.read();
150 Expect.equals(3, contents.length);
151 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
152 donePort.toSendPort().send(null);
153 };
154
155 Expect.isFalse(stream.closed);
156 stream.write([1, 2, 3]);
157 Expect.isFalse(stream.closed);
158 stream.close();
159 Expect.isTrue(stream.closed);
160 Expect.throws(() => stream.write([4, 5, 6]));
161
162 donePort.receive((x,y) => donePort.close());
163 }
164
165 main() {
166 testEmptyListOutputStream1();
167 testEmptyListOutputStream2();
168 testListOutputStream1();
169 testListOutputStream2();
170 testListOutputStream3();
171 testListOutputStream4();
172 testListOutputStream5();
173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698