| 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 error handling in file I/O. | 5 // Dart test program for testing error handling in file I/O. |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 Directory tempDir() { | 10 Directory tempDir() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 e.toString().indexOf( | 28 e.toString().indexOf( |
| 29 "The system cannot find the file specified") != -1); | 29 "The system cannot find the file specified") != -1); |
| 30 } | 30 } |
| 31 // File not not found has error code 2 on all supported platforms. | 31 // File not not found has error code 2 on all supported platforms. |
| 32 Expect.equals(2, e.osError.errorCode); | 32 Expect.equals(2, e.osError.errorCode); |
| 33 | 33 |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void testOpenNonExistent() { | 37 void testOpenNonExistent() { |
| 38 var file = new File("${tempDir().path}/nonExistentFile"); | 38 Directory temp = tempDir(); |
| 39 ReceivePort p = new ReceivePort(); |
| 40 p.receive((x, y) { |
| 41 p.close(); |
| 42 temp.deleteRecursivelySync(); |
| 43 }); |
| 44 var file = new File("${temp.path}/nonExistentFile"); |
| 39 | 45 |
| 40 // Non-existing file should throw exception. | 46 // Non-existing file should throw exception. |
| 41 Expect.throws(() => file.openSync(), | 47 Expect.throws(() => file.openSync(), |
| 42 (e) => checkOpenNonExistentFileException(e)); | 48 (e) => checkOpenNonExistentFileException(e)); |
| 43 | 49 |
| 44 file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code")); | 50 file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code")); |
| 45 file.onError = (e) => checkOpenNonExistentFileException(e); | 51 file.onError = (e) { |
| 52 checkOpenNonExistentFileException(e); |
| 53 p.toSendPort().send(null); |
| 54 }; |
| 46 } | 55 } |
| 47 | 56 |
| 48 bool checkDeleteNonExistentFileException(e) { | 57 bool checkDeleteNonExistentFileException(e) { |
| 49 Expect.isTrue(e is FileIOException); | 58 Expect.isTrue(e is FileIOException); |
| 50 Expect.isTrue(e.osError != null); | 59 Expect.isTrue(e.osError != null); |
| 51 Expect.isTrue(e.toString().indexOf("Cannot delete file") != -1); | 60 Expect.isTrue(e.toString().indexOf("Cannot delete file") != -1); |
| 52 Platform platform = new Platform(); | 61 Platform platform = new Platform(); |
| 53 if (platform.operatingSystem() == "linux") { | 62 if (platform.operatingSystem() == "linux") { |
| 54 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 63 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 55 } else if (platform.operatingSystem() == "macos") { | 64 } else if (platform.operatingSystem() == "macos") { |
| 56 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 65 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 57 } else if (platform.operatingSystem() == "windows") { | 66 } else if (platform.operatingSystem() == "windows") { |
| 58 Expect.isTrue( | 67 Expect.isTrue( |
| 59 e.toString().indexOf( | 68 e.toString().indexOf( |
| 60 "The system cannot find the file specified") != -1); | 69 "The system cannot find the file specified") != -1); |
| 61 } | 70 } |
| 62 // File not not found has error code 2 on all supported platforms. | 71 // File not not found has error code 2 on all supported platforms. |
| 63 Expect.equals(2, e.osError.errorCode); | 72 Expect.equals(2, e.osError.errorCode); |
| 64 | 73 |
| 65 return true; | 74 return true; |
| 66 } | 75 } |
| 67 | 76 |
| 68 void testDeleteNonExistent() { | 77 void testDeleteNonExistent() { |
| 69 var file = new File("${tempDir().path}/nonExistentFile"); | 78 Directory temp = tempDir(); |
| 79 ReceivePort p = new ReceivePort(); |
| 80 p.receive((x, y) { |
| 81 p.close(); |
| 82 temp.deleteRecursivelySync(); |
| 83 }); |
| 84 var file = new File("${temp.path}/nonExistentFile"); |
| 70 | 85 |
| 71 // Non-existing file should throw exception. | 86 // Non-existing file should throw exception. |
| 72 Expect.throws(() => file.deleteSync(), | 87 Expect.throws(() => file.deleteSync(), |
| 73 (e) => checkDeleteNonExistentFileException(e)); | 88 (e) => checkDeleteNonExistentFileException(e)); |
| 74 | 89 |
| 75 file.delete(() => Expect.fail("Unreachable code")); | 90 file.delete(() => Expect.fail("Unreachable code")); |
| 76 file.onError = (e) => checkDeleteNonExistentFileException(e); | 91 file.onError = (e) { |
| 92 checkDeleteNonExistentFileException(e); |
| 93 p.toSendPort().send(null); |
| 94 }; |
| 77 } | 95 } |
| 78 | 96 |
| 79 bool checkCreateInNonExistentDirectoryException(e) { | 97 bool checkCreateInNonExistentDirectoryException(e) { |
| 80 Expect.isTrue(e is FileIOException); | 98 Expect.isTrue(e is FileIOException); |
| 81 Expect.isTrue(e.osError != null); | 99 Expect.isTrue(e.osError != null); |
| 82 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); | 100 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); |
| 83 Platform platform = new Platform(); | 101 Platform platform = new Platform(); |
| 84 if (platform.operatingSystem() == "linux") { | 102 if (platform.operatingSystem() == "linux") { |
| 85 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 103 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 86 Expect.equals(2, e.osError.errorCode); | 104 Expect.equals(2, e.osError.errorCode); |
| 87 } else if (platform.operatingSystem() == "macos") { | 105 } else if (platform.operatingSystem() == "macos") { |
| 88 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 106 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 89 Expect.equals(2, e.osError.errorCode); | 107 Expect.equals(2, e.osError.errorCode); |
| 90 } else if (platform.operatingSystem() == "windows") { | 108 } else if (platform.operatingSystem() == "windows") { |
| 91 Expect.isTrue( | 109 Expect.isTrue( |
| 92 e.toString().indexOf( | 110 e.toString().indexOf( |
| 93 "The system cannot find the path specified") != -1); | 111 "The system cannot find the path specified") != -1); |
| 94 Expect.equals(3, e.osError.errorCode); | 112 Expect.equals(3, e.osError.errorCode); |
| 95 } | 113 } |
| 96 | 114 |
| 97 return true; | 115 return true; |
| 98 } | 116 } |
| 99 | 117 |
| 100 void testCreateInNonExistentDirectory() { | 118 void testCreateInNonExistentDirectory() { |
| 101 var file = new File("${tempDir().path}/nonExistentDirectory/newFile"); | 119 Directory temp = tempDir(); |
| 120 ReceivePort p = new ReceivePort(); |
| 121 p.receive((x, y) { |
| 122 p.close(); |
| 123 temp.deleteRecursivelySync(); |
| 124 }); |
| 125 var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
| 102 | 126 |
| 103 // Create in non-existent directory should throw exception. | 127 // Create in non-existent directory should throw exception. |
| 104 Expect.throws(() => file.createSync(), | 128 Expect.throws(() => file.createSync(), |
| 105 (e) => checkCreateInNonExistentDirectoryException(e)); | 129 (e) => checkCreateInNonExistentDirectoryException(e)); |
| 106 | 130 |
| 107 file.create(() => Expect.fail("Unreachable code")); | 131 file.create(() => Expect.fail("Unreachable code")); |
| 108 file.onError = (e) => checkCreateInNonExistentDirectoryException(e); | 132 file.onError = (e) { |
| 133 checkCreateInNonExistentDirectoryException(e); |
| 134 p.toSendPort().send(null); |
| 135 }; |
| 109 } | 136 } |
| 110 | 137 |
| 111 bool checkFullPathOnNonExistentDirectoryException(e) { | 138 bool checkFullPathOnNonExistentDirectoryException(e) { |
| 112 Expect.isTrue(e is FileIOException); | 139 Expect.isTrue(e is FileIOException); |
| 113 Expect.isTrue(e.osError != null); | 140 Expect.isTrue(e.osError != null); |
| 114 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); | 141 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); |
| 115 Platform platform = new Platform(); | 142 Platform platform = new Platform(); |
| 116 if (platform.operatingSystem() == "linux") { | 143 if (platform.operatingSystem() == "linux") { |
| 117 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 144 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 118 } else if (platform.operatingSystem() == "macos") { | 145 } else if (platform.operatingSystem() == "macos") { |
| 119 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 146 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 120 } else if (platform.operatingSystem() == "windows") { | 147 } else if (platform.operatingSystem() == "windows") { |
| 121 Expect.isTrue( | 148 Expect.isTrue( |
| 122 e.toString().indexOf( | 149 e.toString().indexOf( |
| 123 "The system cannot find the file specified") != -1); | 150 "The system cannot find the file specified") != -1); |
| 124 } | 151 } |
| 125 // File not not found has error code 2 on all supported platforms. | 152 // File not not found has error code 2 on all supported platforms. |
| 126 Expect.equals(2, e.osError.errorCode); | 153 Expect.equals(2, e.osError.errorCode); |
| 127 | 154 |
| 128 return true; | 155 return true; |
| 129 } | 156 } |
| 130 | 157 |
| 131 void testFullPathOnNonExistentDirectory() { | 158 void testFullPathOnNonExistentDirectory() { |
| 132 var file = new File("${tempDir().path}/nonExistentDirectory"); | 159 Directory temp = tempDir(); |
| 160 ReceivePort p = new ReceivePort(); |
| 161 p.receive((x, y) { |
| 162 p.close(); |
| 163 temp.deleteRecursivelySync(); |
| 164 }); |
| 165 var file = new File("${temp.path}/nonExistentDirectory"); |
| 133 | 166 |
| 134 // Full path non-existent directory should throw exception. | 167 // Full path non-existent directory should throw exception. |
| 135 Expect.throws(() => file.fullPathSync(), | 168 Expect.throws(() => file.fullPathSync(), |
| 136 (e) => checkFullPathOnNonExistentDirectoryException(e)); | 169 (e) => checkFullPathOnNonExistentDirectoryException(e)); |
| 137 | 170 |
| 138 file.fullPath((path) => Expect.fail("Unreachable code $path")); | 171 file.fullPath((path) => Expect.fail("Unreachable code $path")); |
| 139 file.onError = (e) => checkFullPathOnNonExistentDirectoryException(e); | 172 file.onError = (e) { |
| 173 checkFullPathOnNonExistentDirectoryException(e); |
| 174 p.toSendPort().send(null); |
| 175 }; |
| 140 } | 176 } |
| 141 | 177 |
| 142 bool checkDirectoryInNonExistentDirectoryException(e) { | 178 bool checkDirectoryInNonExistentDirectoryException(e) { |
| 143 Expect.isTrue(e is FileIOException); | 179 Expect.isTrue(e is FileIOException); |
| 144 Expect.isTrue(e.osError != null); | 180 Expect.isTrue(e.osError != null); |
| 145 Expect.isTrue( | 181 Expect.isTrue( |
| 146 e.toString().indexOf("Cannot retrieve directory for file") != -1); | 182 e.toString().indexOf("Cannot retrieve directory for file") != -1); |
| 147 Platform platform = new Platform(); | 183 Platform platform = new Platform(); |
| 148 if (platform.operatingSystem() == "linux") { | 184 if (platform.operatingSystem() == "linux") { |
| 149 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 185 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 150 } else if (platform.operatingSystem() == "macos") { | 186 } else if (platform.operatingSystem() == "macos") { |
| 151 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 187 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 152 } else if (platform.operatingSystem() == "windows") { | 188 } else if (platform.operatingSystem() == "windows") { |
| 153 Expect.isTrue( | 189 Expect.isTrue( |
| 154 e.toString().indexOf( | 190 e.toString().indexOf( |
| 155 "The system cannot find the file specified") != -1); | 191 "The system cannot find the file specified") != -1); |
| 156 } | 192 } |
| 157 // File not not found has error code 2 on all supported platforms. | 193 // File not not found has error code 2 on all supported platforms. |
| 158 Expect.equals(2, e.osError.errorCode); | 194 Expect.equals(2, e.osError.errorCode); |
| 159 | 195 |
| 160 return true; | 196 return true; |
| 161 } | 197 } |
| 162 | 198 |
| 163 void testDirectoryInNonExistentDirectory() { | 199 void testDirectoryInNonExistentDirectory() { |
| 164 var file = new File("${tempDir().path}/nonExistentDirectory/newFile"); | 200 Directory temp = tempDir(); |
| 201 ReceivePort p = new ReceivePort(); |
| 202 p.receive((x, y) { |
| 203 p.close(); |
| 204 temp.deleteRecursivelySync(); |
| 205 }); |
| 206 var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
| 165 | 207 |
| 166 // Create in non-existent directory should throw exception. | 208 // Create in non-existent directory should throw exception. |
| 167 Expect.throws(() => file.directorySync(), | 209 Expect.throws(() => file.directorySync(), |
| 168 (e) => checkDirectoryInNonExistentDirectoryException(e)); | 210 (e) => checkDirectoryInNonExistentDirectoryException(e)); |
| 169 | 211 |
| 170 file.directory((directory) => Expect.fail("Unreachable code")); | 212 file.directory((directory) => Expect.fail("Unreachable code")); |
| 171 file.onError = (e) => checkDirectoryInNonExistentDirectoryException(e); | 213 file.onError = (e) { |
| 214 checkDirectoryInNonExistentDirectoryException(e); |
| 215 p.toSendPort().send(null); |
| 216 }; |
| 172 } | 217 } |
| 173 | 218 |
| 174 void testReadAsBytesNonExistent() { | 219 void testReadAsBytesNonExistent() { |
| 175 var file = new File("${tempDir().path}/nonExistentFile3"); | 220 Directory temp = tempDir(); |
| 221 ReceivePort p = new ReceivePort(); |
| 222 p.receive((x, y) { |
| 223 p.close(); |
| 224 temp.deleteRecursivelySync(); |
| 225 }); |
| 226 var file = new File("${temp.path}/nonExistentFile3"); |
| 176 | 227 |
| 177 // Non-existing file should throw exception. | 228 // Non-existing file should throw exception. |
| 178 Expect.throws(() => file.readAsBytesSync(), | 229 Expect.throws(() => file.readAsBytesSync(), |
| 179 (e) => checkOpenNonExistentFileException(e)); | 230 (e) => checkOpenNonExistentFileException(e)); |
| 180 | 231 |
| 181 file.readAsBytes((data) => Expect.fail("Unreachable code")); | 232 file.readAsBytes((data) => Expect.fail("Unreachable code")); |
| 182 file.onError = (e) => checkOpenNonExistentFileException(e); | 233 file.onError = (e) { |
| 234 checkOpenNonExistentFileException(e); |
| 235 p.toSendPort().send(null); |
| 236 }; |
| 183 } | 237 } |
| 184 | 238 |
| 185 void testReadAsTextNonExistent() { | 239 void testReadAsTextNonExistent() { |
| 186 var file = new File("${tempDir().path}/nonExistentFile4"); | 240 Directory temp = tempDir(); |
| 241 ReceivePort p = new ReceivePort(); |
| 242 p.receive((x, y) { |
| 243 p.close(); |
| 244 temp.deleteRecursivelySync(); |
| 245 }); |
| 246 var file = new File("${temp.path}/nonExistentFile4"); |
| 187 | 247 |
| 188 // Non-existing file should throw exception. | 248 // Non-existing file should throw exception. |
| 189 Expect.throws(() => file.readAsTextSync(), | 249 Expect.throws(() => file.readAsTextSync(), |
| 190 (e) => checkOpenNonExistentFileException(e)); | 250 (e) => checkOpenNonExistentFileException(e)); |
| 191 | 251 |
| 192 file.readAsText(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); | 252 file.readAsText(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); |
| 193 file.onError = (e) => checkOpenNonExistentFileException(e); | 253 file.onError = (e) { |
| 254 checkOpenNonExistentFileException(e); |
| 255 p.toSendPort().send(null); |
| 256 }; |
| 194 } | 257 } |
| 195 | 258 |
| 196 void testReadAsLinesNonExistent() { | 259 testReadAsLinesNonExistent() { |
| 197 var file = new File("${tempDir().path}/nonExistentFile5"); | 260 Directory temp = tempDir(); |
| 261 ReceivePort p = new ReceivePort(); |
| 262 p.receive((x, y) { |
| 263 p.close(); |
| 264 temp.deleteRecursivelySync(); |
| 265 }); |
| 266 var file = new File("${temp.path}/nonExistentFile5"); |
| 198 | 267 |
| 199 // Non-existing file should throw exception. | 268 // Non-existing file should throw exception. |
| 200 Expect.throws(() => file.readAsLinesSync(), | 269 Expect.throws(() => file.readAsLinesSync(), |
| 201 (e) => checkOpenNonExistentFileException(e)); | 270 (e) => checkOpenNonExistentFileException(e)); |
| 202 | 271 |
| 203 file.readAsLines(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); | 272 file.readAsLines(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); |
| 204 file.onError = (e) => checkOpenNonExistentFileException(e); | 273 file.onError = (e) { |
| 274 checkOpenNonExistentFileException(e); |
| 275 p.toSendPort().send(null); |
| 276 }; |
| 205 } | 277 } |
| 206 | 278 |
| 207 bool checkWriteReadOnlyFileException(e) { | 279 bool checkWriteReadOnlyFileException(e) { |
| 208 Expect.isTrue(e is FileIOException); | 280 Expect.isTrue(e is FileIOException); |
| 209 Expect.isTrue(e.osError != null); | 281 Expect.isTrue(e.osError != null); |
| 210 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); | 282 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); |
| 211 return true; | 283 return true; |
| 212 } | 284 } |
| 213 | 285 |
| 214 testWriteByteToReadOnlyFile() { | 286 testWriteByteToReadOnlyFile() { |
| 215 Directory temp = tempDir(); | 287 Directory temp = tempDir(); |
| 216 ReceivePort p = new ReceivePort(); | 288 ReceivePort p = new ReceivePort(); |
| 217 p.receive((x,y) { | 289 p.receive((x, y) { |
| 218 p.close(); | 290 p.close(); |
| 219 temp.deleteRecursivelySync(); | 291 temp.deleteRecursivelySync(); |
| 220 }); | 292 }); |
| 221 | 293 |
| 222 var file = new File("${temp.path}/test_file"); | 294 var file = new File("${temp.path}/test_file"); |
| 223 file.createSync(); | 295 file.createSync(); |
| 224 var openedFile = file.openSync(FileMode.READ); | 296 var openedFile = file.openSync(FileMode.READ); |
| 225 | 297 |
| 226 // Writing to read only file should throw an exception. | 298 // Writing to read only file should throw an exception. |
| 227 Expect.throws(() => openedFile.writeByteSync(0), | 299 Expect.throws(() => openedFile.writeByteSync(0), |
| 228 (e) => checkWriteReadOnlyFileException(e)); | 300 (e) => checkWriteReadOnlyFileException(e)); |
| 229 | 301 |
| 230 openedFile.writeByte(0); | 302 openedFile.writeByte(0); |
| 231 openedFile.onError = (e) { | 303 openedFile.onError = (e) { |
| 232 checkWriteReadOnlyFileException(e); | 304 checkWriteReadOnlyFileException(e); |
| 233 openedFile.close(() => p.toSendPort().send(null)); | 305 openedFile.close(() => p.toSendPort().send(null)); |
| 234 }; | 306 }; |
| 235 } | 307 } |
| 236 | 308 |
| 237 testWriteListToReadOnlyFile() { | 309 testWriteListToReadOnlyFile() { |
| 238 Directory temp = tempDir(); | 310 Directory temp = tempDir(); |
| 239 ReceivePort p = new ReceivePort(); | 311 ReceivePort p = new ReceivePort(); |
| 240 p.receive((x,y) { | 312 p.receive((x, y) { |
| 241 p.close(); | 313 p.close(); |
| 242 temp.deleteRecursivelySync(); | 314 temp.deleteRecursivelySync(); |
| 243 }); | 315 }); |
| 244 | 316 |
| 245 var file = new File("${temp.path}/test_file"); | 317 var file = new File("${temp.path}/test_file"); |
| 246 file.createSync(); | 318 file.createSync(); |
| 247 var openedFile = file.openSync(FileMode.READ); | 319 var openedFile = file.openSync(FileMode.READ); |
| 248 | 320 |
| 249 List data = [0, 1, 2, 3]; | 321 List data = [0, 1, 2, 3]; |
| 250 // Writing to read only file should throw an exception. | 322 // Writing to read only file should throw an exception. |
| 251 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), | 323 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), |
| 252 (e) => checkWriteReadOnlyFileException(e)); | 324 (e) => checkWriteReadOnlyFileException(e)); |
| 253 | 325 |
| 254 openedFile.writeList(data, 0, data.length); | 326 openedFile.writeList(data, 0, data.length); |
| 255 openedFile.onError = (e) { | 327 openedFile.onError = (e) { |
| 256 checkWriteReadOnlyFileException(e); | 328 checkWriteReadOnlyFileException(e); |
| 257 openedFile.close(() => p.toSendPort().send(null)); | 329 openedFile.close(() => p.toSendPort().send(null)); |
| 258 }; | 330 }; |
| 259 } | 331 } |
| 260 | 332 |
| 261 testTruncateReadOnlyFile() { | 333 testTruncateReadOnlyFile() { |
| 262 Directory temp = tempDir(); | 334 Directory temp = tempDir(); |
| 263 ReceivePort p = new ReceivePort(); | 335 ReceivePort p = new ReceivePort(); |
| 264 p.receive((x,y) { | 336 p.receive((x, y) { |
| 265 p.close(); | 337 p.close(); |
| 266 temp.deleteRecursivelySync(); | 338 temp.deleteRecursivelySync(); |
| 267 }); | 339 }); |
| 268 | 340 |
| 269 var file = new File("${temp.path}/test_file"); | 341 var file = new File("${temp.path}/test_file"); |
| 270 file.createSync(); | 342 file.createSync(); |
| 271 var openedFile = file.openSync(FileMode.WRITE); | 343 var openedFile = file.openSync(FileMode.WRITE); |
| 272 openedFile.writeByteSync(0); | 344 openedFile.writeByteSync(0); |
| 273 openedFile.closeSync(); | 345 openedFile.closeSync(); |
| 274 openedFile = file.openSync(FileMode.READ); | 346 openedFile = file.openSync(FileMode.READ); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 bool checkFileClosedException(e) { | 359 bool checkFileClosedException(e) { |
| 288 Expect.isTrue(e is FileIOException); | 360 Expect.isTrue(e is FileIOException); |
| 289 Expect.isTrue(e.toString().indexOf("File closed") != -1); | 361 Expect.isTrue(e.toString().indexOf("File closed") != -1); |
| 290 Expect.isTrue(e.osError == null); | 362 Expect.isTrue(e.osError == null); |
| 291 return true; | 363 return true; |
| 292 } | 364 } |
| 293 | 365 |
| 294 testOperateOnClosedFile() { | 366 testOperateOnClosedFile() { |
| 295 Directory temp = tempDir(); | 367 Directory temp = tempDir(); |
| 296 ReceivePort p = new ReceivePort(); | 368 ReceivePort p = new ReceivePort(); |
| 297 p.receive((x,y) { | 369 p.receive((x, y) { |
| 298 p.close(); | 370 p.close(); |
| 299 temp.deleteRecursivelySync(); | 371 temp.deleteRecursivelySync(); |
| 300 }); | 372 }); |
| 301 | 373 |
| 302 var file = new File("${tempDir().path}/test_file"); | 374 var file = new File("${temp.path}/test_file"); |
| 303 file.createSync(); | 375 file.createSync(); |
| 304 var openedFile = file.openSync(FileMode.READ); | 376 var openedFile = file.openSync(FileMode.READ); |
| 305 openedFile.closeSync(); | 377 openedFile.closeSync(); |
| 306 | 378 |
| 307 List data = [0, 1, 2, 3]; | 379 List data = [0, 1, 2, 3]; |
| 308 Expect.throws(() => openedFile.readByteSync(), | 380 Expect.throws(() => openedFile.readByteSync(), |
| 309 (e) => checkFileClosedException(e)); | 381 (e) => checkFileClosedException(e)); |
| 310 Expect.throws(() => openedFile.writeByteSync(0), | 382 Expect.throws(() => openedFile.writeByteSync(0), |
| 311 (e) => checkFileClosedException(e)); | 383 (e) => checkFileClosedException(e)); |
| 312 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), | 384 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 testFullPathOnNonExistentDirectory(); | 436 testFullPathOnNonExistentDirectory(); |
| 365 testDirectoryInNonExistentDirectory(); | 437 testDirectoryInNonExistentDirectory(); |
| 366 testReadAsBytesNonExistent(); | 438 testReadAsBytesNonExistent(); |
| 367 testReadAsTextNonExistent(); | 439 testReadAsTextNonExistent(); |
| 368 testReadAsLinesNonExistent(); | 440 testReadAsLinesNonExistent(); |
| 369 testWriteByteToReadOnlyFile(); | 441 testWriteByteToReadOnlyFile(); |
| 370 testWriteListToReadOnlyFile(); | 442 testWriteListToReadOnlyFile(); |
| 371 testTruncateReadOnlyFile(); | 443 testTruncateReadOnlyFile(); |
| 372 testOperateOnClosedFile(); | 444 testOperateOnClosedFile(); |
| 373 } | 445 } |
| OLD | NEW |