| 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 // | 4 // |
| 5 // Dart test program for testing file I/O. | 5 // Dart test program for testing file I/O. |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 class MyListOfOneElement implements List { | 10 class MyListOfOneElement implements List { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 Expect.isTrue(input.closed); | 115 Expect.isTrue(input.closed); |
| 116 | 116 |
| 117 // Write the contents of the file just read into another file. | 117 // Write the contents of the file just read into another file. |
| 118 String outFilename = tempDirectory.path + "/out_read_write_stream"; | 118 String outFilename = tempDirectory.path + "/out_read_write_stream"; |
| 119 file = new File(outFilename); | 119 file = new File(outFilename); |
| 120 OutputStream output = file.openOutputStream(); | 120 OutputStream output = file.openOutputStream(); |
| 121 bool writeDone = output.writeFrom(buffer1, 0, 42); | 121 bool writeDone = output.writeFrom(buffer1, 0, 42); |
| 122 Expect.equals(false, writeDone); | 122 Expect.equals(false, writeDone); |
| 123 output.noPendingWriteHandler = () { | 123 output.noPendingWriteHandler = () { |
| 124 output.close(); | 124 output.close(); |
| 125 | 125 output.closeHandler = () { |
| 126 // Now read the contents of the file just written. | 126 // Now read the contents of the file just written. |
| 127 List<int> buffer2 = new List<int>(42); | 127 List<int> buffer2 = new List<int>(42); |
| 128 file = new File(outFilename); | 128 file = new File(outFilename); |
| 129 input = file.openInputStream(); | 129 input = file.openInputStream(); |
| 130 input.dataHandler = () { | 130 input.dataHandler = () { |
| 131 bytesRead = input.readInto(buffer2, 0, 42); | 131 bytesRead = input.readInto(buffer2, 0, 42); |
| 132 Expect.equals(42, bytesRead); | 132 Expect.equals(42, bytesRead); |
| 133 // Now compare the two buffers to check if they are identical. | 133 // Now compare the two buffers to check if they are identical. |
| 134 for (int i = 0; i < buffer1.length; i++) { | 134 for (int i = 0; i < buffer1.length; i++) { |
| 135 Expect.equals(buffer1[i], buffer2[i]); | 135 Expect.equals(buffer1[i], buffer2[i]); |
| 136 } | 136 } |
| 137 }; |
| 137 input.closeHandler = () { | 138 input.closeHandler = () { |
| 138 // Delete the output file. | 139 // Delete the output file. |
| 139 file.deleteSync(); | 140 file.deleteSync(); |
| 140 Expect.isFalse(file.existsSync()); | 141 Expect.isFalse(file.existsSync()); |
| 141 asyncTestDone("testReadWriteStream"); | 142 asyncTestDone("testReadWriteStream"); |
| 142 }; | 143 }; |
| 143 }; | 144 }; |
| 144 }; | 145 }; |
| 145 }; | 146 }; |
| 146 }; | 147 }; |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 testWriteVariousLists(); | 1148 testWriteVariousLists(); |
| 1148 testDirectory(); | 1149 testDirectory(); |
| 1149 testDirectorySync(); | 1150 testDirectorySync(); |
| 1150 }); | 1151 }); |
| 1151 } | 1152 } |
| 1152 } | 1153 } |
| 1153 | 1154 |
| 1154 main() { | 1155 main() { |
| 1155 FileTest.testMain(); | 1156 FileTest.testMain(); |
| 1156 } | 1157 } |
| OLD | NEW |