本文整理汇总了Java中com.oracle.testlibrary.jsr292.Helper.randomArgs方法的典型用法代码示例。如果您正苦于以下问题:Java Helper.randomArgs方法的具体用法?Java Helper.randomArgs怎么用?Java Helper.randomArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.oracle.testlibrary.jsr292.Helper
的用法示例。
在下文中一共展示了Helper.randomArgs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultipleArgs
import com.oracle.testlibrary.jsr292.Helper; //导入方法依赖的package包/类
/**
* Tests that MHs.eCA method works correctly with MHs with multiple arguments.
* @throws Throwable
*/
public static void testMultipleArgs() throws Throwable {
int arity = 1 + RNG.nextInt(Helper.MAX_ARITY / 2 - 2);
int arityMinus = RNG.nextInt(arity);
int arityPlus = arity + RNG.nextInt(Helper.MAX_ARITY / 2 - arity) + 1;
MethodType mType = Helper.randomMethodTypeGenerator(arity);
MethodType mTypeNew = Helper.randomMethodTypeGenerator(arity);
MethodType mTypeNewMinus = Helper.randomMethodTypeGenerator(arityMinus);
MethodType mTypeNewPlus = Helper.randomMethodTypeGenerator(arityPlus);
Class<?> rType = mType.returnType();
MethodHandle original;
if (rType.equals(void.class)) {
MethodType mt = MethodType.methodType(void.class);
original = MethodHandles.publicLookup()
.findStatic(THIS_CLASS, "retVoid", mt);
} else {
Object rValue = Helper.castToWrapper(1, rType);
original = MethodHandles.constant(rType, rValue);
}
original = Helper.addTrailingArgs(original, arity, mType.parameterList());
MethodHandle target = MethodHandles
.explicitCastArguments(original, mTypeNew);
Object[] parList = Helper.randomArgs(mTypeNew.parameterList());
for (int i = 0; i < parList.length; i++) {
if (parList[i] instanceof String) {
parList[i] = null; //getting rid of Stings produced by randomArgs
}
}
target.invokeWithArguments(parList);
checkForWrongMethodTypeException(original, mTypeNewMinus);
checkForWrongMethodTypeException(original, mTypeNewPlus);
}
示例2: runTest
import com.oracle.testlibrary.jsr292.Helper; //导入方法依赖的package包/类
private void runTest() {
Helper.clear();
Object[] args = Helper.randomArgs(
argsCount, thrower.type().parameterArray());
Object arg0 = Helper.MISSING_ARG;
Object arg1 = testCase.thrown;
if (argsCount > 0) {
arg0 = args[0];
}
if (argsCount > 1) {
args[1] = arg1;
}
Asserts.assertEQ(nargs, thrower.type().parameterCount());
if (argsCount < nargs) {
Object[] appendArgs = {arg0, arg1};
appendArgs = Arrays.copyOfRange(appendArgs, argsCount, nargs);
thrower = MethodHandles.insertArguments(
thrower, argsCount, appendArgs);
}
Asserts.assertEQ(argsCount, thrower.type().parameterCount());
MethodHandle target = MethodHandles.catchException(
testCase.filter(thrower), testCase.throwableClass,
testCase.filter(catcher));
Asserts.assertEQ(thrower.type(), target.type());
Asserts.assertEQ(argsCount, target.type().parameterCount());
Object returned;
try {
returned = target.invokeWithArguments(args);
} catch (Throwable ex) {
testCase.assertCatch(ex);
returned = ex;
}
testCase.assertReturn(returned, arg0, arg1, dropped, args);
}
示例3: runTest
import com.oracle.testlibrary.jsr292.Helper; //导入方法依赖的package包/类
private void runTest() {
if (Helper.IS_VERBOSE) {
System.out.printf("CatchException(%s, isVararg=%b argsCount=%d "
+ "dropped=%d)%n",
testCase, thrower.isVarargsCollector(),
argsCount, dropped);
}
Helper.clear();
Object[] args = Helper.randomArgs(
argsCount, thrower.type().parameterArray());
Object arg0 = Helper.MISSING_ARG;
Object arg1 = testCase.thrown;
if (argsCount > 0) {
arg0 = args[0];
}
if (argsCount > 1) {
args[1] = arg1;
}
Asserts.assertEQ(nargs, thrower.type().parameterCount());
if (argsCount < nargs) {
Object[] appendArgs = {arg0, arg1};
appendArgs = Arrays.copyOfRange(appendArgs, argsCount, nargs);
thrower = MethodHandles.insertArguments(
thrower, argsCount, appendArgs);
}
Asserts.assertEQ(argsCount, thrower.type().parameterCount());
MethodHandle target = MethodHandles.catchException(
testCase.filter(thrower), testCase.throwableClass,
testCase.filter(catcher));
Asserts.assertEQ(thrower.type(), target.type());
Asserts.assertEQ(argsCount, target.type().parameterCount());
Object returned;
try {
returned = target.invokeWithArguments(args);
} catch (Throwable ex) {
if (CodeCacheOverflowProcessor.isThrowableCausedByVME(ex)) {
// This error will be treated by CodeCacheOverflowProcessor
// to prevent the test from failing because of code cache overflow.
throw new Error(ex);
}
testCase.assertCatch(ex);
returned = ex;
}
testCase.assertReturn(returned, arg0, arg1, dropped, args);
}
示例4: runTest
import com.oracle.testlibrary.jsr292.Helper; //导入方法依赖的package包/类
private void runTest() {
if (Helper.IS_VERBOSE) {
System.out.printf("CatchException(%s, isVararg=%b argsCount=%d " +
"dropped=%d)%n",
testCase, thrower.isVarargsCollector(), argsCount, dropped);
}
Helper.clear();
Object[] args = Helper.randomArgs(
argsCount, thrower.type().parameterArray());
Object arg0 = Helper.MISSING_ARG;
Object arg1 = testCase.thrown;
if (argsCount > 0) {
arg0 = args[0];
}
if (argsCount > 1) {
args[1] = arg1;
}
Asserts.assertEQ(nargs, thrower.type().parameterCount());
if (argsCount < nargs) {
Object[] appendArgs = {arg0, arg1};
appendArgs = Arrays.copyOfRange(appendArgs, argsCount, nargs);
thrower = MethodHandles.insertArguments(
thrower, argsCount, appendArgs);
}
Asserts.assertEQ(argsCount, thrower.type().parameterCount());
MethodHandle target = MethodHandles.catchException(
testCase.filter(thrower), testCase.throwableClass,
testCase.filter(catcher));
Asserts.assertEQ(thrower.type(), target.type());
Asserts.assertEQ(argsCount, target.type().parameterCount());
Object returned;
try {
returned = target.invokeWithArguments(args);
} catch (Throwable ex) {
if (CodeCacheOverflowProcessor.isThrowableCausedByVME(ex)) {
// This error will be treated by CodeCacheOverflowProcessor
// to prevent the test from failing because of code cache overflow.
throw new Error(ex);
}
testCase.assertCatch(ex);
returned = ex;
}
testCase.assertReturn(returned, arg0, arg1, dropped, args);
}