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

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

Issue 9773018: Add error handling to directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | tests/standalone/src/io/DirectoryInvalidArgumentsTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Dart test program for testing error handling in directory I/O.
6
7 #import("dart:io");
8 #import("dart:isolate");
9
10 Directory tempDir() {
11 var d = new Directory('');
12 d.createTempSync();
13 return d;
14 }
15
16
17 bool checkCreateInNonExistentFileException(e) {
18 Expect.isTrue(e is DirectoryIOException);
19 Expect.isTrue(e.osError != null);
20 Expect.isTrue(e.toString().indexOf("Creation failed") != -1);
21 Platform platform = new Platform();
22 if (platform.operatingSystem() == "linux") {
23 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
24 Expect.equals(2, e.osError.errorCode);
25 } else if (platform.operatingSystem() == "macos") {
26 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
27 Expect.equals(2, e.osError.errorCode);
28 } else if (platform.operatingSystem() == "windows") {
29 Expect.isTrue(
30 e.toString().indexOf(
31 "The system cannot find the path specified") != -1);
32 Expect.equals(3, e.osError.errorCode);
33 }
34
35 return true;
36 }
37
38
39 void testCreateInNonExistent(Directory temp, Function done) {
40 Directory inNonExistent = new Directory("${temp.path}/nonExistent/xxx");
41 Expect.throws(() => inNonExistent.createSync(),
42 (e) => checkCreateInNonExistentFileException(e));
43
44 inNonExistent.create(() => Expect.fail("Unreachable code"));
45 inNonExistent.onError = (e) {
46 checkCreateInNonExistentFileException(e);
47 done();
48 };
49 }
50
51
52 bool checkCreateTempInNonExistentFileException(e) {
53 Expect.isTrue(e is DirectoryIOException);
54 Expect.isTrue(e.osError != null);
55 Expect.isTrue(e.toString().indexOf(
56 "Creation of temporary directory failed") != -1);
57 Platform platform = new Platform();
58 if (platform.operatingSystem() == "linux") {
59 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
60 Expect.equals(2, e.osError.errorCode);
61 } else if (platform.operatingSystem() == "macos") {
62 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
63 Expect.equals(2, e.osError.errorCode);
64 } else if (platform.operatingSystem() == "windows") {
65 Expect.isTrue(
66 e.toString().indexOf(
67 "The system cannot find the path specified") != -1);
68 Expect.equals(3, e.osError.errorCode);
69 }
70
71 return true;
72 }
73
74
75 void testCreateTempInNonExistent(Directory temp, Function done) {
76 Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx");
77 Expect.throws(() => nonExistent.createTempSync(),
78 (e) => checkCreateTempInNonExistentFileException(e));
79
80 nonExistent.createTemp(() => Expect.fail("Unreachable code"));
81 nonExistent.onError = (e) {
82 checkCreateTempInNonExistentFileException(e);
83 done();
84 };
85 }
86
87
88 bool checkDeleteNonExistentFileException(e) {
89 Expect.isTrue(e is DirectoryIOException);
90 Expect.isTrue(e.osError != null);
91 Expect.isTrue(e.toString().indexOf("Deletion failed") != -1);
92 Platform platform = new Platform();
93 if (platform.operatingSystem() == "linux") {
94 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
95 } else if (platform.operatingSystem() == "macos") {
96 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
97 } else if (platform.operatingSystem() == "windows") {
98 Expect.isTrue(
99 e.toString().indexOf(
100 "The system cannot find the file specified") != -1);
101 }
102 // File not not found has error code 2 on all supported platforms.
103 Expect.equals(2, e.osError.errorCode);
104
105 return true;
106 }
107
108
109 void testDeleteNonExistent(Directory temp, Function done) {
110 Directory nonExistent = new Directory("${temp.path}/nonExistent");
111 Expect.throws(() => nonExistent.deleteSync(),
112 (e) => checkDeleteNonExistentFileException(e));
113
114 nonExistent.delete(() => Expect.fail("Unreachable code"));
115 nonExistent.onError = (e) {
116 checkDeleteNonExistentFileException(e);
117 done();
118 };
119 }
120
121
122 bool checkDeleteRecursivelyNonExistentFileException(e) {
123 Expect.isTrue(e is DirectoryIOException);
124 Expect.isTrue(e.osError != null);
125 Expect.isTrue(e.toString().indexOf("Deletion failed") != -1);
126 Platform platform = new Platform();
127 if (platform.operatingSystem() == "linux") {
128 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
129 Expect.equals(2, e.osError.errorCode);
130 } else if (platform.operatingSystem() == "macos") {
131 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
132 Expect.equals(2, e.osError.errorCode);
133 } else if (platform.operatingSystem() == "windows") {
134 Expect.isTrue(
135 e.toString().indexOf(
136 "The system cannot find the path specified") != -1);
137 Expect.equals(3, e.osError.errorCode);
138 }
139
140 return true;
141 }
142
143
144 void testDeleteRecursivelyNonExistent(Directory temp, Function done) {
145 Directory nonExistent = new Directory("${temp.path}/nonExistent");
146 Expect.throws(() => nonExistent.deleteRecursivelySync(),
147 (e) => checkDeleteRecursivelyNonExistentFileException(e));
148
149 nonExistent.deleteRecursively(() => Expect.fail("Unreachable code"));
150 nonExistent.onError = (e) {
151 checkDeleteRecursivelyNonExistentFileException(e);
152 done();
153 };
154 }
155
156
157 bool checkListNonExistentFileException(e) {
158 Expect.isTrue(e is DirectoryIOException);
159 Expect.isTrue(e.osError != null);
160 Expect.isTrue(e.toString().indexOf("Directory listing failed") != -1);
161 Platform platform = new Platform();
162 if (platform.operatingSystem() == "linux") {
163 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
164 Expect.equals(2, e.osError.errorCode);
165 } else if (platform.operatingSystem() == "macos") {
166 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1);
167 Expect.equals(2, e.osError.errorCode);
168 } else if (platform.operatingSystem() == "windows") {
169 Expect.isTrue(
170 e.toString().indexOf(
171 "The system cannot find the path specified") != -1);
172 Expect.equals(3, e.osError.errorCode);
173 }
174
175 return true;
176 }
177
178
179 void testListNonExistent(Directory temp, Function done) {
180 Directory nonExistent = new Directory("${temp.path}/nonExistent");
181 nonExistent.list();
182 nonExistent.onError = (e) {
183 checkListNonExistentFileException(e);
184 done();
185 };
186 }
187
188
189 void runTest(Function test) {
190 // Create a temporary directory for the test.
191 var temp = new Directory('');
192 temp.createTempSync();
193
194 // Wait for the test to finish and delete the temporary directory.
195 ReceivePort p = new ReceivePort();
196 p.receive((x,y) {
197 p.close();
198 temp.deleteRecursivelySync();
199 });
200
201 // Run the test.
202 test(temp, () => p.toSendPort().send(null));
203 }
204
205
206 main() {
207 runTest(testCreateInNonExistent);
208 runTest(testCreateTempInNonExistent);
209 runTest(testDeleteNonExistent);
210 runTest(testDeleteRecursivelyNonExistent);
211 runTest(testListNonExistent);
212 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | tests/standalone/src/io/DirectoryInvalidArgumentsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698