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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 p.close(); | 44 p.close(); |
45 temp.deleteSync(recursive: true); | 45 temp.deleteSync(recursive: true); |
46 }); | 46 }); |
47 var file = new File("${temp.path}/nonExistentFile"); | 47 var file = new File("${temp.path}/nonExistentFile"); |
48 | 48 |
49 // Non-existing file should throw exception. | 49 // Non-existing file should throw exception. |
50 Expect.throws(() => file.openSync(), | 50 Expect.throws(() => file.openSync(), |
51 (e) => checkOpenNonExistentFileException(e)); | 51 (e) => checkOpenNonExistentFileException(e)); |
52 | 52 |
53 var openFuture = file.open(FileMode.READ); | 53 var openFuture = file.open(FileMode.READ); |
54 openFuture.then((raf) => Expect.fail("Unreachable code")); | 54 openFuture.then((raf) => Expect.fail("Unreachable code")) |
55 openFuture.handleException((e) { | 55 .catchError((e) { |
56 checkOpenNonExistentFileException(e); | 56 checkOpenNonExistentFileException(e.error); |
57 p.toSendPort().send(null); | 57 p.toSendPort().send(null); |
58 return true; | 58 }); |
59 }); | |
60 } | 59 } |
61 | 60 |
62 | 61 |
63 void testDeleteNonExistent() { | 62 void testDeleteNonExistent() { |
64 Directory temp = tempDir(); | 63 Directory temp = tempDir(); |
65 ReceivePort p = new ReceivePort(); | 64 ReceivePort p = new ReceivePort(); |
66 p.receive((x, y) { | 65 p.receive((x, y) { |
67 p.close(); | 66 p.close(); |
68 temp.deleteSync(recursive: true); | 67 temp.deleteSync(recursive: true); |
69 }); | 68 }); |
70 var file = new File("${temp.path}/nonExistentFile"); | 69 var file = new File("${temp.path}/nonExistentFile"); |
71 | 70 |
72 // Non-existing file should throw exception. | 71 // Non-existing file should throw exception. |
73 Expect.throws(() => file.deleteSync(), | 72 Expect.throws(() => file.deleteSync(), |
74 (e) => checkDeleteNonExistentFileException(e)); | 73 (e) => checkDeleteNonExistentFileException(e)); |
75 | 74 |
76 var delete = file.delete(); | 75 var delete = file.delete(); |
77 delete.then((ignore) => Expect.fail("Unreachable code")); | 76 delete.then((ignore) => Expect.fail("Unreachable code")) |
78 delete.handleException((e) { | 77 .catchError((e) { |
79 checkDeleteNonExistentFileException(e); | 78 checkDeleteNonExistentFileException(e.error); |
80 p.toSendPort().send(null); | 79 p.toSendPort().send(null); |
81 return true; | 80 }); |
82 }); | |
83 } | 81 } |
84 | 82 |
85 | 83 |
86 void testLengthNonExistent() { | 84 void testLengthNonExistent() { |
87 Directory temp = tempDir(); | 85 Directory temp = tempDir(); |
88 ReceivePort p = new ReceivePort(); | 86 ReceivePort p = new ReceivePort(); |
89 p.receive((x, y) { | 87 p.receive((x, y) { |
90 p.close(); | 88 p.close(); |
91 temp.deleteSync(recursive: true); | 89 temp.deleteSync(recursive: true); |
92 }); | 90 }); |
93 var file = new File("${temp.path}/nonExistentFile"); | 91 var file = new File("${temp.path}/nonExistentFile"); |
94 | 92 |
95 // Non-existing file should throw exception. | 93 // Non-existing file should throw exception. |
96 Expect.throws(() => file.lengthSync(), | 94 Expect.throws(() => file.lengthSync(), |
97 (e) => checkLengthNonExistentFileException(e)); | 95 (e) => checkLengthNonExistentFileException(e)); |
98 | 96 |
99 var lenFuture = file.length(); | 97 var lenFuture = file.length(); |
100 lenFuture.then((len) => Expect.fail("Unreachable code")); | 98 lenFuture.then((len) => Expect.fail("Unreachable code")) |
101 lenFuture.handleException((e) { | 99 .catchError((e) { |
102 checkLengthNonExistentFileException(e); | 100 checkLengthNonExistentFileException(e.error); |
103 p.toSendPort().send(null); | 101 p.toSendPort().send(null); |
104 return true; | 102 }); |
105 }); | |
106 } | 103 } |
107 | 104 |
108 | 105 |
109 bool checkCreateInNonExistentDirectoryException(e) { | 106 bool checkCreateInNonExistentDirectoryException(e) { |
110 Expect.isTrue(e is FileIOException); | 107 Expect.isTrue(e is FileIOException); |
111 Expect.isTrue(e.osError != null); | 108 Expect.isTrue(e.osError != null); |
112 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); | 109 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); |
113 if (Platform.operatingSystem == "linux") { | 110 if (Platform.operatingSystem == "linux") { |
114 Expect.equals(2, e.osError.errorCode); | 111 Expect.equals(2, e.osError.errorCode); |
115 } else if (Platform.operatingSystem == "macos") { | 112 } else if (Platform.operatingSystem == "macos") { |
(...skipping 12 matching lines...) Expand all Loading... |
128 p.close(); | 125 p.close(); |
129 temp.deleteSync(recursive: true); | 126 temp.deleteSync(recursive: true); |
130 }); | 127 }); |
131 var file = new File("${temp.path}/nonExistentDirectory/newFile"); | 128 var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
132 | 129 |
133 // Create in non-existent directory should throw exception. | 130 // Create in non-existent directory should throw exception. |
134 Expect.throws(() => file.createSync(), | 131 Expect.throws(() => file.createSync(), |
135 (e) => checkCreateInNonExistentDirectoryException(e)); | 132 (e) => checkCreateInNonExistentDirectoryException(e)); |
136 | 133 |
137 var create = file.create(); | 134 var create = file.create(); |
138 create.then((ignore) => Expect.fail("Unreachable code")); | 135 create.then((ignore) => Expect.fail("Unreachable code")) |
139 create.handleException((e) { | 136 .catchError((e) { |
140 checkCreateInNonExistentDirectoryException(e); | 137 checkCreateInNonExistentDirectoryException(e.error); |
141 p.toSendPort().send(null); | 138 p.toSendPort().send(null); |
142 return true; | |
143 }); | 139 }); |
144 } | 140 } |
145 | 141 |
146 bool checkFullPathOnNonExistentDirectoryException(e) { | 142 bool checkFullPathOnNonExistentDirectoryException(e) { |
147 Expect.isTrue(e is FileIOException); | 143 Expect.isTrue(e is FileIOException); |
148 Expect.isTrue(e.osError != null); | 144 Expect.isTrue(e.osError != null); |
149 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); | 145 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); |
150 // File not not found has error code 2 on all supported platforms. | 146 // File not not found has error code 2 on all supported platforms. |
151 Expect.equals(2, e.osError.errorCode); | 147 Expect.equals(2, e.osError.errorCode); |
152 | 148 |
153 return true; | 149 return true; |
154 } | 150 } |
155 | 151 |
156 void testFullPathOnNonExistentDirectory() { | 152 void testFullPathOnNonExistentDirectory() { |
157 Directory temp = tempDir(); | 153 Directory temp = tempDir(); |
158 ReceivePort p = new ReceivePort(); | 154 ReceivePort p = new ReceivePort(); |
159 p.receive((x, y) { | 155 p.receive((x, y) { |
160 p.close(); | 156 p.close(); |
161 temp.deleteSync(recursive: true); | 157 temp.deleteSync(recursive: true); |
162 }); | 158 }); |
163 var file = new File("${temp.path}/nonExistentDirectory"); | 159 var file = new File("${temp.path}/nonExistentDirectory"); |
164 | 160 |
165 // Full path non-existent directory should throw exception. | 161 // Full path non-existent directory should throw exception. |
166 Expect.throws(() => file.fullPathSync(), | 162 Expect.throws(() => file.fullPathSync(), |
167 (e) => checkFullPathOnNonExistentDirectoryException(e)); | 163 (e) => checkFullPathOnNonExistentDirectoryException(e)); |
168 | 164 |
169 var fullPathFuture = file.fullPath(); | 165 var fullPathFuture = file.fullPath(); |
170 fullPathFuture.then((path) => Expect.fail("Unreachable code $path")); | 166 fullPathFuture.then((path) => Expect.fail("Unreachable code $path")) |
171 fullPathFuture.handleException((e) { | 167 .catchError((e) { |
172 checkFullPathOnNonExistentDirectoryException(e); | 168 checkFullPathOnNonExistentDirectoryException(e.error); |
173 p.toSendPort().send(null); | 169 p.toSendPort().send(null); |
174 return true; | |
175 }); | 170 }); |
176 } | 171 } |
177 | 172 |
178 bool checkDirectoryInNonExistentDirectoryException(e) { | 173 bool checkDirectoryInNonExistentDirectoryException(e) { |
179 Expect.isTrue(e is FileIOException); | 174 Expect.isTrue(e is FileIOException); |
180 Expect.isTrue(e.osError != null); | 175 Expect.isTrue(e.osError != null); |
181 Expect.isTrue( | 176 Expect.isTrue( |
182 e.toString().indexOf("Cannot retrieve directory for file") != -1); | 177 e.toString().indexOf("Cannot retrieve directory for file") != -1); |
183 // File not not found has error code 2 on all supported platforms. | 178 // File not not found has error code 2 on all supported platforms. |
184 Expect.equals(2, e.osError.errorCode); | 179 Expect.equals(2, e.osError.errorCode); |
185 | 180 |
186 return true; | 181 return true; |
187 } | 182 } |
188 | 183 |
189 void testDirectoryInNonExistentDirectory() { | 184 void testDirectoryInNonExistentDirectory() { |
190 Directory temp = tempDir(); | 185 Directory temp = tempDir(); |
191 ReceivePort p = new ReceivePort(); | 186 ReceivePort p = new ReceivePort(); |
192 p.receive((x, y) { | 187 p.receive((x, y) { |
193 p.close(); | 188 p.close(); |
194 temp.deleteSync(recursive: true); | 189 temp.deleteSync(recursive: true); |
195 }); | 190 }); |
196 var file = new File("${temp.path}/nonExistentDirectory/newFile"); | 191 var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
197 | 192 |
198 // Create in non-existent directory should throw exception. | 193 // Create in non-existent directory should throw exception. |
199 Expect.throws(() => file.directorySync(), | 194 Expect.throws(() => file.directorySync(), |
200 (e) => checkDirectoryInNonExistentDirectoryException(e)); | 195 (e) => checkDirectoryInNonExistentDirectoryException(e)); |
201 | 196 |
202 var dirFuture = file.directory(); | 197 var dirFuture = file.directory(); |
203 dirFuture.then((directory) => Expect.fail("Unreachable code")); | 198 dirFuture.then((directory) => Expect.fail("Unreachable code")) |
204 dirFuture.handleException((e) { | 199 .catchError((e) { |
205 checkDirectoryInNonExistentDirectoryException(e); | 200 checkDirectoryInNonExistentDirectoryException(e.error); |
206 p.toSendPort().send(null); | 201 p.toSendPort().send(null); |
207 return true; | |
208 }); | 202 }); |
209 } | 203 } |
210 | 204 |
211 void testReadAsBytesNonExistent() { | 205 void testReadAsBytesNonExistent() { |
212 Directory temp = tempDir(); | 206 Directory temp = tempDir(); |
213 ReceivePort p = new ReceivePort(); | 207 ReceivePort p = new ReceivePort(); |
214 p.receive((x, y) { | 208 p.receive((x, y) { |
215 p.close(); | 209 p.close(); |
216 temp.deleteSync(recursive: true); | 210 temp.deleteSync(recursive: true); |
217 }); | 211 }); |
218 var file = new File("${temp.path}/nonExistentFile3"); | 212 var file = new File("${temp.path}/nonExistentFile3"); |
219 | 213 |
220 // Non-existing file should throw exception. | 214 // Non-existing file should throw exception. |
221 Expect.throws(() => file.readAsBytesSync(), | 215 Expect.throws(() => file.readAsBytesSync(), |
222 (e) => checkOpenNonExistentFileException(e)); | 216 (e) => checkOpenNonExistentFileException(e)); |
223 | 217 |
224 var readAsBytesFuture = file.readAsBytes(); | 218 var readAsBytesFuture = file.readAsBytes(); |
225 readAsBytesFuture.then((data) => Expect.fail("Unreachable code")); | 219 readAsBytesFuture.then((data) => Expect.fail("Unreachable code")) |
226 readAsBytesFuture.handleException((e) { | 220 .catchError((e) { |
227 checkOpenNonExistentFileException(e); | 221 checkOpenNonExistentFileException(e.error); |
228 p.toSendPort().send(null); | 222 p.toSendPort().send(null); |
229 return true; | |
230 }); | 223 }); |
231 } | 224 } |
232 | 225 |
233 void testReadAsTextNonExistent() { | 226 void testReadAsTextNonExistent() { |
234 Directory temp = tempDir(); | 227 Directory temp = tempDir(); |
235 ReceivePort p = new ReceivePort(); | 228 ReceivePort p = new ReceivePort(); |
236 p.receive((x, y) { | 229 p.receive((x, y) { |
237 p.close(); | 230 p.close(); |
238 temp.deleteSync(recursive: true); | 231 temp.deleteSync(recursive: true); |
239 }); | 232 }); |
240 var file = new File("${temp.path}/nonExistentFile4"); | 233 var file = new File("${temp.path}/nonExistentFile4"); |
241 | 234 |
242 // Non-existing file should throw exception. | 235 // Non-existing file should throw exception. |
243 Expect.throws(() => file.readAsStringSync(), | 236 Expect.throws(() => file.readAsStringSync(), |
244 (e) => checkOpenNonExistentFileException(e)); | 237 (e) => checkOpenNonExistentFileException(e)); |
245 | 238 |
246 var readAsStringFuture = file.readAsString(Encoding.ASCII); | 239 var readAsStringFuture = file.readAsString(Encoding.ASCII); |
247 readAsStringFuture.then((data) => Expect.fail("Unreachable code")); | 240 readAsStringFuture.then((data) => Expect.fail("Unreachable code")) |
248 readAsStringFuture.handleException((e) { | 241 .catchError((e) { |
249 checkOpenNonExistentFileException(e); | 242 checkOpenNonExistentFileException(e.error); |
250 p.toSendPort().send(null); | 243 p.toSendPort().send(null); |
251 return true; | |
252 }); | 244 }); |
253 } | 245 } |
254 | 246 |
255 testReadAsLinesNonExistent() { | 247 testReadAsLinesNonExistent() { |
256 Directory temp = tempDir(); | 248 Directory temp = tempDir(); |
257 ReceivePort p = new ReceivePort(); | 249 ReceivePort p = new ReceivePort(); |
258 p.receive((x, y) { | 250 p.receive((x, y) { |
259 p.close(); | 251 p.close(); |
260 temp.deleteSync(recursive: true); | 252 temp.deleteSync(recursive: true); |
261 }); | 253 }); |
262 var file = new File("${temp.path}/nonExistentFile5"); | 254 var file = new File("${temp.path}/nonExistentFile5"); |
263 | 255 |
264 // Non-existing file should throw exception. | 256 // Non-existing file should throw exception. |
265 Expect.throws(() => file.readAsLinesSync(), | 257 Expect.throws(() => file.readAsLinesSync(), |
266 (e) => checkOpenNonExistentFileException(e)); | 258 (e) => checkOpenNonExistentFileException(e)); |
267 | 259 |
268 var readAsLinesFuture = file.readAsLines(Encoding.ASCII); | 260 var readAsLinesFuture = file.readAsLines(Encoding.ASCII); |
269 readAsLinesFuture.then((data) => Expect.fail("Unreachable code")); | 261 readAsLinesFuture.then((data) => Expect.fail("Unreachable code")) |
270 readAsLinesFuture.handleException((e) { | 262 .catchError((e) { |
271 checkOpenNonExistentFileException(e); | 263 checkOpenNonExistentFileException(e.error); |
272 p.toSendPort().send(null); | 264 p.toSendPort().send(null); |
273 return true; | |
274 }); | 265 }); |
275 } | 266 } |
276 | 267 |
277 bool checkWriteReadOnlyFileException(e) { | 268 bool checkWriteReadOnlyFileException(e) { |
278 Expect.isTrue(e is FileIOException); | 269 Expect.isTrue(e is FileIOException); |
279 Expect.isTrue(e.osError != null); | 270 Expect.isTrue(e.osError != null); |
280 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); | 271 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); |
281 return true; | 272 return true; |
282 } | 273 } |
283 | 274 |
(...skipping 17 matching lines...) Expand all Loading... |
301 | 292 |
302 testWriteByteToReadOnlyFile() { | 293 testWriteByteToReadOnlyFile() { |
303 createTestFile((file, port) { | 294 createTestFile((file, port) { |
304 var openedFile = file.openSync(FileMode.READ); | 295 var openedFile = file.openSync(FileMode.READ); |
305 | 296 |
306 // Writing to read only file should throw an exception. | 297 // Writing to read only file should throw an exception. |
307 Expect.throws(() => openedFile.writeByteSync(0), | 298 Expect.throws(() => openedFile.writeByteSync(0), |
308 (e) => checkWriteReadOnlyFileException(e)); | 299 (e) => checkWriteReadOnlyFileException(e)); |
309 | 300 |
310 var writeByteFuture = openedFile.writeByte(0); | 301 var writeByteFuture = openedFile.writeByte(0); |
311 writeByteFuture.handleException((e) { | 302 writeByteFuture.catchError((e) { |
312 checkWriteReadOnlyFileException(e); | 303 checkWriteReadOnlyFileException(e.error); |
313 openedFile.close().then((ignore) => port.send(null)); | 304 openedFile.close().then((ignore) => port.send(null)); |
314 return true; | |
315 }); | 305 }); |
316 }); | 306 }); |
317 } | 307 } |
318 | 308 |
319 testWriteListToReadOnlyFile() { | 309 testWriteListToReadOnlyFile() { |
320 createTestFile((file, port) { | 310 createTestFile((file, port) { |
321 var openedFile = file.openSync(FileMode.READ); | 311 var openedFile = file.openSync(FileMode.READ); |
322 | 312 |
323 List data = [0, 1, 2, 3]; | 313 List data = [0, 1, 2, 3]; |
324 // Writing to read only file should throw an exception. | 314 // Writing to read only file should throw an exception. |
325 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), | 315 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), |
326 (e) => checkWriteReadOnlyFileException(e)); | 316 (e) => checkWriteReadOnlyFileException(e)); |
327 | 317 |
328 var writeListFuture = openedFile.writeList(data, 0, data.length); | 318 var writeListFuture = openedFile.writeList(data, 0, data.length); |
329 writeListFuture.handleException((e) { | 319 writeListFuture.catchError((e) { |
330 checkWriteReadOnlyFileException(e); | 320 checkWriteReadOnlyFileException(e.error); |
331 openedFile.close().then((ignore) => port.send(null)); | 321 openedFile.close().then((ignore) => port.send(null)); |
332 return true; | |
333 }); | 322 }); |
334 }); | 323 }); |
335 } | 324 } |
336 | 325 |
337 testTruncateReadOnlyFile() { | 326 testTruncateReadOnlyFile() { |
338 createTestFile((file, port) { | 327 createTestFile((file, port) { |
339 var openedFile = file.openSync(FileMode.WRITE); | 328 var openedFile = file.openSync(FileMode.WRITE); |
340 openedFile.writeByteSync(0); | 329 openedFile.writeByteSync(0); |
341 openedFile.closeSync(); | 330 openedFile.closeSync(); |
342 openedFile = file.openSync(FileMode.READ); | 331 openedFile = file.openSync(FileMode.READ); |
343 | 332 |
344 // Truncating read only file should throw an exception. | 333 // Truncating read only file should throw an exception. |
345 Expect.throws(() => openedFile.truncateSync(0), | 334 Expect.throws(() => openedFile.truncateSync(0), |
346 (e) => checkWriteReadOnlyFileException(e)); | 335 (e) => checkWriteReadOnlyFileException(e)); |
347 | 336 |
348 var truncateFuture = openedFile.truncate(0); | 337 var truncateFuture = openedFile.truncate(0); |
349 truncateFuture.then((ignore) => Expect.fail("Unreachable code")); | 338 truncateFuture.then((ignore) => Expect.fail("Unreachable code")) |
350 truncateFuture.handleException((e) { | 339 .catchError((e) { |
351 checkWriteReadOnlyFileException(e); | 340 checkWriteReadOnlyFileException(e.error); |
352 openedFile.close().then((ignore) => port.send(null)); | 341 openedFile.close().then((ignore) => port.send(null)); |
353 return true; | |
354 }); | 342 }); |
355 }); | 343 }); |
356 } | 344 } |
357 | 345 |
358 bool checkFileClosedException(e) { | 346 bool checkFileClosedException(e) { |
359 Expect.isTrue(e is FileIOException); | 347 Expect.isTrue(e is FileIOException); |
360 Expect.isTrue(e.toString().indexOf("File closed") != -1); | 348 Expect.isTrue(e.toString().indexOf("File closed") != -1); |
361 Expect.isTrue(e.osError == null); | 349 Expect.isTrue(e.osError == null); |
362 return true; | 350 return true; |
363 } | 351 } |
(...skipping 21 matching lines...) Expand all Loading... |
385 Expect.throws(() => openedFile.truncateSync(0), | 373 Expect.throws(() => openedFile.truncateSync(0), |
386 (e) => checkFileClosedException(e)); | 374 (e) => checkFileClosedException(e)); |
387 Expect.throws(() => openedFile.lengthSync(), | 375 Expect.throws(() => openedFile.lengthSync(), |
388 (e) => checkFileClosedException(e)); | 376 (e) => checkFileClosedException(e)); |
389 Expect.throws(() => openedFile.flushSync(), | 377 Expect.throws(() => openedFile.flushSync(), |
390 (e) => checkFileClosedException(e)); | 378 (e) => checkFileClosedException(e)); |
391 | 379 |
392 var errorCount = 0; | 380 var errorCount = 0; |
393 | 381 |
394 _errorHandler(e) { | 382 _errorHandler(e) { |
395 checkFileClosedException(e); | 383 checkFileClosedException(e.error); |
396 if (--errorCount == 0) { | 384 if (--errorCount == 0) { |
397 port.send(null); | 385 port.send(null); |
398 } | 386 } |
399 return true; | |
400 } | 387 } |
401 | 388 |
402 var readByteFuture = openedFile.readByte(); | 389 var readByteFuture = openedFile.readByte(); |
403 readByteFuture.then((byte) => Expect.fail("Unreachable code")); | 390 readByteFuture.then((byte) => Expect.fail("Unreachable code")) |
404 readByteFuture.handleException(_errorHandler); | 391 .catchError(_errorHandler); |
405 errorCount++; | 392 errorCount++; |
406 var writeByteFuture = openedFile.writeByte(0); | 393 var writeByteFuture = openedFile.writeByte(0); |
407 writeByteFuture.then((ignore) => Expect.fail("Unreachable code")); | 394 writeByteFuture.then((ignore) => Expect.fail("Unreachable code")) |
408 writeByteFuture.handleException(_errorHandler); | 395 .catchError(_errorHandler); |
409 errorCount++; | 396 errorCount++; |
410 var readListFuture = openedFile.readList(data, 0, data.length); | 397 var readListFuture = openedFile.readList(data, 0, data.length); |
411 readListFuture.then((bytesRead) => Expect.fail("Unreachable code")); | 398 readListFuture.then((bytesRead) => Expect.fail("Unreachable code")) |
412 readListFuture.handleException(_errorHandler); | 399 .catchError(_errorHandler); |
413 errorCount++; | 400 errorCount++; |
414 var writeListFuture = openedFile.writeList(data, 0, data.length); | 401 var writeListFuture = openedFile.writeList(data, 0, data.length); |
415 writeListFuture.then((ignore) => Expect.fail("Unreachable code")); | 402 writeListFuture.then((ignore) => Expect.fail("Unreachable code")) |
416 writeListFuture.handleException(_errorHandler); | 403 .catchError(_errorHandler); |
417 errorCount++; | 404 errorCount++; |
418 var writeStringFuture = openedFile.writeString("Hello"); | 405 var writeStringFuture = openedFile.writeString("Hello"); |
419 writeStringFuture.then((ignore) => Expect.fail("Unreachable code")); | 406 writeStringFuture.then((ignore) => Expect.fail("Unreachable code")) |
420 writeStringFuture.handleException(_errorHandler); | 407 .catchError(_errorHandler); |
421 errorCount++; | 408 errorCount++; |
422 var positionFuture = openedFile.position(); | 409 var positionFuture = openedFile.position(); |
423 positionFuture.then((position) => Expect.fail("Unreachable code")); | 410 positionFuture.then((position) => Expect.fail("Unreachable code")) |
424 positionFuture.handleException(_errorHandler); | 411 .catchError(_errorHandler); |
425 errorCount++; | 412 errorCount++; |
426 var setPositionFuture = openedFile.setPosition(0); | 413 var setPositionFuture = openedFile.setPosition(0); |
427 setPositionFuture.then((ignore) => Expect.fail("Unreachable code")); | 414 setPositionFuture.then((ignore) => Expect.fail("Unreachable code")) |
428 setPositionFuture.handleException(_errorHandler); | 415 .catchError(_errorHandler); |
429 errorCount++; | 416 errorCount++; |
430 var truncateFuture = openedFile.truncate(0); | 417 var truncateFuture = openedFile.truncate(0); |
431 truncateFuture.then((ignore) => Expect.fail("Unreachable code")); | 418 truncateFuture.then((ignore) => Expect.fail("Unreachable code")) |
432 truncateFuture.handleException(_errorHandler); | 419 .catchError(_errorHandler); |
433 errorCount++; | 420 errorCount++; |
434 var lenFuture = openedFile.length(); | 421 var lenFuture = openedFile.length(); |
435 lenFuture.then((length) => Expect.fail("Unreachable code")); | 422 lenFuture.then((length) => Expect.fail("Unreachable code")) |
436 lenFuture.handleException(_errorHandler); | 423 .catchError(_errorHandler); |
437 errorCount++; | 424 errorCount++; |
438 var flushFuture = openedFile.flush(); | 425 var flushFuture = openedFile.flush(); |
439 flushFuture.then((ignore) => Expect.fail("Unreachable code")); | 426 flushFuture.then((ignore) => Expect.fail("Unreachable code")) |
440 flushFuture.handleException(_errorHandler); | 427 .catchError(_errorHandler); |
441 errorCount++; | 428 errorCount++; |
442 }); | 429 }); |
443 } | 430 } |
444 | 431 |
445 testRepeatedlyCloseFile() { | 432 testRepeatedlyCloseFile() { |
446 createTestFile((file, port) { | 433 createTestFile((file, port) { |
447 var openedFile = file.openSync(); | 434 var openedFile = file.openSync(); |
448 openedFile.close().then((ignore) { | 435 openedFile.close().then((ignore) { |
449 var closeFuture = openedFile.close(); | 436 var closeFuture = openedFile.close(); |
450 closeFuture.handleException((e) { | 437 closeFuture.then((ignore) => null) |
451 Expect.isTrue(e is FileIOException); | 438 .catchError((e) { |
| 439 Expect.isTrue(e.error is FileIOException); |
452 port.send(null); | 440 port.send(null); |
453 return true; | |
454 }); | 441 }); |
455 closeFuture.then((ignore) => null); | |
456 }); | 442 }); |
457 }); | 443 }); |
458 } | 444 } |
459 | 445 |
460 testRepeatedlyCloseFileSync() { | 446 testRepeatedlyCloseFileSync() { |
461 createTestFile((file, port) { | 447 createTestFile((file, port) { |
462 var openedFile = file.openSync(); | 448 var openedFile = file.openSync(); |
463 openedFile.closeSync(); | 449 openedFile.closeSync(); |
464 Expect.throws(openedFile.closeSync, | 450 Expect.throws(openedFile.closeSync, |
465 (e) => e is FileIOException); | 451 (e) => e is FileIOException); |
(...skipping 11 matching lines...) Expand all Loading... |
477 testReadAsBytesNonExistent(); | 463 testReadAsBytesNonExistent(); |
478 testReadAsTextNonExistent(); | 464 testReadAsTextNonExistent(); |
479 testReadAsLinesNonExistent(); | 465 testReadAsLinesNonExistent(); |
480 testWriteByteToReadOnlyFile(); | 466 testWriteByteToReadOnlyFile(); |
481 testWriteListToReadOnlyFile(); | 467 testWriteListToReadOnlyFile(); |
482 testTruncateReadOnlyFile(); | 468 testTruncateReadOnlyFile(); |
483 testOperateOnClosedFile(); | 469 testOperateOnClosedFile(); |
484 testRepeatedlyCloseFile(); | 470 testRepeatedlyCloseFile(); |
485 testRepeatedlyCloseFileSync(); | 471 testRepeatedlyCloseFileSync(); |
486 } | 472 } |
OLD | NEW |