| 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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 return list; | 736 return list; |
| 737 } | 737 } |
| 738 | 738 |
| 739 await read(0, 3, 3, [1, 2, 3]); | 739 await read(0, 3, 3, [1, 2, 3]); |
| 740 await read(0, 2, 2, [1, 2, null]); | 740 await read(0, 2, 2, [1, 2, null]); |
| 741 await read(1, 2, 1, [null, 1, null]); | 741 await read(1, 2, 1, [null, 1, null]); |
| 742 await read(1, 3, 2, [null, 1, 2]); | 742 await read(1, 3, 2, [null, 1, 2]); |
| 743 await read(2, 3, 1, [null, null, 1]); | 743 await read(2, 3, 1, [null, null, 1]); |
| 744 await read(0, 0, 0, [null, null, null]); | 744 await read(0, 0, 0, [null, null, null]); |
| 745 | 745 |
| 746 await openedFile.close(); |
| 747 |
| 746 asyncTestDone("testReadInto"); | 748 asyncTestDone("testReadInto"); |
| 747 } | 749 } |
| 748 | 750 |
| 749 static void testReadIntoSync() { | 751 static void testReadIntoSync() { |
| 750 File file = new File(tempDirectory.path + "/out_read_into_sync"); | 752 File file = new File(tempDirectory.path + "/out_read_into_sync"); |
| 751 | 753 |
| 752 var openedFile = file.openSync(mode: WRITE); | 754 var openedFile = file.openSync(mode: WRITE); |
| 753 openedFile.writeFromSync(const [1, 2, 3]); | 755 openedFile.writeFromSync(const [1, 2, 3]); |
| 754 | 756 |
| 755 openedFile.setPositionSync(0); | 757 openedFile.setPositionSync(0); |
| 756 var list = [null, null, null]; | 758 var list = [null, null, null]; |
| 757 Expect.equals(3, openedFile.readIntoSync(list)); | 759 Expect.equals(3, openedFile.readIntoSync(list)); |
| 758 Expect.listEquals([1, 2, 3], list); | 760 Expect.listEquals([1, 2, 3], list); |
| 759 | 761 |
| 760 read(start, end, length, expected) { | 762 read(start, end, length, expected) { |
| 761 var list = [null, null, null]; | 763 var list = [null, null, null]; |
| 762 openedFile.setPositionSync(0); | 764 openedFile.setPositionSync(0); |
| 763 Expect.equals(length, openedFile.readIntoSync(list, start, end)); | 765 Expect.equals(length, openedFile.readIntoSync(list, start, end)); |
| 764 Expect.listEquals(expected, list); | 766 Expect.listEquals(expected, list); |
| 765 return list; | 767 return list; |
| 766 } | 768 } |
| 767 | 769 |
| 768 read(0, 3, 3, [1, 2, 3]); | 770 read(0, 3, 3, [1, 2, 3]); |
| 769 read(0, 2, 2, [1, 2, null]); | 771 read(0, 2, 2, [1, 2, null]); |
| 770 read(1, 2, 1, [null, 1, null]); | 772 read(1, 2, 1, [null, 1, null]); |
| 771 read(1, 3, 2, [null, 1, 2]); | 773 read(1, 3, 2, [null, 1, 2]); |
| 772 read(2, 3, 1, [null, null, 1]); | 774 read(2, 3, 1, [null, null, 1]); |
| 773 read(0, 0, 0, [null, null, null]); | 775 read(0, 0, 0, [null, null, null]); |
| 776 |
| 777 openedFile.closeSync(); |
| 774 } | 778 } |
| 775 | 779 |
| 776 static testWriteFrom() async { | 780 static testWriteFrom() async { |
| 777 asyncTestStarted(); | 781 asyncTestStarted(); |
| 778 File file = new File(tempDirectory.path + "/out_write_from"); | 782 File file = new File(tempDirectory.path + "/out_write_from"); |
| 779 | 783 |
| 780 var buffer = const [1, 2, 3]; | 784 var buffer = const [1, 2, 3]; |
| 781 var openedFile = await file.open(mode: WRITE); | 785 var openedFile = await file.open(mode: WRITE); |
| 782 | 786 |
| 783 await openedFile.writeFrom(buffer); | 787 await openedFile.writeFrom(buffer); |
| 784 var result = []..addAll(buffer);; | 788 var result = []..addAll(buffer);; |
| 785 | 789 |
| 786 write([start, end]) async { | 790 write([start, end]) async { |
| 787 var returnValue = await openedFile.writeFrom(buffer, start, end); | 791 var returnValue = await openedFile.writeFrom(buffer, start, end); |
| 788 Expect.identical(openedFile, returnValue); | 792 Expect.identical(openedFile, returnValue); |
| 789 result.addAll(buffer.sublist(start, end)); | 793 result.addAll(buffer.sublist(start, end)); |
| 790 } | 794 } |
| 791 await write(0, 3); | 795 await write(0, 3); |
| 792 await write(0, 2); | 796 await write(0, 2); |
| 793 await write(1, 2); | 797 await write(1, 2); |
| 794 await write(1, 3); | 798 await write(1, 3); |
| 795 await write(2, 3); | 799 await write(2, 3); |
| 796 await write(0, 0); | 800 await write(0, 0); |
| 797 | 801 |
| 798 var bytesFromFile = await file.readAsBytes(); | 802 var bytesFromFile = await file.readAsBytes(); |
| 799 Expect.listEquals(result, bytesFromFile); | 803 Expect.listEquals(result, bytesFromFile); |
| 804 |
| 805 await openedFile.close(); |
| 806 |
| 800 asyncTestDone("testWriteFrom"); | 807 asyncTestDone("testWriteFrom"); |
| 801 } | 808 } |
| 802 | 809 |
| 803 static void testWriteFromSync() { | 810 static void testWriteFromSync() { |
| 804 File file = new File(tempDirectory.path + "/out_write_from_sync"); | 811 File file = new File(tempDirectory.path + "/out_write_from_sync"); |
| 805 | 812 |
| 806 var buffer = const [1, 2, 3]; | 813 var buffer = const [1, 2, 3]; |
| 807 var openedFile = file.openSync(mode: WRITE); | 814 var openedFile = file.openSync(mode: WRITE); |
| 808 | 815 |
| 809 openedFile.writeFromSync(buffer); | 816 openedFile.writeFromSync(buffer); |
| 810 var result = []..addAll(buffer);; | 817 var result = []..addAll(buffer);; |
| 811 | 818 |
| 812 write([start, end]) { | 819 write([start, end]) { |
| 813 var returnValue = openedFile.writeFromSync(buffer, start, end); | 820 var returnValue = openedFile.writeFromSync(buffer, start, end); |
| 814 result.addAll(buffer.sublist(start, end)); | 821 result.addAll(buffer.sublist(start, end)); |
| 815 } | 822 } |
| 816 write(0, 3); | 823 write(0, 3); |
| 817 write(0, 2); | 824 write(0, 2); |
| 818 write(1, 2); | 825 write(1, 2); |
| 819 write(1, 3); | 826 write(1, 3); |
| 820 write(2, 3); | 827 write(2, 3); |
| 821 | 828 |
| 822 var bytesFromFile = file.readAsBytesSync(); | 829 var bytesFromFile = file.readAsBytesSync(); |
| 823 Expect.listEquals(result, bytesFromFile); | 830 Expect.listEquals(result, bytesFromFile); |
| 831 |
| 832 openedFile.closeSync(); |
| 824 } | 833 } |
| 825 | 834 |
| 826 // Tests exception handling after file was closed. | 835 // Tests exception handling after file was closed. |
| 827 static void testCloseException() { | 836 static void testCloseException() { |
| 828 bool exceptionCaught = false; | 837 bool exceptionCaught = false; |
| 829 bool wrongExceptionCaught = false; | 838 bool wrongExceptionCaught = false; |
| 830 File input = new File(tempDirectory.path + "/out_close_exception"); | 839 File input = new File(tempDirectory.path + "/out_close_exception"); |
| 831 RandomAccessFile openedFile = input.openSync(mode: WRITE); | 840 RandomAccessFile openedFile = input.openSync(mode: WRITE); |
| 832 openedFile.closeSync(); | 841 openedFile.closeSync(); |
| 833 try { | 842 try { |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 testLastModified(); | 1467 testLastModified(); |
| 1459 testDoubleAsyncOperation(); | 1468 testDoubleAsyncOperation(); |
| 1460 asyncEnd(); | 1469 asyncEnd(); |
| 1461 }); | 1470 }); |
| 1462 } | 1471 } |
| 1463 } | 1472 } |
| 1464 | 1473 |
| 1465 main() { | 1474 main() { |
| 1466 FileTest.testMain(); | 1475 FileTest.testMain(); |
| 1467 } | 1476 } |
| OLD | NEW |