Path: blob/master/test/jdk/java/lang/Package/IsCompatibleWith.java
41149 views
/*1* Copyright (c) 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*/2223public class IsCompatibleWith {24private static boolean fail = false;25private static Package p = p.A.class.getPackage();2627public static void main(String [] args) {28IsCompatibleWith s = new IsCompatibleWith();2930s.ex("");31s.ex("x.31");32s.ex("5....");33s.ex("10.3a");34s.ex("2.-2");35s.ex("-1.0");36s.ex(".01");3738s.t("0");39s.t("1.4");40s.t("1.4.0");41s.f("1.415");42s.t("1.3.1.0.0.0.0.7");43s.t("1.2.02");44s.f("1.4.35");45s.f("33.0");4647s.f(new Integer(Integer.MAX_VALUE).toString());48s.ex("2147483648"); // Integer.MAX_VALUE + 14950if (fail == true)51throw new RuntimeException("Test FAILED");52else53System.out.println("Test PASSED");54}5556// NumberFormatException expected57private void ex(String s) {58try {59p.isCompatibleWith(s);60} catch (NumberFormatException e) {61System.out.println("PASS: \"" + s + "\"");62e.printStackTrace(System.out);63return;64}65fail = true;66System.err.println("FAIL: Exception missing: \"" + s + "\"");67}6869// "true" or "false" expected70private void t(String s) { test(s, true); }71private void f(String s) { test(s, false); }7273private void test(String s, boolean expect) {74try {75if (p.isCompatibleWith(s) != expect) {76System.err.println("FAIL: \"" + s + "\", expected: " + expect);77fail = true;78return;79}80} catch (Exception e) {81System.err.println("FAIL: \"" + s + "\"");82e.printStackTrace();83fail = true;84return;85}86System.out.println("PASS: \"" + s + "\"");87}88}899091