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

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

Issue 9428003: Add more file tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/FileTest.dart
diff --git a/tests/standalone/src/FileTest.dart b/tests/standalone/src/FileTest.dart
index b740ca3dd5d9ac06a16ab985aaa47e1805e87354..b9d4d5235d6a63cf2516c45bb4ab0ce21057a22b 100644
--- a/tests/standalone/src/FileTest.dart
+++ b/tests/standalone/src/FileTest.dart
@@ -6,6 +6,13 @@
#import("dart:io");
+class MyListOfOneElement implements List {
+ int _value;
+ MyListOfOneElement(this._value);
+ int get length() => 1;
+ operator [](int index) => _value;
+}
+
class FileTest {
static Directory tempDirectory;
static int numLiveAsyncTests = 0;
@@ -395,6 +402,55 @@ class FileTest {
file.create();
}
+ // Test for file write of different types of lists.
+ static void testWriteVariousLists() {
+ final String fileName = "${tempDirectory.path}/testWriteVariousLists";
+ final File file = new File(fileName);
+ file.create();
+ file.createHandler = () {
+ file.open(FileMode.WRITE);
+ file.openHandler = (RandomAccessFile openedFile) {
+ // Write bytes from 0 to 7.
+ openedFile.writeList([0], 0, 1);
+ openedFile.writeList(const [1], 0, 1);
+ openedFile.writeList(new MyListOfOneElement(2), 0, 1);
+ var x = 12345678901234567890123456789012345678901234567890;
+ var y = 12345678901234567890123456789012345678901234567893;
+ openedFile.writeList([y - x], 0, 1);
+ openedFile.writeList([260], 0, 1); // 260 = 256 + 4 = 0x104.
+ openedFile.writeList(const [261], 0, 1);
+ openedFile.writeList(new MyListOfOneElement(262), 0, 1);
+ x = 12345678901234567890123456789012345678901234567890;
+ y = 12345678901234567890123456789012345678901234568153;
+ openedFile.writeList([y - x], 0, 1);
+
+ openedFile.errorHandler = (s) {
+ Expect.fail("No errors expected : $s");
+ };
+ openedFile.noPendingWriteHandler = () {
+ openedFile.close();
+ };
+ openedFile.closeHandler = () {
+ // Check the written bytes.
+ final File file2 = new File(fileName);
+ var openedFile2 = file2.openSync();
+ vat length = openedFile2.lengthSync();
+ Expect.equals(8, length);
+ List data = new List(length);
+ openedFile2.readListSync(data, 0, length);
Mads Ager (google) 2012/02/21 15:46:22 Maybe add an Expect.equals on the return value of
Søren Gjesse 2012/02/21 16:03:17 Done.
+ for (var i = 0; i < data.length; i++) {
+ Expect.equals(i, data[i]);
+ }
+ openedFile2.closeSync();
+ file2.deleteSync();
+ };
+ };
+ file.errorHandler = (s) {
+ Expect.fail("No errors expected : $s");
+ };
+ };
+ }
+
// Test for file length functionality.
static void testLength() {
String filename = getFilename("tests/vm/data/fixed_length_file");
@@ -843,6 +899,7 @@ class FileTest {
testAppendSync();
testWriteAppend();
testOutputStreamWriteAppend();
+ testWriteVariousLists();
});
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698