| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 7 |
| 8 class FileTest { | 8 class FileTest { |
| 9 // Test for file read functionality. | 9 // Test for file read functionality. |
| 10 static int testReadStream() { | 10 static int testReadStream() { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 input.readListSync(buffer, 0, 12); | 320 input.readListSync(buffer, 0, 12); |
| 321 Expect.equals(12, input.positionSync()); | 321 Expect.equals(12, input.positionSync()); |
| 322 input.readListSync(buffer, 12, 6); | 322 input.readListSync(buffer, 12, 6); |
| 323 Expect.equals(18, input.positionSync()); | 323 Expect.equals(18, input.positionSync()); |
| 324 input.setPositionSync(8); | 324 input.setPositionSync(8); |
| 325 Expect.equals(8, input.positionSync()); | 325 Expect.equals(8, input.positionSync()); |
| 326 input.closeSync(); | 326 input.closeSync(); |
| 327 return 1; | 327 return 1; |
| 328 } | 328 } |
| 329 | 329 |
| 330 static int testTruncate() { |
| 331 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 332 File file = new File("${filename}_out_truncate"); |
| 333 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 334 file.errorHandler = (error) { |
| 335 Expect.fail("testTruncate: No errors expected"); |
| 336 }; |
| 337 file.openHandler = () { |
| 338 file.noPendingWriteHandler = () { |
| 339 file.lengthHandler = (length) { |
| 340 Expect.equals(10, length); |
| 341 file.truncateHandler = () { |
| 342 file.lengthHandler = (length) { |
| 343 Expect.equals(5, length); |
| 344 file.closeHandler = () { |
| 345 file.deleteHandler = () { |
| 346 file.existsHandler = (exists) { |
| 347 Expect.isFalse(exists); |
| 348 }; |
| 349 file.exists(); |
| 350 }; |
| 351 file.delete(); |
| 352 }; |
| 353 file.close(); |
| 354 }; |
| 355 file.length(); |
| 356 }; |
| 357 file.truncate(5); |
| 358 }; |
| 359 file.length(); |
| 360 }; |
| 361 file.writeList(buffer, 0, 10); |
| 362 }; |
| 363 file.open(true); |
| 364 return 1; |
| 365 } |
| 366 |
| 367 static int testTruncateSync() { |
| 368 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 369 File file = new File("${filename}_out_truncate_sync"); |
| 370 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 371 file.openSync(true); |
| 372 file.writeListSync(buffer, 0, 10); |
| 373 Expect.equals(10, file.lengthSync()); |
| 374 file.truncateSync(5); |
| 375 Expect.equals(5, file.lengthSync()); |
| 376 file.closeSync(); |
| 377 file.deleteSync(); |
| 378 Expect.isFalse(file.existsSync()); |
| 379 return 1; |
| 380 } |
| 381 |
| 330 // Tests exception handling after file was closed. | 382 // Tests exception handling after file was closed. |
| 331 static int testCloseException() { | 383 static int testCloseException() { |
| 332 bool exceptionCaught = false; | 384 bool exceptionCaught = false; |
| 333 bool wrongExceptionCaught = false; | 385 bool wrongExceptionCaught = false; |
| 334 String filename = getFilename("tests/vm/data/fixed_length_file"); | 386 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 335 File input = new File(filename + "_out_close_exception"); | 387 File input = new File(filename + "_out_close_exception"); |
| 336 input.openSync(true); | 388 input.openSync(true); |
| 337 input.closeSync(); | 389 input.closeSync(); |
| 338 try { | 390 try { |
| 339 input.readByteSync(); | 391 input.readByteSync(); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 Expect.equals(1, testRead()); | 635 Expect.equals(1, testRead()); |
| 584 Expect.equals(1, testReadSync()); | 636 Expect.equals(1, testReadSync()); |
| 585 Expect.equals(1, testReadWrite()); | 637 Expect.equals(1, testReadWrite()); |
| 586 Expect.equals(1, testReadWriteSync()); | 638 Expect.equals(1, testReadWriteSync()); |
| 587 Expect.equals(1, testReadStream()); | 639 Expect.equals(1, testReadStream()); |
| 588 Expect.equals(1, testReadWriteStream()); | 640 Expect.equals(1, testReadWriteStream()); |
| 589 Expect.equals(1, testLength()); | 641 Expect.equals(1, testLength()); |
| 590 Expect.equals(1, testLengthSync()); | 642 Expect.equals(1, testLengthSync()); |
| 591 Expect.equals(1, testPosition()); | 643 Expect.equals(1, testPosition()); |
| 592 Expect.equals(1, testPositionSync()); | 644 Expect.equals(1, testPositionSync()); |
| 645 Expect.equals(1, testTruncate()); |
| 646 Expect.equals(1, testTruncateSync()); |
| 593 Expect.equals(1, testCloseException()); | 647 Expect.equals(1, testCloseException()); |
| 594 Expect.equals(1, testCloseExceptionStream()); | 648 Expect.equals(1, testCloseExceptionStream()); |
| 595 Expect.equals(1, testBufferOutOfBoundsException()); | 649 Expect.equals(1, testBufferOutOfBoundsException()); |
| 596 Expect.equals(1, testMixedSyncAndAsync()); | 650 Expect.equals(1, testMixedSyncAndAsync()); |
| 597 } | 651 } |
| 598 } | 652 } |
| 599 | 653 |
| 600 main() { | 654 main() { |
| 601 FileTest.testMain(); | 655 FileTest.testMain(); |
| 602 } | 656 } |
| OLD | NEW |