Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: tests/standalone/io/file_fuzz_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
11 10
12 import 'fuzz_support.dart'; 11 import 'fuzz_support.dart';
13 12
13 import "package:async_helper/async_helper.dart";
14
14 fuzzSyncMethods() { 15 fuzzSyncMethods() {
15 typeMapping.forEach((k, v) { 16 typeMapping.forEach((k, v) {
16 doItSync(() { 17 doItSync(() {
17 var f = new File(v); 18 var f = new File(v);
18 doItSync(f.existsSync); 19 doItSync(f.existsSync);
19 doItSync(f.createSync); 20 doItSync(f.createSync);
20 doItSync(f.deleteSync); 21 doItSync(f.deleteSync);
21 doItSync(f.lengthSync); 22 doItSync(f.lengthSync);
22 doItSync(f.modifiedSync); 23 doItSync(f.modifiedSync);
23 doItSync(f.fullPathSync); 24 doItSync(f.fullPathSync);
24 doItSync(() => f.openRead().listen((_) {}, onError: (e) {})); 25 doItSync(() => f.openRead().listen((_) {}, onError: (e) {}));
25 doItSync(f.readAsBytesSync); 26 doItSync(f.readAsBytesSync);
26 doItSync(f.readAsStringSync); 27 doItSync(f.readAsStringSync);
27 doItSync(f.readAsLinesSync); 28 doItSync(f.readAsLinesSync);
28 typeMapping.forEach((k2, v2) { 29 typeMapping.forEach((k2, v2) {
29 doItSync(() => f.openSync(mode: v2)); 30 doItSync(() => f.openSync(mode: v2));
30 doItSync(() => f.openWrite(mode: v2)); 31 doItSync(() => f.openWrite(mode: v2));
31 doItSync(() => f.readAsStringSync(encoding: v2)); 32 doItSync(() => f.readAsStringSync(encoding: v2));
32 doItSync(() => f.readAsLinesSync(encoding: v2)); 33 doItSync(() => f.readAsLinesSync(encoding: v2));
33 }); 34 });
34 }); 35 });
35 }); 36 });
36 } 37 }
37 38
38 fuzzAsyncMethods() { 39 fuzzAsyncMethods() {
39 var port = new ReceivePort(); 40 asyncStart();
40 var futures = []; 41 var futures = [];
41 typeMapping.forEach((k, v) { 42 typeMapping.forEach((k, v) {
42 doItSync(() { 43 doItSync(() {
43 var f = new File(v); 44 var f = new File(v);
44 futures.add(doItAsync(f.exists)); 45 futures.add(doItAsync(f.exists));
45 futures.add(doItAsync(f.delete)); 46 futures.add(doItAsync(f.delete));
46 futures.add(doItAsync(f.directory)); 47 futures.add(doItAsync(f.directory));
47 futures.add(doItAsync(f.length)); 48 futures.add(doItAsync(f.length));
48 futures.add(doItAsync(f.modified)); 49 futures.add(doItAsync(f.modified));
49 futures.add(doItAsync(f.open)); 50 futures.add(doItAsync(f.open));
50 futures.add(doItAsync(f.fullPath)); 51 futures.add(doItAsync(f.fullPath));
51 futures.add(doItAsync(f.readAsBytes)); 52 futures.add(doItAsync(f.readAsBytes));
52 futures.add(doItAsync(f.readAsLines)); 53 futures.add(doItAsync(f.readAsLines));
53 futures.add(doItAsync(f.readAsString)); 54 futures.add(doItAsync(f.readAsString));
54 typeMapping.forEach((k2, v2) { 55 typeMapping.forEach((k2, v2) {
55 futures.add(doItAsync(() => f.open(mode: v2))); 56 futures.add(doItAsync(() => f.open(mode: v2)));
56 futures.add(doItAsync(() => f.readAsString(encoding: v2))); 57 futures.add(doItAsync(() => f.readAsString(encoding: v2)));
57 futures.add(doItAsync(() => f.readAsLines(encoding: v2))); 58 futures.add(doItAsync(() => f.readAsLines(encoding: v2)));
58 }); 59 });
59 }); 60 });
60 }); 61 });
61 Future.wait(futures).then((ignore) => port.close()); 62 Future.wait(futures).then((_) => asyncEnd());
62 } 63 }
63 64
64 65
65 fuzzSyncRandomAccessMethods() { 66 fuzzSyncRandomAccessMethods() {
66 var d = new Directory(''); 67 var d = new Directory('');
67 var temp = d.createTempSync(); 68 var temp = d.createTempSync();
68 var file = new File('${temp.path}/x'); 69 var file = new File('${temp.path}/x');
69 file.createSync(); 70 file.createSync();
70 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ]; 71 var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ];
71 for (var m in modes) { 72 for (var m in modes) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 temp.deleteSync(recursive: true); 119 temp.deleteSync(recursive: true);
119 }); 120 });
120 } 121 }
121 122
122 main() { 123 main() {
123 fuzzSyncMethods(); 124 fuzzSyncMethods();
124 fuzzAsyncMethods(); 125 fuzzAsyncMethods();
125 fuzzSyncRandomAccessMethods(); 126 fuzzSyncRandomAccessMethods();
126 fuzzAsyncRandomAccessMethods(); 127 fuzzAsyncRandomAccessMethods();
127 } 128 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_error_test.dart ('k') | tests/standalone/io/file_input_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698