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 #import('fuzz_support.dart'); | 11 #import('fuzz_support.dart'); |
12 | 12 |
13 fuzzSyncMethods() { | 13 fuzzSyncMethods() { |
14 typeMapping.forEach((k, v) { | 14 typeMapping.forEach((k, v) { |
15 doItSync(() { | 15 doItSync(() { |
16 var f = new File(v); | 16 var f = new File(v); |
17 doItSync(f.existsSync); | 17 doItSync(f.existsSync); |
18 doItSync(f.createSync); | 18 doItSync(f.createSync); |
19 doItSync(f.deleteSync); | 19 doItSync(f.deleteSync); |
20 doItSync(f.directorySync); | 20 doItSync(f.directorySync); |
21 doItSync(f.lengthSync); | 21 doItSync(f.lengthSync); |
22 doItSync(f.modifiedSync); | 22 doItSync(f.modifiedSync); |
23 doItSync(f.fullPathSync); | 23 doItSync(f.fullPathSync); |
24 doItSync(() => f.openInputStream().onError = (e) => null); | 24 doItSync(() => f.openInputStream().onError = (e) => null); |
25 doItSync(f.readAsBytesSync); | 25 doItSync(f.readAsBytesSync); |
26 doItSync(f.readAsTextSync); | 26 doItSync(f.readAsStringSync); |
27 doItSync(f.readAsLinesSync); | 27 doItSync(f.readAsLinesSync); |
28 typeMapping.forEach((k2, v2) { | 28 typeMapping.forEach((k2, v2) { |
29 doItSync(() => f.openSync(v2)); | 29 doItSync(() => f.openSync(v2)); |
30 doItSync(() => f.openOutputStream(v2).onError = (e) => null); | 30 doItSync(() => f.openOutputStream(v2).onError = (e) => null); |
31 doItSync(() => f.readAsTextSync(v2)); | 31 doItSync(() => f.readAsStringSync(v2)); |
32 doItSync(() => f.readAsLinesSync(v2)); | 32 doItSync(() => f.readAsLinesSync(v2)); |
33 }); | 33 }); |
34 }); | 34 }); |
35 }); | 35 }); |
36 } | 36 } |
37 | 37 |
38 fuzzAsyncMethods() { | 38 fuzzAsyncMethods() { |
39 var port = new ReceivePort(); | 39 var port = new ReceivePort(); |
40 var futures = []; | 40 var futures = []; |
41 typeMapping.forEach((k, v) { | 41 typeMapping.forEach((k, v) { |
42 doItSync(() { | 42 doItSync(() { |
43 var f = new File(v); | 43 var f = new File(v); |
44 futures.add(doItAsync(f.exists)); | 44 futures.add(doItAsync(f.exists)); |
45 futures.add(doItAsync(f.delete)); | 45 futures.add(doItAsync(f.delete)); |
46 futures.add(doItAsync(f.directory)); | 46 futures.add(doItAsync(f.directory)); |
47 futures.add(doItAsync(f.length)); | 47 futures.add(doItAsync(f.length)); |
48 futures.add(doItAsync(f.modified)); | 48 futures.add(doItAsync(f.modified)); |
49 futures.add(doItAsync(f.open)); | 49 futures.add(doItAsync(f.open)); |
50 futures.add(doItAsync(f.fullPath)); | 50 futures.add(doItAsync(f.fullPath)); |
51 futures.add(doItAsync(f.readAsBytes)); | 51 futures.add(doItAsync(f.readAsBytes)); |
52 futures.add(doItAsync(f.readAsLines)); | 52 futures.add(doItAsync(f.readAsLines)); |
53 futures.add(doItAsync(f.readAsText)); | 53 futures.add(doItAsync(f.readAsString)); |
54 typeMapping.forEach((k2, v2) { | 54 typeMapping.forEach((k2, v2) { |
55 futures.add(doItAsync(() => f.open(v2))); | 55 futures.add(doItAsync(() => f.open(v2))); |
56 futures.add(doItAsync(() => f.readAsText(v2))); | 56 futures.add(doItAsync(() => f.readAsString(v2))); |
57 futures.add(doItAsync(() => f.readAsLines(v2))); | 57 futures.add(doItAsync(() => f.readAsLines(v2))); |
58 }); | 58 }); |
59 }); | 59 }); |
60 }); | 60 }); |
61 Futures.wait(futures).then((ignore) => port.close()); | 61 Futures.wait(futures).then((ignore) => port.close()); |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 fuzzSyncRandomAccessMethods() { | 65 fuzzSyncRandomAccessMethods() { |
66 var d = new Directory(''); | 66 var d = new Directory(''); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 temp.deleteSync(recursive: true); | 118 temp.deleteSync(recursive: true); |
119 }); | 119 }); |
120 } | 120 } |
121 | 121 |
122 main() { | 122 main() { |
123 fuzzSyncMethods(); | 123 fuzzSyncMethods(); |
124 fuzzAsyncMethods(); | 124 fuzzAsyncMethods(); |
125 fuzzSyncRandomAccessMethods(); | 125 fuzzSyncRandomAccessMethods(); |
126 fuzzAsyncRandomAccessMethods(); | 126 fuzzAsyncRandomAccessMethods(); |
127 } | 127 } |
OLD | NEW |