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

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

Issue 10392023: Change dart:io to use Future for one-shot operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use defaults in more of File again. 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
Index: tests/standalone/io/file_invalid_arguments_test.dart
diff --git a/tests/standalone/io/file_invalid_arguments_test.dart b/tests/standalone/io/file_invalid_arguments_test.dart
index c2add31d588a3c4f0f2d841bba46b96f92e3d155..3f064b2b1183a35199d40b2be7a2766415146b4e 100644
--- a/tests/standalone/io/file_invalid_arguments_test.dart
+++ b/tests/standalone/io/file_invalid_arguments_test.dart
@@ -14,10 +14,12 @@ class FileTest {
Expect.isTrue(e is IllegalArgumentException);
}
- file.onError = (e) {
+ var openFuture = file.open(FileMode.READ);
+ openFuture.handleException((e) {
Expect.isTrue(e is IllegalArgumentException);
- };
- file.open(FileMode.READ, (opened) {
+ return true;
+ });
+ openFuture.then((opened) {
Expect.fail('non-string name open');
});
}
@@ -31,10 +33,12 @@ class FileTest {
Expect.isTrue(e is IllegalArgumentException);
}
- file.onError = (e) {
+ var existsFuture = file.exists();
+ existsFuture.handleException((e) {
Expect.isTrue(e is IllegalArgumentException);
- };
- file.exists((bool) {
+ return true;
+ });
+ existsFuture.then((bool) {
Expect.fail('non-string name exists');
});
}
@@ -48,8 +52,12 @@ class FileTest {
Expect.isTrue(e is IllegalArgumentException);
}
- file.onError = (e) => Expect.isTrue(e is IllegalArgumentException);
- file.create(() => Expect.fail('non-string name exists'));
+ var createFuture = file.create();
+ createFuture.handleException((e) {
+ Expect.isTrue(e is IllegalArgumentException);
+ return true;
+ });
+ createFuture.then((ignore) => Expect.fail('non-string name exists'));
}
static void testReadListInvalidArgs(buffer, offset, length) {
@@ -64,15 +72,17 @@ class FileTest {
}
var errors = 0;
- file.onError = (s) {
+ var readListFuture = file.readList(buffer, offset, length);
+ readListFuture.handleException((e) {
errors++;
- Expect.isTrue(s is FileIOException);
- Expect.isTrue(s.toString().contains('Invalid arguments'));
- file.close(() {
+ Expect.isTrue(e is FileIOException);
+ Expect.isTrue(e.toString().contains('Invalid arguments'));
+ file.close().then((ignore) {
Expect.equals(1, errors);
});
- };
- file.readList(buffer, offset, length, (bytes) {
+ return true;
+ });
+ readListFuture.then((bytes) {
Expect.fail('read list invalid arguments');
});
}
@@ -88,20 +98,16 @@ class FileTest {
Expect.isTrue(e.toString().contains('Invalid argument'));
}
- var errors = 0;
- file.onError = (s) {
- errors++;
+ var writeByteFuture = file.writeByte(value);
+ writeByteFuture.then((ignore) {
+ Expect.fail('write list invalid argument');
ricow1 2012/05/10 11:48:01 this is write byte, not write list
Mads Ager (google) 2012/05/10 12:42:38 Good catch! Done.
+ });
+ writeByteFuture.handleException((s) {
Expect.isTrue(s is FileIOException);
Expect.isTrue(s.toString().contains('Invalid argument'));
- file.close(() {
- Expect.equals(1, errors);
- });
- };
- var calls = 0;
- file.writeByte(value);
- file.onNoPendingWrites = () {
- if (++calls > 1) Expect.fail('write list invalid argument');
- };
+ file.close();
+ return true;
+ });
}
static void testWriteListInvalidArgs(buffer, offset, bytes) {
@@ -115,20 +121,14 @@ class FileTest {
Expect.isTrue(e.toString().contains('Invalid arguments'));
}
- var errors = 0;
- file.onError = (s) {
- errors++;
+ var writeListFuture = file.writeList(buffer, offset, bytes);
+ writeListFuture.then((ignore) => Expect.fail('write string invalid argument'));
ricow1 2012/05/10 11:48:01 long line and this is not write string, it is writ
Mads Ager (google) 2012/05/10 12:42:38 Another good catch. Thanks!
+ writeListFuture.handleException((s) {
Expect.isTrue(s is FileIOException);
Expect.isTrue(s.toString().contains('Invalid arguments'));
- file.close(() {
- Expect.equals(1, errors);
- });
- };
- var calls = 0;
- file.writeList(buffer, offset, bytes);
- file.onNoPendingWrites = () {
- if (++calls > 1) Expect.fail('write string invalid argument');
- };
+ file.close();
+ return true;
+ });
}
static void testWriteStringInvalidArgs(string) {
@@ -168,10 +168,12 @@ class FileTest {
Expect.isTrue(e is IllegalArgumentException);
}
- file.onError = (e) {
+ var fullPathFuture = file.fullPath();
+ fullPathFuture.handleException((e) {
Expect.isTrue(e is IllegalArgumentException);
- };
- file.fullPath((path) {
+ return true;
+ });
+ fullPathFuture.then((path) {
Expect.fail('full path invalid argument');
});
}

Powered by Google App Engine
This is Rietveld 408576698