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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/src/FileInputStreamTest.dart ('k') | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // Testing file input stream, VM-only, standalone test.
5
6 #import("dart:io");
7
8 void testOpenOutputStreamSync() {
9 Directory tempDirectory = new Directory('');
10
11 // Create a port for waiting on the final result of this test.
12 ReceivePort done = new ReceivePort();
13 done.receive((message, replyTo) {
14 tempDirectory.deleteSync();
15 done.close();
16 });
17
18 tempDirectory.createTempSync();
19 String fileName = "${tempDirectory.path}/test";
20 File file = new File(fileName);
21 file.createSync();
22 OutputStream x = file.openOutputStreamSync();
23 x.write([65, 66, 67]);
24 x.close();
25 x.closeHandler = () {
26 file.deleteSync();
27 done.toSendPort().send("done");
28 };
29 }
30
31
32 void testOpenOutputStreamAsync() {
33 Directory tempDirectory = new Directory('');
34
35 // Create a port for waiting on the final result of this test.
36 ReceivePort done = new ReceivePort();
37 done.receive((message, replyTo) {
38 tempDirectory.delete();
39 tempDirectory.deleteHandler = () {
40 done.close();
41 };
42 });
43
44 tempDirectory.createTemp();
45 tempDirectory.createTempHandler = () {
46 String fileName = "${tempDirectory.path}/test";
47 File file = new File(fileName);
48 file.create();
49 file.createHandler = () {
50 file.openOutputStream();
51 file.outputStreamHandler = (OutputStream stream) {
52 stream.close();
53 stream.closeHandler = () {
54 file.delete();
55 };
56 };
57 };
58 file.deleteHandler = () {
59 done.toSendPort().send("done");
60 };
61 };
62 }
63
64
65 void testOutputStreamNoPendingWrite() {
66 Directory tempDirectory = new Directory('');
67
68 // Create a port for waiting on the final result of this test.
69 ReceivePort done = new ReceivePort();
70 done.receive((message, replyTo) {
71 tempDirectory.delete();
72 tempDirectory.deleteHandler = () {
73 done.close();
74 };
75 });
76
77 tempDirectory.createTemp();
78 tempDirectory.createTempHandler = () {
79 String fileName = "${tempDirectory.path}/test";
80 File file = new File(fileName);
81 file.create();
82 file.createHandler = () {
83 file.openOutputStream();
84 file.outputStreamHandler = (OutputStream stream) {
85 final total = 100;
86 var count = 0;
87 stream.noPendingWriteHandler = () {
88 stream.write([count++]);
89 if (count == total) {
90 stream.close();
91 }
92 };
93 stream.closeHandler = () {
94 List buffer = new List<int>(total);
95 File fileSync = new File(fileName);
96 var openedFile = fileSync.openSync();
97 openedFile.readListSync(buffer, 0, total);
98 for (var i = 0; i < total; i++) {
99 Expect.equals(i, buffer[i]);
100 }
101 openedFile.closeSync();
102 fileSync.deleteSync();
103 done.toSendPort().send("done");
104 };
105 };
106 };
107 };
108 }
109
110
111 main() {
112 testOpenOutputStreamSync();
113 testOpenOutputStreamAsync();
114 testOutputStreamNoPendingWrite();
115 }
OLDNEW
« 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