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

Unified Diff: tests/standalone/src/io/FileErrorTest.dart

Issue 10065013: Support length operation without opening file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/src/io/FileErrorTest.dart
diff --git a/tests/standalone/src/io/FileErrorTest.dart b/tests/standalone/src/io/FileErrorTest.dart
index 388420583563aee8f76ee8c6c89ea0acb058bdbe..e4e9575bee5d2acc4d464f10c44d3a8ab8511bcc 100644
--- a/tests/standalone/src/io/FileErrorTest.dart
+++ b/tests/standalone/src/io/FileErrorTest.dart
@@ -14,10 +14,10 @@ Directory tempDir() {
}
-bool checkOpenNonExistentFileException(e) {
+bool checkNonExistentFileException(e, str) {
Expect.isTrue(e is FileIOException);
Expect.isTrue(e.osError != null);
- Expect.isTrue(e.toString().indexOf("Cannot open file") != -1);
+ Expect.isTrue(e.toString().indexOf(str) != -1);
Platform platform = new Platform();
if (platform.operatingSystem() == "linux") {
Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
@@ -34,6 +34,22 @@ bool checkOpenNonExistentFileException(e) {
return true;
}
+
+bool checkOpenNonExistentFileException(e) {
+ return checkNonExistentFileException(e, "Cannot open file");
+}
+
+
+bool checkDeleteNonExistentFileException(e) {
+ return checkNonExistentFileException(e, "Cannot delete file");
+}
+
+
+bool checkLengthNonExistentFileException(e) {
+ return checkNonExistentFileException(e, "Cannot retrieve length for file");
+}
+
+
void testOpenNonExistent() {
Directory temp = tempDir();
ReceivePort p = new ReceivePort();
@@ -54,25 +70,6 @@ void testOpenNonExistent() {
};
}
-bool checkDeleteNonExistentFileException(e) {
- Expect.isTrue(e is FileIOException);
- Expect.isTrue(e.osError != null);
- Expect.isTrue(e.toString().indexOf("Cannot delete file") != -1);
- Platform platform = new Platform();
- if (platform.operatingSystem() == "linux") {
- Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
- } else if (platform.operatingSystem() == "macos") {
- Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
- } else if (platform.operatingSystem() == "windows") {
- Expect.isTrue(
- e.toString().indexOf(
- "The system cannot find the file specified") != -1);
- }
- // File not not found has error code 2 on all supported platforms.
- Expect.equals(2, e.osError.errorCode);
-
- return true;
-}
void testDeleteNonExistent() {
Directory temp = tempDir();
@@ -94,6 +91,28 @@ void testDeleteNonExistent() {
};
}
+
+void testLengthNonExistent() {
+ Directory temp = tempDir();
+ ReceivePort p = new ReceivePort();
+ p.receive((x, y) {
+ p.close();
+ temp.deleteRecursivelySync();
+ });
+ var file = new File("${temp.path}/nonExistentFile");
+
+ // Non-existing file should throw exception.
+ Expect.throws(() => file.lengthSync(),
+ (e) => checkLengthNonExistentFileException(e));
+
+ file.length((len) => Expect.fail("Unreachable code"));
+ file.onError = (e) {
+ checkLengthNonExistentFileException(e);
+ p.toSendPort().send(null);
+ };
+}
+
+
bool checkCreateInNonExistentDirectoryException(e) {
Expect.isTrue(e is FileIOException);
Expect.isTrue(e.osError != null);
@@ -432,6 +451,7 @@ testOperateOnClosedFile() {
main() {
testOpenNonExistent();
testDeleteNonExistent();
+ testLengthNonExistent();
testCreateInNonExistentDirectory();
testFullPathOnNonExistentDirectory();
testDirectoryInNonExistentDirectory();

Powered by Google App Engine
This is Rietveld 408576698