test/jdk/sun/net/util/IPAddressUtilTest.java
author dholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
32271
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    24
/*
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    25
 * @test
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    26
 * @bug 8087190
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    27
 * @summary Exercise the sun.net.util.IPAddressUtil class
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 32271
diff changeset
    28
 * @modules java.base/sun.net.util
32271
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    29
 */
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    30
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.net.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Unit test for sun.net.util.IPAddressUtil
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class IPAddressUtilTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    final static Boolean good = Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    final static Boolean bad = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static Object [][] assertions = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        {"224.0.1.0", good},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        {"238.255.255.255", good},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        {"239.255.255.255", good},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        {"238.255.255.2550", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        {"256.255.255.255", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        {"238.255.2550.255", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        {"238.2550.255.255", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        {"2380.255.255.255", bad},
32271
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    49
        {".1.1.1", bad},
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    50
        {"1..1.1", bad},
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    51
        {"1.1.1.", bad},
d6cb1602f271 8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
robm
parents: 5506
diff changeset
    52
        {"...", bad},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        {"10::10", good},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        {"10::10.1", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        {"10::10.1.2", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        {"10::10.1.2.3", good},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        {"10::10.1.2.3.4", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        {"10::10.", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        {"10::.10.", bad},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        {"10::.10", bad}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        for (int i=0; i<assertions.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            String addr = (String) assertions[i][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            boolean expected = ((Boolean) assertions[i][1]).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            boolean result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (!IPAddressUtil.isIPv4LiteralAddress(addr) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                !IPAddressUtil.isIPv6LiteralAddress(addr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (result != expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                throw new RuntimeException ("wrong result for " + addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
}