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

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

Issue 9316066: Implement recursive directory deletion. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 10 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/directory_win.cc ('K') | « runtime/bin/file_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) 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 // Directory listing test. 5 // Directory listing test.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 class DirectoryTest { 9 class DirectoryTest {
10 static void testListing() { 10 static void testListing() {
11 bool listedDir = false; 11 bool listedDir = false;
(...skipping 16 matching lines...) Expand all
28 directory.fileHandler = (f) { 28 directory.fileHandler = (f) {
29 listedFile = true; 29 listedFile = true;
30 Expect.isTrue(f.contains('subdir')); 30 Expect.isTrue(f.contains('subdir'));
31 Expect.isTrue(f.contains('file.txt')); 31 Expect.isTrue(f.contains('file.txt'));
32 }; 32 };
33 33
34 directory.doneHandler = (completed) { 34 directory.doneHandler = (completed) {
35 Expect.isTrue(completed, "directory listing did not complete"); 35 Expect.isTrue(completed, "directory listing did not complete");
36 Expect.isTrue(listedDir, "directory not found"); 36 Expect.isTrue(listedDir, "directory not found");
37 Expect.isTrue(listedFile, "file not found"); 37 Expect.isTrue(listedFile, "file not found");
38 f.deleteHandler = () { 38 directory.delete(recursive: true);
39 // TODO(ager): use async directory deletion API when available. 39 directory.deleteHandler = () {
40 subDirectory.deleteSync(); 40 f.exists();
41 directory.deleteSync(); 41 f.existsHandler = (exists) => Expect.isFalse(exists);
42 directory.exists();
43 directory.existsHandler = (exists) => Expect.isFalse(exists);
44 subDirectory.exists();
45 subDirectory.existsHandler = (exists) => Expect.isFalse(exists);
42 }; 46 };
43 f.delete();
44 }; 47 };
45 48
46 directory.errorHandler = (error) { 49 directory.errorHandler = (error) {
47 Expect.fail("error listing directory: $error"); 50 Expect.fail("error listing directory: $error");
48 }; 51 };
49 52
50 directory.list(recursive: true); 53 directory.list(recursive: true);
51 54
52 // Listing is asynchronous, so nothing should be listed at this 55 // Listing is asynchronous, so nothing should be listed at this
53 // point. 56 // point.
54 Expect.isFalse(listedDir); 57 Expect.isFalse(listedDir);
55 Expect.isFalse(listedFile); 58 Expect.isFalse(listedFile);
56 } 59 }
57 60
61 static void testListNonExistent() {
62 Directory d = new Directory("");
63 d.errorHandler = (error) {
64 Expect.fail("Directory error: $error");
65 };
66 d.createTemp();
67 d.createTempHandler = () {
68 d.delete();
69 d.deleteHandler = () {
70 // Test that listing a non-existing directory fails.
71 d.errorHandler = (error) {
72 // TODO(ager): When directory errors have been changed to
73 // post back exceptions, check that we get the right exception
74 // type here.
75 };
76 d.fileHandler = (file) {
77 Expect.fail("Listing of non-existing directory should fail");
78 };
79 d.fileHandler = (dir) {
80 Expect.fail("Listing of non-existing directory should fail");
81 };
82 d.doneHandler = (done) {
83 Expect.isFalse(done);
84 };
85 d.list();
86 d.list(recursive: true);
87 };
88 };
89 }
90
91 static void testListTooLongName() {
92 Directory d = new Directory("");
93 d.errorHandler = (error) {
94 Expect.fail("Directory error: $error");
95 };
96 d.createTemp();
97 d.createTempHandler = () {
98 var subDirName = 'subdir';
99 var subDir = new Directory("${d.path}/$subDirName");
100 subDir.errorHandler = (error) {
101 Expect.fail("Directory error: $error");
102 };
103 subDir.create();
104 subDir.createHandler = () {
105 // Construct a long string of the form
106 // 'tempdir/subdir/../subdir/../subdir'.
107 var buffer = new StringBuffer();
108 buffer.add(subDir.path);
109 for (var i = 0; i < 1000; i++) {
110 buffer.add("/../${subDirName}");
111 }
112 var long = new Directory("${buffer.toString()}");
113 var errors = 0;
114 long.errorHandler = (error) {
115 // TODO(ager): When directory errors have been changed to
116 // post back exceptions, check that we get the right exception
117 // type here.
118 if (++errors == 2) {
119 d.delete(recursive: true);
120 }
121 };
122 long.fileHandler = (file) {
123 Expect.fail("Listing of non-existing directory should fail");
124 };
125 long.fileHandler = (dir) {
126 Expect.fail("Listing of non-existing directory should fail");
127 };
128 long.doneHandler = (done) {
129 Expect.isFalse(done);
130 };
131 long.list();
132 long.list(recursive: true);
133 };
134 };
135 }
136
137 static void testDeleteNonExistent() {
138 Directory d = new Directory("");
139 d.errorHandler = (error) {
140 Expect.fail("Directory error: $error");
141 };
142 d.createTemp();
143 d.createTempHandler = () {
144 d.delete();
145 d.deleteHandler = () {
146 // Test that deleting a non-existing directory fails.
147 d.errorHandler = (error) {
148 // TODO(ager): When directory errors have been changed to
149 // post back exceptions, check that we get the right exception
150 // type here.
151 };
152 d.deleteHandler = () {
153 Expect.fail("Deletion of non-existing directory should fail");
154 };
155 d.delete();
156 d.delete(recursive: true);
157 };
158 };
159 }
160
161 static void testDeleteTooLongName() {
162 Directory d = new Directory("");
163 d.errorHandler = (error) {
164 Expect.fail("Directory error: $error");
165 };
166 d.createTemp();
167 d.createTempHandler = () {
168 var subDirName = 'subdir';
169 var subDir = new Directory("${d.path}/$subDirName");
170 subDir.errorHandler = (error) {
171 Expect.fail("Directory error: $error");
172 };
173 subDir.create();
174 subDir.createHandler = () {
175 // Construct a long string of the form
176 // 'tempdir/subdir/../subdir/../subdir'.
177 var buffer = new StringBuffer();
178 buffer.add(subDir.path);
179 for (var i = 0; i < 1000; i++) {
180 buffer.add("/../${subDirName}");
181 }
182 var long = new Directory("${buffer.toString()}");
183 var errors = 0;
184 long.errorHandler = (error) {
185 // TODO(ager): When directory errors have been changed to
186 // post back exceptions, check that we get the right exception
187 // type here.
188 if (++errors == 2) {
189 d.delete(recursive: true);
190 }
191 };
192 long.deleteHandler = () {
193 Expect.fail("Deletion of a directory with a long name should fail");
194 };
195 long.delete();
196 long.delete(recursive:true);
197 };
198 };
199 }
200
201 static void testDeleteNonExistentSync() {
202 Directory d = new Directory("");
203 d.createTempSync();
204 d.deleteSync();
205 Expect.throws(d.deleteSync);
206 Expect.throws(() => d.deleteSync(recursive: true));
207 }
208
209 static void testDeleteTooLongNameSync() {
210 Directory d = new Directory("");
211 d.createTempSync();
212 var subDirName = 'subdir';
213 var subDir = new Directory("${d.path}/$subDirName");
214 subDir.createSync();
215 // Construct a long string of the form
216 // 'tempdir/subdir/../subdir/../subdir'.
217 var buffer = new StringBuffer();
218 buffer.add(subDir.path);
219 for (var i = 0; i < 1000; i++) {
220 buffer.add("/../${subDirName}");
221 }
222 var long = new Directory("${buffer.toString()}");
223 Expect.throws(long.deleteSync);
224 Expect.throws(() => long.deleteSync(recursive:true));
225 }
226
58 static void testExistsCreateDelete() { 227 static void testExistsCreateDelete() {
59 Directory d = new Directory(""); 228 Directory d = new Directory("");
60 d.createTempHandler = () { 229 d.createTempHandler = () {
61 d.existsHandler = (bool exists) { 230 d.existsHandler = (bool exists) {
62 Expect.isTrue(exists); 231 Expect.isTrue(exists);
63 Directory created = new Directory("${d.path}/subdir"); 232 Directory created = new Directory("${d.path}/subdir");
64 created.createHandler = () { 233 created.createHandler = () {
65 created.existsHandler = (bool exists) { 234 created.existsHandler = (bool exists) {
66 Expect.isTrue(exists); 235 Expect.isTrue(exists);
67 created.deleteHandler = () { 236 created.deleteHandler = () {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 }; 369 };
201 file.exists(); 370 file.exists();
202 }; 371 };
203 file.create(); 372 file.create();
204 }; 373 };
205 tempDirectory.createTemp(); 374 tempDirectory.createTemp();
206 } 375 }
207 376
208 static void testMain() { 377 static void testMain() {
209 testListing(); 378 testListing();
379 testListNonExistent();
380 testListTooLongName();
381 testDeleteNonExistent();
382 testDeleteTooLongName();
383 testDeleteNonExistentSync();
384 testDeleteTooLongNameSync();
210 testExistsCreateDelete(); 385 testExistsCreateDelete();
211 testExistsCreateDeleteSync(); 386 testExistsCreateDeleteSync();
212 testCreateTemp(); 387 testCreateTemp();
213 testCreateDeleteTemp(); 388 testCreateDeleteTemp();
214 } 389 }
215 } 390 }
216 391
217 392
218 class NestedTempDirectoryTest { 393 class NestedTempDirectoryTest {
219 List<Directory> createdDirectories; 394 List<Directory> createdDirectories;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 dir.createTemp(); 474 dir.createTemp();
300 } 475 }
301 476
302 477
303 main() { 478 main() {
304 DirectoryTest.testMain(); 479 DirectoryTest.testMain();
305 NestedTempDirectoryTest.testMain(); 480 NestedTempDirectoryTest.testMain();
306 testCreateTempErrorSync(); 481 testCreateTempErrorSync();
307 testCreateTempError(); 482 testCreateTempError();
308 } 483 }
OLDNEW
« runtime/bin/directory_win.cc ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698