| OLD | NEW |
| (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 #import("dart:isolate"); | |
| 8 | |
| 9 void testOpenOutputStreamSync() { | |
| 10 Directory tempDirectory = new Directory(''); | |
| 11 | |
| 12 // Create a port for waiting on the final result of this test. | |
| 13 ReceivePort done = new ReceivePort(); | |
| 14 done.receive((message, replyTo) { | |
| 15 tempDirectory.deleteSync(); | |
| 16 done.close(); | |
| 17 }); | |
| 18 | |
| 19 tempDirectory.createTempSync(); | |
| 20 String fileName = "${tempDirectory.path}/test"; | |
| 21 File file = new File(fileName); | |
| 22 file.createSync(); | |
| 23 OutputStream x = file.openOutputStream(); | |
| 24 x.write([65, 66, 67]); | |
| 25 x.close(); | |
| 26 x.onClosed = () { | |
| 27 file.deleteSync(); | |
| 28 done.toSendPort().send("done"); | |
| 29 }; | |
| 30 } | |
| 31 | |
| 32 | |
| 33 void testOutputStreamNoPendingWrite() { | |
| 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.deleteRecursively(() { | |
| 40 done.close(); | |
| 41 }); | |
| 42 }); | |
| 43 | |
| 44 tempDirectory.createTemp(() { | |
| 45 String fileName = "${tempDirectory.path}/test"; | |
| 46 File file = new File(fileName); | |
| 47 file.create(() { | |
| 48 OutputStream stream = file.openOutputStream(); | |
| 49 final total = 100; | |
| 50 var count = 0; | |
| 51 stream.onNoPendingWrites = () { | |
| 52 stream.write([count++]); | |
| 53 if (count == total) { | |
| 54 stream.close(); | |
| 55 } | |
| 56 stream.onClosed = () { | |
| 57 List buffer = new List<int>(total); | |
| 58 File fileSync = new File(fileName); | |
| 59 var openedFile = fileSync.openSync(); | |
| 60 openedFile.readListSync(buffer, 0, total); | |
| 61 for (var i = 0; i < total; i++) { | |
| 62 Expect.equals(i, buffer[i]); | |
| 63 } | |
| 64 openedFile.closeSync(); | |
| 65 fileSync.deleteSync(); | |
| 66 done.toSendPort().send("done"); | |
| 67 }; | |
| 68 }; | |
| 69 }); | |
| 70 }); | |
| 71 } | |
| 72 | |
| 73 | |
| 74 main() { | |
| 75 testOpenOutputStreamSync(); | |
| 76 testOutputStreamNoPendingWrite(); | |
| 77 } | |
| OLD | NEW |