| 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 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 class MyListOfOneElement implements List { | 10 class MyListOfOneElement implements List { |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 openedFile.closeSync(); | 1211 openedFile.closeSync(); |
| 1212 openedFile = file.openSync(FileMode.WRITE); | 1212 openedFile = file.openSync(FileMode.WRITE); |
| 1213 openedFile.setPositionSync(4); | 1213 openedFile.setPositionSync(4); |
| 1214 openedFile.writeStringSync("asdf"); | 1214 openedFile.writeStringSync("asdf"); |
| 1215 Expect.equals(8, openedFile.lengthSync()); | 1215 Expect.equals(8, openedFile.lengthSync()); |
| 1216 openedFile.closeSync(); | 1216 openedFile.closeSync(); |
| 1217 file.deleteSync(); | 1217 file.deleteSync(); |
| 1218 Expect.isFalse(file.existsSync()); | 1218 Expect.isFalse(file.existsSync()); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 static void testWriteStringUtf8() { |
| 1222 var file = new File('${tempDirectory.path}/out_write_string'); |
| 1223 var string = new String.fromCharCodes([0x192]); |
| 1224 file.open(FileMode.WRITE).then((openedFile) { |
| 1225 openedFile.writeString(string).then((_) { |
| 1226 openedFile.length().then((l) { |
| 1227 Expect.equals(2, l); |
| 1228 openedFile.close().then((_) { |
| 1229 file.open(FileMode.APPEND).then((openedFile) { |
| 1230 openedFile.setPosition(2).then((_) { |
| 1231 openedFile.writeString(string).then((_) { |
| 1232 openedFile.length().then((l) { |
| 1233 Expect.equals(4, l); |
| 1234 openedFile.close().then((_) { |
| 1235 file.readAsText().then((readBack) { |
| 1236 Expect.stringEquals(readBack, '$string$string'); |
| 1237 file.delete().then((_) { |
| 1238 file.exists().then((e) { |
| 1239 Expect.isFalse(e); |
| 1240 asyncTestDone("testWriteStringUtf8"); |
| 1241 }); |
| 1242 }); |
| 1243 }); |
| 1244 }); |
| 1245 }); |
| 1246 }); |
| 1247 }); |
| 1248 }); |
| 1249 }); |
| 1250 }); |
| 1251 }); |
| 1252 }); |
| 1253 asyncTestStarted(); |
| 1254 } |
| 1255 |
| 1256 static void testWriteStringUtf8Sync() { |
| 1257 var file = new File('${tempDirectory.path}/out_write_string_sync'); |
| 1258 var string = new String.fromCharCodes([0x192]); |
| 1259 var openedFile = file.openSync(FileMode.WRITE); |
| 1260 openedFile.writeStringSync(string); |
| 1261 Expect.equals(2, openedFile.lengthSync()); |
| 1262 openedFile.closeSync(); |
| 1263 openedFile = file.openSync(FileMode.APPEND); |
| 1264 openedFile.setPositionSync(2); |
| 1265 openedFile.writeStringSync(string); |
| 1266 Expect.equals(4, openedFile.lengthSync()); |
| 1267 openedFile.closeSync(); |
| 1268 var readBack = file.readAsTextSync(); |
| 1269 Expect.stringEquals(readBack, '$string$string'); |
| 1270 file.deleteSync(); |
| 1271 Expect.isFalse(file.existsSync()); |
| 1272 } |
| 1273 |
| 1221 // Helper method to be able to run the test from the runtime | 1274 // Helper method to be able to run the test from the runtime |
| 1222 // directory, or the top directory. | 1275 // directory, or the top directory. |
| 1223 static String getFilename(String path) => | 1276 static String getFilename(String path) => |
| 1224 new File(path).existsSync() ? path : 'runtime/$path'; | 1277 new File(path).existsSync() ? path : 'runtime/$path'; |
| 1225 | 1278 |
| 1226 static String getDataFilename(String path) => | 1279 static String getDataFilename(String path) => |
| 1227 new File(path).existsSync() ? path : '../$path'; | 1280 new File(path).existsSync() ? path : '../$path'; |
| 1228 | 1281 |
| 1229 // Main test entrypoint. | 1282 // Main test entrypoint. |
| 1230 static testMain() { | 1283 static testMain() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 testCloseExceptionStream(); | 1319 testCloseExceptionStream(); |
| 1267 testBufferOutOfBoundsException(); | 1320 testBufferOutOfBoundsException(); |
| 1268 testAppend(); | 1321 testAppend(); |
| 1269 testAppendSync(); | 1322 testAppendSync(); |
| 1270 testWriteAppend(); | 1323 testWriteAppend(); |
| 1271 testOutputStreamWriteAppend(); | 1324 testOutputStreamWriteAppend(); |
| 1272 testOutputStreamWriteString(); | 1325 testOutputStreamWriteString(); |
| 1273 testWriteVariousLists(); | 1326 testWriteVariousLists(); |
| 1274 testDirectory(); | 1327 testDirectory(); |
| 1275 testDirectorySync(); | 1328 testDirectorySync(); |
| 1329 testWriteStringUtf8(); |
| 1330 testWriteStringUtf8Sync(); |
| 1276 }); | 1331 }); |
| 1277 } | 1332 } |
| 1278 } | 1333 } |
| 1279 | 1334 |
| 1280 main() { | 1335 main() { |
| 1281 FileTest.testMain(); | 1336 FileTest.testMain(); |
| 1282 } | 1337 } |
| OLD | NEW |