Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/util/IPAddressUtilTest.java
41149 views
1
/*
2
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8087190
27
* @summary Exercise the sun.net.util.IPAddressUtil class
28
* @modules java.base/sun.net.util
29
*/
30
31
import sun.net.util.*;
32
33
/*
34
* Unit test for sun.net.util.IPAddressUtil
35
*/
36
public class IPAddressUtilTest {
37
final static Boolean good = Boolean.TRUE;
38
final static Boolean bad = Boolean.FALSE;
39
40
static Object [][] assertions = {
41
{"224.0.1.0", good},
42
{"238.255.255.255", good},
43
{"239.255.255.255", good},
44
{"238.255.255.2550", bad},
45
{"256.255.255.255", bad},
46
{"238.255.2550.255", bad},
47
{"238.2550.255.255", bad},
48
{"2380.255.255.255", bad},
49
{".1.1.1", bad},
50
{"1..1.1", bad},
51
{"1.1.1.", bad},
52
{"...", bad},
53
{"10::10", good},
54
{"10::10.1", bad},
55
{"10::10.1.2", bad},
56
{"10::10.1.2.3", good},
57
{"10::10.1.2.3.4", bad},
58
{"10::10.", bad},
59
{"10::.10.", bad},
60
{"10::.10", bad}
61
};
62
63
public static void main(String[] args) {
64
for (int i=0; i<assertions.length; i++) {
65
String addr = (String) assertions[i][0];
66
boolean expected = ((Boolean) assertions[i][1]).booleanValue();
67
68
boolean result = true;
69
70
if (!IPAddressUtil.isIPv4LiteralAddress(addr) &&
71
!IPAddressUtil.isIPv6LiteralAddress(addr)) {
72
result = false;
73
}
74
75
if (result != expected) {
76
throw new RuntimeException ("wrong result for " + addr);
77
}
78
}
79
}
80
}
81
82