Bug 1498059 - Tests for CEnums in XPIDL; r=nika,froydnj

Depends on D8594

Differential Revision: https://phabricator.services.mozilla.com/D8595

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kyle Machulis 2018-11-06 00:05:44 +00:00
Родитель cd6f797161
Коммит 8ad671c4c0
11 изменённых файлов: 190 добавлений и 0 удалений

Просмотреть файл

@ -24,3 +24,6 @@ contract @mozilla.org/js/xpc/test/js/ReturnCodeChild;1 {38dd78aa-467f-4fad-8dcf-
component {e86573c4-a384-441a-8c92-7b99e8575b28} xpctest_utils.js
contract @mozilla.org/js/xpc/test/js/TestUtils;1 {e86573c4-a384-441a-8c92-7b99e8575b28}
component {43929c74-dc70-11e8-b6f9-8fce71a2796a} xpctest_cenums.js
contract @mozilla.org/js/xpc/test/js/CEnums;1 {43929c74-dc70-11e8-b6f9-8fce71a2796a}

Просмотреть файл

@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
function TestCEnums() {
}
TestCEnums.prototype = {
/* Boilerplate */
QueryInterface: ChromeUtils.generateQI([Ci["nsIXPCTestCEnums"]]),
contractID: "@mozilla.org/js/xpc/test/js/CEnums;1",
classID: Components.ID("{43929c74-dc70-11e8-b6f9-8fce71a2796a}"),
testCEnumInput: function(input) {
if (input != Ci.nsIXPCTestCEnums.shouldBe12Explicit)
{
throw new Error("Enum values do not match expected value");
}
},
testCEnumOutput: function() {
return Ci.nsIXPCTestCEnums.shouldBe8Explicit;
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestCEnums]);

Просмотреть файл

@ -10,6 +10,7 @@ EXPORTS += [
UNIFIED_SOURCES += [
'xpctest_attributes.cpp',
'xpctest_cenums.cpp',
'xpctest_module.cpp',
'xpctest_params.cpp',
'xpctest_returncode.cpp',

Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* local header for xpconnect tests components */
#include "xpctest_private.h"
NS_IMPL_ISUPPORTS(xpcTestCEnums, nsIXPCTestCEnums)
// If this compiles, we pass. Otherwise, this means that XPIDL bitflag
// generation is broken.
xpcTestCEnums::xpcTestCEnums() {
static_assert(0 == static_cast<uint32_t>(shouldBe0Implicit),
"XPIDL bitflag generation did not create correct shouldBe0Implicit flag");
static_assert(1 == static_cast<uint32_t>(shouldBe1Implicit),
"XPIDL bitflag generation did not create correct shouldBe1Implicit flag");
static_assert(2 == static_cast<uint32_t>(shouldBe2Implicit),
"XPIDL bitflag generation did not create correct shouldBe2Implicit flag");
static_assert(3 == static_cast<uint32_t>(shouldBe3Implicit),
"XPIDL bitflag generation did not create correct shouldBe3Implicit flag");
static_assert(5 == static_cast<uint32_t>(shouldBe5Implicit),
"XPIDL bitflag generation did not create correct shouldBe5Implicit flag");
static_assert(6 == static_cast<uint32_t>(shouldBe6Implicit),
"XPIDL bitflag generation did not create correct shouldBe6Implicit flag");
static_assert(2 == static_cast<uint32_t>(shouldBe2AgainImplicit),
"XPIDL bitflag generation did not create correct shouldBe2AgainImplicit flag");
static_assert(3 == static_cast<uint32_t>(shouldBe3AgainImplicit),
"XPIDL bitflag generation did not create correct shouldBe3AgainImplicit flag");
static_assert(1 == static_cast<uint32_t>(shouldBe1Explicit),
"XPIDL bitflag generation did not create correct shouldBe1Explicit flag");
static_assert(2 == static_cast<uint32_t>(shouldBe2Explicit),
"XPIDL bitflag generation did not create correct shouldBe2Explicit flag");
static_assert(4 == static_cast<uint32_t>(shouldBe4Explicit),
"XPIDL bitflag generation did not create correct shouldBe4Explicit flag");
static_assert(8 == static_cast<uint32_t>(shouldBe8Explicit),
"XPIDL bitflag generation did not create correct shouldBe8Explicit flag");
static_assert(12 == static_cast<uint32_t>(shouldBe12Explicit),
"XPIDL bitflag generation did not create correct shouldBe12Explicit flag");
}
nsresult
xpcTestCEnums::TestCEnumInput(testFlagsExplicit a)
{
if (a != shouldBe12Explicit) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
xpcTestCEnums::TestCEnumOutput(testFlagsExplicit* a)
{
*a = shouldBe8Explicit;
return NS_OK;
}

Просмотреть файл

@ -24,6 +24,11 @@
{ 0x3818f744, 0x5445, 0x4e9c, \
{ 0x9b, 0xb8, 0x64, 0x62, 0xfe, 0x81, 0xb6, 0x19 } }
#define NS_XPCTESTCENUMS_CID \
{ 0x89ba673a, 0xa987, 0xb89c, \
{ 0x92, 0x02, 0xb9, 0xc6, 0x23, 0x38, 0x64, 0x55 } }
NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestCEnums)
NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestObjectReadOnly)
NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestObjectReadWrite)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCTestParams)
@ -32,16 +37,19 @@ NS_DEFINE_NAMED_CID(NS_XPCTESTOBJECTREADONLY_CID);
NS_DEFINE_NAMED_CID(NS_XPCTESTOBJECTREADWRITE_CID);
NS_DEFINE_NAMED_CID(NS_XPCTESTPARAMS_CID);
NS_DEFINE_NAMED_CID(NS_XPCTESTRETURNCODEPARENT_CID);
NS_DEFINE_NAMED_CID(NS_XPCTESTCENUMS_CID);
static const mozilla::Module::CIDEntry kXPCTestCIDs[] = {
{ &kNS_XPCTESTOBJECTREADONLY_CID, false, nullptr, xpcTestObjectReadOnlyConstructor },
{ &kNS_XPCTESTOBJECTREADWRITE_CID, false, nullptr, xpcTestObjectReadWriteConstructor },
{ &kNS_XPCTESTPARAMS_CID, false, nullptr, nsXPCTestParamsConstructor },
{ &kNS_XPCTESTRETURNCODEPARENT_CID, false, nullptr, nsXPCTestReturnCodeParentConstructor },
{ &kNS_XPCTESTCENUMS_CID, false, nullptr, xpcTestCEnumsConstructor },
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kXPCTestContracts[] = {
{ "@mozilla.org/js/xpc/test/native/CEnums;1", &kNS_XPCTESTCENUMS_CID },
{ "@mozilla.org/js/xpc/test/native/ObjectReadOnly;1", &kNS_XPCTESTOBJECTREADONLY_CID },
{ "@mozilla.org/js/xpc/test/native/ObjectReadWrite;1", &kNS_XPCTESTOBJECTREADWRITE_CID },
{ "@mozilla.org/js/xpc/test/native/Params;1", &kNS_XPCTESTPARAMS_CID },

Просмотреть файл

@ -15,6 +15,7 @@
#include "xpctest_attributes.h"
#include "xpctest_params.h"
#include "xpctest_returncode.h"
#include "xpctest_cenums.h"
#include "mozilla/Attributes.h"
#include "mozilla/ModuleUtils.h"
@ -80,4 +81,13 @@ private:
~nsXPCTestReturnCodeParent();
};
class xpcTestCEnums final : public nsIXPCTestCEnums {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPCTESTCENUMS
xpcTestCEnums();
private:
~xpcTestCEnums() = default;
};
#endif /* xpctest_private_h___ */

Просмотреть файл

@ -7,6 +7,7 @@
XPIDL_SOURCES += [
'xpctest_attributes.idl',
'xpctest_bug809674.idl',
'xpctest_cenums.idl',
'xpctest_interfaces.idl',
'xpctest_params.idl',
'xpctest_returncode.idl',

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
/*
* This defines the interface for a test object.
*
*/
[scriptable, uuid(6a2f918e-cda2-11e8-bc9a-a34c716d1f2a)]
interface nsIXPCTestCEnums : nsISupports {
const long testConst = 1;
cenum testFlagsExplicit: 8 {
shouldBe1Explicit = 1,
shouldBe2Explicit = 2,
shouldBe4Explicit = 4,
shouldBe8Explicit = 8,
shouldBe12Explicit = shouldBe4Explicit | shouldBe8Explicit,
};
cenum testFlagsImplicit: 8 {
shouldBe0Implicit,
shouldBe1Implicit,
shouldBe2Implicit,
shouldBe3Implicit,
shouldBe5Implicit = 5,
shouldBe6Implicit,
shouldBe2AgainImplicit = 2,
shouldBe3AgainImplicit,
};
void testCEnumInput(in nsIXPCTestCEnums_testFlagsExplicit abc);
nsIXPCTestCEnums_testFlagsExplicit testCEnumOutput();
};

Просмотреть файл

@ -25,6 +25,7 @@ TEST_HARNESS_FILES.xpcshell.js.xpconnect.tests.components.js += [
'components/js/xpctest.manifest',
'components/js/xpctest_attributes.js',
'components/js/xpctest_bug809674.js',
'components/js/xpctest_cenums.js',
'components/js/xpctest_interfaces.js',
'components/js/xpctest_params.js',
'components/js/xpctest_returncode_child.js',

Просмотреть файл

@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
// Load the component manifests.
registerXPCTestComponents();
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
// Test for each component.
test_interface_consts();
test_component("@mozilla.org/js/xpc/test/native/CEnums;1");
test_component("@mozilla.org/js/xpc/test/js/CEnums;1");
}
function test_interface_consts() {
Assert.equal(Ci.nsIXPCTestCEnums.testConst, 1);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe1Explicit, 1);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2Explicit, 2);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe4Explicit, 4);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe8Explicit, 8);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe12Explicit, 12);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe1Implicit, 1);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2Implicit, 2);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe3Implicit, 3);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe5Implicit, 5);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe6Implicit, 6);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe2AgainImplicit, 2);
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe3AgainImplicit, 3);
}
function test_component(contractid) {
// Instantiate the object.
var o = Cc[contractid].createInstance(Ci["nsIXPCTestCEnums"]);
o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe12Explicit);
o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe8Explicit | Ci.nsIXPCTestCEnums.shouldBe4Explicit);
var a = o.testCEnumOutput();
Assert.equal(a, Ci.nsIXPCTestCEnums.shouldBe8Explicit);
}

Просмотреть файл

@ -64,6 +64,7 @@ support-files =
[test_bug1244222.js]
[test_bug_442086.js]
[test_callFunctionWithAsyncStack.js]
[test_cenums.js]
[test_classesByID_instanceof.js]
[test_compileScript.js]
[test_deepFreezeClone.js]