Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: tests/standalone/io/file_error_test.dart

Issue 10392023: Change dart:io to use Future for one-shot operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use defaults in more of File again. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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() {
11 var d = new Directory(''); 11 return new Directory('').createTempSync();
12 d.createTempSync();
13 return d;
14 } 12 }
15 13
16 14
17 bool checkNonExistentFileException(e, str) { 15 bool checkNonExistentFileException(e, str) {
18 Expect.isTrue(e is FileIOException); 16 Expect.isTrue(e is FileIOException);
19 Expect.isTrue(e.osError != null); 17 Expect.isTrue(e.osError != null);
20 Expect.isTrue(e.toString().indexOf(str) != -1); 18 Expect.isTrue(e.toString().indexOf(str) != -1);
21 if (Platform.operatingSystem == "linux") { 19 if (Platform.operatingSystem == "linux") {
22 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); 20 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
23 } else if (Platform.operatingSystem == "macos") { 21 } else if (Platform.operatingSystem == "macos") {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 p.receive((x, y) { 53 p.receive((x, y) {
56 p.close(); 54 p.close();
57 temp.deleteRecursivelySync(); 55 temp.deleteRecursivelySync();
58 }); 56 });
59 var file = new File("${temp.path}/nonExistentFile"); 57 var file = new File("${temp.path}/nonExistentFile");
60 58
61 // Non-existing file should throw exception. 59 // Non-existing file should throw exception.
62 Expect.throws(() => file.openSync(), 60 Expect.throws(() => file.openSync(),
63 (e) => checkOpenNonExistentFileException(e)); 61 (e) => checkOpenNonExistentFileException(e));
64 62
65 file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code")); 63 var openFuture = file.open(FileMode.READ);
66 file.onError = (e) { 64 openFuture.then((raf) => Expect.fail("Unreachable code"));
65 openFuture.handleException((e) {
67 checkOpenNonExistentFileException(e); 66 checkOpenNonExistentFileException(e);
68 p.toSendPort().send(null); 67 p.toSendPort().send(null);
69 }; 68 return true;
69 });
70 } 70 }
71 71
72 72
73 void testDeleteNonExistent() { 73 void testDeleteNonExistent() {
74 Directory temp = tempDir(); 74 Directory temp = tempDir();
75 ReceivePort p = new ReceivePort(); 75 ReceivePort p = new ReceivePort();
76 p.receive((x, y) { 76 p.receive((x, y) {
77 p.close(); 77 p.close();
78 temp.deleteRecursivelySync(); 78 temp.deleteRecursivelySync();
79 }); 79 });
80 var file = new File("${temp.path}/nonExistentFile"); 80 var file = new File("${temp.path}/nonExistentFile");
81 81
82 // Non-existing file should throw exception. 82 // Non-existing file should throw exception.
83 Expect.throws(() => file.deleteSync(), 83 Expect.throws(() => file.deleteSync(),
84 (e) => checkDeleteNonExistentFileException(e)); 84 (e) => checkDeleteNonExistentFileException(e));
85 85
86 file.delete(() => Expect.fail("Unreachable code")); 86 var delete = file.delete();
87 file.onError = (e) { 87 delete.then((ignore) => Expect.fail("Unreachable code"));
88 delete.handleException((e) {
88 checkDeleteNonExistentFileException(e); 89 checkDeleteNonExistentFileException(e);
89 p.toSendPort().send(null); 90 p.toSendPort().send(null);
90 }; 91 return true;
92 });
91 } 93 }
92 94
93 95
94 void testLengthNonExistent() { 96 void testLengthNonExistent() {
95 Directory temp = tempDir(); 97 Directory temp = tempDir();
96 ReceivePort p = new ReceivePort(); 98 ReceivePort p = new ReceivePort();
97 p.receive((x, y) { 99 p.receive((x, y) {
98 p.close(); 100 p.close();
99 temp.deleteRecursivelySync(); 101 temp.deleteRecursivelySync();
100 }); 102 });
101 var file = new File("${temp.path}/nonExistentFile"); 103 var file = new File("${temp.path}/nonExistentFile");
102 104
103 // Non-existing file should throw exception. 105 // Non-existing file should throw exception.
104 Expect.throws(() => file.lengthSync(), 106 Expect.throws(() => file.lengthSync(),
105 (e) => checkLengthNonExistentFileException(e)); 107 (e) => checkLengthNonExistentFileException(e));
106 108
107 file.length((len) => Expect.fail("Unreachable code")); 109 var lenFuture = file.length();
108 file.onError = (e) { 110 lenFuture.then((len) => Expect.fail("Unreachable code"));
111 lenFuture.handleException((e) {
109 checkLengthNonExistentFileException(e); 112 checkLengthNonExistentFileException(e);
110 p.toSendPort().send(null); 113 p.toSendPort().send(null);
111 }; 114 return true;
115 });
112 } 116 }
113 117
114 118
115 bool checkCreateInNonExistentDirectoryException(e) { 119 bool checkCreateInNonExistentDirectoryException(e) {
116 Expect.isTrue(e is FileIOException); 120 Expect.isTrue(e is FileIOException);
117 Expect.isTrue(e.osError != null); 121 Expect.isTrue(e.osError != null);
118 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); 122 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1);
119 if (Platform.operatingSystem == "linux") { 123 if (Platform.operatingSystem == "linux") {
120 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); 124 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
121 Expect.equals(2, e.osError.errorCode); 125 Expect.equals(2, e.osError.errorCode);
(...skipping 16 matching lines...) Expand all
138 p.receive((x, y) { 142 p.receive((x, y) {
139 p.close(); 143 p.close();
140 temp.deleteRecursivelySync(); 144 temp.deleteRecursivelySync();
141 }); 145 });
142 var file = new File("${temp.path}/nonExistentDirectory/newFile"); 146 var file = new File("${temp.path}/nonExistentDirectory/newFile");
143 147
144 // Create in non-existent directory should throw exception. 148 // Create in non-existent directory should throw exception.
145 Expect.throws(() => file.createSync(), 149 Expect.throws(() => file.createSync(),
146 (e) => checkCreateInNonExistentDirectoryException(e)); 150 (e) => checkCreateInNonExistentDirectoryException(e));
147 151
148 file.create(() => Expect.fail("Unreachable code")); 152 var create = file.create();
149 file.onError = (e) { 153 create.then((ignore) => Expect.fail("Unreachable code"));
154 create.handleException((e) {
150 checkCreateInNonExistentDirectoryException(e); 155 checkCreateInNonExistentDirectoryException(e);
151 p.toSendPort().send(null); 156 p.toSendPort().send(null);
152 }; 157 return true;
158 });
153 } 159 }
154 160
155 bool checkFullPathOnNonExistentDirectoryException(e) { 161 bool checkFullPathOnNonExistentDirectoryException(e) {
156 Expect.isTrue(e is FileIOException); 162 Expect.isTrue(e is FileIOException);
157 Expect.isTrue(e.osError != null); 163 Expect.isTrue(e.osError != null);
158 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); 164 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1);
159 if (Platform.operatingSystem == "linux") { 165 if (Platform.operatingSystem == "linux") {
160 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); 166 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
161 } else if (Platform.operatingSystem == "macos") { 167 } else if (Platform.operatingSystem == "macos") {
162 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); 168 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
(...skipping 14 matching lines...) Expand all
177 p.receive((x, y) { 183 p.receive((x, y) {
178 p.close(); 184 p.close();
179 temp.deleteRecursivelySync(); 185 temp.deleteRecursivelySync();
180 }); 186 });
181 var file = new File("${temp.path}/nonExistentDirectory"); 187 var file = new File("${temp.path}/nonExistentDirectory");
182 188
183 // Full path non-existent directory should throw exception. 189 // Full path non-existent directory should throw exception.
184 Expect.throws(() => file.fullPathSync(), 190 Expect.throws(() => file.fullPathSync(),
185 (e) => checkFullPathOnNonExistentDirectoryException(e)); 191 (e) => checkFullPathOnNonExistentDirectoryException(e));
186 192
187 file.fullPath((path) => Expect.fail("Unreachable code $path")); 193 var fullPathFuture = file.fullPath();
188 file.onError = (e) { 194 fullPathFuture.then((path) => Expect.fail("Unreachable code $path"));
195 fullPathFuture.handleException((e) {
189 checkFullPathOnNonExistentDirectoryException(e); 196 checkFullPathOnNonExistentDirectoryException(e);
190 p.toSendPort().send(null); 197 p.toSendPort().send(null);
191 }; 198 return true;
199 });
192 } 200 }
193 201
194 bool checkDirectoryInNonExistentDirectoryException(e) { 202 bool checkDirectoryInNonExistentDirectoryException(e) {
195 Expect.isTrue(e is FileIOException); 203 Expect.isTrue(e is FileIOException);
196 Expect.isTrue(e.osError != null); 204 Expect.isTrue(e.osError != null);
197 Expect.isTrue( 205 Expect.isTrue(
198 e.toString().indexOf("Cannot retrieve directory for file") != -1); 206 e.toString().indexOf("Cannot retrieve directory for file") != -1);
199 if (Platform.operatingSystem == "linux") { 207 if (Platform.operatingSystem == "linux") {
200 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); 208 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
201 } else if (Platform.operatingSystem == "macos") { 209 } else if (Platform.operatingSystem == "macos") {
(...skipping 15 matching lines...) Expand all
217 p.receive((x, y) { 225 p.receive((x, y) {
218 p.close(); 226 p.close();
219 temp.deleteRecursivelySync(); 227 temp.deleteRecursivelySync();
220 }); 228 });
221 var file = new File("${temp.path}/nonExistentDirectory/newFile"); 229 var file = new File("${temp.path}/nonExistentDirectory/newFile");
222 230
223 // Create in non-existent directory should throw exception. 231 // Create in non-existent directory should throw exception.
224 Expect.throws(() => file.directorySync(), 232 Expect.throws(() => file.directorySync(),
225 (e) => checkDirectoryInNonExistentDirectoryException(e)); 233 (e) => checkDirectoryInNonExistentDirectoryException(e));
226 234
227 file.directory((directory) => Expect.fail("Unreachable code")); 235 var dirFuture = file.directory();
228 file.onError = (e) { 236 dirFuture.then((directory) => Expect.fail("Unreachable code"));
237 dirFuture.handleException((e) {
229 checkDirectoryInNonExistentDirectoryException(e); 238 checkDirectoryInNonExistentDirectoryException(e);
230 p.toSendPort().send(null); 239 p.toSendPort().send(null);
231 }; 240 return true;
241 });
232 } 242 }
233 243
234 void testReadAsBytesNonExistent() { 244 void testReadAsBytesNonExistent() {
235 Directory temp = tempDir(); 245 Directory temp = tempDir();
236 ReceivePort p = new ReceivePort(); 246 ReceivePort p = new ReceivePort();
237 p.receive((x, y) { 247 p.receive((x, y) {
238 p.close(); 248 p.close();
239 temp.deleteRecursivelySync(); 249 temp.deleteRecursivelySync();
240 }); 250 });
241 var file = new File("${temp.path}/nonExistentFile3"); 251 var file = new File("${temp.path}/nonExistentFile3");
242 252
243 // Non-existing file should throw exception. 253 // Non-existing file should throw exception.
244 Expect.throws(() => file.readAsBytesSync(), 254 Expect.throws(() => file.readAsBytesSync(),
245 (e) => checkOpenNonExistentFileException(e)); 255 (e) => checkOpenNonExistentFileException(e));
246 256
247 file.readAsBytes((data) => Expect.fail("Unreachable code")); 257 var readAsBytesFuture = file.readAsBytes();
248 file.onError = (e) { 258 readAsBytesFuture.then((data) => Expect.fail("Unreachable code"));
259 readAsBytesFuture.handleException((e) {
249 checkOpenNonExistentFileException(e); 260 checkOpenNonExistentFileException(e);
250 p.toSendPort().send(null); 261 p.toSendPort().send(null);
251 }; 262 return true;
263 });
252 } 264 }
253 265
254 void testReadAsTextNonExistent() { 266 void testReadAsTextNonExistent() {
255 Directory temp = tempDir(); 267 Directory temp = tempDir();
256 ReceivePort p = new ReceivePort(); 268 ReceivePort p = new ReceivePort();
257 p.receive((x, y) { 269 p.receive((x, y) {
258 p.close(); 270 p.close();
259 temp.deleteRecursivelySync(); 271 temp.deleteRecursivelySync();
260 }); 272 });
261 var file = new File("${temp.path}/nonExistentFile4"); 273 var file = new File("${temp.path}/nonExistentFile4");
262 274
263 // Non-existing file should throw exception. 275 // Non-existing file should throw exception.
264 Expect.throws(() => file.readAsTextSync(), 276 Expect.throws(() => file.readAsTextSync(),
265 (e) => checkOpenNonExistentFileException(e)); 277 (e) => checkOpenNonExistentFileException(e));
266 278
267 file.readAsText(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); 279 var readAsTextFuture = file.readAsText(Encoding.ASCII);
268 file.onError = (e) { 280 readAsTextFuture.then((data) => Expect.fail("Unreachable code"));
281 readAsTextFuture.handleException((e) {
269 checkOpenNonExistentFileException(e); 282 checkOpenNonExistentFileException(e);
270 p.toSendPort().send(null); 283 p.toSendPort().send(null);
271 }; 284 return true;
285 });
272 } 286 }
273 287
274 testReadAsLinesNonExistent() { 288 testReadAsLinesNonExistent() {
275 Directory temp = tempDir(); 289 Directory temp = tempDir();
276 ReceivePort p = new ReceivePort(); 290 ReceivePort p = new ReceivePort();
277 p.receive((x, y) { 291 p.receive((x, y) {
278 p.close(); 292 p.close();
279 temp.deleteRecursivelySync(); 293 temp.deleteRecursivelySync();
280 }); 294 });
281 var file = new File("${temp.path}/nonExistentFile5"); 295 var file = new File("${temp.path}/nonExistentFile5");
282 296
283 // Non-existing file should throw exception. 297 // Non-existing file should throw exception.
284 Expect.throws(() => file.readAsLinesSync(), 298 Expect.throws(() => file.readAsLinesSync(),
285 (e) => checkOpenNonExistentFileException(e)); 299 (e) => checkOpenNonExistentFileException(e));
286 300
287 file.readAsLines(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); 301 var readAsLinesFuture = file.readAsLines(Encoding.ASCII);
288 file.onError = (e) { 302 readAsLinesFuture.then((data) => Expect.fail("Unreachable code"));
303 readAsLinesFuture.handleException((e) {
289 checkOpenNonExistentFileException(e); 304 checkOpenNonExistentFileException(e);
290 p.toSendPort().send(null); 305 p.toSendPort().send(null);
291 }; 306 return true;
307 });
292 } 308 }
293 309
294 bool checkWriteReadOnlyFileException(e) { 310 bool checkWriteReadOnlyFileException(e) {
295 Expect.isTrue(e is FileIOException); 311 Expect.isTrue(e is FileIOException);
296 Expect.isTrue(e.osError != null); 312 Expect.isTrue(e.osError != null);
297 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); 313 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode);
298 return true; 314 return true;
299 } 315 }
300 316
301 317
302 // Create a test file in a temporary directory. Setup a port to signal 318 // Create a test file in a temporary directory. Setup a port to signal
303 // when the temporary directory should be deleted. Pass the file and 319 // when the temporary directory should be deleted. Pass the file and
304 // the port to the callback argument. 320 // the port to the callback argument.
305 createTestFile(callback) { 321 createTestFile(callback) {
306 Directory temp = tempDir(); 322 Directory temp = tempDir();
307 ReceivePort p = new ReceivePort(); 323 ReceivePort p = new ReceivePort();
308 p.receive((x, y) { 324 p.receive((x, y) {
309 p.close(); 325 p.close();
310 temp.deleteRecursivelySync(); 326 temp.deleteRecursivelySync();
311 }); 327 });
312 328
313 var file = new File("${temp.path}/test_file"); 329 var file = new File("${temp.path}/test_file");
314 file.createSync(); 330 file.createSync();
315 callback(file, p.toSendPort()); 331 callback(file, p.toSendPort());
316 } 332 }
317 333
318 334
319 testWriteByteToReadOnlyFile() { 335 testWriteByteToReadOnlyFile() {
320 createTestFile((file, port) { 336 createTestFile((file, port) {
321 var openedFile = file.openSync(FileMode.READ); 337 var openedFile = file.openSync(FileMode.READ);
322 338
323 // Writing to read only file should throw an exception. 339 // Writing to read only file should throw an exception.
324 Expect.throws(() => openedFile.writeByteSync(0), 340 Expect.throws(() => openedFile.writeByteSync(0),
325 (e) => checkWriteReadOnlyFileException(e)); 341 (e) => checkWriteReadOnlyFileException(e));
326 342
327 openedFile.writeByte(0); 343 var writeByteFuture = openedFile.writeByte(0);
328 openedFile.onError = (e) { 344 writeByteFuture.handleException((e) {
329 checkWriteReadOnlyFileException(e); 345 checkWriteReadOnlyFileException(e);
330 openedFile.close(() => port.send(null)); 346 openedFile.close().then((ignore) => port.send(null));
331 }; 347 return true;
348 });
332 }); 349 });
333 } 350 }
334 351
335 testWriteListToReadOnlyFile() { 352 testWriteListToReadOnlyFile() {
336 createTestFile((file, port) { 353 createTestFile((file, port) {
337 var openedFile = file.openSync(FileMode.READ); 354 var openedFile = file.openSync(FileMode.READ);
338 355
339 List data = [0, 1, 2, 3]; 356 List data = [0, 1, 2, 3];
340 // Writing to read only file should throw an exception. 357 // Writing to read only file should throw an exception.
341 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), 358 Expect.throws(() => openedFile.writeListSync(data, 0, data.length),
342 (e) => checkWriteReadOnlyFileException(e)); 359 (e) => checkWriteReadOnlyFileException(e));
343 360
344 openedFile.writeList(data, 0, data.length); 361 var writeListFuture = openedFile.writeList(data, 0, data.length);
345 openedFile.onError = (e) { 362 writeListFuture.handleException((e) {
346 checkWriteReadOnlyFileException(e); 363 checkWriteReadOnlyFileException(e);
347 openedFile.close(() => port.send(null)); 364 openedFile.close().then((ignore) => port.send(null));
348 }; 365 return true;
366 });
349 }); 367 });
350 } 368 }
351 369
352 testTruncateReadOnlyFile() { 370 testTruncateReadOnlyFile() {
353 createTestFile((file, port) { 371 createTestFile((file, port) {
354 var openedFile = file.openSync(FileMode.WRITE); 372 var openedFile = file.openSync(FileMode.WRITE);
355 openedFile.writeByteSync(0); 373 openedFile.writeByteSync(0);
356 openedFile.closeSync(); 374 openedFile.closeSync();
357 openedFile = file.openSync(FileMode.READ); 375 openedFile = file.openSync(FileMode.READ);
358 376
359 // Truncating read only file should throw an exception. 377 // Truncating read only file should throw an exception.
360 Expect.throws(() => openedFile.truncateSync(0), 378 Expect.throws(() => openedFile.truncateSync(0),
361 (e) => checkWriteReadOnlyFileException(e)); 379 (e) => checkWriteReadOnlyFileException(e));
362 380
363 openedFile.truncate(0, () => Expect.fail("Unreachable code")); 381 var truncateFuture = openedFile.truncate(0);
364 openedFile.onError = (e) { 382 truncateFuture.then((ignore) => Expect.fail("Unreachable code"));
383 truncateFuture.handleException((e) {
365 checkWriteReadOnlyFileException(e); 384 checkWriteReadOnlyFileException(e);
366 openedFile.close(() => port.send(null)); 385 openedFile.close().then((ignore) => port.send(null));
367 }; 386 return true;
387 });
368 }); 388 });
369 } 389 }
370 390
371 bool checkFileClosedException(e) { 391 bool checkFileClosedException(e) {
372 Expect.isTrue(e is FileIOException); 392 Expect.isTrue(e is FileIOException);
373 Expect.isTrue(e.toString().indexOf("File closed") != -1); 393 Expect.isTrue(e.toString().indexOf("File closed") != -1);
374 Expect.isTrue(e.osError == null); 394 Expect.isTrue(e.osError == null);
375 return true; 395 return true;
376 } 396 }
377 397
(...skipping 18 matching lines...) Expand all
396 Expect.throws(() => openedFile.setPositionSync(0), 416 Expect.throws(() => openedFile.setPositionSync(0),
397 (e) => checkFileClosedException(e)); 417 (e) => checkFileClosedException(e));
398 Expect.throws(() => openedFile.truncateSync(0), 418 Expect.throws(() => openedFile.truncateSync(0),
399 (e) => checkFileClosedException(e)); 419 (e) => checkFileClosedException(e));
400 Expect.throws(() => openedFile.lengthSync(), 420 Expect.throws(() => openedFile.lengthSync(),
401 (e) => checkFileClosedException(e)); 421 (e) => checkFileClosedException(e));
402 Expect.throws(() => openedFile.flushSync(), 422 Expect.throws(() => openedFile.flushSync(),
403 (e) => checkFileClosedException(e)); 423 (e) => checkFileClosedException(e));
404 424
405 var errorCount = 0; 425 var errorCount = 0;
406 openedFile.readByte((byte) => Expect.fail("Unreachable code"));
407 errorCount++;
408 openedFile.writeByte(0);
409 errorCount++;
410 openedFile.readList(
411 data, 0, data.length, (bytesRead) => Expect.fail("Unreachable code"));
412 errorCount++;
413 openedFile.writeList(data, 0, data.length);
414 errorCount++;
415 openedFile.writeString("Hello");
416 errorCount++;
417 openedFile.position((position) => Expect.fail("Unreachable code"));
418 errorCount++;
419 openedFile.setPosition(0, () => Expect.fail("Unreachable code"));
420 errorCount++;
421 openedFile.truncate(0, () => Expect.fail("Unreachable code"));
422 errorCount++;
423 openedFile.length((length) => Expect.fail("Unreachable code"));
424 errorCount++;
425 openedFile.flush(() => Expect.fail("Unreachable code"));
426 errorCount++;
427 426
428 openedFile.onError = (e) { 427 _errorHandler(e) {
429 checkFileClosedException(e); 428 checkFileClosedException(e);
430 if (--errorCount == 0) { 429 if (--errorCount == 0) {
431 port.send(null); 430 port.send(null);
432 } 431 }
433 }; 432 return true;
433 }
434
435 var readByteFuture = openedFile.readByte();
436 readByteFuture.then((byte) => Expect.fail("Unreachable code"));
437 readByteFuture.handleException(_errorHandler);
438 errorCount++;
439 var writeByteFuture = openedFile.writeByte(0);
440 writeByteFuture.then((ignore) => Expect.fail("Unreachable code"));
441 writeByteFuture.handleException(_errorHandler);
442 errorCount++;
443 var readListFuture = openedFile.readList(data, 0, data.length);
444 readListFuture.then((bytesRead) => Expect.fail("Unreachable code"));
445 readListFuture.handleException(_errorHandler);
446 errorCount++;
447 var writeListFuture = openedFile.writeList(data, 0, data.length);
448 writeListFuture.then((ignore) => Expect.fail("Unreachable code"));
449 writeListFuture.handleException(_errorHandler);
450 errorCount++;
451 var writeStringFuture = openedFile.writeString("Hello");
452 writeStringFuture.then((ignore) => Expect.fail("Unreachable code"));
453 writeStringFuture.handleException(_errorHandler);
454 errorCount++;
455 var positionFuture = openedFile.position();
456 positionFuture.then((position) => Expect.fail("Unreachable code"));
457 positionFuture.handleException(_errorHandler);
458 errorCount++;
459 var setPositionFuture = openedFile.setPosition(0);
460 setPositionFuture.then((ignore) => Expect.fail("Unreachable code"));
461 setPositionFuture.handleException(_errorHandler);
462 errorCount++;
463 var truncateFuture = openedFile.truncate(0);
464 truncateFuture.then((ignore) => Expect.fail("Unreachable code"));
465 truncateFuture.handleException(_errorHandler);
466 errorCount++;
467 var lenFuture = openedFile.length();
468 lenFuture.then((length) => Expect.fail("Unreachable code"));
469 lenFuture.handleException(_errorHandler);
470 errorCount++;
471 var flushFuture = openedFile.flush();
472 flushFuture.then((ignore) => Expect.fail("Unreachable code"));
473 flushFuture.handleException(_errorHandler);
474 errorCount++;
434 }); 475 });
435 } 476 }
436 477
437 testRepeatedlyCloseFile() { 478 testRepeatedlyCloseFile() {
438 createTestFile((file, port) { 479 createTestFile((file, port) {
439 var openedFile = file.openSync(); 480 var openedFile = file.openSync();
440 openedFile.close(() { 481 openedFile.close().then((ignore) {
441 openedFile.onError = (e) { 482 var closeFuture = openedFile.close();
483 closeFuture.handleException((e) {
442 Expect.isTrue(e is FileIOException); 484 Expect.isTrue(e is FileIOException);
443 port.send(null); 485 port.send(null);
444 }; 486 return true;
445 openedFile.close(() => null); 487 });
488 closeFuture.then((ignore) => null);
446 }); 489 });
447 }); 490 });
448 } 491 }
449 492
450 main() { 493 main() {
451 testOpenNonExistent(); 494 testOpenNonExistent();
452 testDeleteNonExistent(); 495 testDeleteNonExistent();
453 testLengthNonExistent(); 496 testLengthNonExistent();
454 testCreateInNonExistentDirectory(); 497 testCreateInNonExistentDirectory();
455 testFullPathOnNonExistentDirectory(); 498 testFullPathOnNonExistentDirectory();
456 testDirectoryInNonExistentDirectory(); 499 testDirectoryInNonExistentDirectory();
457 testReadAsBytesNonExistent(); 500 testReadAsBytesNonExistent();
458 testReadAsTextNonExistent(); 501 testReadAsTextNonExistent();
459 testReadAsLinesNonExistent(); 502 testReadAsLinesNonExistent();
460 testWriteByteToReadOnlyFile(); 503 testWriteByteToReadOnlyFile();
461 testWriteListToReadOnlyFile(); 504 testWriteListToReadOnlyFile();
462 testTruncateReadOnlyFile(); 505 testTruncateReadOnlyFile();
463 testOperateOnClosedFile(); 506 testOperateOnClosedFile();
464 testRepeatedlyCloseFile(); 507 testRepeatedlyCloseFile();
465 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698