| 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 file APIs by providing unexpected type arguments. The test | 5 // 'fuzz' test the file APIs by providing unexpected type arguments. The test |
| 6 // passes if the VM does not crash. | 6 // passes if the VM does not crash. |
| 7 | 7 |
| 8 #import('dart:io'); | 8 #import('dart:io'); |
| 9 #import('dart:isolate'); | 9 #import('dart:isolate'); |
| 10 | 10 |
| 11 final typeMapping = const { | 11 #import('fuzz_support.dart'); |
| 12 'null': null, | |
| 13 'int': 0, | |
| 14 'bigint': 18446744073709551617, | |
| 15 'String': 'a', | |
| 16 'FileMode': FileMode.READ, | |
| 17 'num': 0.50, | |
| 18 'List<int>': const [1, 2, 3], | |
| 19 'Map<String, int>': const { "a": 23 } | |
| 20 }; | |
| 21 | |
| 22 typePermutations(int argCount) { | |
| 23 var result = []; | |
| 24 if (argCount == 2) { | |
| 25 typeMapping.forEach((k, v) { | |
| 26 typeMapping.forEach((k2, v2) { | |
| 27 result.add([v, v2]); | |
| 28 }); | |
| 29 }); | |
| 30 } else { | |
| 31 Expect.isTrue(argCount == 3); | |
| 32 typeMapping.forEach((k, v) { | |
| 33 typeMapping.forEach((k2, v2) { | |
| 34 typeMapping.forEach((k3, v3) { | |
| 35 result.add([v, v2, v3]); | |
| 36 }); | |
| 37 }); | |
| 38 }); | |
| 39 } | |
| 40 return result; | |
| 41 } | |
| 42 | |
| 43 // Perform sync operation and ignore all exceptions. | |
| 44 doItSync(Function f) { | |
| 45 try { f(); } catch (var e) {} | |
| 46 } | |
| 47 | |
| 48 // Perform async operation and transform the future for the operation | |
| 49 // into a future that never fails by treating errors as normal | |
| 50 // completion. | |
| 51 Future doItAsync(Function f) { | |
| 52 // Ignore value and errors. | |
| 53 var completer = new Completer(); | |
| 54 var future = f(); | |
| 55 future.handleException((e) { | |
| 56 completer.complete(true); | |
| 57 return true; | |
| 58 }); | |
| 59 future.then((v) => completer.complete(true)); | |
| 60 return completer.future; | |
| 61 } | |
| 62 | 12 |
| 63 fuzzSyncMethods() { | 13 fuzzSyncMethods() { |
| 64 typeMapping.forEach((k, v) { | 14 typeMapping.forEach((k, v) { |
| 65 doItSync(() { | 15 doItSync(() { |
| 66 var f = new File(v); | 16 var f = new File(v); |
| 67 doItSync(f.existsSync); | 17 doItSync(f.existsSync); |
| 68 doItSync(f.createSync); | 18 doItSync(f.createSync); |
| 69 doItSync(f.deleteSync); | 19 doItSync(f.deleteSync); |
| 70 doItSync(f.directorySync); | 20 doItSync(f.directorySync); |
| 71 doItSync(f.lengthSync); | 21 doItSync(f.lengthSync); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 temp.deleteRecursivelySync(); | 116 temp.deleteRecursivelySync(); |
| 167 }); | 117 }); |
| 168 } | 118 } |
| 169 | 119 |
| 170 main() { | 120 main() { |
| 171 fuzzSyncMethods(); | 121 fuzzSyncMethods(); |
| 172 fuzzAsyncMethods(); | 122 fuzzAsyncMethods(); |
| 173 fuzzSyncRandomAccessMethods(); | 123 fuzzSyncRandomAccessMethods(); |
| 174 fuzzAsyncRandomAccessMethods(); | 124 fuzzAsyncRandomAccessMethods(); |
| 175 } | 125 } |
| OLD | NEW |