Chromium Code Reviews| Index: tests/standalone/src/FileOutputStreamTest.dart |
| diff --git a/tests/standalone/src/FileOutputStreamTest.dart b/tests/standalone/src/FileOutputStreamTest.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a4891f23c5c8fa221f678ea34477ba4bb4363940 |
| --- /dev/null |
| +++ b/tests/standalone/src/FileOutputStreamTest.dart |
| @@ -0,0 +1,111 @@ |
| +// 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. |
| + |
| +#import("dart:io"); |
| + |
| +void testOpenOutputStreamSync() { |
| + Directory tempDirectory = new Directory(''); |
| + |
| + // Create a port for waiting on the final result of this test. |
| + ReceivePort done = new ReceivePort(); |
| + done.receive((message, replyTo) { |
| + tempDirectory.deleteSync(); |
| + done.close(); |
| + }); |
| + |
| + tempDirectory.createTempSync(); |
| + String fileName = "${tempDirectory.path}/test"; |
| + File file = new File(fileName); |
| + file.createSync(); |
| + OutputStream x = file.openOutputStreamSync(); |
| + x.write([65, 66, 67]); |
| + x.close(); |
| + x.closeHandler = () { |
| + file.deleteSync(); |
| + done.toSendPort().send("done"); |
| + }; |
| +} |
| + |
| + |
| +void testOpenOutputStreamAsync() { |
| + Directory tempDirectory = new Directory(''); |
| + |
| + // Create a port for waiting on the final result of this test. |
| + ReceivePort done = new ReceivePort(); |
| + done.receive((message, replyTo) { |
| + tempDirectory.deleteSync(); |
|
Mads Ager (google)
2012/02/22 13:20:20
This really should be an async call. In fact, shou
Søren Gjesse
2012/02/22 14:03:18
Fixed, Directory does not check mixed sync/async -
|
| + done.close(); |
| + }); |
| + |
| + tempDirectory.createTemp(); |
| + tempDirectory.createTempHandler = () { |
| + String fileName = "${tempDirectory.path}/test"; |
| + File file = new File(fileName); |
| + file.create(); |
| + file.createHandler = () { |
| + file.openOutputStream(); |
| + file.outputStreamHandler = (OutputStream stream) { |
| + stream.close(); |
| + stream.closeHandler = () { |
| + file.delete(); |
| + }; |
| + }; |
| + }; |
| + file.deleteHandler = () { |
| + done.toSendPort().send("done"); |
| + }; |
| + }; |
| +} |
| + |
| + |
| +void testOutputStreamNoPendingWrite() { |
| + Directory tempDirectory = new Directory(''); |
| + |
| + // Create a port for waiting on the final result of this test. |
| + ReceivePort done = new ReceivePort(); |
| + done.receive((message, replyTo) { |
| + tempDirectory.deleteSync(); |
|
Mads Ager (google)
2012/02/22 13:20:20
Ditto.
Søren Gjesse
2012/02/22 14:03:18
Done.
|
| + done.close(); |
| + }); |
| + |
| + tempDirectory.createTemp(); |
| + tempDirectory.createTempHandler = () { |
| + String fileName = "${tempDirectory.path}/test"; |
| + File file = new File(fileName); |
| + file.create(); |
| + file.createHandler = () { |
| + file.openOutputStream(); |
| + file.outputStreamHandler = (OutputStream stream) { |
| + final total = 100; |
| + var count = 0; |
| + stream.noPendingWriteHandler = () { |
| + stream.write([count++]); |
| + if (count == total) { |
| + stream.close(); |
| + } |
| + }; |
| + stream.closeHandler = () { |
| + List buffer = new List<int>(total); |
| + File fileSync = new File(fileName); |
| + var openedFile = fileSync.openSync(); |
| + openedFile.readListSync(buffer, 0, total); |
| + for (var i = 0; i < total; i++) { |
| + Expect.equals(i, buffer[i]); |
| + } |
| + openedFile.closeSync(); |
| + fileSync.deleteSync(); |
| + done.toSendPort().send("done"); |
| + }; |
| + }; |
| + }; |
| + }; |
| +} |
| + |
| + |
| +main() { |
| + testOpenOutputStreamSync(); |
| + testOpenOutputStreamAsync(); |
| + testOutputStreamNoPendingWrite(); |
| +} |