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

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: 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/io.dart ('K') | « runtime/bin/io.dart ('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 Expect.isTrue(e is FileIOException);
516 Expect.isTrue(e.osError != null);
517 Expect.isTrue(e.toString().indexOf("Cannot open file") != -1);
518 if (new Platform().operatingSystem() == "macos") {
519 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
520 Expect.equals(2, e.osError.errorCode);
521 }
522 }
523
524 var tempDir = tempDirectory.path;
525 var file = new File("${tempDir}/nonExistentFile");
526
527 // Non-existing file should throw exception.
528 try {
529 file.openSync();
530 } catch (Exception e) {
531 checkOpenNonExistentFileException(e);
532 }
533
534 file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code"));
535 file.onError = (e) => checkOpenNonExistentFileException(e);
536 }
537
538
513 // Test for file length functionality. 539 // Test for file length functionality.
514 static void testLength() { 540 static void testLength() {
515 String filename = getFilename("tests/vm/data/fixed_length_file"); 541 String filename = getFilename("tests/vm/data/fixed_length_file");
516 RandomAccessFile input = (new File(filename)).openSync(); 542 RandomAccessFile input = (new File(filename)).openSync();
517 input.onError = (s) { 543 input.onError = (s) {
518 Expect.fail("No errors expected"); 544 Expect.fail("No errors expected");
519 }; 545 };
520 input.length((length) { 546 input.length((length) {
521 Expect.equals(42, length); 547 Expect.equals(42, length);
522 input.close(() => null); 548 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 1059 // Helper method to be able to run the test from the runtime
1034 // directory, or the top directory. 1060 // directory, or the top directory.
1035 static String getFilename(String path) => 1061 static String getFilename(String path) =>
1036 new File(path).existsSync() ? path : 'runtime/' + path; 1062 new File(path).existsSync() ? path : 'runtime/' + path;
1037 1063
1038 static String getDataFilename(String path) => 1064 static String getDataFilename(String path) =>
1039 new File(path).existsSync() ? path : '../' + path; 1065 new File(path).existsSync() ? path : '../' + path;
1040 1066
1041 // Main test entrypoint. 1067 // Main test entrypoint.
1042 static testMain() { 1068 static testMain() {
1043 testRead(); 1069 /*testRead();
1044 testReadSync(); 1070 testReadSync();
1045 testReadStream(); 1071 testReadStream();
1046 testLength(); 1072 testLength();
1047 testLengthSync(); 1073 testLengthSync();
1048 testPosition(); 1074 testPosition();
1049 testPositionSync(); 1075 testPositionSync();
1050 testMixedSyncAndAsync(); 1076 testMixedSyncAndAsync();
1051 testOpenDirectoryAsFile(); 1077 testOpenDirectoryAsFile();
1052 testOpenDirectoryAsFileSync(); 1078 testOpenDirectoryAsFileSync();
1053 testReadAsBytes(); 1079 testReadAsBytes();
1054 testReadAsBytesSync(); 1080 testReadAsBytesSync();
1055 testReadAsText(); 1081 testReadAsText();
1056 testReadAsTextSync(); 1082 testReadAsTextSync();
1057 testReadAsLines(); 1083 testReadAsLines();
1058 testReadAsLinesSync(); 1084 testReadAsLinesSync();
1059 testReadAsErrors(); 1085 testReadAsErrors();
1060 1086 */
1061 createTempDirectory(() { 1087 createTempDirectory(() {
1062 testReadWrite(); 1088 /* testReadWrite();
1063 testReadWriteSync(); 1089 testReadWriteSync();
1064 testReadWriteStream(); 1090 testReadWriteStream();
1065 testReadEmptyFileSync(); 1091 testReadEmptyFileSync();
1066 testReadEmptyFile(); 1092 testReadEmptyFile();
1067 testTruncate(); 1093 testTruncate();
1068 testTruncateSync(); 1094 testTruncateSync();
1069 testCloseException(); 1095 testCloseException();
1070 testCloseExceptionStream(); 1096 testCloseExceptionStream();
1071 testBufferOutOfBoundsException(); 1097 testBufferOutOfBoundsException();
1072 testAppend(); 1098 testAppend();
1073 testAppendSync(); 1099 testAppendSync();
1074 testWriteAppend(); 1100 testWriteAppend();
1075 testOutputStreamWriteAppend(); 1101 testOutputStreamWriteAppend();
1076 testWriteVariousLists(); 1102 testWriteVariousLists();
1077 testDirectory(); 1103 testDirectory();
1078 testDirectorySync(); 1104 testDirectorySync();*/
1105 testFileError();
1079 }); 1106 });
1080 } 1107 }
1081 } 1108 }
1082 1109
1083 main() { 1110 main() {
1084 FileTest.testMain(); 1111 FileTest.testMain();
1085 } 1112 }
OLDNEW
« runtime/bin/io.dart ('K') | « runtime/bin/io.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698