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

Side by Side Diff: tests/standalone/src/io/FileTest.dart

Issue 9630012: Error reporting on File in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made Dart OSError constructor const Created 8 years, 9 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
« runtime/bin/utils.h ('K') | « runtime/bin/utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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:io"); 7 #import("dart:io");
8 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 class MyListOfOneElement implements List { 10 class MyListOfOneElement implements List {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 Expect.isTrue(d.existsSync()); 503 Expect.isTrue(d.existsSync());
504 Expect.isTrue(d.path.endsWith(tempDir)); 504 Expect.isTrue(d.path.endsWith(tempDir));
505 file.deleteSync(); 505 file.deleteSync();
506 // Directories should throw exception. 506 // Directories should throw exception.
507 var file_dir = new File("."); 507 var file_dir = new File(".");
508 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; }); 508 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; });
509 file_dir = new File(tempDir); 509 file_dir = new File(tempDir);
510 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; }); 510 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; });
511 } 511 }
512 512
513 static void testFileError() {
514 void checkOpenNonExistentFileException(e) {
515 print(e);
516 Expect.isTrue(e is FileIOException);
517 Expect.isTrue(e.osError != null);
518 Expect.isTrue(e.toString().indexOf("Cannot open file") != -1);
519 if (new Platform().operatingSystem() == "macos") {
Mads Ager (google) 2012/03/09 09:40:13 Remember to broaden this one to the other platform
Søren Gjesse 2012/03/13 08:25:55 Done.
520 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
521 Expect.equals(2, e.osError.errorCode);
522 }
523 }
524
525 var tempDir = tempDirectory.path;
526 var file = new File("${tempDir}/nonExistentFile");
527
528 // Non-existing file should throw exception.
529 try {
530 file.openSync();
531 } catch (Exception e) {
532 checkOpenNonExistentFileException(e);
533 }
534
535 file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code"));
536 file.onError = (e) => checkOpenNonExistentFileException(e);
537 }
538
539
513 // Test for file length functionality. 540 // Test for file length functionality.
514 static void testLength() { 541 static void testLength() {
515 String filename = getFilename("tests/vm/data/fixed_length_file"); 542 String filename = getFilename("tests/vm/data/fixed_length_file");
516 RandomAccessFile input = (new File(filename)).openSync(); 543 RandomAccessFile input = (new File(filename)).openSync();
517 input.onError = (s) { 544 input.onError = (s) {
518 Expect.fail("No errors expected"); 545 Expect.fail("No errors expected");
519 }; 546 };
520 input.length((length) { 547 input.length((length) {
521 Expect.equals(42, length); 548 Expect.equals(42, length);
522 input.close(() => null); 549 input.close(() => null);
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 // Helper method to be able to run the test from the runtime 1060 // Helper method to be able to run the test from the runtime
1034 // directory, or the top directory. 1061 // directory, or the top directory.
1035 static String getFilename(String path) => 1062 static String getFilename(String path) =>
1036 new File(path).existsSync() ? path : 'runtime/' + path; 1063 new File(path).existsSync() ? path : 'runtime/' + path;
1037 1064
1038 static String getDataFilename(String path) => 1065 static String getDataFilename(String path) =>
1039 new File(path).existsSync() ? path : '../' + path; 1066 new File(path).existsSync() ? path : '../' + path;
1040 1067
1041 // Main test entrypoint. 1068 // Main test entrypoint.
1042 static testMain() { 1069 static testMain() {
1043 testRead(); 1070 /*testRead();
1044 testReadSync(); 1071 testReadSync();
1045 testReadStream(); 1072 testReadStream();
1046 testLength(); 1073 testLength();
1047 testLengthSync(); 1074 testLengthSync();
1048 testPosition(); 1075 testPosition();
1049 testPositionSync(); 1076 testPositionSync();
1050 testMixedSyncAndAsync(); 1077 testMixedSyncAndAsync();
1051 testOpenDirectoryAsFile(); 1078 testOpenDirectoryAsFile();
1052 testOpenDirectoryAsFileSync(); 1079 testOpenDirectoryAsFileSync();
1053 testReadAsBytes(); 1080 testReadAsBytes();
1054 testReadAsBytesSync(); 1081 testReadAsBytesSync();
1055 testReadAsText(); 1082 testReadAsText();
1056 testReadAsTextSync(); 1083 testReadAsTextSync();
1057 testReadAsLines(); 1084 testReadAsLines();
1058 testReadAsLinesSync(); 1085 testReadAsLinesSync();
1059 testReadAsErrors(); 1086 testReadAsErrors();
1060 1087 */
1061 createTempDirectory(() { 1088 createTempDirectory(() {
1062 testReadWrite(); 1089 /* testReadWrite();
1063 testReadWriteSync(); 1090 testReadWriteSync();
1064 testReadWriteStream(); 1091 testReadWriteStream();
1065 testReadEmptyFileSync(); 1092 testReadEmptyFileSync();
1066 testReadEmptyFile(); 1093 testReadEmptyFile();
1067 testTruncate(); 1094 testTruncate();
1068 testTruncateSync(); 1095 testTruncateSync();
1069 testCloseException(); 1096 testCloseException();
1070 testCloseExceptionStream(); 1097 testCloseExceptionStream();
1071 testBufferOutOfBoundsException(); 1098 testBufferOutOfBoundsException();
1072 testAppend(); 1099 testAppend();
1073 testAppendSync(); 1100 testAppendSync();
1074 testWriteAppend(); 1101 testWriteAppend();
1075 testOutputStreamWriteAppend(); 1102 testOutputStreamWriteAppend();
1076 testWriteVariousLists(); 1103 testWriteVariousLists();
1077 testDirectory(); 1104 testDirectory();
1078 testDirectorySync(); 1105 testDirectorySync();*/
1106 testFileError();
1079 }); 1107 });
1080 } 1108 }
1081 } 1109 }
1082 1110
1083 main() { 1111 main() {
1084 FileTest.testMain(); 1112 FileTest.testMain();
1085 } 1113 }
OLDNEW
« runtime/bin/utils.h ('K') | « runtime/bin/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698