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

Side by Side Diff: tests/standalone/io/directory_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) 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 directory APIs by providing unexpected type 5 // 'fuzz' test the directory APIs by providing unexpected type
6 // arguments. The test passes if the VM does not crash. 6 // arguments. The test 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
11 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart"; 12 import "package:expect/expect.dart";
12 13
13 import 'fuzz_support.dart'; 14 import 'fuzz_support.dart';
14 15
15 fuzzSyncMethods() { 16 fuzzSyncMethods() {
16 typeMapping.forEach((k, v) { 17 typeMapping.forEach((k, v) {
17 doItSync(() { 18 doItSync(() {
18 var d = new Directory(v); 19 var d = new Directory(v);
19 doItSync(d.existsSync); 20 doItSync(d.existsSync);
20 doItSync(d.createSync); 21 doItSync(d.createSync);
21 doItSync(d.deleteSync); 22 doItSync(d.deleteSync);
22 doItSync(d.listSync); 23 doItSync(d.listSync);
23 doItSync(() { 24 doItSync(() {
24 d.createTempSync().deleteSync(); 25 d.createTempSync().deleteSync();
25 }); 26 });
26 doItSync(() { 27 doItSync(() {
27 // Let's be a little careful. If the directory exists we don't 28 // Let's be a little careful. If the directory exists we don't
28 // want to delete it and all its contents. 29 // want to delete it and all its contents.
29 if (!d.existsSync()) d.deleteSync(recursive: true); 30 if (!d.existsSync()) d.deleteSync(recursive: true);
30 }); 31 });
31 typeMapping.forEach((k2, v2) { 32 typeMapping.forEach((k2, v2) {
32 doItSync(() => d.renameSync(v2)); 33 doItSync(() => d.renameSync(v2));
33 doItSync(() => d.listSync(recursive: v2)); 34 doItSync(() => d.listSync(recursive: v2));
34 }); 35 });
35 }); 36 });
36 }); 37 });
37 } 38 }
38 39
39 fuzzAsyncMethods() { 40 fuzzAsyncMethods() {
40 var port = new ReceivePort(); 41 asyncStart();
41 var futures = []; 42 var futures = [];
42 typeMapping.forEach((k, v) { 43 typeMapping.forEach((k, v) {
43 if (v is! String) { 44 if (v is! String) {
44 Expect.throws(() => new Directory(v), 45 Expect.throws(() => new Directory(v),
45 (e) => e is ArgumentError); 46 (e) => e is ArgumentError);
46 return; 47 return;
47 } 48 }
48 var d = new Directory(v); 49 var d = new Directory(v);
49 futures.add(doItAsync(d.exists)); 50 futures.add(doItAsync(d.exists));
50 futures.add(doItAsync(d.create)); 51 futures.add(doItAsync(d.create));
51 futures.add(doItAsync(d.delete)); 52 futures.add(doItAsync(d.delete));
52 futures.add(doItAsync(() { 53 futures.add(doItAsync(() {
53 return d.createTemp().then((temp) { 54 return d.createTemp().then((temp) {
54 return temp.delete(); 55 return temp.delete();
55 }); 56 });
56 })); 57 }));
57 futures.add(doItAsync(() { 58 futures.add(doItAsync(() {
58 return d.exists().then((res) { 59 return d.exists().then((res) {
59 if (!res) return d.delete(recursive: true); 60 if (!res) return d.delete(recursive: true);
60 return new Future.value(true); 61 return new Future.value(true);
61 }); 62 });
62 })); 63 }));
63 typeMapping.forEach((k2, v2) { 64 typeMapping.forEach((k2, v2) {
64 futures.add(doItAsync(() => d.rename(v2))); 65 futures.add(doItAsync(() => d.rename(v2)));
65 futures.add(doItAsync(() { 66 futures.add(doItAsync(() {
66 d.list(recursive: v2).listen((_) {}, onError: (e) => null); 67 d.list(recursive: v2).listen((_) {}, onError: (e) => null);
67 })); 68 }));
68 }); 69 });
69 }); 70 });
70 Future.wait(futures).then((ignore) => port.close()); 71 Future.wait(futures).then((_) => asyncEnd());
71 } 72 }
72 73
73 main() { 74 main() {
74 fuzzSyncMethods(); 75 fuzzSyncMethods();
75 fuzzAsyncMethods(); 76 fuzzAsyncMethods();
76 } 77 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_error_test.dart ('k') | tests/standalone/io/directory_invalid_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698