OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 var opened = file.openSync(mode: m); | 73 var opened = file.openSync(mode: m); |
74 typeMapping.forEach((k, v) { | 74 typeMapping.forEach((k, v) { |
75 doItSync(() => opened.setPositionSync(v)); | 75 doItSync(() => opened.setPositionSync(v)); |
76 doItSync(() => opened.truncateSync(v)); | 76 doItSync(() => opened.truncateSync(v)); |
77 doItSync(() => opened.writeByteSync(v)); | 77 doItSync(() => opened.writeByteSync(v)); |
78 }); | 78 }); |
79 for (var p in typePermutations(2)) { | 79 for (var p in typePermutations(2)) { |
80 doItSync(() => opened.writeStringSync(p[0], p[1])); | 80 doItSync(() => opened.writeStringSync(p[0], p[1])); |
81 } | 81 } |
82 for (var p in typePermutations(3)) { | 82 for (var p in typePermutations(3)) { |
83 doItSync(() => opened.readListSync(p[0], p[1], p[2])); | 83 doItSync(() => opened.readIntoSync(p[0], p[1], p[2])); |
84 doItSync(() => opened.writeListSync(p[0], p[1], p[2])); | 84 doItSync(() => opened.writeFromSync(p[0], p[1], p[2])); |
85 } | 85 } |
86 opened.closeSync(); | 86 opened.closeSync(); |
87 } | 87 } |
88 temp.deleteSync(recursive: true); | 88 temp.deleteSync(recursive: true); |
89 } | 89 } |
90 | 90 |
91 fuzzAsyncRandomAccessMethods() { | 91 fuzzAsyncRandomAccessMethods() { |
92 var d = new Directory(''); | 92 var d = new Directory(''); |
93 var temp = d.createTempSync(); | 93 var temp = d.createTempSync(); |
94 var file = new File('${temp.path}/x'); | 94 var file = new File('${temp.path}/x'); |
95 file.createSync(); | 95 file.createSync(); |
96 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; | 96 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; |
97 var futures = []; | 97 var futures = []; |
98 var openedFiles = []; | 98 var openedFiles = []; |
99 for (var m in modes) { | 99 for (var m in modes) { |
100 var opened = file.openSync(mode: m); | 100 var opened = file.openSync(mode: m); |
101 openedFiles.add(opened); | 101 openedFiles.add(opened); |
102 typeMapping.forEach((k, v) { | 102 typeMapping.forEach((k, v) { |
103 futures.add(doItAsync(() => opened.setPosition(v))); | 103 futures.add(doItAsync(() => opened.setPosition(v))); |
104 futures.add(doItAsync(() => opened.truncate(v))); | 104 futures.add(doItAsync(() => opened.truncate(v))); |
105 futures.add(doItAsync(() => opened.writeByte(v))); | 105 futures.add(doItAsync(() => opened.writeByte(v))); |
106 }); | 106 }); |
107 for (var p in typePermutations(2)) { | 107 for (var p in typePermutations(2)) { |
108 futures.add(doItAsync(() => opened.writeString(p[0], p[1]))); | 108 futures.add(doItAsync(() => opened.writeString(p[0], p[1]))); |
109 } | 109 } |
110 for (var p in typePermutations(3)) { | 110 for (var p in typePermutations(3)) { |
111 futures.add(doItAsync(() => opened.readList(p[0], p[1], p[2]))); | 111 futures.add(doItAsync(() => opened.readInto(p[0], p[1], p[2]))); |
112 futures.add(doItAsync(() => opened.writeList(p[0], p[1], p[2]))); | 112 futures.add(doItAsync(() => opened.writeFrom(p[0], p[1], p[2]))); |
113 } | 113 } |
114 } | 114 } |
115 Future.wait(futures).then((ignore) { | 115 Future.wait(futures).then((ignore) { |
116 for (var opened in openedFiles) { | 116 for (var opened in openedFiles) { |
117 opened.closeSync(); | 117 opened.closeSync(); |
118 } | 118 } |
119 temp.deleteSync(recursive: true); | 119 temp.deleteSync(recursive: true); |
120 }); | 120 }); |
121 } | 121 } |
122 | 122 |
123 main() { | 123 main() { |
124 fuzzSyncMethods(); | 124 fuzzSyncMethods(); |
125 fuzzAsyncMethods(); | 125 fuzzAsyncMethods(); |
126 fuzzSyncRandomAccessMethods(); | 126 fuzzSyncRandomAccessMethods(); |
127 fuzzAsyncRandomAccessMethods(); | 127 fuzzAsyncRandomAccessMethods(); |
128 } | 128 } |
OLD | NEW |