mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 693341 - Test arrays of arithmetic types. r=khuey
This commit is contained in:
parent
e3dbbb4263
commit
c0aed148aa
@ -45,6 +45,20 @@ function f(a, b) {
|
||||
return rv;
|
||||
};
|
||||
|
||||
/* Implementation for size_is and iid_is methods. */
|
||||
function f_is(aIs, a, bIs, b, rvIs) {
|
||||
|
||||
// Set up the return value and its 'is' parameter.
|
||||
var rv = b.value;
|
||||
rvIs.value = bIs.value;
|
||||
|
||||
// Set up b and its 'is' parameter.
|
||||
b.value = a;
|
||||
bIs.value = aIs;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
TestParams.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
@ -71,7 +85,9 @@ TestParams.prototype = {
|
||||
testAString: f,
|
||||
testAUTF8String: f,
|
||||
testACString: f,
|
||||
testJsval: f
|
||||
testJsval: f,
|
||||
testShortArray: f_is,
|
||||
testLongLongArray: f_is,
|
||||
};
|
||||
|
||||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([TestParams]);
|
||||
|
@ -58,6 +58,27 @@ nsXPCTestParams::~nsXPCTestParams()
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define BUFFER_METHOD_IMPL(type) { \
|
||||
PRUint32 elemSize = sizeof(type); \
|
||||
\
|
||||
/* Copy b into rv. */ \
|
||||
*rvLength = *bLength; \
|
||||
*rv = static_cast<type*>(NS_Alloc(elemSize * (*bLength))); \
|
||||
if (!*rv) \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
memcpy(*rv, *b, elemSize * (*bLength)); \
|
||||
\
|
||||
/* Copy a into b. */ \
|
||||
*bLength = aLength; \
|
||||
NS_Free(*b); \
|
||||
*b = static_cast<type*>(NS_Alloc(elemSize * aLength)); \
|
||||
if (!*b) \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
memcpy(*b, a, elemSize * aLength); \
|
||||
\
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
/* boolean testBoolean (in boolean a, inout boolean b); */
|
||||
NS_IMETHODIMP nsXPCTestParams::TestBoolean(bool a, bool *b NS_INOUTPARAM, bool *_retval NS_OUTPARAM)
|
||||
{
|
||||
@ -192,3 +213,23 @@ NS_IMETHODIMP nsXPCTestParams::TestJsval(const jsval & a, jsval & b NS_INOUTPARA
|
||||
b = a;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void testShortArray (in unsigned long aLength, [array, size_is (aLength)] in short a,
|
||||
* inout unsigned long bLength, [array, size_is (bLength)] inout short b,
|
||||
* out unsigned long rvLength, [array, size_is (rvLength), retval] out short rv); */
|
||||
NS_IMETHODIMP nsXPCTestParams::TestShortArray(PRUint32 aLength, PRInt16 *a,
|
||||
PRUint32 *bLength NS_INOUTPARAM, PRInt16 **b NS_INOUTPARAM,
|
||||
PRUint32 *rvLength NS_OUTPARAM, PRInt16 **rv NS_OUTPARAM)
|
||||
{
|
||||
BUFFER_METHOD_IMPL(PRInt16);
|
||||
}
|
||||
|
||||
/* void testLongLongArray (in unsigned long aLength, [array, size_is (aLength)] in long long a,
|
||||
* inout unsigned long bLength, [array, size_is (bLength)] inout long long b,
|
||||
* out unsigned long rvLength, [array, size_is (rvLength), retval] out long long rv); */
|
||||
NS_IMETHODIMP nsXPCTestParams::TestLongLongArray(PRUint32 aLength, PRInt64 *a,
|
||||
PRUint32 *bLength NS_INOUTPARAM, PRInt64 **b NS_INOUTPARAM,
|
||||
PRUint32 *rvLength NS_OUTPARAM, PRInt64 **rv NS_OUTPARAM)
|
||||
{
|
||||
BUFFER_METHOD_IMPL(PRInt64);
|
||||
}
|
||||
|
@ -67,4 +67,16 @@ interface nsIXPCTestParams : nsISupports {
|
||||
AUTF8String testAUTF8String(in AUTF8String a, inout AUTF8String b);
|
||||
ACString testACString(in ACString a, inout ACString b);
|
||||
jsval testJsval(in jsval a, inout jsval b);
|
||||
|
||||
//
|
||||
// Dependent parameters use the same types as above, but are handled much differently.
|
||||
//
|
||||
|
||||
// Test arrays with non-allocated parameters.
|
||||
void testShortArray(in unsigned long aLength, [array, size_is(aLength)] in short a,
|
||||
inout unsigned long bLength, [array, size_is(bLength)] inout short b,
|
||||
out unsigned long rvLength, [retval, array, size_is(rvLength)] out short rv);
|
||||
void testLongLongArray(in unsigned long aLength, [array, size_is(aLength)] in long long a,
|
||||
inout unsigned long bLength, [array, size_is(bLength)] inout long long b,
|
||||
out unsigned long rvLength, [retval, array, size_is(rvLength)] out long long rv);
|
||||
};
|
||||
|
@ -56,6 +56,14 @@ function test_component(contractid) {
|
||||
// Possible comparator functions.
|
||||
var standardComparator = function(a,b) {return a == b;};
|
||||
var fuzzComparator = function(a,b) {return Math.abs(a - b) < 0.1;};
|
||||
var arrayComparator = function(a,b) {
|
||||
if (a.length != b.length)
|
||||
return false;
|
||||
for (var i = 0; i < a.length; ++i)
|
||||
if (a[i] != b[i])
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
// Helper test function - takes the name of test method and two values of
|
||||
// the given type.
|
||||
@ -72,6 +80,19 @@ function test_component(contractid) {
|
||||
do_check_true(comparator(val1, b.value));
|
||||
};
|
||||
|
||||
function doIsTest(name, val1, val1Is, val2, val2Is, comparator) {
|
||||
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);
|
||||
}
|
||||
|
||||
// Workaround for bug 687612 (inout parameters broken for dipper types).
|
||||
// We do a simple test of copying a into b, and ignore the rv.
|
||||
function doTestWorkaround(name, val1) {
|
||||
@ -102,4 +123,8 @@ function test_component(contractid) {
|
||||
doTestWorkaround("testAUTF8String", "We deliver 〠!");
|
||||
doTestWorkaround("testACString", "Just a regular C string.");
|
||||
doTest("testJsval", {aprop: 12, bprop: "str"}, 4.22);
|
||||
|
||||
// Test arrays.
|
||||
doIsTest("testShortArray", [2, 4, 6], 3, [1, 3, 5, 7], 4, arrayComparator);
|
||||
doIsTest("testLongLongArray", [-10000000000], 1, [1, 3, 1234511234551], 3, arrayComparator);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user