Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/NetworkInterface/Test.java
41149 views
1
/*
2
* Copyright (c) 2001, 2013, 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
/* @test
25
* @bug 4405354 6594296 8058216
26
* @library /test/lib
27
* @run main/othervm -Xcheck:jni Test
28
* @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true Test
29
* @summary Basic tests for NetworkInterface
30
*/
31
import java.net.NetworkInterface;
32
import java.net.InetAddress;
33
import java.util.Enumeration;
34
import jdk.test.lib.net.IPSupport;
35
36
public class Test {
37
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
38
39
public static void main(String args[]) throws Exception {
40
IPSupport.throwSkippedExceptionIfNonOperational();
41
42
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
43
44
while (nifs.hasMoreElements()) {
45
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
46
47
//JDK-8038276: Should not test on Windows with Teredo Tunneling Pseudo-Interface
48
String dName = ni.getDisplayName();
49
if (isWindows && dName != null && dName.contains("Teredo"))
50
continue;
51
52
String name = ni.getName();
53
System.out.println("\n" + name);
54
55
/*
56
* Enumeration the IP addresses on this interface
57
*/
58
Enumeration addrs = ni.getInetAddresses();
59
while (addrs.hasMoreElements()) {
60
InetAddress addr = (InetAddress)addrs.nextElement();
61
System.out.println(addr);
62
if (NetworkInterface.getByInetAddress(addr) == null) {
63
throw new Exception("getByInetAddress returned null");
64
}
65
}
66
System.out.println("getInetAddresses() test passed.");
67
68
/*
69
* Check equals and hashCode contract
70
*/
71
NetworkInterface ni2 = NetworkInterface.getByName(name);
72
if (!ni2.equals(ni)) {
73
throw new Exception("getByName returned: " + ni2);
74
}
75
if (!ni.equals(ni2)) {
76
throw new Exception("equals specification broken");
77
}
78
System.out.println("equals() tests passed.");
79
if (ni2.hashCode() != ni.hashCode()) {
80
throw new Exception("hashCode contract broken");
81
}
82
System.out.println("hashCode() test passed.");
83
84
byte[] ba = ni.getHardwareAddress();
85
if (ba != null && ba.length == 0) {
86
throw new Exception("getHardwareAddress returned 0 length byte array");
87
}
88
System.out.println("getHardwareAddress() test passed.");
89
}
90
91
// misc tests :-
92
// getByXXX(null) should throw NPE
93
// getByXXX("garbage") should return null
94
95
System.out.println("\nMiscellenous tests: ");
96
97
try {
98
NetworkInterface.getByName(null);
99
} catch (NullPointerException npe) {
100
}
101
System.out.println("getByName(null) test passed.");
102
103
try {
104
NetworkInterface.getByInetAddress(null);
105
} catch (NullPointerException npe) {
106
}
107
System.out.println("getByInetAddress(null) test passed.");
108
109
if (NetworkInterface.getByName("not-a-valid-name") != null) {
110
throw new Exception
111
("getByName returned unexpected interface: null expected");
112
}
113
System.out.println("getByName(<unknown>) test passed.");
114
115
InetAddress ia = InetAddress.getByName("255.255.255.255");
116
if (NetworkInterface.getByInetAddress(ia) != null) {
117
throw new Exception
118
("getByInetAddress returned unexpected interface: null expected");
119
}
120
System.out.println("getByName(getByInetAddress(<unknown>) test passed.");
121
122
}
123
}
124
125