test/com/sun/jdi/InterfaceMethodsTest.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8160987.2 Sdiff test/com/sun/jdi

test/com/sun/jdi/InterfaceMethodsTest.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, 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  */


 180         // invoke the InterfaceA's "defaultMethodB"
 181         testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
 182 
 183         // invoke the InterfaceA's "defaultMethodC"
 184         testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_A));
 185 
 186         // "defaultMethodD" from InterfaceB is not accessible from here
 187         testInvokeNeg(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B),
 188                 "Attempted to invoke non-existing method");
 189 
 190         // trying to invoke the asbtract method "implementedMethod"
 191         testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(TARGET_CLASS_NAME),
 192                 "Invocation of non-default methods is not supported");
 193 
 194 
 195         /* Static method calls */
 196 
 197         // invoke interface static method A
 198         testInvokePos(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
 199 
 200         // try to invoke static method A on the instance
 201         testInvokePos(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));



 202 
 203         // invoke interface static method B
 204         testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
 205 
 206         // try to invoke static method B on the instance
 207         testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));



 208 
 209         // try to invoke a virtual method
 210         testInvokePos(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_A), true);
 211     }
 212 
 213     private void testInterfaceB(ObjectReference ref) {
 214         // Test non-virtual calls on InterfaceB
 215         ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEB_NAME).get(0);
 216 
 217         /* Default method calls */
 218 
 219         // invoke the inherited "defaultMethodA"
 220         testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
 221 
 222         // invoke the inherited "defaultMethodB"
 223         testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
 224 
 225         // invoke the inherited and overridden "defaultMethodC"
 226         testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_B));
 227 


 230 
 231         // "implementedMethod" is not present in InterfaceB
 232         testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET),
 233                 "Invocation of non-default methods is not supported");
 234 
 235 
 236         /* Static method calls*/
 237 
 238         // "staticMethodA" must not be inherited by InterfaceB
 239         testInvokeNeg(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
 240                 "Static interface methods are not inheritable");
 241 
 242         // however it is possible to call "staticMethodA" on the actual instance
 243         testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
 244                 "Static interface methods are not inheritable");
 245 
 246         // "staticMethodB" is overridden in InterfaceB
 247         testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
 248 
 249         // the instance invokes the overriden form of "staticMethodB" from InterfaceB
 250         testInvokePos(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));



 251 
 252         // "staticMethodC" is present only in InterfaceB
 253         testInvokePos(ifaceClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
 254 
 255         // "staticMethodC" should be reachable from the instance too
 256         testInvokePos(ifaceClass, ref, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));



 257     }
 258 
 259     private void testImplementationClass(ReferenceType targetClass, ObjectReference thisObject) {
 260         // Test invocations on the implementation object
 261 
 262         /* Default method calls */
 263 
 264         // "defaultMethodA" is accessible and not overridden
 265         testInvokePos(targetClass, thisObject, "defaultMethodA", "()I", vm().mirrorOf(RESULT_TARGET));
 266 
 267         // "defaultMethodB" is accessible and overridden in TargetClass
 268         testInvokePos(targetClass, thisObject, "defaultMethodB", "()I", vm().mirrorOf(RESULT_TARGET));
 269 
 270         // "defaultMethodC" is accessible and overridden in InterfaceB
 271         testInvokePos(targetClass, thisObject, "defaultMethodC", "()I", vm().mirrorOf(RESULT_TARGET));
 272 
 273         // "defaultMethodD" is accessible
 274         testInvokePos(targetClass, thisObject, "defaultMethodD", "()I", vm().mirrorOf(RESULT_TARGET));
 275 
 276 


   1 /*
   2  * Copyright (c) 2014, 2016, 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  */


 180         // invoke the InterfaceA's "defaultMethodB"
 181         testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
 182 
 183         // invoke the InterfaceA's "defaultMethodC"
 184         testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_A));
 185 
 186         // "defaultMethodD" from InterfaceB is not accessible from here
 187         testInvokeNeg(ifaceClass, ref, "defaultMethodD", "()I", vm().mirrorOf(RESULT_B),
 188                 "Attempted to invoke non-existing method");
 189 
 190         // trying to invoke the asbtract method "implementedMethod"
 191         testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(TARGET_CLASS_NAME),
 192                 "Invocation of non-default methods is not supported");
 193 
 194 
 195         /* Static method calls */
 196 
 197         // invoke interface static method A
 198         testInvokePos(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A));
 199 
 200         // try to invoke static method A on the instance. This should fail because ref
 201         // is of type InterfacemethodsTest$TargetClass which is not a subtype of the
 202         // class containing staticMethodA.
 203         testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
 204                 "Invalid MethodID");
 205 
 206         // invoke interface static method B
 207         testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_A));
 208 
 209         // try to invoke static method B on the instance. This should fail because ref
 210         // is of type InterfacemethodsTest$TargetClass which is not a subtype of the
 211         // class containing staticMethodB.
 212         testInvokeNeg(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_A),
 213                 "Invalid MethodID");
 214 
 215         // try to invoke a virtual method
 216         testInvokePos(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_A), true);
 217     }
 218 
 219     private void testInterfaceB(ObjectReference ref) {
 220         // Test non-virtual calls on InterfaceB
 221         ReferenceType ifaceClass = (ReferenceType)vm().classesByName(INTERFACEB_NAME).get(0);
 222 
 223         /* Default method calls */
 224 
 225         // invoke the inherited "defaultMethodA"
 226         testInvokePos(ifaceClass, ref, "defaultMethodA", "()I", vm().mirrorOf(RESULT_A));
 227 
 228         // invoke the inherited "defaultMethodB"
 229         testInvokePos(ifaceClass, ref, "defaultMethodB", "()I", vm().mirrorOf(RESULT_A));
 230 
 231         // invoke the inherited and overridden "defaultMethodC"
 232         testInvokePos(ifaceClass, ref, "defaultMethodC", "()I", vm().mirrorOf(RESULT_B));
 233 


 236 
 237         // "implementedMethod" is not present in InterfaceB
 238         testInvokeNeg(ifaceClass, ref, "implementedMethod", "()I", vm().mirrorOf(RESULT_TARGET),
 239                 "Invocation of non-default methods is not supported");
 240 
 241 
 242         /* Static method calls*/
 243 
 244         // "staticMethodA" must not be inherited by InterfaceB
 245         testInvokeNeg(ifaceClass, null, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
 246                 "Static interface methods are not inheritable");
 247 
 248         // however it is possible to call "staticMethodA" on the actual instance
 249         testInvokeNeg(ifaceClass, ref, "staticMethodA", "()I", vm().mirrorOf(RESULT_A),
 250                 "Static interface methods are not inheritable");
 251 
 252         // "staticMethodB" is overridden in InterfaceB
 253         testInvokePos(ifaceClass, null, "staticMethodB", "()I", vm().mirrorOf(RESULT_B));
 254 
 255         // the instance invokes the overriden form of "staticMethodB" from InterfaceB
 256         // This should fail because ref is of type InterfacemethodsTest$TargetClass
 257         // which is not a subtype of the class containing staticMethodB.
 258         testInvokeNeg(ifaceClass, ref, "staticMethodB", "()I", vm().mirrorOf(RESULT_B),
 259                 "Invalid MethodID");
 260 
 261         // "staticMethodC" is present only in InterfaceB
 262         testInvokePos(ifaceClass, null, "staticMethodC", "()I", vm().mirrorOf(RESULT_B));
 263 
 264         // "staticMethodC" should not be reachable from the instance because ref is of
 265         // type InterfacemethodsTest$TargetClass which is not a subtype of the class
 266         // containing staticMethodC.
 267         testInvokeNeg(ifaceClass, ref, "staticMethodC", "()I", vm().mirrorOf(RESULT_B),
 268                 "Invalid MethodID");
 269     }
 270 
 271     private void testImplementationClass(ReferenceType targetClass, ObjectReference thisObject) {
 272         // Test invocations on the implementation object
 273 
 274         /* Default method calls */
 275 
 276         // "defaultMethodA" is accessible and not overridden
 277         testInvokePos(targetClass, thisObject, "defaultMethodA", "()I", vm().mirrorOf(RESULT_TARGET));
 278 
 279         // "defaultMethodB" is accessible and overridden in TargetClass
 280         testInvokePos(targetClass, thisObject, "defaultMethodB", "()I", vm().mirrorOf(RESULT_TARGET));
 281 
 282         // "defaultMethodC" is accessible and overridden in InterfaceB
 283         testInvokePos(targetClass, thisObject, "defaultMethodC", "()I", vm().mirrorOf(RESULT_TARGET));
 284 
 285         // "defaultMethodD" is accessible
 286         testInvokePos(targetClass, thisObject, "defaultMethodD", "()I", vm().mirrorOf(RESULT_TARGET));
 287 
 288 


test/com/sun/jdi/InterfaceMethodsTest.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File