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

Unified Diff: tests/standalone/io/directory_fuzz_test.dart

Issue 10408060: Fuzzing of dart:io Directory API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | tests/standalone/io/file_fuzz_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/directory_fuzz_test.dart
diff --git a/tests/standalone/io/directory_fuzz_test.dart b/tests/standalone/io/directory_fuzz_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3aa46d478eb9d51beefdcf4616b99e4602ade2d7
--- /dev/null
+++ b/tests/standalone/io/directory_fuzz_test.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// 'fuzz' test the directory APIs by providing unexpected type
+// arguments. The test passes if the VM does not crash.
+
+#import('dart:io');
+#import('dart:isolate');
+
+#import('fuzz_support.dart');
+
+fuzzSyncMethods() {
+ typeMapping.forEach((k, v) {
+ doItSync(() {
+ var d = new Directory(v);
+ doItSync(d.existsSync);
+ doItSync(d.createSync);
+ doItSync(d.deleteSync);
+ doItSync(() {
+ d.createTempSync().deleteSync();
+ });
+ doItSync(() {
+ // Let's be a little careful. If the directory exists we don't
+ // want to delete it and all its contents.
+ if (!d.existsSync()) d.deleteRecursivelySync();
+ });
+ typeMapping.forEach((k2, v2) {
+ doItSync(() => d.renameSync(v2));
+ doItSync(() => d.list(v2).onError = (e) => null);
+ });
+ });
+ });
+}
+
+fuzzAsyncMethods() {
+ var port = new ReceivePort();
+ var futures = [];
+ typeMapping.forEach((k, v) {
+ var d = new Directory(v);
+ futures.add(doItAsync(d.exists));
+ futures.add(doItAsync(d.create));
+ futures.add(doItAsync(d.delete));
+ futures.add(doItAsync(() {
+ return d.createTemp().chain((temp) {
+ return temp.delete();
+ });
+ }));
+ futures.add(doItAsync(() {
+ return d.exists().chain((res) {
+ if (!res) return d.deleteRecursively();
+ return new Future.immediate(true);
+ });
+ }));
+ typeMapping.forEach((k2, v2) {
+ futures.add(doItAsync(() => d.rename(v2)));
+ });
+ });
+ Futures.wait(futures).then((ignore) => port.close());
+}
+
+main() {
+ fuzzSyncMethods();
+ fuzzAsyncMethods();
+}
« no previous file with comments | « runtime/bin/directory_impl.dart ('k') | tests/standalone/io/file_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698