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

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

Issue 8679005: Add truncate operation to File API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file_win.cc ('k') | 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 38d76c9aae0f6df0e0f8935c59c9ec97e4bccdae..876b464580364b840c0f4d5851ad37825924450f 100644
--- a/tests/standalone/src/FileTest.dart
+++ b/tests/standalone/src/FileTest.dart
@@ -327,6 +327,58 @@ class FileTest {
return 1;
}
+ static int testTruncate() {
+ String filename = getFilename("tests/vm/data/fixed_length_file");
+ File file = new File("${filename}_out_truncate");
+ List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65];
+ file.errorHandler = (error) {
+ Expect.fail("testTruncate: No errors expected");
+ };
+ file.openHandler = () {
+ file.noPendingWriteHandler = () {
+ file.lengthHandler = (length) {
+ Expect.equals(10, length);
+ file.truncateHandler = () {
+ file.lengthHandler = (length) {
+ Expect.equals(5, length);
+ file.closeHandler = () {
+ file.deleteHandler = () {
+ file.existsHandler = (exists) {
+ Expect.isFalse(exists);
+ };
+ file.exists();
+ };
+ file.delete();
+ };
+ file.close();
+ };
+ file.length();
+ };
+ file.truncate(5);
+ };
+ file.length();
+ };
+ file.writeList(buffer, 0, 10);
+ };
+ file.open(true);
+ return 1;
+ }
+
+ static int testTruncateSync() {
+ String filename = getFilename("tests/vm/data/fixed_length_file");
+ File file = new File("${filename}_out_truncate_sync");
+ List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65];
+ file.openSync(true);
+ file.writeListSync(buffer, 0, 10);
+ Expect.equals(10, file.lengthSync());
+ file.truncateSync(5);
+ Expect.equals(5, file.lengthSync());
+ file.closeSync();
+ file.deleteSync();
+ Expect.isFalse(file.existsSync());
+ return 1;
+ }
+
// Tests exception handling after file was closed.
static int testCloseException() {
bool exceptionCaught = false;
@@ -590,6 +642,8 @@ class FileTest {
Expect.equals(1, testLengthSync());
Expect.equals(1, testPosition());
Expect.equals(1, testPositionSync());
+ Expect.equals(1, testTruncate());
+ Expect.equals(1, testTruncateSync());
Expect.equals(1, testCloseException());
Expect.equals(1, testCloseExceptionStream());
Expect.equals(1, testBufferOutOfBoundsException());
« no previous file with comments | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698