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 // OtherResources=empty_file | 7 // OtherResources=empty_file |
8 // OtherResources=file_test.txt | 8 // OtherResources=file_test.txt |
9 // OtherResources=fixed_length_file | 9 // OtherResources=fixed_length_file |
10 // OtherResources=read_as_text.dat | 10 // OtherResources=read_as_text.dat |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 getLength(); | 1261 getLength(); |
1262 Expect.throws(() => file.lengthSync()); | 1262 Expect.throws(() => file.lengthSync()); |
1263 } | 1263 } |
1264 | 1264 |
1265 static void testLastModifiedSync() { | 1265 static void testLastModifiedSync() { |
1266 var modified = new File(Platform.executable).lastModifiedSync(); | 1266 var modified = new File(Platform.executable).lastModifiedSync(); |
1267 Expect.isTrue(modified is DateTime); | 1267 Expect.isTrue(modified is DateTime); |
1268 Expect.isTrue(modified.isBefore(new DateTime.now())); | 1268 Expect.isTrue(modified.isBefore(new DateTime.now())); |
1269 } | 1269 } |
1270 | 1270 |
| 1271 static void testLastModifiedSyncDirectory() { |
| 1272 Directory tmp = tempDirectory.createTempSync('file_last_modified_test_'); |
| 1273 String dirPath = '${tmp.path}/dir'; |
| 1274 new Directory(dirPath).createSync(); |
| 1275 try { |
| 1276 new File(dirPath).lastModifiedSync(); |
| 1277 Expect.fail('Expected operation to throw'); |
| 1278 } catch (e) { |
| 1279 if (e is! FileSystemException) { |
| 1280 print(e); |
| 1281 } |
| 1282 Expect.isTrue(e is FileSystemException); |
| 1283 } finally { |
| 1284 tmp.deleteSync(recursive: true); |
| 1285 } |
| 1286 } |
| 1287 |
1271 // Test that opens the same file for writing then for appending to test | 1288 // Test that opens the same file for writing then for appending to test |
1272 // that the file is not truncated when opened for appending. | 1289 // that the file is not truncated when opened for appending. |
1273 static void testAppend() { | 1290 static void testAppend() { |
1274 asyncTestStarted(); | 1291 asyncTestStarted(); |
1275 var file = new File('${tempDirectory.path}/out_append'); | 1292 var file = new File('${tempDirectory.path}/out_append'); |
1276 file.open(mode: WRITE).then((openedFile) { | 1293 file.open(mode: WRITE).then((openedFile) { |
1277 openedFile.writeString("asdf").then((ignore) { | 1294 openedFile.writeString("asdf").then((ignore) { |
1278 openedFile.close().then((ignore) { | 1295 openedFile.close().then((ignore) { |
1279 file.open(mode: APPEND).then((openedFile) { | 1296 file.open(mode: APPEND).then((openedFile) { |
1280 openedFile.length().then((length) { | 1297 openedFile.length().then((length) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 testWriteVariousLists(); | 1494 testWriteVariousLists(); |
1478 testDirectory(); | 1495 testDirectory(); |
1479 testDirectorySync(); | 1496 testDirectorySync(); |
1480 testWriteStringUtf8(); | 1497 testWriteStringUtf8(); |
1481 testWriteStringUtf8Sync(); | 1498 testWriteStringUtf8Sync(); |
1482 testRename(targetExists: false); | 1499 testRename(targetExists: false); |
1483 testRenameSync(targetExists: false); | 1500 testRenameSync(targetExists: false); |
1484 testRename(targetExists: true); | 1501 testRename(targetExists: true); |
1485 testRenameSync(targetExists: true); | 1502 testRenameSync(targetExists: true); |
1486 testLastModified(); | 1503 testLastModified(); |
| 1504 testLastModifiedSyncDirectory(); |
1487 testDoubleAsyncOperation(); | 1505 testDoubleAsyncOperation(); |
1488 asyncEnd(); | 1506 asyncEnd(); |
1489 }); | 1507 }); |
1490 } | 1508 } |
1491 } | 1509 } |
1492 | 1510 |
1493 main() { | 1511 main() { |
1494 FileTest.testMain(); | 1512 FileTest.testMain(); |
1495 } | 1513 } |
OLD | NEW |