michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: function run_test() { michael@0: michael@0: // Load the component manifests. michael@0: Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest')); michael@0: Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest')); michael@0: michael@0: // Test for each component. michael@0: test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"); michael@0: test_component_readwrite("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1"); michael@0: test_component_readonly("@mozilla.org/js/xpc/test/native/ObjectReadOnly;1"); michael@0: test_component_readonly("@mozilla.org/js/xpc/test/js/ObjectReadOnly;1"); michael@0: } michael@0: michael@0: function test_component_readwrite(contractid) { michael@0: michael@0: // Instantiate the object. michael@0: var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadWrite"]); michael@0: michael@0: // Test the initial values. michael@0: do_check_eq("XPConnect Read-Writable String", o.stringProperty); michael@0: do_check_eq(true, o.booleanProperty); michael@0: do_check_eq(32767, o.shortProperty); michael@0: do_check_eq(2147483647, o.longProperty); michael@0: do_check_true(5.25 < o.floatProperty && 5.75 > o.floatProperty); michael@0: do_check_eq("X", o.charProperty); michael@0: do_check_eq(-1, o.timeProperty); michael@0: michael@0: // Write new values. michael@0: o.stringProperty = "another string"; michael@0: o.booleanProperty = false; michael@0: o.shortProperty = -12345; michael@0: o.longProperty = 1234567890; michael@0: o.floatProperty = 10.2; michael@0: o.charProperty = "Z"; michael@0: o.timeProperty = 1; michael@0: michael@0: // Test the new values. michael@0: do_check_eq("another string", o.stringProperty); michael@0: do_check_eq(false, o.booleanProperty); michael@0: do_check_eq(-12345, o.shortProperty); michael@0: do_check_eq(1234567890, o.longProperty); michael@0: do_check_true(10.15 < o.floatProperty && 10.25 > o.floatProperty); michael@0: do_check_eq("Z", o.charProperty); michael@0: do_check_eq(1, o.timeProperty); michael@0: michael@0: // Assign values that differ from the expected type to verify conversion. michael@0: michael@0: function SetAndTestBooleanProperty(newValue, expectedValue) { michael@0: o.booleanProperty = newValue; michael@0: do_check_eq(expectedValue, o.booleanProperty); michael@0: }; michael@0: SetAndTestBooleanProperty(false, false); michael@0: SetAndTestBooleanProperty(1, true); michael@0: SetAndTestBooleanProperty(null, false); michael@0: SetAndTestBooleanProperty("A", true); michael@0: SetAndTestBooleanProperty(undefined, false); michael@0: SetAndTestBooleanProperty([], true); michael@0: SetAndTestBooleanProperty({}, true); michael@0: } michael@0: michael@0: function test_component_readonly(contractid) { michael@0: michael@0: // Instantiate the object. michael@0: var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadOnly"]); michael@0: michael@0: // Test the initial values. michael@0: do_check_eq("XPConnect Read-Only String", o.strReadOnly); michael@0: do_check_eq(true, o.boolReadOnly); michael@0: do_check_eq(32767, o.shortReadOnly); michael@0: do_check_eq(2147483647, o.longReadOnly); michael@0: do_check_true(5.25 < o.floatReadOnly && 5.75 > o.floatReadOnly); michael@0: do_check_eq("X", o.charReadOnly); michael@0: do_check_eq(-1, o.timeReadOnly); michael@0: }