| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 Expect.equals(1, file.openSync().readSync(1).length); | 272 Expect.equals(1, file.openSync().readSync(1).length); |
| 273 Expect.equals(len - 1, file.openSync().readSync(len - 1).length); | 273 Expect.equals(len - 1, file.openSync().readSync(len - 1).length); |
| 274 Expect.equals(len, file.openSync().readSync(len).length); | 274 Expect.equals(len, file.openSync().readSync(len).length); |
| 275 Expect.equals(len, file.openSync().readSync(len + 1).length); | 275 Expect.equals(len, file.openSync().readSync(len + 1).length); |
| 276 Expect.equals(len, file.openSync().readSync(len * 2).length); | 276 Expect.equals(len, file.openSync().readSync(len * 2).length); |
| 277 Expect.equals(len, file.openSync().readSync(len * 10).length); | 277 Expect.equals(len, file.openSync().readSync(len * 10).length); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Test for file read and write functionality. | 280 // Test for file read and write functionality. |
| 281 static void testReadWrite() { | 281 static void testReadWrite() { |
| 282 asyncTestStarted(); |
| 282 // Read a file. | 283 // Read a file. |
| 283 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 284 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
| 284 final File file = new File(inFilename); | 285 final File file = new File(inFilename); |
| 285 file.open(mode: READ).then((openedFile) { | 286 file.open(mode: READ).then((openedFile) { |
| 286 List<int> buffer1 = new List<int>(42); | 287 List<int> buffer1 = new List<int>(42); |
| 287 openedFile.readInto(buffer1, 0, 42).then((bytes_read) { | 288 openedFile.readInto(buffer1, 0, 42).then((bytes_read) { |
| 288 Expect.equals(42, bytes_read); | 289 Expect.equals(42, bytes_read); |
| 289 openedFile.close().then((ignore) { | 290 openedFile.close().then((ignore) { |
| 290 // Write the contents of the file just read into another file. | 291 // Write the contents of the file just read into another file. |
| 291 String outFilename = tempDirectory.path + "/out_read_write"; | 292 String outFilename = tempDirectory.path + "/out_read_write"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 }); | 324 }); |
| 324 }); | 325 }); |
| 325 }); | 326 }); |
| 326 }); | 327 }); |
| 327 }); | 328 }); |
| 328 }); | 329 }); |
| 329 }); | 330 }); |
| 330 }); | 331 }); |
| 331 }); | 332 }); |
| 332 }); | 333 }); |
| 333 asyncTestStarted(); | |
| 334 } | 334 } |
| 335 | 335 |
| 336 static void testWriteAppend() { | 336 static void testWriteAppend() { |
| 337 String content = "foobar"; | 337 String content = "foobar"; |
| 338 String filename = tempDirectory.path + "/write_append"; | 338 String filename = tempDirectory.path + "/write_append"; |
| 339 File file = new File(filename); | 339 File file = new File(filename); |
| 340 file.createSync(); | 340 file.createSync(); |
| 341 Expect.isTrue(new File(filename).existsSync()); | 341 Expect.isTrue(new File(filename).existsSync()); |
| 342 List<int> buffer = content.codeUnits; | 342 List<int> buffer = content.codeUnits; |
| 343 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 343 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
| 344 openedFile.writeFromSync(buffer, 0, buffer.length); | 344 openedFile.writeFromSync(buffer, 0, buffer.length); |
| 345 openedFile.closeSync(); | 345 openedFile.closeSync(); |
| 346 // Reopen the file in write mode to ensure that we overwrite the content. | 346 // Reopen the file in write mode to ensure that we overwrite the content. |
| 347 openedFile = (new File(filename)).openSync(mode: WRITE); | 347 openedFile = (new File(filename)).openSync(mode: WRITE); |
| 348 openedFile.writeFromSync(buffer, 0, buffer.length); | 348 openedFile.writeFromSync(buffer, 0, buffer.length); |
| 349 Expect.equals(content.length, openedFile.lengthSync()); | 349 Expect.equals(content.length, openedFile.lengthSync()); |
| 350 openedFile.closeSync(); | 350 openedFile.closeSync(); |
| 351 // Open the file in append mode and ensure that we do not overwrite | 351 // Open the file in append mode and ensure that we do not overwrite |
| 352 // the existing content. | 352 // the existing content. |
| 353 openedFile = (new File(filename)).openSync(mode: APPEND); | 353 openedFile = (new File(filename)).openSync(mode: APPEND); |
| 354 openedFile.writeFromSync(buffer, 0, buffer.length); | 354 openedFile.writeFromSync(buffer, 0, buffer.length); |
| 355 Expect.equals(content.length * 2, openedFile.lengthSync()); | 355 Expect.equals(content.length * 2, openedFile.lengthSync()); |
| 356 openedFile.closeSync(); | 356 openedFile.closeSync(); |
| 357 file.deleteSync(); | 357 file.deleteSync(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 static void testOutputStreamWriteAppend() { | 360 static void testOutputStreamWriteAppend() { |
| 361 asyncTestStarted(); |
| 361 String content = "foobar"; | 362 String content = "foobar"; |
| 362 String filename = tempDirectory.path + "/outstream_write_append"; | 363 String filename = tempDirectory.path + "/outstream_write_append"; |
| 363 File file = new File(filename); | 364 File file = new File(filename); |
| 364 file.createSync(); | 365 file.createSync(); |
| 365 List<int> buffer = content.codeUnits; | 366 List<int> buffer = content.codeUnits; |
| 366 var output = file.openWrite(); | 367 var output = file.openWrite(); |
| 367 output.add(buffer); | 368 output.add(buffer); |
| 368 output.close(); | 369 output.close(); |
| 369 output.done.then((_) { | 370 output.done.then((_) { |
| 370 File file2 = new File(filename); | 371 File file2 = new File(filename); |
| 371 var appendingOutput = file2.openWrite(mode: APPEND); | 372 var appendingOutput = file2.openWrite(mode: APPEND); |
| 372 appendingOutput.add(buffer); | 373 appendingOutput.add(buffer); |
| 373 appendingOutput.close(); | 374 appendingOutput.close(); |
| 374 appendingOutput.done.then((_) { | 375 appendingOutput.done.then((_) { |
| 375 File file3 = new File(filename); | 376 File file3 = new File(filename); |
| 376 file3.open(mode: READ).then((RandomAccessFile openedFile) { | 377 file3.open(mode: READ).then((RandomAccessFile openedFile) { |
| 377 openedFile.length().then((int length) { | 378 openedFile.length().then((int length) { |
| 378 Expect.equals(content.length * 2, length); | 379 Expect.equals(content.length * 2, length); |
| 379 openedFile.close().then((ignore) { | 380 openedFile.close().then((ignore) { |
| 380 file3.delete().then((ignore) { | 381 file3.delete().then((ignore) { |
| 381 asyncTestDone("testOutputStreamWriteAppend"); | 382 asyncTestDone("testOutputStreamWriteAppend"); |
| 382 }); | 383 }); |
| 383 }); | 384 }); |
| 384 }); | 385 }); |
| 385 }); | 386 }); |
| 386 }); | 387 }); |
| 387 }); | 388 }); |
| 388 asyncTestStarted(); | |
| 389 } | 389 } |
| 390 | 390 |
| 391 // Test for file read and write functionality. | 391 // Test for file read and write functionality. |
| 392 static void testOutputStreamWriteString() { | 392 static void testOutputStreamWriteString() { |
| 393 asyncTestStarted(); |
| 393 String content = "foobar"; | 394 String content = "foobar"; |
| 394 String filename = tempDirectory.path + "/outstream_write_string"; | 395 String filename = tempDirectory.path + "/outstream_write_string"; |
| 395 File file = new File(filename); | 396 File file = new File(filename); |
| 396 file.createSync(); | 397 file.createSync(); |
| 397 List<int> buffer = content.codeUnits; | 398 List<int> buffer = content.codeUnits; |
| 398 var output = file.openWrite(); | 399 var output = file.openWrite(); |
| 399 output.write("abcdABCD"); | 400 output.write("abcdABCD"); |
| 400 output.encoding = UTF8; | 401 output.encoding = UTF8; |
| 401 output.write("abcdABCD"); | 402 output.write("abcdABCD"); |
| 402 output.encoding = LATIN1; | 403 output.encoding = LATIN1; |
| 403 output.write("abcdABCD"); | 404 output.write("abcdABCD"); |
| 404 output.encoding = ASCII; | 405 output.encoding = ASCII; |
| 405 output.write("abcdABCD"); | 406 output.write("abcdABCD"); |
| 406 output.encoding = UTF8; | 407 output.encoding = UTF8; |
| 407 output.write("æøå"); | 408 output.write("æøå"); |
| 408 output.close(); | 409 output.close(); |
| 409 output.done.then((_) { | 410 output.done.then((_) { |
| 410 RandomAccessFile raf = file.openSync(); | 411 RandomAccessFile raf = file.openSync(); |
| 411 Expect.equals(38, raf.lengthSync()); | 412 Expect.equals(38, raf.lengthSync()); |
| 412 raf.close().then((ignore) { | 413 raf.close().then((ignore) { |
| 413 asyncTestDone("testOutputStreamWriteString"); | 414 asyncTestDone("testOutputStreamWriteString"); |
| 414 }); | 415 }); |
| 415 }); | 416 }); |
| 416 asyncTestStarted(); | |
| 417 } | 417 } |
| 418 | 418 |
| 419 | 419 |
| 420 static void testReadWriteSync() { | 420 static void testReadWriteSync() { |
| 421 // Read a file. | 421 // Read a file. |
| 422 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 422 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
| 423 RandomAccessFile file = (new File(inFilename)).openSync(); | 423 RandomAccessFile file = (new File(inFilename)).openSync(); |
| 424 List<int> buffer1 = new List<int>(42); | 424 List<int> buffer1 = new List<int>(42); |
| 425 int bytes_read = 0; | 425 int bytes_read = 0; |
| 426 int bytes_written = 0; | 426 int bytes_written = 0; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 input.readIntoSync(buffer, 0, 12); | 653 input.readIntoSync(buffer, 0, 12); |
| 654 Expect.equals(12, input.positionSync()); | 654 Expect.equals(12, input.positionSync()); |
| 655 input.readIntoSync(buffer, 12, 18); | 655 input.readIntoSync(buffer, 12, 18); |
| 656 Expect.equals(18, input.positionSync()); | 656 Expect.equals(18, input.positionSync()); |
| 657 input.setPositionSync(8); | 657 input.setPositionSync(8); |
| 658 Expect.equals(8, input.positionSync()); | 658 Expect.equals(8, input.positionSync()); |
| 659 input.closeSync(); | 659 input.closeSync(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 static void testTruncate() { | 662 static void testTruncate() { |
| 663 asyncTestStarted(); |
| 663 File file = new File(tempDirectory.path + "/out_truncate"); | 664 File file = new File(tempDirectory.path + "/out_truncate"); |
| 664 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 665 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 665 file.open(mode: WRITE).then((RandomAccessFile openedFile) { | 666 file.open(mode: WRITE).then((RandomAccessFile openedFile) { |
| 666 openedFile.writeFrom(buffer, 0, 10).then((ignore) { | 667 openedFile.writeFrom(buffer, 0, 10).then((ignore) { |
| 667 openedFile.length().then((length) { | 668 openedFile.length().then((length) { |
| 668 Expect.equals(10, length); | 669 Expect.equals(10, length); |
| 669 openedFile.truncate(5).then((ignore) { | 670 openedFile.truncate(5).then((ignore) { |
| 670 openedFile.length().then((length) { | 671 openedFile.length().then((length) { |
| 671 Expect.equals(5, length); | 672 Expect.equals(5, length); |
| 672 openedFile.close().then((ignore) { | 673 openedFile.close().then((ignore) { |
| 673 file.delete().then((ignore) { | 674 file.delete().then((ignore) { |
| 674 file.exists().then((exists) { | 675 file.exists().then((exists) { |
| 675 Expect.isFalse(exists); | 676 Expect.isFalse(exists); |
| 676 asyncTestDone("testTruncate"); | 677 asyncTestDone("testTruncate"); |
| 677 }); | 678 }); |
| 678 }); | 679 }); |
| 679 }); | 680 }); |
| 680 }); | 681 }); |
| 681 }); | 682 }); |
| 682 }); | 683 }); |
| 683 }); | 684 }); |
| 684 }); | 685 }); |
| 685 asyncTestStarted(); | |
| 686 } | 686 } |
| 687 | 687 |
| 688 static void testTruncateSync() { | 688 static void testTruncateSync() { |
| 689 File file = new File(tempDirectory.path + "/out_truncate_sync"); | 689 File file = new File(tempDirectory.path + "/out_truncate_sync"); |
| 690 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 690 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 691 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 691 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
| 692 openedFile.writeFromSync(buffer, 0, 10); | 692 openedFile.writeFromSync(buffer, 0, 10); |
| 693 Expect.equals(10, openedFile.lengthSync()); | 693 Expect.equals(10, openedFile.lengthSync()); |
| 694 openedFile.truncateSync(5); | 694 openedFile.truncateSync(5); |
| 695 Expect.equals(5, openedFile.lengthSync()); | 695 Expect.equals(5, openedFile.lengthSync()); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 | 1094 |
| 1095 static void testLastModifiedSync() { | 1095 static void testLastModifiedSync() { |
| 1096 var modified = new File(Platform.executable).lastModifiedSync(); | 1096 var modified = new File(Platform.executable).lastModifiedSync(); |
| 1097 Expect.isTrue(modified is DateTime); | 1097 Expect.isTrue(modified is DateTime); |
| 1098 Expect.isTrue(modified.isBefore(new DateTime.now())); | 1098 Expect.isTrue(modified.isBefore(new DateTime.now())); |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 // Test that opens the same file for writing then for appending to test | 1101 // Test that opens the same file for writing then for appending to test |
| 1102 // that the file is not truncated when opened for appending. | 1102 // that the file is not truncated when opened for appending. |
| 1103 static void testAppend() { | 1103 static void testAppend() { |
| 1104 asyncTestStarted(); |
| 1104 var file = new File('${tempDirectory.path}/out_append'); | 1105 var file = new File('${tempDirectory.path}/out_append'); |
| 1105 file.open(mode: WRITE).then((openedFile) { | 1106 file.open(mode: WRITE).then((openedFile) { |
| 1106 openedFile.writeString("asdf").then((ignore) { | 1107 openedFile.writeString("asdf").then((ignore) { |
| 1107 openedFile.close().then((ignore) { | 1108 openedFile.close().then((ignore) { |
| 1108 file.open(mode: APPEND).then((openedFile) { | 1109 file.open(mode: APPEND).then((openedFile) { |
| 1109 openedFile.length().then((length) { | 1110 openedFile.length().then((length) { |
| 1110 Expect.equals(4, length); | 1111 Expect.equals(4, length); |
| 1111 openedFile.writeString("asdf").then((ignore) { | 1112 openedFile.writeString("asdf").then((ignore) { |
| 1112 openedFile.length().then((length) { | 1113 openedFile.length().then((length) { |
| 1113 Expect.equals(8, length); | 1114 Expect.equals(8, length); |
| 1114 openedFile.close().then((ignore) { | 1115 openedFile.close().then((ignore) { |
| 1115 file.delete().then((ignore) { | 1116 file.delete().then((ignore) { |
| 1116 file.exists().then((exists) { | 1117 file.exists().then((exists) { |
| 1117 Expect.isFalse(exists); | 1118 Expect.isFalse(exists); |
| 1118 asyncTestDone("testAppend"); | 1119 asyncTestDone("testAppend"); |
| 1119 }); | 1120 }); |
| 1120 }); | 1121 }); |
| 1121 }); | 1122 }); |
| 1122 }); | 1123 }); |
| 1123 }); | 1124 }); |
| 1124 }); | 1125 }); |
| 1125 }); | 1126 }); |
| 1126 }); | 1127 }); |
| 1127 }); | 1128 }); |
| 1128 }); | 1129 }); |
| 1129 asyncTestStarted(); | |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 static void testAppendSync() { | 1132 static void testAppendSync() { |
| 1133 var file = new File('${tempDirectory.path}/out_append_sync'); | 1133 var file = new File('${tempDirectory.path}/out_append_sync'); |
| 1134 var openedFile = file.openSync(mode: WRITE); | 1134 var openedFile = file.openSync(mode: WRITE); |
| 1135 openedFile.writeStringSync("asdf"); | 1135 openedFile.writeStringSync("asdf"); |
| 1136 Expect.equals(4, openedFile.lengthSync()); | 1136 Expect.equals(4, openedFile.lengthSync()); |
| 1137 openedFile.closeSync(); | 1137 openedFile.closeSync(); |
| 1138 openedFile = file.openSync(mode: WRITE); | 1138 openedFile = file.openSync(mode: WRITE); |
| 1139 openedFile.setPositionSync(4); | 1139 openedFile.setPositionSync(4); |
| 1140 openedFile.writeStringSync("asdf"); | 1140 openedFile.writeStringSync("asdf"); |
| 1141 Expect.equals(8, openedFile.lengthSync()); | 1141 Expect.equals(8, openedFile.lengthSync()); |
| 1142 openedFile.closeSync(); | 1142 openedFile.closeSync(); |
| 1143 file.deleteSync(); | 1143 file.deleteSync(); |
| 1144 Expect.isFalse(file.existsSync()); | 1144 Expect.isFalse(file.existsSync()); |
| 1145 } | 1145 } |
| 1146 | 1146 |
| 1147 static void testWriteStringUtf8() { | 1147 static void testWriteStringUtf8() { |
| 1148 asyncTestStarted(); |
| 1148 var file = new File('${tempDirectory.path}/out_write_string'); | 1149 var file = new File('${tempDirectory.path}/out_write_string'); |
| 1149 var string = new String.fromCharCodes([0x192]); | 1150 var string = new String.fromCharCodes([0x192]); |
| 1150 file.open(mode: WRITE).then((openedFile) { | 1151 file.open(mode: WRITE).then((openedFile) { |
| 1151 openedFile.writeString(string).then((_) { | 1152 openedFile.writeString(string).then((_) { |
| 1152 openedFile.length().then((l) { | 1153 openedFile.length().then((l) { |
| 1153 Expect.equals(2, l); | 1154 Expect.equals(2, l); |
| 1154 openedFile.close().then((_) { | 1155 openedFile.close().then((_) { |
| 1155 file.open(mode: APPEND).then((openedFile) { | 1156 file.open(mode: APPEND).then((openedFile) { |
| 1156 openedFile.setPosition(2).then((_) { | 1157 openedFile.setPosition(2).then((_) { |
| 1157 openedFile.writeString(string).then((_) { | 1158 openedFile.writeString(string).then((_) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1169 }); | 1170 }); |
| 1170 }); | 1171 }); |
| 1171 }); | 1172 }); |
| 1172 }); | 1173 }); |
| 1173 }); | 1174 }); |
| 1174 }); | 1175 }); |
| 1175 }); | 1176 }); |
| 1176 }); | 1177 }); |
| 1177 }); | 1178 }); |
| 1178 }); | 1179 }); |
| 1179 asyncTestStarted(); | |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 static void testWriteStringUtf8Sync() { | 1182 static void testWriteStringUtf8Sync() { |
| 1183 var file = new File('${tempDirectory.path}/out_write_string_sync'); | 1183 var file = new File('${tempDirectory.path}/out_write_string_sync'); |
| 1184 var string = new String.fromCharCodes([0x192]); | 1184 var string = new String.fromCharCodes([0x192]); |
| 1185 var openedFile = file.openSync(mode: WRITE); | 1185 var openedFile = file.openSync(mode: WRITE); |
| 1186 openedFile.writeStringSync(string); | 1186 openedFile.writeStringSync(string); |
| 1187 Expect.equals(2, openedFile.lengthSync()); | 1187 Expect.equals(2, openedFile.lengthSync()); |
| 1188 openedFile.closeSync(); | 1188 openedFile.closeSync(); |
| 1189 openedFile = file.openSync(mode: APPEND); | 1189 openedFile = file.openSync(mode: APPEND); |
| 1190 openedFile.setPositionSync(2); | 1190 openedFile.setPositionSync(2); |
| 1191 openedFile.writeStringSync(string); | 1191 openedFile.writeStringSync(string); |
| 1192 Expect.equals(4, openedFile.lengthSync()); | 1192 Expect.equals(4, openedFile.lengthSync()); |
| 1193 openedFile.closeSync(); | 1193 openedFile.closeSync(); |
| 1194 var readBack = file.readAsStringSync(); | 1194 var readBack = file.readAsStringSync(); |
| 1195 Expect.stringEquals(readBack, '$string$string'); | 1195 Expect.stringEquals(readBack, '$string$string'); |
| 1196 file.deleteSync(); | 1196 file.deleteSync(); |
| 1197 Expect.isFalse(file.existsSync()); | 1197 Expect.isFalse(file.existsSync()); |
| 1198 } | 1198 } |
| 1199 | 1199 |
| 1200 // Test that opens the same file for writing then for appending to test | 1200 // Test that opens the same file for writing then for appending to test |
| 1201 // that the file is not truncated when opened for appending. | 1201 // that the file is not truncated when opened for appending. |
| 1202 static void testRename() { | 1202 static void testRename() { |
| 1203 asyncTestStarted(); |
| 1203 var file = new File('${tempDirectory.path}/rename_name'); | 1204 var file = new File('${tempDirectory.path}/rename_name'); |
| 1204 file.create().then((file) { | 1205 file.create().then((file) { |
| 1205 file.rename("${tempDirectory.path}/rename_newname").then((newfile) { | 1206 file.rename("${tempDirectory.path}/rename_newname").then((newfile) { |
| 1206 file.exists().then((e) { | 1207 file.exists().then((e) { |
| 1207 Expect.isFalse(e); | 1208 Expect.isFalse(e); |
| 1208 newfile.exists().then((e) { | 1209 newfile.exists().then((e) { |
| 1209 Expect.isTrue(e); | 1210 Expect.isTrue(e); |
| 1210 newfile.delete().then((_) { | 1211 newfile.delete().then((_) { |
| 1211 file.exists().then((e) { | 1212 file.exists().then((e) { |
| 1212 Expect.isFalse(e); | 1213 Expect.isFalse(e); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1225 | 1226 |
| 1226 } else { | 1227 } else { |
| 1227 asyncTestDone("testRename"); | 1228 asyncTestDone("testRename"); |
| 1228 } | 1229 } |
| 1229 }); | 1230 }); |
| 1230 }); | 1231 }); |
| 1231 }); | 1232 }); |
| 1232 }); | 1233 }); |
| 1233 }); | 1234 }); |
| 1234 }); | 1235 }); |
| 1235 asyncTestStarted(); | |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 static void testRenameSync() { | 1238 static void testRenameSync() { |
| 1239 var file = new File('${tempDirectory.path}/rename_name_sync'); | 1239 var file = new File('${tempDirectory.path}/rename_name_sync'); |
| 1240 file.createSync(); | 1240 file.createSync(); |
| 1241 var newfile = file.renameSync('${tempDirectory.path}/rename_newname_sync'); | 1241 var newfile = file.renameSync('${tempDirectory.path}/rename_newname_sync'); |
| 1242 Expect.isFalse(file.existsSync()); | 1242 Expect.isFalse(file.existsSync()); |
| 1243 Expect.isTrue(newfile.existsSync()); | 1243 Expect.isTrue(newfile.existsSync()); |
| 1244 newfile.deleteSync(); | 1244 newfile.deleteSync(); |
| 1245 Expect.isFalse(newfile.existsSync()); | 1245 Expect.isFalse(newfile.existsSync()); |
| 1246 if (Platform.operatingSystem != "windows") { | 1246 if (Platform.operatingSystem != "windows") { |
| 1247 var brokenLink = new Link('${tempDirectory.path}/rename_name_sync'); | 1247 var brokenLink = new Link('${tempDirectory.path}/rename_name_sync'); |
| 1248 brokenLink.createSync('${tempDirectory.path}/rename_newname_sync'); | 1248 brokenLink.createSync('${tempDirectory.path}/rename_newname_sync'); |
| 1249 Expect.throws(() => file.renameSync('xxx')); | 1249 Expect.throws(() => file.renameSync('xxx')); |
| 1250 } | 1250 } |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 // Helper method to be able to run the test from the runtime | 1253 // Helper method to be able to run the test from the runtime |
| 1254 // directory, or the top directory. | 1254 // directory, or the top directory. |
| 1255 static String getFilename(String path) => | 1255 static String getFilename(String path) => |
| 1256 new File(path).existsSync() ? path : 'runtime/$path'; | 1256 new File(path).existsSync() ? path : 'runtime/$path'; |
| 1257 | 1257 |
| 1258 static String getDataFilename(String path) => | 1258 static String getDataFilename(String path) => |
| 1259 new File(path).existsSync() ? path : '../$path'; | 1259 new File(path).existsSync() ? path : '../$path'; |
| 1260 | 1260 |
| 1261 // Main test entrypoint. | 1261 // Main test entrypoint. |
| 1262 static testMain() { | 1262 static testMain() { |
| 1263 asyncStart(); |
| 1264 |
| 1263 testRead(); | 1265 testRead(); |
| 1264 testReadSync(); | 1266 testReadSync(); |
| 1265 testReadStream(); | 1267 testReadStream(); |
| 1266 testLengthSync(); | 1268 testLengthSync(); |
| 1267 testPositionSync(); | 1269 testPositionSync(); |
| 1268 testOpenDirectoryAsFile(); | 1270 testOpenDirectoryAsFile(); |
| 1269 testOpenDirectoryAsFileSync(); | 1271 testOpenDirectoryAsFileSync(); |
| 1270 testOpenFile(); | 1272 testOpenFile(); |
| 1271 testReadAsBytesSync(); | 1273 testReadAsBytesSync(); |
| 1272 testReadAsBytesSyncEmptyFile(); | 1274 testReadAsBytesSyncEmptyFile(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1302 testOutputStreamWriteAppend(); | 1304 testOutputStreamWriteAppend(); |
| 1303 testOutputStreamWriteString(); | 1305 testOutputStreamWriteString(); |
| 1304 testWriteVariousLists(); | 1306 testWriteVariousLists(); |
| 1305 testDirectory(); | 1307 testDirectory(); |
| 1306 testDirectorySync(); | 1308 testDirectorySync(); |
| 1307 testWriteStringUtf8(); | 1309 testWriteStringUtf8(); |
| 1308 testWriteStringUtf8Sync(); | 1310 testWriteStringUtf8Sync(); |
| 1309 testRename(); | 1311 testRename(); |
| 1310 testRenameSync(); | 1312 testRenameSync(); |
| 1311 testLastModified(); | 1313 testLastModified(); |
| 1314 asyncEnd(); |
| 1312 }); | 1315 }); |
| 1313 } | 1316 } |
| 1314 } | 1317 } |
| 1315 | 1318 |
| 1316 main() { | 1319 main() { |
| 1317 FileTest.testMain(); | 1320 FileTest.testMain(); |
| 1318 } | 1321 } |
| OLD | NEW |