| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 import "dart:isolate"; | 9 import "dart:isolate"; |
| 10 | 10 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 (e) => checkWriteReadOnlyFileException(e)); | 300 (e) => checkWriteReadOnlyFileException(e)); |
| 301 | 301 |
| 302 var writeByteFuture = openedFile.writeByte(0); | 302 var writeByteFuture = openedFile.writeByte(0); |
| 303 writeByteFuture.catchError((e) { | 303 writeByteFuture.catchError((e) { |
| 304 checkWriteReadOnlyFileException(e.error); | 304 checkWriteReadOnlyFileException(e.error); |
| 305 openedFile.close().then((ignore) => port.send(null)); | 305 openedFile.close().then((ignore) => port.send(null)); |
| 306 }); | 306 }); |
| 307 }); | 307 }); |
| 308 } | 308 } |
| 309 | 309 |
| 310 testWriteListToReadOnlyFile() { | 310 testWriteFromToReadOnlyFile() { |
| 311 createTestFile((file, port) { | 311 createTestFile((file, port) { |
| 312 var openedFile = file.openSync(mode: FileMode.READ); | 312 var openedFile = file.openSync(mode: FileMode.READ); |
| 313 | 313 |
| 314 List data = [0, 1, 2, 3]; | 314 List data = [0, 1, 2, 3]; |
| 315 // Writing to read only file should throw an exception. | 315 // Writing to read only file should throw an exception. |
| 316 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), | 316 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length), |
| 317 (e) => checkWriteReadOnlyFileException(e)); | 317 (e) => checkWriteReadOnlyFileException(e)); |
| 318 | 318 |
| 319 var writeListFuture = openedFile.writeList(data, 0, data.length); | 319 var writeFromFuture = openedFile.writeFrom(data, 0, data.length); |
| 320 writeListFuture.catchError((e) { | 320 writeFromFuture.catchError((e) { |
| 321 checkWriteReadOnlyFileException(e.error); | 321 checkWriteReadOnlyFileException(e.error); |
| 322 openedFile.close().then((ignore) => port.send(null)); | 322 openedFile.close().then((ignore) => port.send(null)); |
| 323 }); | 323 }); |
| 324 }); | 324 }); |
| 325 } | 325 } |
| 326 | 326 |
| 327 testTruncateReadOnlyFile() { | 327 testTruncateReadOnlyFile() { |
| 328 createTestFile((file, port) { | 328 createTestFile((file, port) { |
| 329 var openedFile = file.openSync(mode: FileMode.WRITE); | 329 var openedFile = file.openSync(mode: FileMode.WRITE); |
| 330 openedFile.writeByteSync(0); | 330 openedFile.writeByteSync(0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 354 testOperateOnClosedFile() { | 354 testOperateOnClosedFile() { |
| 355 createTestFile((file, port) { | 355 createTestFile((file, port) { |
| 356 var openedFile = file.openSync(mode: FileMode.READ); | 356 var openedFile = file.openSync(mode: FileMode.READ); |
| 357 openedFile.closeSync(); | 357 openedFile.closeSync(); |
| 358 | 358 |
| 359 List data = [0, 1, 2, 3]; | 359 List data = [0, 1, 2, 3]; |
| 360 Expect.throws(() => openedFile.readByteSync(), | 360 Expect.throws(() => openedFile.readByteSync(), |
| 361 (e) => checkFileClosedException(e)); | 361 (e) => checkFileClosedException(e)); |
| 362 Expect.throws(() => openedFile.writeByteSync(0), | 362 Expect.throws(() => openedFile.writeByteSync(0), |
| 363 (e) => checkFileClosedException(e)); | 363 (e) => checkFileClosedException(e)); |
| 364 Expect.throws(() => openedFile.writeListSync(data, 0, data.length), | 364 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length), |
| 365 (e) => checkFileClosedException(e)); | 365 (e) => checkFileClosedException(e)); |
| 366 Expect.throws(() => openedFile.readListSync(data, 0, data.length), | 366 Expect.throws(() => openedFile.readIntoSync(data, 0, data.length), |
| 367 (e) => checkFileClosedException(e)); | 367 (e) => checkFileClosedException(e)); |
| 368 Expect.throws(() => openedFile.writeStringSync("Hello"), | 368 Expect.throws(() => openedFile.writeStringSync("Hello"), |
| 369 (e) => checkFileClosedException(e)); | 369 (e) => checkFileClosedException(e)); |
| 370 Expect.throws(() => openedFile.positionSync(), | 370 Expect.throws(() => openedFile.positionSync(), |
| 371 (e) => checkFileClosedException(e)); | 371 (e) => checkFileClosedException(e)); |
| 372 Expect.throws(() => openedFile.setPositionSync(0), | 372 Expect.throws(() => openedFile.setPositionSync(0), |
| 373 (e) => checkFileClosedException(e)); | 373 (e) => checkFileClosedException(e)); |
| 374 Expect.throws(() => openedFile.truncateSync(0), | 374 Expect.throws(() => openedFile.truncateSync(0), |
| 375 (e) => checkFileClosedException(e)); | 375 (e) => checkFileClosedException(e)); |
| 376 Expect.throws(() => openedFile.lengthSync(), | 376 Expect.throws(() => openedFile.lengthSync(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 388 } | 388 } |
| 389 | 389 |
| 390 var readByteFuture = openedFile.readByte(); | 390 var readByteFuture = openedFile.readByte(); |
| 391 readByteFuture.then((byte) => Expect.fail("Unreachable code")) | 391 readByteFuture.then((byte) => Expect.fail("Unreachable code")) |
| 392 .catchError(_errorHandler); | 392 .catchError(_errorHandler); |
| 393 errorCount++; | 393 errorCount++; |
| 394 var writeByteFuture = openedFile.writeByte(0); | 394 var writeByteFuture = openedFile.writeByte(0); |
| 395 writeByteFuture.then((ignore) => Expect.fail("Unreachable code")) | 395 writeByteFuture.then((ignore) => Expect.fail("Unreachable code")) |
| 396 .catchError(_errorHandler); | 396 .catchError(_errorHandler); |
| 397 errorCount++; | 397 errorCount++; |
| 398 var readListFuture = openedFile.readList(data, 0, data.length); | 398 var readIntoFuture = openedFile.readInto(data, 0, data.length); |
| 399 readListFuture.then((bytesRead) => Expect.fail("Unreachable code")) | 399 readIntoFuture.then((bytesRead) => Expect.fail("Unreachable code")) |
| 400 .catchError(_errorHandler); | 400 .catchError(_errorHandler); |
| 401 errorCount++; | 401 errorCount++; |
| 402 var writeListFuture = openedFile.writeList(data, 0, data.length); | 402 var writeFromFuture = openedFile.writeFrom(data, 0, data.length); |
| 403 writeListFuture.then((ignore) => Expect.fail("Unreachable code")) | 403 writeFromFuture.then((ignore) => Expect.fail("Unreachable code")) |
| 404 .catchError(_errorHandler); | 404 .catchError(_errorHandler); |
| 405 errorCount++; | 405 errorCount++; |
| 406 var writeStringFuture = openedFile.writeString("Hello"); | 406 var writeStringFuture = openedFile.writeString("Hello"); |
| 407 writeStringFuture.then((ignore) => Expect.fail("Unreachable code")) | 407 writeStringFuture.then((ignore) => Expect.fail("Unreachable code")) |
| 408 .catchError(_errorHandler); | 408 .catchError(_errorHandler); |
| 409 errorCount++; | 409 errorCount++; |
| 410 var positionFuture = openedFile.position(); | 410 var positionFuture = openedFile.position(); |
| 411 positionFuture.then((position) => Expect.fail("Unreachable code")) | 411 positionFuture.then((position) => Expect.fail("Unreachable code")) |
| 412 .catchError(_errorHandler); | 412 .catchError(_errorHandler); |
| 413 errorCount++; | 413 errorCount++; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 testOpenNonExistent(); | 479 testOpenNonExistent(); |
| 480 testDeleteNonExistent(); | 480 testDeleteNonExistent(); |
| 481 testLengthNonExistent(); | 481 testLengthNonExistent(); |
| 482 testCreateInNonExistentDirectory(); | 482 testCreateInNonExistentDirectory(); |
| 483 testFullPathOnNonExistentDirectory(); | 483 testFullPathOnNonExistentDirectory(); |
| 484 testDirectoryInNonExistentDirectory(); | 484 testDirectoryInNonExistentDirectory(); |
| 485 testReadAsBytesNonExistent(); | 485 testReadAsBytesNonExistent(); |
| 486 testReadAsTextNonExistent(); | 486 testReadAsTextNonExistent(); |
| 487 testReadAsLinesNonExistent(); | 487 testReadAsLinesNonExistent(); |
| 488 testWriteByteToReadOnlyFile(); | 488 testWriteByteToReadOnlyFile(); |
| 489 testWriteListToReadOnlyFile(); | 489 testWriteFromToReadOnlyFile(); |
| 490 testTruncateReadOnlyFile(); | 490 testTruncateReadOnlyFile(); |
| 491 testOperateOnClosedFile(); | 491 testOperateOnClosedFile(); |
| 492 testRepeatedlyCloseFile(); | 492 testRepeatedlyCloseFile(); |
| 493 testRepeatedlyCloseFileSync(); | 493 testRepeatedlyCloseFileSync(); |
| 494 testReadSyncBigInt(); | 494 testReadSyncBigInt(); |
| 495 testReadSyncClosedFile(); | 495 testReadSyncClosedFile(); |
| 496 } | 496 } |
| OLD | NEW |