Updated tests.

This commit is contained in:
Alan Kligman 2013-07-22 23:34:38 -04:00
parent fb9fed0663
commit ea8fbd48ad
4 changed files with 151 additions and 52 deletions

35
dist/idbfs.js vendored
View File

@ -6509,7 +6509,14 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
deferred.resolve();
}
deferred.then(callback);
deferred.promise.then(
function() {
callback();
},
function(error) {
callback(error);
}
);
};
FileSystem.prototype.mkdir = function mkdir(path, callback) {
var that = this;
@ -6622,7 +6629,28 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
};
FileSystem.prototype.link = function link(oldpath, newpath, callback) {
var that = this;
this.promise.then(
function() {
var deferred = when.defer();
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
var files = transaction.objectStore(FILE_STORE_NAME);
deferred.promise.then(
function(result) {
callback(undefined, result);
},
function(error) {
callback(error);
}
);
},
function() {
callback(new EFileSystemError('unknown error'));
}
);
};
FileSystem.prototype.unlink = function unlink(path, callback) {
@ -6722,7 +6750,10 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p
}
);
};
FileSystem.prototype.seek = function seek(fd, offset, origin) {
FileSystem.prototype.seek = function seek(fd, offset, whence, callback) {
};
FileSystem.prototype.utime = function utime(path, atime, mtime, callback) {
};

View File

@ -31,60 +31,21 @@ fs.open('/myfile', 'w+', function(error, fd) {
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, nbytes) {
console.log('write:', nbytes)
if(error) throw error;
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, nbytes) {
console.log('write:', nbytes);
fs.stat('/myfile', function(error, stats) {
fs.close(fd, function(error) {
if(error) throw error;
console.log('closed');
fs.write(fd, buffer, 0, buffer.length, undefined, function(error, nbytes) {
if(error) throw error;
console.log(stats);
console.log('write:', nbytes);
fs.stat('/myfile', function(error, stats) {
if(error) throw error;
console.log(stats);
});
});
});
});
});
/*
function make_tmp_directory() {
return fs.mkdir('/tmp');
};
function remove_tmp_directory() {
return fs.rmdir('/tmp');
};
function create_tmp_file() {
return fs.open('/tmp/1', 'w+');
};
function print_fd(fd) {
console.log(fd);
return fd;
};
function write_data(fd) {
var data = new Uint8Array([1, 2, 3, 4]);
return fs.write(fd, data, 0, 4);
};
function close_tmp_file(fd) {
return fs.close(fd);
};
fs.promise.then(make_tmp_directory)
.then(function() {
var fd = fs.open('/tmp/1', 'w+');
function write_data() {
var data = new Uint8Array([1, 2, 3, 4]);
return fs.write(fd, data, 0, 4);
};
fd.promise.then(write_data);
})
.then(create_tmp_file)
.then(print_fd)
.then(write_data)
.then(function() { console.log('done'); })
.otherwise(function(error) { console.error(error, error.message, error.stack); });
*/
});
</script>
</html>

View File

@ -709,7 +709,14 @@ define(function(require) {
deferred.resolve();
}
deferred.then(callback);
deferred.promise.then(
function() {
callback();
},
function(error) {
callback(error);
}
);
};
FileSystem.prototype.mkdir = function mkdir(path, callback) {
var that = this;
@ -822,7 +829,28 @@ define(function(require) {
};
FileSystem.prototype.link = function link(oldpath, newpath, callback) {
var that = this;
this.promise.then(
function() {
var deferred = when.defer();
var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW);
var files = transaction.objectStore(FILE_STORE_NAME);
deferred.promise.then(
function(result) {
callback(undefined, result);
},
function(error) {
callback(error);
}
);
},
function() {
callback(new EFileSystemError('unknown error'));
}
);
};
FileSystem.prototype.unlink = function unlink(path, callback) {
@ -922,7 +950,10 @@ define(function(require) {
}
);
};
FileSystem.prototype.seek = function seek(fd, offset, origin) {
FileSystem.prototype.seek = function seek(fd, offset, whence, callback) {
};
FileSystem.prototype.utime = function utime(path, atime, mtime, callback) {
};

View File

@ -690,4 +690,80 @@ describe('fs.read', function() {
expect(array_buffer_equal(wbuffer.buffer, rbuffer.buffer)).toEqual(true);
});
});
});
describe('fs.close', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.close).toEqual('function');
});
it('should release the file descriptor', function() {
var complete = false;
var _error;
var that = this;
var buffer = new Uint8Array(0);
that.fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
var fd = result;
that.fs.close(fd, function(error) {
that.fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
_error = error;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toBeDefined();
});
});
});
describe('fs.link', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.link).toEqual('function');
});
});
describe('fs.unlink', function() {
beforeEach(function() {
this.db_name = mk_db_name();
this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT');
});
afterEach(function() {
indexedDB.deleteDatabase(this.db_name);
delete this.fs;
});
it('should be a function', function() {
expect(typeof this.fs.unlink).toEqual('function');
});
});