Chromium Code Reviews| 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 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1211 openedFile.setPositionSync(2); | 1211 openedFile.setPositionSync(2); |
| 1212 openedFile.writeStringSync(string); | 1212 openedFile.writeStringSync(string); |
| 1213 Expect.equals(4, openedFile.lengthSync()); | 1213 Expect.equals(4, openedFile.lengthSync()); |
| 1214 openedFile.closeSync(); | 1214 openedFile.closeSync(); |
| 1215 var readBack = file.readAsStringSync(); | 1215 var readBack = file.readAsStringSync(); |
| 1216 Expect.stringEquals(readBack, '$string$string'); | 1216 Expect.stringEquals(readBack, '$string$string'); |
| 1217 file.deleteSync(); | 1217 file.deleteSync(); |
| 1218 Expect.isFalse(file.existsSync()); | 1218 Expect.isFalse(file.existsSync()); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 // Test that opens the same file for writing then for appending to test | |
|
Anders Johnsen
2013/06/14 07:54:35
Add test for rename of broken link. (Should fail,
Søren Gjesse
2013/06/14 11:00:10
Done.
| |
| 1222 // that the file is not truncated when opened for appending. | |
| 1223 static void testRename() { | |
| 1224 var file = new File('${tempDirectory.path}/rename_name'); | |
| 1225 file.create().then((file) { | |
| 1226 file.rename("${tempDirectory.path}/rename_newname").then((newfile) { | |
| 1227 file.exists().then((e) { | |
| 1228 Expect.isFalse(e); | |
| 1229 newfile.exists().then((e) { | |
| 1230 Expect.isTrue(e); | |
| 1231 newfile.delete().then((_) { | |
| 1232 file.exists().then((e) { | |
| 1233 Expect.isFalse(e); | |
| 1234 asyncTestDone("testRename"); | |
| 1235 }); | |
| 1236 }); | |
| 1237 }); | |
| 1238 }); | |
| 1239 }); | |
| 1240 }); | |
| 1241 asyncTestStarted(); | |
| 1242 } | |
| 1243 | |
| 1244 static void testRenameSync() { | |
| 1245 var file = new File('${tempDirectory.path}/rename_name_sync'); | |
| 1246 file.createSync(); | |
| 1247 var newfile = file.renameSync('${tempDirectory.path}/rename_newname_sync'); | |
| 1248 Expect.isFalse(file.existsSync()); | |
| 1249 Expect.isTrue(newfile.existsSync()); | |
| 1250 newfile.deleteSync(); | |
| 1251 Expect.isFalse(newfile.existsSync()); | |
| 1252 } | |
| 1253 | |
| 1221 // Helper method to be able to run the test from the runtime | 1254 // Helper method to be able to run the test from the runtime |
| 1222 // directory, or the top directory. | 1255 // directory, or the top directory. |
| 1223 static String getFilename(String path) => | 1256 static String getFilename(String path) => |
| 1224 new File(path).existsSync() ? path : 'runtime/$path'; | 1257 new File(path).existsSync() ? path : 'runtime/$path'; |
| 1225 | 1258 |
| 1226 static String getDataFilename(String path) => | 1259 static String getDataFilename(String path) => |
| 1227 new File(path).existsSync() ? path : '../$path'; | 1260 new File(path).existsSync() ? path : '../$path'; |
| 1228 | 1261 |
| 1229 // Main test entrypoint. | 1262 // Main test entrypoint. |
| 1230 static testMain() { | 1263 static testMain() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 testAppend(); | 1302 testAppend(); |
| 1270 testAppendSync(); | 1303 testAppendSync(); |
| 1271 testWriteAppend(); | 1304 testWriteAppend(); |
| 1272 testOutputStreamWriteAppend(); | 1305 testOutputStreamWriteAppend(); |
| 1273 testOutputStreamWriteString(); | 1306 testOutputStreamWriteString(); |
| 1274 testWriteVariousLists(); | 1307 testWriteVariousLists(); |
| 1275 testDirectory(); | 1308 testDirectory(); |
| 1276 testDirectorySync(); | 1309 testDirectorySync(); |
| 1277 testWriteStringUtf8(); | 1310 testWriteStringUtf8(); |
| 1278 testWriteStringUtf8Sync(); | 1311 testWriteStringUtf8Sync(); |
| 1312 testRename(); | |
| 1313 testRenameSync(); | |
| 1279 }); | 1314 }); |
| 1280 } | 1315 } |
| 1281 } | 1316 } |
| 1282 | 1317 |
| 1283 main() { | 1318 main() { |
| 1284 FileTest.testMain(); | 1319 FileTest.testMain(); |
| 1285 } | 1320 } |
| OLD | NEW |