1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function TestCEnums() {
8 TestCEnums.prototype = {
10 QueryInterface: ChromeUtils.generateQI(["nsIXPCTestCEnums"]),
12 testCEnumInput: function(input) {
13 if (input != Ci.nsIXPCTestCEnums.shouldBe12Explicit)
15 throw new Error("Enum values do not match expected value");
19 testCEnumOutput: function() {
20 return Ci.nsIXPCTestCEnums.shouldBe8Explicit;
26 // Load the component manifests.
27 registerXPCTestComponents();
29 // Test for each component.
30 test_interface_consts();
31 test_component(Cc["@mozilla.org/js/xpc/test/native/CEnums;1"].createInstance());
32 test_component(xpcWrap(new TestCEnums()));
35 function test_interface_consts() {
36 Assert.equal(Ci.nsIXPCTestCEnums.testConst, 1);
37 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe1Explicit, 1);
38 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2Explicit, 2);
39 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe4Explicit, 4);
40 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe8Explicit, 8);
41 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe12Explicit, 12);
42 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe1Implicit, 1);
43 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2Implicit, 2);
44 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe3Implicit, 3);
45 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe5Implicit, 5);
46 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe6Implicit, 6);
47 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2AgainImplicit, 2);
48 Assert.equal(Ci.nsIXPCTestCEnums.shouldBe3AgainImplicit, 3);
51 function test_component(obj) {
52 var o = obj.QueryInterface(Ci.nsIXPCTestCEnums);
53 o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe12Explicit);
54 o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe8Explicit | Ci.nsIXPCTestCEnums.shouldBe4Explicit);
55 var a = o.testCEnumOutput();
56 Assert.equal(a, Ci.nsIXPCTestCEnums.shouldBe8Explicit);