OLD | NEW |
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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import "dart:async"; | 8 import "dart:async"; |
9 import "dart:io"; | 9 import "dart:io"; |
10 import "dart:isolate"; | 10 import "dart:isolate"; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // point. | 83 // point. |
84 Expect.isFalse(listedDir); | 84 Expect.isFalse(listedDir); |
85 Expect.isFalse(listedFile); | 85 Expect.isFalse(listedFile); |
86 } | 86 } |
87 | 87 |
88 static void testListNonExistent() { | 88 static void testListNonExistent() { |
89 setupListerHandlers(Stream<FileSystemEntity> stream) { | 89 setupListerHandlers(Stream<FileSystemEntity> stream) { |
90 stream.listen( | 90 stream.listen( |
91 (_) => Expect.fail("Listing of non-existing directory should fail"), | 91 (_) => Expect.fail("Listing of non-existing directory should fail"), |
92 onError: (error) { | 92 onError: (error) { |
93 Expect.isTrue(error is DirectoryIOException); | 93 Expect.isTrue(error is DirectoryException); |
94 }); | 94 }); |
95 } | 95 } |
96 new Directory("").createTemp().then((d) { | 96 new Directory("").createTemp().then((d) { |
97 d.delete().then((ignore) { | 97 d.delete().then((ignore) { |
98 setupListerHandlers(d.list()); | 98 setupListerHandlers(d.list()); |
99 setupListerHandlers(d.list(recursive: true)); | 99 setupListerHandlers(d.list(recursive: true)); |
100 }); | 100 }); |
101 }); | 101 }); |
102 } | 102 } |
103 | 103 |
104 static void testListTooLongName() { | 104 static void testListTooLongName() { |
105 new Directory("").createTemp().then((d) { | 105 new Directory("").createTemp().then((d) { |
106 var errors = 0; | 106 var errors = 0; |
107 var port = new ReceivePort(); | 107 var port = new ReceivePort(); |
108 setupListHandlers(Stream<FileSystemEntity> stream) { | 108 setupListHandlers(Stream<FileSystemEntity> stream) { |
109 stream.listen( | 109 stream.listen( |
110 (_) => Expect.fail("Listing of non-existing directory should fail"), | 110 (_) => Expect.fail("Listing of non-existing directory should fail"), |
111 onError: (error) { | 111 onError: (error) { |
112 Expect.isTrue(error is DirectoryIOException); | 112 Expect.isTrue(error is DirectoryException); |
113 if (++errors == 2) { | 113 if (++errors == 2) { |
114 d.delete(recursive: true).then((_) { | 114 d.delete(recursive: true).then((_) { |
115 port.close(); | 115 port.close(); |
116 }); | 116 }); |
117 } | 117 } |
118 }); | 118 }); |
119 } | 119 } |
120 var subDirName = 'subdir'; | 120 var subDirName = 'subdir'; |
121 var subDir = new Directory("${d.path}/$subDirName"); | 121 var subDir = new Directory("${d.path}/$subDirName"); |
122 subDir.create().then((ignore) { | 122 subDir.create().then((ignore) { |
(...skipping 10 matching lines...) Expand all Loading... |
133 }); | 133 }); |
134 }); | 134 }); |
135 } | 135 } |
136 | 136 |
137 static void testDeleteNonExistent() { | 137 static void testDeleteNonExistent() { |
138 // Test that deleting a non-existing directory fails. | 138 // Test that deleting a non-existing directory fails. |
139 setupFutureHandlers(future) { | 139 setupFutureHandlers(future) { |
140 future.then((ignore) { | 140 future.then((ignore) { |
141 Expect.fail("Deletion of non-existing directory should fail"); | 141 Expect.fail("Deletion of non-existing directory should fail"); |
142 }).catchError((error) { | 142 }).catchError((error) { |
143 Expect.isTrue(error is DirectoryIOException); | 143 Expect.isTrue(error is DirectoryException); |
144 }); | 144 }); |
145 } | 145 } |
146 | 146 |
147 new Directory("").createTemp().then((d) { | 147 new Directory("").createTemp().then((d) { |
148 d.delete().then((ignore) { | 148 d.delete().then((ignore) { |
149 setupFutureHandlers(d.delete()); | 149 setupFutureHandlers(d.delete()); |
150 setupFutureHandlers(d.delete(recursive: true)); | 150 setupFutureHandlers(d.delete(recursive: true)); |
151 }); | 151 }); |
152 }); | 152 }); |
153 } | 153 } |
154 | 154 |
155 static void testDeleteTooLongName() { | 155 static void testDeleteTooLongName() { |
156 var port = new ReceivePort(); | 156 var port = new ReceivePort(); |
157 new Directory("").createTemp().then((d) { | 157 new Directory("").createTemp().then((d) { |
158 var subDirName = 'subdir'; | 158 var subDirName = 'subdir'; |
159 var subDir = new Directory("${d.path}/$subDirName"); | 159 var subDir = new Directory("${d.path}/$subDirName"); |
160 subDir.create().then((ignore) { | 160 subDir.create().then((ignore) { |
161 // Construct a long string of the form | 161 // Construct a long string of the form |
162 // 'tempdir/subdir/../subdir/../subdir'. | 162 // 'tempdir/subdir/../subdir/../subdir'. |
163 var buffer = new StringBuffer(); | 163 var buffer = new StringBuffer(); |
164 buffer.write(subDir.path); | 164 buffer.write(subDir.path); |
165 for (var i = 0; i < 1000; i++) { | 165 for (var i = 0; i < 1000; i++) { |
166 buffer.write("/../${subDirName}"); | 166 buffer.write("/../${subDirName}"); |
167 } | 167 } |
168 var long = new Directory("${buffer.toString()}"); | 168 var long = new Directory("${buffer.toString()}"); |
169 var errors = 0; | 169 var errors = 0; |
170 onError(error) { | 170 onError(error) { |
171 Expect.isTrue(error is DirectoryIOException); | 171 Expect.isTrue(error is DirectoryException); |
172 if (++errors == 2) { | 172 if (++errors == 2) { |
173 d.delete(recursive: true).then((ignore) => port.close()); | 173 d.delete(recursive: true).then((ignore) => port.close()); |
174 } | 174 } |
175 return true; | 175 return true; |
176 } | 176 } |
177 long.delete().catchError(onError); | 177 long.delete().catchError(onError); |
178 long.delete(recursive: true).catchError(onError); | 178 long.delete(recursive: true).catchError(onError); |
179 }); | 179 }); |
180 }); | 180 }); |
181 } | 181 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return "*"; | 466 return "*"; |
467 } | 467 } |
468 return null; | 468 return null; |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 testCreateTempErrorSync() { | 472 testCreateTempErrorSync() { |
473 var location = illegalTempDirectoryLocation(); | 473 var location = illegalTempDirectoryLocation(); |
474 if (location != null) { | 474 if (location != null) { |
475 Expect.throws(new Directory(location).createTempSync, | 475 Expect.throws(new Directory(location).createTempSync, |
476 (e) => e is DirectoryIOException); | 476 (e) => e is DirectoryException); |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 | 480 |
481 testCreateTempError() { | 481 testCreateTempError() { |
482 var location = illegalTempDirectoryLocation(); | 482 var location = illegalTempDirectoryLocation(); |
483 if (location == null) return; | 483 if (location == null) return; |
484 | 484 |
485 var port = new ReceivePort(); | 485 var port = new ReceivePort(); |
486 var future = new Directory(location).createTemp(); | 486 var future = new Directory(location).createTemp(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 530 |
531 testCreateDirExistingFileSync() { | 531 testCreateDirExistingFileSync() { |
532 // Test that creating an existing directory succeeds. | 532 // Test that creating an existing directory succeeds. |
533 var d = new Directory(''); | 533 var d = new Directory(''); |
534 var temp = d.createTempSync(); | 534 var temp = d.createTempSync(); |
535 var path = '${temp.path}/flaf'; | 535 var path = '${temp.path}/flaf'; |
536 var file = new File(path); | 536 var file = new File(path); |
537 file.createSync(); | 537 file.createSync(); |
538 Expect.isTrue(file.existsSync()); | 538 Expect.isTrue(file.existsSync()); |
539 Expect.throws(new Directory(path).createSync, | 539 Expect.throws(new Directory(path).createSync, |
540 (e) => e is DirectoryIOException); | 540 (e) => e is DirectoryException); |
541 temp.deleteSync(recursive: true); | 541 temp.deleteSync(recursive: true); |
542 } | 542 } |
543 | 543 |
544 | 544 |
545 testCreateDirExistingFile() { | 545 testCreateDirExistingFile() { |
546 // Test that creating an existing directory succeeds. | 546 // Test that creating an existing directory succeeds. |
547 var port = new ReceivePort(); | 547 var port = new ReceivePort(); |
548 var d = new Directory(''); | 548 var d = new Directory(''); |
549 d.createTemp().then((temp) { | 549 d.createTemp().then((temp) { |
550 var path = '${temp.path}/flaf'; | 550 var path = '${temp.path}/flaf'; |
551 var file = new File(path); | 551 var file = new File(path); |
552 var subDir = new Directory(path); | 552 var subDir = new Directory(path); |
553 file.create().then((_) { | 553 file.create().then((_) { |
554 subDir.create() | 554 subDir.create() |
555 .then((_) { Expect.fail("dir create should fail on existing file"); }) | 555 .then((_) { Expect.fail("dir create should fail on existing file"); }) |
556 .catchError((error) { | 556 .catchError((error) { |
557 Expect.isTrue(error is DirectoryIOException); | 557 Expect.isTrue(error is DirectoryException); |
558 temp.delete(recursive: true).then((_) { | 558 temp.delete(recursive: true).then((_) { |
559 port.close(); | 559 port.close(); |
560 }); | 560 }); |
561 }); | 561 }); |
562 }); | 562 }); |
563 }); | 563 }); |
564 } | 564 } |
565 | 565 |
566 | 566 |
567 testCreateRecursiveSync() { | 567 testCreateRecursiveSync() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 testCreateTempErrorSync(); | 615 testCreateTempErrorSync(); |
616 testCreateTempError(); | 616 testCreateTempError(); |
617 testCreateExistingSync(); | 617 testCreateExistingSync(); |
618 testCreateExisting(); | 618 testCreateExisting(); |
619 testCreateDirExistingFileSync(); | 619 testCreateDirExistingFileSync(); |
620 testCreateDirExistingFile(); | 620 testCreateDirExistingFile(); |
621 testCreateRecursive(); | 621 testCreateRecursive(); |
622 testCreateRecursiveSync(); | 622 testCreateRecursiveSync(); |
623 testRename(); | 623 testRename(); |
624 } | 624 } |
OLD | NEW |