OLD | NEW |
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('').createTempSync(); |
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(); | |
20 String fileName = "${tempDirectory.path}/test"; | 19 String fileName = "${tempDirectory.path}/test"; |
21 File file = new File(fileName); | 20 File file = new File(fileName); |
22 file.createSync(); | 21 file.createSync(); |
23 OutputStream x = file.openOutputStream(); | 22 OutputStream x = file.openOutputStream(); |
24 x.write([65, 66, 67]); | 23 x.write([65, 66, 67]); |
25 x.close(); | 24 x.close(); |
26 x.onClosed = () { | 25 x.onClosed = () { |
27 file.deleteSync(); | 26 file.deleteSync(); |
28 done.toSendPort().send("done"); | 27 done.toSendPort().send("done"); |
29 }; | 28 }; |
30 } | 29 } |
31 | 30 |
32 | 31 |
33 void testOutputStreamNoPendingWrite() { | 32 void testOutputStreamNoPendingWrite() { |
34 Directory tempDirectory = new Directory(''); | 33 var tempDirectory; |
35 | 34 |
36 // Create a port for waiting on the final result of this test. | 35 // Create a port for waiting on the final result of this test. |
37 ReceivePort done = new ReceivePort(); | 36 ReceivePort done = new ReceivePort(); |
38 done.receive((message, replyTo) { | 37 done.receive((message, replyTo) { |
39 tempDirectory.deleteRecursively(() { | 38 tempDirectory.deleteRecursively().then((ignore) => done.close()); |
40 done.close(); | |
41 }); | |
42 }); | 39 }); |
43 | 40 |
44 tempDirectory.createTemp(() { | 41 new Directory('').createTemp().then((temp) { |
| 42 tempDirectory = temp; |
45 String fileName = "${tempDirectory.path}/test"; | 43 String fileName = "${tempDirectory.path}/test"; |
46 File file = new File(fileName); | 44 File file = new File(fileName); |
47 file.create(() { | 45 file.create().then((ignore) { |
48 OutputStream stream = file.openOutputStream(); | 46 OutputStream stream = file.openOutputStream(); |
49 final total = 100; | 47 final total = 100; |
50 var count = 0; | 48 var count = 0; |
51 stream.onNoPendingWrites = () { | 49 stream.onNoPendingWrites = () { |
52 stream.write([count++]); | 50 stream.write([count++]); |
53 if (count == total) { | 51 if (count == total) { |
54 stream.close(); | 52 stream.close(); |
55 } | 53 } |
56 stream.onClosed = () { | 54 stream.onClosed = () { |
57 List buffer = new List<int>(total); | 55 List buffer = new List<int>(total); |
(...skipping 10 matching lines...) Expand all Loading... |
68 }; | 66 }; |
69 }); | 67 }); |
70 }); | 68 }); |
71 } | 69 } |
72 | 70 |
73 | 71 |
74 main() { | 72 main() { |
75 testOpenOutputStreamSync(); | 73 testOpenOutputStreamSync(); |
76 testOutputStreamNoPendingWrite(); | 74 testOutputStreamNoPendingWrite(); |
77 } | 75 } |
OLD | NEW |