| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class DirectoryTest { | 7 class DirectoryTest { |
| 8 static void testListing() { | 8 static void testListing() { |
| 9 bool listedDir = false; | 9 bool listedDir = false; |
| 10 bool listedFile = false; | 10 bool listedFile = false; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Try to delete the directory containing the file - should throw. | 165 // Try to delete the directory containing the file - should throw. |
| 166 bool threw_exception = false; | 166 bool threw_exception = false; |
| 167 try { | 167 try { |
| 168 tempDirectory.deleteSync(); | 168 tempDirectory.deleteSync(); |
| 169 } catch (var e) { | 169 } catch (var e) { |
| 170 Expect.isTrue(tempDirectory.existsSync()); | 170 Expect.isTrue(tempDirectory.existsSync()); |
| 171 threw_exception = true; | 171 threw_exception = true; |
| 172 } | 172 } |
| 173 Expect.isTrue(threw_exception); | 173 Expect.isTrue(threw_exception); |
| 174 Expect.isTrue(tempDirectory.existsSync()); | 174 Expect.isTrue(tempDirectory.existsSync()); |
| 175 | 175 |
| 176 // Delete the file, and then delete the directory. | 176 // Delete the file, and then delete the directory. |
| 177 file.delete(); | 177 file.delete(); |
| 178 }; | 178 }; |
| 179 file.deleteHandler = () { | 179 file.deleteHandler = () { |
| 180 tempDirectory.deleteSync(); | 180 tempDirectory.deleteSync(); |
| 181 Expect.isFalse(tempDirectory.existsSync()); | 181 Expect.isFalse(tempDirectory.existsSync()); |
| 182 }; | 182 }; |
| 183 }; | 183 }; |
| 184 file.open(writable: true); | 184 file.open(writable: true); |
| 185 }; | 185 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void startTest() { | 237 void startTest() { |
| 238 current = new Directory(""); | 238 current = new Directory(""); |
| 239 current.createTempHandler = createPhaseCallback; | 239 current.createTempHandler = createPhaseCallback; |
| 240 current.errorHandler = errorCallback; | 240 current.errorHandler = errorCallback; |
| 241 current.createTemp(); | 241 current.createTemp(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 static void testMain() { | 244 static void testMain() { |
| 245 new NestedTempDirectoryTest().startTest(); | 245 new NestedTempDirectoryTest().startTest(); |
| 246 new NestedTempDirectoryTest().startTest(); | 246 new NestedTempDirectoryTest().startTest(); |
| 247 } | 247 } |
| 248 } |
| 249 |
| 250 |
| 251 String illegalTempDirectoryLocation() { |
| 252 // Determine a platform specific illegal location for a temporary directory. |
| 253 var os = new Platform().operatingSystem(); |
| 254 if (os == "linux" || os == "macos") { |
| 255 return "/dev/zero/"; |
| 256 } |
| 257 if (os == "windows") { |
| 258 return "*"; |
| 259 } |
| 260 return null; |
| 261 } |
| 262 |
| 263 |
| 264 testCreateTempErrorSync() { |
| 265 var location = illegalTempDirectoryLocation(); |
| 266 if (location != null) { |
| 267 Expect.throws(new Directory(location).createTempSync()); |
| 268 } |
| 269 } |
| 270 |
| 271 |
| 272 testCreateTempError() { |
| 273 var location = illegalTempDirectoryLocation(); |
| 274 if (location == null) return; |
| 275 |
| 276 var resultPort = new ReceivePort.singleShot(); |
| 277 resultPort.receive((String message, ignored) { |
| 278 Expect.equals("error", message); |
| 279 }); |
| 280 |
| 281 Directory dir = new Directory(location); |
| 282 dir.errorHandler = (error) { resultPort.toSendPort().send("error"); }; |
| 283 dir.createTempHandler = () { resultPort.toSendPort().send("success"); }; |
| 284 dir.createTemp(); |
| 248 } | 285 } |
| 249 | 286 |
| 250 | 287 |
| 251 main() { | 288 main() { |
| 252 DirectoryTest.testMain(); | 289 DirectoryTest.testMain(); |
| 253 NestedTempDirectoryTest.testMain(); | 290 NestedTempDirectoryTest.testMain(); |
| 291 testCreateTempErrorSync(); |
| 292 testCreateTempError(); |
| 254 } | 293 } |
| OLD | NEW |