Java Code Examples for jdk.testlibrary.Asserts#assertEQ()

The following examples show how to use jdk.testlibrary.Asserts#assertEQ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatchExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void assertReturn(Object returned, Object arg0, Object arg1,
        int catchDrops, Object... args) {
    int lag = 0;
    if (throwMode == ThrowMode.CAUGHT) {
        lag = 1;
    }
    Helper.assertCalled(lag, callName(), arg0, arg1);

    if (throwMode == ThrowMode.NOTHING) {
        assertEQ(cast.apply(arg0), returned);
    } else if (throwMode == ThrowMode.CAUGHT) {
        List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
        // catcher receives an initial subsequence of target arguments:
        catchArgs.subList(args.length - catchDrops, args.length).clear();
        // catcher also receives the exception, prepended:
        catchArgs.add(0, thrown);
        Helper.assertCalled("catcher", catchArgs);
        assertEQ(cast.apply(catchArgs), returned);
    }
    Asserts.assertEQ(0, fakeIdentityCount);
}
 
Example 2
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void assertReturn(Object returned, Object arg0, Object arg1,
        int catchDrops, Object... args) {
    int lag = 0;
    if (throwMode == ThrowMode.CAUGHT) {
        lag = 1;
    }
    Helper.assertCalled(lag, callName(), arg0, arg1);

    if (throwMode == ThrowMode.NOTHING) {
        assertEQ(cast.apply(arg0), returned);
    } else if (throwMode == ThrowMode.CAUGHT) {
        List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
        // catcher receives an initial subsequence of target arguments:
        catchArgs.subList(args.length - catchDrops, args.length).clear();
        // catcher also receives the exception, prepended:
        catchArgs.add(0, thrown);
        Helper.assertCalled("catcher", catchArgs);
        assertEQ(cast.apply(catchArgs), returned);
    }
    Asserts.assertEQ(0, fakeIdentityCount);
}
 
Example 3
Source File: TestEventFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyValues(RecordedEvent event) {
    for (Map.Entry<String, Object> entry : EVENT_VALUES.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = EVENT_VALUES.get(fieldName);
        if (expected instanceof Class) {
            value = ((RecordedClass) value).getName();
            expected = ((Class<?>) expected).getName();
        }
        if (expected instanceof Thread) {
            value = ((RecordedThread) value).getJavaName();
            expected = ((Thread) expected).getName();
        }
        Asserts.assertEQ(value, expected);
    }
}
 
Example 4
Source File: TestBiasedLockRevocationEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testBulkRevocation() throws Throwable {
    class MyLock {};

    Recording recording = new Recording();

    recording.enable(EventNames.BiasedLockClassRevocation);
    recording.start();

    Thread biasBreaker = triggerRevocation(BULK_REVOKE_THRESHOLD, MyLock.class);

    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    Asserts.assertEQ(events.size(), 1);

    RecordedEvent event = events.get(0);
    Events.assertEventThread(event, biasBreaker);
    Events.assertField(event, "disableBiasing").equal(false);

    RecordedClass lockClass = event.getValue("revokedClass");
    Asserts.assertEquals(lockClass.getName(), MyLock.class.getName());

    validateStackTrace(event.getStackTrace());
}
 
Example 5
Source File: CatchExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void assertReturn(Object returned, Object arg0, Object arg1,
        int catchDrops, Object... args) {
    int lag = 0;
    if (throwMode == ThrowMode.CAUGHT) {
        lag = 1;
    }
    Helper.assertCalled(lag, callName(), arg0, arg1);

    if (throwMode == ThrowMode.NOTHING) {
        assertEQ(cast.apply(arg0), returned);
    } else if (throwMode == ThrowMode.CAUGHT) {
        List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
        // catcher receives an initial subsequence of target arguments:
        catchArgs.subList(args.length - catchDrops, args.length).clear();
        // catcher also receives the exception, prepended:
        catchArgs.add(0, thrown);
        Helper.assertCalled("catcher", catchArgs);
        assertEQ(cast.apply(catchArgs), returned);
    }
    Asserts.assertEQ(0, fakeIdentityCount);
}
 
Example 6
Source File: CatchExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void assertReturn(Object returned, Object arg0, Object arg1,
        int catchDrops, Object... args) {
    int lag = 0;
    if (throwMode == ThrowMode.CAUGHT) {
        lag = 1;
    }
    Helper.assertCalled(lag, callName(), arg0, arg1);

    if (throwMode == ThrowMode.NOTHING) {
        assertEQ(cast.apply(arg0), returned);
    } else if (throwMode == ThrowMode.CAUGHT) {
        List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
        // catcher receives an initial subsequence of target arguments:
        catchArgs.subList(args.length - catchDrops, args.length).clear();
        // catcher also receives the exception, prepended:
        catchArgs.add(0, thrown);
        Helper.assertCalled("catcher", catchArgs);
        assertEQ(cast.apply(catchArgs), returned);
    }
    Asserts.assertEQ(0, fakeIdentityCount);
}
 
Example 7
Source File: CatchExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void assertReturn(Object returned, Object arg0, Object arg1,
        int catchDrops, Object... args) {
    int lag = 0;
    if (throwMode == ThrowMode.CAUGHT) {
        lag = 1;
    }
    Helper.assertCalled(lag, callName(), arg0, arg1);

    if (throwMode == ThrowMode.NOTHING) {
        assertEQ(cast.apply(arg0), returned);
    } else if (throwMode == ThrowMode.CAUGHT) {
        List<Object> catchArgs = new ArrayList<>(Arrays.asList(args));
        // catcher receives an initial subsequence of target arguments:
        catchArgs.subList(args.length - catchDrops, args.length).clear();
        // catcher also receives the exception, prepended:
        catchArgs.add(0, thrown);
        Helper.assertCalled("catcher", catchArgs);
        assertEQ(cast.apply(catchArgs), returned);
    }
    Asserts.assertEQ(0, fakeIdentityCount);
}
 
Example 8
Source File: CatchExceptionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void assertEQ(T t, Object returned) {
    if (rtype.isArray()) {
        Asserts.assertEQ(t.getClass(), returned.getClass());
        int n = Array.getLength(t);
        Asserts.assertEQ(n, Array.getLength(returned));
        for (int i = 0; i < n; ++i) {
            Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
        }
    } else {
        Asserts.assertEQ(t, returned);
    }
}
 
Example 9
Source File: CatchExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: CatchExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void assertEQ(T t, Object returned) {
    if (rtype.isArray()) {
        Asserts.assertEQ(t.getClass(), returned.getClass());
        int n = Array.getLength(t);
        Asserts.assertEQ(n, Array.getLength(returned));
        for (int i = 0; i < n; ++i) {
            Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
        }
    } else {
        Asserts.assertEQ(t, returned);
    }
}
 
Example 11
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void assertEQ(T t, Object returned) {
    if (rtype.isArray()) {
        Asserts.assertEQ(t.getClass(), returned.getClass());
        int n = Array.getLength(t);
        Asserts.assertEQ(n, Array.getLength(returned));
        for (int i = 0; i < n; ++i) {
            Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
        }
    } else {
        Asserts.assertEQ(t, returned);
    }
}
 
Example 12
Source File: Invalid.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

        // Normal
        FilePermission fp = new FilePermission("a", "read");

        // Invalid
        FilePermission fp1 = new FilePermission("a\000", "read");
        FilePermission fp2 = new FilePermission("a\000", "read");
        FilePermission fp3 = new FilePermission("b\000", "read");

        // Invalid equals to itself
        Asserts.assertEQ(fp1, fp1);

        // and not equals to anything else, including other invalid ones
        Asserts.assertNE(fp, fp1);
        Asserts.assertNE(fp1, fp);
        Asserts.assertNE(fp1, fp2);
        Asserts.assertNE(fp1, fp3);

        // Invalid implies itself
        Asserts.assertTrue(fp1.implies(fp1));

        // and not implies or implied by anything else, including other
        // invalid ones
        Asserts.assertFalse(fp.implies(fp1));
        Asserts.assertFalse(fp1.implies(fp));
        Asserts.assertFalse(fp1.implies(fp2));
        Asserts.assertFalse(fp1.implies(fp3));
    }
 
Example 13
Source File: CatchExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void assertEQ(T t, Object returned) {
    if (rtype.isArray()) {
        Asserts.assertEQ(t.getClass(), returned.getClass());
        int n = Array.getLength(t);
        Asserts.assertEQ(n, Array.getLength(returned));
        for (int i = 0; i < n; ++i) {
            Asserts.assertEQ(Array.get(t, i), Array.get(returned, i));
        }
    } else {
        Asserts.assertEQ(t, returned);
    }
}
 
Example 14
Source File: Helper.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void assertCalled(int lag, String name, Object... args) {
    Object expected = logEntry(name, args);
    Object actual = getCalled(lag);
    Asserts.assertEQ(expected, actual, "method call w/ lag = " + lag);
}
 
Example 15
Source File: KeyAlgorithms.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void test(KeyPair kp) {
    Asserts.assertEQ(kp.getPrivate().getAlgorithm(), ALG);
    Asserts.assertEQ(kp.getPublic().getAlgorithm(), ALG);
}
 
Example 16
Source File: CatchExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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) {
        testCase.assertCatch(ex);
        returned = ex;
    }

    testCase.assertReturn(returned, arg0, arg1, dropped, args);
}
 
Example 17
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 18
Source File: TestBiasedLockRevocationEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void testSelfRevocation() throws Throwable {
    class MyLock {};

    Recording recording = new Recording();

    recording.enable(EventNames.BiasedLockSelfRevocation);
    recording.start();

    MyLock l = new MyLock();
    touch(l);
    Thread.holdsLock(l);

    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Asserts.assertEQ(events.size(), 1);

    RecordedEvent event = events.get(0);
    Events.assertEventThread(event, Thread.currentThread());

    validateStackTrace(event.getStackTrace(), "holdsLock");
}
 
Example 19
Source File: TestPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType periodicEvent = EventType.getEventType(PeriodicEvent.class);
    String defaultValue = Events.getSetting(periodicEvent, Period.NAME).getDefaultValue();
    Asserts.assertEQ(defaultValue, "47 s", "Incorrect default value for period");
}
 
Example 20
Source File: WeakAlg.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static void checkInplaceImportKeyStore() throws Exception {

        rm("ks");
        genkeypair("a", "");

        // Same type backup
        importkeystore("ks", "ks", "")
                .shouldContain("Warning:")
                .shouldMatch(".*ks.old");

        importkeystore("ks", "ks", "")
                .shouldContain("Warning:")
                .shouldMatch(".*ks.old2");

        importkeystore("ks", "ks", "-srcstoretype jks") // it knows real type
                .shouldContain("Warning:")
                .shouldMatch(".*ks.old3");

        String cPath = new File("ks").getCanonicalPath();

        importkeystore("ks", cPath, "")
                .shouldContain("Warning:")
                .shouldMatch(".*ks.old4");

        // Migration
        importkeystore("ks", "ks", "-deststoretype jks")
                .shouldContain("Warning:")
                .shouldContain("JKS keystore uses a proprietary format")
                .shouldMatch("The original.*ks.old5");

        KeyStore test_ks = KeyStore.getInstance("JKS");
        test_ks.load(new FileInputStream(new File("ks")),
                "changeit".toCharArray());
        Asserts.assertEQ(
                    test_ks.getType(), "JKS");

        importkeystore("ks", "ks", "-deststoretype PKCS12")
                .shouldContain("Warning:")
                .shouldNotContain("proprietary format")
                .shouldMatch("Migrated.*Non.*JKS.*ks.old6");

        test_ks = KeyStore.getInstance("PKCS12");
        test_ks.load(new FileInputStream(new File("ks")),
                "changeit".toCharArray());
        Asserts.assertEQ(
                test_ks.getType(), "PKCS12");

        test_ks = KeyStore.getInstance("JKS");
        test_ks.load(new FileInputStream(new File("ks.old6")),
                "changeit".toCharArray());
        Asserts.assertEQ(
                test_ks.getType(), "JKS");

        // One password prompt is enough for migration
        kt0("-importkeystore -srckeystore ks -destkeystore ks", "changeit")
                .shouldMatch("backed.*ks.old7");

        // But three if importing to a different keystore
        rm("ks2");
        kt0("-importkeystore -srckeystore ks -destkeystore ks2",
                    "changeit")
                .shouldContain("Keystore password is too short");

        kt0("-importkeystore -srckeystore ks -destkeystore ks2",
                "changeit", "changeit", "changeit")
                .shouldContain("Importing keystore ks to ks2...")
                .shouldNotContain("original")
                .shouldNotContain("Migrated");
    }