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('').createTempSync(); | 10 Directory tempDirectory = new Directory('').createTempSync(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 file.create().then((ignore) { | 48 file.create().then((ignore) { |
49 OutputStream stream = file.openOutputStream(); | 49 OutputStream stream = file.openOutputStream(); |
50 final total = 100; | 50 final total = 100; |
51 var count = 0; | 51 var count = 0; |
52 stream.onNoPendingWrites = () { | 52 stream.onNoPendingWrites = () { |
53 stream.write([count++]); | 53 stream.write([count++]); |
54 if (count == total) { | 54 if (count == total) { |
55 stream.close(); | 55 stream.close(); |
56 } | 56 } |
57 stream.onClosed = () { | 57 stream.onClosed = () { |
58 List buffer = new List<int>(total); | 58 List buffer = new List<int>.fixedLength(total); |
59 File fileSync = new File(fileName); | 59 File fileSync = new File(fileName); |
60 var openedFile = fileSync.openSync(); | 60 var openedFile = fileSync.openSync(); |
61 openedFile.readListSync(buffer, 0, total); | 61 openedFile.readListSync(buffer, 0, total); |
62 for (var i = 0; i < total; i++) { | 62 for (var i = 0; i < total; i++) { |
63 Expect.equals(i, buffer[i]); | 63 Expect.equals(i, buffer[i]); |
64 } | 64 } |
65 openedFile.closeSync(); | 65 openedFile.closeSync(); |
66 fileSync.deleteSync(); | 66 fileSync.deleteSync(); |
67 done.toSendPort().send("done"); | 67 done.toSendPort().send("done"); |
68 }; | 68 }; |
(...skipping 28 matching lines...) Expand all Loading... |
97 }; | 97 }; |
98 x.close(); | 98 x.close(); |
99 x.onError = (e) => Expect.fail("No error expected"); | 99 x.onError = (e) => Expect.fail("No error expected"); |
100 } | 100 } |
101 | 101 |
102 main() { | 102 main() { |
103 testOpenOutputStreamSync(); | 103 testOpenOutputStreamSync(); |
104 testOutputStreamNoPendingWrite(); | 104 testOutputStreamNoPendingWrite(); |
105 testOutputStreamFlush(); | 105 testOutputStreamFlush(); |
106 } | 106 } |
OLD | NEW |