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 listedSomething = false; | 9 bool listedSomething = false; |
10 Directory directory = new Directory.open("."); | 10 Directory directory = new Directory("."); |
11 | 11 |
12 directory.setDirHandler((dir) { | 12 directory.setDirHandler((dir) { |
13 listedSomething = true; | 13 listedSomething = true; |
14 }); | 14 }); |
15 | 15 |
16 directory.setFileHandler((f) { | 16 directory.setFileHandler((f) { |
17 listedSomething = true; | 17 listedSomething = true; |
18 }); | 18 }); |
19 | 19 |
20 directory.setDoneHandler((completed) { | 20 directory.setDoneHandler((completed) { |
21 Expect.isTrue(completed, "directory listing did not complete"); | 21 Expect.isTrue(completed, "directory listing did not complete"); |
22 Expect.isTrue(listedSomething, "empty directory"); | 22 Expect.isTrue(listedSomething, "empty directory"); |
23 directory.close(); | |
24 }); | 23 }); |
25 | 24 |
26 directory.setDirErrorHandler((dir) { | 25 directory.setErrorHandler((error) { |
27 Expect.fail("error listing directory"); | 26 Expect.fail("error listing directory: $error"); |
28 }); | 27 }); |
29 | 28 |
30 directory.list(); | 29 directory.list(); |
31 | 30 |
32 // Listing is asynchronous, so nothing should be listed at this | 31 // Listing is asynchronous, so nothing should be listed at this |
33 // point. | 32 // point. |
34 Expect.isFalse(listedSomething); | 33 Expect.isFalse(listedSomething); |
35 } | 34 } |
36 | 35 |
37 static void testMain() { | 36 static void testMain() { |
38 testListing(); | 37 testListing(); |
39 } | 38 } |
40 } | 39 } |
41 | 40 |
42 main() { | 41 main() { |
43 DirectoryTest.testMain(); | 42 DirectoryTest.testMain(); |
44 } | 43 } |
OLD | NEW |