| 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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 futures.add(doItAsync(() => f.open(v2))); | 103 futures.add(doItAsync(() => f.open(v2))); |
| 104 futures.add(doItAsync(() => f.readAsText(v2))); | 104 futures.add(doItAsync(() => f.readAsText(v2))); |
| 105 futures.add(doItAsync(() => f.readAsLines(v2))); | 105 futures.add(doItAsync(() => f.readAsLines(v2))); |
| 106 }); | 106 }); |
| 107 }); | 107 }); |
| 108 }); | 108 }); |
| 109 Futures.wait(futures).then((ignore) => port.close()); | 109 Futures.wait(futures).then((ignore) => port.close()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 // TODO(ager): Finish implementation. | |
| 114 fuzzSyncRandomAccessMethods() { | 113 fuzzSyncRandomAccessMethods() { |
| 115 var d = new Directory(''); | 114 var d = new Directory(''); |
| 116 var temp = d.createTempSync(); | 115 var temp = d.createTempSync(); |
| 117 var file = new File('${temp.path}/x'); | 116 var file = new File('${temp.path}/x'); |
| 118 file.createSync(); | 117 file.createSync(); |
| 119 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; | 118 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; |
| 120 for (var m in modes) { | 119 for (var m in modes) { |
| 121 var opened = file.openSync(m); | 120 var opened = file.openSync(m); |
| 122 typeMapping.forEach((k, v) { | 121 typeMapping.forEach((k, v) { |
| 123 doItSync(() => opened.setPositionSync(v)); | 122 doItSync(() => opened.setPositionSync(v)); |
| 123 doItSync(() => opened.truncateSync(v)); |
| 124 doItSync(() => opened.writeByteSync(v)); | 124 doItSync(() => opened.writeByteSync(v)); |
| 125 }); | 125 }); |
| 126 for (var p in typePermutations(2)) { | 126 for (var p in typePermutations(2)) { |
| 127 doItSync(() => opened.writeStringSync(p[0], p[1])); | 127 doItSync(() => opened.writeStringSync(p[0], p[1])); |
| 128 } | 128 } |
| 129 for (var p in typePermutations(3)) { | 129 for (var p in typePermutations(3)) { |
| 130 doItSync(() => opened.readListSync(p[0], p[1], p[2])); | 130 doItSync(() => opened.readListSync(p[0], p[1], p[2])); |
| 131 doItSync(() => opened.writeList(p[0], p[1], p[2])); | 131 doItSync(() => opened.writeListSync(p[0], p[1], p[2])); |
| 132 } | 132 } |
| 133 opened.closeSync(); | 133 opened.closeSync(); |
| 134 } | 134 } |
| 135 temp.deleteRecursivelySync(); | 135 temp.deleteRecursivelySync(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 fuzzAsyncRandomAccessMethods() { |
| 139 var d = new Directory(''); |
| 140 var temp = d.createTempSync(); |
| 141 var file = new File('${temp.path}/x'); |
| 142 file.createSync(); |
| 143 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; |
| 144 var futures = []; |
| 145 var openedFiles = []; |
| 146 for (var m in modes) { |
| 147 var opened = file.openSync(m); |
| 148 openedFiles.add(opened); |
| 149 typeMapping.forEach((k, v) { |
| 150 futures.add(doItAsync(() => opened.setPosition(v))); |
| 151 futures.add(doItAsync(() => opened.truncate(v))); |
| 152 futures.add(doItAsync(() => opened.writeByte(v))); |
| 153 }); |
| 154 for (var p in typePermutations(2)) { |
| 155 futures.add(doItAsync(() => opened.writeString(p[0], p[1]))); |
| 156 } |
| 157 for (var p in typePermutations(3)) { |
| 158 futures.add(doItAsync(() => opened.readList(p[0], p[1], p[2]))); |
| 159 futures.add(doItAsync(() => opened.writeList(p[0], p[1], p[2]))); |
| 160 } |
| 161 } |
| 162 Futures.wait(futures).then((ignore) { |
| 163 for (var opened in openedFiles) { |
| 164 opened.closeSync(); |
| 165 } |
| 166 temp.deleteRecursivelySync(); |
| 167 }); |
| 168 } |
| 169 |
| 138 main() { | 170 main() { |
| 139 fuzzSyncMethods(); | 171 fuzzSyncMethods(); |
| 140 fuzzAsyncMethods(); | 172 fuzzAsyncMethods(); |
| 141 fuzzSyncRandomAccessMethods(); | 173 fuzzSyncRandomAccessMethods(); |
| 174 fuzzAsyncRandomAccessMethods(); |
| 142 } | 175 } |
| OLD | NEW |