| 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; |
| 11 | 11 |
| 12 Directory directory = new Directory(""); | 12 Directory directory = new Directory(""); |
| 13 directory.createTempSync(); | 13 directory.createTempSync(); |
| 14 Directory subDirectory = new Directory("${directory.path}/subdir"); | 14 Directory subDirectory = new Directory("${directory.path}/subdir"); |
| 15 Expect.isFalse(subDirectory.existsSync()); | 15 Expect.isFalse(subDirectory.existsSync()); |
| 16 subDirectory.createSync(); | 16 subDirectory.createSync(); |
| 17 File f = new File('${subDirectory.path}/file.txt'); | 17 File f = new File('${subDirectory.path}/file.txt'); |
| 18 Expect.isFalse(f.existsSync()); | 18 Expect.isFalse(f.existsSync()); |
| 19 f.createSync(); | 19 f.createSync(); |
| 20 | 20 |
| 21 directory.dirHandler = (dir) { | 21 directory.dirHandler = (dir) { |
| 22 print(dir); | |
| 23 listedDir = true; | 22 listedDir = true; |
| 24 Expect.isTrue(dir.contains('subdir')); | 23 Expect.isTrue(dir.contains('subdir')); |
| 25 }; | 24 }; |
| 26 | 25 |
| 27 directory.fileHandler = (f) { | 26 directory.fileHandler = (f) { |
| 28 print(f); | |
| 29 listedFile = true; | 27 listedFile = true; |
| 30 Expect.isTrue(f.contains('subdir')); | 28 Expect.isTrue(f.contains('subdir')); |
| 31 Expect.isTrue(f.contains('file.txt')); | 29 Expect.isTrue(f.contains('file.txt')); |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 directory.doneHandler = (completed) { | 32 directory.doneHandler = (completed) { |
| 35 Expect.isTrue(completed, "directory listing did not complete"); | 33 Expect.isTrue(completed, "directory listing did not complete"); |
| 36 Expect.isTrue(listedDir, "directory not found"); | 34 Expect.isTrue(listedDir, "directory not found"); |
| 37 Expect.isTrue(listedFile, "file not found"); | 35 Expect.isTrue(listedFile, "file not found"); |
| 38 f.deleteHandler = () { | 36 f.deleteHandler = () { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 Directory tempDirectory = new Directory(""); | 141 Directory tempDirectory = new Directory(""); |
| 144 tempDirectory.createTempHandler = () { | 142 tempDirectory.createTempHandler = () { |
| 145 String filename = tempDirectory.path + | 143 String filename = tempDirectory.path + |
| 146 new Platform().pathSeparator() + "dart_testfile"; | 144 new Platform().pathSeparator() + "dart_testfile"; |
| 147 File file = new File(filename); | 145 File file = new File(filename); |
| 148 Expect.isFalse(file.existsSync()); | 146 Expect.isFalse(file.existsSync()); |
| 149 file.errorHandler = (error) { | 147 file.errorHandler = (error) { |
| 150 Expect.fail("testCreateTemp file.errorHandler called: $error"); | 148 Expect.fail("testCreateTemp file.errorHandler called: $error"); |
| 151 }; | 149 }; |
| 152 file.createHandler = () { | 150 file.createHandler = () { |
| 151 file.openHandler = (RandomAccessFile openedFile) { |
| 152 openedFile.writeList([65, 66, 67, 13], 0, 4); |
| 153 openedFile.noPendingWriteHandler = () { |
| 154 openedFile.length(); |
| 155 }; |
| 156 openedFile.lengthHandler = (int length) { |
| 157 Expect.equals(4, length); |
| 158 openedFile.close(); |
| 159 }; |
| 160 openedFile.closeHandler = () { |
| 161 file.exists(); |
| 162 }; |
| 163 file.existsHandler = (bool exists) { |
| 164 Expect.isTrue(exists); |
| 165 // Try to delete the directory containing the file - should throw. |
| 166 bool threw_exception = false; |
| 167 try { |
| 168 tempDirectory.deleteSync(); |
| 169 } catch (var e) { |
| 170 Expect.isTrue(tempDirectory.existsSync()); |
| 171 threw_exception = true; |
| 172 } |
| 173 Expect.isTrue(threw_exception); |
| 174 Expect.isTrue(tempDirectory.existsSync()); |
| 175 |
| 176 // Delete the file, and then delete the directory. |
| 177 file.delete(); |
| 178 }; |
| 179 file.deleteHandler = () { |
| 180 tempDirectory.deleteSync(); |
| 181 Expect.isFalse(tempDirectory.existsSync()); |
| 182 }; |
| 183 }; |
| 153 file.open(writable: true); | 184 file.open(writable: true); |
| 154 }; | 185 }; |
| 155 file.openHandler = () { | |
| 156 file.writeList([65, 66, 67, 13], 0, 4); | |
| 157 }; | |
| 158 file.noPendingWriteHandler = () { | |
| 159 file.length(); | |
| 160 }; | |
| 161 file.lengthHandler = (int length) { | |
| 162 Expect.equals(4, length); | |
| 163 file.close(); | |
| 164 }; | |
| 165 file.closeHandler = () { | |
| 166 file.exists(); | |
| 167 }; | |
| 168 file.existsHandler = (bool exists) { | |
| 169 Expect.isTrue(exists); | |
| 170 // Try to delete the directory containing the file - should throw. | |
| 171 bool threw_exception = false; | |
| 172 try { | |
| 173 tempDirectory.deleteSync(); | |
| 174 } catch (var e) { | |
| 175 Expect.isTrue(tempDirectory.existsSync()); | |
| 176 threw_exception = true; | |
| 177 } | |
| 178 Expect.isTrue(threw_exception); | |
| 179 Expect.isTrue(tempDirectory.existsSync()); | |
| 180 | |
| 181 // Delete the file, and then delete the directory. | |
| 182 file.delete(); | |
| 183 }; | |
| 184 file.deleteHandler = () { | |
| 185 tempDirectory.deleteSync(); | |
| 186 Expect.isFalse(tempDirectory.existsSync()); | |
| 187 }; | |
| 188 | |
| 189 file.create(); | 186 file.create(); |
| 190 }; | 187 }; |
| 191 tempDirectory.createTemp(); | 188 tempDirectory.createTemp(); |
| 192 } | 189 } |
| 193 | 190 |
| 194 static void testNestedTempDirectory() { | 191 static void testNestedTempDirectory() { |
| 195 var test = new NestedTempDirectoryTest(); | 192 var test = new NestedTempDirectoryTest(); |
| 196 } | 193 } |
| 197 | 194 |
| 198 | 195 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 new NestedTempDirectoryTest().startTest(); | 245 new NestedTempDirectoryTest().startTest(); |
| 249 new NestedTempDirectoryTest().startTest(); | 246 new NestedTempDirectoryTest().startTest(); |
| 250 } | 247 } |
| 251 } | 248 } |
| 252 | 249 |
| 253 | 250 |
| 254 main() { | 251 main() { |
| 255 DirectoryTest.testMain(); | 252 DirectoryTest.testMain(); |
| 256 NestedTempDirectoryTest.testMain(); | 253 NestedTempDirectoryTest.testMain(); |
| 257 } | 254 } |
| OLD | NEW |