Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Indentation fixes. More tests + comments in the test.
Browse files Browse the repository at this point in the history
  • Loading branch information
protz committed Jan 11, 2011
1 parent 76c2746 commit 8351cea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions SimpleStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Cu.import("resource://conversations/log.js");
let Log = setupLogging("Conversations.SimpleStorage");
Log.debug("Simple Storage loaded.");

let JSON = Components.classes["@mozilla.org/dom/json;1"]
.createInstance(Components.interfaces.nsIJSON);
let JSON = Cc["@mozilla.org/dom/json;1"]
.createInstance(Ci.nsIJSON);
let gStorageService = Cc["@mozilla.org/storage/service;1"]
.getService(Ci.mozIStorageService);
let gDbFile = Cc["@mozilla.org/file/directory_service;1"]
Expand Down Expand Up @@ -134,8 +134,7 @@ SimpleStorage.prototype = {
? "UPDATE #1 SET value = :value WHERE key = :key"
: "INSERT INTO #1 (key, value) VALUES (:key, :value)"
;
let statement = this.dbConnection
.createStatement(query.replace("#1", this.tableName));
let statement = this.dbConnection.createStatement(query.replace("#1", this.tableName));
statement.params.key = aKey;
statement.params.value = JSON.encode({ value: aValue });
statement.executeAsync({
Expand Down
19 changes: 13 additions & 6 deletions tests/test_SimpleStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,30 @@ function test_sync_api () {
r = yield ss.sHas("myKey");
do_check_false(r);
r = yield ss.sSet("myKey", "myVal");
do_check_true(r);
do_check_true(r); // Value was added
r = yield ss.sGet("myKey");
do_check_true(r == "myVal");

let o = { k1: "v1", k2: "v2" };
r = yield ss.sSet("myKey", o);
do_check_false(r);
do_check_false(r); // Value was updated in-place
r = yield ss.sGet("myKey");
for each (key in Object.keys(r))
do_check_true(r[key] == o[key]);
for each (key in Object.keys(o))
do_check_true(r[key] == o[key]);

r = yield ss.sRemove("myKey");
do_check_true(r);
r = yield ss.sRemove("myKey");
do_check_false(r);
// Test nested async actions. Not recommended for the casual user because of
// the very specific order of finish vs. yield kWorkDone.
yield (function (finish) (spin (function () {
r = yield ss.sRemove("myKey");
do_check_true(r);
r = yield ss.sRemove("myKey");
do_check_false(r);
finish();
yield kWorkDone; // Remember, nothing is executed past that line
})));

r = yield ss.sHas("myKey");
do_check_false(r);
dump("\033[01;34m--- async api test is over\033[00m\n");
Expand Down

0 comments on commit 8351cea

Please sign in to comment.