hotspot/test/testlibrary_tests/AssertsTest.java
author ctornqvi
Fri, 19 Aug 2016 10:06:30 -0400
changeset 40631 ed82623d7831
parent 38152 80e5da81fb2c
permissions -rw-r--r--
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder Reviewed-by: coleenp, gtriantafill, mseledtsov, iignatyev, dholmes, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     4
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     8
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    13
 * accompanied this code).
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    14
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    18
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    21
 * questions.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    22
 */
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    23
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 20280
diff changeset
    24
import static jdk.test.lib.Asserts.*;
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    25
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    26
/* @test
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    27
 * @summary Tests the different assertions in the Assert class
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 30604
diff changeset
    28
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    29
 * @library /test/lib
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    30
 */
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    31
public class AssertsTest {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    32
    private static class Foo implements Comparable<Foo> {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    33
        final int id;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    34
        public Foo(int id) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    35
            this.id = id;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    36
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    37
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    38
        public int compareTo(Foo f) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    39
            return new Integer(id).compareTo(new Integer(f.id));
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    40
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    41
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    42
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    44
        testLessThan();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    45
        testLessThanOrEqual();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    46
        testEquals();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    47
        testGreaterThanOrEqual();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    48
        testGreaterThan();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    49
        testNotEquals();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    50
        testNull();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    51
        testNotNull();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    52
        testTrue();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    53
        testFalse();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    54
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    55
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    56
    private static void testLessThan() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    57
        expectPass(Assertion.LT, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    58
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    59
        expectFail(Assertion.LT, 2, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    60
        expectFail(Assertion.LT, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    61
        expectFail(Assertion.LT, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    62
        expectFail(Assertion.LT, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    63
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    64
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    65
    private static void testLessThanOrEqual() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    66
        expectPass(Assertion.LTE, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    67
        expectPass(Assertion.LTE, 2, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    68
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    69
        expectFail(Assertion.LTE, 3, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    70
        expectFail(Assertion.LTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    71
        expectFail(Assertion.LTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    72
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    73
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    74
    private static void testEquals() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    75
        expectPass(Assertion.EQ, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    76
        expectPass(Assertion.EQ, null, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    77
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    78
        Foo f1 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    79
        expectPass(Assertion.EQ, f1, f1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    80
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    81
        Foo f2 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    82
        expectFail(Assertion.EQ, f1, f2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    83
        expectFail(Assertion.LTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    84
        expectFail(Assertion.LTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    85
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    86
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    87
    private static void testGreaterThanOrEqual() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    88
        expectPass(Assertion.GTE, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    89
        expectPass(Assertion.GTE, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    90
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    91
        expectFail(Assertion.GTE, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    92
        expectFail(Assertion.GTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    93
        expectFail(Assertion.GTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    94
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    95
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    96
    private static void testGreaterThan() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    97
        expectPass(Assertion.GT, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    98
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    99
        expectFail(Assertion.GT, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   100
        expectFail(Assertion.GT, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   101
        expectFail(Assertion.GT, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   102
        expectFail(Assertion.GT, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   103
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   104
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   105
    private static void testNotEquals() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   106
        expectPass(Assertion.NE, null, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   107
        expectPass(Assertion.NE, 1, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   108
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   109
        Foo f1 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   110
        Foo f2 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   111
        expectPass(Assertion.NE, f1, f2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   112
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   113
        expectFail(Assertion.NE, null, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   114
        expectFail(Assertion.NE, f1, f1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   115
        expectFail(Assertion.NE, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   116
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   117
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   118
    private static void testNull() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   119
        expectPass(Assertion.NULL, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   120
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   121
        expectFail(Assertion.NULL, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   122
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   123
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   124
    private static void testNotNull() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   125
        expectPass(Assertion.NOTNULL, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   126
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   127
        expectFail(Assertion.NOTNULL, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   128
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   129
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   130
    private static void testTrue() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   131
        expectPass(Assertion.TRUE, true);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   132
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   133
        expectFail(Assertion.TRUE, false);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   134
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   135
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   136
    private static void testFalse() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   137
        expectPass(Assertion.FALSE, false);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   138
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   139
        expectFail(Assertion.FALSE, true);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   140
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   141
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   142
    private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args)
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   143
        throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   144
        Assertion.run(assertion, args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   145
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   146
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   147
    private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args)
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   148
        throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   149
        try {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   150
            Assertion.run(assertion, args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   151
        } catch (RuntimeException e) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   152
            return;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   153
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   154
        throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) +
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   155
                            " to throw a RuntimeException");
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   156
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   157
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   158
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   159
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   160
enum Assertion {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   161
    LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   162
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   163
    public static <T extends Comparable<T>> void run(Assertion assertion, T ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   164
        String msg = "Expected " + format(assertion, args) + " to pass";
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   165
        switch (assertion) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   166
            case LT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   167
                assertLessThan(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   168
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   169
            case LTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   170
                assertLessThanOrEqual(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   171
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   172
            case EQ:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   173
                assertEquals(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   174
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   175
            case GTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   176
                assertGreaterThanOrEqual(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   177
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   178
            case GT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   179
                assertGreaterThan(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   180
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   181
            case NE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   182
                assertNotEquals(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   183
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   184
            case NULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   185
                assertNull(args == null ? args : args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   186
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   187
            case NOTNULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   188
                assertNotNull(args == null ? args : args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   189
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   190
            case FALSE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   191
                assertFalse((Boolean) args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   192
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   193
            case TRUE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   194
                assertTrue((Boolean) args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   195
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   196
            default:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   197
                // do nothing
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   198
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   199
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   200
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   201
    public static String format(Assertion assertion, Object ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   202
        switch (assertion) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   203
            case LT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   204
                return asString("assertLessThan", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   205
            case LTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   206
                return asString("assertLessThanOrEqual", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   207
            case EQ:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   208
                return asString("assertEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   209
            case GTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   210
                return asString("assertGreaterThanOrEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   211
            case GT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   212
                return asString("assertGreaterThan", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   213
            case NE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   214
                return asString("assertNotEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   215
            case NULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   216
                return asString("assertNull", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   217
            case NOTNULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   218
                return asString("assertNotNull", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   219
            case FALSE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   220
                return asString("assertFalse", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   221
            case TRUE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   222
                return asString("assertTrue", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   223
            default:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   224
                return "";
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   225
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   226
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   227
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   228
    private static String asString(String assertion, Object ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   229
        if (args == null) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   230
            return String.format("%s(null)", assertion);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   231
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   232
        if (args.length == 1) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   233
            return String.format("%s(%s)", assertion, args[0]);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   234
        } else {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   235
            return String.format("%s(%s, %s)", assertion, args[0], args[1]);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   236
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   237
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   238
}