Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/SocketOption/ImmutableOptions.java
41152 views
1
/*
2
* Copyright (c) 2016, 2018, 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 8148609
27
* @library /test/lib
28
* @summary Assert that the set of socket options are immutable
29
* @run testng/othervm ImmutableOptions
30
* @run testng/othervm -Djava.net.preferIPv4Stack=true ImmutableOptions
31
*/
32
import java.io.IOException;
33
import java.io.InputStream;
34
import java.io.OutputStream;
35
import java.net.*;
36
import java.util.Set;
37
38
import jdk.test.lib.net.IPSupport;
39
40
import org.testng.annotations.BeforeTest;
41
import org.testng.annotations.Test;
42
43
public class ImmutableOptions {
44
45
@BeforeTest
46
void setupServerSocketFactory() throws IOException {
47
IPSupport.throwSkippedExceptionIfNonOperational();
48
ServerSocket.setSocketFactory(new ServerSocketImplFactory());
49
}
50
51
@Test(expectedExceptions = UnsupportedOperationException.class)
52
public void socketThrows() throws IOException {
53
CustomSocketImpl impl = new CustomSocketImpl();
54
Socket socket = new CustomSocket(impl);
55
socket.supportedOptions().clear();
56
}
57
58
@Test(expectedExceptions = UnsupportedOperationException.class)
59
public void socketImplThrows() throws IOException {
60
CustomSocketImpl impl = new CustomSocketImpl();
61
impl.supportedOptions().clear();
62
}
63
64
@Test(expectedExceptions = UnsupportedOperationException.class)
65
public void serverSocketThrows() throws IOException {
66
ServerSocket ss = new ServerSocket();
67
ss.supportedOptions().clear();
68
}
69
70
@Test(expectedExceptions = UnsupportedOperationException.class)
71
public void serverSocketImplThrows() throws IOException {
72
ServerSocket ss = new ServerSocket();
73
ServerSocketImplFactory.mostRecentlyCreated.supportedOptions().clear();
74
}
75
76
@Test(expectedExceptions = UnsupportedOperationException.class)
77
public void datagramSocketThrows() throws IOException {
78
CustomDatagramSocketImpl impl = new CustomDatagramSocketImpl();
79
DatagramSocket socket = new CustomDatagramSocket(impl);
80
socket.supportedOptions().clear();
81
}
82
83
@Test(expectedExceptions = UnsupportedOperationException.class)
84
public void datagramSocketImplThrows() throws IOException {
85
CustomDatagramSocketImpl impl = new CustomDatagramSocketImpl();
86
impl.supportedOptions().clear();
87
}
88
89
90
// Socket descendants
91
static class CustomSocket extends Socket {
92
public CustomSocket(SocketImpl impl) throws IOException {
93
super(impl);
94
}
95
}
96
97
static class CustomDatagramSocket extends DatagramSocket {
98
public CustomDatagramSocket(DatagramSocketImpl impl) {
99
super(impl);
100
}
101
}
102
103
static class ServerSocketImplFactory implements SocketImplFactory {
104
static volatile CustomSocketImpl mostRecentlyCreated;
105
106
@Override public SocketImpl createSocketImpl() {
107
return mostRecentlyCreated = new CustomSocketImpl();
108
}
109
}
110
111
// Custom impl's
112
static class CustomSocketImpl extends SocketImpl {
113
// The only method interesting to this test.
114
@Override public Set<SocketOption<?>> supportedOptions() {
115
return super.supportedOptions();
116
}
117
118
public void create(boolean stream) throws IOException { }
119
120
public void connect(String host, int port) throws IOException { }
121
122
public void connect(InetAddress addr, int port) throws IOException { }
123
124
public void connect(SocketAddress addr, int timeout) throws IOException { }
125
126
public void bind(InetAddress host, int port) throws IOException { }
127
128
public void listen(int backlog) throws IOException { }
129
130
public void accept(SocketImpl s) throws IOException { }
131
132
public InputStream getInputStream() throws IOException { return null; }
133
134
public OutputStream getOutputStream() throws IOException { return null; }
135
136
public int available() throws IOException { return 0; }
137
138
public void close() throws IOException { }
139
140
public void sendUrgentData(int data) throws IOException { }
141
142
public Object getOption(int i) throws SocketException { return null; }
143
144
public void setOption(int i, Object o) throws SocketException { }
145
}
146
147
static class CustomDatagramSocketImpl extends DatagramSocketImpl {
148
// The only method interesting to this test.
149
@Override public Set<SocketOption<?>> supportedOptions() {
150
return super.supportedOptions();
151
}
152
153
protected void create() throws SocketException { }
154
155
protected void bind(int lport, InetAddress laddr) throws SocketException { }
156
157
protected void send(DatagramPacket p) throws IOException { }
158
159
protected int peek(InetAddress i) throws IOException { return 0; }
160
161
protected int peekData(DatagramPacket p) throws IOException { return 0; }
162
163
protected void receive(DatagramPacket p) throws IOException { }
164
165
protected void setTTL(byte ttl) throws IOException { }
166
167
protected byte getTTL() throws IOException { return 0; }
168
169
protected void setTimeToLive(int ttl) throws IOException { }
170
171
protected int getTimeToLive() throws IOException { return 0; }
172
173
protected void join(InetAddress inetaddr) throws IOException { }
174
175
protected void leave(InetAddress inetaddr) throws IOException { }
176
177
protected void joinGroup(SocketAddress x, NetworkInterface y)
178
throws IOException { }
179
180
protected void leaveGroup(SocketAddress x, NetworkInterface y)
181
throws IOException { }
182
183
protected void close() { }
184
185
public void setOption(int optID, Object value) throws SocketException { }
186
187
public Object getOption(int optID) throws SocketException { return null; }
188
}
189
}
190
191