OLD | NEW |
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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 var port = new ReceivePort(); | 885 var port = new ReceivePort(); |
886 port.receive((result, replyTo) { | 886 port.receive((result, replyTo) { |
887 port.close(); | 887 port.close(); |
888 Expect.equals(1, result); | 888 Expect.equals(1, result); |
889 }); | 889 }); |
890 var name = getFilename("tests/vm/data/fixed_length_file"); | 890 var name = getFilename("tests/vm/data/fixed_length_file"); |
891 var f = new File(name); | 891 var f = new File(name); |
892 f.readAsText(Encoding.UTF_8, (text) { | 892 f.readAsText(Encoding.UTF_8, (text) { |
893 Expect.isTrue(text.endsWith("42 bytes.")); | 893 Expect.isTrue(text.endsWith("42 bytes.")); |
894 Expect.equals(42, text.length); | 894 Expect.equals(42, text.length); |
895 var name = getDataFilename("tests/standalone/src/io/read_as_text.dat"); | 895 var name = getDataFilename("tests/standalone/io/read_as_text.dat"); |
896 var f = new File(name); | 896 var f = new File(name); |
897 f.onError = (e) => Expect.fail("No errors expected: $e"); | 897 f.onError = (e) => Expect.fail("No errors expected: $e"); |
898 f.readAsText(Encoding.UTF_8, (text) { | 898 f.readAsText(Encoding.UTF_8, (text) { |
899 Expect.equals(6, text.length); | 899 Expect.equals(6, text.length); |
900 var expected = [955, 120, 46, 32, 120, 10]; | 900 var expected = [955, 120, 46, 32, 120, 10]; |
901 Expect.listEquals(expected, text.charCodes()); | 901 Expect.listEquals(expected, text.charCodes()); |
902 f.readAsText(Encoding.ISO_8859_1, (text) { | 902 f.readAsText(Encoding.ISO_8859_1, (text) { |
903 Expect.equals(7, text.length); | 903 Expect.equals(7, text.length); |
904 var expected = [206, 187, 120, 46, 32, 120, 10]; | 904 var expected = [206, 187, 120, 46, 32, 120, 10]; |
905 Expect.listEquals(expected, text.charCodes()); | 905 Expect.listEquals(expected, text.charCodes()); |
906 f.onError = (e) { | 906 f.onError = (e) { |
907 port.toSendPort().send(1); | 907 port.toSendPort().send(1); |
908 }; | 908 }; |
909 f.readAsText(Encoding.ASCII, (text) { | 909 f.readAsText(Encoding.ASCII, (text) { |
910 Expect.fail("Non-ascii char should cause error"); | 910 Expect.fail("Non-ascii char should cause error"); |
911 }); | 911 }); |
912 }); | 912 }); |
913 }); | 913 }); |
914 }); | 914 }); |
915 f.onError = (e) { | 915 f.onError = (e) { |
916 Expect.fail("No errors expected: $e"); | 916 Expect.fail("No errors expected: $e"); |
917 }; | 917 }; |
918 } | 918 } |
919 | 919 |
920 static void testReadAsTextSync() { | 920 static void testReadAsTextSync() { |
921 var name = getFilename("tests/vm/data/fixed_length_file"); | 921 var name = getFilename("tests/vm/data/fixed_length_file"); |
922 var text = new File(name).readAsTextSync(); | 922 var text = new File(name).readAsTextSync(); |
923 Expect.isTrue(text.endsWith("42 bytes.")); | 923 Expect.isTrue(text.endsWith("42 bytes.")); |
924 Expect.equals(42, text.length); | 924 Expect.equals(42, text.length); |
925 name = getDataFilename("tests/standalone/src/io/read_as_text.dat"); | 925 name = getDataFilename("tests/standalone/io/read_as_text.dat"); |
926 text = new File(name).readAsTextSync(); | 926 text = new File(name).readAsTextSync(); |
927 Expect.equals(6, text.length); | 927 Expect.equals(6, text.length); |
928 var expected = [955, 120, 46, 32, 120, 10]; | 928 var expected = [955, 120, 46, 32, 120, 10]; |
929 Expect.listEquals(expected, text.charCodes()); | 929 Expect.listEquals(expected, text.charCodes()); |
930 Expect.throws(() { new File(name).readAsTextSync(Encoding.ASCII); }); | 930 Expect.throws(() { new File(name).readAsTextSync(Encoding.ASCII); }); |
931 text = new File(name).readAsTextSync(Encoding.ISO_8859_1); | 931 text = new File(name).readAsTextSync(Encoding.ISO_8859_1); |
932 expected = [206, 187, 120, 46, 32, 120, 10]; | 932 expected = [206, 187, 120, 46, 32, 120, 10]; |
933 Expect.equals(7, text.length); | 933 Expect.equals(7, text.length); |
934 Expect.listEquals(expected, text.charCodes()); | 934 Expect.listEquals(expected, text.charCodes()); |
935 } | 935 } |
(...skipping 15 matching lines...) Expand all Loading... |
951 f.onError = (e) => Expect.fail("No errors expected: $e"); | 951 f.onError = (e) => Expect.fail("No errors expected: $e"); |
952 } | 952 } |
953 | 953 |
954 static void testReadAsLinesSync() { | 954 static void testReadAsLinesSync() { |
955 var name = getFilename("tests/vm/data/fixed_length_file"); | 955 var name = getFilename("tests/vm/data/fixed_length_file"); |
956 var lines = new File(name).readAsLinesSync(); | 956 var lines = new File(name).readAsLinesSync(); |
957 Expect.equals(1, lines.length); | 957 Expect.equals(1, lines.length); |
958 var line = lines[0]; | 958 var line = lines[0]; |
959 Expect.isTrue(line.endsWith("42 bytes.")); | 959 Expect.isTrue(line.endsWith("42 bytes.")); |
960 Expect.equals(42, line.length); | 960 Expect.equals(42, line.length); |
961 name = getDataFilename("tests/standalone/src/io/readline_test1.dat"); | 961 name = getDataFilename("tests/standalone/io/readline_test1.dat"); |
962 lines = new File(name).readAsLinesSync(); | 962 lines = new File(name).readAsLinesSync(); |
963 Expect.equals(10, lines.length); | 963 Expect.equals(10, lines.length); |
964 } | 964 } |
965 | 965 |
966 | 966 |
967 static void testReadAsErrors() { | 967 static void testReadAsErrors() { |
968 var port = new ReceivePort(); | 968 var port = new ReceivePort(); |
969 port.receive((message, _) { | 969 port.receive((message, _) { |
970 port.close(); | 970 port.close(); |
971 Expect.equals(1, message); | 971 Expect.equals(1, message); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 testWriteVariousLists(); | 1079 testWriteVariousLists(); |
1080 testDirectory(); | 1080 testDirectory(); |
1081 testDirectorySync(); | 1081 testDirectorySync(); |
1082 }); | 1082 }); |
1083 } | 1083 } |
1084 } | 1084 } |
1085 | 1085 |
1086 main() { | 1086 main() { |
1087 FileTest.testMain(); | 1087 FileTest.testMain(); |
1088 } | 1088 } |
OLD | NEW |