2014-01-14 15:56:36 +00:00
|
|
|
define(["Filer"], function(Filer) {
|
2013-12-13 05:46:31 +00:00
|
|
|
|
|
|
|
describe('fs.utimes', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.db_name = mk_db_name();
|
2014-01-14 15:56:36 +00:00
|
|
|
this.fs = new Filer.FileSystem({
|
2013-12-13 05:46:31 +00:00
|
|
|
name: this.db_name,
|
|
|
|
flags: 'FORMAT'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
indexedDB.deleteDatabase(this.db_name);
|
|
|
|
delete this.fs;
|
|
|
|
});
|
|
|
|
|
2013-12-16 02:22:36 +00:00
|
|
|
it('should be a function', function() {
|
|
|
|
expect(typeof this.fs.utimes).toEqual('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when atime is negative', function () {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.writeFile('/testfile', '', function(error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/testfile', -1, Date.now(), function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-20 05:45:11 +00:00
|
|
|
waitsFor(function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
2013-12-17 16:28:22 +00:00
|
|
|
expect(_error.name).toEqual('EInvalid');
|
2013-12-16 02:22:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when mtime is negative', function () {
|
2013-12-15 07:54:51 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
2013-12-16 02:22:36 +00:00
|
|
|
that.fs.writeFile('/testfile', '', function(error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/testfile', Date.now(), -1, function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-20 05:45:11 +00:00
|
|
|
waitsFor(function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
2013-12-17 16:28:22 +00:00
|
|
|
expect(_error.name).toEqual('EInvalid');
|
2013-12-16 02:22:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-17 16:28:22 +00:00
|
|
|
it('should error when atime is as invalid number', function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.writeFile('/testfile', '', function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-20 05:45:11 +00:00
|
|
|
waitsFor(function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
2013-12-17 16:28:22 +00:00
|
|
|
expect(_error.name).toEqual('EInvalid');
|
2013-12-16 02:22:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-17 16:28:22 +00:00
|
|
|
it ('should error when path does not exist', function () {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var atime = Date.parse('1 Oct 2000 15:33:22');
|
|
|
|
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
2013-12-20 05:45:11 +00:00
|
|
|
|
2013-12-17 16:28:22 +00:00
|
|
|
that.fs.utimes('/pathdoesnotexist', atime, mtime, function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_error.name).toEqual('ENoEntry');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when mtime is an invalid number', function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
that.fs.writeFile('/testfile', '', function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-20 05:45:11 +00:00
|
|
|
waitsFor(function () {
|
2013-12-16 02:22:36 +00:00
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
2013-12-17 16:28:22 +00:00
|
|
|
expect(_error.name).toEqual('EInvalid');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('should error when file descriptor is invalid', function () {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var atime = Date.parse('1 Oct 2000 15:33:22');
|
|
|
|
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
|
|
|
|
|
|
|
that.fs.futimes(1, atime, mtime, function (error) {
|
|
|
|
_error = error;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toBeDefined();
|
|
|
|
expect(_error.name).toEqual('EBadFileDescriptor');
|
2013-12-16 02:22:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change atime and mtime of a file path', function () {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var _stat;
|
2013-12-15 07:54:51 +00:00
|
|
|
|
|
|
|
var atime = Date.parse('1 Oct 2000 15:33:22');
|
|
|
|
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
|
|
|
|
|
|
|
that.fs.writeFile('/testfile', '', function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/testfile', atime, mtime, function (error) {
|
|
|
|
_error = error;
|
|
|
|
|
2013-12-16 02:22:36 +00:00
|
|
|
that.fs.stat('/testfile', function (error, stat) {
|
2013-12-15 07:54:51 +00:00
|
|
|
if (error) throw error;
|
|
|
|
|
2013-12-16 02:22:36 +00:00
|
|
|
_stat = stat;
|
2013-12-15 07:54:51 +00:00
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(_error).toEqual(null);
|
2013-12-16 02:22:36 +00:00
|
|
|
expect(_stat.atime).toEqual(atime);
|
|
|
|
expect(_stat.mtime).toEqual(mtime);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('should change atime and mtime for a valid file descriptor', function (error) {
|
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var ofd;
|
|
|
|
var _stat;
|
|
|
|
|
|
|
|
var atime = Date.parse('1 Oct 2000 15:33:22');
|
|
|
|
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
|
|
|
|
|
|
|
that.fs.open('/testfile', 'w', function (error, result) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
ofd = result;
|
|
|
|
|
|
|
|
that.fs.futimes(ofd, atime, mtime, function (error) {
|
|
|
|
_error = error;
|
2013-12-20 05:45:11 +00:00
|
|
|
|
2013-12-16 02:22:36 +00:00
|
|
|
that.fs.fstat(ofd, function (error, stat) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
_stat = stat;
|
|
|
|
complete = true;
|
2013-12-20 05:45:11 +00:00
|
|
|
});
|
2013-12-16 02:22:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_stat.atime).toEqual(atime);
|
|
|
|
expect(_stat.mtime).toEqual(mtime);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('should update atime and mtime of directory path', function (error) {
|
2013-12-21 21:49:52 +00:00
|
|
|
var complete = false;
|
2013-12-16 02:22:36 +00:00
|
|
|
var _error;
|
2013-12-21 21:49:52 +00:00
|
|
|
var that = this;
|
2013-12-16 02:22:36 +00:00
|
|
|
|
|
|
|
var _stat;
|
|
|
|
|
|
|
|
var atime = Date.parse('1 Oct 2000 15:33:22');
|
|
|
|
var mtime = Date.parse('30 Sep 2000 06:43:54');
|
|
|
|
|
2013-12-21 21:49:52 +00:00
|
|
|
that.fs.mkdir('/testdir', function (error) {
|
2013-12-16 02:22:36 +00:00
|
|
|
if (error) throw error;
|
|
|
|
|
2013-12-21 21:49:52 +00:00
|
|
|
that.fs.utimes('/testdir', atime, mtime, function (error) {
|
2013-12-16 02:22:36 +00:00
|
|
|
_error = error;
|
|
|
|
|
2014-01-16 02:35:42 +00:00
|
|
|
that.fs.stat('/testdir', function (error, stat) {
|
2013-12-17 16:28:22 +00:00
|
|
|
if (error) throw error;
|
2013-12-16 02:22:36 +00:00
|
|
|
|
|
|
|
_stat = stat;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function () {
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
expect(_stat.atime).toEqual(atime);
|
|
|
|
expect(_stat.mtime).toEqual(mtime);
|
2013-12-15 07:54:51 +00:00
|
|
|
});
|
2013-12-13 05:46:31 +00:00
|
|
|
});
|
2013-12-17 16:28:22 +00:00
|
|
|
|
2013-12-20 05:45:11 +00:00
|
|
|
it ('should update atime and mtime using current time if arguments are null', function () {
|
2013-12-17 16:28:22 +00:00
|
|
|
var complete = false;
|
|
|
|
var _error;
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
var atimeEst;
|
|
|
|
var mtimeEst;
|
|
|
|
var now;
|
|
|
|
|
|
|
|
that.fs.writeFile('/myfile', '', function (error) {
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
that.fs.utimes('/myfile', null, null, function (error) {
|
|
|
|
_error = error;
|
|
|
|
|
|
|
|
now = Date.now();
|
|
|
|
|
|
|
|
that.fs.stat('/myfile', function (error, stat) {
|
|
|
|
if (error) throw error;
|
2013-12-20 05:45:11 +00:00
|
|
|
|
2013-12-17 16:28:22 +00:00
|
|
|
atimeEst = now - stat.atime;
|
|
|
|
mtimeEst = now - stat.mtime;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(function (){
|
|
|
|
return complete;
|
|
|
|
}, 'test to complete', DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
expect(_error).toEqual(null);
|
|
|
|
// Note: testing estimation as time may differ by a couple of milliseconds
|
|
|
|
// This number should be increased if tests are on slow systems
|
|
|
|
expect(atimeEst).toBeLessThan(10);
|
|
|
|
expect(mtimeEst).toBeLessThan(10);
|
|
|
|
});
|
|
|
|
});
|
2013-12-13 05:46:31 +00:00
|
|
|
});
|
|
|
|
});
|