| OLD | NEW |
| 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 "No data expected"; | 10 throw "No data expected"; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 InputStream input = new ListInputStream(data); | 131 InputStream input = new ListInputStream(data); |
| 132 input.closeHandler = onClose; | 132 input.closeHandler = onClose; |
| 133 input.pipe(output, close: false); | 133 input.pipe(output, close: false); |
| 134 count++; | 134 count++; |
| 135 | 135 |
| 136 donePort.receive((x,y) => donePort.close()); | 136 donePort.receive((x,y) => donePort.close()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void testDynamicListInputStream1() { | 139 void testListInputClose1() { |
| 140 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 141 InputStream stream = new ListInputStream(data); |
| 142 ReceivePort donePort = new ReceivePort(); |
| 143 |
| 144 void onData() { |
| 145 throw "No data expected"; |
| 146 } |
| 147 |
| 148 void onClose() { |
| 149 donePort.toSendPort().send(null); |
| 150 } |
| 151 |
| 152 stream.dataHandler = onData; |
| 153 stream.closeHandler = onClose; |
| 154 stream.close(); |
| 155 |
| 156 donePort.receive((x,y) => donePort.close()); |
| 157 } |
| 158 |
| 159 void testListInputClose2() { |
| 160 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 161 InputStream stream = new ListInputStream(data); |
| 162 ReceivePort donePort = new ReceivePort(); |
| 163 int count = 0; |
| 164 |
| 165 void onData() { |
| 166 count += stream.read(2).length; |
| 167 stream.close(); |
| 168 } |
| 169 |
| 170 void onClose() { |
| 171 Expect.equals(2, count); |
| 172 donePort.toSendPort().send(count); |
| 173 } |
| 174 |
| 175 stream.dataHandler = onData; |
| 176 stream.closeHandler = onClose; |
| 177 |
| 178 donePort.receive((x,y) => donePort.close()); |
| 179 } |
| 180 |
| 181 void testDynamicListInputStream() { |
| 140 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 182 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 141 InputStream stream = new DynamicListInputStream(); | 183 InputStream stream = new DynamicListInputStream(); |
| 142 int count = 0; | 184 int count = 0; |
| 143 ReceivePort donePort = new ReceivePort(); | 185 ReceivePort donePort = new ReceivePort(); |
| 144 | 186 |
| 145 void onData() { | 187 void onData() { |
| 146 List<int> x = stream.read(1); | 188 List<int> x = stream.read(1); |
| 147 Expect.equals(1, x.length); | 189 Expect.equals(1, x.length); |
| 148 x = stream.read(); | 190 x = stream.read(); |
| 149 Expect.equals(9, x.length); | 191 Expect.equals(9, x.length); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 donePort.toSendPort().send(count); | 202 donePort.toSendPort().send(count); |
| 161 } | 203 } |
| 162 | 204 |
| 163 stream.write(data); | 205 stream.write(data); |
| 164 stream.dataHandler = onData; | 206 stream.dataHandler = onData; |
| 165 stream.closeHandler = onClose; | 207 stream.closeHandler = onClose; |
| 166 | 208 |
| 167 donePort.receive((x,y) => donePort.close()); | 209 donePort.receive((x,y) => donePort.close()); |
| 168 } | 210 } |
| 169 | 211 |
| 212 void testDynamicListInputClose1() { |
| 213 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 214 InputStream stream = new DynamicListInputStream(); |
| 215 ReceivePort donePort = new ReceivePort(); |
| 216 |
| 217 void onData() { |
| 218 throw "No data expected"; |
| 219 } |
| 220 |
| 221 void onClose() { |
| 222 donePort.toSendPort().send(null); |
| 223 } |
| 224 |
| 225 stream.write(data); |
| 226 stream.dataHandler = onData; |
| 227 stream.closeHandler = onClose; |
| 228 stream.close(); |
| 229 Expect.throws(() => stream.write(data), (e) => e is StreamException); |
| 230 |
| 231 donePort.receive((x,y) => donePort.close()); |
| 232 } |
| 233 |
| 234 void testDynamicListInputClose2() { |
| 235 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 236 InputStream stream = new DynamicListInputStream(); |
| 237 ReceivePort donePort = new ReceivePort(); |
| 238 int count = 0; |
| 239 |
| 240 void onData() { |
| 241 count += stream.read(15).length; |
| 242 stream.close(); |
| 243 Expect.throws(() => stream.write(data), (e) => e is StreamException); |
| 244 } |
| 245 |
| 246 void onClose() { |
| 247 Expect.equals(15, count); |
| 248 donePort.toSendPort().send(null); |
| 249 } |
| 250 |
| 251 stream.write(data); |
| 252 stream.write(data); |
| 253 stream.write(data); |
| 254 stream.dataHandler = onData; |
| 255 stream.closeHandler = onClose; |
| 256 |
| 257 donePort.receive((x,y) => donePort.close()); |
| 258 } |
| 259 |
| 170 main() { | 260 main() { |
| 171 testEmptyListInputStream(); | 261 testEmptyListInputStream(); |
| 172 testEmptyDynamicListInputStream(); | 262 testEmptyDynamicListInputStream(); |
| 173 testListInputStream1(); | 263 testListInputStream1(); |
| 174 testListInputStream2(); | 264 testListInputStream2(); |
| 175 testListInputStreamPipe1(); | 265 testListInputStreamPipe1(); |
| 176 testListInputStreamPipe2(); | 266 testListInputStreamPipe2(); |
| 177 testDynamicListInputStream1(); | 267 testListInputClose1(); |
| 268 testListInputClose2(); |
| 269 testDynamicListInputStream(); |
| 270 testDynamicListInputClose1(); |
| 271 testDynamicListInputClose2(); |
| 178 } | 272 } |
| OLD | NEW |