| 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'; |
| 11 import "package:expect/expect.dart"; |
| 11 | 12 |
| 12 import 'fuzz_support.dart'; | 13 import 'fuzz_support.dart'; |
| 13 | 14 |
| 14 fuzzSyncMethods() { | 15 fuzzSyncMethods() { |
| 15 typeMapping.forEach((k, v) { | 16 typeMapping.forEach((k, v) { |
| 16 doItSync(() { | 17 doItSync(() { |
| 17 var d = new Directory(v); | 18 var d = new Directory(v); |
| 18 doItSync(d.existsSync); | 19 doItSync(d.existsSync); |
| 19 doItSync(d.createSync); | 20 doItSync(d.createSync); |
| 20 doItSync(d.deleteSync); | 21 doItSync(d.deleteSync); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 doItSync(() => d.listSync(recursive: v2)); | 33 doItSync(() => d.listSync(recursive: v2)); |
| 33 }); | 34 }); |
| 34 }); | 35 }); |
| 35 }); | 36 }); |
| 36 } | 37 } |
| 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) { |
| 43 if (v is! String) { |
| 44 Expect.throws(() => new Directory(v), |
| 45 (e) => e is ArgumentError); |
| 46 return; |
| 47 } |
| 42 var d = new Directory(v); | 48 var d = new Directory(v); |
| 43 futures.add(doItAsync(d.exists)); | 49 futures.add(doItAsync(d.exists)); |
| 44 futures.add(doItAsync(d.create)); | 50 futures.add(doItAsync(d.create)); |
| 45 futures.add(doItAsync(d.delete)); | 51 futures.add(doItAsync(d.delete)); |
| 46 futures.add(doItAsync(() { | 52 futures.add(doItAsync(() { |
| 47 return d.createTemp().then((temp) { | 53 return d.createTemp().then((temp) { |
| 48 return temp.delete(); | 54 return temp.delete(); |
| 49 }); | 55 }); |
| 50 })); | 56 })); |
| 51 futures.add(doItAsync(() { | 57 futures.add(doItAsync(() { |
| 52 return d.exists().then((res) { | 58 return d.exists().then((res) { |
| 53 if (!res) return d.delete(recursive: true); | 59 if (!res) return d.delete(recursive: true); |
| 54 return new Future.value(true); | 60 return new Future.value(true); |
| 55 }); | 61 }); |
| 56 })); | 62 })); |
| 57 typeMapping.forEach((k2, v2) { | 63 typeMapping.forEach((k2, v2) { |
| 58 futures.add(doItAsync(() => d.rename(v2))); | 64 futures.add(doItAsync(() => d.rename(v2))); |
| 59 futures.add(doItAsync(() { | 65 futures.add(doItAsync(() { |
| 60 d.list(recursive: v2).listen((_) {}, onError: (e) => null); | 66 d.list(recursive: v2).listen((_) {}, onError: (e) => null); |
| 61 })); | 67 })); |
| 62 }); | 68 }); |
| 63 }); | 69 }); |
| 64 Future.wait(futures).then((ignore) => port.close()); | 70 Future.wait(futures).then((ignore) => port.close()); |
| 65 } | 71 } |
| 66 | 72 |
| 67 main() { | 73 main() { |
| 68 fuzzSyncMethods(); | 74 fuzzSyncMethods(); |
| 69 fuzzAsyncMethods(); | 75 fuzzAsyncMethods(); |
| 70 } | 76 } |
| OLD | NEW |