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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 709 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
710 openedFile.writeFromSync(buffer, 0, 10); | 710 openedFile.writeFromSync(buffer, 0, 10); |
711 Expect.equals(10, openedFile.lengthSync()); | 711 Expect.equals(10, openedFile.lengthSync()); |
712 openedFile.truncateSync(5); | 712 openedFile.truncateSync(5); |
713 Expect.equals(5, openedFile.lengthSync()); | 713 Expect.equals(5, openedFile.lengthSync()); |
714 openedFile.closeSync(); | 714 openedFile.closeSync(); |
715 file.deleteSync(); | 715 file.deleteSync(); |
716 Expect.isFalse(file.existsSync()); | 716 Expect.isFalse(file.existsSync()); |
717 } | 717 } |
718 | 718 |
| 719 static void testWriteFrom() async { |
| 720 asyncTestStarted(); |
| 721 File file = new File(tempDirectory.path + "/out_write_from"); |
| 722 |
| 723 var buffer = const [1, 2, 3]; |
| 724 var openedFile = await file.open(mode: WRITE); |
| 725 |
| 726 await openedFile.writeFrom(buffer); |
| 727 var result = []..addAll(buffer);; |
| 728 |
| 729 write([start, end]) async { |
| 730 await openedFile.writeFrom(buffer, start, end); |
| 731 result.addAll(buffer.sublist(start, end)); |
| 732 } |
| 733 await write(0, 3); |
| 734 await write(0, 2); |
| 735 await write(1, 2); |
| 736 await write(1, 3); |
| 737 await write(2, 3); |
| 738 |
| 739 var bytesFromFile = await file.readAsBytes(); |
| 740 Expect.listEquals(result, bytesFromFile); |
| 741 asyncTestDone("testWriteFrom"); |
| 742 } |
| 743 |
| 744 static void testWriteFromSync() { |
| 745 File file = new File(tempDirectory.path + "/out_write_from_sync"); |
| 746 |
| 747 var buffer = const [1, 2, 3]; |
| 748 var openedFile = file.openSync(mode: WRITE); |
| 749 |
| 750 openedFile.writeFromSync(buffer); |
| 751 var result = []..addAll(buffer);; |
| 752 |
| 753 write([start, end]) { |
| 754 openedFile.writeFromSync(buffer, start, end); |
| 755 result.addAll(buffer.sublist(start, end)); |
| 756 } |
| 757 write(0, 3); |
| 758 write(0, 2); |
| 759 write(1, 2); |
| 760 write(1, 3); |
| 761 write(2, 3); |
| 762 |
| 763 var bytesFromFile = file.readAsBytesSync(); |
| 764 Expect.listEquals(result, bytesFromFile); |
| 765 } |
| 766 |
719 // Tests exception handling after file was closed. | 767 // Tests exception handling after file was closed. |
720 static void testCloseException() { | 768 static void testCloseException() { |
721 bool exceptionCaught = false; | 769 bool exceptionCaught = false; |
722 bool wrongExceptionCaught = false; | 770 bool wrongExceptionCaught = false; |
723 File input = new File(tempDirectory.path + "/out_close_exception"); | 771 File input = new File(tempDirectory.path + "/out_close_exception"); |
724 RandomAccessFile openedFile = input.openSync(mode: WRITE); | 772 RandomAccessFile openedFile = input.openSync(mode: WRITE); |
725 openedFile.closeSync(); | 773 openedFile.closeSync(); |
726 try { | 774 try { |
727 openedFile.readByteSync(); | 775 openedFile.readByteSync(); |
728 } on FileSystemException catch (ex) { | 776 } on FileSystemException catch (ex) { |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 testReadWriteStreamLargeFile(); | 1368 testReadWriteStreamLargeFile(); |
1321 testReadAsBytes(); | 1369 testReadAsBytes(); |
1322 testReadAsBytesEmptyFile(); | 1370 testReadAsBytesEmptyFile(); |
1323 testReadAsText(); | 1371 testReadAsText(); |
1324 testReadAsTextEmptyFile(); | 1372 testReadAsTextEmptyFile(); |
1325 testReadAsLines(); | 1373 testReadAsLines(); |
1326 testReadAsErrors(); | 1374 testReadAsErrors(); |
1327 testPosition(); | 1375 testPosition(); |
1328 testTruncate(); | 1376 testTruncate(); |
1329 testTruncateSync(); | 1377 testTruncateSync(); |
| 1378 testWriteFrom(); |
| 1379 testWriteFromSync(); |
1330 testCloseException(); | 1380 testCloseException(); |
1331 testCloseExceptionStream(); | 1381 testCloseExceptionStream(); |
1332 testBufferOutOfBoundsException(); | 1382 testBufferOutOfBoundsException(); |
1333 testAppend(); | 1383 testAppend(); |
1334 testAppendSync(); | 1384 testAppendSync(); |
1335 testWriteAppend(); | 1385 testWriteAppend(); |
1336 testOutputStreamWriteAppend(); | 1386 testOutputStreamWriteAppend(); |
1337 testOutputStreamWriteString(); | 1387 testOutputStreamWriteString(); |
1338 testWriteVariousLists(); | 1388 testWriteVariousLists(); |
1339 testDirectory(); | 1389 testDirectory(); |
1340 testDirectorySync(); | 1390 testDirectorySync(); |
1341 testWriteStringUtf8(); | 1391 testWriteStringUtf8(); |
1342 testWriteStringUtf8Sync(); | 1392 testWriteStringUtf8Sync(); |
1343 testRename(targetExists: false); | 1393 testRename(targetExists: false); |
1344 testRenameSync(targetExists: false); | 1394 testRenameSync(targetExists: false); |
1345 testRename(targetExists: true); | 1395 testRename(targetExists: true); |
1346 testRenameSync(targetExists: true); | 1396 testRenameSync(targetExists: true); |
1347 testLastModified(); | 1397 testLastModified(); |
1348 testDoubleAsyncOperation(); | 1398 testDoubleAsyncOperation(); |
1349 asyncEnd(); | 1399 asyncEnd(); |
1350 }); | 1400 }); |
1351 } | 1401 } |
1352 } | 1402 } |
1353 | 1403 |
1354 main() { | 1404 main() { |
1355 FileTest.testMain(); | 1405 FileTest.testMain(); |
1356 } | 1406 } |
OLD | NEW |