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

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: 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
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.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 -
39 done.close();
40 });
41
42 tempDirectory.createTemp();
43 tempDirectory.createTempHandler = () {
44 String fileName = "${tempDirectory.path}/test";
45 File file = new File(fileName);
46 file.create();
47 file.createHandler = () {
48 file.openOutputStream();
49 file.outputStreamHandler = (OutputStream stream) {
50 stream.close();
51 stream.closeHandler = () {
52 file.delete();
53 };
54 };
55 };
56 file.deleteHandler = () {
57 done.toSendPort().send("done");
58 };
59 };
60 }
61
62
63 void testOutputStreamNoPendingWrite() {
64 Directory tempDirectory = new Directory('');
65
66 // Create a port for waiting on the final result of this test.
67 ReceivePort done = new ReceivePort();
68 done.receive((message, replyTo) {
69 tempDirectory.deleteSync();
Mads Ager (google) 2012/02/22 13:20:20 Ditto.
Søren Gjesse 2012/02/22 14:03:18 Done.
70 done.close();
71 });
72
73 tempDirectory.createTemp();
74 tempDirectory.createTempHandler = () {
75 String fileName = "${tempDirectory.path}/test";
76 File file = new File(fileName);
77 file.create();
78 file.createHandler = () {
79 file.openOutputStream();
80 file.outputStreamHandler = (OutputStream stream) {
81 final total = 100;
82 var count = 0;
83 stream.noPendingWriteHandler = () {
84 stream.write([count++]);
85 if (count == total) {
86 stream.close();
87 }
88 };
89 stream.closeHandler = () {
90 List buffer = new List<int>(total);
91 File fileSync = new File(fileName);
92 var openedFile = fileSync.openSync();
93 openedFile.readListSync(buffer, 0, total);
94 for (var i = 0; i < total; i++) {
95 Expect.equals(i, buffer[i]);
96 }
97 openedFile.closeSync();
98 fileSync.deleteSync();
99 done.toSendPort().send("done");
100 };
101 };
102 };
103 };
104 }
105
106
107 main() {
108 testOpenOutputStreamSync();
109 testOpenOutputStreamAsync();
110 testOutputStreamNoPendingWrite();
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698