Chromium Code Reviews| Index: tests/standalone/io/file_test.dart |
| diff --git a/tests/standalone/io/file_test.dart b/tests/standalone/io/file_test.dart |
| index 3411f8891f4d9c6a8c08d989e4bf11db6a53a3a7..b3145758216ceca9c2d24ccd11de154759948700 100644 |
| --- a/tests/standalone/io/file_test.dart |
| +++ b/tests/standalone/io/file_test.dart |
| @@ -164,6 +164,96 @@ class FileTest { |
| }; |
| } |
| + // Test for file stream buffered handling of large files. |
| + static void testReadWriteStreamLargeFile() { |
|
Anders Johnsen
2012/06/13 12:51:31
We should also test the case of using pipe:
Input
|
| + asyncTestStarted(); |
| + |
| + String filename = |
| + tempDirectory.path.concat("/out_read_write_stream_large_file"); |
|
Anders Johnsen
2012/06/13 12:51:31
What about using Options.executable?
Bill Hesse
2012/06/13 14:18:46
This also tests outputStream, and fits in with the
|
| + File file = new File(filename); |
| + OutputStream output = file.openOutputStream(); |
| + List<int> buffer = new List<int>(100000); |
| + for (var i = 0; i < buffer.length; ++i) { |
| + buffer[i] = i % 25 + 97; // The letters a through y. |
|
Anders Johnsen
2012/06/13 12:51:31
I don't think we should restrict it to normal char
Bill Hesse
2012/06/13 14:18:46
Done.
|
| + } |
| + bool writeDone = output.writeFrom(buffer, 0, 20000); |
| + Expect.equals(false, writeDone); |
|
Anders Johnsen
2012/06/13 12:51:31
We can not assume this.
Bill Hesse
2012/06/13 14:18:46
I guess not. Though it is true in this case.
|
| + output.onNoPendingWrites = () { |
| + output.writeFrom(buffer, 20000, 60000); |
| + output.writeFrom(buffer, 80000, 20000); |
| + output.onNoPendingWrites = () { |
| + output.writeFrom(buffer, 0, 0); |
| + output.writeFrom(buffer, 0, 0); |
| + output.writeFrom(buffer, 0, 100000); |
| + output.close(); |
| + }; |
| + }; |
| + output.onClosed = () { |
| + InputStream input = file.openInputStream(); |
| + int position = 0; |
| + final int expectedLength = 200000; |
| + // Start an independent asynchronous check on the length. |
| + asyncTestStarted(); |
| + file.length().then((len) { |
| + Expect.equals(expectedLength, len); |
| + asyncTestDone('testReadWriteStreamLargeFile: length check'); |
| + }); |
| + |
| + List<int> inputBuffer = new List<int>(expectedLength + 100000); |
| + // Immediate read should read 0 bytes. |
| + Expect.equals(0, input.available()); |
|
Anders Johnsen
2012/06/13 12:51:31
The tests here, and below, could be moved to a iso
Bill Hesse
2012/06/13 14:18:46
It is really not a natural test, "All read but not
|
| + Expect.equals(false, input.closed); |
| + int bytesRead = input.readInto(inputBuffer); |
| + Expect.equals(0, bytesRead); |
| + Expect.equals(0, input.available()); |
| + Expect.isFalse(input.closed); |
| + input.onError = (e) { |
| + print('Error handler called on input in testReadWriteStreamLargeFile'); |
| + print('with error $e'); |
| + throw e; |
| + }; |
| + input.onData = () { |
| + Expect.isFalse(input.closed); |
| + bytesRead = input.readInto(inputBuffer, offset: position, |
| + len: inputBuffer.length - position); |
| + position += bytesRead; |
| + // The buffer is large enough to hold all available data. |
| + // So there should be no data left to read. |
| + Expect.equals(0, input.available()); |
| + bytesRead = input.readInto(inputBuffer, offset: position, |
| + len: expectedLength - position); |
| + Expect.equals(0, bytesRead); |
| + Expect.equals(0, input.available()); |
| + Expect.isFalse(input.closed); |
| + }; |
| + input.onClosed = () { |
| + Expect.equals(0, input.available()); |
| + Expect.isTrue(input.closed); |
| + input.close(); // This should be safe to call. |
| + |
| + Expect.equals(expectedLength, position); |
| + for (int i = 0; i < position; ++i) { |
| + Expect.equals(buffer[i % buffer.length], inputBuffer[i]); |
| + } |
| + |
| + Future futureDeleted = file.delete(); |
| + futureDeleted.handleException((e) { |
| + print('Exception while deleting ReadWriteStreamLargeFile file'); |
| + print('Exception $e'); |
| + return false; // Throw exception further. |
| + }); |
| + futureDeleted.then((ignored) { |
| + asyncTestDone('testReadWriteStreamLargeFile: main test'); |
| + }); |
| + }; |
| + // Try a read again after handlers are set. |
| + bytesRead = input.readInto(inputBuffer); |
| + Expect.equals(0, bytesRead); |
| + Expect.equals(0, input.available()); |
| + Expect.isFalse(input.closed); |
| + }; |
| + } |
| + |
| static void testRead() { |
| ReceivePort port = new ReceivePort(); |
| // Read a file and check part of it's contents. |
| @@ -1082,6 +1172,7 @@ class FileTest { |
| testReadWriteStream(); |
| testReadEmptyFileSync(); |
| testReadEmptyFile(); |
| + testReadWriteStreamLargeFile(); |
| testTruncate(); |
| testTruncateSync(); |
| testCloseException(); |