test_cenums.js (2018B)
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/. */ 4 5 function TestCEnums() { 6 } 7 8 TestCEnums.prototype = { 9 /* Boilerplate */ 10 QueryInterface: ChromeUtils.generateQI(["nsIXPCTestCEnums"]), 11 12 testCEnumInput: function(input) { 13 if (input != Ci.nsIXPCTestCEnums.shouldBe12Explicit) 14 { 15 throw new Error("Enum values do not match expected value"); 16 } 17 }, 18 19 testCEnumOutput: function() { 20 return Ci.nsIXPCTestCEnums.shouldBe8Explicit; 21 }, 22 }; 23 24 25 function run_test() { 26 // Load the component manifests. 27 registerXPCTestComponents(); 28 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())); 33 } 34 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); 49 } 50 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); 57 }