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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Listing is asynchronous, so nothing should be listed at this | 82 // Listing is asynchronous, so nothing should be listed at this |
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: (e) { | 92 onError: (error) { |
93 Expect.isTrue(e is AsyncError); | 93 Expect.isTrue(error is DirectoryIOException); |
94 Expect.isTrue(e.error is DirectoryIOException); | |
95 }); | 94 }); |
96 } | 95 } |
97 new Directory("").createTemp().then((d) { | 96 new Directory("").createTemp().then((d) { |
98 d.delete().then((ignore) { | 97 d.delete().then((ignore) { |
99 setupListerHandlers(d.list()); | 98 setupListerHandlers(d.list()); |
100 setupListerHandlers(d.list(recursive: true)); | 99 setupListerHandlers(d.list(recursive: true)); |
101 }); | 100 }); |
102 }); | 101 }); |
103 } | 102 } |
104 | 103 |
105 static void testListTooLongName() { | 104 static void testListTooLongName() { |
106 new Directory("").createTemp().then((d) { | 105 new Directory("").createTemp().then((d) { |
107 var errors = 0; | 106 var errors = 0; |
108 var port = new ReceivePort(); | 107 var port = new ReceivePort(); |
109 setupListHandlers(Stream<FileSystemEntity> stream) { | 108 setupListHandlers(Stream<FileSystemEntity> stream) { |
110 stream.listen( | 109 stream.listen( |
111 (_) => Expect.fail("Listing of non-existing directory should fail"), | 110 (_) => Expect.fail("Listing of non-existing directory should fail"), |
112 onError: (e) { | 111 onError: (error) { |
113 Expect.isTrue(e is AsyncError); | 112 Expect.isTrue(error is DirectoryIOException); |
114 Expect.isTrue(e.error is DirectoryIOException); | |
115 if (++errors == 2) { | 113 if (++errors == 2) { |
116 d.delete(recursive: true).then((_) { | 114 d.delete(recursive: true).then((_) { |
117 port.close(); | 115 port.close(); |
118 }); | 116 }); |
119 } | 117 } |
120 }); | 118 }); |
121 } | 119 } |
122 var subDirName = 'subdir'; | 120 var subDirName = 'subdir'; |
123 var subDir = new Directory("${d.path}/$subDirName"); | 121 var subDir = new Directory("${d.path}/$subDirName"); |
124 subDir.create().then((ignore) { | 122 subDir.create().then((ignore) { |
125 // Construct a long string of the form | 123 // Construct a long string of the form |
126 // 'tempdir/subdir/../subdir/../subdir'. | 124 // 'tempdir/subdir/../subdir/../subdir'. |
127 var buffer = new StringBuffer(); | 125 var buffer = new StringBuffer(); |
128 buffer.write(subDir.path); | 126 buffer.write(subDir.path); |
129 for (var i = 0; i < 1000; i++) { | 127 for (var i = 0; i < 1000; i++) { |
130 buffer.write("/../${subDirName}"); | 128 buffer.write("/../${subDirName}"); |
131 } | 129 } |
132 var long = new Directory("${buffer.toString()}"); | 130 var long = new Directory("${buffer.toString()}"); |
133 setupListHandlers(long.list()); | 131 setupListHandlers(long.list()); |
134 setupListHandlers(long.list(recursive: true)); | 132 setupListHandlers(long.list(recursive: true)); |
135 }); | 133 }); |
136 }); | 134 }); |
137 } | 135 } |
138 | 136 |
139 static void testDeleteNonExistent() { | 137 static void testDeleteNonExistent() { |
140 // Test that deleting a non-existing directory fails. | 138 // Test that deleting a non-existing directory fails. |
141 setupFutureHandlers(future) { | 139 setupFutureHandlers(future) { |
142 future.then((ignore) { | 140 future.then((ignore) { |
143 Expect.fail("Deletion of non-existing directory should fail"); | 141 Expect.fail("Deletion of non-existing directory should fail"); |
144 }).catchError((e) { | 142 }).catchError((error) { |
145 Expect.isTrue(e.error is DirectoryIOException); | 143 Expect.isTrue(error is DirectoryIOException); |
146 }); | 144 }); |
147 } | 145 } |
148 | 146 |
149 new Directory("").createTemp().then((d) { | 147 new Directory("").createTemp().then((d) { |
150 d.delete().then((ignore) { | 148 d.delete().then((ignore) { |
151 setupFutureHandlers(d.delete()); | 149 setupFutureHandlers(d.delete()); |
152 setupFutureHandlers(d.delete(recursive: true)); | 150 setupFutureHandlers(d.delete(recursive: true)); |
153 }); | 151 }); |
154 }); | 152 }); |
155 } | 153 } |
156 | 154 |
157 static void testDeleteTooLongName() { | 155 static void testDeleteTooLongName() { |
158 var port = new ReceivePort(); | 156 var port = new ReceivePort(); |
159 new Directory("").createTemp().then((d) { | 157 new Directory("").createTemp().then((d) { |
160 var subDirName = 'subdir'; | 158 var subDirName = 'subdir'; |
161 var subDir = new Directory("${d.path}/$subDirName"); | 159 var subDir = new Directory("${d.path}/$subDirName"); |
162 subDir.create().then((ignore) { | 160 subDir.create().then((ignore) { |
163 // Construct a long string of the form | 161 // Construct a long string of the form |
164 // 'tempdir/subdir/../subdir/../subdir'. | 162 // 'tempdir/subdir/../subdir/../subdir'. |
165 var buffer = new StringBuffer(); | 163 var buffer = new StringBuffer(); |
166 buffer.write(subDir.path); | 164 buffer.write(subDir.path); |
167 for (var i = 0; i < 1000; i++) { | 165 for (var i = 0; i < 1000; i++) { |
168 buffer.write("/../${subDirName}"); | 166 buffer.write("/../${subDirName}"); |
169 } | 167 } |
170 var long = new Directory("${buffer.toString()}"); | 168 var long = new Directory("${buffer.toString()}"); |
171 var errors = 0; | 169 var errors = 0; |
172 onError(e) { | 170 onError(error) { |
173 Expect.isTrue(e.error is DirectoryIOException); | 171 Expect.isTrue(error is DirectoryIOException); |
174 if (++errors == 2) { | 172 if (++errors == 2) { |
175 d.delete(recursive: true).then((ignore) => port.close()); | 173 d.delete(recursive: true).then((ignore) => port.close()); |
176 } | 174 } |
177 return true; | 175 return true; |
178 } | 176 } |
179 long.delete().catchError(onError); | 177 long.delete().catchError(onError); |
180 long.delete(recursive: true).catchError(onError); | 178 long.delete(recursive: true).catchError(onError); |
181 }); | 179 }); |
182 }); | 180 }); |
183 } | 181 } |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 // Test that creating an existing directory succeeds. | 546 // Test that creating an existing directory succeeds. |
549 var port = new ReceivePort(); | 547 var port = new ReceivePort(); |
550 var d = new Directory(''); | 548 var d = new Directory(''); |
551 d.createTemp().then((temp) { | 549 d.createTemp().then((temp) { |
552 var path = '${temp.path}/flaf'; | 550 var path = '${temp.path}/flaf'; |
553 var file = new File(path); | 551 var file = new File(path); |
554 var subDir = new Directory(path); | 552 var subDir = new Directory(path); |
555 file.create().then((_) { | 553 file.create().then((_) { |
556 subDir.create() | 554 subDir.create() |
557 .then((_) { Expect.fail("dir create should fail on existing file"); }) | 555 .then((_) { Expect.fail("dir create should fail on existing file"); }) |
558 .catchError((e) { | 556 .catchError((error) { |
559 Expect.isTrue(e.error is DirectoryIOException); | 557 Expect.isTrue(error is DirectoryIOException); |
560 temp.delete(recursive: true).then((_) { | 558 temp.delete(recursive: true).then((_) { |
561 port.close(); | 559 port.close(); |
562 }); | 560 }); |
563 }); | 561 }); |
564 }); | 562 }); |
565 }); | 563 }); |
566 } | 564 } |
567 | 565 |
568 | 566 |
569 testCreateRecursiveSync() { | 567 testCreateRecursiveSync() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 testCreateTempErrorSync(); | 615 testCreateTempErrorSync(); |
618 testCreateTempError(); | 616 testCreateTempError(); |
619 testCreateExistingSync(); | 617 testCreateExistingSync(); |
620 testCreateExisting(); | 618 testCreateExisting(); |
621 testCreateDirExistingFileSync(); | 619 testCreateDirExistingFileSync(); |
622 testCreateDirExistingFile(); | 620 testCreateDirExistingFile(); |
623 testCreateRecursive(); | 621 testCreateRecursive(); |
624 testCreateRecursiveSync(); | 622 testCreateRecursiveSync(); |
625 testRename(); | 623 testRename(); |
626 } | 624 } |
OLD | NEW |