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 file I/O. | 5 // Dart test program for testing file I/O. |
6 | 6 |
7 // OtherResources=empty_file | 7 // OtherResources=empty_file |
8 // OtherResources=file_test.txt | 8 // OtherResources=file_test.txt |
9 // OtherResources=fixed_length_file | 9 // OtherResources=fixed_length_file |
10 // OtherResources=read_as_text.dat | 10 // OtherResources=read_as_text.dat |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 749 } |
750 | 750 |
751 static void testTruncateSync() { | 751 static void testTruncateSync() { |
752 File file = new File(tempDirectory.path + "/out_truncate_sync"); | 752 File file = new File(tempDirectory.path + "/out_truncate_sync"); |
753 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 753 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
754 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 754 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
755 openedFile.writeFromSync(buffer, 0, 10); | 755 openedFile.writeFromSync(buffer, 0, 10); |
756 Expect.equals(10, openedFile.lengthSync()); | 756 Expect.equals(10, openedFile.lengthSync()); |
757 openedFile.truncateSync(5); | 757 openedFile.truncateSync(5); |
758 Expect.equals(5, openedFile.lengthSync()); | 758 Expect.equals(5, openedFile.lengthSync()); |
| 759 bool exceptionCaught = false; |
| 760 bool wrongExceptionCaught = false; |
| 761 try { |
| 762 openedFile.truncateSync(-5); |
| 763 } on FileSystemException catch (ex) { |
| 764 exceptionCaught = true; |
| 765 } on Exception catch (ex) { |
| 766 wrongExceptionCaught = true; |
| 767 } |
| 768 Expect.equals(true, exceptionCaught); |
| 769 Expect.equals(true, !wrongExceptionCaught); |
759 openedFile.closeSync(); | 770 openedFile.closeSync(); |
760 file.deleteSync(); | 771 file.deleteSync(); |
761 Expect.isFalse(file.existsSync()); | 772 Expect.isFalse(file.existsSync()); |
762 } | 773 } |
763 | 774 |
764 static testReadInto() async { | 775 static testReadInto() async { |
765 asyncTestStarted(); | 776 asyncTestStarted(); |
766 File file = new File(tempDirectory.path + "/out_read_into"); | 777 File file = new File(tempDirectory.path + "/out_read_into"); |
767 | 778 |
768 var openedFile = await file.open(mode: WRITE); | 779 var openedFile = await file.open(mode: WRITE); |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 testSetLastAccessedSyncDirectory(); | 1671 testSetLastAccessedSyncDirectory(); |
1661 testDoubleAsyncOperation(); | 1672 testDoubleAsyncOperation(); |
1662 asyncEnd(); | 1673 asyncEnd(); |
1663 }); | 1674 }); |
1664 } | 1675 } |
1665 } | 1676 } |
1666 | 1677 |
1667 main() { | 1678 main() { |
1668 FileTest.testMain(); | 1679 FileTest.testMain(); |
1669 } | 1680 } |
OLD | NEW |