Chromium Code Reviews| 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) { | |
|
Bill Hesse
2011/12/13 13:51:03
Should we use expect.throws() here, instead of wri
Søren Gjesse
2011/12/13 14:07:40
Yes, done. I didn't know that existed.
| |
| 267 bool exceptionCaught = false; | |
| 268 try { | |
| 269 new Directory(location).createTempSync(); | |
| 270 } catch (DirectoryException e) { | |
| 271 exceptionCaught = true; | |
| 272 } | |
| 273 Expect.isTrue(exceptionCaught); | |
| 274 } | |
| 275 } | |
| 276 | |
| 277 | |
| 278 testCreateTempError() { | |
| 279 var location = illegalTempDirectoryLocation(); | |
| 280 if (location == null) return; | |
| 281 | |
| 282 var resultPort = new ReceivePort.singleShot(); | |
| 283 resultPort.receive((String message, ignored) { | |
| 284 Expect.equals("error", message); | |
| 285 }); | |
| 286 | |
| 287 Directory dir = new Directory(location); | |
| 288 dir.errorHandler = (error) { resultPort.toSendPort().send("error"); }; | |
| 289 dir.createTempHandler = () { resultPort.toSendPort().send("success"); }; | |
| 290 dir.createTemp(); | |
| 248 } | 291 } |
| 249 | 292 |
| 250 | 293 |
| 251 main() { | 294 main() { |
| 252 DirectoryTest.testMain(); | 295 DirectoryTest.testMain(); |
| 253 NestedTempDirectoryTest.testMain(); | 296 NestedTempDirectoryTest.testMain(); |
| 297 testCreateTempErrorSync(); | |
| 298 testCreateTempError(); | |
| 254 } | 299 } |
| OLD | NEW |