зеркало из https://github.com/mozilla/gecko-dev.git
Bug 693341 - Test iid_is(). r=khuey
This commit is contained in:
Родитель
44e8e809cd
Коммит
365c594573
|
@ -93,6 +93,7 @@ TestParams.prototype = {
|
|||
testInterfaceArray: f_is,
|
||||
testSizedString: f_is,
|
||||
testSizedWstring: f_is,
|
||||
testInterfaceIs: f_is,
|
||||
};
|
||||
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TestParams]);
|
||||
|
|
|
@ -305,3 +305,39 @@ NS_IMETHODIMP nsXPCTestParams::TestSizedWstring(PRUint32 aLength, const PRUnicha
|
|||
{
|
||||
BUFFER_METHOD_IMPL(PRUnichar, 1, TAKE_OWNERSHIP_NOOP);
|
||||
}
|
||||
|
||||
/* void testInterfaceIs (in nsIIDPtr aIID, [iid_is (aIID)] in nsQIResult a,
|
||||
* inout nsIIDPtr bIID, [iid_is (bIID)] inout nsQIResult b,
|
||||
* out nsIIDPtr rvIID, [iid_is (rvIID), retval] out nsQIResult rv); */
|
||||
NS_IMETHODIMP nsXPCTestParams::TestInterfaceIs(const nsIID *aIID, void *a,
|
||||
nsIID **bIID NS_INOUTPARAM, void **b NS_INOUTPARAM,
|
||||
nsIID **rvIID NS_OUTPARAM, void **rv NS_OUTPARAM)
|
||||
{
|
||||
//
|
||||
// Getting the buffers and ownership right here can be a little tricky.
|
||||
//
|
||||
|
||||
// The interface pointers are heap-allocated, and b has been AddRef'd
|
||||
// by XPConnect for the duration of the call. If we snatch it away from b
|
||||
// and leave no trace, XPConnect won't Release it. Since we also need to
|
||||
// return an already-AddRef'd pointer in rv, we don't need to do anything
|
||||
// special here.
|
||||
*rv = *b;
|
||||
|
||||
// rvIID is out-only, so nobody allocated an IID buffer for us. Do that now,
|
||||
// and store b's IID in the new buffer.
|
||||
*rvIID = static_cast<nsIID*>(NS_Alloc(sizeof(nsID)));
|
||||
if (!*rvIID)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
**rvIID = **bIID;
|
||||
|
||||
// Copy the interface pointer from a to b. Since a is in-only, XPConnect will
|
||||
// release it upon completion of the call. AddRef it for b.
|
||||
*b = a;
|
||||
static_cast<nsISupports*>(*b)->AddRef();
|
||||
|
||||
// We already had a buffer allocated for b's IID, so we can re-use it.
|
||||
**bIID = *aIID;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -99,4 +99,9 @@ interface nsIXPCTestParams : nsISupports {
|
|||
void testSizedWstring(in unsigned long aLength, [size_is(aLength)] in wstring a,
|
||||
inout unsigned long bLength, [size_is(bLength)] inout wstring b,
|
||||
out unsigned long rvLength, [retval, size_is(rvLength)] out wstring rv);
|
||||
|
||||
// Test iid_is.
|
||||
void testInterfaceIs(in nsIIDPtr aIID, [iid_is(aIID)] in nsQIResult a,
|
||||
inout nsIIDPtr bIID, [iid_is(bIID)] inout nsQIResult b,
|
||||
out nsIIDPtr rvIID, [retval, iid_is(rvIID)] out nsQIResult rv);
|
||||
};
|
||||
|
|
|
@ -55,7 +55,9 @@ function test_component(contractid) {
|
|||
|
||||
// Possible comparator functions.
|
||||
var standardComparator = function(a,b) {return a == b;};
|
||||
var dotEqualsComparator = function(a,b) {return a.equals(b); }
|
||||
var fuzzComparator = function(a,b) {return Math.abs(a - b) < 0.1;};
|
||||
var interfaceComparator = function(a,b) {return a.name == b.name; }
|
||||
var arrayComparator = function(a,b) {
|
||||
if (a.length != b.length)
|
||||
return false;
|
||||
|
@ -80,17 +82,19 @@ function test_component(contractid) {
|
|||
do_check_true(comparator(val1, b.value));
|
||||
};
|
||||
|
||||
function doIsTest(name, val1, val1Is, val2, val2Is, comparator) {
|
||||
function doIsTest(name, val1, val1Is, val2, val2Is, valComparator, isComparator) {
|
||||
if (!isComparator)
|
||||
isComparator = standardComparator;
|
||||
var a = val1;
|
||||
var aIs = val1Is;
|
||||
var b = {value: val2};
|
||||
var bIs = {value: val2Is};
|
||||
var rvIs = {};
|
||||
var rv = o[name].call(o, aIs, a, bIs, b, rvIs);
|
||||
do_check_true(comparator(rv, val2));
|
||||
do_check_eq(rvIs.value, val2Is);
|
||||
do_check_true(comparator(val1, b.value));
|
||||
do_check_eq(val1Is, bIs.value);
|
||||
do_check_true(valComparator(rv, val2));
|
||||
do_check_true(isComparator(rvIs.value, val2Is));
|
||||
do_check_true(valComparator(val1, b.value));
|
||||
do_check_true(isComparator(val1Is, bIs.value));
|
||||
}
|
||||
|
||||
// Workaround for bug 687612 (inout parameters broken for dipper types).
|
||||
|
@ -117,7 +121,6 @@ function test_component(contractid) {
|
|||
doTest("testString", "someString", "another string");
|
||||
// TODO: Fix bug 687679 and use the second argument listed below
|
||||
doTest("testWchar", "z", "q");// "ア");
|
||||
// TODO - Test nsIID in bug 687662
|
||||
doTestWorkaround("testDOMString", "Beware: ☠ s");
|
||||
doTestWorkaround("testAString", "Frosty the ☃ ;-)");
|
||||
doTestWorkaround("testAUTF8String", "We deliver 〠!");
|
||||
|
@ -142,4 +145,9 @@ function test_component(contractid) {
|
|||
var ssTests = ["Tis not possible, I muttered", "give me back my free hardcore!", "quoth the server:", "4〠4"];
|
||||
doIsTest("testSizedString", ssTests[0], ssTests[0].length, ssTests[1], ssTests[1].length, standardComparator);
|
||||
doIsTest("testSizedWstring", ssTests[2], ssTests[2].length, ssTests[3], ssTests[3].length, standardComparator);
|
||||
|
||||
// Test iid_is.
|
||||
doIsTest("testInterfaceIs", makeA(), Ci['nsIXPCTestInterfaceA'],
|
||||
makeB(), Ci['nsIXPCTestInterfaceB'],
|
||||
interfaceComparator, dotEqualsComparator);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче