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

Side by Side Diff: tests/standalone/src/DirectoryTest.dart

Issue 8965036: Add asynchronous versions of the methods on Directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years 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/directory_impl.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Directory listing test. 5 // Directory listing test.
6 6
7 class DirectoryTest { 7 class DirectoryTest {
8 static void testListing() { 8 static void testListing() {
9 bool listedDir = false; 9 bool listedDir = false;
10 bool listedFile = false; 10 bool listedFile = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 directory.list(recursive: true); 48 directory.list(recursive: true);
49 49
50 // Listing is asynchronous, so nothing should be listed at this 50 // Listing is asynchronous, so nothing should be listed at this
51 // point. 51 // point.
52 Expect.isFalse(listedDir); 52 Expect.isFalse(listedDir);
53 Expect.isFalse(listedFile); 53 Expect.isFalse(listedFile);
54 } 54 }
55 55
56 static void testExistsCreateDelete() { 56 static void testExistsCreateDelete() {
57 Directory d = new Directory("/tmp/dart_temp_dir_"); 57 Directory d = new Directory("");
58 d.createTempHandler = () {
59 d.existsHandler = (bool exists) {
60 Expect.isTrue(exists);
61 Directory created = new Directory("${d.path}/subdir");
62 created.createHandler = () {
63 created.existsHandler = (bool exists) {
64 Expect.isTrue(exists);
65 created.deleteHandler = () {
66 created.existsHandler = (bool exists) {
67 Expect.isFalse(exists);
68 d.deleteHandler = () {
69 d.existsHandler = (bool exists) {
70 Expect.isFalse(exists);
71 };
72 d.exists();
73 };
74 d.delete();
75 };
76 created.exists();
77 };
78 created.delete();
79 };
80 created.exists();
81 };
82 created.create();
83 };
84 d.exists();
85 };
86 d.createTemp();
87 }
88
89 static void testExistsCreateDeleteSync() {
90 Directory d = new Directory("");
58 d.createTempSync(); 91 d.createTempSync();
59 Expect.isTrue(d.existsSync()); 92 Expect.isTrue(d.existsSync());
60 Directory created = new Directory("${d.path}/subdir"); 93 Directory created = new Directory("${d.path}/subdir");
61 created.createSync(); 94 created.createSync();
62 Expect.isTrue(created.existsSync()); 95 Expect.isTrue(created.existsSync());
63 created.deleteSync(); 96 created.deleteSync();
64 Expect.isFalse(created.existsSync()); 97 Expect.isFalse(created.existsSync());
65 d.deleteSync(); 98 d.deleteSync();
66 Expect.isFalse(d.existsSync()); 99 Expect.isFalse(d.existsSync());
100 }
67 101
102 static void testCreateTemp() {
68 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); 103 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_");
69 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); 104 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_");
70 bool stage1aDone = false; 105 bool stage1aDone = false;
71 bool stage1bDone = false; 106 bool stage1bDone = false;
72 bool emptyTemplateTestRunning = false; 107 bool emptyTemplateTestRunning = false;
73 108
74 // Stages 0 through 2 run twice, the second time with an empty path. 109 // Stages 0 through 2 run twice, the second time with an empty path.
75 Function stage0; 110 Function stage0;
76 Function stage1a; 111 Function stage1a;
77 Function stage1b; 112 Function stage1b;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 }; 165 };
131 166
132 if (new Directory("/tmp").existsSync()) { 167 if (new Directory("/tmp").existsSync()) {
133 stage0(); 168 stage0();
134 } else { 169 } else {
135 emptyTemplateTestRunning = true; 170 emptyTemplateTestRunning = true;
136 stage3(); 171 stage3();
137 } 172 }
138 } 173 }
139 174
140 static void testCreateTemp() { 175 static void testCreateDeleteTemp() {
141 Directory tempDirectory = new Directory(""); 176 Directory tempDirectory = new Directory("");
142 tempDirectory.createTempHandler = () { 177 tempDirectory.createTempHandler = () {
143 String filename = tempDirectory.path + 178 String filename = tempDirectory.path +
144 new Platform().pathSeparator() + "dart_testfile"; 179 new Platform().pathSeparator() + "dart_testfile";
145 File file = new File(filename); 180 File file = new File(filename);
146 Expect.isFalse(file.existsSync()); 181 Expect.isFalse(file.existsSync());
147 file.errorHandler = (error) { 182 file.errorHandler = (error) {
148 Expect.fail("testCreateTemp file.errorHandler called: $error"); 183 Expect.fail("testCreateTemp file.errorHandler called: $error");
149 }; 184 };
150 file.createHandler = () { 185 file.createHandler = () {
151 file.openHandler = (RandomAccessFile openedFile) { 186 file.existsHandler = (bool exists) {
152 openedFile.writeList([65, 66, 67, 13], 0, 4); 187 Expect.isTrue(exists);
153 openedFile.noPendingWriteHandler = () { 188 // Try to delete the directory containing the file - should throw.
154 openedFile.length(); 189 Expect.throws(tempDirectory.deleteSync);
155 }; 190 Expect.isTrue(tempDirectory.existsSync());
156 openedFile.lengthHandler = (int length) {
157 Expect.equals(4, length);
158 openedFile.close();
159 };
160 openedFile.closeHandler = () {
161 file.exists();
162 };
163 file.existsHandler = (bool exists) {
164 Expect.isTrue(exists);
165 // Try to delete the directory containing the file - should throw.
166 bool threw_exception = false;
167 try {
168 tempDirectory.deleteSync();
169 } catch (var e) {
170 Expect.isTrue(tempDirectory.existsSync());
171 threw_exception = true;
172 }
173 Expect.isTrue(threw_exception);
174 Expect.isTrue(tempDirectory.existsSync());
175 191
176 // Delete the file, and then delete the directory. 192 // Delete the file, and then delete the directory.
177 file.delete();
178 };
179 file.deleteHandler = () { 193 file.deleteHandler = () {
180 tempDirectory.deleteSync(); 194 tempDirectory.deleteSync();
181 Expect.isFalse(tempDirectory.existsSync()); 195 Expect.isFalse(tempDirectory.existsSync());
182 }; 196 };
197 file.delete();
183 }; 198 };
184 file.open(writable: true); 199 file.exists();
185 }; 200 };
186 file.create(); 201 file.create();
187 }; 202 };
188 tempDirectory.createTemp(); 203 tempDirectory.createTemp();
189 } 204 }
190 205
191 static void testNestedTempDirectory() {
192 var test = new NestedTempDirectoryTest();
193 }
194
195
196 static void testMain() { 206 static void testMain() {
197 testListing(); 207 testListing();
198 testExistsCreateDelete(); 208 testExistsCreateDelete();
209 testExistsCreateDeleteSync();
199 testCreateTemp(); 210 testCreateTemp();
200 testNestedTempDirectory(); 211 testCreateDeleteTemp();
201 } 212 }
202 } 213 }
203 214
204 215
205 class NestedTempDirectoryTest { 216 class NestedTempDirectoryTest {
206 List<Directory> createdDirectories; 217 List<Directory> createdDirectories;
207 Directory current; 218 Directory current;
208 219
209 NestedTempDirectoryTest(): createdDirectories = new List<Directory>(); 220 NestedTempDirectoryTest.run()
221 : createdDirectories = new List<Directory>(),
222 current = new Directory("") {
223 current.createTempHandler = createPhaseCallback;
224 current.errorHandler = errorCallback;
225 current.createTemp();
226 }
210 227
211 void errorCallback(error) { 228 void errorCallback(error) {
212 Expect.fail("Error callback called in NestedTempDirectoryTest: $error"); 229 Expect.fail("Error callback called in NestedTempDirectoryTest: $error");
213 } 230 }
214 231
215 void createPhaseCallback() { 232 void createPhaseCallback() {
216 createdDirectories.add(current); 233 createdDirectories.add(current);
217 int nestingDepth = 6; 234 int nestingDepth = 6;
218 var os = new Platform().operatingSystem(); 235 var os = new Platform().operatingSystem();
219 if (os == "windows") nestingDepth = 2; 236 if (os == "windows") nestingDepth = 2;
220 if (createdDirectories.length < nestingDepth) { 237 if (createdDirectories.length < nestingDepth) {
221 current = new Directory( 238 current = new Directory(
222 current.path + "/nested_temp_dir_${createdDirectories.length}_"); 239 current.path + "/nested_temp_dir_${createdDirectories.length}_");
223 current.errorHandler = errorCallback; 240 current.errorHandler = errorCallback;
224 current.createTempHandler = createPhaseCallback; 241 current.createTempHandler = createPhaseCallback;
225 current.createTemp(); 242 current.createTemp();
226 } else { 243 } else {
227 deletePhaseCallback(); 244 deletePhaseCallback();
228 } 245 }
229 } 246 }
230 247
231 void deletePhaseCallback() { 248 void deletePhaseCallback() {
232 if (!createdDirectories.isEmpty()) { 249 if (!createdDirectories.isEmpty()) {
233 current = createdDirectories.removeLast(); 250 current = createdDirectories.removeLast();
234 current.deleteSync(); 251 current.deleteSync();
235 deletePhaseCallback(); 252 deletePhaseCallback();
236 } 253 }
237 } 254 }
238 255
239 void startTest() {
240 current = new Directory("");
241 current.createTempHandler = createPhaseCallback;
242 current.errorHandler = errorCallback;
243 current.createTemp();
244 }
245
246 static void testMain() { 256 static void testMain() {
247 new NestedTempDirectoryTest().startTest(); 257 new NestedTempDirectoryTest.run();
248 new NestedTempDirectoryTest().startTest(); 258 new NestedTempDirectoryTest.run();
249 } 259 }
250 } 260 }
251 261
252 262
253 String illegalTempDirectoryLocation() { 263 String illegalTempDirectoryLocation() {
254 // Determine a platform specific illegal location for a temporary directory. 264 // Determine a platform specific illegal location for a temporary directory.
255 var os = new Platform().operatingSystem(); 265 var os = new Platform().operatingSystem();
256 if (os == "linux" || os == "macos") { 266 if (os == "linux" || os == "macos") {
257 return "/dev/zero/"; 267 return "/dev/zero/";
258 } 268 }
(...skipping 28 matching lines...) Expand all
287 dir.createTemp(); 297 dir.createTemp();
288 } 298 }
289 299
290 300
291 main() { 301 main() {
292 DirectoryTest.testMain(); 302 DirectoryTest.testMain();
293 NestedTempDirectoryTest.testMain(); 303 NestedTempDirectoryTest.testMain();
294 testCreateTempErrorSync(); 304 testCreateTempErrorSync();
295 testCreateTempError(); 305 testCreateTempError();
296 } 306 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698