Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/MulticastSocket/IPMulticastIF.java
41149 views
1
/*
2
* Copyright (c) 2019, 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
import java.net.InetAddress;
25
import java.net.InetSocketAddress;
26
import java.net.MulticastSocket;
27
import java.net.NetworkInterface;
28
import java.util.ArrayList;
29
import java.util.List;
30
import jdk.test.lib.NetworkConfiguration;
31
import jdk.test.lib.net.IPSupport;
32
import org.testng.annotations.BeforeTest;
33
import org.testng.annotations.DataProvider;
34
import org.testng.annotations.Test;
35
import static java.lang.String.format;
36
import static java.lang.System.out;
37
import static java.net.StandardSocketOptions.IP_MULTICAST_IF;
38
import static java.util.stream.Collectors.toList;
39
import static org.testng.Assert.assertEquals;
40
import static org.testng.Assert.assertTrue;
41
42
/**
43
* @test
44
* @bug 8236441
45
* @summary Bound MulticastSocket fails when setting outbound interface on Windows
46
* @library /test/lib
47
* @run testng IPMulticastIF
48
* @run testng/othervm -Djava.net.preferIPv4Stack=true IPMulticastIF
49
* @run testng/othervm -Djava.net.preferIPv6Addresses=true IPMulticastIF
50
* @run testng/othervm -Djava.net.preferIPv6Addresses=true -Djava.net.preferIPv4Stack=true IPMulticastIF
51
*/
52
public class IPMulticastIF {
53
54
@BeforeTest
55
public void sanity() {
56
IPSupport.throwSkippedExceptionIfNonOperational();
57
NetworkConfiguration.printSystemConfiguration(out);
58
}
59
60
@DataProvider(name = "scenarios")
61
public Object[][] positive() throws Exception {
62
List<InetAddress> addrs = List.of(InetAddress.getLocalHost(),
63
InetAddress.getLoopbackAddress());
64
List<Object[]> list = new ArrayList<>();
65
NetworkConfiguration nc = NetworkConfiguration.probe();
66
addrs.stream().forEach(a -> nc.multicastInterfaces(true)
67
.map(nif -> new Object[] { new InetSocketAddress(a, 0), nif })
68
.forEach(list::add) );
69
70
return list.stream().toArray(Object[][]::new);
71
}
72
73
@Test(dataProvider = "scenarios")
74
public void testSetGetInterfaceBound(InetSocketAddress bindAddr, NetworkInterface nif)
75
throws Exception
76
{
77
out.println(format("\n\n--- testSetGetInterfaceBound bindAddr=[%s], nif=[%s]", bindAddr, nif));
78
try (MulticastSocket ms = new MulticastSocket(bindAddr)) {
79
ms.setNetworkInterface(nif);
80
NetworkInterface msNetIf = ms.getNetworkInterface();
81
assertEquals(msNetIf, nif);
82
}
83
}
84
85
@Test(dataProvider = "scenarios")
86
public void testSetGetInterfaceUnbound(InetSocketAddress ignore, NetworkInterface nif)
87
throws Exception
88
{
89
out.println(format("\n\n--- testSetGetInterfaceUnbound nif=[%s]", nif));
90
try (MulticastSocket ms = new MulticastSocket()) {
91
ms.setNetworkInterface(nif);
92
NetworkInterface msNetIf = ms.getNetworkInterface();
93
assertEquals(msNetIf, nif);
94
}
95
}
96
97
@Test(dataProvider = "scenarios")
98
public void testSetGetOptionBound(InetSocketAddress bindAddr, NetworkInterface nif)
99
throws Exception
100
{
101
out.println(format("\n\n--- testSetGetOptionBound bindAddr=[%s], nif=[%s]", bindAddr, nif));
102
try (MulticastSocket ms = new MulticastSocket(bindAddr)) {
103
ms.setOption(IP_MULTICAST_IF, nif);
104
NetworkInterface msNetIf = ms.getOption(IP_MULTICAST_IF);
105
assertEquals(msNetIf, nif);
106
}
107
}
108
109
@Test(dataProvider = "scenarios")
110
public void testSetGetOptionUnbound(InetSocketAddress ignore, NetworkInterface nif)
111
throws Exception
112
{
113
out.println(format("\n\n--- testSetGetOptionUnbound nif=[%s]", nif));
114
try (MulticastSocket ms = new MulticastSocket()) {
115
ms.setOption(IP_MULTICAST_IF, nif);
116
NetworkInterface msNetIf = ms.getOption(IP_MULTICAST_IF);
117
assertEquals(msNetIf, nif);
118
}
119
}
120
121
// -- get without set
122
123
@DataProvider(name = "bindAddresses")
124
public Object[][] bindAddresses() throws Exception {
125
return new Object[][] {
126
{ new InetSocketAddress(InetAddress.getLocalHost(), 0) },
127
{ new InetSocketAddress(InetAddress.getLoopbackAddress(), 0) },
128
};
129
}
130
131
@Test(dataProvider = "bindAddresses")
132
public void testGetInterfaceBound(InetSocketAddress bindAddr)
133
throws Exception
134
{
135
out.println(format("\n\n--- testGetInterfaceBound bindAddr=[%s]", bindAddr));
136
try (MulticastSocket ms = new MulticastSocket(bindAddr)) {
137
assertPlaceHolder(ms.getNetworkInterface());
138
}
139
}
140
141
@Test
142
public void testGettInterfaceUnbound() throws Exception {
143
out.println("\n\n--- testGettInterfaceUnbound ");
144
try (MulticastSocket ms = new MulticastSocket()) {
145
assertPlaceHolder(ms.getNetworkInterface());
146
}
147
}
148
149
@Test(dataProvider = "bindAddresses")
150
public void testGetOptionBound(InetSocketAddress bindAddr)
151
throws Exception
152
{
153
out.println(format("\n\n--- testGetOptionBound bindAddr=[%s]", bindAddr));
154
try (MulticastSocket ms = new MulticastSocket(bindAddr)) {
155
assertEquals(ms.getOption(IP_MULTICAST_IF), null);
156
}
157
}
158
159
@Test
160
public void testGetOptionUnbound() throws Exception {
161
out.println("\n\n--- testGetOptionUnbound ");
162
try (MulticastSocket ms = new MulticastSocket()) {
163
assertEquals(ms.getOption(IP_MULTICAST_IF), null);
164
}
165
}
166
167
// Asserts that the placeholder NetworkInterface has a single InetAddress
168
// that represent any local address.
169
static void assertPlaceHolder(NetworkInterface nif) {
170
List<InetAddress> addrs = nif.inetAddresses().collect(toList());
171
assertEquals(addrs.size(), 1);
172
assertTrue(addrs.get(0).isAnyLocalAddress());
173
}
174
}
175
176