From f83b9a5ba78e627b5edf57c2d06e291802c50bd0 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Thu, 1 Sep 2011 00:34:55 +0100 Subject: [PATCH] Added "touch(path)" to the FS API * Implemented in the JS Shim * Added test accordingly --- src/filesystem.h | 3 +-- src/fs-shim.js | 4 ++++ test/fs-spec-01.js | 14 ++++++++++++++ test/fs-spec-02.js | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/filesystem.h b/src/filesystem.h index c1be4579..e14fe0ec 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -98,8 +98,7 @@ public slots: // 'copy(source, destination)' implemented in "fs-shim.js" using '_copy(source, destination)' bool _copy(const QString &source, const QString &destination) const; // 'move(source, destination)' implemented in "fs-shim.js" - // - touch(path, date) - // - rename() + // 'touch(path)' implemented in "fs-shim.js" // Listing QStringList list(const QString &path) const; diff --git a/src/fs-shim.js b/src/fs-shim.js index e0884b80..9215474a 100644 --- a/src/fs-shim.js +++ b/src/fs-shim.js @@ -144,4 +144,8 @@ window.fs.removeTree = function (path) { if (!fs._removeTree(path)) { throw "Unable to remove directory tree '" + path + "'"; } +}; + +window.fs.touch = function (path) { + fs.write(path, "", 'a'); }; \ No newline at end of file diff --git a/test/fs-spec-01.js b/test/fs-spec-01.js index 3b733d01..91af7bc2 100644 --- a/test/fs-spec-01.js +++ b/test/fs-spec-01.js @@ -2,6 +2,7 @@ describe("Basic Files API (read, write, remove, ...)", function() { var FILENAME = "temp-01.test", FILENAME_COPY = FILENAME + ".copy", FILENAME_MOVED = FILENAME + ".moved", + FILENAME_EMPTY = FILENAME + ".empty", ABSENT = "absent-01.test"; it("should be able to create and write a file", function() { @@ -15,6 +16,13 @@ describe("Basic Files API (read, write, remove, ...)", function() { } catch (e) { } expect(fs.exists(FILENAME)).toBeTruthy(); }); + + it("should be able to create (touch) an empty file", function() { + expect(fs.exists(FILENAME_EMPTY)).toBeFalsy(); + fs.touch(FILENAME_EMPTY); + expect(fs.exists(FILENAME_EMPTY)).toBeTruthy(); + expect(fs.size(FILENAME_EMPTY)).toEqual(0); + }); it("should be able to read content from a file", function() { var content = ""; @@ -55,6 +63,12 @@ describe("Basic Files API (read, write, remove, ...)", function() { expect(fs.exists(FILENAME_COPY)).toBeFalsy(); }); + it("should be able to remove an empty file", function() { + expect(fs.exists(FILENAME_EMPTY)).toBeTruthy(); + fs.remove(FILENAME_EMPTY); + expect(fs.exists(FILENAME_EMPTY)).toBeFalsy(); + }); + it("should throw an exception when trying to open for read a non existing file", function(){ expect(function(){ fs.open(ABSENT, "r"); diff --git a/test/fs-spec-02.js b/test/fs-spec-02.js index f89041c1..32aed558 100644 --- a/test/fs-spec-02.js +++ b/test/fs-spec-02.js @@ -6,7 +6,7 @@ describe("Attributes Files API", function() { it("should throw an exception when trying to read the size of a non existing file", function(){ expect(function(){ - fs.size(ABSENT, "r"); + fs.size(ABSENT); }).toThrow("Unable to read file '"+ ABSENT +"' size"); });