当前位置: 首页>>代码示例>>Java>>正文


Java Helper.randomArgs方法代码示例

本文整理汇总了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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:ExplicitCastArgumentsTest.java

示例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);
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:40,代码来源:CatchExceptionTest.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:52,代码来源:CatchExceptionTest.java

示例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);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:51,代码来源:CatchExceptionTest.java


注:本文中的com.oracle.testlibrary.jsr292.Helper.randomArgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。