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:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 12 matching lines...) Expand all Loading... |
23 d.createTempSync().deleteSync(); | 23 d.createTempSync().deleteSync(); |
24 }); | 24 }); |
25 doItSync(() { | 25 doItSync(() { |
26 // Let's be a little careful. If the directory exists we don't | 26 // Let's be a little careful. If the directory exists we don't |
27 // want to delete it and all its contents. | 27 // want to delete it and all its contents. |
28 if (!d.existsSync()) d.deleteSync(recursive: true); | 28 if (!d.existsSync()) d.deleteSync(recursive: true); |
29 }); | 29 }); |
30 typeMapping.forEach((k2, v2) { | 30 typeMapping.forEach((k2, v2) { |
31 doItSync(() => d.renameSync(v2)); | 31 doItSync(() => d.renameSync(v2)); |
32 doItSync(() => d.listSync(recursive: v2)); | 32 doItSync(() => d.listSync(recursive: v2)); |
33 doItSync(() => d.list(recursive: v2).onError = (e) => null); | |
34 }); | 33 }); |
35 }); | 34 }); |
36 }); | 35 }); |
37 } | 36 } |
38 | 37 |
39 fuzzAsyncMethods() { | 38 fuzzAsyncMethods() { |
40 var port = new ReceivePort(); | 39 var port = new ReceivePort(); |
41 var futures = []; | 40 var futures = []; |
42 typeMapping.forEach((k, v) { | 41 typeMapping.forEach((k, v) { |
43 var d = new Directory(v); | 42 var d = new Directory(v); |
44 futures.add(doItAsync(d.exists)); | 43 futures.add(doItAsync(d.exists)); |
45 futures.add(doItAsync(d.create)); | 44 futures.add(doItAsync(d.create)); |
46 futures.add(doItAsync(d.delete)); | 45 futures.add(doItAsync(d.delete)); |
47 futures.add(doItAsync(() { | 46 futures.add(doItAsync(() { |
48 return d.createTemp().then((temp) { | 47 return d.createTemp().then((temp) { |
49 return temp.delete(); | 48 return temp.delete(); |
50 }); | 49 }); |
51 })); | 50 })); |
52 futures.add(doItAsync(() { | 51 futures.add(doItAsync(() { |
53 return d.exists().then((res) { | 52 return d.exists().then((res) { |
54 if (!res) return d.delete(recursive: true); | 53 if (!res) return d.delete(recursive: true); |
55 return new Future.immediate(true); | 54 return new Future.immediate(true); |
56 }); | 55 }); |
57 })); | 56 })); |
58 typeMapping.forEach((k2, v2) { | 57 typeMapping.forEach((k2, v2) { |
59 futures.add(doItAsync(() => d.rename(v2))); | 58 futures.add(doItAsync(() => d.rename(v2))); |
| 59 futures.add(doItAsync(() { |
| 60 d.list(recursive: v2).listen((_) {}, onError: (e) => null); |
| 61 })); |
60 }); | 62 }); |
61 }); | 63 }); |
62 Future.wait(futures).then((ignore) => port.close()); | 64 Future.wait(futures).then((ignore) => port.close()); |
63 } | 65 } |
64 | 66 |
65 main() { | 67 main() { |
66 fuzzSyncMethods(); | 68 fuzzSyncMethods(); |
67 fuzzAsyncMethods(); | 69 fuzzAsyncMethods(); |
68 } | 70 } |
OLD | NEW |