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 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 706 |
707 // Tests exception handling after file was closed. | 707 // Tests exception handling after file was closed. |
708 static void testCloseException() { | 708 static void testCloseException() { |
709 bool exceptionCaught = false; | 709 bool exceptionCaught = false; |
710 bool wrongExceptionCaught = false; | 710 bool wrongExceptionCaught = false; |
711 File input = new File(tempDirectory.path + "/out_close_exception"); | 711 File input = new File(tempDirectory.path + "/out_close_exception"); |
712 RandomAccessFile openedFile = input.openSync(mode: WRITE); | 712 RandomAccessFile openedFile = input.openSync(mode: WRITE); |
713 openedFile.closeSync(); | 713 openedFile.closeSync(); |
714 try { | 714 try { |
715 openedFile.readByteSync(); | 715 openedFile.readByteSync(); |
716 } on FileIOException catch (ex) { | 716 } on FileException catch (ex) { |
717 exceptionCaught = true; | 717 exceptionCaught = true; |
718 } on Exception catch (ex) { | 718 } on Exception catch (ex) { |
719 wrongExceptionCaught = true; | 719 wrongExceptionCaught = true; |
720 } | 720 } |
721 Expect.equals(true, exceptionCaught); | 721 Expect.equals(true, exceptionCaught); |
722 Expect.equals(true, !wrongExceptionCaught); | 722 Expect.equals(true, !wrongExceptionCaught); |
723 exceptionCaught = false; | 723 exceptionCaught = false; |
724 try { | 724 try { |
725 openedFile.writeByteSync(1); | 725 openedFile.writeByteSync(1); |
726 } on FileIOException catch (ex) { | 726 } on FileException catch (ex) { |
727 exceptionCaught = true; | 727 exceptionCaught = true; |
728 } on Exception catch (ex) { | 728 } on Exception catch (ex) { |
729 wrongExceptionCaught = true; | 729 wrongExceptionCaught = true; |
730 } | 730 } |
731 Expect.equals(true, exceptionCaught); | 731 Expect.equals(true, exceptionCaught); |
732 Expect.equals(true, !wrongExceptionCaught); | 732 Expect.equals(true, !wrongExceptionCaught); |
733 exceptionCaught = false; | 733 exceptionCaught = false; |
734 try { | 734 try { |
735 openedFile.writeStringSync("Test"); | 735 openedFile.writeStringSync("Test"); |
736 } on FileIOException catch (ex) { | 736 } on FileException catch (ex) { |
737 exceptionCaught = true; | 737 exceptionCaught = true; |
738 } on Exception catch (ex) { | 738 } on Exception catch (ex) { |
739 wrongExceptionCaught = true; | 739 wrongExceptionCaught = true; |
740 } | 740 } |
741 Expect.equals(true, exceptionCaught); | 741 Expect.equals(true, exceptionCaught); |
742 Expect.equals(true, !wrongExceptionCaught); | 742 Expect.equals(true, !wrongExceptionCaught); |
743 exceptionCaught = false; | 743 exceptionCaught = false; |
744 try { | 744 try { |
745 List<int> buffer = new List<int>(100); | 745 List<int> buffer = new List<int>(100); |
746 openedFile.readIntoSync(buffer, 0, 10); | 746 openedFile.readIntoSync(buffer, 0, 10); |
747 } on FileIOException catch (ex) { | 747 } on FileException catch (ex) { |
748 exceptionCaught = true; | 748 exceptionCaught = true; |
749 } on Exception catch (ex) { | 749 } on Exception catch (ex) { |
750 wrongExceptionCaught = true; | 750 wrongExceptionCaught = true; |
751 } | 751 } |
752 Expect.equals(true, exceptionCaught); | 752 Expect.equals(true, exceptionCaught); |
753 Expect.equals(true, !wrongExceptionCaught); | 753 Expect.equals(true, !wrongExceptionCaught); |
754 exceptionCaught = false; | 754 exceptionCaught = false; |
755 try { | 755 try { |
756 List<int> buffer = new List<int>(100); | 756 List<int> buffer = new List<int>(100); |
757 openedFile.writeFromSync(buffer, 0, 10); | 757 openedFile.writeFromSync(buffer, 0, 10); |
758 } on FileIOException catch (ex) { | 758 } on FileException catch (ex) { |
759 exceptionCaught = true; | 759 exceptionCaught = true; |
760 } on Exception catch (ex) { | 760 } on Exception catch (ex) { |
761 wrongExceptionCaught = true; | 761 wrongExceptionCaught = true; |
762 } | 762 } |
763 Expect.equals(true, exceptionCaught); | 763 Expect.equals(true, exceptionCaught); |
764 Expect.equals(true, !wrongExceptionCaught); | 764 Expect.equals(true, !wrongExceptionCaught); |
765 exceptionCaught = false; | 765 exceptionCaught = false; |
766 try { | 766 try { |
767 openedFile.positionSync(); | 767 openedFile.positionSync(); |
768 } on FileIOException catch (ex) { | 768 } on FileException catch (ex) { |
769 exceptionCaught = true; | 769 exceptionCaught = true; |
770 } on Exception catch (ex) { | 770 } on Exception catch (ex) { |
771 wrongExceptionCaught = true; | 771 wrongExceptionCaught = true; |
772 } | 772 } |
773 Expect.equals(true, exceptionCaught); | 773 Expect.equals(true, exceptionCaught); |
774 Expect.equals(true, !wrongExceptionCaught); | 774 Expect.equals(true, !wrongExceptionCaught); |
775 exceptionCaught = false; | 775 exceptionCaught = false; |
776 try { | 776 try { |
777 openedFile.lengthSync(); | 777 openedFile.lengthSync(); |
778 } on FileIOException catch (ex) { | 778 } on FileException catch (ex) { |
779 exceptionCaught = true; | 779 exceptionCaught = true; |
780 } on Exception catch (ex) { | 780 } on Exception catch (ex) { |
781 wrongExceptionCaught = true; | 781 wrongExceptionCaught = true; |
782 } | 782 } |
783 Expect.equals(true, exceptionCaught); | 783 Expect.equals(true, exceptionCaught); |
784 Expect.equals(true, !wrongExceptionCaught); | 784 Expect.equals(true, !wrongExceptionCaught); |
785 exceptionCaught = false; | 785 exceptionCaught = false; |
786 try { | 786 try { |
787 openedFile.flushSync(); | 787 openedFile.flushSync(); |
788 } on FileIOException catch (ex) { | 788 } on FileException catch (ex) { |
789 exceptionCaught = true; | 789 exceptionCaught = true; |
790 } on Exception catch (ex) { | 790 } on Exception catch (ex) { |
791 wrongExceptionCaught = true; | 791 wrongExceptionCaught = true; |
792 } | 792 } |
793 Expect.equals(true, exceptionCaught); | 793 Expect.equals(true, exceptionCaught); |
794 Expect.equals(true, !wrongExceptionCaught); | 794 Expect.equals(true, !wrongExceptionCaught); |
795 input.deleteSync(); | 795 input.deleteSync(); |
796 } | 796 } |
797 | 797 |
798 // Tests stream exception handling after file was closed. | 798 // Tests stream exception handling after file was closed. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 future.then((r) => Expect.fail('Directory opened as file')) | 915 future.then((r) => Expect.fail('Directory opened as file')) |
916 .catchError((e) {}); | 916 .catchError((e) {}); |
917 } | 917 } |
918 | 918 |
919 static void testOpenDirectoryAsFileSync() { | 919 static void testOpenDirectoryAsFileSync() { |
920 var f = new File('.'); | 920 var f = new File('.'); |
921 try { | 921 try { |
922 f.openSync(); | 922 f.openSync(); |
923 Expect.fail("Expected exception opening directory as file"); | 923 Expect.fail("Expected exception opening directory as file"); |
924 } catch (e) { | 924 } catch (e) { |
925 Expect.isTrue(e is FileIOException); | 925 Expect.isTrue(e is FileException); |
926 } | 926 } |
927 } | 927 } |
928 | 928 |
929 static void testOpenFileFromPath() { | 929 static void testOpenFileFromPath() { |
930 var name = getFilename("tests/vm/data/fixed_length_file"); | 930 var name = getFilename("tests/vm/data/fixed_length_file"); |
931 var path = new Path(name); | 931 var path = new Path(name); |
932 var f = new File.fromPath(path); | 932 var f = new File.fromPath(path); |
933 Expect.isTrue(f.existsSync()); | 933 Expect.isTrue(f.existsSync()); |
934 name = f.fullPathSync(); | 934 name = f.fullPathSync(); |
935 path = new Path(name); | 935 path = new Path(name); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 } | 1079 } |
1080 | 1080 |
1081 | 1081 |
1082 static void testReadAsErrors() { | 1082 static void testReadAsErrors() { |
1083 var port = new ReceivePort(); | 1083 var port = new ReceivePort(); |
1084 port.receive((message, _) { | 1084 port.receive((message, _) { |
1085 port.close(); | 1085 port.close(); |
1086 Expect.equals(1, message); | 1086 Expect.equals(1, message); |
1087 }); | 1087 }); |
1088 var f = new File('.'); | 1088 var f = new File('.'); |
1089 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); | 1089 Expect.throws(f.readAsBytesSync, (e) => e is FileException); |
1090 Expect.throws(f.readAsStringSync, (e) => e is FileIOException); | 1090 Expect.throws(f.readAsStringSync, (e) => e is FileException); |
1091 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); | 1091 Expect.throws(f.readAsLinesSync, (e) => e is FileException); |
1092 var readAsBytesFuture = f.readAsBytes(); | 1092 var readAsBytesFuture = f.readAsBytes(); |
1093 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected")) | 1093 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected")) |
1094 .catchError((e) { | 1094 .catchError((e) { |
1095 var readAsStringFuture = f.readAsString(encoding: UTF_8); | 1095 var readAsStringFuture = f.readAsString(encoding: UTF_8); |
1096 readAsStringFuture.then((text) => Expect.fail("no text expected")) | 1096 readAsStringFuture.then((text) => Expect.fail("no text expected")) |
1097 .catchError((e) { | 1097 .catchError((e) { |
1098 var readAsLinesFuture = f.readAsLines(encoding: UTF_8); | 1098 var readAsLinesFuture = f.readAsLines(encoding: UTF_8); |
1099 readAsLinesFuture.then((lines) => Expect.fail("no lines expected")) | 1099 readAsLinesFuture.then((lines) => Expect.fail("no lines expected")) |
1100 .catchError((e) { | 1100 .catchError((e) { |
1101 port.toSendPort().send(1); | 1101 port.toSendPort().send(1); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 testDirectorySync(); | 1276 testDirectorySync(); |
1277 testWriteStringUtf8(); | 1277 testWriteStringUtf8(); |
1278 testWriteStringUtf8Sync(); | 1278 testWriteStringUtf8Sync(); |
1279 }); | 1279 }); |
1280 } | 1280 } |
1281 } | 1281 } |
1282 | 1282 |
1283 main() { | 1283 main() { |
1284 FileTest.testMain(); | 1284 FileTest.testMain(); |
1285 } | 1285 } |
OLD | NEW |