Bug 1474369 - Part 5: Add tests for new Sequence<T> types, r=mccr8

Summary: Depends On D2110

Reviewers: mccr8!

Tags: #secure-revision

Bug #: 1474369

Differential Revision: https://phabricator.services.mozilla.com/D2111
This commit is contained in:
Nika Layzell 2018-07-10 21:25:11 -04:00
Родитель b47aabdb25
Коммит aa005d31b4
4 изменённых файлов: 114 добавлений и 0 удалений

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

@ -64,6 +64,13 @@ TestParams.prototype = {
testAUTF8String: f,
testACString: f,
testJsval: f,
testShortSequence: f,
testDoubleSequence: f,
testAStringSequence: f,
testACStringSequence: f,
testInterfaceSequence: f,
testJsvalSequence: f,
testInterfaceIsSequence: f_is,
testShortArray: f_is,
testDoubleArray: f_is,
testStringArray: f_is,

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

@ -28,6 +28,14 @@ nsXPCTestParams::~nsXPCTestParams()
return NS_OK; \
}
#define SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP) { \
_retval.SwapElements(b); \
b = a; \
for (uint32_t i = 0; i < b.Length(); ++i) \
TAKE_OWNERSHIP(b[i]); \
return NS_OK; \
}
#define TAKE_OWNERSHIP_NOOP(val) {}
#define TAKE_OWNERSHIP_INTERFACE(val) {static_cast<nsISupports*>(val)->AddRef();}
#define TAKE_OWNERSHIP_STRING(val) { \
@ -313,3 +321,69 @@ NS_IMETHODIMP nsXPCTestParams::TestStringArrayOptionalSize(const char * *a, uint
return NS_OK;
}
NS_IMETHODIMP
nsXPCTestParams::TestShortSequence(const nsTArray<short>& a, nsTArray<short>& b, nsTArray<short>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
NS_IMETHODIMP
nsXPCTestParams::TestDoubleSequence(const nsTArray<double>& a, nsTArray<double>& b, nsTArray<double>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
// XXX(nika): Consider generating the exposed type 'nsTArray<RefPtr<nsIXPCTestInterfaceA>>` here instead?
NS_IMETHODIMP
nsXPCTestParams::TestInterfaceSequence(const nsTArray<nsIXPCTestInterfaceA*>& a,
nsTArray<nsIXPCTestInterfaceA*>& b,
nsTArray<nsIXPCTestInterfaceA*>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE);
}
NS_IMETHODIMP
nsXPCTestParams::TestAStringSequence(const nsTArray<nsString>& a,
nsTArray<nsString>& b,
nsTArray<nsString>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
NS_IMETHODIMP
nsXPCTestParams::TestACStringSequence(const nsTArray<nsCString>& a,
nsTArray<nsCString>& b,
nsTArray<nsCString>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
NS_IMETHODIMP
nsXPCTestParams::TestJsvalSequence(const nsTArray<JS::Value>& a,
nsTArray<JS::Value>& b,
nsTArray<JS::Value>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
NS_IMETHODIMP
nsXPCTestParams::TestSequenceSequence(const nsTArray<nsTArray<short>>& a,
nsTArray<nsTArray<short>>& b,
nsTArray<nsTArray<short>>& _retval)
{
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
}
NS_IMETHODIMP
nsXPCTestParams::TestInterfaceIsSequence(const nsIID* aIID, const nsTArray<void*>& a,
nsIID** bIID, nsTArray<void*>& b,
nsIID** rvIID, nsTArray<void*>& _retval)
{
// Shuffle around our nsIIDs
*rvIID = (*bIID)->Clone();
*bIID = aIID->Clone();
// Perform the generic sequence shuffle.
SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE);
}

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

@ -39,6 +39,19 @@ interface nsIXPCTestParams : nsISupports {
ACString testACString(in ACString a, inout ACString b);
jsval testJsval(in jsval a, inout jsval b);
// Test various forms of the Sequence<T> type.
Sequence<short> testShortSequence(in Sequence<short> a, inout Sequence<short> b);
Sequence<double> testDoubleSequence(in Sequence<double> a, inout Sequence<double> b);
Sequence<nsIXPCTestInterfaceA> testInterfaceSequence(in Sequence<nsIXPCTestInterfaceA> a, inout Sequence<nsIXPCTestInterfaceA> b);
Sequence<AString> testAStringSequence(in Sequence<AString> a, inout Sequence<AString> b);
Sequence<ACString> testACStringSequence(in Sequence<ACString> a, inout Sequence<ACString> b);
Sequence<jsval> testJsvalSequence(in Sequence<jsval> a, inout Sequence<jsval> b);
Sequence<Sequence<short> > testSequenceSequence(in Sequence<Sequence<short> > a, inout Sequence<Sequence<short> > b);
void testInterfaceIsSequence(in nsIIDPtr aIID, [iid_is(aIID)] in Sequence<nsQIResult> a,
inout nsIIDPtr bIID, [iid_is(bIID)] inout Sequence<nsQIResult> b,
out nsIIDPtr rvIID, [retval, iid_is(rvIID)] out Sequence<nsQIResult> rv);
//
// Dependent parameters use the same types as above, but are handled much differently.
//

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

@ -197,4 +197,24 @@ function test_component(contractid) {
// Test type mismatch (int16 <-> uint16); this should throw BAD_CONVERT_JS.
doTypedArrayMismatchTest("testShortArray", new Uint16Array([0, 7, 4, 3]), 4,
new Uint16Array([1, 5, 6]), 3);
// Test Sequence<T> types.
doTest("testShortSequence", [2, 4, 6], [1, 3, 5, 7], arrayComparator(standardComparator));
doTest("testDoubleSequence", [-10, -0.5], [1, 3, 1e11, -8e-5 ], arrayComparator(fuzzComparator));
doTest("testACStringSequence", ["mary", "hat", "hey", "lid", "tell", "lam"],
["ids", "fleas", "woes", "wide", "has", "know", "!"],
arrayComparator(standardComparator));
doTest("testAStringSequence", ["沒有語言", "的偉大嗎?]"],
["we", "are", "being", "sooo", "international", "right", "now"],
arrayComparator(standardComparator));
doTest("testInterfaceSequence", [makeA(), makeA()],
[makeA(), makeA(), makeA(), makeA(), makeA(), makeA()], arrayComparator(interfaceComparator));
doTest("testJsvalSequence", [{ cheese: 'whiz', apple: 8 }, [1, 5, '3'], /regex/],
['apple', 2.2e10, 3.3e30, { only: "wheedle", except: {} }], arrayComparator(standardComparator));
doIsTest("testInterfaceIsSequence", [makeA(), makeA(), makeA(), makeA(), makeA()], Ci['nsIXPCTestInterfaceA'],
[makeB(), makeB(), makeB()], Ci['nsIXPCTestInterfaceB'],
arrayComparator(interfaceComparator), dotEqualsComparator);
}