test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/StaticMethodsTest.java
author hseigel
Mon, 29 Oct 2018 08:38:59 -0400
changeset 52310 a8e43293b4c4
parent 50243 4fac3c99487d
permissions -rw-r--r--
8212997: [TESTBUG] Remove defmeth tests for class file versions 50 and 51 Summary: Remove the unneeded tests. Keep the tests for class file versions 49 and 52. Reviewed-by: acorn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50243
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     1
/*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     4
 *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     8
 *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    13
 * accompanied this code).
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    14
 *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    18
 *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    21
 * questions.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    22
 */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    23
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    24
package vm.runtime.defmeth;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    25
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    26
import nsk.share.test.TestBase;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    27
import vm.runtime.defmeth.shared.DefMethTest;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    28
import vm.runtime.defmeth.shared.annotation.Crash;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    29
import vm.runtime.defmeth.shared.data.*;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    30
import vm.runtime.defmeth.shared.builder.TestBuilder;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    31
import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    32
import static vm.runtime.defmeth.shared.data.method.body.CallMethod.Invoke.*;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    33
import static vm.runtime.defmeth.shared.data.method.body.CallMethod.IndexbyteOp.*;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    34
import static vm.runtime.defmeth.shared.ExecutionMode.*;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    35
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    36
/*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    37
 * Scenarios on static methods in interfaces.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    38
 */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    39
public class StaticMethodsTest extends DefMethTest {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    40
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    41
    public static void main(String[] args) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    42
        TestBase.runTest(new StaticMethodsTest(), args);
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    43
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    44
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    45
    // static method in interface
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    46
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    47
     * testStaticMethod
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    48
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    49
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    50
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    51
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    52
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    53
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    54
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    55
    public void testStaticMethod() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    56
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    57
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    58
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    59
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    60
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    61
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    62
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    63
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    64
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    65
        b.test().staticCallSite(I, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    66
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    67
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    68
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    69
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    70
    // invoke[virtual|interface|special] from same/subintf
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    71
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    72
     * testInvokeVirtual
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    73
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    74
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    75
     *  default static public int staticM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    76
     *  default public int m() { return ((I)this).staticM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    77
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    78
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    79
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    80
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    81
    public void testInvokeVirtual() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    82
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    83
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    84
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    85
                .defaultMethod("staticM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    86
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    87
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    88
                // force an invokevirtual MR of staticM()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    89
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    90
                    .invoke(VIRTUAL, b.intfByName("I"), null, "staticM", "()I", METHODREF).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    91
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    92
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    93
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    94
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    95
        b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    96
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    97
         .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    98
         .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
    99
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   100
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   101
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   102
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   103
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   104
     * testInvokeIntf
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   105
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   106
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   107
     *  default static public int staticM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   108
     *  default public int m() { return ((I)this).staticM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   109
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   110
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   111
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   112
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   113
    public void testInvokeIntf() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   114
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   115
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   116
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   117
                .defaultMethod("staticM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   118
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   119
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   120
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   121
                    .invoke(INTERFACE, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   122
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   123
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   124
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   125
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   126
        b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   127
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   128
         .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   129
         .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   130
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   131
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   132
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   133
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   134
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   135
     * testInvokeSpecial
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   136
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   137
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   138
     *  default static public int staticM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   139
     *  default public int m() { return I.super.staticM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   140
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   141
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   142
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   143
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   144
    public void testInvokeSpecial() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   145
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   146
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   147
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   148
                .defaultMethod("staticM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   149
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   150
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   151
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   152
                    .invoke(SPECIAL, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   153
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   154
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   155
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   156
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   157
        b.test().staticCallSite(I, "staticM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   158
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   159
         .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   160
         .test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   161
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   162
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   163
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   164
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   165
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   166
     * testStaticVsDefault
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   167
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   168
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   169
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   170
     *  default public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   171
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   172
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   173
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   174
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   175
    public void testStaticVsDefault() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   176
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   177
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   178
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   179
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   180
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   181
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   182
                    .public_().returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   183
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   184
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   185
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   186
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   187
        b.test().staticCallSite(I, "m", "()I").throws_(ClassFormatError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   188
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   189
         // FIXME: throws exception during an attempt to lookup Test2.test() method
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   190
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   191
         // Invalid test. ClassFormatError is thrown at verification time, rather
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   192
         // than execution time.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   193
         // .test().callSite(I, C, "m", "()I").throws_(ClassFormatError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   194
         .test().callSite(C, C, "m", "()I").throws_(ClassFormatError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   195
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   196
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   197
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   198
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   199
    // call static method from default method
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   200
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   201
     * testInvokeFromDefaultMethod
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   202
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   203
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   204
     *  default static public int staticPublicM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   205
     *  default public int invokePublic() { return I.staticPublicM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   206
     *  default static private int staticPrivateM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   207
     *  default public int invokePrivate() { return I.staticPrivateM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   208
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   209
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   210
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   211
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   212
    public void testInvokeFromDefaultMethod() throws Exception {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   213
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   214
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   215
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   216
                .defaultMethod("staticPublicM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   217
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   218
                .defaultMethod("invokePublic", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   219
                    .invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   220
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   221
                .defaultMethod("staticPrivateM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   222
                    .static_().private_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   223
                .defaultMethod("invokePrivate", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   224
                    .invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   225
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   226
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   227
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   228
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   229
        Class expectedClass;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   230
        if (factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   231
            expectedClass = NoSuchMethodException.class;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   232
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   233
            expectedClass = IllegalAccessError.class;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   234
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   235
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   236
        // call static method from another class
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   237
        b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   238
         .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedClass).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   239
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   240
         // call public static method from default method
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   241
         .test().callSite(I, C, "invokePublic", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   242
         .test().callSite(C, C, "invokePublic", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   243
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   244
         // call private static method from default method
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   245
         .test().callSite(I, C, "invokePrivate", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   246
         .test().callSite(C, C, "invokePrivate", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   247
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   248
        .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   249
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   250
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   251
    // call static method from implementing subclass
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   252
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   253
     * testInvokeFromSubclass
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   254
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   255
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   256
     *  default static public int staticPublicM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   257
     *  default static private int staticPrivateM() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   258
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   259
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   260
     * class C implements I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   261
     *  public int invokePublic() { return I.staticPublicM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   262
     *  public int invokePrivate() { return I.staticPublicM(); }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   263
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   264
     * I.staticPublicM();  ==> returns 1;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   265
     * I.staticPrivateM(); ==> Either NSME or IAE depending on execution mode
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   266
     * C c = new C(); c.invokePublic(); ==> returns 1 or if -ver < 52 IAE or VerifyError
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   267
     * C c = new C(); c.invokePrivate() ==> IAE or if -ver < 52, IAE or VerifyError
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   268
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   269
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   270
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   271
    @NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   272
    public void testInvokeFromSubclass() throws Exception {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   273
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   274
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   275
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   276
                .defaultMethod("staticPublicM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   277
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   278
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   279
                .defaultMethod("staticPrivateM", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   280
                    .static_().private_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   281
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   282
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   283
        ConcreteClass C = b.clazz("C").implement(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   284
                .concreteMethod("invokePublic", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   285
                    .invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   286
                .concreteMethod("invokePrivate", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   287
                    .invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   288
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   289
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   290
        Class expectedError1;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   291
        if (factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   292
            expectedError1 = NoSuchMethodException.class;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   293
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   294
            expectedError1 = IllegalAccessError.class;
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   295
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   296
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   297
        // Adjust for -ver < 52
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   298
        if (factory.getVer() >=52) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   299
            // call static method from another class
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   300
            b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   301
             .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedError1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   302
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   303
            // call static method from implementing subclass
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   304
             .test().callSite(C, C, "invokePublic", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   305
             .test().callSite(C, C, "invokePrivate", "()I").throws_(IllegalAccessError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   306
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   307
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   308
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   309
            // call static method from another class
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   310
            b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   311
             .test().staticCallSite(I, "staticPrivateM", "()I").throws_(expectedError1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   312
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   313
            // call static method from implementing subclass
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   314
            // invokestatic IMR - not supported for ver < 52
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   315
             .test().callSite(C, C, "invokePublic",  "()I").throws_(VerifyError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   316
             .test().callSite(C, C, "invokePrivate", "()I").throws_(VerifyError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   317
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   318
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   319
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   320
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   321
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   322
    // static method doesn't participate in default method analysis:
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   323
    //   method overriding
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   324
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   325
     * testNotInherited
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   326
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   327
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   328
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   329
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   330
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   331
     * class C implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   332
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   333
    public void testNotInherited() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   334
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   335
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   336
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   337
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   338
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   339
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   340
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   341
        ConcreteClass C = b.clazz("C").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   342
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   343
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   344
            b.test().staticCallSite(I, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   345
              // invokeinterface to static method ==> ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   346
              .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   347
             .test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   348
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   349
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   350
            b.test().staticCallSite(I, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   351
             .test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   352
             .test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   353
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   354
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   355
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   356
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   357
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   358
     * testDefaultVsConcrete
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   359
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   360
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   361
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   362
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   363
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   364
     * class C implements I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   365
     *  public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   366
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   367
     * TEST: I o = new C(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   368
     * TEST: C o = new C(); o.m()I == 2
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   369
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   370
    public void testDefaultVsConcrete() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   371
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   372
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   373
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   374
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   375
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   376
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   377
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   378
        ConcreteClass C = b.clazz("C").implement(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   379
                .concreteMethod("m", "()I").returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   380
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   381
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   382
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   383
            // invokeinterface to static method ==> ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   384
            b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   385
             .test().callSite(C, C, "m", "()I").returns(2).done().run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   386
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   387
            b.test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   388
             .test().callSite(C, C, "m", "()I").returns(2).done().run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   389
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   390
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   391
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   392
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   393
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   394
     * TEST: StaticMethodsTest.testOverrideStatic
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   395
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   396
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   397
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   398
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   399
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   400
     * interface J extends I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   401
     *  default public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   402
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   403
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   404
     * class C implements J {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   405
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   406
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   407
    public void testOverrideStatic() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   408
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   409
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   410
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   411
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   412
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   413
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   414
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   415
        Interface J = b.intf("J").extend(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   416
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   417
                    .returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   418
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   419
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   420
        ConcreteClass C = b.clazz("C").implement(J).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   421
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   422
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   423
            b.test().staticCallSite(I, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   424
             .test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   425
             .test().callSite(J, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   426
             .test().callSite(C, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   427
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   428
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   429
            b.test().staticCallSite(I, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   430
             .test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   431
             .test().callSite(J, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   432
             .test().callSite(C, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   433
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   434
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   435
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   436
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   437
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   438
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   439
     * testOverrideDefault
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   440
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   441
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   442
     *  default public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   443
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   444
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   445
     * interface J extends I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   446
     *  default static public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   447
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   448
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   449
     * class C implements J {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   450
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   451
     * TEST: I o = new C(); o.m()I == 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   452
     * TEST: J o = new C(); o.m()I == ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   453
     * TEST: C o = new C(); o.m()I == 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   454
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   455
    public void testOverrideDefault() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   456
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   457
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   458
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   459
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   460
                    .returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   461
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   462
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   463
        Interface J = b.intf("J").extend(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   464
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   465
                    .static_().public_().returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   466
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   467
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   468
        ConcreteClass C = b.clazz("C").implement(J).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   469
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   470
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   471
            b.test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   472
             .test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   473
             .test().callSite(C, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   474
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   475
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   476
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   477
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   478
            // Reflection correctly finds the static method defined in J and
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   479
            // calls it with invokestatic.
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   480
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   481
            b.test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   482
             .test().callSite(J, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   483
             .test().callSite(C, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   484
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   485
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   486
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   487
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   488
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   489
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   490
     * testReabstract
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   491
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   492
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   493
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   494
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   495
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   496
     * interface J extends I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   497
     *  abstract public int m();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   498
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   499
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   500
     * class C implements J {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   501
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   502
     * TEST: I o = new C(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   503
     *                             -mode reflect returns 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   504
     * TEST: J o = new C(); o.m()I throws AME
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   505
     * TEST: C o = new C(); o.m()I throws AME
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   506
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   507
    public void testReabstract() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   508
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   509
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   510
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   511
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   512
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   513
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   514
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   515
        Interface J = b.intf("J").extend(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   516
                .abstractMethod("m", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   517
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   518
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   519
        ConcreteClass C = b.clazz("C").implement(J).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   520
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   521
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   522
            b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   523
             .test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   524
             .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   525
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   526
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   527
            b.test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   528
             .test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   529
             .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   530
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   531
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   532
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   533
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   534
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   535
     * testOverrideAbstract
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   536
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   537
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   538
     *  abstract public int m();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   539
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   540
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   541
     * interface J extends I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   542
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   543
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   544
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   545
     * class C implements J {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   546
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   547
     * TEST: I o = new C(); o.m()I throws AME
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   548
     * TEST: J o = new C(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   549
     *                             -mode reflect returns 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   550
     * TEST: C o = new C(); o.m()I throws AME
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   551
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   552
    public void testOverrideAbstract() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   553
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   554
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   555
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   556
                .abstractMethod("m", "()I").build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   557
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   558
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   559
        Interface J = b.intf("J").extend(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   560
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   561
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   562
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   563
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   564
        ConcreteClass C = b.clazz("C").implement(J).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   565
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   566
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   567
            b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   568
             .test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   569
             .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   570
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   571
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   572
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   573
            b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   574
             .test().callSite(J, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   575
             .test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   576
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   577
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   578
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   579
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   580
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   581
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   582
     * testInheritedDefault
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   583
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   584
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   585
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   586
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   587
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   588
     * class B implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   589
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   590
     * class C extends B {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   591
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   592
     * TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   593
     *                             -mode reflect returns 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   594
     * TEST: B o = new C(); o.m()I throws NoSuchMethodError
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   595
     * TEST: C o = new C(); o.m()I throws NoSuchMethodError
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   596
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   597
    public void testInheritedDefault() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   598
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   599
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   600
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   601
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   602
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   603
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   604
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   605
        ConcreteClass B = b.clazz("B").implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   606
        ConcreteClass C = b.clazz("C").extend(B).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   607
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   608
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   609
            b.test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   610
             .test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   611
             .test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   612
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   613
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   614
            b.test().callSite(I, C, "m","()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   615
             .test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   616
             .test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   617
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   618
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   619
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   620
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   621
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   622
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   623
     * testDefaultVsConcreteInherited
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   624
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   625
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   626
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   627
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   628
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   629
     * class B {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   630
     *  public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   631
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   632
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   633
     * class C extends B implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   634
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   635
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   636
    public void testDefaultVsConcreteInherited() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   637
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   638
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   639
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   640
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   641
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   642
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   643
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   644
        ConcreteClass B = b.clazz("B")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   645
                .concreteMethod("m", "()I").returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   646
                .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   647
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   648
        ConcreteClass C = b.clazz("C").extend(B).implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   649
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   650
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   651
            b.test().staticCallSite(I, "m","()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   652
             .test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   653
             .test().callSite(B, C, "m","()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   654
             .test().callSite(C, C, "m","()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   655
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   656
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   657
            b.test().staticCallSite(I, "m","()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   658
             .test().callSite(I, C, "m","()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   659
             .test().callSite(B, C, "m","()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   660
             .test().callSite(C, C, "m","()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   661
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   662
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   663
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   664
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   665
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   666
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   667
     * testDefaultVsStaticConflict
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   668
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   669
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   670
     *  default static public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   671
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   672
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   673
     * interface J {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   674
     *  default public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   675
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   676
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   677
     * class C implements I, J {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   678
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   679
     * TEST: I o = new C(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   680
     *                             -mode reflect returns 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   681
     * TEST: J o = new C(); o.m()I == 2
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   682
     * TEST: C o = new C(); o.m()I == 2
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   683
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   684
    public void testDefaultVsStaticConflict() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   685
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   686
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   687
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   688
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   689
                    .static_().public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   690
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   691
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   692
        Interface J = b.intf("J")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   693
                .defaultMethod("m", "()I").returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   694
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   695
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   696
        ConcreteClass C = b.clazz("C").implement(I,J).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   697
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   698
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   699
            b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   700
             .test().callSite(J, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   701
             .test().callSite(C, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   702
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   703
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   704
            b.test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   705
             .test().callSite(J, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   706
             .test().callSite(C, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   707
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   708
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   709
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   710
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   711
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   712
     * testStaticSuperClassVsDefaultSuperInterface
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   713
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   714
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   715
     *  default public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   716
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   717
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   718
     * class A {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   719
     *  public static int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   720
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   721
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   722
     * class C extends A implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   723
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   724
     * TEST: C o = new C(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   725
     *                             -mode reflect returns 2
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   726
     * TEST: I o = new C(); o.m()I == 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   727
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   728
    public void testStaticSuperClassVsDefaultSuperInterface() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   729
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   730
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   731
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   732
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   733
                    .public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   734
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   735
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   736
        ConcreteClass A = b.clazz("A")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   737
                .concreteMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   738
                    .static_().public_().returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   739
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   740
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   741
        ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   742
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   743
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   744
            b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   745
             .test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   746
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   747
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   748
            b.test().callSite(C, C, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   749
             .test().callSite(I, C, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   750
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   751
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   752
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   753
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   754
     * testStaticLocalVsDefaultSuperInterface
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   755
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   756
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   757
     *  default public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   758
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   759
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   760
     * class A implements I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   761
     *  public static int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   762
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   763
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   764
     * class C extends A implements I {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   765
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   766
     * TEST: A o = new A(); o.m()I throws ICCE
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   767
     *                             -mode reflect returns 2
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   768
     * TEST: I o = new A(); o.m()I == 1
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   769
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   770
    public void testStaticLocalVsDefaultSuperInterface() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   771
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   772
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   773
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   774
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   775
                    .public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   776
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   777
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   778
        ConcreteClass A = b.clazz("A").implement(I)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   779
                .concreteMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   780
                    .static_().public_().returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   781
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   782
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   783
        ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   784
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   785
        if (!factory.getExecutionMode().equals("REFLECTION")) {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   786
            b.test().callSite(A, A, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   787
             .test().callSite(I, A, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   788
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   789
        } else {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   790
            b.test().callSite(A, A, "m", "()I").returns(2).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   791
             .test().callSite(I, A, "m", "()I").returns(1).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   792
            .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   793
        }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   794
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   795
    /*
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   796
     * testConflictingDefaultsandStaticMethod
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   797
     * @bug 8033150
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   798
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   799
     * interface I {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   800
     *  default public int m() { return 1; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   801
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   802
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   803
     * interface J {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   804
     *  default public int m() { return 2; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   805
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   806
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   807
     * class A implements I, J {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   808
     *  public static int m() { return 3; }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   809
     * }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   810
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   811
     * class C extends A {}
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   812
     *
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   813
     * TEST: C.m(); should call A.m, return value = 3
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   814
     */
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   815
    public void testConflictingDefaultsandStaticMethod() {
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   816
        TestBuilder b = factory.getBuilder();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   817
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   818
        Interface I = b.intf("I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   819
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   820
                    .public_().returns(1).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   821
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   822
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   823
        Interface J = b.intf("J")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   824
                .defaultMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   825
                    .public_().returns(2).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   826
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   827
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   828
        ConcreteClass A = b.clazz("A").implement(I,J)
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   829
                .concreteMethod("m", "()I")
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   830
                    .static_().public_().returns(3).build()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   831
            .build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   832
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   833
        ConcreteClass C = b.clazz("C").extend(A).build();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   834
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   835
        b.test().staticCallSite(C, "m", "()I").returns(3).done()
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   836
         .run();
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   837
    }
4fac3c99487d 8199255: [TESTBUG] Open source VM testbase default methods tests
mseledtsov
parents:
diff changeset
   838
}