test/jdk/java/net/SocketImpl/BadClient.java
author alanb
Sun, 07 Apr 2019 18:40:55 +0100
branchniosocketimpl-branch
changeset 57310 c1fad761a86e
permissions -rw-r--r--
Add tests for invalid usages of SocketImpl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57310
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     1
/*
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     4
 *
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     8
 *
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    13
 * accompanied this code).
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    14
 *
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    18
 *
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    21
 * questions.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    22
 */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    23
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    24
/*
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    25
 * @test
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    26
 * @modules java.base/java.net:+open java.base/sun.nio.ch:+open
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    27
 * @run testng/othervm BadClient
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    28
 * @summary Test the SocketImpl for scenarios that do not arise with Socket or
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    29
 *          ServerSocket
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    30
 */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    31
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    32
import java.io.IOException;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    33
import java.io.InputStream;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    34
import java.io.OutputStream;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    35
import java.lang.reflect.Constructor;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    37
import java.lang.reflect.Method;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    38
import java.net.InetAddress;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    39
import java.net.InetSocketAddress;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    40
import java.net.ServerSocket;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    41
import java.net.SocketAddress;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    42
import java.net.SocketException;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    43
import java.net.SocketImpl;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    44
import java.net.SocketOption;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    45
import java.net.StandardSocketOptions;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    46
import java.util.Set;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    47
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    48
import org.testng.annotations.Test;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    49
import static org.testng.Assert.*;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    50
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    51
@Test
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    52
public class BadClient {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    53
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    54
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    55
     * Test create when already created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    56
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    57
    public void testCreate1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    58
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    59
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    60
            expectThrows(IOException.class, () -> impl.create(true));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    61
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    62
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    63
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    64
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    65
     * Test create when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    66
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    67
    public void testCreate2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    68
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    69
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    70
        expectThrows(IOException.class, () -> impl.create(true));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    71
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    72
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    73
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    74
     * Test connect when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    75
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    76
    public void testConnect1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    77
        try (var ss = new ServerSocket(0)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    78
            var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    79
            var remote = ss.getLocalSocketAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    80
            expectThrows(IOException.class, () -> impl.connect(remote, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    81
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    82
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    83
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    84
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    85
     * Test connect with unsupported address type
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    86
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    87
    public void testConnect2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    88
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    89
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    90
            var remote = new SocketAddress() { };
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    91
            expectThrows(IOException.class, () -> impl.connect(remote, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    92
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    93
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    94
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    95
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    96
     * Test connect with an unresolved address
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    97
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    98
    public void testConnect3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
    99
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   100
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   101
            var remote = new InetSocketAddress("blah-blah.blah-blah", 80);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   102
            expectThrows(IOException.class, () -> impl.connect(remote, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   103
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   104
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   105
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   106
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   107
     * Test connect when already connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   108
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   109
    public void testConnect4() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   110
        try (var ss = new ServerSocket(0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   111
             var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   112
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   113
            impl.connect(ss.getLocalSocketAddress(), 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   114
            var remote = ss.getLocalSocketAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   115
            expectThrows(IOException.class, () -> impl.connect(remote, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   116
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   117
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   118
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   119
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   120
     * Test connect when impl is closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   121
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   122
    public void testConnect5() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   123
        try (var ss = new ServerSocket(0)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   124
            var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   125
            impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   126
            var remote = ss.getLocalSocketAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   127
            expectThrows(IOException.class, () -> impl.connect(remote, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   128
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   129
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   130
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   131
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   132
     * Test connect(String host, int port)
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   133
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   134
    public void testConnect6() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   135
        try (var ss = new ServerSocket(0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   136
             var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   137
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   138
            impl.connect(ss.getInetAddress().getHostAddress(), ss.getLocalPort());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   139
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   140
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   141
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   142
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   143
     * Test connect(InetAddress address, int port)
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   144
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   145
    public void testConnect7() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   146
        try (var ss = new ServerSocket(0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   147
             var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   148
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   149
            impl.connect(ss.getInetAddress(), ss.getLocalPort());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   150
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   151
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   152
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   153
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   154
     * Test bind when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   155
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   156
    public void testBind1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   157
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   158
        var loopback = InetAddress.getLoopbackAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   159
        expectThrows(IOException.class, () -> impl.bind(loopback, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   160
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   161
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   162
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   163
     * Test bind when already bound
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   164
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   165
    public void testBind2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   166
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   167
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   168
            var loopback = InetAddress.getLoopbackAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   169
            impl.bind(loopback, 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   170
            expectThrows(IOException.class, () -> impl.bind(loopback, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   171
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   172
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   173
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   174
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   175
     * Test bind when connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   176
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   177
    public void testBind3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   178
        try (var ss = new ServerSocket(0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   179
             var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   180
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   181
            impl.connect(ss.getLocalSocketAddress(), 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   182
            var loopback = InetAddress.getLoopbackAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   183
            expectThrows(IOException.class, () -> impl.bind(loopback, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   184
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   185
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   186
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   187
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   188
     * Test bind when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   189
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   190
    public void testBind4() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   191
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   192
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   193
        var loopback = InetAddress.getLoopbackAddress();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   194
        expectThrows(IOException.class, () -> impl.bind(loopback, 0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   195
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   196
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   197
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   198
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   199
     * Test listen when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   200
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   201
    public void testListen1() {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   202
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   203
        expectThrows(IOException.class, () -> impl.listen(16));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   204
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   205
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   206
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   207
     * Test listen when not bound
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   208
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   209
    public void testListen2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   210
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   211
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   212
            expectThrows(IOException.class, () -> impl.listen(16));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   213
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   214
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   215
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   216
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   217
     * Test listen when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   218
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   219
    public void testListen3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   220
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   221
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   222
        expectThrows(IOException.class, () -> impl.listen(16));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   223
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   224
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   225
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   226
     * Test accept when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   227
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   228
    public void testAccept1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   229
        var impl = new PlatformSocketImpl(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   230
        var si = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   231
        expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   232
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   233
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   234
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   235
     * Test accept when not bound
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   236
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   237
    public void testAccept2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   238
        try (var impl = new PlatformSocketImpl(true)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   239
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   240
            var si = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   241
            expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   242
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   243
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   244
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   245
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   246
     * Test accept when not a stream socket
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   247
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   248
    public void testAccept3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   249
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   250
            impl.create(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   251
            impl.bind(InetAddress.getLoopbackAddress(), 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   252
            var si = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   253
            expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   254
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   255
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   256
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   257
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   258
     * Test accept when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   259
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   260
    public void testAccept4() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   261
        var impl = new PlatformSocketImpl(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   262
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   263
        var si = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   264
        expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   265
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   266
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   267
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   268
     * Test accept with SocketImpl that is already created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   269
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   270
    public void testAccept5() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   271
        try (var impl = new PlatformSocketImpl(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   272
             var si = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   273
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   274
            impl.bind(InetAddress.getLoopbackAddress(), 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   275
            si.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   276
            expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   277
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   278
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   279
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   280
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   281
     * Test accept with SocketImpl that is closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   282
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   283
    public void testAccept6() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   284
        try (var impl = new PlatformSocketImpl(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   285
             var si = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   286
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   287
            impl.bind(InetAddress.getLoopbackAddress(), 0);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   288
            si.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   289
            si.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   290
            expectThrows(IOException.class, () -> impl.accept(si));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   291
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   292
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   293
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   294
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   295
     * Test available when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   296
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   297
    public void testAvailable1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   298
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   299
        expectThrows(IOException.class, () -> impl.available());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   300
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   301
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   302
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   303
     * Test available when created but not connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   304
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   305
    public void testAvailable2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   306
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   307
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   308
            expectThrows(IOException.class, () -> impl.available());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   309
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   310
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   311
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   312
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   313
     * Test available when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   314
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   315
    public void testAvailable3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   316
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   317
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   318
        expectThrows(IOException.class, () -> impl.available());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   319
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   320
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   321
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   322
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   323
     * Test setOption with unsupported option
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   324
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   325
    public void testSetOption1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   326
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   327
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   328
            var opt = new SocketOption<String>() {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   329
                @Override public String name() { return "birthday"; }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   330
                @Override public Class<String> type() { return String.class; }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   331
            };
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   332
            expectThrows(UnsupportedOperationException.class, () -> impl.setOption(opt, "today"));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   333
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   334
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   335
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   336
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   337
     * Test setOption when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   338
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   339
    public void testSetOption2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   340
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   341
        var opt = StandardSocketOptions.SO_REUSEADDR;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   342
        expectThrows(IOException.class, () -> impl.setOption(opt, true));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   343
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   344
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   345
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   346
     * Test setOption when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   347
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   348
    public void testSetOption3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   349
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   350
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   351
        var opt = StandardSocketOptions.SO_REUSEADDR;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   352
        expectThrows(IOException.class, () -> impl.setOption(opt, true));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   353
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   354
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   355
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   356
     * Test getOption with unsupported option
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   357
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   358
    public void testGetOption1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   359
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   360
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   361
            var opt = new SocketOption<String>() {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   362
                @Override public String name() { return "birthday"; }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   363
                @Override public Class<String> type() { return String.class; }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   364
            };
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   365
            expectThrows(UnsupportedOperationException.class, () -> impl.getOption(opt));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   366
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   367
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   368
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   369
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   370
     * Test getOption when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   371
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   372
    public void testGetOption2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   373
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   374
        var opt = StandardSocketOptions.SO_REUSEADDR;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   375
        expectThrows(IOException.class, () -> impl.getOption(opt));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   376
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   377
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   378
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   379
     * Test getOption when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   380
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   381
    public void testGetOption3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   382
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   383
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   384
        var opt = StandardSocketOptions.SO_REUSEADDR;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   385
        expectThrows(IOException.class, () -> impl.getOption(opt));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   386
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   387
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   388
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   389
     * Test shutdownInput when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   390
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   391
    public void testShutdownInput1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   392
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   393
        expectThrows(IOException.class, () -> impl.shutdownInput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   394
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   395
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   396
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   397
     * Test shutdownInput when not connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   398
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   399
    public void testShutdownInput2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   400
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   401
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   402
            expectThrows(IOException.class, () -> impl.shutdownInput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   403
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   404
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   405
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   406
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   407
     * Test shutdownInput when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   408
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   409
    public void testShutdownInput3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   410
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   411
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   412
        expectThrows(IOException.class, () -> impl.shutdownInput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   413
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   414
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   415
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   416
     * Test shutdownOutput when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   417
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   418
    public void testShutdownOutput1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   419
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   420
        expectThrows(IOException.class, () -> impl.shutdownOutput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   421
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   422
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   423
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   424
     * Test shutdownOutput when not connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   425
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   426
    public void testShutdownOutput2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   427
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   428
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   429
            expectThrows(IOException.class, () -> impl.shutdownOutput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   430
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   431
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   432
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   433
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   434
     * Test shutdownOutput when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   435
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   436
    public void testShutdownOutput3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   437
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   438
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   439
        expectThrows(IOException.class, () -> impl.shutdownOutput());
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   440
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   441
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   442
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   443
     * Test sendUrgentData when not created
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   444
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   445
    public void testSendUrgentData1() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   446
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   447
        expectThrows(IOException.class, () -> impl.sendUrgentData(0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   448
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   449
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   450
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   451
     * Test sendUrgentData when not connected
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   452
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   453
    public void testSendUrgentData2() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   454
        try (var impl = new PlatformSocketImpl(false)) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   455
            impl.create(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   456
            expectThrows(IOException.class, () -> impl.sendUrgentData(0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   457
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   458
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   459
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   460
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   461
     * Test sendUrgentData when closed
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   462
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   463
    public void testSendUrgentData3() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   464
        var impl = new PlatformSocketImpl(false);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   465
        impl.close();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   466
        expectThrows(IOException.class, () -> impl.sendUrgentData(0));
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   467
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   468
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   469
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   470
    /**
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   471
     * A SocketImpl that delegates all operations to a NioSocketImpl.
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   472
     */
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   473
    static class PlatformSocketImpl extends SocketImpl implements AutoCloseable {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   474
        private final SocketImpl impl;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   475
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   476
        PlatformSocketImpl(boolean server) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   477
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   478
                Class<?> clazz = Class.forName("sun.nio.ch.NioSocketImpl");
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   479
                Constructor<?> ctor = clazz.getConstructor(boolean.class);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   480
                this.impl = (SocketImpl) ctor.newInstance(server);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   481
            } catch (Exception e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   482
                throw new RuntimeException(e);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   483
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   484
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   485
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   486
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   487
        public void close() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   488
            find("close").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   489
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   490
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   491
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   492
        protected void create(boolean stream) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   493
            find("create", boolean.class).invoke(impl, stream);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   494
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   495
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   496
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   497
        protected void connect(SocketAddress remote, int millis) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   498
            find("connect", SocketAddress.class, int.class).invoke(impl, remote, millis);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   499
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   500
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   501
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   502
        protected void connect(String host, int port) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   503
            find("connect", String.class, int.class).invoke(impl, host, port);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   504
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   505
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   506
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   507
        protected void connect(InetAddress address, int port) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   508
            find("connect", InetAddress.class, int.class).invoke(impl, address, port);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   509
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   510
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   511
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   512
        protected void bind(InetAddress address, int port) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   513
            find("bind", InetAddress.class, int.class).invoke(impl, address, port);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   514
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   515
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   516
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   517
        protected void listen(int backlog) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   518
            find("listen", int.class).invoke(impl, backlog);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   519
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   520
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   521
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   522
        protected void accept(SocketImpl si) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   523
            find("accept", SocketImpl.class).invoke(this.impl, ((PlatformSocketImpl) si).impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   524
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   525
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   526
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   527
        protected InputStream getInputStream() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   528
            return (InputStream) find("getInputStream").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   529
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   530
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   531
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   532
        protected OutputStream getOutputStream() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   533
            return (OutputStream) find("getOutputStream").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   534
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   535
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   536
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   537
        protected int available() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   538
            return (int) find("available").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   539
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   540
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   541
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   542
        protected Set<SocketOption<?>> supportedOptions() {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   543
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   544
                return (Set<SocketOption<?>>) find("supportedOptions").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   545
            } catch (IOException ioe) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   546
                throw new RuntimeException(ioe);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   547
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   548
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   549
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   550
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   551
        protected <T> void setOption(SocketOption<T> opt, T value) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   552
            find("setOption", SocketOption.class, Object.class).invoke(impl, opt, value);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   553
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   554
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   555
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   556
        protected <T> T getOption(SocketOption<T> opt) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   557
            return (T) find("getOption", SocketOption.class).invoke(impl, opt);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   558
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   559
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   560
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   561
        public void setOption(int opt, Object value) throws SocketException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   562
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   563
                find("setOption", int.class, Object.class).invoke(impl, opt, value);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   564
            } catch (SocketException e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   565
                throw e;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   566
            } catch (IOException ioe) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   567
                throw new RuntimeException(ioe);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   568
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   569
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   570
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   571
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   572
        public Object getOption(int opt) throws SocketException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   573
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   574
                return find("getOption", int.class).invoke(impl, opt);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   575
            } catch (SocketException e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   576
                throw e;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   577
            } catch (IOException ioe) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   578
                throw new RuntimeException(ioe);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   579
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   580
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   581
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   582
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   583
        protected void shutdownInput() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   584
            find("shutdownInput").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   585
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   586
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   587
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   588
        protected void shutdownOutput() throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   589
            find("shutdownOutput").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   590
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   591
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   592
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   593
        protected boolean supportsUrgentData() {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   594
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   595
                return (boolean) find("supportsUrgentData").invoke(impl);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   596
            } catch (IOException ioe) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   597
                throw new RuntimeException(ioe);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   598
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   599
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   600
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   601
        @Override
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   602
        protected void sendUrgentData(int data) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   603
            find("sendUrgentData", int.class).invoke(impl, data);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   604
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   605
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   606
        private MethodInvoker find(String name, Class<?>... paramTypes) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   607
            try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   608
                Method m = SocketImpl.class.getDeclaredMethod(name, paramTypes);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   609
                m.setAccessible(true);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   610
                return new MethodInvoker(m);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   611
            } catch (Exception e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   612
                throw new RuntimeException(e);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   613
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   614
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   615
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   616
        static class MethodInvoker {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   617
            private final Method method;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   618
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   619
            MethodInvoker(Method method) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   620
                this.method = method;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   621
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   622
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   623
            Object invoke(Object target, Object... args) throws IOException {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   624
                try {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   625
                    return method.invoke(target, args);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   626
                } catch (InvocationTargetException e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   627
                    Throwable cause = e.getCause();
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   628
                    if (cause instanceof IOException) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   629
                        throw (IOException) cause;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   630
                    } else if (cause instanceof RuntimeException) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   631
                        throw (RuntimeException) cause;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   632
                    } else if (cause instanceof Error) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   633
                        throw (Error) cause;
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   634
                    } else {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   635
                        throw new RuntimeException(e);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   636
                    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   637
                } catch (Exception e) {
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   638
                    throw new RuntimeException(e);
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   639
                }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   640
            }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   641
        }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   642
    }
c1fad761a86e Add tests for invalid usages of SocketImpl
alanb
parents:
diff changeset
   643
}