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 // 'fuzz' test the directory APIs by providing unexpected type | 5 // 'fuzz' test the directory APIs by providing unexpected type |
6 // arguments. The test passes if the VM does not crash. | 6 // arguments. The test passes if the VM does not crash. |
7 | 7 |
8 import "dart:io"; | 8 import 'dart:async'; |
9 import "dart:isolate"; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; |
10 | 11 |
11 import "fuzz_support.dart"; | 12 import 'fuzz_support.dart'; |
12 | 13 |
13 fuzzSyncMethods() { | 14 fuzzSyncMethods() { |
14 typeMapping.forEach((k, v) { | 15 typeMapping.forEach((k, v) { |
15 doItSync(() { | 16 doItSync(() { |
16 var d = new Directory(v); | 17 var d = new Directory(v); |
17 doItSync(d.existsSync); | 18 doItSync(d.existsSync); |
18 doItSync(d.createSync); | 19 doItSync(d.createSync); |
19 doItSync(d.deleteSync); | 20 doItSync(d.deleteSync); |
20 doItSync(d.listSync); | 21 doItSync(d.listSync); |
21 doItSync(() { | 22 doItSync(() { |
(...skipping 15 matching lines...) Expand all Loading... |
37 | 38 |
38 fuzzAsyncMethods() { | 39 fuzzAsyncMethods() { |
39 var port = new ReceivePort(); | 40 var port = new ReceivePort(); |
40 var futures = []; | 41 var futures = []; |
41 typeMapping.forEach((k, v) { | 42 typeMapping.forEach((k, v) { |
42 var d = new Directory(v); | 43 var d = new Directory(v); |
43 futures.add(doItAsync(d.exists)); | 44 futures.add(doItAsync(d.exists)); |
44 futures.add(doItAsync(d.create)); | 45 futures.add(doItAsync(d.create)); |
45 futures.add(doItAsync(d.delete)); | 46 futures.add(doItAsync(d.delete)); |
46 futures.add(doItAsync(() { | 47 futures.add(doItAsync(() { |
47 return d.createTemp().chain((temp) { | 48 return d.createTemp().then((temp) { |
48 return temp.delete(); | 49 return temp.delete(); |
49 }); | 50 }); |
50 })); | 51 })); |
51 futures.add(doItAsync(() { | 52 futures.add(doItAsync(() { |
52 return d.exists().chain((res) { | 53 return d.exists().then((res) { |
53 if (!res) return d.delete(recursive: true); | 54 if (!res) return d.delete(recursive: true); |
54 return new Future.immediate(true); | 55 return new Future.immediate(true); |
55 }); | 56 }); |
56 })); | 57 })); |
57 typeMapping.forEach((k2, v2) { | 58 typeMapping.forEach((k2, v2) { |
58 futures.add(doItAsync(() => d.rename(v2))); | 59 futures.add(doItAsync(() => d.rename(v2))); |
59 }); | 60 }); |
60 }); | 61 }); |
61 Futures.wait(futures).then((ignore) => port.close()); | 62 Futures.wait(futures).then((ignore) => port.close()); |
62 } | 63 } |
63 | 64 |
64 main() { | 65 main() { |
65 fuzzSyncMethods(); | 66 fuzzSyncMethods(); |
66 fuzzAsyncMethods(); | 67 fuzzAsyncMethods(); |
67 } | 68 } |
OLD | NEW |