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

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: Addressed review comments from ager@ 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
« no previous file with comments | « tests/standalone/src/FileInputStreamTest.dart ('k') | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..847d93cea8c64e615b4045b963d4fe0460c16737
--- /dev/null
+++ b/tests/standalone/src/FileOutputStreamTest.dart
@@ -0,0 +1,115 @@
+// 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.delete();
+ tempDirectory.deleteHandler = () {
+ 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.delete();
+ tempDirectory.deleteHandler = () {
+ 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();
+}
« no previous file with comments | « tests/standalone/src/FileInputStreamTest.dart ('k') | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698