Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/CheckMethods.java
41152 views
/*1* Copyright (c) 2003, 2007, 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*/2223/*24* @test25* @bug 479167626* @summary various pass through methods missing in SSLSocketImpl27*/28import java.net.*;29import java.util.*;30import java.lang.reflect.*;3132public class CheckMethods {33static boolean debug = false;34static class MethodSignature {35String name;36Class[] paramTypes;37MethodSignature(String name, Class[] paramTypes) {38this.name = name;39this.paramTypes = paramTypes;40}4142public boolean equals(Object obj) {43if (debug) {44System.out.println("comparing " + this + " against: " + obj);45}46if (!(obj instanceof MethodSignature)) {47if (debug)48System.out.println(false);49return false;50}51MethodSignature ms = (MethodSignature) obj;52Class[] types = ms.paramTypes;53try {54for (int i = 0; i < types.length; i++) {55if (!types[i].equals(paramTypes[i])) {56if (debug)57System.out.println(false);58return false;59}60}61} catch (Exception e) {62if (debug)63System.out.println(false);64return false;65}66boolean result = this.name.equals(ms.name);67if (debug)68System.out.println(result);69return result;70}7172public String toString() {73StringBuffer sb = new StringBuffer(name + "(");74for (int i = 0; i < paramTypes.length; i++) {75sb.append(paramTypes[i].getName() + ",");76if (i == (paramTypes.length - 1))77sb.deleteCharAt(sb.length() - 1);78}79sb.append(")");80return sb.toString();81}82}8384// check that SSLSocket contains all public and protected85// methods defined in Socket86public static void main(String[] args) throws Exception {87ArrayList allMethods = new ArrayList(88Arrays.asList(Socket.class.getDeclaredMethods()));8990ArrayList allMethodSignatures = new ArrayList();91for (Iterator itr = allMethods.iterator(); itr.hasNext();) {92Method m = (Method) itr.next();93// don't include static and private methods94if (!Modifier.isStatic(m.getModifiers()) &&95(Modifier.isPublic(m.getModifiers()) ||96Modifier.isProtected(m.getModifiers()))) {97allMethodSignatures.add( new MethodSignature(m.getName(),98m.getParameterTypes()));99}100}101102// testing Socket103Class sslSI = Class.forName(104"sun.security.ssl.SSLSocketImpl");105Class baseSSLSI = Class.forName(106"sun.security.ssl.BaseSSLSocketImpl");107108ArrayList sslSocketMethods =109new ArrayList(Arrays.asList(sslSI.getDeclaredMethods()));110111sslSocketMethods.addAll( new ArrayList(112Arrays.asList(baseSSLSI.getDeclaredMethods())));113114ArrayList sslSocketMethodSignatures = new ArrayList();115for (Iterator itr = sslSocketMethods.iterator(); itr.hasNext();) {116Method m = (Method) itr.next();117if (!Modifier.isStatic(m.getModifiers())) {118sslSocketMethodSignatures.add(119new MethodSignature(m.getName(),120m.getParameterTypes()));121}122}123124if (!sslSocketMethodSignatures.containsAll(allMethodSignatures)) {125throw new RuntimeException(126"Method definition test failed on SSLSocketImpl");127}128129// testing for non static public field130ArrayList allFields =131new ArrayList(Arrays.asList(Socket.class.getFields()));132133for (Iterator itr = allFields.iterator(); itr.hasNext();) {134Field f = (Field) itr.next();135if (!Modifier.isStatic(f.getModifiers())) {136throw new RuntimeException("Non static Public fields" +137" declared in superclasses");138}139}140}141}142143144