michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: function test() { michael@0: let prefs = TiltUtils.Preferences; michael@0: ok(prefs, "The TiltUtils.Preferences wasn't found."); michael@0: michael@0: prefs.create("test-pref-bool", "boolean", true); michael@0: prefs.create("test-pref-int", "integer", 42); michael@0: prefs.create("test-pref-string", "string", "hello world!"); michael@0: michael@0: is(prefs.get("test-pref-bool", "boolean"), true, michael@0: "The boolean test preference wasn't initially set correctly."); michael@0: is(prefs.get("test-pref-int", "integer"), 42, michael@0: "The integer test preference wasn't initially set correctly."); michael@0: is(prefs.get("test-pref-string", "string"), "hello world!", michael@0: "The string test preference wasn't initially set correctly."); michael@0: michael@0: michael@0: prefs.set("test-pref-bool", "boolean", false); michael@0: prefs.set("test-pref-int", "integer", 24); michael@0: prefs.set("test-pref-string", "string", "!dlrow olleh"); michael@0: michael@0: is(prefs.get("test-pref-bool", "boolean"), false, michael@0: "The boolean test preference wasn't changed correctly."); michael@0: is(prefs.get("test-pref-int", "integer"), 24, michael@0: "The integer test preference wasn't changed correctly."); michael@0: is(prefs.get("test-pref-string", "string"), "!dlrow olleh", michael@0: "The string test preference wasn't changed correctly."); michael@0: michael@0: michael@0: is(typeof prefs.get("unknown-pref", "boolean"), "undefined", michael@0: "Inexisted boolean prefs should be handled as undefined."); michael@0: is(typeof prefs.get("unknown-pref", "integer"), "undefined", michael@0: "Inexisted integer prefs should be handled as undefined."); michael@0: is(typeof prefs.get("unknown-pref", "string"), "undefined", michael@0: "Inexisted string prefs should be handled as undefined."); michael@0: michael@0: michael@0: is(prefs.get("test-pref-bool", "integer"), null, michael@0: "The get() boolean function didn't handle incorrect types as it should."); michael@0: is(prefs.get("test-pref-bool", "string"), null, michael@0: "The get() boolean function didn't handle incorrect types as it should."); michael@0: is(prefs.get("test-pref-int", "boolean"), null, michael@0: "The get() integer function didn't handle incorrect types as it should."); michael@0: is(prefs.get("test-pref-int", "string"), null, michael@0: "The get() integer function didn't handle incorrect types as it should."); michael@0: is(prefs.get("test-pref-string", "boolean"), null, michael@0: "The get() string function didn't handle incorrect types as it should."); michael@0: is(prefs.get("test-pref-string", "integer"), null, michael@0: "The get() string function didn't handle incorrect types as it should."); michael@0: michael@0: michael@0: is(typeof prefs.get(), "undefined", michael@0: "The get() function should not work if not enough params are passed."); michael@0: is(typeof prefs.set(), "undefined", michael@0: "The set() function should not work if not enough params are passed."); michael@0: is(typeof prefs.create(), "undefined", michael@0: "The create() function should not work if not enough params are passed."); michael@0: michael@0: michael@0: is(prefs.get("test-pref-wrong-type", "wrong-type", 1), null, michael@0: "The get() function should expect only correct pref types."); michael@0: is(prefs.set("test-pref-wrong-type", "wrong-type", 1), false, michael@0: "The set() function should expect only correct pref types."); michael@0: is(prefs.create("test-pref-wrong-type", "wrong-type", 1), false, michael@0: "The create() function should expect only correct pref types."); michael@0: }