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

Side by Side Diff: tests/standalone/src/FileOutputStreamTest.dart

Issue 9487005: Move back to having File.open{Input,Output}Stream return the stream directly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Testing file input stream, VM-only, standalone test. 4 // Testing file input stream, VM-only, standalone test.
5 5
6 #import("dart:io"); 6 #import("dart:io");
7 #import("dart:isolate"); 7 #import("dart:isolate");
8 8
9 void testOpenOutputStreamSync() { 9 void testOpenOutputStreamSync() {
10 Directory tempDirectory = new Directory(''); 10 Directory tempDirectory = new Directory('');
11 11
12 // Create a port for waiting on the final result of this test. 12 // Create a port for waiting on the final result of this test.
13 ReceivePort done = new ReceivePort(); 13 ReceivePort done = new ReceivePort();
14 done.receive((message, replyTo) { 14 done.receive((message, replyTo) {
15 tempDirectory.deleteSync(); 15 tempDirectory.deleteSync();
16 done.close(); 16 done.close();
17 }); 17 });
18 18
19 tempDirectory.createTempSync(); 19 tempDirectory.createTempSync();
20 String fileName = "${tempDirectory.path}/test"; 20 String fileName = "${tempDirectory.path}/test";
21 File file = new File(fileName); 21 File file = new File(fileName);
22 file.createSync(); 22 file.createSync();
23 OutputStream x = file.openOutputStreamSync(); 23 OutputStream x = file.openOutputStream();
24 x.write([65, 66, 67]); 24 x.write([65, 66, 67]);
25 x.close(); 25 x.close();
26 x.closeHandler = () { 26 x.closeHandler = () {
27 file.deleteSync(); 27 file.deleteSync();
28 done.toSendPort().send("done"); 28 done.toSendPort().send("done");
29 }; 29 };
30 } 30 }
31 31
32 32
33 void testOpenOutputStreamAsync() {
34 Directory tempDirectory = new Directory('');
35
36 // Create a port for waiting on the final result of this test.
37 ReceivePort done = new ReceivePort();
38 done.receive((message, replyTo) {
39 tempDirectory.delete();
40 tempDirectory.deleteHandler = () {
41 done.close();
42 };
43 });
44
45 tempDirectory.createTemp();
46 tempDirectory.createTempHandler = () {
47 String fileName = "${tempDirectory.path}/test";
48 File file = new File(fileName);
49 file.create();
50 file.createHandler = () {
51 file.openOutputStream();
52 file.outputStreamHandler = (OutputStream stream) {
53 stream.close();
54 stream.closeHandler = () {
55 file.delete();
56 };
57 };
58 };
59 file.deleteHandler = () {
60 done.toSendPort().send("done");
61 };
62 };
63 }
64
65
66 void testOutputStreamNoPendingWrite() { 33 void testOutputStreamNoPendingWrite() {
67 Directory tempDirectory = new Directory(''); 34 Directory tempDirectory = new Directory('');
68 35
69 // Create a port for waiting on the final result of this test. 36 // Create a port for waiting on the final result of this test.
70 ReceivePort done = new ReceivePort(); 37 ReceivePort done = new ReceivePort();
71 done.receive((message, replyTo) { 38 done.receive((message, replyTo) {
72 tempDirectory.delete(); 39 tempDirectory.delete();
73 tempDirectory.deleteHandler = () { 40 tempDirectory.deleteHandler = () {
74 done.close(); 41 done.close();
75 }; 42 };
76 }); 43 });
77 44
78 tempDirectory.createTemp(); 45 tempDirectory.createTemp();
79 tempDirectory.createTempHandler = () { 46 tempDirectory.createTempHandler = () {
80 String fileName = "${tempDirectory.path}/test"; 47 String fileName = "${tempDirectory.path}/test";
81 File file = new File(fileName); 48 File file = new File(fileName);
82 file.create(); 49 file.create();
83 file.createHandler = () { 50 file.createHandler = () {
84 file.openOutputStream(); 51 OutputStream stream = file.openOutputStream();
85 file.outputStreamHandler = (OutputStream stream) { 52 final total = 100;
86 final total = 100; 53 var count = 0;
87 var count = 0; 54 stream.noPendingWriteHandler = () {
88 stream.noPendingWriteHandler = () { 55 stream.write([count++]);
89 stream.write([count++]); 56 if (count == total) {
90 if (count == total) { 57 stream.close();
91 stream.close(); 58 }
92 }
93 };
94 stream.closeHandler = () { 59 stream.closeHandler = () {
95 List buffer = new List<int>(total); 60 List buffer = new List<int>(total);
96 File fileSync = new File(fileName); 61 File fileSync = new File(fileName);
97 var openedFile = fileSync.openSync(); 62 var openedFile = fileSync.openSync();
98 openedFile.readListSync(buffer, 0, total); 63 openedFile.readListSync(buffer, 0, total);
99 for (var i = 0; i < total; i++) { 64 for (var i = 0; i < total; i++) {
100 Expect.equals(i, buffer[i]); 65 Expect.equals(i, buffer[i]);
101 } 66 }
102 openedFile.closeSync(); 67 openedFile.closeSync();
103 fileSync.deleteSync(); 68 fileSync.deleteSync();
104 done.toSendPort().send("done"); 69 done.toSendPort().send("done");
105 }; 70 };
106 }; 71 };
107 }; 72 };
108 }; 73 };
109 } 74 }
110 75
111 76
112 main() { 77 main() {
113 testOpenOutputStreamSync(); 78 testOpenOutputStreamSync();
114 testOpenOutputStreamAsync();
115 testOutputStreamNoPendingWrite(); 79 testOutputStreamNoPendingWrite();
116 } 80 }
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