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

Side by Side Diff: tests/standalone/io/directory_error_test.dart

Issue 10414046: Add support for directory renaming to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 8 years, 7 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/directory_win.cc ('k') | tests/standalone/io/directory_test.dart » ('j') | 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 error handling in directory I/O. 5 // Dart test program for testing error handling in directory I/O.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 Directory tempDir() { 10 Directory tempDir() {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void testListNonExistent(Directory temp, Function done) { 172 void testListNonExistent(Directory temp, Function done) {
173 Directory nonExistent = new Directory("${temp.path}/nonExistent"); 173 Directory nonExistent = new Directory("${temp.path}/nonExistent");
174 var lister = nonExistent.list(); 174 var lister = nonExistent.list();
175 lister.onError = (e) { 175 lister.onError = (e) {
176 checkListNonExistentFileException(e); 176 checkListNonExistentFileException(e);
177 done(); 177 done();
178 }; 178 };
179 } 179 }
180 180
181 181
182 void testRenameNonExistent(Directory temp, Function done) {
183 Directory nonExistent = new Directory("${temp.path}/nonExistent");
184 var newPath = "${temp.path}/nonExistent2";
185 Expect.throws(() => nonExistent.renameSync(newPath),
186 (e) => e is DirectoryIOException);
187 var renameDone = nonExistent.rename(newPath);
188 renameDone.then((ignore) => Expect.fail('rename non existent'));
189 renameDone.handleException((e) {
190 Expect.isTrue(e is DirectoryIOException);
191 done();
192 return true;
193 });
194 }
195
196
197 void testRenameFileAsDirectory(Directory temp, Function done) {
198 File f = new File("${temp.path}/file");
199 var newPath = "${temp.path}/file2";
200 f.createSync();
201 var d = new Directory(f.name);
202 Expect.throws(() => d.renameSync(newPath),
203 (e) => e is DirectoryIOException);
204 var renameDone = d.rename(newPath);
205 renameDone.then((ignore) => Expect.fail('rename file as directory'));
206 renameDone.handleException((e) {
207 Expect.isTrue(e is DirectoryIOException);
208 done();
209 return true;
210 });
211 }
212
213
214 testRenameOverwriteFile(Directory temp, Function done) {
215 var d = new Directory('');
216 var temp1 = d.createTempSync();
217 var fileName = '${temp.path}/x';
218 new File(fileName).createSync();
219 Expect.throws(() => temp1.renameSync(fileName),
220 (e) => e is DirectoryIOException);
221 var renameDone = temp1.rename(fileName);
222 renameDone.then((ignore) => Expect.fail('rename dir overwrite file'));
223 renameDone.handleException((e) {
224 Expect.isTrue(e is DirectoryIOException);
225 temp1.deleteRecursivelySync();
226 done();
227 return true;
228 });
229 }
230
231
182 void runTest(Function test) { 232 void runTest(Function test) {
183 // Create a temporary directory for the test. 233 // Create a temporary directory for the test.
184 var temp = new Directory('').createTempSync(); 234 var temp = new Directory('').createTempSync();
185 235
186 // Wait for the test to finish and delete the temporary directory. 236 // Wait for the test to finish and delete the temporary directory.
187 ReceivePort p = new ReceivePort(); 237 ReceivePort p = new ReceivePort();
188 p.receive((x,y) { 238 p.receive((x,y) {
189 p.close(); 239 p.close();
190 temp.deleteRecursivelySync(); 240 temp.deleteRecursivelySync();
191 }); 241 });
192 242
193 // Run the test. 243 // Run the test.
194 test(temp, () => p.toSendPort().send(null)); 244 test(temp, () => p.toSendPort().send(null));
195 } 245 }
196 246
197 247
198 main() { 248 main() {
199 runTest(testCreateInNonExistent); 249 runTest(testCreateInNonExistent);
200 runTest(testCreateTempInNonExistent); 250 runTest(testCreateTempInNonExistent);
201 runTest(testDeleteNonExistent); 251 runTest(testDeleteNonExistent);
202 runTest(testDeleteRecursivelyNonExistent); 252 runTest(testDeleteRecursivelyNonExistent);
203 runTest(testListNonExistent); 253 runTest(testListNonExistent);
254 runTest(testRenameNonExistent);
255 runTest(testRenameFileAsDirectory);
256 runTest(testRenameOverwriteFile);
204 } 257 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_win.cc ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698