Added "touch(path)" to the FS API

* Implemented in the JS Shim
* Added test accordingly
1.3
Ivan De Marino 2011-09-01 00:34:55 +01:00 committed by Ariya Hidayat
parent 750e1e98c4
commit f83b9a5ba7
4 changed files with 20 additions and 3 deletions

View File

@ -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;

View File

@ -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');
};

View File

@ -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");

View File

@ -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");
});