Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Unified Diff: tests/standalone/src/FileOutputStreamTest.dart

Issue 9432023: Add both sync and async methods for getting streams for a File (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+}

Powered by Google App Engine
This is Rietveld 408576698