| 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 testReadInto() async { | 719 static testReadInto() async { |
| 720 asyncTestStarted(); | 720 asyncTestStarted(); |
| 721 File file = new File(tempDirectory.path + "/out_read_into"); | 721 File file = new File(tempDirectory.path + "/out_read_into"); |
| 722 | 722 |
| 723 var openedFile = await file.open(mode: WRITE); | 723 var openedFile = await file.open(mode: WRITE); |
| 724 await openedFile.writeFrom(const [1, 2, 3]); | 724 await openedFile.writeFrom(const [1, 2, 3]); |
| 725 | 725 |
| 726 await openedFile.setPosition(0); | 726 await openedFile.setPosition(0); |
| 727 var list = [null, null, null]; | 727 var list = [null, null, null]; |
| 728 Expect.equals(3, await openedFile.readInto(list)); | 728 Expect.equals(3, await openedFile.readInto(list)); |
| 729 Expect.listEquals([1, 2, 3], list); | 729 Expect.listEquals([1, 2, 3], list); |
| 730 | 730 |
| 731 read(start, end, length, expected) async { | 731 read(start, end, length, expected) async { |
| 732 var list = [null, null, null]; | 732 var list = [null, null, null]; |
| 733 await openedFile.setPosition(0); | 733 await openedFile.setPosition(0); |
| 734 Expect.equals(length, await openedFile.readInto(list, start, end)); | 734 Expect.equals(length, await openedFile.readInto(list, start, end)); |
| 735 Expect.listEquals(expected, list); | 735 Expect.listEquals(expected, list); |
| 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 | 745 |
| 745 asyncTestDone("testReadInto"); | 746 asyncTestDone("testReadInto"); |
| 746 } | 747 } |
| 747 | 748 |
| 748 static void testReadIntoSync() { | 749 static void testReadIntoSync() { |
| 749 File file = new File(tempDirectory.path + "/out_read_into_sync"); | 750 File file = new File(tempDirectory.path + "/out_read_into_sync"); |
| 750 | 751 |
| 751 var openedFile = file.openSync(mode: WRITE); | 752 var openedFile = file.openSync(mode: WRITE); |
| 752 openedFile.writeFromSync(const [1, 2, 3]); | 753 openedFile.writeFromSync(const [1, 2, 3]); |
| 753 | 754 |
| 754 openedFile.setPositionSync(0); | 755 openedFile.setPositionSync(0); |
| 755 var list = [null, null, null]; | 756 var list = [null, null, null]; |
| 756 Expect.equals(3, openedFile.readIntoSync(list)); | 757 Expect.equals(3, openedFile.readIntoSync(list)); |
| 757 Expect.listEquals([1, 2, 3], list); | 758 Expect.listEquals([1, 2, 3], list); |
| 758 | 759 |
| 759 read(start, end, length, expected) { | 760 read(start, end, length, expected) { |
| 760 var list = [null, null, null]; | 761 var list = [null, null, null]; |
| 761 openedFile.setPositionSync(0); | 762 openedFile.setPositionSync(0); |
| 762 Expect.equals(length, openedFile.readIntoSync(list, start, end)); | 763 Expect.equals(length, openedFile.readIntoSync(list, start, end)); |
| 763 Expect.listEquals(expected, list); | 764 Expect.listEquals(expected, list); |
| 764 return list; | 765 return list; |
| 765 } | 766 } |
| 766 | 767 |
| 767 read(0, 3, 3, [1, 2, 3]); | 768 read(0, 3, 3, [1, 2, 3]); |
| 768 read(0, 2, 2, [1, 2, null]); | 769 read(0, 2, 2, [1, 2, null]); |
| 769 read(1, 2, 1, [null, 1, null]); | 770 read(1, 2, 1, [null, 1, null]); |
| 770 read(1, 3, 2, [null, 1, 2]); | 771 read(1, 3, 2, [null, 1, 2]); |
| 771 read(2, 3, 1, [null, null, 1]); | 772 read(2, 3, 1, [null, null, 1]); |
| 773 read(0, 0, 0, [null, null, null]); |
| 772 } | 774 } |
| 773 | 775 |
| 774 static void testWriteFrom() async { | 776 static testWriteFrom() async { |
| 775 asyncTestStarted(); | 777 asyncTestStarted(); |
| 776 File file = new File(tempDirectory.path + "/out_write_from"); | 778 File file = new File(tempDirectory.path + "/out_write_from"); |
| 777 | 779 |
| 778 var buffer = const [1, 2, 3]; | 780 var buffer = const [1, 2, 3]; |
| 779 var openedFile = await file.open(mode: WRITE); | 781 var openedFile = await file.open(mode: WRITE); |
| 780 | 782 |
| 781 await openedFile.writeFrom(buffer); | 783 await openedFile.writeFrom(buffer); |
| 782 var result = []..addAll(buffer);; | 784 var result = []..addAll(buffer);; |
| 783 | 785 |
| 784 write([start, end]) async { | 786 write([start, end]) async { |
| 785 await openedFile.writeFrom(buffer, start, end); | 787 var returnValue = await openedFile.writeFrom(buffer, start, end); |
| 788 Expect.identical(openedFile, returnValue); |
| 786 result.addAll(buffer.sublist(start, end)); | 789 result.addAll(buffer.sublist(start, end)); |
| 787 } | 790 } |
| 788 await write(0, 3); | 791 await write(0, 3); |
| 789 await write(0, 2); | 792 await write(0, 2); |
| 790 await write(1, 2); | 793 await write(1, 2); |
| 791 await write(1, 3); | 794 await write(1, 3); |
| 792 await write(2, 3); | 795 await write(2, 3); |
| 796 await write(0, 0); |
| 793 | 797 |
| 794 var bytesFromFile = await file.readAsBytes(); | 798 var bytesFromFile = await file.readAsBytes(); |
| 795 Expect.listEquals(result, bytesFromFile); | 799 Expect.listEquals(result, bytesFromFile); |
| 796 asyncTestDone("testWriteFrom"); | 800 asyncTestDone("testWriteFrom"); |
| 797 } | 801 } |
| 798 | 802 |
| 799 static void testWriteFromSync() { | 803 static void testWriteFromSync() { |
| 800 File file = new File(tempDirectory.path + "/out_write_from_sync"); | 804 File file = new File(tempDirectory.path + "/out_write_from_sync"); |
| 801 | 805 |
| 802 var buffer = const [1, 2, 3]; | 806 var buffer = const [1, 2, 3]; |
| 803 var openedFile = file.openSync(mode: WRITE); | 807 var openedFile = file.openSync(mode: WRITE); |
| 804 | 808 |
| 805 openedFile.writeFromSync(buffer); | 809 openedFile.writeFromSync(buffer); |
| 806 var result = []..addAll(buffer);; | 810 var result = []..addAll(buffer);; |
| 807 | 811 |
| 808 write([start, end]) { | 812 write([start, end]) { |
| 809 openedFile.writeFromSync(buffer, start, end); | 813 var returnValue = openedFile.writeFromSync(buffer, start, end); |
| 810 result.addAll(buffer.sublist(start, end)); | 814 result.addAll(buffer.sublist(start, end)); |
| 811 } | 815 } |
| 812 write(0, 3); | 816 write(0, 3); |
| 813 write(0, 2); | 817 write(0, 2); |
| 814 write(1, 2); | 818 write(1, 2); |
| 815 write(1, 3); | 819 write(1, 3); |
| 816 write(2, 3); | 820 write(2, 3); |
| 817 | 821 |
| 818 var bytesFromFile = file.readAsBytesSync(); | 822 var bytesFromFile = file.readAsBytesSync(); |
| 819 Expect.listEquals(result, bytesFromFile); | 823 Expect.listEquals(result, bytesFromFile); |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 testLastModified(); | 1458 testLastModified(); |
| 1455 testDoubleAsyncOperation(); | 1459 testDoubleAsyncOperation(); |
| 1456 asyncEnd(); | 1460 asyncEnd(); |
| 1457 }); | 1461 }); |
| 1458 } | 1462 } |
| 1459 } | 1463 } |
| 1460 | 1464 |
| 1461 main() { | 1465 main() { |
| 1462 FileTest.testMain(); | 1466 FileTest.testMain(); |
| 1463 } | 1467 } |
| OLD | NEW |