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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
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 // Directory listing test. 5 // Directory listing test.
6 6
7 import "dart:io"; 7 import "dart:io";
8 import "dart:isolate"; 8 import "dart:isolate";
9 9
10 class DirectoryTest { 10 class DirectoryTest {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 var long = new Directory("${buffer.toString()}"); 136 var long = new Directory("${buffer.toString()}");
137 setupListHandlers(long.list()); 137 setupListHandlers(long.list());
138 setupListHandlers(long.list(recursive: true)); 138 setupListHandlers(long.list(recursive: true));
139 }); 139 });
140 }); 140 });
141 } 141 }
142 142
143 static void testDeleteNonExistent() { 143 static void testDeleteNonExistent() {
144 // Test that deleting a non-existing directory fails. 144 // Test that deleting a non-existing directory fails.
145 setupFutureHandlers(future) { 145 setupFutureHandlers(future) {
146 future.handleException((e) {
147 Expect.isTrue(e is DirectoryIOException);
148 return true;
149 });
150 future.then((ignore) { 146 future.then((ignore) {
151 Expect.fail("Deletion of non-existing directory should fail"); 147 Expect.fail("Deletion of non-existing directory should fail");
148 }).catchError((e) {
149 Expect.isTrue(e.error is DirectoryIOException);
152 }); 150 });
153 } 151 }
154 152
155 new Directory("").createTemp().then((d) { 153 new Directory("").createTemp().then((d) {
156 d.delete().then((ignore) { 154 d.delete().then((ignore) {
157 setupFutureHandlers(d.delete()); 155 setupFutureHandlers(d.delete());
158 setupFutureHandlers(d.delete(recursive: true)); 156 setupFutureHandlers(d.delete(recursive: true));
159 }); 157 });
160 }); 158 });
161 } 159 }
162 160
163 static void testDeleteTooLongName() { 161 static void testDeleteTooLongName() {
164 var port = new ReceivePort(); 162 var port = new ReceivePort();
165 new Directory("").createTemp().then((d) { 163 new Directory("").createTemp().then((d) {
166 var subDirName = 'subdir'; 164 var subDirName = 'subdir';
167 var subDir = new Directory("${d.path}/$subDirName"); 165 var subDir = new Directory("${d.path}/$subDirName");
168 subDir.create().then((ignore) { 166 subDir.create().then((ignore) {
169 // Construct a long string of the form 167 // Construct a long string of the form
170 // 'tempdir/subdir/../subdir/../subdir'. 168 // 'tempdir/subdir/../subdir/../subdir'.
171 var buffer = new StringBuffer(); 169 var buffer = new StringBuffer();
172 buffer.add(subDir.path); 170 buffer.add(subDir.path);
173 for (var i = 0; i < 1000; i++) { 171 for (var i = 0; i < 1000; i++) {
174 buffer.add("/../${subDirName}"); 172 buffer.add("/../${subDirName}");
175 } 173 }
176 var long = new Directory("${buffer.toString()}"); 174 var long = new Directory("${buffer.toString()}");
177 var errors = 0; 175 var errors = 0;
178 onError(e) { 176 onError(e) {
179 Expect.isTrue(e is DirectoryIOException); 177 Expect.isTrue(e.error is DirectoryIOException);
180 if (++errors == 2) { 178 if (++errors == 2) {
181 d.delete(recursive: true).then((ignore) => port.close()); 179 d.delete(recursive: true).then((ignore) => port.close());
182 } 180 }
183 return true; 181 return true;
184 } 182 }
185 long.delete().handleException(onError); 183 long.delete().catchError(onError);
186 long.delete(recursive: true).handleException(onError); 184 long.delete(recursive: true).catchError(onError);
187 }); 185 });
188 }); 186 });
189 } 187 }
190 188
191 static void testDeleteNonExistentSync() { 189 static void testDeleteNonExistentSync() {
192 Directory d = new Directory("").createTempSync(); 190 Directory d = new Directory("").createTempSync();
193 d.deleteSync(); 191 d.deleteSync();
194 Expect.throws(d.deleteSync); 192 Expect.throws(d.deleteSync);
195 Expect.throws(() => d.deleteSync(recursive: true)); 193 Expect.throws(() => d.deleteSync(recursive: true));
196 } 194 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 473 }
476 } 474 }
477 475
478 476
479 testCreateTempError() { 477 testCreateTempError() {
480 var location = illegalTempDirectoryLocation(); 478 var location = illegalTempDirectoryLocation();
481 if (location == null) return; 479 if (location == null) return;
482 480
483 var port = new ReceivePort(); 481 var port = new ReceivePort();
484 var future = new Directory(location).createTemp(); 482 var future = new Directory(location).createTemp();
485 future.handleException((e) => port.close()); 483 future.catchError((e) => port.close());
486 } 484 }
487 485
488 486
489 testCreateExistingSync() { 487 testCreateExistingSync() {
490 // Test that creating an existing directory succeeds. 488 // Test that creating an existing directory succeeds.
491 var d = new Directory(''); 489 var d = new Directory('');
492 var temp = d.createTempSync(); 490 var temp = d.createTempSync();
493 var subDir = new Directory('${temp.path}/flaf'); 491 var subDir = new Directory('${temp.path}/flaf');
494 Expect.isFalse(subDir.existsSync()); 492 Expect.isFalse(subDir.existsSync());
495 subDir.createSync(); 493 subDir.createSync();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 testCreateDirExistingFile() { 541 testCreateDirExistingFile() {
544 // Test that creating an existing directory succeeds. 542 // Test that creating an existing directory succeeds.
545 var port = new ReceivePort(); 543 var port = new ReceivePort();
546 var d = new Directory(''); 544 var d = new Directory('');
547 d.createTemp().then((temp) { 545 d.createTemp().then((temp) {
548 var path = '${temp.path}/flaf'; 546 var path = '${temp.path}/flaf';
549 var file = new File(path); 547 var file = new File(path);
550 var subDir = new Directory(path); 548 var subDir = new Directory(path);
551 file.create().then((_) { 549 file.create().then((_) {
552 subDir.create() 550 subDir.create()
553 ..then((_) { Expect.fail("dir create should fail on existing file"); }) 551 .then((_) { Expect.fail("dir create should fail on existing file"); })
554 ..handleException((e) { 552 .catchError((e) {
555 Expect.isTrue(e is DirectoryIOException); 553 Expect.isTrue(e.error is DirectoryIOException);
556 temp.delete(recursive: true).then((_) { 554 temp.delete(recursive: true).then((_) {
557 port.close(); 555 port.close();
558 });
559 return true;
560 }); 556 });
557 });
561 }); 558 });
562 }); 559 });
563 } 560 }
564 561
565 562
566 testCreateRecursiveSync() { 563 testCreateRecursiveSync() {
567 var temp = new Directory('').createTempSync(); 564 var temp = new Directory('').createTempSync();
568 var d = new Directory('${temp.path}/a/b/c'); 565 var d = new Directory('${temp.path}/a/b/c');
569 d.createSync(recursive: true); 566 d.createSync(recursive: true);
570 Expect.isTrue(new Directory('${temp.path}/a').existsSync()); 567 Expect.isTrue(new Directory('${temp.path}/a').existsSync());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 testCreateTempErrorSync(); 611 testCreateTempErrorSync();
615 testCreateTempError(); 612 testCreateTempError();
616 testCreateExistingSync(); 613 testCreateExistingSync();
617 testCreateExisting(); 614 testCreateExisting();
618 testCreateDirExistingFileSync(); 615 testCreateDirExistingFileSync();
619 testCreateDirExistingFile(); 616 testCreateDirExistingFile();
620 testCreateRecursive(); 617 testCreateRecursive();
621 testCreateRecursiveSync(); 618 testCreateRecursiveSync();
622 testRename(); 619 testRename();
623 } 620 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_fuzz_test.dart ('k') | tests/standalone/io/echo_server_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698