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

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

Issue 10913005: Better handling of reading empty files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed the aproach slightly 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
« no previous file with comments | « runtime/tests/vm/data/empty_file ('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 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 class MyListOfOneElement implements List { 10 class MyListOfOneElement implements List {
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 Expect.equals(42, result); 996 Expect.equals(42, result);
997 }); 997 });
998 var name = getFilename("tests/vm/data/fixed_length_file"); 998 var name = getFilename("tests/vm/data/fixed_length_file");
999 var f = new File(name); 999 var f = new File(name);
1000 f.readAsBytes().then((bytes) { 1000 f.readAsBytes().then((bytes) {
1001 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 1001 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
1002 port.toSendPort().send(bytes.length); 1002 port.toSendPort().send(bytes.length);
1003 }); 1003 });
1004 } 1004 }
1005 1005
1006 static void testReadAsBytesEmptyFile() {
1007 var port = new ReceivePort();
1008 port.receive((result, replyTo) {
1009 port.close();
1010 Expect.equals(0, result);
1011 });
1012 var name = getFilename("tests/vm/data/empty_file");
1013 var f = new File(name);
1014 f.readAsBytes().then((bytes) {
1015 port.toSendPort().send(bytes.length);
1016 });
1017 }
1018
1006 static void testReadAsBytesSync() { 1019 static void testReadAsBytesSync() {
1007 var name = getFilename("tests/vm/data/fixed_length_file"); 1020 var name = getFilename("tests/vm/data/fixed_length_file");
1008 var bytes = new File(name).readAsBytesSync(); 1021 var bytes = new File(name).readAsBytesSync();
1009 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 1022 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
1010 Expect.equals(bytes.length, 42); 1023 Expect.equals(bytes.length, 42);
1011 } 1024 }
1012 1025
1026 static void testReadAsBytesSyncEmptyFile() {
1027 var name = getFilename("tests/vm/data/empty_file");
1028 var bytes = new File(name).readAsBytesSync();
1029 Expect.equals(bytes.length, 0);
1030 }
1031
1013 static void testReadAsText() { 1032 static void testReadAsText() {
1014 var port = new ReceivePort(); 1033 var port = new ReceivePort();
1015 port.receive((result, replyTo) { 1034 port.receive((result, replyTo) {
1016 port.close(); 1035 port.close();
1017 Expect.equals(1, result); 1036 Expect.equals(1, result);
1018 }); 1037 });
1019 var name = getFilename("tests/vm/data/fixed_length_file"); 1038 var name = getFilename("tests/vm/data/fixed_length_file");
1020 var f = new File(name); 1039 var f = new File(name);
1021 f.readAsText(Encoding.UTF_8).then((text) { 1040 f.readAsText(Encoding.UTF_8).then((text) {
1022 Expect.isTrue(text.endsWith("42 bytes.")); 1041 Expect.isTrue(text.endsWith("42 bytes."));
(...skipping 14 matching lines...) Expand all
1037 }); 1056 });
1038 readAsTextFuture.handleException((e) { 1057 readAsTextFuture.handleException((e) {
1039 port.toSendPort().send(1); 1058 port.toSendPort().send(1);
1040 return true; 1059 return true;
1041 }); 1060 });
1042 }); 1061 });
1043 }); 1062 });
1044 }); 1063 });
1045 } 1064 }
1046 1065
1066 static void testReadAsTextEmptyFile() {
1067 var port = new ReceivePort();
1068 port.receive((result, replyTo) {
1069 port.close();
1070 Expect.equals(0, result);
1071 });
1072 var name = getFilename("tests/vm/data/empty_file");
1073 var f = new File(name);
1074 f.readAsText(Encoding.UTF_8).then((text) {
1075 port.toSendPort().send(text.length);
1076 return true;
1077 });
1078 }
1079
1047 static void testReadAsTextSync() { 1080 static void testReadAsTextSync() {
1048 var name = getFilename("tests/vm/data/fixed_length_file"); 1081 var name = getFilename("tests/vm/data/fixed_length_file");
1049 var text = new File(name).readAsTextSync(); 1082 var text = new File(name).readAsTextSync();
1050 Expect.isTrue(text.endsWith("42 bytes.")); 1083 Expect.isTrue(text.endsWith("42 bytes."));
1051 Expect.equals(42, text.length); 1084 Expect.equals(42, text.length);
1052 name = getDataFilename("tests/standalone/io/read_as_text.dat"); 1085 name = getDataFilename("tests/standalone/io/read_as_text.dat");
1053 text = new File(name).readAsTextSync(); 1086 text = new File(name).readAsTextSync();
1054 Expect.equals(6, text.length); 1087 Expect.equals(6, text.length);
1055 var expected = [955, 120, 46, 32, 120, 10]; 1088 var expected = [955, 120, 46, 32, 120, 10];
1056 Expect.listEquals(expected, text.charCodes()); 1089 Expect.listEquals(expected, text.charCodes());
1057 Expect.throws(() { new File(name).readAsTextSync(Encoding.ASCII); }); 1090 Expect.throws(() { new File(name).readAsTextSync(Encoding.ASCII); });
1058 text = new File(name).readAsTextSync(Encoding.ISO_8859_1); 1091 text = new File(name).readAsTextSync(Encoding.ISO_8859_1);
1059 expected = [206, 187, 120, 46, 32, 120, 10]; 1092 expected = [206, 187, 120, 46, 32, 120, 10];
1060 Expect.equals(7, text.length); 1093 Expect.equals(7, text.length);
1061 Expect.listEquals(expected, text.charCodes()); 1094 Expect.listEquals(expected, text.charCodes());
1062 } 1095 }
1063 1096
1097 static void testReadAsTextSyncEmptyFile() {
1098 var name = getFilename("tests/vm/data/empty_file");
1099 var text = new File(name).readAsTextSync();
1100 Expect.equals(0, text.length);
1101 }
1102
1064 static void testReadAsLines() { 1103 static void testReadAsLines() {
1065 var port = new ReceivePort(); 1104 var port = new ReceivePort();
1066 port.receive((result, replyTo) { 1105 port.receive((result, replyTo) {
1067 port.close(); 1106 port.close();
1068 Expect.equals(42, result); 1107 Expect.equals(42, result);
1069 }); 1108 });
1070 var name = getFilename("tests/vm/data/fixed_length_file"); 1109 var name = getFilename("tests/vm/data/fixed_length_file");
1071 var f = new File(name); 1110 var f = new File(name);
1072 f.readAsLines(Encoding.UTF_8).then((lines) { 1111 f.readAsLines(Encoding.UTF_8).then((lines) {
1073 Expect.equals(1, lines.length); 1112 Expect.equals(1, lines.length);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 testReadSync(); 1233 testReadSync();
1195 testReadStream(); 1234 testReadStream();
1196 testLength(); 1235 testLength();
1197 testLengthSync(); 1236 testLengthSync();
1198 testPosition(); 1237 testPosition();
1199 testPositionSync(); 1238 testPositionSync();
1200 testOpenDirectoryAsFile(); 1239 testOpenDirectoryAsFile();
1201 testOpenDirectoryAsFileSync(); 1240 testOpenDirectoryAsFileSync();
1202 testOpenFileFromPath(); 1241 testOpenFileFromPath();
1203 testReadAsBytes(); 1242 testReadAsBytes();
1243 testReadAsBytesEmptyFile();
1204 testReadAsBytesSync(); 1244 testReadAsBytesSync();
1245 testReadAsBytesSyncEmptyFile();
1205 testReadAsText(); 1246 testReadAsText();
1247 testReadAsTextEmptyFile();
1206 testReadAsTextSync(); 1248 testReadAsTextSync();
1249 testReadAsTextSyncEmptyFile();
1207 testReadAsLines(); 1250 testReadAsLines();
1208 testReadAsLinesSync(); 1251 testReadAsLinesSync();
1209 testReadAsErrors(); 1252 testReadAsErrors();
1210 testLastModified(); 1253 testLastModified();
1211 testLastModifiedSync(); 1254 testLastModifiedSync();
1212 1255
1213 createTempDirectory(() { 1256 createTempDirectory(() {
1214 testReadWrite(); 1257 testReadWrite();
1215 testReadWriteSync(); 1258 testReadWriteSync();
1216 testReadWriteStream(); 1259 testReadWriteStream();
(...skipping 13 matching lines...) Expand all
1230 testWriteVariousLists(); 1273 testWriteVariousLists();
1231 testDirectory(); 1274 testDirectory();
1232 testDirectorySync(); 1275 testDirectorySync();
1233 }); 1276 });
1234 } 1277 }
1235 } 1278 }
1236 1279
1237 main() { 1280 main() {
1238 FileTest.testMain(); 1281 FileTest.testMain();
1239 } 1282 }
OLDNEW
« no previous file with comments | « runtime/tests/vm/data/empty_file ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698