| 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 | 8 |
| 9 class MyListOfOneElement implements List { | 9 class MyListOfOneElement implements List { |
| 10 int _value; | 10 int _value; |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 var port = new ReceivePort.singleShot(); | 908 var port = new ReceivePort.singleShot(); |
| 909 port.receive((result, replyTo) { | 909 port.receive((result, replyTo) { |
| 910 Expect.equals(1, result); | 910 Expect.equals(1, result); |
| 911 }); | 911 }); |
| 912 var name = getFilename("tests/vm/data/fixed_length_file"); | 912 var name = getFilename("tests/vm/data/fixed_length_file"); |
| 913 var f = new File(name); | 913 var f = new File(name); |
| 914 f.readAsText('UTF-8'); | 914 f.readAsText('UTF-8'); |
| 915 f.readAsTextHandler = (text) { | 915 f.readAsTextHandler = (text) { |
| 916 Expect.isTrue(text.endsWith("42 bytes.")); | 916 Expect.isTrue(text.endsWith("42 bytes.")); |
| 917 Expect.equals(42, text.length); | 917 Expect.equals(42, text.length); |
| 918 var name = getFilename("tests/standalone/src/read_as_text.dat"); | 918 var name = getDataFilename("tests/standalone/src/read_as_text.dat"); |
| 919 var f = new File(name); | 919 var f = new File(name); |
| 920 f.errorHandler = (e) => Expect.fail("No errors expected"); | 920 f.errorHandler = (e) => Expect.fail("No errors expected"); |
| 921 f.readAsText('UTF-8'); | 921 f.readAsText('UTF-8'); |
| 922 f.readAsTextHandler = (text) { | 922 f.readAsTextHandler = (text) { |
| 923 Expect.equals(6, text.length); | 923 Expect.equals(6, text.length); |
| 924 var expected = [955, 120, 46, 32, 120, 10]; | 924 var expected = [955, 120, 46, 32, 120, 10]; |
| 925 Expect.listEquals(expected, text.charCodes()); | 925 Expect.listEquals(expected, text.charCodes()); |
| 926 f.readAsText('ISO-8859-1'); | 926 f.readAsText('ISO-8859-1'); |
| 927 f.readAsTextHandler = (text) { | 927 f.readAsTextHandler = (text) { |
| 928 Expect.equals(7, text.length); | 928 Expect.equals(7, text.length); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 941 f.errorHandler = (e) { | 941 f.errorHandler = (e) { |
| 942 Expect.fail("No errors expected: $e"); | 942 Expect.fail("No errors expected: $e"); |
| 943 }; | 943 }; |
| 944 } | 944 } |
| 945 | 945 |
| 946 static void testReadAsTextSync() { | 946 static void testReadAsTextSync() { |
| 947 var name = getFilename("tests/vm/data/fixed_length_file"); | 947 var name = getFilename("tests/vm/data/fixed_length_file"); |
| 948 var text = new File(name).readAsTextSync(); | 948 var text = new File(name).readAsTextSync(); |
| 949 Expect.isTrue(text.endsWith("42 bytes.")); | 949 Expect.isTrue(text.endsWith("42 bytes.")); |
| 950 Expect.equals(42, text.length); | 950 Expect.equals(42, text.length); |
| 951 name = getFilename("tests/standalone/src/read_as_text.dat"); | 951 name = getDataFilename("tests/standalone/src/read_as_text.dat"); |
| 952 text = new File(name).readAsTextSync(); | 952 text = new File(name).readAsTextSync(); |
| 953 Expect.equals(6, text.length); | 953 Expect.equals(6, text.length); |
| 954 var expected = [955, 120, 46, 32, 120, 10]; | 954 var expected = [955, 120, 46, 32, 120, 10]; |
| 955 Expect.listEquals(expected, text.charCodes()); | 955 Expect.listEquals(expected, text.charCodes()); |
| 956 Expect.throws(() { new File(name).readAsTextSync("ASCII"); }); | 956 Expect.throws(() { new File(name).readAsTextSync("ASCII"); }); |
| 957 text = new File(name).readAsTextSync("ISO-8859-1"); | 957 text = new File(name).readAsTextSync("ISO-8859-1"); |
| 958 expected = [206, 187, 120, 46, 32, 120, 10]; | 958 expected = [206, 187, 120, 46, 32, 120, 10]; |
| 959 Expect.equals(7, text.length); | 959 Expect.equals(7, text.length); |
| 960 Expect.listEquals(expected, text.charCodes()); | 960 Expect.listEquals(expected, text.charCodes()); |
| 961 } | 961 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 979 }; | 979 }; |
| 980 } | 980 } |
| 981 | 981 |
| 982 static void testReadAsLinesSync() { | 982 static void testReadAsLinesSync() { |
| 983 var name = getFilename("tests/vm/data/fixed_length_file"); | 983 var name = getFilename("tests/vm/data/fixed_length_file"); |
| 984 var lines = new File(name).readAsLinesSync(); | 984 var lines = new File(name).readAsLinesSync(); |
| 985 Expect.equals(1, lines.length); | 985 Expect.equals(1, lines.length); |
| 986 var line = lines[0]; | 986 var line = lines[0]; |
| 987 Expect.isTrue(line.endsWith("42 bytes.")); | 987 Expect.isTrue(line.endsWith("42 bytes.")); |
| 988 Expect.equals(42, line.length); | 988 Expect.equals(42, line.length); |
| 989 name = getFilename("tests/standalone/src/readline_test1.dat"); | 989 name = getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 990 lines = new File(name).readAsLinesSync(); | 990 lines = new File(name).readAsLinesSync(); |
| 991 Expect.equals(10, lines.length); | 991 Expect.equals(10, lines.length); |
| 992 } | 992 } |
| 993 | 993 |
| 994 static void testReadAsErrors() { | 994 static void testReadAsErrors() { |
| 995 var f = new File('.'); | 995 var f = new File('.'); |
| 996 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); | 996 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); |
| 997 Expect.throws(f.readAsTextSync, (e) => e is FileIOException); | 997 Expect.throws(f.readAsTextSync, (e) => e is FileIOException); |
| 998 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); | 998 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); |
| 999 // TODO(ager): Add tests of errors in readAsBytes when input | 999 // TODO(ager): Add tests of errors in readAsBytes when input |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 openedFile.closeSync(); | 1057 openedFile.closeSync(); |
| 1058 file.deleteSync(); | 1058 file.deleteSync(); |
| 1059 Expect.isFalse(file.existsSync()); | 1059 Expect.isFalse(file.existsSync()); |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 // Helper method to be able to run the test from the runtime | 1062 // Helper method to be able to run the test from the runtime |
| 1063 // directory, or the top directory. | 1063 // directory, or the top directory. |
| 1064 static String getFilename(String path) => | 1064 static String getFilename(String path) => |
| 1065 new File(path).existsSync() ? path : 'runtime/' + path; | 1065 new File(path).existsSync() ? path : 'runtime/' + path; |
| 1066 | 1066 |
| 1067 static String getDataFilename(String path) => |
| 1068 new File(path).existsSync() ? path : '../' + path; |
| 1069 |
| 1067 // Main test entrypoint. | 1070 // Main test entrypoint. |
| 1068 static testMain() { | 1071 static testMain() { |
| 1069 testRead(); | 1072 testRead(); |
| 1070 testReadSync(); | 1073 testReadSync(); |
| 1071 testReadStream(); | 1074 testReadStream(); |
| 1072 testLength(); | 1075 testLength(); |
| 1073 testLengthSync(); | 1076 testLengthSync(); |
| 1074 testPosition(); | 1077 testPosition(); |
| 1075 testPositionSync(); | 1078 testPositionSync(); |
| 1076 testMixedSyncAndAsync(); | 1079 testMixedSyncAndAsync(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1102 testWriteVariousLists(); | 1105 testWriteVariousLists(); |
| 1103 testDirectory(); | 1106 testDirectory(); |
| 1104 testDirectorySync(); | 1107 testDirectorySync(); |
| 1105 }); | 1108 }); |
| 1106 } | 1109 } |
| 1107 } | 1110 } |
| 1108 | 1111 |
| 1109 main() { | 1112 main() { |
| 1110 FileTest.testMain(); | 1113 FileTest.testMain(); |
| 1111 } | 1114 } |
| OLD | NEW |