Chromium Code Reviews| Index: tests/standalone/src/FileInputStreamTest.dart |
| diff --git a/tests/standalone/src/FileInputStreamTest.dart b/tests/standalone/src/FileInputStreamTest.dart |
| index adc21fa5fadd54033f80bd55c7c2ed180b67db6b..2a2204a9cd3a369ad0e49cda46d644ae68fe0a93 100644 |
| --- a/tests/standalone/src/FileInputStreamTest.dart |
| +++ b/tests/standalone/src/FileInputStreamTest.dart |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| // Testing file input stream, VM-only, standalone test. |
| @@ -14,7 +14,7 @@ void testStringInputStreamSync() { |
| String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| // File contains "Hello Dart\nwassup!\n" |
| File file = new File(fileName); |
| - StringInputStream x = new StringInputStream(file.openInputStream()); |
| + StringInputStream x = new StringInputStream(file.openInputStreamSync()); |
| x.lineHandler = () { |
| // The file input stream is known (for now) to have read the whole |
| // file when the data handler is called. |
| @@ -29,7 +29,7 @@ void testInputStreamAsync() { |
| String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| // File contains "Hello Dart\nwassup!\n" |
| var expected = "Hello Dart\nwassup!\n".charCodes(); |
| - InputStream x = (new File(fileName)).openInputStream(); |
| + InputStream x = (new File(fileName)).openInputStreamSync(); |
| var byteCount = 0; |
| x.dataHandler = () { |
| Expect.equals(expected[byteCount], x.read(1)[0]); |
| @@ -46,7 +46,7 @@ void testStringInputStreamAsync(String name, int length) { |
| // File contains 10 lines. |
| File file = new File(fileName); |
| Expect.equals(length, file.openSync().lengthSync()); |
| - StringInputStream x = new StringInputStream(file.openInputStream()); |
| + StringInputStream x = new StringInputStream(file.openInputStreamSync()); |
| int lineCount = 0; |
| x.lineHandler = () { |
| var line = x.readLine(); |
| @@ -66,7 +66,7 @@ void testChunkedInputStream() { |
| String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| // File contains 19 bytes ("Hello Dart\nwassup!") |
| File file = new File(fileName); |
| - ChunkedInputStream x = new ChunkedInputStream(file.openInputStream()); |
| + ChunkedInputStream x = new ChunkedInputStream(file.openInputStreamSync()); |
| x.chunkSize = 9; |
| List<int> chunk = x.read(); |
| Expect.equals(9, chunk.length); |
| @@ -80,13 +80,41 @@ void testChunkedInputStream() { |
| } |
| +void testOpenInputStreamAsync() { |
| + // Create a port for waiting on the final result of this test. |
| + ReceivePort done = new ReceivePort(); |
| + done.receive((message, replyTo) { |
| + done.close(); |
| + }); |
| + |
| + // Test using the asynchronous way of opening an input stream. |
| + String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); |
| + File file = new File(fileName); |
| + file.exists(); |
| + file.existsHandler = (exists) { |
| + if (exists) { |
| + file.openInputStream(); |
| + } else { |
| + Expect.fail("Test file not found"); |
| + } |
| + }; |
| + file.inputStreamHandler = (InputStream stream) { |
| + done.toSendPort().send("Got an InputStream"); |
| + }; |
| + file.errorHandler = (String error) { |
| + Expect.fail("Error $error"); |
| + }; |
| +} |
| + |
| + |
| main() { |
| testStringInputStreamSync(); |
| testInputStreamAsync(); |
| // Check the length of these files as both are text files where one |
| // is without a terminating line separator which can easily be added |
| // back if accidentally opened in a text editor. |
| - testStringInputStreamAsync("readline_test1.dat", 111); |
| + //testStringInputStreamAsync("readline_test1.dat", 111); |
|
Mads Ager (google)
2012/02/22 13:20:20
Accidental edit?
Søren Gjesse
2012/02/22 14:03:18
Yes.
|
| testStringInputStreamAsync("readline_test2.dat", 114); |
| testChunkedInputStream(); |
| + testOpenInputStreamAsync(); |
| } |