You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2012/04/10 15:57:58 UTC
spec commit: Tests for CB-472: FileWriter.seek(0) does not actually
seek to the beginning of the file
Updated Branches:
refs/heads/master 2a042a34a -> 0e412704a
Tests for CB-472: FileWriter.seek(0) does not actually seek to the beginning of the file
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/0e412704
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/0e412704
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/0e412704
Branch: refs/heads/master
Commit: 0e412704adc642248ce60a57db5d6e6c04d1951a
Parents: 2a042a3
Author: macdonst <si...@gmail.com>
Authored: Tue Apr 10 09:57:43 2012 -0400
Committer: macdonst <si...@gmail.com>
Committed: Tue Apr 10 09:57:43 2012 -0400
----------------------------------------------------------------------
autotest/tests/file.tests.js | 82 +++++++++++++++++++++++++++++++++++++
1 files changed, 82 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/0e412704/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index 4a0fd30..f1ff6b6 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -2592,6 +2592,47 @@ Tests.prototype.FileTests = function() {
file.fullPath = filePath;
write_file(file);
});
+ test("should be able to seek to the beginning of the file and write more data than file.length", function() {
+ QUnit.stop(Tests.TEST_TIMEOUT);
+ expect(4);
+
+ var that = this,
+ fileName = "writer.seek.write",
+ filePath = this.root.fullPath + '/' + fileName,
+ // file content
+ rule = "This is our sentence.",
+ // for testing file length
+ length = rule.length,
+ // writes initial file content
+ write_file = function(fileEntry) {
+ fileEntry.createWriter(function(writer) {
+ writer.onwriteend = function(evt) {
+ ok(writer.length === length, "should have written " + length + " bytes");
+ ok(writer.position === length, "position should be at " + length);
+ append_file(writer);
+ };
+ writer.write(rule);
+ }, that.fail);
+ },
+ // appends to file
+ append_file = function(writer) {
+ var exception = "This is our newer sentence.";
+ writer.onwriteend = function(evt) {
+ ok(writer.length === length, "file length should be " + length);
+ ok(writer.position === length, "position should be at " + length);
+
+ // cleanup
+ that.deleteFile(fileName);
+ QUnit.start();
+ };
+ length = exception.length;
+ writer.seek(0);
+ writer.write(exception);
+ };
+
+ // create file, then write and append to it
+ this.createFile(fileName, write_file);
+ });
test("should be able to seek to the middle of the file and write more data than file.length", function() {
QUnit.stop(Tests.TEST_TIMEOUT);
expect(4);
@@ -2633,6 +2674,47 @@ Tests.prototype.FileTests = function() {
// create file, then write and append to it
this.createFile(fileName, write_file);
});
+ test("should be able to seek to the beginning of the file and write less data than file.length", function() {
+ QUnit.stop(Tests.TEST_TIMEOUT);
+ expect(4);
+
+ var that = this,
+ fileName = "writer.seek.write2",
+ filePath = this.root.fullPath + '/' + fileName,
+ // file content
+ rule = "This is our sentence.",
+ // for testing file length
+ length = rule.length,
+ // writes initial file content
+ write_file = function(fileEntry) {
+ fileEntry.createWriter(function(writer) {
+ writer.onwriteend = function(evt) {
+ ok(writer.length === length, "should have written " + length + " bytes");
+ ok(writer.position === length, "position should be at " + length);
+ append_file(writer);
+ };
+ writer.write(rule);
+ }, that.fail);
+ },
+ // appends to file
+ append_file = function(writer) {
+ var exception = "new.";
+ writer.onwriteend = function(evt) {
+ ok(writer.length === length, "file length should be " + length);
+ ok(writer.position === length, "position should be at " + length);
+
+ // cleanup
+ that.deleteFile(fileName);
+ QUnit.start();
+ };
+ length = exception.length;
+ writer.seek(0);
+ writer.write(exception);
+ };
+
+ // create file, then write and append to it
+ this.createFile(fileName, write_file);
+ });
test("should be able to seek to the middle of the file and write less data than file.length", function() {
QUnit.stop(Tests.TEST_TIMEOUT);
expect(4);