OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // 'fuzz' test the directory APIs by providing unexpected type |
| 6 // arguments. The test passes if the VM does not crash. |
| 7 |
| 8 #import('dart:io'); |
| 9 #import('dart:isolate'); |
| 10 |
| 11 #import('fuzz_support.dart'); |
| 12 |
| 13 fuzzSyncMethods() { |
| 14 typeMapping.forEach((k, v) { |
| 15 doItSync(() { |
| 16 var d = new Directory(v); |
| 17 doItSync(d.existsSync); |
| 18 doItSync(d.createSync); |
| 19 doItSync(d.deleteSync); |
| 20 doItSync(() { |
| 21 d.createTempSync().deleteSync(); |
| 22 }); |
| 23 doItSync(() { |
| 24 // Let's be a little careful. If the directory exists we don't |
| 25 // want to delete it and all its contents. |
| 26 if (!d.existsSync()) d.deleteRecursivelySync(); |
| 27 }); |
| 28 typeMapping.forEach((k2, v2) { |
| 29 doItSync(() => d.renameSync(v2)); |
| 30 doItSync(() => d.list(v2).onError = (e) => null); |
| 31 }); |
| 32 }); |
| 33 }); |
| 34 } |
| 35 |
| 36 fuzzAsyncMethods() { |
| 37 var port = new ReceivePort(); |
| 38 var futures = []; |
| 39 typeMapping.forEach((k, v) { |
| 40 var d = new Directory(v); |
| 41 futures.add(doItAsync(d.exists)); |
| 42 futures.add(doItAsync(d.create)); |
| 43 futures.add(doItAsync(d.delete)); |
| 44 futures.add(doItAsync(() { |
| 45 return d.createTemp().chain((temp) { |
| 46 return temp.delete(); |
| 47 }); |
| 48 })); |
| 49 futures.add(doItAsync(() { |
| 50 return d.exists().chain((res) { |
| 51 if (!res) return d.deleteRecursively(); |
| 52 return new Future.immediate(true); |
| 53 }); |
| 54 })); |
| 55 typeMapping.forEach((k2, v2) { |
| 56 futures.add(doItAsync(() => d.rename(v2))); |
| 57 }); |
| 58 }); |
| 59 Futures.wait(futures).then((ignore) => port.close()); |
| 60 } |
| 61 |
| 62 main() { |
| 63 fuzzSyncMethods(); |
| 64 fuzzAsyncMethods(); |
| 65 } |
OLD | NEW |