You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/06/18 02:35:59 UTC

[2/3] cordova-plugin-file git commit: Verify data in tests for write after seek.

Verify data in tests for write after seek.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/5c604107
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5c604107
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5c604107

Branch: refs/heads/master
Commit: 5c60410791873261065690123eab1a462d8271c6
Parents: ad64f0e
Author: unknown <vl...@gmail.com>
Authored: Fri Mar 20 16:36:44 2015 -0500
Committer: unknown <vl...@gmail.com>
Committed: Fri Mar 20 16:36:44 2015 -0500

----------------------------------------------------------------------
 tests/tests.js | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5c604107/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 239a0d3..22108f0 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -2376,6 +2376,7 @@ exports.defineAutoTests = function () {
             it("file.spec.96 should be able to write and append to file, createWriter", function (done) {
                 var fileName = "writer.append.createWriter", // file content
                 content = "There is an exception to every rule.", // for checkin file length
+                exception = " Except this one.",
                 length = content.length;
                 // create file, then write and append to it
                 createFile(fileName, function (fileEntry) {
@@ -2386,7 +2387,6 @@ exports.defineAutoTests = function () {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
                             // Append some more data
-                            var exception = " Except this one.";
                             writer.onwriteend = secondVerifier;
                             length += exception.length;
                             writer.seek(writer.length);
@@ -2395,6 +2395,13 @@ exports.defineAutoTests = function () {
                         secondVerifier = function (evt) {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
+                            var reader = new FileReader();
+                            reader.onloadend = thirdVerifier;
+                            reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
+                            fileEntry.file(function(f){reader.readAsText(f);});
+                        },
+                        thirdVerifier = function (evt) {
+                            expect(evt.target.result).toBe(content+exception);
                             // cleanup
                             deleteFile(fileName, done);
                         };
@@ -2406,7 +2413,8 @@ exports.defineAutoTests = function () {
             });
             it("file.spec.97 should be able to write and append to file, File object", function (done) {
                 var fileName = "writer.append.File", // file content
-                content = "There is an exception to every rule.", // for checking file length
+                content = "There is an exception to every rule.", // for checkin file length
+                exception = " Except this one.",
                 length = content.length;
                 root.getFile(fileName, {
                     create : true
@@ -2417,7 +2425,6 @@ exports.defineAutoTests = function () {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
                             // Append some more data
-                            var exception = " Except this one.";
                             writer.onwriteend = secondVerifier;
                             length += exception.length;
                             writer.seek(writer.length);
@@ -2426,6 +2433,13 @@ exports.defineAutoTests = function () {
                         secondVerifier = function () {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
+                            var reader = new FileReader();
+                            reader.onloadend = thirdVerifier;
+                            reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
+                            fileEntry.file(function(f){reader.readAsText(f);});
+                        },
+                        thirdVerifier = function (evt) {
+                            expect(evt.target.result).toBe(content+exception);
                             // cleanup
                             deleteFile(fileName, done);
                         };
@@ -2438,6 +2452,7 @@ exports.defineAutoTests = function () {
             it("file.spec.98 should be able to seek to the middle of the file and write more data than file.length", function (done) {
                 var fileName = "writer.seek.write", // file content
                 content = "This is our sentence.", // for checking file length
+                exception = "newer sentence.",
                 length = content.length;
                 // create file, then write and append to it
                 createFile(fileName, function (fileEntry) {
@@ -2447,7 +2462,6 @@ exports.defineAutoTests = function () {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
                             // Append some more data
-                            var exception = "newer sentence.";
                             writer.onwriteend = secondVerifier;
                             length = 12 + exception.length;
                             writer.seek(12);
@@ -2456,6 +2470,13 @@ exports.defineAutoTests = function () {
                         secondVerifier = function (evt) {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
+                            var reader = new FileReader();
+                            reader.onloadend = thirdVerifier;
+                            reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
+                            fileEntry.file(function(f){reader.readAsText(f);});
+                        },
+                        thirdVerifier = function (evt) {
+                            expect(evt.target.result).toBe(content.substr(0,12)+exception);
                             // cleanup
                             deleteFile(fileName, done);
                         };
@@ -2474,6 +2495,7 @@ exports.defineAutoTests = function () {
 
                 var fileName = "writer.seek.write2", // file content
                 content = "This is our sentence.", // for checking file length
+                exception = "new.",
                 length = content.length;
                 // create file, then write and append to it
                 createFile(fileName, function (fileEntry) {
@@ -2483,7 +2505,6 @@ exports.defineAutoTests = function () {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
                             // Append some more data
-                            var exception = "new.";
                             writer.onwriteend = secondVerifier;
                             length = 8 + exception.length;
                             writer.seek(8);
@@ -2492,6 +2513,13 @@ exports.defineAutoTests = function () {
                         secondVerifier = function (evt) {
                             expect(writer.length).toBe(length);
                             expect(writer.position).toBe(length);
+                            var reader = new FileReader();
+                            reader.onloadend = thirdVerifier;
+                            reader.onerror = failed.bind(null, done, 'reader.onerror - Error reading file: ' + fileName);
+                            fileEntry.file(function(f){reader.readAsText(f);});
+                        },
+                        thirdVerifier = function (evt) {
+                            expect(evt.target.result).toBe(content.substr(0,8)+exception);
                             // cleanup
                             deleteFile(fileName, done);
                         };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org