Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: tests/standalone/io/file_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "package:expect/expect.dart";
8 import "package:path/path.dart";
9 import 'dart:async'; 7 import 'dart:async';
10 import 'dart:convert'; 8 import 'dart:convert';
11 import 'dart:collection'; 9 import 'dart:collection';
12 import 'dart:io'; 10 import 'dart:io';
13 import 'dart:isolate'; 11
12 import "package:async_helper/async_helper.dart";
13 import "package:expect/expect.dart";
14 import "package:path/path.dart";
14 15
15 class MyListOfOneElement 16 class MyListOfOneElement
16 extends Object with ListMixin<int> implements List<int> { 17 extends Object with ListMixin<int> implements List<int> {
17 int _value; 18 int _value;
18 MyListOfOneElement(this._value); 19 MyListOfOneElement(this._value);
19 int get length => 1; 20 int get length => 1;
20 operator [](int index) => _value; 21 operator [](int index) => _value;
21 void set length(int index) { throw "Unsupported"; } 22 void set length(int index) { throw "Unsupported"; }
22 operator []=(int index, value) { 23 operator []=(int index, value) {
23 if (index != 0) { 24 if (index != 0) {
24 throw "Unsupported"; 25 throw "Unsupported";
25 } else { 26 } else {
26 _value = value; 27 _value = value;
27 } 28 }
28 } 29 }
29 } 30 }
30 31
31 class FileTest { 32 class FileTest {
32 static Directory tempDirectory; 33 static Directory tempDirectory;
33 static int numLiveAsyncTests = 0; 34 static int numLiveAsyncTests = 0;
34 static ReceivePort port;
35 35
36 static void asyncTestStarted() { ++numLiveAsyncTests; } 36 static void asyncTestStarted() {
37 asyncStart();
38 ++numLiveAsyncTests;
39 }
37 static void asyncTestDone(String name) { 40 static void asyncTestDone(String name) {
41 asyncEnd();
38 --numLiveAsyncTests; 42 --numLiveAsyncTests;
39 if (numLiveAsyncTests == 0) { 43 if (numLiveAsyncTests == 0) {
40 deleteTempDirectory(); 44 deleteTempDirectory();
41 port.close();
42 } 45 }
43 } 46 }
44 47
45 static void createTempDirectory(Function doNext) { 48 static void createTempDirectory(Function doNext) {
46 new Directory('').createTemp().then((temp) { 49 new Directory('').createTemp().then((temp) {
47 tempDirectory = temp; 50 tempDirectory = temp;
48 doNext(); 51 doNext();
49 }); 52 });
50 } 53 }
51 54
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 }, 209 },
207 onDone: () { 210 onDone: () {
208 Expect.equals(2 * buffer.length, position); 211 Expect.equals(2 * buffer.length, position);
209 outputFile.delete().then((ignore) { done.complete(); }); 212 outputFile.delete().then((ignore) { done.complete(); });
210 }); 213 });
211 }); 214 });
212 return done.future; 215 return done.future;
213 } 216 }
214 217
215 static void testRead() { 218 static void testRead() {
216 ReceivePort port = new ReceivePort(); 219 asyncStart();
217 // Read a file and check part of it's contents. 220 // Read a file and check part of it's contents.
218 String filename = getFilename("bin/file_test.cc"); 221 String filename = getFilename("bin/file_test.cc");
219 File file = new File(filename); 222 File file = new File(filename);
220 file.open(mode: READ).then((RandomAccessFile file) { 223 file.open(mode: READ).then((RandomAccessFile file) {
221 List<int> buffer = new List<int>(10); 224 List<int> buffer = new List<int>(10);
222 file.readInto(buffer, 0, 5).then((bytes_read) { 225 file.readInto(buffer, 0, 5).then((bytes_read) {
223 Expect.equals(5, bytes_read); 226 Expect.equals(5, bytes_read);
224 file.readInto(buffer, 5, 10).then((bytes_read) { 227 file.readInto(buffer, 5, 10).then((bytes_read) {
225 Expect.equals(5, bytes_read); 228 Expect.equals(5, bytes_read);
226 Expect.equals(47, buffer[0]); // represents '/' in the file. 229 Expect.equals(47, buffer[0]); // represents '/' in the file.
227 Expect.equals(47, buffer[1]); // represents '/' in the file. 230 Expect.equals(47, buffer[1]); // represents '/' in the file.
228 Expect.equals(32, buffer[2]); // represents ' ' in the file. 231 Expect.equals(32, buffer[2]); // represents ' ' in the file.
229 Expect.equals(67, buffer[3]); // represents 'C' in the file. 232 Expect.equals(67, buffer[3]); // represents 'C' in the file.
230 Expect.equals(111, buffer[4]); // represents 'o' in the file. 233 Expect.equals(111, buffer[4]); // represents 'o' in the file.
231 Expect.equals(112, buffer[5]); // represents 'p' in the file. 234 Expect.equals(112, buffer[5]); // represents 'p' in the file.
232 Expect.equals(121, buffer[6]); // represents 'y' in the file. 235 Expect.equals(121, buffer[6]); // represents 'y' in the file.
233 Expect.equals(114, buffer[7]); // represents 'r' in the file. 236 Expect.equals(114, buffer[7]); // represents 'r' in the file.
234 Expect.equals(105, buffer[8]); // represents 'i' in the file. 237 Expect.equals(105, buffer[8]); // represents 'i' in the file.
235 Expect.equals(103, buffer[9]); // represents 'g' in the file. 238 Expect.equals(103, buffer[9]); // represents 'g' in the file.
236 file.close().then((ignore) => port.close()); 239 file.close().then((ignore) => asyncEnd());
237 }); 240 });
238 }); 241 });
239 }); 242 });
240 } 243 }
241 244
242 static void testReadSync() { 245 static void testReadSync() {
243 // Read a file and check part of it's contents. 246 // Read a file and check part of it's contents.
244 String filename = getFilename("bin/file_test.cc"); 247 String filename = getFilename("bin/file_test.cc");
245 RandomAccessFile raf = (new File(filename)).openSync(); 248 RandomAccessFile raf = (new File(filename)).openSync();
246 List<int> buffer = new List<int>(42); 249 List<int> buffer = new List<int>(42);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 file2.deleteSync(); 555 file2.deleteSync();
553 asyncTestDone("testWriteVariousLists"); 556 asyncTestDone("testWriteVariousLists");
554 }); 557 });
555 }); 558 });
556 }); 559 });
557 }); 560 });
558 } 561 }
559 562
560 static void testDirectory() { 563 static void testDirectory() {
561 asyncTestStarted(); 564 asyncTestStarted();
562
563 // Port to verify that the test completes.
564 var port = new ReceivePort();
565 port.receive((message, replyTo) {
566 port.close();
567 Expect.equals(1, message);
568 asyncTestDone("testDirectory");
569 });
570
571 var tempDir = tempDirectory.path; 565 var tempDir = tempDirectory.path;
572 var file = new File("${tempDir}/testDirectory"); 566 var file = new File("${tempDir}/testDirectory");
573 file.create().then((ignore) { 567 file.create().then((ignore) {
574 Directory d = file.directory; 568 Directory d = file.directory;
575 d.exists().then((xexists) { 569 d.exists().then((xexists) {
576 Expect.isTrue(xexists); 570 Expect.isTrue(xexists);
577 Expect.isTrue(d.path.endsWith(tempDir)); 571 Expect.isTrue(d.path.endsWith(tempDir));
578 file.delete().then((ignore) { 572 file.delete().then((ignore) => asyncTestDone("testDirectory"));
579 port.toSendPort().send(1);
580 });
581 }); 573 });
582 }); 574 });
583 } 575 }
584 576
585 static void testDirectorySync() { 577 static void testDirectorySync() {
586 var tempDir = tempDirectory.path; 578 var tempDir = tempDirectory.path;
587 var file = new File("${tempDir}/testDirectorySync"); 579 var file = new File("${tempDir}/testDirectorySync");
588 // Non-existing file still provides the directory. 580 // Non-existing file still provides the directory.
589 Expect.equals("${tempDir}", file.directory.path); 581 Expect.equals("${tempDir}", file.directory.path);
590 file.createSync(); 582 file.createSync();
591 // Check that the path of the returned directory is the temp directory. 583 // Check that the path of the returned directory is the temp directory.
592 Directory d = file.directory; 584 Directory d = file.directory;
593 Expect.isTrue(d.existsSync()); 585 Expect.isTrue(d.existsSync());
594 Expect.isTrue(d.path.endsWith(tempDir)); 586 Expect.isTrue(d.path.endsWith(tempDir));
595 file.deleteSync(); 587 file.deleteSync();
596 // The directory getter does not care about file or type of file 588 // The directory getter does not care about file or type of file
597 // system entity. 589 // system entity.
598 Expect.equals("${tempDir}", file.directory.path); 590 Expect.equals("${tempDir}", file.directory.path);
599 file = new File("foo"); 591 file = new File("foo");
600 Expect.equals(".", file.directory.path); 592 Expect.equals(".", file.directory.path);
601 file = new File("."); 593 file = new File(".");
602 Expect.equals(".", file.directory.path); 594 Expect.equals(".", file.directory.path);
603 } 595 }
604 596
605 // Test for file length functionality. 597 // Test for file length functionality.
606 static void testLength() { 598 static void testLength() {
607 var port = new ReceivePort(); 599 asyncTestStarted();
608 String filename = getFilename("tests/vm/data/fixed_length_file"); 600 String filename = getFilename("tests/vm/data/fixed_length_file");
609 File file = new File(filename); 601 File file = new File(filename);
610 RandomAccessFile openedFile = file.openSync(); 602 RandomAccessFile openedFile = file.openSync();
611 openedFile.length().then((length) { 603 openedFile.length().then((length) {
612 Expect.equals(42, length); 604 Expect.equals(42, length);
613 openedFile.close().then((ignore) => port.close()); 605 openedFile.close().then((ignore) => asyncTestDone("testLength"));
614 }); 606 });
615 file.length().then((length) { 607 file.length().then((length) {
616 Expect.equals(42, length); 608 Expect.equals(42, length);
617 }); 609 });
618 } 610 }
619 611
620 static void testLengthSync() { 612 static void testLengthSync() {
621 String filename = getFilename("tests/vm/data/fixed_length_file"); 613 String filename = getFilename("tests/vm/data/fixed_length_file");
622 File file = new File(filename); 614 File file = new File(filename);
623 RandomAccessFile openedFile = file.openSync(); 615 RandomAccessFile openedFile = file.openSync();
624 Expect.equals(42, file.lengthSync()); 616 Expect.equals(42, file.lengthSync());
625 Expect.equals(42, openedFile.lengthSync()); 617 Expect.equals(42, openedFile.lengthSync());
626 openedFile.closeSync(); 618 openedFile.closeSync();
627 } 619 }
628 620
629 // Test for file position functionality. 621 // Test for file position functionality.
630 static void testPosition() { 622 static void testPosition() {
631 var port = new ReceivePort(); 623 asyncTestStarted();
632 String filename = getFilename("tests/vm/data/fixed_length_file"); 624 String filename = getFilename("tests/vm/data/fixed_length_file");
633 RandomAccessFile input = (new File(filename)).openSync(); 625 RandomAccessFile input = (new File(filename)).openSync();
634 input.position().then((position) { 626 input.position().then((position) {
635 Expect.equals(0, position); 627 Expect.equals(0, position);
636 List<int> buffer = new List<int>(100); 628 List<int> buffer = new List<int>(100);
637 input.readInto(buffer, 0, 12).then((bytes_read) { 629 input.readInto(buffer, 0, 12).then((bytes_read) {
638 input.position().then((position) { 630 input.position().then((position) {
639 Expect.equals(12, position); 631 Expect.equals(12, position);
640 input.readInto(buffer, 12, 18).then((bytes_read) { 632 input.readInto(buffer, 12, 18).then((bytes_read) {
641 input.position().then((position) { 633 input.position().then((position) {
642 Expect.equals(18, position); 634 Expect.equals(18, position);
643 input.setPosition(8).then((ignore) { 635 input.setPosition(8).then((ignore) {
644 input.position().then((position) { 636 input.position().then((position) {
645 Expect.equals(8, position); 637 Expect.equals(8, position);
646 input.close().then((ignore) => port.close()); 638 input.close().then((ignore) => asyncTestDone("testPosition"));
647 }); 639 });
648 }); 640 });
649 }); 641 });
650 }); 642 });
651 }); 643 });
652 }); 644 });
653 }); 645 });
654 } 646 }
655 647
656 static void testPositionSync() { 648 static void testPositionSync() {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 var name = getFilename("tests/vm/data/fixed_length_file"); 924 var name = getFilename("tests/vm/data/fixed_length_file");
933 var f = new File(name); 925 var f = new File(name);
934 Expect.isTrue(f.existsSync()); 926 Expect.isTrue(f.existsSync());
935 name = f.fullPathSync(); 927 name = f.fullPathSync();
936 var g = new File(name); 928 var g = new File(name);
937 Expect.isTrue(g.existsSync()); 929 Expect.isTrue(g.existsSync());
938 Expect.equals(name, g.fullPathSync()); 930 Expect.equals(name, g.fullPathSync());
939 } 931 }
940 932
941 static void testReadAsBytes() { 933 static void testReadAsBytes() {
942 var port = new ReceivePort(); 934 asyncTestStarted();
943 port.receive((result, replyTo) {
944 port.close();
945 Expect.equals(42, result);
946 });
947 var name = getFilename("tests/vm/data/fixed_length_file"); 935 var name = getFilename("tests/vm/data/fixed_length_file");
948 var f = new File(name); 936 var f = new File(name);
949 f.readAsBytes().then((bytes) { 937 f.readAsBytes().then((bytes) {
950 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 938 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
951 port.toSendPort().send(bytes.length); 939 Expect.equals(42, bytes.length);
940 asyncTestDone("testReadAsBytes");
952 }); 941 });
953 } 942 }
954 943
955 static void testReadAsBytesEmptyFile() { 944 static void testReadAsBytesEmptyFile() {
956 var port = new ReceivePort(); 945 asyncTestStarted();
957 port.receive((result, replyTo) {
958 port.close();
959 Expect.equals(0, result);
960 });
961 var name = getFilename("tests/vm/data/empty_file"); 946 var name = getFilename("tests/vm/data/empty_file");
962 var f = new File(name); 947 var f = new File(name);
963 f.readAsBytes().then((bytes) { 948 f.readAsBytes().then((bytes) {
964 port.toSendPort().send(bytes.length); 949 Expect.equals(0, bytes.length);
950 asyncTestDone("testReadAsBytesEmptyFile");
965 }); 951 });
966 } 952 }
967 953
968 static void testReadAsBytesSync() { 954 static void testReadAsBytesSync() {
969 var name = getFilename("tests/vm/data/fixed_length_file"); 955 var name = getFilename("tests/vm/data/fixed_length_file");
970 var bytes = new File(name).readAsBytesSync(); 956 var bytes = new File(name).readAsBytesSync();
971 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 957 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
972 Expect.equals(bytes.length, 42); 958 Expect.equals(bytes.length, 42);
973 } 959 }
974 960
975 static void testReadAsBytesSyncEmptyFile() { 961 static void testReadAsBytesSyncEmptyFile() {
976 var name = getFilename("tests/vm/data/empty_file"); 962 var name = getFilename("tests/vm/data/empty_file");
977 var bytes = new File(name).readAsBytesSync(); 963 var bytes = new File(name).readAsBytesSync();
978 Expect.equals(bytes.length, 0); 964 Expect.equals(bytes.length, 0);
979 } 965 }
980 966
981 static void testReadAsText() { 967 static void testReadAsText() {
982 var port = new ReceivePort(); 968 asyncTestStarted();
983 port.receive((result, replyTo) {
984 port.close();
985 Expect.equals(1, result);
986 });
987 var name = getFilename("tests/vm/data/fixed_length_file"); 969 var name = getFilename("tests/vm/data/fixed_length_file");
988 var f = new File(name); 970 var f = new File(name);
989 f.readAsString(encoding: UTF8).then((text) { 971 f.readAsString(encoding: UTF8).then((text) {
990 Expect.isTrue(text.endsWith("42 bytes.")); 972 Expect.isTrue(text.endsWith("42 bytes."));
991 Expect.equals(42, text.length); 973 Expect.equals(42, text.length);
992 var name = getDataFilename("tests/standalone/io/read_as_text.dat"); 974 var name = getDataFilename("tests/standalone/io/read_as_text.dat");
993 var f = new File(name); 975 var f = new File(name);
994 f.readAsString(encoding: UTF8).then((text) { 976 f.readAsString(encoding: UTF8).then((text) {
995 Expect.equals(6, text.length); 977 Expect.equals(6, text.length);
996 var expected = [955, 120, 46, 32, 120, 10]; 978 var expected = [955, 120, 46, 32, 120, 10];
997 Expect.listEquals(expected, text.codeUnits); 979 Expect.listEquals(expected, text.codeUnits);
998 f.readAsString(encoding: LATIN1).then((text) { 980 f.readAsString(encoding: LATIN1).then((text) {
999 Expect.equals(7, text.length); 981 Expect.equals(7, text.length);
1000 var expected = [206, 187, 120, 46, 32, 120, 10]; 982 var expected = [206, 187, 120, 46, 32, 120, 10];
1001 Expect.listEquals(expected, text.codeUnits); 983 Expect.listEquals(expected, text.codeUnits);
1002 var readAsStringFuture = f.readAsString(encoding: ASCII); 984 var readAsStringFuture = f.readAsString(encoding: ASCII);
1003 readAsStringFuture.then((text) { 985 readAsStringFuture.then((text) {
1004 Expect.fail("Non-ascii char should cause error"); 986 Expect.fail("Non-ascii char should cause error");
1005 }).catchError((e) { 987 }).catchError((e) {
1006 port.toSendPort().send(1); 988 asyncTestDone("testReadAsText");
1007 }); 989 });
1008 }); 990 });
1009 }); 991 });
1010 }); 992 });
1011 } 993 }
1012 994
1013 static void testReadAsTextEmptyFile() { 995 static void testReadAsTextEmptyFile() {
1014 var port = new ReceivePort(); 996 asyncTestStarted();
1015 port.receive((result, replyTo) {
1016 port.close();
1017 Expect.equals(0, result);
1018 });
1019 var name = getFilename("tests/vm/data/empty_file"); 997 var name = getFilename("tests/vm/data/empty_file");
1020 var f = new File(name); 998 var f = new File(name);
1021 f.readAsString(encoding: UTF8).then((text) { 999 f.readAsString(encoding: UTF8).then((text) {
1022 port.toSendPort().send(text.length); 1000 Expect.equals(0, text.length);
1001 asyncTestDone("testReadAsTextEmptyFile");
1023 return true; 1002 return true;
1024 }); 1003 });
1025 } 1004 }
1026 1005
1027 static void testReadAsTextSync() { 1006 static void testReadAsTextSync() {
1028 var name = getFilename("tests/vm/data/fixed_length_file"); 1007 var name = getFilename("tests/vm/data/fixed_length_file");
1029 var text = new File(name).readAsStringSync(); 1008 var text = new File(name).readAsStringSync();
1030 Expect.isTrue(text.endsWith("42 bytes.")); 1009 Expect.isTrue(text.endsWith("42 bytes."));
1031 Expect.equals(42, text.length); 1010 Expect.equals(42, text.length);
1032 name = getDataFilename("tests/standalone/io/read_as_text.dat"); 1011 name = getDataFilename("tests/standalone/io/read_as_text.dat");
(...skipping 18 matching lines...) Expand all
1051 Expect.listEquals(expected, text.codeUnits); 1030 Expect.listEquals(expected, text.codeUnits);
1052 } 1031 }
1053 1032
1054 static void testReadAsTextSyncEmptyFile() { 1033 static void testReadAsTextSyncEmptyFile() {
1055 var name = getFilename("tests/vm/data/empty_file"); 1034 var name = getFilename("tests/vm/data/empty_file");
1056 var text = new File(name).readAsStringSync(); 1035 var text = new File(name).readAsStringSync();
1057 Expect.equals(0, text.length); 1036 Expect.equals(0, text.length);
1058 } 1037 }
1059 1038
1060 static void testReadAsLines() { 1039 static void testReadAsLines() {
1061 var port = new ReceivePort(); 1040 asyncTestStarted();
1062 port.receive((result, replyTo) {
1063 port.close();
1064 Expect.equals(42, result);
1065 });
1066 var name = getFilename("tests/vm/data/fixed_length_file"); 1041 var name = getFilename("tests/vm/data/fixed_length_file");
1067 var f = new File(name); 1042 var f = new File(name);
1068 f.readAsLines(encoding: UTF8).then((lines) { 1043 f.readAsLines(encoding: UTF8).then((lines) {
1069 Expect.equals(1, lines.length); 1044 Expect.equals(1, lines.length);
1070 var line = lines[0]; 1045 var line = lines[0];
1071 Expect.isTrue(line.endsWith("42 bytes.")); 1046 Expect.isTrue(line.endsWith("42 bytes."));
1072 port.toSendPort().send(line.length); 1047 Expect.equals(42, line.length);
1048 asyncTestDone("testReadAsLines");
1073 }); 1049 });
1074 } 1050 }
1075 1051
1076 static void testReadAsLinesSync() { 1052 static void testReadAsLinesSync() {
1077 var name = getFilename("tests/vm/data/fixed_length_file"); 1053 var name = getFilename("tests/vm/data/fixed_length_file");
1078 var lines = new File(name).readAsLinesSync(); 1054 var lines = new File(name).readAsLinesSync();
1079 Expect.equals(1, lines.length); 1055 Expect.equals(1, lines.length);
1080 var line = lines[0]; 1056 var line = lines[0];
1081 Expect.isTrue(line.endsWith("42 bytes.")); 1057 Expect.isTrue(line.endsWith("42 bytes."));
1082 Expect.equals(42, line.length); 1058 Expect.equals(42, line.length);
1083 name = getDataFilename("tests/standalone/io/readline_test1.dat"); 1059 name = getDataFilename("tests/standalone/io/readline_test1.dat");
1084 lines = new File(name).readAsLinesSync(); 1060 lines = new File(name).readAsLinesSync();
1085 Expect.equals(10, lines.length); 1061 Expect.equals(10, lines.length);
1086 } 1062 }
1087 1063
1088 1064
1089 static void testReadAsErrors() { 1065 static void testReadAsErrors() {
1090 var port = new ReceivePort(); 1066 asyncTestStarted();
1091 port.receive((message, _) {
1092 port.close();
1093 Expect.equals(1, message);
1094 });
1095 var f = new File('.'); 1067 var f = new File('.');
1096 Expect.throws(f.readAsBytesSync, (e) => e is FileException); 1068 Expect.throws(f.readAsBytesSync, (e) => e is FileException);
1097 Expect.throws(f.readAsStringSync, (e) => e is FileException); 1069 Expect.throws(f.readAsStringSync, (e) => e is FileException);
1098 Expect.throws(f.readAsLinesSync, (e) => e is FileException); 1070 Expect.throws(f.readAsLinesSync, (e) => e is FileException);
1099 var readAsBytesFuture = f.readAsBytes(); 1071 var readAsBytesFuture = f.readAsBytes();
1100 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected")) 1072 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected"))
1101 .catchError((e) { 1073 .catchError((e) {
1102 var readAsStringFuture = f.readAsString(encoding: UTF8); 1074 var readAsStringFuture = f.readAsString(encoding: UTF8);
1103 readAsStringFuture.then((text) => Expect.fail("no text expected")) 1075 readAsStringFuture.then((text) => Expect.fail("no text expected"))
1104 .catchError((e) { 1076 .catchError((e) {
1105 var readAsLinesFuture = f.readAsLines(encoding: UTF8); 1077 var readAsLinesFuture = f.readAsLines(encoding: UTF8);
1106 readAsLinesFuture.then((lines) => Expect.fail("no lines expected")) 1078 readAsLinesFuture.then((lines) => Expect.fail("no lines expected"))
1107 .catchError((e) { 1079 .catchError((e) {
1108 port.toSendPort().send(1); 1080 asyncTestDone("testReadAsLines");
1109 }); 1081 });
1110 }); 1082 });
1111 }); 1083 });
1112 } 1084 }
1113 1085
1114 static void testLastModified() { 1086 static void testLastModified() {
1115 var port = new ReceivePort(); 1087 asyncTestStarted();
1116 new File(Platform.executable).lastModified().then((modified) { 1088 new File(Platform.executable).lastModified().then((modified) {
1117 Expect.isTrue(modified is DateTime); 1089 Expect.isTrue(modified is DateTime);
1118 Expect.isTrue(modified.isBefore(new DateTime.now())); 1090 Expect.isTrue(modified.isBefore(new DateTime.now()));
1119 port.close(); 1091 asyncTestDone("testLastModified");
1120 }); 1092 });
1121 } 1093 }
1122 1094
1123 static void testLastModifiedSync() { 1095 static void testLastModifiedSync() {
1124 var modified = new File(Platform.executable).lastModifiedSync(); 1096 var modified = new File(Platform.executable).lastModifiedSync();
1125 Expect.isTrue(modified is DateTime); 1097 Expect.isTrue(modified is DateTime);
1126 Expect.isTrue(modified.isBefore(new DateTime.now())); 1098 Expect.isTrue(modified.isBefore(new DateTime.now()));
1127 } 1099 }
1128 1100
1129 // 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
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 // 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
1282 // directory, or the top directory. 1254 // directory, or the top directory.
1283 static String getFilename(String path) => 1255 static String getFilename(String path) =>
1284 new File(path).existsSync() ? path : 'runtime/$path'; 1256 new File(path).existsSync() ? path : 'runtime/$path';
1285 1257
1286 static String getDataFilename(String path) => 1258 static String getDataFilename(String path) =>
1287 new File(path).existsSync() ? path : '../$path'; 1259 new File(path).existsSync() ? path : '../$path';
1288 1260
1289 // Main test entrypoint. 1261 // Main test entrypoint.
1290 static testMain() { 1262 static testMain() {
1291 port = new ReceivePort();
1292 testRead(); 1263 testRead();
1293 testReadSync(); 1264 testReadSync();
1294 testReadStream(); 1265 testReadStream();
1295 testLength(); 1266 testLength();
1296 testLengthSync(); 1267 testLengthSync();
1297 testPosition(); 1268 testPosition();
1298 testPositionSync(); 1269 testPositionSync();
1299 testOpenDirectoryAsFile(); 1270 testOpenDirectoryAsFile();
1300 testOpenDirectoryAsFileSync(); 1271 testOpenDirectoryAsFileSync();
1301 testOpenFile(); 1272 testOpenFile();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 testWriteStringUtf8Sync(); 1309 testWriteStringUtf8Sync();
1339 testRename(); 1310 testRename();
1340 testRenameSync(); 1311 testRenameSync();
1341 }); 1312 });
1342 } 1313 }
1343 } 1314 }
1344 1315
1345 main() { 1316 main() {
1346 FileTest.testMain(); 1317 FileTest.testMain();
1347 } 1318 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_system_links_test.dart ('k') | tests/standalone/io/file_typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698