| 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 // Testing FileInputStream, VM-only, standalone test. | 4 // Testing FileInputStream, VM-only, standalone test. |
| 5 | 5 |
| 6 // Helper method to be able to run the test from the runtime | 6 // Helper method to be able to run the test from the runtime |
| 7 // directory, or the top directory. | 7 // directory, or the top directory. |
| 8 String getFilename(String path) => | 8 String getFilename(String path) => |
| 9 new File(path).existsSync() ? path : '../' + path; | 9 new File(path).existsSync() ? path : '../' + path; |
| 10 | 10 |
| 11 main() { | 11 void testStringInputStream() { |
| 12 String fName = getFilename("tests/standalone/src/readuntil_test.dat"); | 12 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| 13 // File contains "Hello Dart\nwassup!" | 13 // File contains "Hello Dart\nwassup!" |
| 14 File file = new File(fName); | 14 File file = new File(fileName); |
| 15 file.openSync(); | 15 file.openSync(); |
| 16 StringInputStream x = new StringInputStream(file.openInputStream()); | 16 StringInputStream x = new StringInputStream(file.openInputStream()); |
| 17 String line = x.readLine(); | 17 String line = x.readLine(); |
| 18 Expect.equals("Hello Dart", line); | 18 Expect.equals("Hello Dart", line); |
| 19 file.closeSync(); | 19 file.closeSync(); |
| 20 line = x.readLine(); | 20 line = x.readLine(); |
| 21 Expect.equals("wassup!", line); | 21 Expect.equals("wassup!", line); |
| 22 } | 22 } |
| 23 |
| 24 void testChunkedInputStream() { |
| 25 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| 26 // File contains 19 bytes ("Hello Dart\nwassup!") |
| 27 File file = new File(fileName); |
| 28 file.openSync(); |
| 29 ChunkedInputStream x = new ChunkedInputStream(file.openInputStream()); |
| 30 x.chunkSize = 9; |
| 31 List<int> chunk = x.read(); |
| 32 Expect.equals(9, chunk.length); |
| 33 file.closeSync(); |
| 34 x.chunkSize = 5; |
| 35 chunk = x.read(); |
| 36 Expect.equals(5, chunk.length); |
| 37 chunk = x.read(); |
| 38 Expect.equals(5, chunk.length); |
| 39 chunk = x.read(); |
| 40 Expect.equals(null, chunk); |
| 41 } |
| 42 |
| 43 main() { |
| 44 testStringInputStream(); |
| 45 testChunkedInputStream(); |
| 46 } |
| OLD | NEW |