1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @summary Test of method selection and resolution cases that
  27  * generate InvokeInterfaceSuccessTest
  28  * @run main InvokeInterfaceSuccessTest
  29  */
  30 
  31 import java.util.function.Consumer;
  32 import java.util.Collection;
  33 import java.util.Collections;
  34 import java.util.Arrays;
  35 import java.util.EnumSet;
  36 
  37 public class InvokeInterfaceSuccessTest extends SelectionResolutionTest {
  38 
  39     private static final SelectionResolutionTestCase.Builder initBuilder =
  40         new SelectionResolutionTestCase.Builder();
  41 
  42     static {
  43         initBuilder.invoke = SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE;
  44     }
  45 
  46     private static final Collection<TestGroup> testgroups =
  47         Arrays.asList(
  48                 /* invokeinterface tests */
  49 
  50                 /* Group 40: callsite = methodref = expected */
  51                 new TestGroup.Simple(initBuilder,
  52                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  53                                              EnumSet.of(MethodData.Access.PUBLIC),
  54                                              EnumSet.of(MethodData.Context.INSTANCE,
  55                                                         MethodData.Context.ABSTRACT),
  56                                              EnumSet.of(ClassData.Package.SAME)),
  57                         Template.OverrideAbstractExpectedIface,
  58                         Template.MethodrefEqualsExpected,
  59                         Template.IgnoredAbstract,
  60                         Template.CallsiteEqualsMethodref,
  61                         Template.IfaceMethodrefSelection,
  62                         Template.SelectionOverrideAbstract),
  63                 /* Group 41: callsite = methodref, methodref != expected */
  64                 new TestGroup.Simple(initBuilder,
  65                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  66                                              EnumSet.of(MethodData.Access.PUBLIC),
  67                                              EnumSet.of(MethodData.Context.INSTANCE,
  68                                                         MethodData.Context.ABSTRACT),
  69                                              EnumSet.of(ClassData.Package.SAME,
  70                                                         ClassData.Package.DIFFERENT)),
  71                         Template.OverrideAbstractExpectedIface,
  72                         Template.IfaceMethodrefNotEqualsExpected,
  73                         Template.IgnoredAbstract,
  74                         Template.CallsiteEqualsMethodref,
  75                         Template.IfaceMethodrefSelection,
  76                         Template.SelectionOverrideAbstract),
  77                 /* Group 42: callsite :> methodref, methodref = expected */
  78                 new TestGroup.Simple(initBuilder,
  79                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  80                                              EnumSet.of(MethodData.Access.PUBLIC),
  81                                              EnumSet.of(MethodData.Context.INSTANCE,
  82                                                         MethodData.Context.ABSTRACT),
  83                                              EnumSet.of(ClassData.Package.SAME,
  84                                                         ClassData.Package.DIFFERENT)),
  85                         Template.OverrideAbstractExpectedIface,
  86                         Template.MethodrefEqualsExpected,
  87                         Template.IgnoredAbstract,
  88                         Template.CallsiteSubclassMethodref,
  89                         Template.IfaceMethodrefSelection,
  90                         Template.SelectionOverrideAbstract),
  91                 /* Group 43: callsite :> methodref, methodref != expected */
  92                 new TestGroup.Simple(initBuilder,
  93                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  94                                              EnumSet.of(MethodData.Access.PUBLIC),
  95                                              EnumSet.of(MethodData.Context.INSTANCE,
  96                                                         MethodData.Context.ABSTRACT),
  97                                              EnumSet.of(ClassData.Package.SAME,
  98                                                         ClassData.Package.DIFFERENT)),
  99                         Template.OverrideAbstractExpectedIface,
 100                         Template.IfaceMethodrefNotEqualsExpected,
 101                         Template.IgnoredAbstract,
 102                         Template.CallsiteSubclassMethodref,
 103                         Template.IfaceMethodrefSelection,
 104                         Template.SelectionOverrideAbstract),
 105                 /* Group 44: callsite unrelated to methodref, methodref = expected */
 106                 new TestGroup.Simple(initBuilder,
 107                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 108                                              EnumSet.of(MethodData.Access.PUBLIC),
 109                                              EnumSet.of(MethodData.Context.INSTANCE,
 110                                                         MethodData.Context.ABSTRACT),
 111                                              EnumSet.of(ClassData.Package.SAME,
 112                                                         ClassData.Package.DIFFERENT)),
 113                         Template.OverrideAbstractExpectedIface,
 114                         Template.MethodrefEqualsExpected,
 115                         Template.IgnoredAbstract,
 116                         Template.CallsiteUnrelatedToMethodref,
 117                         Template.IfaceMethodrefSelection,
 118                         Template.SelectionOverrideAbstract),
 119                 /* Group 45: callsite unrelated to methodref, methodref != expected */
 120                 new TestGroup.Simple(initBuilder,
 121                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 122                                              EnumSet.of(MethodData.Access.PUBLIC),
 123                                              EnumSet.of(MethodData.Context.INSTANCE,
 124                                                         MethodData.Context.ABSTRACT),
 125                                              EnumSet.of(ClassData.Package.SAME,
 126                                                         ClassData.Package.DIFFERENT)),
 127                         Template.OverrideAbstractExpectedIface,
 128                         Template.IfaceMethodrefNotEqualsExpected,
 129                         Template.IgnoredAbstract,
 130                         Template.CallsiteUnrelatedToMethodref,
 131                         Template.IfaceMethodrefSelection,
 132                         Template.SelectionOverrideAbstract)
 133             );
 134 
 135     private InvokeInterfaceSuccessTest() {
 136         super(testgroups);
 137     }
 138 
 139     public static void main(final String... args) {
 140         new InvokeInterfaceSuccessTest().run();
 141     }
 142 }