Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/util/IPAddressUtilTest.java
38839 views
/*1* Copyright (c) 2004, 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 808719026* @summary Exercise the sun.net.util.IPAddressUtil class27*/2829import sun.net.util.*;3031/*32* Unit test for sun.net.util.IPAddressUtil33*/34public class IPAddressUtilTest {35final static Boolean good = Boolean.TRUE;36final static Boolean bad = Boolean.FALSE;3738static Object [][] assertions = {39{"224.0.1.0", good},40{"238.255.255.255", good},41{"239.255.255.255", good},42{"238.255.255.2550", bad},43{"256.255.255.255", bad},44{"238.255.2550.255", bad},45{"238.2550.255.255", bad},46{"2380.255.255.255", bad},47{".1.1.1", bad},48{"1..1.1", bad},49{"1.1.1.", bad},50{"...", bad},51{"10::10", good},52{"10::10.1", bad},53{"10::10.1.2", bad},54{"10::10.1.2.3", good},55{"10::10.1.2.3.4", bad},56{"10::10.", bad},57{"10::.10.", bad},58{"10::.10", bad}59};6061public static void main(String[] args) {62for (int i=0; i<assertions.length; i++) {63String addr = (String) assertions[i][0];64boolean expected = ((Boolean) assertions[i][1]).booleanValue();6566boolean result = true;6768if (!IPAddressUtil.isIPv4LiteralAddress(addr) &&69!IPAddressUtil.isIPv6LiteralAddress(addr)) {70result = false;71}7273if (result != expected) {74throw new RuntimeException ("wrong result for " + addr);75}76}77}78}798081