| 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("dart:io"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 class DirectoryTest { | 10 class DirectoryTest { |
| 11 static void testListing() { | 11 static void testListing() { |
| 12 bool listedDir = false; | 12 bool listedDir = false; |
| 13 bool listedFile = false; | 13 bool listedFile = false; |
| 14 | 14 |
| 15 Directory directory = new Directory(""); | 15 Directory directory = new Directory(""); |
| 16 directory.createTempSync(); | 16 directory.createTempSync(); |
| 17 Directory subDirectory = new Directory("${directory.path}/subdir"); | 17 Directory subDirectory = new Directory("${directory.path}/subdir"); |
| 18 Expect.isFalse(subDirectory.existsSync()); | 18 Expect.isFalse(subDirectory.existsSync()); |
| 19 subDirectory.createSync(); | 19 subDirectory.createSync(); |
| 20 File f = new File('${subDirectory.path}/file.txt'); | 20 File f = new File('${subDirectory.path}/file.txt'); |
| 21 Expect.isFalse(f.existsSync()); | 21 Expect.isFalse(f.existsSync()); |
| 22 f.createSync(); | 22 f.createSync(); |
| 23 | 23 |
| 24 directory.dirHandler = (dir) { | 24 directory.onDir = (dir) { |
| 25 listedDir = true; | 25 listedDir = true; |
| 26 Expect.isTrue(dir.contains(directory.path)); | 26 Expect.isTrue(dir.contains(directory.path)); |
| 27 Expect.isTrue(dir.contains('subdir')); | 27 Expect.isTrue(dir.contains('subdir')); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 directory.fileHandler = (f) { | 30 directory.onFile = (f) { |
| 31 listedFile = true; | 31 listedFile = true; |
| 32 Expect.isTrue(f.contains(directory.path)); | 32 Expect.isTrue(f.contains(directory.path)); |
| 33 Expect.isTrue(f.contains('subdir')); | 33 Expect.isTrue(f.contains('subdir')); |
| 34 Expect.isTrue(f.contains('file.txt')); | 34 Expect.isTrue(f.contains('file.txt')); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 directory.doneHandler = (completed) { | 37 directory.onDone = (completed) { |
| 38 Expect.isTrue(completed, "directory listing did not complete"); | 38 Expect.isTrue(completed, "directory listing did not complete"); |
| 39 Expect.isTrue(listedDir, "directory not found"); | 39 Expect.isTrue(listedDir, "directory not found"); |
| 40 Expect.isTrue(listedFile, "file not found"); | 40 Expect.isTrue(listedFile, "file not found"); |
| 41 directory.delete(recursive: true); | 41 directory.deleteRecursively(() { |
| 42 directory.deleteHandler = () { | 42 f.exists((exists) => Expect.isFalse(exists)); |
| 43 f.exists(); | 43 directory.exists((exists) => Expect.isFalse(exists)); |
| 44 f.existsHandler = (exists) => Expect.isFalse(exists); | 44 subDirectory.exists((exists) => Expect.isFalse(exists)); |
| 45 directory.exists(); | 45 }); |
| 46 directory.existsHandler = (exists) => Expect.isFalse(exists); | |
| 47 subDirectory.exists(); | |
| 48 subDirectory.existsHandler = (exists) => Expect.isFalse(exists); | |
| 49 }; | |
| 50 }; | 46 }; |
| 51 | 47 |
| 52 directory.errorHandler = (error) { | 48 directory.onError = (error) { |
| 53 Expect.fail("error listing directory: $error"); | 49 Expect.fail("error listing directory: $error"); |
| 54 }; | 50 }; |
| 55 | 51 |
| 56 directory.list(recursive: true); | 52 directory.list(recursive: true); |
| 57 | 53 |
| 58 // Listing is asynchronous, so nothing should be listed at this | 54 // Listing is asynchronous, so nothing should be listed at this |
| 59 // point. | 55 // point. |
| 60 Expect.isFalse(listedDir); | 56 Expect.isFalse(listedDir); |
| 61 Expect.isFalse(listedFile); | 57 Expect.isFalse(listedFile); |
| 62 } | 58 } |
| 63 | 59 |
| 64 static void testListNonExistent() { | 60 static void testListNonExistent() { |
| 65 Directory d = new Directory(""); | 61 Directory d = new Directory(""); |
| 66 d.errorHandler = (error) { | 62 d.onError = (error) { |
| 67 Expect.fail("Directory error: $error"); | 63 Expect.fail("Directory error: $error"); |
| 68 }; | 64 }; |
| 69 d.createTemp(); | 65 d.createTemp(() { |
| 70 d.createTempHandler = () { | 66 d.delete(() { |
| 71 d.delete(); | |
| 72 d.deleteHandler = () { | |
| 73 // Test that listing a non-existing directory fails. | 67 // Test that listing a non-existing directory fails. |
| 74 d.errorHandler = (error) { | 68 d.onError = (error) { |
| 75 // TODO(ager): When directory errors have been changed to | 69 // TODO(ager): When directory errors have been changed to |
| 76 // post back exceptions, check that we get the right exception | 70 // post back exceptions, check that we get the right exception |
| 77 // type here. | 71 // type here. |
| 78 }; | 72 }; |
| 79 d.fileHandler = (file) { | 73 d.onFile = (file) { |
| 80 Expect.fail("Listing of non-existing directory should fail"); | 74 Expect.fail("Listing of non-existing directory should fail"); |
| 81 }; | 75 }; |
| 82 d.fileHandler = (dir) { | 76 d.onDir = (dir) { |
| 83 Expect.fail("Listing of non-existing directory should fail"); | 77 Expect.fail("Listing of non-existing directory should fail"); |
| 84 }; | 78 }; |
| 85 d.doneHandler = (done) { | 79 d.onDone = (done) { |
| 86 Expect.isFalse(done); | 80 Expect.isFalse(done); |
| 87 }; | 81 }; |
| 88 d.list(); | 82 d.list(); |
| 89 d.list(recursive: true); | 83 d.list(recursive: true); |
| 90 }; | 84 }); |
| 91 }; | 85 }); |
| 92 } | 86 } |
| 93 | 87 |
| 94 static void testListTooLongName() { | 88 static void testListTooLongName() { |
| 95 Directory d = new Directory(""); | 89 Directory d = new Directory(""); |
| 96 d.errorHandler = (error) { | 90 d.onError = (error) { |
| 97 Expect.fail("Directory error: $error"); | 91 Expect.fail("Directory error: $error"); |
| 98 }; | 92 }; |
| 99 d.createTemp(); | 93 d.createTemp(() { |
| 100 d.createTempHandler = () { | |
| 101 var subDirName = 'subdir'; | 94 var subDirName = 'subdir'; |
| 102 var subDir = new Directory("${d.path}/$subDirName"); | 95 var subDir = new Directory("${d.path}/$subDirName"); |
| 103 subDir.errorHandler = (error) { | 96 subDir.onError = (error) { |
| 104 Expect.fail("Directory error: $error"); | 97 Expect.fail("Directory error: $error"); |
| 105 }; | 98 }; |
| 106 subDir.create(); | 99 subDir.create(() { |
| 107 subDir.createHandler = () { | |
| 108 // Construct a long string of the form | 100 // Construct a long string of the form |
| 109 // 'tempdir/subdir/../subdir/../subdir'. | 101 // 'tempdir/subdir/../subdir/../subdir'. |
| 110 var buffer = new StringBuffer(); | 102 var buffer = new StringBuffer(); |
| 111 buffer.add(subDir.path); | 103 buffer.add(subDir.path); |
| 112 for (var i = 0; i < 1000; i++) { | 104 for (var i = 0; i < 1000; i++) { |
| 113 buffer.add("/../${subDirName}"); | 105 buffer.add("/../${subDirName}"); |
| 114 } | 106 } |
| 115 var long = new Directory("${buffer.toString()}"); | 107 var long = new Directory("${buffer.toString()}"); |
| 116 var errors = 0; | 108 var errors = 0; |
| 117 long.errorHandler = (error) { | 109 long.onError = (error) { |
| 118 // TODO(ager): When directory errors have been changed to | 110 // TODO(ager): When directory errors have been changed to |
| 119 // post back exceptions, check that we get the right exception | 111 // post back exceptions, check that we get the right exception |
| 120 // type here. | 112 // type here. |
| 121 if (++errors == 2) { | 113 if (++errors == 2) { |
| 122 d.delete(recursive: true); | 114 d.deleteRecursively(() => null); |
| 123 } | 115 } |
| 124 }; | 116 }; |
| 125 long.fileHandler = (file) { | 117 long.onFile = (file) { |
| 126 Expect.fail("Listing of non-existing directory should fail"); | 118 Expect.fail("Listing of non-existing directory should fail"); |
| 127 }; | 119 }; |
| 128 long.fileHandler = (dir) { | 120 long.onDir = (dir) { |
| 129 Expect.fail("Listing of non-existing directory should fail"); | 121 Expect.fail("Listing of non-existing directory should fail"); |
| 130 }; | 122 }; |
| 131 long.doneHandler = (done) { | 123 long.onDone = (done) { |
| 132 Expect.isFalse(done); | 124 Expect.isFalse(done); |
| 133 }; | 125 }; |
| 134 long.list(); | 126 long.list(); |
| 135 long.list(recursive: true); | 127 long.list(recursive: true); |
| 136 }; | 128 }); |
| 137 }; | 129 }); |
| 138 } | 130 } |
| 139 | 131 |
| 140 static void testDeleteNonExistent() { | 132 static void testDeleteNonExistent() { |
| 141 Directory d = new Directory(""); | 133 Directory d = new Directory(""); |
| 142 d.errorHandler = (error) { | 134 d.onError = (error) { |
| 143 Expect.fail("Directory error: $error"); | 135 Expect.fail("Directory error: $error"); |
| 144 }; | 136 }; |
| 145 d.createTemp(); | 137 d.createTemp(() { |
| 146 d.createTempHandler = () { | 138 d.delete(() { |
| 147 d.delete(); | |
| 148 d.deleteHandler = () { | |
| 149 // Test that deleting a non-existing directory fails. | 139 // Test that deleting a non-existing directory fails. |
| 150 d.errorHandler = (error) { | 140 d.onError = (error) { |
| 151 // TODO(ager): When directory errors have been changed to | 141 // TODO(ager): When directory errors have been changed to |
| 152 // post back exceptions, check that we get the right exception | 142 // post back exceptions, check that we get the right exception |
| 153 // type here. | 143 // type here. |
| 154 }; | 144 }; |
| 155 d.deleteHandler = () { | 145 d.delete(() { |
| 156 Expect.fail("Deletion of non-existing directory should fail"); | 146 Expect.fail("Deletion of non-existing directory should fail"); |
| 157 }; | 147 }); |
| 158 d.delete(); | 148 d.deleteRecursively(() { |
| 159 d.delete(recursive: true); | 149 Expect.fail("Deletion of non-existing directory should fail"); |
| 160 }; | 150 }); |
| 161 }; | 151 }); |
| 152 }); |
| 162 } | 153 } |
| 163 | 154 |
| 164 static void testDeleteTooLongName() { | 155 static void testDeleteTooLongName() { |
| 165 Directory d = new Directory(""); | 156 Directory d = new Directory(""); |
| 166 d.errorHandler = (error) { | 157 d.onError = (error) { |
| 167 Expect.fail("Directory error: $error"); | 158 Expect.fail("Directory error: $error"); |
| 168 }; | 159 }; |
| 169 d.createTemp(); | 160 d.createTemp(() { |
| 170 d.createTempHandler = () { | |
| 171 var subDirName = 'subdir'; | 161 var subDirName = 'subdir'; |
| 172 var subDir = new Directory("${d.path}/$subDirName"); | 162 var subDir = new Directory("${d.path}/$subDirName"); |
| 173 subDir.errorHandler = (error) { | 163 subDir.onError = (error) { |
| 174 Expect.fail("Directory error: $error"); | 164 Expect.fail("Directory error: $error"); |
| 175 }; | 165 }; |
| 176 subDir.create(); | 166 subDir.create(() { |
| 177 subDir.createHandler = () { | |
| 178 // Construct a long string of the form | 167 // Construct a long string of the form |
| 179 // 'tempdir/subdir/../subdir/../subdir'. | 168 // 'tempdir/subdir/../subdir/../subdir'. |
| 180 var buffer = new StringBuffer(); | 169 var buffer = new StringBuffer(); |
| 181 buffer.add(subDir.path); | 170 buffer.add(subDir.path); |
| 182 for (var i = 0; i < 1000; i++) { | 171 for (var i = 0; i < 1000; i++) { |
| 183 buffer.add("/../${subDirName}"); | 172 buffer.add("/../${subDirName}"); |
| 184 } | 173 } |
| 185 var long = new Directory("${buffer.toString()}"); | 174 var long = new Directory("${buffer.toString()}"); |
| 186 var errors = 0; | 175 var errors = 0; |
| 187 long.errorHandler = (error) { | 176 long.onError = (error) { |
| 188 // TODO(ager): When directory errors have been changed to | 177 // TODO(ager): When directory errors have been changed to |
| 189 // post back exceptions, check that we get the right exception | 178 // post back exceptions, check that we get the right exception |
| 190 // type here. | 179 // type here. |
| 191 if (++errors == 2) { | 180 if (++errors == 2) { |
| 192 d.delete(recursive: true); | 181 d.deleteRecursively(() => null); |
| 193 } | 182 } |
| 194 }; | 183 }; |
| 195 long.deleteHandler = () { | 184 long.delete(() { |
| 196 Expect.fail("Deletion of a directory with a long name should fail"); | 185 Expect.fail("Deletion of a directory with a long name should fail"); |
| 197 }; | 186 }); |
| 198 long.delete(); | 187 long.deleteRecursively(() { |
| 199 long.delete(recursive:true); | 188 Expect.fail("Deletion of a directory with a long name should fail"); |
| 200 }; | 189 }); |
| 201 }; | 190 }); |
| 191 }); |
| 202 } | 192 } |
| 203 | 193 |
| 204 static void testDeleteNonExistentSync() { | 194 static void testDeleteNonExistentSync() { |
| 205 Directory d = new Directory(""); | 195 Directory d = new Directory(""); |
| 206 d.createTempSync(); | 196 d.createTempSync(); |
| 207 d.deleteSync(); | 197 d.deleteSync(); |
| 208 Expect.throws(d.deleteSync); | 198 Expect.throws(d.deleteSync); |
| 209 Expect.throws(() => d.deleteSync(recursive: true)); | 199 Expect.throws(() => d.deleteRecursivelySync()); |
| 210 } | 200 } |
| 211 | 201 |
| 212 static void testDeleteTooLongNameSync() { | 202 static void testDeleteTooLongNameSync() { |
| 213 Directory d = new Directory(""); | 203 Directory d = new Directory(""); |
| 214 d.createTempSync(); | 204 d.createTempSync(); |
| 215 var subDirName = 'subdir'; | 205 var subDirName = 'subdir'; |
| 216 var subDir = new Directory("${d.path}/$subDirName"); | 206 var subDir = new Directory("${d.path}/$subDirName"); |
| 217 subDir.createSync(); | 207 subDir.createSync(); |
| 218 // Construct a long string of the form | 208 // Construct a long string of the form |
| 219 // 'tempdir/subdir/../subdir/../subdir'. | 209 // 'tempdir/subdir/../subdir/../subdir'. |
| 220 var buffer = new StringBuffer(); | 210 var buffer = new StringBuffer(); |
| 221 buffer.add(subDir.path); | 211 buffer.add(subDir.path); |
| 222 for (var i = 0; i < 1000; i++) { | 212 for (var i = 0; i < 1000; i++) { |
| 223 buffer.add("/../${subDirName}"); | 213 buffer.add("/../${subDirName}"); |
| 224 } | 214 } |
| 225 var long = new Directory("${buffer.toString()}"); | 215 var long = new Directory("${buffer.toString()}"); |
| 226 Expect.throws(long.deleteSync); | 216 Expect.throws(long.deleteSync); |
| 227 Expect.throws(() => long.deleteSync(recursive:true)); | 217 Expect.throws(() => long.deleteRecursivelySync()); |
| 228 } | 218 } |
| 229 | 219 |
| 230 static void testExistsCreateDelete() { | 220 static void testExistsCreateDelete() { |
| 231 Directory d = new Directory(""); | 221 Directory d = new Directory(""); |
| 232 d.createTempHandler = () { | 222 d.createTemp(() { |
| 233 d.existsHandler = (bool exists) { | 223 d.exists((bool exists) { |
| 234 Expect.isTrue(exists); | 224 Expect.isTrue(exists); |
| 235 Directory created = new Directory("${d.path}/subdir"); | 225 Directory created = new Directory("${d.path}/subdir"); |
| 236 created.createHandler = () { | 226 created.create(() { |
| 237 created.existsHandler = (bool exists) { | 227 created.exists((bool exists) { |
| 238 Expect.isTrue(exists); | 228 Expect.isTrue(exists); |
| 239 created.deleteHandler = () { | 229 created.delete(() { |
| 240 created.existsHandler = (bool exists) { | 230 created.exists((bool exists) { |
| 241 Expect.isFalse(exists); | 231 Expect.isFalse(exists); |
| 242 d.deleteHandler = () { | 232 d.delete(() { |
| 243 d.existsHandler = (bool exists) { | 233 d.exists((bool exists) { |
| 244 Expect.isFalse(exists); | 234 Expect.isFalse(exists); |
| 245 }; | 235 }); |
| 246 d.exists(); | 236 }); |
| 247 }; | 237 }); |
| 248 d.delete(); | 238 }); |
| 249 }; | 239 }); |
| 250 created.exists(); | 240 }); |
| 251 }; | 241 }); |
| 252 created.delete(); | 242 }); |
| 253 }; | |
| 254 created.exists(); | |
| 255 }; | |
| 256 created.create(); | |
| 257 }; | |
| 258 d.exists(); | |
| 259 }; | |
| 260 d.createTemp(); | |
| 261 } | 243 } |
| 262 | 244 |
| 263 static void testExistsCreateDeleteSync() { | 245 static void testExistsCreateDeleteSync() { |
| 264 Directory d = new Directory(""); | 246 Directory d = new Directory(""); |
| 265 d.createTempSync(); | 247 d.createTempSync(); |
| 266 Expect.isTrue(d.existsSync()); | 248 Expect.isTrue(d.existsSync()); |
| 267 Directory created = new Directory("${d.path}/subdir"); | 249 Directory created = new Directory("${d.path}/subdir"); |
| 268 created.createSync(); | 250 created.createSync(); |
| 269 Expect.isTrue(created.existsSync()); | 251 Expect.isTrue(created.existsSync()); |
| 270 created.deleteSync(); | 252 created.deleteSync(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 281 bool emptyTemplateTestRunning = false; | 263 bool emptyTemplateTestRunning = false; |
| 282 | 264 |
| 283 // Stages 0 through 2 run twice, the second time with an empty path. | 265 // Stages 0 through 2 run twice, the second time with an empty path. |
| 284 Function stage0; | 266 Function stage0; |
| 285 Function stage1a; | 267 Function stage1a; |
| 286 Function stage1b; | 268 Function stage1b; |
| 287 Function stage2; | 269 Function stage2; |
| 288 Function stage3; // Loops to stage 0. | 270 Function stage3; // Loops to stage 0. |
| 289 | 271 |
| 290 Function error(String message) { | 272 Function error(String message) { |
| 291 Expect.fail("Directory errorHandler: $message"); | 273 Expect.fail("Directory onError: $message"); |
| 292 } | 274 } |
| 293 | 275 |
| 294 stage0 = () { | 276 stage0 = () { |
| 295 tempDir1.createTempHandler = stage1a; | 277 tempDir1.onError = error; |
| 296 tempDir1.errorHandler = error; | 278 tempDir1.createTemp(stage1a); |
| 297 tempDir1.createTemp(); | 279 tempDir2.onError = error; |
| 298 tempDir2.createTempHandler = stage1b; | 280 tempDir2.createTemp(stage1b); |
| 299 tempDir2.errorHandler = error; | |
| 300 tempDir2.createTemp(); | |
| 301 }; | 281 }; |
| 302 | 282 |
| 303 stage1a = () { | 283 stage1a = () { |
| 304 stage1aDone = true; | 284 stage1aDone = true; |
| 305 Expect.isTrue(tempDir1.existsSync()); | 285 Expect.isTrue(tempDir1.existsSync()); |
| 306 if (stage1bDone) { | 286 if (stage1bDone) { |
| 307 stage2(); | 287 stage2(); |
| 308 } | 288 } |
| 309 }; | 289 }; |
| 310 | 290 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 341 if (new Directory("/tmp").existsSync()) { | 321 if (new Directory("/tmp").existsSync()) { |
| 342 stage0(); | 322 stage0(); |
| 343 } else { | 323 } else { |
| 344 emptyTemplateTestRunning = true; | 324 emptyTemplateTestRunning = true; |
| 345 stage3(); | 325 stage3(); |
| 346 } | 326 } |
| 347 } | 327 } |
| 348 | 328 |
| 349 static void testCreateDeleteTemp() { | 329 static void testCreateDeleteTemp() { |
| 350 Directory tempDirectory = new Directory(""); | 330 Directory tempDirectory = new Directory(""); |
| 351 tempDirectory.createTempHandler = () { | 331 tempDirectory.createTemp(() { |
| 352 String filename = tempDirectory.path + | 332 String filename = tempDirectory.path + |
| 353 new Platform().pathSeparator() + "dart_testfile"; | 333 new Platform().pathSeparator() + "dart_testfile"; |
| 354 File file = new File(filename); | 334 File file = new File(filename); |
| 355 Expect.isFalse(file.existsSync()); | 335 Expect.isFalse(file.existsSync()); |
| 356 file.errorHandler = (error) { | 336 file.onError = (error) { |
| 357 Expect.fail("testCreateTemp file.errorHandler called: $error"); | 337 Expect.fail("testCreateTemp file.onError called: $error"); |
| 358 }; | 338 }; |
| 359 file.createHandler = () { | 339 file.create(() { |
| 360 file.existsHandler = (bool exists) { | 340 file.exists((bool exists) { |
| 361 Expect.isTrue(exists); | 341 Expect.isTrue(exists); |
| 362 // Try to delete the directory containing the file - should throw. | 342 // Try to delete the directory containing the file - should throw. |
| 363 Expect.throws(tempDirectory.deleteSync); | 343 Expect.throws(tempDirectory.deleteSync); |
| 364 Expect.isTrue(tempDirectory.existsSync()); | 344 Expect.isTrue(tempDirectory.existsSync()); |
| 365 | 345 |
| 366 // Delete the file, and then delete the directory. | 346 // Delete the file, and then delete the directory. |
| 367 file.deleteHandler = () { | 347 file.delete(() { |
| 368 tempDirectory.deleteSync(); | 348 tempDirectory.deleteSync(); |
| 369 Expect.isFalse(tempDirectory.existsSync()); | 349 Expect.isFalse(tempDirectory.existsSync()); |
| 370 }; | 350 }); |
| 371 file.delete(); | 351 }); |
| 372 }; | 352 }); |
| 373 file.exists(); | 353 }); |
| 374 }; | |
| 375 file.create(); | |
| 376 }; | |
| 377 tempDirectory.createTemp(); | |
| 378 } | 354 } |
| 379 | 355 |
| 380 static void testMain() { | 356 static void testMain() { |
| 381 testListing(); | 357 testListing(); |
| 382 testListNonExistent(); | 358 testListNonExistent(); |
| 383 testListTooLongName(); | 359 testListTooLongName(); |
| 384 testDeleteNonExistent(); | 360 testDeleteNonExistent(); |
| 385 testDeleteTooLongName(); | 361 testDeleteTooLongName(); |
| 386 testDeleteNonExistentSync(); | 362 testDeleteNonExistentSync(); |
| 387 testDeleteTooLongNameSync(); | 363 testDeleteTooLongNameSync(); |
| 388 testExistsCreateDelete(); | 364 testExistsCreateDelete(); |
| 389 testExistsCreateDeleteSync(); | 365 testExistsCreateDeleteSync(); |
| 390 testCreateTemp(); | 366 testCreateTemp(); |
| 391 testCreateDeleteTemp(); | 367 testCreateDeleteTemp(); |
| 392 } | 368 } |
| 393 } | 369 } |
| 394 | 370 |
| 395 | 371 |
| 396 class NestedTempDirectoryTest { | 372 class NestedTempDirectoryTest { |
| 397 List<Directory> createdDirectories; | 373 List<Directory> createdDirectories; |
| 398 Directory current; | 374 Directory current; |
| 399 | 375 |
| 400 NestedTempDirectoryTest.run() | 376 NestedTempDirectoryTest.run() |
| 401 : createdDirectories = new List<Directory>(), | 377 : createdDirectories = new List<Directory>(), |
| 402 current = new Directory("") { | 378 current = new Directory("") { |
| 403 current.createTempHandler = createPhaseCallback; | 379 current.onError = errorCallback; |
| 404 current.errorHandler = errorCallback; | 380 current.createTemp(createPhaseCallback); |
| 405 current.createTemp(); | |
| 406 } | 381 } |
| 407 | 382 |
| 408 void errorCallback(error) { | 383 void errorCallback(error) { |
| 409 Expect.fail("Error callback called in NestedTempDirectoryTest: $error"); | 384 Expect.fail("Error callback called in NestedTempDirectoryTest: $error"); |
| 410 } | 385 } |
| 411 | 386 |
| 412 void createPhaseCallback() { | 387 void createPhaseCallback() { |
| 413 createdDirectories.add(current); | 388 createdDirectories.add(current); |
| 414 int nestingDepth = 6; | 389 int nestingDepth = 6; |
| 415 var os = new Platform().operatingSystem(); | 390 var os = new Platform().operatingSystem(); |
| 416 if (os == "windows") nestingDepth = 2; | 391 if (os == "windows") nestingDepth = 2; |
| 417 if (createdDirectories.length < nestingDepth) { | 392 if (createdDirectories.length < nestingDepth) { |
| 418 current = new Directory( | 393 current = new Directory( |
| 419 current.path + "/nested_temp_dir_${createdDirectories.length}_"); | 394 current.path + "/nested_temp_dir_${createdDirectories.length}_"); |
| 420 current.errorHandler = errorCallback; | 395 current.onError = errorCallback; |
| 421 current.createTempHandler = createPhaseCallback; | 396 current.createTemp(createPhaseCallback); |
| 422 current.createTemp(); | |
| 423 } else { | 397 } else { |
| 424 deletePhaseCallback(); | 398 deletePhaseCallback(); |
| 425 } | 399 } |
| 426 } | 400 } |
| 427 | 401 |
| 428 void deletePhaseCallback() { | 402 void deletePhaseCallback() { |
| 429 if (!createdDirectories.isEmpty()) { | 403 if (!createdDirectories.isEmpty()) { |
| 430 current = createdDirectories.removeLast(); | 404 current = createdDirectories.removeLast(); |
| 431 current.deleteSync(); | 405 current.deleteSync(); |
| 432 deletePhaseCallback(); | 406 deletePhaseCallback(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 testCreateTempError() { | 439 testCreateTempError() { |
| 466 var location = illegalTempDirectoryLocation(); | 440 var location = illegalTempDirectoryLocation(); |
| 467 if (location == null) return; | 441 if (location == null) return; |
| 468 | 442 |
| 469 var resultPort = new ReceivePort.singleShot(); | 443 var resultPort = new ReceivePort.singleShot(); |
| 470 resultPort.receive((String message, ignored) { | 444 resultPort.receive((String message, ignored) { |
| 471 Expect.equals("error", message); | 445 Expect.equals("error", message); |
| 472 }); | 446 }); |
| 473 | 447 |
| 474 Directory dir = new Directory(location); | 448 Directory dir = new Directory(location); |
| 475 dir.errorHandler = (error) { resultPort.toSendPort().send("error"); }; | 449 dir.onError = (error) { resultPort.toSendPort().send("error"); }; |
| 476 dir.createTempHandler = () { resultPort.toSendPort().send("success"); }; | 450 dir.createTemp(() => resultPort.toSendPort().send("success")); |
| 477 dir.createTemp(); | |
| 478 } | 451 } |
| 479 | 452 |
| 480 | 453 |
| 481 main() { | 454 main() { |
| 482 DirectoryTest.testMain(); | 455 DirectoryTest.testMain(); |
| 483 NestedTempDirectoryTest.testMain(); | 456 NestedTempDirectoryTest.testMain(); |
| 484 testCreateTempErrorSync(); | 457 testCreateTempErrorSync(); |
| 485 testCreateTempError(); | 458 testCreateTempError(); |
| 486 } | 459 } |
| OLD | NEW |