| OLD | NEW |
| 1 // Copyright (c) 2011, 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 test1() { | 7 void test1() { |
| 8 void testWithChunkSize(var data, int chunkSize, Function testDone) { | 8 void testWithChunkSize(var data, int chunkSize, Function testDone) { |
| 9 InputStream s = new ListInputStream(data); | 9 InputStream list_input_stream = new ListInputStream(); |
| 10 ChunkedInputStream stream = new ChunkedInputStream(s); | 10 list_input_stream.write(data); |
| 11 list_input_stream.markEndOfStream(); |
| 12 ChunkedInputStream stream = new ChunkedInputStream(list_input_stream); |
| 11 int chunkCount = 0; | 13 int chunkCount = 0; |
| 12 int byteCount = 0; | 14 int byteCount = 0; |
| 13 void chunkData() { | 15 void chunkData() { |
| 14 List<int> chunk = stream.read(); | 16 List<int> chunk = stream.read(); |
| 15 if (byteCount + chunkSize < data.length) { | 17 if (byteCount + chunkSize < data.length) { |
| 16 Expect.equals(chunkSize, chunk.length); | 18 Expect.equals(chunkSize, chunk.length); |
| 17 } else { | 19 } else { |
| 18 if (byteCount == data.length) { | 20 if (byteCount == data.length) { |
| 19 Expect.equals(null, chunk); | 21 Expect.equals(null, chunk); |
| 20 } else { | 22 } else { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Expect.equals(data.length, byteCount); | 60 Expect.equals(data.length, byteCount); |
| 59 } | 61 } |
| 60 | 62 |
| 61 testWithChunkSize(data, 512, testDone); | 63 testWithChunkSize(data, 512, testDone); |
| 62 testWithChunkSize(data, 1024, testDone); | 64 testWithChunkSize(data, 1024, testDone); |
| 63 testWithChunkSize(data, 2048, testDone); | 65 testWithChunkSize(data, 2048, testDone); |
| 64 } | 66 } |
| 65 | 67 |
| 66 | 68 |
| 67 void test2() { | 69 void test2() { |
| 68 InputStream s = new DynamicListInputStream(); | 70 InputStream s = new ListInputStream(); |
| 69 ChunkedInputStream stream = new ChunkedInputStream(s); | 71 ChunkedInputStream stream = new ChunkedInputStream(s); |
| 70 stream.chunkSize = 5; | 72 stream.chunkSize = 5; |
| 71 ReceivePort donePort = new ReceivePort(); | 73 ReceivePort donePort = new ReceivePort(); |
| 72 | 74 |
| 73 var stage = 0; | 75 var stage = 0; |
| 74 | 76 |
| 75 void chunkData() { | 77 void chunkData() { |
| 76 var chunk; | 78 var chunk; |
| 77 if (stage == 0) { | 79 if (stage == 0) { |
| 78 Expect.equals(stream.chunkSize, 5); | 80 Expect.equals(stream.chunkSize, 5); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 s.write([4, 5, 6]); // 7 bytes written to stream. | 130 s.write([4, 5, 6]); // 7 bytes written to stream. |
| 129 | 131 |
| 130 donePort.receive((x,y) => donePort.close()); | 132 donePort.receive((x,y) => donePort.close()); |
| 131 } | 133 } |
| 132 | 134 |
| 133 | 135 |
| 134 main() { | 136 main() { |
| 135 test1(); | 137 test1(); |
| 136 test2(); | 138 test2(); |
| 137 } | 139 } |
| OLD | NEW |