Path: blob/master/test/jdk/jdk/lambda/vm/InterfaceAccessFlagsTest.java
43305 views
/*1* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package vm;2425import java.io.*;2627import org.testng.annotations.Test;28import separate.*;29import separate.Compiler;3031import static org.testng.Assert.*;32import static separate.SourceModel.*;33import static separate.SourceModel.Class;3435public class InterfaceAccessFlagsTest extends TestHarness {36public InterfaceAccessFlagsTest() {37super(false, false);38}3940public void testMethodCallWithFlag(AccessFlag ... flags) {41Class I = new Class("I",42new ConcreteMethod("int", "m", "return priv();", AccessFlag.PUBLIC),43new ConcreteMethod("int", "priv", "return 99;", flags));44Interface Istub = new Interface("I",45new DefaultMethod("int", "m", "return 0;"));46Class C = new Class("C", Istub,47new ConcreteMethod("int", "foo", "return (new C()).m();",48AccessFlag.PUBLIC, AccessFlag.STATIC));49C.addCompilationDependency(Istub.findMethod("m"));5051Compiler compiler = new Compiler(/*Compiler.Flags.VERBOSE*/);52compiler.addPostprocessor(new ClassToInterfaceConverter("I"));53// Turns I from a class into an interface when loading5455ClassLoader cl = compiler.compile(C, I);56try {57java.lang.Class<?> C_class =58java.lang.Class.forName("C", true, cl);59assertNotNull(C_class);60java.lang.reflect.Method m = C_class.getMethod("foo");61assertNotNull(m);62Integer res = (Integer)m.invoke(null);63assertEquals(res.intValue(), 99);64} catch (java.lang.reflect.InvocationTargetException e) {65fail("Unexpected exception: " + e.getCause());66} catch (Throwable e) {67fail("Unexpected exception: " + e);68} finally {69compiler.cleanup();70}71}7273/* excluded: 8187655 */74@Test(enabled=false, groups = "vm_prototype")75public void testPrivateMethodCall() {76testMethodCallWithFlag(AccessFlag.PRIVATE);77}7879@Test(groups = "vm_prototype")80public void testStaticMethodCall() {81testMethodCallWithFlag(AccessFlag.PUBLIC, AccessFlag.STATIC);82}8384@Test(groups = "vm_prototype")85public void testPrivateStaticMethodCall() {86testMethodCallWithFlag(AccessFlag.PRIVATE, AccessFlag.STATIC);87}8889// Test other combos? Protected?90}919293