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

Unified Diff: tests/standalone/src/FileTest.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert temporary edit Created 8 years, 10 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/src/FileTest.dart
diff --git a/tests/standalone/src/FileTest.dart b/tests/standalone/src/FileTest.dart
index 2ce8ac4a2b44f1b2acc84b210f3e9aa3084e5647..cbf0fb7026c0b921c4bcacad6622d30989a667c0 100644
--- a/tests/standalone/src/FileTest.dart
+++ b/tests/standalone/src/FileTest.dart
@@ -28,10 +28,10 @@ class FileTest {
static void createTempDirectory(Function doNext) {
tempDirectory = new Directory('');
- tempDirectory.errorHandler = (e) {
+ tempDirectory.onError = (e) {
Expect.fail("Failed creating temporary directory");
};
- tempDirectory.createTempHandler = doNext;
+ tempDirectory.onCreateTemp = doNext;
tempDirectory.createTemp();
}
@@ -45,7 +45,7 @@ class FileTest {
String filename = getFilename("bin/file_test.cc");
File file = new File(filename);
InputStream input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
List<int> buffer = new List<int>(42);
int bytesRead = input.readInto(buffer, 0, 12);
Expect.equals(12, bytesRead);
@@ -80,7 +80,7 @@ class FileTest {
// Test reading all using readInto.
file = new File(inFilename);
input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
List<int> buffer1 = new List<int>(42);
bytesRead = input.readInto(buffer1, 0, 42);
Expect.equals(42, bytesRead);
@@ -89,7 +89,7 @@ class FileTest {
// Test reading all using readInto and read.
file = new File(inFilename);
input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
bytesRead = input.readInto(buffer1, 0, 21);
Expect.equals(21, bytesRead);
buffer1 = input.read();
@@ -99,7 +99,7 @@ class FileTest {
// Test reading all using read and readInto.
file = new File(inFilename);
input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
buffer1 = input.read(21);
Expect.equals(21, buffer1.length);
bytesRead = input.readInto(buffer1, 0, 21);
@@ -109,7 +109,7 @@ class FileTest {
// Test reading all using read.
file = new File(inFilename);
input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
buffer1 = input.read();
Expect.equals(42, buffer1.length);
Expect.isTrue(input.closed);
@@ -120,21 +120,21 @@ class FileTest {
OutputStream output = file.openOutputStream();
bool writeDone = output.writeFrom(buffer1, 0, 42);
Expect.equals(false, writeDone);
- output.noPendingWriteHandler = () {
+ output.onNoPendingWrite = () {
output.close();
// Now read the contents of the file just written.
List<int> buffer2 = new List<int>(42);
file = new File(outFilename);
input = file.openInputStream();
- input.dataHandler = () {
+ input.onData = () {
bytesRead = input.readInto(buffer2, 0, 42);
Expect.equals(42, bytesRead);
// Now compare the two buffers to check if they are identical.
for (int i = 0; i < buffer1.length; i++) {
Expect.equals(buffer1[i], buffer2[i]);
}
- input.closeHandler = () {
+ input.onClose = () {
// Delete the output file.
file.deleteSync();
Expect.isFalse(file.existsSync());
@@ -152,14 +152,14 @@ class FileTest {
// Read a file and check part of it's contents.
String filename = getFilename("bin/file_test.cc");
File file = new File(filename);
- file.errorHandler = (s) {
+ file.onError = (s) {
Expect.fail("No errors expected : $s");
};
- file.openHandler = (RandomAccessFile file) {
+ file.onOpen = (RandomAccessFile file) {
List<int> buffer = new List<int>(10);
- file.readListHandler = (bytes_read) {
+ file.onReadList = (bytes_read) {
Expect.equals(5, bytes_read);
- file.readListHandler = (bytes_read) {
+ file.onReadList = (bytes_read) {
Expect.equals(5, bytes_read);
Expect.equals(47, buffer[0]); // represents '/' in the file.
Expect.equals(47, buffer[1]); // represents '/' in the file.
@@ -209,47 +209,47 @@ class FileTest {
// Read a file.
String inFilename = getFilename("tests/vm/data/fixed_length_file");
final File file = new File(inFilename);
- file.errorHandler = (s) {
+ file.onError = (s) {
Expect.fail("No errors expected : $s");
};
- file.openHandler = (RandomAccessFile openedFile) {
- openedFile.errorHandler = (s) {
+ file.onOpen = (RandomAccessFile openedFile) {
+ openedFile.onError = (s) {
Expect.fail("No errors expected : $s");
};
List<int> buffer1 = new List<int>(42);
- openedFile.readListHandler = (bytes_read) {
+ openedFile.onReadList = (bytes_read) {
Expect.equals(42, bytes_read);
- openedFile.closeHandler = () {
+ openedFile.onClose = () {
// Write the contents of the file just read into another file.
String outFilename = tempDirectory.path + "/out_read_write";
final File file2 = new File(outFilename);
- file2.errorHandler = (s) {
+ file2.onError = (s) {
Expect.fail("No errors expected : $s");
};
- file2.createHandler = () {
- file2.fullPathHandler = (s) {
+ file2.onCreate = () {
+ file2.onFullPath = (s) {
Expect.isTrue(new File(s).existsSync());
if (s[0] != '/' && s[0] != '\\' && s[1] != ':') {
Expect.fail("Not a full path");
}
- file2.openHandler = (RandomAccessFile openedFile2) {
- openedFile2.errorHandler = (s) {
+ file2.onOpen = (RandomAccessFile openedFile2) {
+ openedFile2.onError = (s) {
Expect.fail("No errors expected : $s");
};
- openedFile2.noPendingWriteHandler = () {
- openedFile2.closeHandler = () {
+ openedFile2.onNoPendingWrite = () {
+ openedFile2.onClose = () {
List<int> buffer2 = new List<int>(bytes_read);
final File file3 = new File(outFilename);
- file3.errorHandler = (s) {
+ file3.onError = (s) {
Expect.fail("No errors expected : $s");
};
- file3.openHandler = (RandomAccessFile openedFile3) {
- openedFile3.errorHandler = (s) {
+ file3.onOpen = (RandomAccessFile openedFile3) {
+ openedFile3.onError = (s) {
Expect.fail("No errors expected : $s");
};
- openedFile3.readListHandler = (bytes_read) {
+ openedFile3.onReadList = (bytes_read) {
Expect.equals(42, bytes_read);
- openedFile3.closeHandler = () {
+ openedFile3.onClose = () {
// Now compare the two buffers to check if they
// are identical.
Expect.equals(buffer1.length, buffer2.length);
@@ -258,8 +258,8 @@ class FileTest {
}
// Delete the output file.
final file4 = file3;
- file4.deleteHandler = () {
- file4.existsHandler = (exists) {
+ file4.onDelete = () {
+ file4.onExists = (exists) {
Expect.isFalse(exists);
asyncTestDone("testReadWrite");
};
@@ -323,20 +323,20 @@ class FileTest {
List<int> buffer = content.charCodes();
OutputStream outStream = file.openOutputStream();
outStream.write(buffer);
- outStream.noPendingWriteHandler = () {
+ outStream.onNoPendingWrite = () {
outStream.close();
File file2 = new File(filename);
OutputStream appendingOutput =
file2.openOutputStream(FileMode.APPEND);
appendingOutput.write(buffer);
- appendingOutput.noPendingWriteHandler = () {
+ appendingOutput.onNoPendingWrite = () {
appendingOutput.close();
File file3 = new File(filename);
- file3.openHandler = (RandomAccessFile openedFile) {
- openedFile.lengthHandler = (int length) {
+ file3.onOpen = (RandomAccessFile openedFile) {
+ openedFile.onLength = (int length) {
Expect.equals(content.length * 2, length);
- openedFile.closeHandler = () {
- file3.deleteHandler = () {
+ openedFile.onClose = () {
+ file3.onDelete = () {
asyncTestDone("testOutputStreamWriteAppend");
};
file3.delete();
@@ -403,18 +403,18 @@ class FileTest {
static void testReadEmptyFile() {
String fileName = tempDirectory.path + "/empty_file";
File file = new File(fileName);
- file.errorHandler = (s) {
+ file.onError = (s) {
Expect.fail("No errors expected : $s");
};
- file.createHandler = () {
- file.openHandler = (RandomAccessFile openedFile) {
- openedFile.readByteHandler = (int byte) {
+ file.onCreate = () {
+ file.onOpen = (RandomAccessFile openedFile) {
+ openedFile.onReadByte = (int byte) {
Expect.fail("Read byte from empty file");
};
- openedFile.errorHandler = (String err) {
+ openedFile.onError = (String err) {
Expect.isTrue(err.indexOf("failed") != -1);
- openedFile.closeHandler = () {
- file.deleteHandler = () {
+ openedFile.onClose = () {
+ file.onDelete = () {
asyncTestDone("testReadEmptyFile");
};
file.delete();
@@ -435,9 +435,9 @@ class FileTest {
final String fileName = "${tempDirectory.path}/testWriteVariousLists";
final File file = new File(fileName);
file.create();
- file.createHandler = () {
+ file.onCreate = () {
file.open(FileMode.WRITE);
- file.openHandler = (RandomAccessFile openedFile) {
+ file.onOpen = (RandomAccessFile openedFile) {
// Write bytes from 0 to 7.
openedFile.writeList([0], 0, 1);
openedFile.writeList(const [1], 0, 1);
@@ -452,13 +452,13 @@ class FileTest {
y = 12345678901234567890123456789012345678901234568153;
openedFile.writeList([y - x], 0, 1);
- openedFile.errorHandler = (s) {
+ openedFile.onError = (s) {
Expect.fail("No errors expected : $s");
};
- openedFile.noPendingWriteHandler = () {
+ openedFile.onNoPendingWrite = () {
openedFile.close();
};
- openedFile.closeHandler = () {
+ openedFile.onClose = () {
// Check the written bytes.
final File file2 = new File(fileName);
var openedFile2 = file2.openSync();
@@ -474,7 +474,7 @@ class FileTest {
asyncTestDone("testWriteVariousLists");
};
};
- file.errorHandler = (s) {
+ file.onError = (s) {
Expect.fail("No errors expected : $s");
};
};
@@ -494,32 +494,32 @@ class FileTest {
var file = new File("${tempDir}/testDirectory");
var errors = 0;
file.directory();
- file.directoryHandler = (d) => Expect.fail("non-existing file");
- file.errorHandler = (s) {
- file.errorHandler = (s) => Expect.fail("no error expected");
+ file.onDirectory = (d) => Expect.fail("non-existing file");
+ file.onError = (s) {
+ file.onError = (s) => Expect.fail("no error expected");
file.create();
- file.createHandler = () {
+ file.onCreate = () {
file.directory();
- file.directoryHandler = (Directory d) {
+ file.onDirectory = (Directory d) {
d.exists();
- d.errorHandler = (s) => Expect.fail("no error expected");
- d.existsHandler = (exists) {
+ d.onError = (s) => Expect.fail("no error expected");
+ d.onExists = (exists) {
Expect.isTrue(exists);
Expect.isTrue(d.path.endsWith(tempDir));
file.delete();
- file.deleteHandler = () {
+ file.onDelete = () {
var file_dir = new File(".");
file_dir.directory();
- file_dir.directoryHandler = (d) {
+ file_dir.onDirectory = (d) {
Expect.fail("non-existing file");
};
- file_dir.errorHandler = (s) {
+ file_dir.onError = (s) {
var file_dir = new File(tempDir);
file_dir.directory();
- file_dir.directoryHandler = (d) {
+ file_dir.onDirectory = (d) {
Expect.fail("non-existing file");
};
- file_dir.errorHandler = (s) {
+ file_dir.onError = (s) {
port.toSendPort().send(1);
};
};
@@ -552,10 +552,10 @@ class FileTest {
static void testLength() {
String filename = getFilename("tests/vm/data/fixed_length_file");
RandomAccessFile input = (new File(filename)).openSync();
- input.errorHandler = (s) {
+ input.onError = (s) {
Expect.fail("No errors expected");
};
- input.lengthHandler = (length) {
+ input.onLength = (length) {
Expect.equals(42, length);
input.close();
};
@@ -573,20 +573,20 @@ class FileTest {
static void testPosition() {
String filename = getFilename("tests/vm/data/fixed_length_file");
RandomAccessFile input = (new File(filename)).openSync();
- input.errorHandler = (s) {
+ input.onError = (s) {
Expect.fail("No errors expected");
};
- input.positionHandler = (position) {
+ input.onPosition = (position) {
Expect.equals(0, position);
List<int> buffer = new List<int>(100);
- input.readListHandler = (bytes_read) {
- input.positionHandler = (position) {
+ input.onReadList = (bytes_read) {
+ input.onPosition = (position) {
Expect.equals(12, position);
- input.readListHandler = (bytes_read) {
- input.positionHandler = (position) {
+ input.onReadList = (bytes_read) {
+ input.onPosition = (position) {
Expect.equals(18, position);
- input.setPositionHandler = () {
- input.positionHandler = (position) {
+ input.onSetPosition = () {
+ input.onPosition = (position) {
Expect.equals(8, position);
input.close();
};
@@ -621,19 +621,19 @@ class FileTest {
static void testTruncate() {
File file = new File(tempDirectory.path + "/out_truncate");
List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65];
- file.errorHandler = (error) {
+ file.onError = (error) {
Expect.fail("testTruncate: No errors expected");
};
- file.openHandler = (RandomAccessFile openedFile) {
- openedFile.noPendingWriteHandler = () {
- openedFile.lengthHandler = (length) {
+ file.onOpen = (RandomAccessFile openedFile) {
+ openedFile.onNoPendingWrite = () {
+ openedFile.onLength = (length) {
Expect.equals(10, length);
- openedFile.truncateHandler = () {
- openedFile.lengthHandler = (length) {
+ openedFile.onTruncate = () {
+ openedFile.onLength = (length) {
Expect.equals(5, length);
- openedFile.closeHandler = () {
- file.deleteHandler = () {
- file.existsHandler = (exists) {
+ openedFile.onClose = () {
+ file.onDelete = () {
+ file.onExists = (exists) {
Expect.isFalse(exists);
asyncTestDone("testTruncate");
};
@@ -766,13 +766,13 @@ class FileTest {
File file = new File(tempDirectory.path + "/out_close_exception_stream");
file.createSync();
InputStream input = file.openInputStream();
- input.closeHandler = () {
+ input.onClose = () {
Expect.isTrue(input.closed);
Expect.isNull(input.readInto(buffer, 0, 12));
OutputStream output = file.openOutputStream();
output.close();
Expect.throws(() => output.writeFrom(buffer, 0, 12));
- output.closeHandler = () {
+ output.onClose = () {
file.deleteSync();
asyncTestDone("testCloseExceptionStream");
};
@@ -879,10 +879,10 @@ class FileTest {
static void testMixedSyncAndAsync() {
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
- f.errorHandler = (s) {
+ f.onError = (s) {
Expect.fail("No errors expected");
};
- f.existsHandler = (exists) {
+ f.onExists = (exists) {
try {
f.existsSync();
Expect.fail("Expected exception");
@@ -896,7 +896,7 @@ class FileTest {
static void testOpenDirectoryAsFile() {
var f = new File('.');
f.open();
- f.openHandler = (r) => Expect.fail('Directory opened as file');
+ f.onOpen = (r) => Expect.fail('Directory opened as file');
}
static void testOpenDirectoryAsFileSync() {
@@ -917,11 +917,11 @@ class FileTest {
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
f.readAsBytes();
- f.readAsBytesHandler = (bytes) {
+ f.onReadAsBytes = (bytes) {
Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
port.toSendPort().send(bytes.length);
};
- f.errorHandler = (e) {
+ f.onError = (e) {
Expect.fail("No errors expected: $e");
};
}
@@ -941,33 +941,33 @@ class FileTest {
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
f.readAsText('UTF-8');
- f.readAsTextHandler = (text) {
+ f.onReadAsText = (text) {
Expect.isTrue(text.endsWith("42 bytes."));
Expect.equals(42, text.length);
var name = getDataFilename("tests/standalone/src/read_as_text.dat");
var f = new File(name);
- f.errorHandler = (e) => Expect.fail("No errors expected");
+ f.onError = (e) => Expect.fail("No errors expected");
f.readAsText('UTF-8');
- f.readAsTextHandler = (text) {
+ f.onReadAsText = (text) {
Expect.equals(6, text.length);
var expected = [955, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.charCodes());
f.readAsText('ISO-8859-1');
- f.readAsTextHandler = (text) {
+ f.onReadAsText = (text) {
Expect.equals(7, text.length);
var expected = [206, 187, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.charCodes());
f.readAsText('ASCII');
- f.errorHandler = (e) {
+ f.onError = (e) {
port.toSendPort().send(1);
};
- f.readAsTextHandler = (text) {
+ f.onReadAsText = (text) {
Expect.fail("Non-ascii char should cause error");
};
};
};
};
- f.errorHandler = (e) {
+ f.onError = (e) {
Expect.fail("No errors expected: $e");
};
}
@@ -997,13 +997,13 @@ class FileTest {
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
f.readAsLines('UTF-8');
- f.readAsLinesHandler = (lines) {
+ f.onReadAsLines = (lines) {
Expect.equals(1, lines.length);
var line = lines[0];
Expect.isTrue(line.endsWith("42 bytes."));
port.toSendPort().send(line.length);
};
- f.errorHandler = (e) {
+ f.onError = (e) {
Expect.fail("No errors expected: $e");
};
}
@@ -1031,11 +1031,11 @@ class FileTest {
Expect.throws(f.readAsTextSync, (e) => e is FileIOException);
Expect.throws(f.readAsLinesSync, (e) => e is FileIOException);
f.readAsBytes();
- f.errorHandler = (e) {
+ f.onError = (e) {
f.readAsText();
- f.errorHandler = (e) {
+ f.onError = (e) {
f.readAsLines();
- f.errorHandler = (e) {
+ f.onError = (e) {
port.toSendPort().send(1);
};
};
@@ -1046,19 +1046,19 @@ class FileTest {
// that the file is not truncated when opened for appending.
static void testAppend() {
var file = new File('${tempDirectory.path}/out_append');
- file.openHandler = (openedFile) {
- openedFile.noPendingWriteHandler = () {
- openedFile.closeHandler = () {
- file.openHandler = (openedFile) {
- openedFile.lengthHandler = (length) {
+ file.onOpen = (openedFile) {
+ openedFile.onNoPendingWrite = () {
+ openedFile.onClose = () {
+ file.onOpen = (openedFile) {
+ openedFile.onLength = (length) {
Expect.equals(4, length);
- openedFile.setPositionHandler = () {
- openedFile.noPendingWriteHandler = () {
- openedFile.lengthHandler = (length) {
+ openedFile.onSetPosition = () {
+ openedFile.onNoPendingWrite = () {
+ openedFile.onLength = (length) {
Expect.equals(8, length);
- openedFile.closeHandler = () {
- file.deleteHandler = () {
- file.existsHandler = (exists) {
+ openedFile.onClose = () {
+ file.onDelete = () {
+ file.onExists = (exists) {
Expect.isFalse(exists);
asyncTestDone("testAppend");
};

Powered by Google App Engine
This is Rietveld 408576698