Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/SocketImpl/TestDefaultBehavior.java
41152 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
/*
25
* @test
26
* @bug 8224477
27
* @summary Basic test for java.net.SocketImpl default behavior
28
* @run testng TestDefaultBehavior
29
*/
30
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.OutputStream;
34
import java.net.InetAddress;
35
import java.net.SocketAddress;
36
import java.net.SocketImpl;
37
import java.net.SocketOption;
38
import java.util.Set;
39
import org.testng.annotations.Test;
40
import static java.lang.Boolean.*;
41
import static java.net.StandardSocketOptions.*;
42
import static org.testng.Assert.assertEquals;
43
import static org.testng.Assert.expectThrows;
44
45
public class TestDefaultBehavior {
46
47
static final Class<NullPointerException> NPE = NullPointerException.class;
48
static final Class<UnsupportedOperationException> UOE = UnsupportedOperationException.class;
49
50
@Test
51
public void socketImpl() {
52
CustomSocketImpl csi = new CustomSocketImpl();
53
54
assertEquals(csi.supportedOptions().size(), 0);
55
56
expectThrows(NPE, () -> csi.setOption(null, null));
57
expectThrows(NPE, () -> csi.setOption(null, 1));
58
expectThrows(UOE, () -> csi.setOption(SO_RCVBUF, 100));
59
expectThrows(UOE, () -> csi.setOption(SO_KEEPALIVE, TRUE));
60
expectThrows(UOE, () -> csi.setOption(SO_KEEPALIVE, FALSE));
61
expectThrows(UOE, () -> csi.setOption(FAKE_SOCK_OPT, TRUE));
62
expectThrows(UOE, () -> csi.setOption(FAKE_SOCK_OPT, FALSE));
63
expectThrows(UOE, () -> csi.setOption(SO_KEEPALIVE, TRUE));
64
65
expectThrows(NPE, () -> csi.getOption(null));
66
expectThrows(UOE, () -> csi.getOption(SO_RCVBUF));
67
expectThrows(UOE, () -> csi.getOption(SO_KEEPALIVE));
68
expectThrows(UOE, () -> csi.getOption(FAKE_SOCK_OPT));
69
}
70
71
static final SocketOption<Boolean> FAKE_SOCK_OPT = new SocketOption<>() {
72
@Override public String name() { return "FAKE_SOCK_OPT"; }
73
@Override public Class<Boolean> type() { return Boolean.class; }
74
};
75
76
// A SocketImpl that delegates the three new-style socket option
77
// methods to the default java.net.SocketImpl implementation.
78
static class CustomSocketImpl extends SocketImpl {
79
80
@Override
81
public <T> void setOption(SocketOption<T> name, T value) throws IOException {
82
super.setOption(name, value);
83
}
84
85
@Override
86
public Set<SocketOption<?>> supportedOptions() {
87
return super.supportedOptions();
88
}
89
90
@Override
91
public <T> T getOption(SocketOption<T> name) throws IOException {
92
return super.getOption(name);
93
}
94
95
// --
96
97
@Override protected void create(boolean stream) { }
98
@Override protected void connect(String host, int port) { }
99
@Override protected void connect(InetAddress address, int port) { }
100
@Override protected void connect(SocketAddress address, int timeout) { }
101
@Override protected void bind(InetAddress host, int port) { }
102
@Override protected void listen(int backlog) { }
103
@Override protected void accept(SocketImpl s) { }
104
@Override protected InputStream getInputStream() { return null; }
105
@Override protected OutputStream getOutputStream() { return null; }
106
@Override protected int available() { return 0; }
107
@Override protected void close() { }
108
@Override protected void sendUrgentData(int data) { }
109
@Override public void setOption(int optID, Object value) { }
110
@Override public Object getOption(int optID) { return null; }
111
}
112
}
113
114