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 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 | 1075 |
1076 static void testLastModified() { | 1076 static void testLastModified() { |
1077 asyncTestStarted(); | 1077 asyncTestStarted(); |
1078 new File(Platform.executable).lastModified().then((modified) { | 1078 new File(Platform.executable).lastModified().then((modified) { |
1079 Expect.isTrue(modified is DateTime); | 1079 Expect.isTrue(modified is DateTime); |
1080 Expect.isTrue(modified.isBefore(new DateTime.now())); | 1080 Expect.isTrue(modified.isBefore(new DateTime.now())); |
1081 asyncTestDone("testLastModified"); | 1081 asyncTestDone("testLastModified"); |
1082 }); | 1082 }); |
1083 } | 1083 } |
1084 | 1084 |
| 1085 static void testDoubleAsyncOperation() { |
| 1086 asyncTestStarted(); |
| 1087 var file = new File(Platform.executable).openSync(); |
| 1088 var completer = new Completer(); |
| 1089 int done = 0; |
| 1090 bool error = false; |
| 1091 void getLength() { |
| 1092 file.length() |
| 1093 .catchError((e) { error = true; }) |
| 1094 .whenComplete(() { |
| 1095 if (++done == 2) { |
| 1096 asyncTestDone("testDoubleAsyncOperation"); |
| 1097 Expect.isTrue(error); |
| 1098 file.lengthSync(); |
| 1099 file.closeSync(); |
| 1100 } |
| 1101 }); |
| 1102 } |
| 1103 getLength(); |
| 1104 getLength(); |
| 1105 Expect.throws(() => file.lengthSync()); |
| 1106 } |
| 1107 |
1085 static void testLastModifiedSync() { | 1108 static void testLastModifiedSync() { |
1086 var modified = new File(Platform.executable).lastModifiedSync(); | 1109 var modified = new File(Platform.executable).lastModifiedSync(); |
1087 Expect.isTrue(modified is DateTime); | 1110 Expect.isTrue(modified is DateTime); |
1088 Expect.isTrue(modified.isBefore(new DateTime.now())); | 1111 Expect.isTrue(modified.isBefore(new DateTime.now())); |
1089 } | 1112 } |
1090 | 1113 |
1091 // Test that opens the same file for writing then for appending to test | 1114 // Test that opens the same file for writing then for appending to test |
1092 // that the file is not truncated when opened for appending. | 1115 // that the file is not truncated when opened for appending. |
1093 static void testAppend() { | 1116 static void testAppend() { |
1094 asyncTestStarted(); | 1117 asyncTestStarted(); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 testOutputStreamWriteAppend(); | 1316 testOutputStreamWriteAppend(); |
1294 testOutputStreamWriteString(); | 1317 testOutputStreamWriteString(); |
1295 testWriteVariousLists(); | 1318 testWriteVariousLists(); |
1296 testDirectory(); | 1319 testDirectory(); |
1297 testDirectorySync(); | 1320 testDirectorySync(); |
1298 testWriteStringUtf8(); | 1321 testWriteStringUtf8(); |
1299 testWriteStringUtf8Sync(); | 1322 testWriteStringUtf8Sync(); |
1300 testRename(); | 1323 testRename(); |
1301 testRenameSync(); | 1324 testRenameSync(); |
1302 testLastModified(); | 1325 testLastModified(); |
| 1326 testDoubleAsyncOperation(); |
1303 asyncEnd(); | 1327 asyncEnd(); |
1304 }); | 1328 }); |
1305 } | 1329 } |
1306 } | 1330 } |
1307 | 1331 |
1308 main() { | 1332 main() { |
1309 FileTest.testMain(); | 1333 FileTest.testMain(); |
1310 } | 1334 } |
OLD | NEW |