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

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

Issue 11364097: Allow Directory.create to create all missing path components. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload Created 8 years, 1 month 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: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 d = new Directory(v); 16 var d = new Directory(v);
17 doItSync(d.existsSync); 17 doItSync(d.existsSync);
18 doItSync(d.createSync); 18 doItSync(d.createSync);
19 doItSync(d.deleteSync); 19 doItSync(d.deleteSync);
20 doItSync(() { 20 doItSync(() {
21 d.createTempSync().deleteSync(); 21 d.createTempSync().deleteSync();
22 }); 22 });
23 doItSync(() { 23 doItSync(() {
24 // Let's be a little careful. If the directory exists we don't 24 // Let's be a little careful. If the directory exists we don't
25 // want to delete it and all its contents. 25 // want to delete it and all its contents.
26 if (!d.existsSync()) d.deleteRecursivelySync(); 26 if (!d.existsSync()) d.deleteSync(recursive: true);
27 }); 27 });
28 typeMapping.forEach((k2, v2) { 28 typeMapping.forEach((k2, v2) {
29 doItSync(() => d.renameSync(v2)); 29 doItSync(() => d.renameSync(v2));
30 doItSync(() => d.list(v2).onError = (e) => null); 30 doItSync(() => d.list(v2).onError = (e) => null);
31 }); 31 });
32 }); 32 });
33 }); 33 });
34 } 34 }
35 35
36 fuzzAsyncMethods() { 36 fuzzAsyncMethods() {
37 var port = new ReceivePort(); 37 var port = new ReceivePort();
38 var futures = []; 38 var futures = [];
39 typeMapping.forEach((k, v) { 39 typeMapping.forEach((k, v) {
40 var d = new Directory(v); 40 var d = new Directory(v);
41 futures.add(doItAsync(d.exists)); 41 futures.add(doItAsync(d.exists));
42 futures.add(doItAsync(d.create)); 42 futures.add(doItAsync(d.create));
43 futures.add(doItAsync(d.delete)); 43 futures.add(doItAsync(d.delete));
44 futures.add(doItAsync(() { 44 futures.add(doItAsync(() {
45 return d.createTemp().chain((temp) { 45 return d.createTemp().chain((temp) {
46 return temp.delete(); 46 return temp.delete();
47 }); 47 });
48 })); 48 }));
49 futures.add(doItAsync(() { 49 futures.add(doItAsync(() {
50 return d.exists().chain((res) { 50 return d.exists().chain((res) {
51 if (!res) return d.deleteRecursively(); 51 if (!res) return d.delete(recursive: true);
52 return new Future.immediate(true); 52 return new Future.immediate(true);
53 }); 53 });
54 })); 54 }));
55 typeMapping.forEach((k2, v2) { 55 typeMapping.forEach((k2, v2) {
56 futures.add(doItAsync(() => d.rename(v2))); 56 futures.add(doItAsync(() => d.rename(v2)));
57 }); 57 });
58 }); 58 });
59 Futures.wait(futures).then((ignore) => port.close()); 59 Futures.wait(futures).then((ignore) => port.close());
60 } 60 }
61 61
62 main() { 62 main() {
63 fuzzSyncMethods(); 63 fuzzSyncMethods();
64 fuzzAsyncMethods(); 64 fuzzAsyncMethods();
65 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698