Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/rmic/minimizeWrapperInstances/Test.java
38855 views
/*1* Copyright (c) 2005, 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*/2223import java.io.ObjectInput;24import java.io.ObjectOutput;25import java.lang.reflect.Constructor;26import java.lang.reflect.Method;27import java.rmi.Remote;28import java.rmi.server.Operation;29import java.rmi.server.RemoteCall;30import java.rmi.server.RemoteObject;31import java.rmi.server.RemoteRef;32import java.util.Arrays;3334public class Test {35public static void main(String[] args) throws Exception {36System.err.println("\nRegression test for RFE 5096178\n");37Class<? extends P> cl =38Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class);39Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class);40cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false);41cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true);42System.err.println("TEST PASSED");43}4445private static void printValues(Object... values) {46System.err.print("{ ");47for (int i = 0; i < values.length; i++) {48if (i > 0) {49System.err.print(", ");50}51printValue(values[i]);52}53System.err.println(" }");54}5556private static void printValue(Object value) {57System.err.print(value.getClass().getName() + "@" +58System.identityHashCode(value) + "(" + value + ")");59}6061private static class ArgCheckingRemoteRef extends AbstractRemoteRef {62Object[] expected;63ArgCheckingRemoteRef(Object... expected) {64this.expected = expected;65}66protected void test(Object[] args) {67System.err.print("expected argument values: ");68printValues(expected);69System.err.print(" actual argument values: ");70printValues(args);71if (args.length != expected.length) {72throw new Error("wrong number of arguments");73}74for (int i = 0; i < args.length; i++) {75if (args[i] != expected[i]) {76throw new Error("args[" + i + "] not expected value");77}78}79}80}8182private static abstract class AbstractRemoteRef implements RemoteRef {83AbstractRemoteRef() { }84protected abstract void test(Object[] args);85public Object invoke(Remote obj,86Method method,87Object[] args,88long opnum)89{90test(args);91return null;92}93public RemoteCall newCall(RemoteObject obj,94Operation[] op,95int opnum,96long hash)97{98throw new AssertionError();99}100public void invoke(RemoteCall call) { throw new AssertionError(); }101public void done(RemoteCall call) { throw new AssertionError(); }102public String getRefClass(ObjectOutput out) {103throw new AssertionError();104}105public int remoteHashCode() { throw new AssertionError(); }106public boolean remoteEquals(RemoteRef obj) {107throw new AssertionError();108}109public String remoteToString() { throw new AssertionError(); }110public void writeExternal(ObjectOutput out) {111throw new AssertionError();112}113public void readExternal(ObjectInput in) {114throw new AssertionError();115}116}117}118119120