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

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

Issue 10832145: Add a ListOutputStream.onData callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « tests/standalone/io/list_input_stream_test.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 #import("dart:isolate"); 6 #import("dart:isolate");
7 7
8 void testEmptyListOutputStream1() { 8 void testEmptyListOutputStream1() {
9 ListOutputStream stream = new ListOutputStream(); 9 ListOutputStream stream = new ListOutputStream();
10 Expect.equals(null, stream.contents()); 10 Expect.equals(null, stream.read());
11 stream.close(); 11 stream.close();
12 Expect.equals(null, stream.contents()); 12 Expect.equals(null, stream.read());
13 Expect.throws(() { stream.write([0]); }); 13 Expect.throws(() { stream.write([0]); });
14 } 14 }
15 15
16 16
17 void testEmptyListOutputStream2() { 17 void testEmptyListOutputStream2() {
18 ListOutputStream stream = new ListOutputStream(); 18 ListOutputStream stream = new ListOutputStream();
19 ReceivePort donePort = new ReceivePort(); 19 ReceivePort donePort = new ReceivePort();
20 20
21 void onNoPendingWrites() { 21 void onNoPendingWrites() {
22 stream.close(); 22 stream.close();
23 } 23 }
24 24
25 void onClosed() { 25 void onClosed() {
26 Expect.equals(null, stream.contents()); 26 Expect.equals(null, stream.read());
27 donePort.toSendPort().send(null); 27 donePort.toSendPort().send(null);
28 } 28 }
29 29
30 stream.onNoPendingWrites = onNoPendingWrites; 30 stream.onNoPendingWrites = onNoPendingWrites;
31 stream.onClosed = onClosed; 31 stream.onClosed = onClosed;
32 32
33 donePort.receive((x,y) => donePort.close()); 33 donePort.receive((x,y) => donePort.close());
34 } 34 }
35 35
36 36
37 void testListOutputStream1() { 37 void testListOutputStream1() {
38 ListOutputStream stream = new ListOutputStream(); 38 ListOutputStream stream = new ListOutputStream();
39 Expect.equals(null, stream.contents()); 39 Expect.equals(null, stream.read());
40 stream.write([1, 2]); 40 stream.write([1, 2]);
41 stream.writeFrom([1, 2, 3, 4, 5], 2, 2); 41 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
42 stream.write([5]); 42 stream.write([5]);
43 stream.close(); 43 stream.close();
44 var contents = stream.contents(); 44 var contents = stream.read();
45 Expect.equals(5, contents.length); 45 Expect.equals(5, contents.length);
46 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]); 46 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
47 Expect.equals(null, stream.contents()); 47 Expect.equals(null, stream.read());
48 } 48 }
49 49
50 50
51 void testListOutputStream2() { 51 void testListOutputStream2() {
52 ListOutputStream stream = new ListOutputStream(); 52 ListOutputStream stream = new ListOutputStream();
53 ReceivePort donePort = new ReceivePort(); 53 ReceivePort donePort = new ReceivePort();
54 int stage = 0; 54 int stage = 0;
55 void onNoPendingWrites() { 55 void onNoPendingWrites() {
56 switch (stage) { 56 switch (stage) {
57 case 0: 57 case 0:
58 stream.write([1, 2]); 58 stream.write([1, 2]);
59 break; 59 break;
60 case 1: 60 case 1:
61 stream.writeFrom([1, 2, 3, 4, 5], 2, 2); 61 stream.writeFrom([1, 2, 3, 4, 5], 2, 2);
62 break; 62 break;
63 case 2: 63 case 2:
64 stream.write([5]); 64 stream.write([5]);
65 break; 65 break;
66 case 3: 66 case 3:
67 stream.close(); 67 stream.close();
68 break; 68 break;
69 } 69 }
70 stage++; 70 stage++;
71 } 71 }
72 72
73 void onClosed() { 73 void onClosed() {
74 Expect.equals(4, stage); 74 Expect.equals(4, stage);
75 var contents = stream.contents(); 75 var contents = stream.read();
76 Expect.equals(5, contents.length); 76 Expect.equals(5, contents.length);
77 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]); 77 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]);
78 Expect.equals(null, stream.contents()); 78 Expect.equals(null, stream.read());
79 donePort.toSendPort().send(null); 79 donePort.toSendPort().send(null);
80 } 80 }
81 81
82 stream.onNoPendingWrites = onNoPendingWrites; 82 stream.onNoPendingWrites = onNoPendingWrites;
83 stream.onClosed = onClosed; 83 stream.onClosed = onClosed;
84 84
85 donePort.receive((x,y) => donePort.close()); 85 donePort.receive((x,y) => donePort.close());
86 } 86 }
87 87
88 void testListOutputStream3() { 88 void testListOutputStream3() {
89 ListOutputStream stream = new ListOutputStream(); 89 ListOutputStream stream = new ListOutputStream();
90 ReceivePort donePort = new ReceivePort(); 90 ReceivePort donePort = new ReceivePort();
91 void onNoPendingWrites() { 91 void onNoPendingWrites() {
92 stream.writeString("abcdABCD"); 92 stream.writeString("abcdABCD");
93 stream.writeString("abcdABCD", Encoding.UTF_8); 93 stream.writeString("abcdABCD", Encoding.UTF_8);
94 stream.writeString("abcdABCD", Encoding.ISO_8859_1); 94 stream.writeString("abcdABCD", Encoding.ISO_8859_1);
95 stream.writeString("abcdABCD", Encoding.ASCII); 95 stream.writeString("abcdABCD", Encoding.ASCII);
96 stream.writeString("æøå", Encoding.UTF_8); 96 stream.writeString("æøå", Encoding.UTF_8);
97 stream.close(); 97 stream.close();
98 } 98 }
99 99
100 void onClosed() { 100 void onClosed() {
101 var contents = stream.contents(); 101 var contents = stream.read();
102 Expect.equals(38, contents.length); 102 Expect.equals(38, contents.length);
103 donePort.toSendPort().send(null); 103 donePort.toSendPort().send(null);
104 } 104 }
105 105
106 stream.onNoPendingWrites = onNoPendingWrites; 106 stream.onNoPendingWrites = onNoPendingWrites;
107 stream.onClosed = onClosed; 107 stream.onClosed = onClosed;
108 108
109 donePort.receive((x,y) => donePort.close()); 109 donePort.receive((x,y) => donePort.close());
110 } 110 }
111 111
112 void testListOutputStream4() {
113 ListOutputStream stream = new ListOutputStream();
114 ReceivePort donePort = new ReceivePort();
115 List result = <int>[];
116
117 void onData() => result.addAll(stream.read());
118
119 void onClosed() {
120 Expect.equals(4, result.length);
121 for (var i = 0; i < result.length; i++) Expect.equals(i + 1, result[i]);
122 donePort.toSendPort().send(null);
123 }
124
125 stream.onData = onData;
126 stream.onClosed = onClosed;
127
128 new Timer(0, (_) {
129 result.add(1);
130 stream.write([2]);
131
132 new Timer(0, (_) {
133 result.add(3);
134 stream.write([4]);
135 stream.close();
136 });
137 });
138
139 donePort.receive((x,y) => donePort.close());
140 }
141
112 main() { 142 main() {
113 testEmptyListOutputStream1(); 143 testEmptyListOutputStream1();
114 testEmptyListOutputStream2(); 144 testEmptyListOutputStream2();
115 testListOutputStream1(); 145 testListOutputStream1();
116 testListOutputStream2(); 146 testListOutputStream2();
117 testListOutputStream3(); 147 testListOutputStream3();
148 testListOutputStream4();
118 } 149 }
OLDNEW
« no previous file with comments | « tests/standalone/io/list_input_stream_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698