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

Side by Side Diff: tests/standalone/src/FileTest.dart

Issue 9427014: Disallow opening of directories as files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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
« no previous file with comments | « runtime/bin/file.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 file I/O. 5 // Dart test program for testing file I/O.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 class FileTest { 9 class FileTest {
10 static Directory tempDirectory; 10 static Directory tempDirectory;
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 try { 728 try {
729 f.existsSync(); 729 f.existsSync();
730 Expect.fail("Expected exception"); 730 Expect.fail("Expected exception");
731 } catch (var e) { 731 } catch (var e) {
732 Expect.isTrue(e is FileIOException); 732 Expect.isTrue(e is FileIOException);
733 } 733 }
734 }; 734 };
735 f.exists(); 735 f.exists();
736 } 736 }
737 737
738 static void testOpenDirectoryAsFile() {
739 var f = new File('.');
740 f.open();
741 f.openHandler = (r) => Expect.fail('Directory opened as file');
742 }
743
744 static void testOpenDirectoryAsFileSync() {
745 var f = new File('.');
746 try {
747 f.openSync();
748 Expect.fail("Expected exception opening directory as file");
749 } catch (var e) {
750 Expect.isTrue(e is FileIOException);
751 }
752 }
753
738 // Test that opens the same file for writing then for appending to test 754 // Test that opens the same file for writing then for appending to test
739 // that the file is not truncated when opened for appending. 755 // that the file is not truncated when opened for appending.
740 static void testAppend() { 756 static void testAppend() {
741 var file = new File('${tempDirectory.path}/out_append'); 757 var file = new File('${tempDirectory.path}/out_append');
742 file.openHandler = (openedFile) { 758 file.openHandler = (openedFile) {
743 openedFile.noPendingWriteHandler = () { 759 openedFile.noPendingWriteHandler = () {
744 openedFile.closeHandler = () { 760 openedFile.closeHandler = () {
745 file.openHandler = (openedFile) { 761 file.openHandler = (openedFile) {
746 openedFile.lengthHandler = (length) { 762 openedFile.lengthHandler = (length) {
747 Expect.equals(4, length); 763 Expect.equals(4, length);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 // Main test entrypoint. 818 // Main test entrypoint.
803 static testMain() { 819 static testMain() {
804 testRead(); 820 testRead();
805 testReadSync(); 821 testReadSync();
806 testReadStream(); 822 testReadStream();
807 testLength(); 823 testLength();
808 testLengthSync(); 824 testLengthSync();
809 testPosition(); 825 testPosition();
810 testPositionSync(); 826 testPositionSync();
811 testMixedSyncAndAsync(); 827 testMixedSyncAndAsync();
828 testOpenDirectoryAsFile();
829 testOpenDirectoryAsFileSync();
812 830
813 createTempDirectory(() { 831 createTempDirectory(() {
814 testReadWrite(); 832 testReadWrite();
815 testReadWriteSync(); 833 testReadWriteSync();
816 testReadWriteStream(); 834 testReadWriteStream();
817 testReadEmptyFileSync(); 835 testReadEmptyFileSync();
818 testReadEmptyFile(); 836 testReadEmptyFile();
819 testTruncate(); 837 testTruncate();
820 testTruncateSync(); 838 testTruncateSync();
821 testCloseException(); 839 testCloseException();
822 testCloseExceptionStream(); 840 testCloseExceptionStream();
823 testBufferOutOfBoundsException(); 841 testBufferOutOfBoundsException();
824 testAppend(); 842 testAppend();
825 testAppendSync(); 843 testAppendSync();
826 testWriteAppend(); 844 testWriteAppend();
827 testOutputStreamWriteAppend(); 845 testOutputStreamWriteAppend();
828 }); 846 });
829 } 847 }
830 } 848 }
831 849
832 main() { 850 main() {
833 FileTest.testMain(); 851 FileTest.testMain();
834 } 852 }
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698