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

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

Issue 10891020: Update almost all tests (except co19) to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge. Created 8 years, 3 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 file I/O. 5 // Dart test program for testing file I/O.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 class MyListOfOneElement implements List { 10 class MyListOfOneElement implements List {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 752
753 // Tests exception handling after file was closed. 753 // Tests exception handling after file was closed.
754 static void testCloseException() { 754 static void testCloseException() {
755 bool exceptionCaught = false; 755 bool exceptionCaught = false;
756 bool wrongExceptionCaught = false; 756 bool wrongExceptionCaught = false;
757 File input = new File(tempDirectory.path.concat("/out_close_exception")); 757 File input = new File(tempDirectory.path.concat("/out_close_exception"));
758 RandomAccessFile openedFile = input.openSync(FileMode.WRITE); 758 RandomAccessFile openedFile = input.openSync(FileMode.WRITE);
759 openedFile.closeSync(); 759 openedFile.closeSync();
760 try { 760 try {
761 openedFile.readByteSync(); 761 openedFile.readByteSync();
762 } catch (FileIOException ex) { 762 } on FileIOException catch (ex) {
763 exceptionCaught = true; 763 exceptionCaught = true;
764 } catch (Exception ex) { 764 } on Exception catch (ex) {
765 wrongExceptionCaught = true; 765 wrongExceptionCaught = true;
766 } 766 }
767 Expect.equals(true, exceptionCaught); 767 Expect.equals(true, exceptionCaught);
768 Expect.equals(true, !wrongExceptionCaught); 768 Expect.equals(true, !wrongExceptionCaught);
769 exceptionCaught = false; 769 exceptionCaught = false;
770 try { 770 try {
771 openedFile.writeByteSync(1); 771 openedFile.writeByteSync(1);
772 } catch (FileIOException ex) { 772 } on FileIOException catch (ex) {
773 exceptionCaught = true; 773 exceptionCaught = true;
774 } catch (Exception ex) { 774 } on Exception catch (ex) {
775 wrongExceptionCaught = true; 775 wrongExceptionCaught = true;
776 } 776 }
777 Expect.equals(true, exceptionCaught); 777 Expect.equals(true, exceptionCaught);
778 Expect.equals(true, !wrongExceptionCaught); 778 Expect.equals(true, !wrongExceptionCaught);
779 exceptionCaught = false; 779 exceptionCaught = false;
780 try { 780 try {
781 openedFile.writeStringSync("Test"); 781 openedFile.writeStringSync("Test");
782 } catch (FileIOException ex) { 782 } on FileIOException catch (ex) {
783 exceptionCaught = true; 783 exceptionCaught = true;
784 } catch (Exception ex) { 784 } on Exception catch (ex) {
785 wrongExceptionCaught = true; 785 wrongExceptionCaught = true;
786 } 786 }
787 Expect.equals(true, exceptionCaught); 787 Expect.equals(true, exceptionCaught);
788 Expect.equals(true, !wrongExceptionCaught); 788 Expect.equals(true, !wrongExceptionCaught);
789 exceptionCaught = false; 789 exceptionCaught = false;
790 try { 790 try {
791 List<int> buffer = new List<int>(100); 791 List<int> buffer = new List<int>(100);
792 openedFile.readListSync(buffer, 0, 10); 792 openedFile.readListSync(buffer, 0, 10);
793 } catch (FileIOException ex) { 793 } on FileIOException catch (ex) {
794 exceptionCaught = true; 794 exceptionCaught = true;
795 } catch (Exception ex) { 795 } on Exception catch (ex) {
796 wrongExceptionCaught = true; 796 wrongExceptionCaught = true;
797 } 797 }
798 Expect.equals(true, exceptionCaught); 798 Expect.equals(true, exceptionCaught);
799 Expect.equals(true, !wrongExceptionCaught); 799 Expect.equals(true, !wrongExceptionCaught);
800 exceptionCaught = false; 800 exceptionCaught = false;
801 try { 801 try {
802 List<int> buffer = new List<int>(100); 802 List<int> buffer = new List<int>(100);
803 openedFile.writeListSync(buffer, 0, 10); 803 openedFile.writeListSync(buffer, 0, 10);
804 } catch (FileIOException ex) { 804 } on FileIOException catch (ex) {
805 exceptionCaught = true; 805 exceptionCaught = true;
806 } catch (Exception ex) { 806 } on Exception catch (ex) {
807 wrongExceptionCaught = true; 807 wrongExceptionCaught = true;
808 } 808 }
809 Expect.equals(true, exceptionCaught); 809 Expect.equals(true, exceptionCaught);
810 Expect.equals(true, !wrongExceptionCaught); 810 Expect.equals(true, !wrongExceptionCaught);
811 exceptionCaught = false; 811 exceptionCaught = false;
812 try { 812 try {
813 openedFile.positionSync(); 813 openedFile.positionSync();
814 } catch (FileIOException ex) { 814 } on FileIOException catch (ex) {
815 exceptionCaught = true; 815 exceptionCaught = true;
816 } catch (Exception ex) { 816 } on Exception catch (ex) {
817 wrongExceptionCaught = true; 817 wrongExceptionCaught = true;
818 } 818 }
819 Expect.equals(true, exceptionCaught); 819 Expect.equals(true, exceptionCaught);
820 Expect.equals(true, !wrongExceptionCaught); 820 Expect.equals(true, !wrongExceptionCaught);
821 exceptionCaught = false; 821 exceptionCaught = false;
822 try { 822 try {
823 openedFile.lengthSync(); 823 openedFile.lengthSync();
824 } catch (FileIOException ex) { 824 } on FileIOException catch (ex) {
825 exceptionCaught = true; 825 exceptionCaught = true;
826 } catch (Exception ex) { 826 } on Exception catch (ex) {
827 wrongExceptionCaught = true; 827 wrongExceptionCaught = true;
828 } 828 }
829 Expect.equals(true, exceptionCaught); 829 Expect.equals(true, exceptionCaught);
830 Expect.equals(true, !wrongExceptionCaught); 830 Expect.equals(true, !wrongExceptionCaught);
831 exceptionCaught = false; 831 exceptionCaught = false;
832 try { 832 try {
833 openedFile.flushSync(); 833 openedFile.flushSync();
834 } catch (FileIOException ex) { 834 } on FileIOException catch (ex) {
835 exceptionCaught = true; 835 exceptionCaught = true;
836 } catch (Exception ex) { 836 } on Exception catch (ex) {
837 wrongExceptionCaught = true; 837 wrongExceptionCaught = true;
838 } 838 }
839 Expect.equals(true, exceptionCaught); 839 Expect.equals(true, exceptionCaught);
840 Expect.equals(true, !wrongExceptionCaught); 840 Expect.equals(true, !wrongExceptionCaught);
841 input.deleteSync(); 841 input.deleteSync();
842 } 842 }
843 843
844 // Tests stream exception handling after file was closed. 844 // Tests stream exception handling after file was closed.
845 static void testCloseExceptionStream() { 845 static void testCloseExceptionStream() {
846 asyncTestStarted(); 846 asyncTestStarted();
(...skipping 18 matching lines...) Expand all
865 // Tests buffer out of bounds exception. 865 // Tests buffer out of bounds exception.
866 static void testBufferOutOfBoundsException() { 866 static void testBufferOutOfBoundsException() {
867 bool exceptionCaught = false; 867 bool exceptionCaught = false;
868 bool wrongExceptionCaught = false; 868 bool wrongExceptionCaught = false;
869 File file = 869 File file =
870 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds")); 870 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds"));
871 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 871 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
872 try { 872 try {
873 List<int> buffer = new List<int>(10); 873 List<int> buffer = new List<int>(10);
874 openedFile.readListSync(buffer, 0, 12); 874 openedFile.readListSync(buffer, 0, 12);
875 } catch (IndexOutOfRangeException ex) { 875 } on IndexOutOfRangeException catch (ex) {
876 exceptionCaught = true; 876 exceptionCaught = true;
877 } catch (Exception ex) { 877 } on Exception catch (ex) {
878 wrongExceptionCaught = true; 878 wrongExceptionCaught = true;
879 } 879 }
880 Expect.equals(true, exceptionCaught); 880 Expect.equals(true, exceptionCaught);
881 Expect.equals(true, !wrongExceptionCaught); 881 Expect.equals(true, !wrongExceptionCaught);
882 exceptionCaught = false; 882 exceptionCaught = false;
883 try { 883 try {
884 List<int> buffer = new List<int>(10); 884 List<int> buffer = new List<int>(10);
885 openedFile.readListSync(buffer, 6, 6); 885 openedFile.readListSync(buffer, 6, 6);
886 } catch (IndexOutOfRangeException ex) { 886 } on IndexOutOfRangeException catch (ex) {
887 exceptionCaught = true; 887 exceptionCaught = true;
888 } catch (Exception ex) { 888 } on Exception catch (ex) {
889 wrongExceptionCaught = true; 889 wrongExceptionCaught = true;
890 } 890 }
891 Expect.equals(true, exceptionCaught); 891 Expect.equals(true, exceptionCaught);
892 Expect.equals(true, !wrongExceptionCaught); 892 Expect.equals(true, !wrongExceptionCaught);
893 exceptionCaught = false; 893 exceptionCaught = false;
894 try { 894 try {
895 List<int> buffer = new List<int>(10); 895 List<int> buffer = new List<int>(10);
896 openedFile.readListSync(buffer, -1, 1); 896 openedFile.readListSync(buffer, -1, 1);
897 } catch (IndexOutOfRangeException ex) { 897 } on IndexOutOfRangeException catch (ex) {
898 exceptionCaught = true; 898 exceptionCaught = true;
899 } catch (Exception ex) { 899 } on Exception catch (ex) {
900 wrongExceptionCaught = true; 900 wrongExceptionCaught = true;
901 } 901 }
902 Expect.equals(true, exceptionCaught); 902 Expect.equals(true, exceptionCaught);
903 Expect.equals(true, !wrongExceptionCaught); 903 Expect.equals(true, !wrongExceptionCaught);
904 exceptionCaught = false; 904 exceptionCaught = false;
905 try { 905 try {
906 List<int> buffer = new List<int>(10); 906 List<int> buffer = new List<int>(10);
907 openedFile.readListSync(buffer, 0, -1); 907 openedFile.readListSync(buffer, 0, -1);
908 } catch (IndexOutOfRangeException ex) { 908 } on IndexOutOfRangeException catch (ex) {
909 exceptionCaught = true; 909 exceptionCaught = true;
910 } catch (Exception ex) { 910 } on Exception catch (ex) {
911 wrongExceptionCaught = true; 911 wrongExceptionCaught = true;
912 } 912 }
913 Expect.equals(true, exceptionCaught); 913 Expect.equals(true, exceptionCaught);
914 Expect.equals(true, !wrongExceptionCaught); 914 Expect.equals(true, !wrongExceptionCaught);
915 exceptionCaught = false; 915 exceptionCaught = false;
916 try { 916 try {
917 List<int> buffer = new List<int>(10); 917 List<int> buffer = new List<int>(10);
918 openedFile.writeListSync(buffer, 0, 12); 918 openedFile.writeListSync(buffer, 0, 12);
919 } catch (IndexOutOfRangeException ex) { 919 } on IndexOutOfRangeException catch (ex) {
920 exceptionCaught = true; 920 exceptionCaught = true;
921 } catch (Exception ex) { 921 } on Exception catch (ex) {
922 wrongExceptionCaught = true; 922 wrongExceptionCaught = true;
923 } 923 }
924 Expect.equals(true, exceptionCaught); 924 Expect.equals(true, exceptionCaught);
925 Expect.equals(true, !wrongExceptionCaught); 925 Expect.equals(true, !wrongExceptionCaught);
926 exceptionCaught = false; 926 exceptionCaught = false;
927 try { 927 try {
928 List<int> buffer = new List<int>(10); 928 List<int> buffer = new List<int>(10);
929 openedFile.writeListSync(buffer, 6, 6); 929 openedFile.writeListSync(buffer, 6, 6);
930 } catch (IndexOutOfRangeException ex) { 930 } on IndexOutOfRangeException catch (ex) {
931 exceptionCaught = true; 931 exceptionCaught = true;
932 } catch (Exception ex) { 932 } on Exception catch (ex) {
933 wrongExceptionCaught = true; 933 wrongExceptionCaught = true;
934 } 934 }
935 Expect.equals(true, exceptionCaught); 935 Expect.equals(true, exceptionCaught);
936 Expect.equals(true, !wrongExceptionCaught); 936 Expect.equals(true, !wrongExceptionCaught);
937 exceptionCaught = false; 937 exceptionCaught = false;
938 try { 938 try {
939 List<int> buffer = new List<int>(10); 939 List<int> buffer = new List<int>(10);
940 openedFile.writeListSync(buffer, -1, 1); 940 openedFile.writeListSync(buffer, -1, 1);
941 } catch (IndexOutOfRangeException ex) { 941 } on IndexOutOfRangeException catch (ex) {
942 exceptionCaught = true; 942 exceptionCaught = true;
943 } catch (Exception ex) { 943 } on Exception catch (ex) {
944 wrongExceptionCaught = true; 944 wrongExceptionCaught = true;
945 } 945 }
946 Expect.equals(true, exceptionCaught); 946 Expect.equals(true, exceptionCaught);
947 Expect.equals(true, !wrongExceptionCaught); 947 Expect.equals(true, !wrongExceptionCaught);
948 exceptionCaught = false; 948 exceptionCaught = false;
949 try { 949 try {
950 List<int> buffer = new List<int>(10); 950 List<int> buffer = new List<int>(10);
951 openedFile.writeListSync(buffer, 0, -1); 951 openedFile.writeListSync(buffer, 0, -1);
952 } catch (IndexOutOfRangeException ex) { 952 } on IndexOutOfRangeException catch (ex) {
953 exceptionCaught = true; 953 exceptionCaught = true;
954 } catch (Exception ex) { 954 } on Exception catch (ex) {
955 wrongExceptionCaught = true; 955 wrongExceptionCaught = true;
956 } 956 }
957 Expect.equals(true, exceptionCaught); 957 Expect.equals(true, exceptionCaught);
958 Expect.equals(true, !wrongExceptionCaught); 958 Expect.equals(true, !wrongExceptionCaught);
959 openedFile.closeSync(); 959 openedFile.closeSync();
960 file.deleteSync(); 960 file.deleteSync();
961 } 961 }
962 962
963 static void testOpenDirectoryAsFile() { 963 static void testOpenDirectoryAsFile() {
964 var f = new File('.'); 964 var f = new File('.');
965 var future = f.open(FileMode.READ); 965 var future = f.open(FileMode.READ);
966 future.then((r) => Expect.fail('Directory opened as file')); 966 future.then((r) => Expect.fail('Directory opened as file'));
967 future.handleException((e) => true); 967 future.handleException((e) => true);
968 } 968 }
969 969
970 static void testOpenDirectoryAsFileSync() { 970 static void testOpenDirectoryAsFileSync() {
971 var f = new File('.'); 971 var f = new File('.');
972 try { 972 try {
973 f.openSync(); 973 f.openSync();
974 Expect.fail("Expected exception opening directory as file"); 974 Expect.fail("Expected exception opening directory as file");
975 } catch (var e) { 975 } catch (e) {
976 Expect.isTrue(e is FileIOException); 976 Expect.isTrue(e is FileIOException);
977 } 977 }
978 } 978 }
979 979
980 static void testOpenFileFromPath() { 980 static void testOpenFileFromPath() {
981 var name = getFilename("tests/vm/data/fixed_length_file"); 981 var name = getFilename("tests/vm/data/fixed_length_file");
982 var path = new Path(name); 982 var path = new Path(name);
983 var f = new File.fromPath(path); 983 var f = new File.fromPath(path);
984 Expect.isTrue(f.existsSync()); 984 Expect.isTrue(f.existsSync());
985 name = f.fullPathSync(); 985 name = f.fullPathSync();
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 testWriteVariousLists(); 1230 testWriteVariousLists();
1231 testDirectory(); 1231 testDirectory();
1232 testDirectorySync(); 1232 testDirectorySync();
1233 }); 1233 });
1234 } 1234 }
1235 } 1235 }
1236 1236
1237 main() { 1237 main() {
1238 FileTest.testMain(); 1238 FileTest.testMain();
1239 } 1239 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_invalid_arguments_test.dart ('k') | tests/standalone/io/fuzz_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698