test/jdk/java/net/SocketOption/NullsAndBadValues.java
author chegar
Fri, 07 Jun 2019 11:47:49 +0100
changeset 55288 ae41e1037bde
parent 55081 dd321e3596c0
permissions -rw-r--r--
8225424: Add jdk.net.usePlainSocketImpl runs to a couple of tests Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55081
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     1
/*
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     4
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     8
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    13
 * accompanied this code).
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    14
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    18
 *
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    21
 * questions.
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    22
 */
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    23
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    24
/*
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    25
 * @test
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    26
 * @bug 8224477
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    27
 * @summary Basic test for NPE, UOE, and IAE for get/setOption
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    28
 * @run testng NullsAndBadValues
55288
ae41e1037bde 8225424: Add jdk.net.usePlainSocketImpl runs to a couple of tests
chegar
parents: 55081
diff changeset
    29
 * @run testng/othervm -Djdk.net.usePlainSocketImpl NullsAndBadValues
55081
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    30
 * @run testng/othervm -Dsun.net.useExclusiveBind=false NullsAndBadValues
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    31
 */
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    32
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    33
import java.net.DatagramSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    34
import java.net.MulticastSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    35
import java.net.ServerSocket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    36
import java.net.Socket;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    37
import java.net.SocketOption;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    38
import java.nio.channels.DatagramChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    39
import java.nio.channels.ServerSocketChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    40
import java.nio.channels.SocketChannel;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    41
import java.util.ArrayList;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    42
import java.util.Arrays;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    43
import java.util.HashMap;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    44
import java.util.List;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    45
import java.util.Map;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    46
import java.util.stream.Stream;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    47
import org.testng.annotations.DataProvider;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    48
import org.testng.annotations.Test;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    49
import static java.lang.Boolean.*;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    50
import static java.net.StandardSocketOptions.*;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    51
import static org.testng.Assert.expectThrows;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    52
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    53
public class NullsAndBadValues {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    54
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    55
    static final Class<NullPointerException> NPE = NullPointerException.class;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    56
    static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    57
    static final Class<UnsupportedOperationException> UOE = UnsupportedOperationException.class;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    58
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    59
    @Test
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    60
    public void nulls() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    61
        try (Socket s = new Socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    62
            expectThrows(NPE, () -> s.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    63
            expectThrows(NPE, () -> s.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    64
            expectThrows(NPE, () -> s.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    65
            expectThrows(NPE, () -> s.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    66
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    67
        try (ServerSocket ss = new ServerSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    68
            expectThrows(NPE, () -> ss.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    69
            expectThrows(NPE, () -> ss.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    70
            expectThrows(NPE, () -> ss.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    71
            expectThrows(NPE, () -> ss.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    72
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    73
        try (DatagramSocket ds = new DatagramSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    74
            expectThrows(NPE, () -> ds.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    75
            expectThrows(NPE, () -> ds.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    76
            expectThrows(NPE, () -> ds.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    77
            expectThrows(NPE, () -> ds.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    78
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    79
        try (MulticastSocket ms = new MulticastSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    80
            expectThrows(NPE, () -> ms.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    81
            expectThrows(NPE, () -> ms.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    82
            expectThrows(NPE, () -> ms.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    83
            expectThrows(NPE, () -> ms.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    84
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    85
        try (Socket sa = SocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    86
            expectThrows(NPE, () -> sa.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    87
            expectThrows(NPE, () -> sa.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    88
            expectThrows(NPE, () -> sa.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    89
            expectThrows(NPE, () -> sa.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    90
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    91
        try (ServerSocket ssa = ServerSocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    92
            expectThrows(NPE, () -> ssa.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    93
            expectThrows(NPE, () -> ssa.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    94
            expectThrows(NPE, () -> ssa.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    95
            expectThrows(NPE, () -> ssa.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    96
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    97
        try (DatagramSocket dsa = DatagramChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    98
            expectThrows(NPE, () -> dsa.setOption(null, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
    99
            expectThrows(NPE, () -> dsa.setOption(null, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   100
            expectThrows(NPE, () -> dsa.setOption(null, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   101
            expectThrows(NPE, () -> dsa.getOption(null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   102
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   103
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   104
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   105
    static final SocketOption<Boolean> FAKE_SOCK_OPT = new SocketOption<>() {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   106
        @Override public String name() { return "FAKE_SOCK_OPT"; }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   107
        @Override public Class<Boolean> type() { return Boolean.class; }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   108
    };
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   109
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   110
    static final SocketOption RAW_SOCK_OPT = new SocketOption() {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   111
        @Override public String name() { return "RAW_SOCK_OPT"; }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   112
        @Override public Class type()  { return Boolean.class;  }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   113
    };
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   114
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   115
    @Test
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   116
    public void uoe() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   117
        try (Socket s = new Socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   118
            expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   119
            expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   120
            expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   121
            expectThrows(UOE, () -> s.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   122
            expectThrows(UOE, () -> s.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   123
            expectThrows(UOE, () -> s.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   124
            expectThrows(UOE, () -> s.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   125
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   126
        try (ServerSocket ss = new ServerSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   127
            expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   128
            expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   129
            expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   130
            expectThrows(UOE, () -> ss.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   131
            expectThrows(UOE, () -> ss.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   132
            expectThrows(UOE, () -> ss.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   133
            expectThrows(UOE, () -> ss.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   134
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   135
        try (DatagramSocket ds = new DatagramSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   136
            expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   137
            expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   138
            expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   139
            expectThrows(UOE, () -> ds.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   140
            expectThrows(UOE, () -> ds.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   141
            expectThrows(UOE, () -> ds.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   142
            expectThrows(UOE, () -> ds.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   143
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   144
        try (MulticastSocket ms = new MulticastSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   145
            expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   146
            expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   147
            expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   148
            expectThrows(UOE, () -> ms.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   149
            expectThrows(UOE, () -> ms.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   150
            expectThrows(UOE, () -> ms.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   151
            expectThrows(UOE, () -> ms.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   152
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   153
        try (Socket sa = SocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   154
            expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   155
            expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   156
            expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   157
            expectThrows(UOE, () -> sa.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   158
            expectThrows(UOE, () -> sa.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   159
            expectThrows(UOE, () -> sa.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   160
            expectThrows(UOE, () -> sa.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   161
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   162
        try (ServerSocket ssa = ServerSocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   163
            expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   164
            expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   165
            expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   166
            expectThrows(UOE, () -> ssa.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   167
            expectThrows(UOE, () -> ssa.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   168
            expectThrows(UOE, () -> ssa.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   169
            expectThrows(UOE, () -> ssa.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   170
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   171
        try (DatagramSocket dsa = DatagramChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   172
            expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, null));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   173
            expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, TRUE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   174
            expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, FALSE));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   175
            expectThrows(UOE, () -> dsa.setOption(RAW_SOCK_OPT, ""));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   176
            expectThrows(UOE, () -> dsa.setOption(RAW_SOCK_OPT, 1));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   177
            expectThrows(UOE, () -> dsa.getOption(FAKE_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   178
            expectThrows(UOE, () -> dsa.getOption(RAW_SOCK_OPT));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   179
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   180
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   181
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   182
    static Map<SocketOption<?>,List<Object>> BAD_OPTION_VALUES = badOptionValues();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   183
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   184
    static Map<SocketOption<?>,List<Object>> badOptionValues() {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   185
        Map<SocketOption<?>,List<Object>> map = new HashMap<>();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   186
        map.put(IP_MULTICAST_IF,   listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   187
        map.put(IP_MULTICAST_LOOP, listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   188
        map.put(IP_MULTICAST_TTL,  listOf(null, -1, 256));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   189
        map.put(IP_TOS,            listOf(null, -1, 256));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   190
        map.put(SO_BROADCAST,      listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   191
        map.put(SO_KEEPALIVE,      listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   192
        map.put(SO_LINGER,         listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   193
        map.put(SO_RCVBUF,         listOf(null, -1)     );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   194
        map.put(SO_REUSEADDR,      listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   195
        map.put(SO_REUSEPORT,      listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   196
        map.put(SO_SNDBUF,         listOf(null, -1)     );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   197
        map.put(TCP_NODELAY,       listOf(null)         );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   198
        // extended options, not in the map, will get a null value
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   199
        return map;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   200
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   201
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   202
    // -- Socket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   203
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   204
    @DataProvider(name = "socketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   205
    public Object[][] socketBadOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   206
        try (Socket s = new Socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   207
            return s.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   208
                    .flatMap(NullsAndBadValues::socketOptionToBadValues)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   209
                    .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   210
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   211
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   212
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   213
    @Test(dataProvider = "socketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   214
    public <T> void socket(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   215
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   216
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   217
        try (Socket s = new Socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   218
            expectThrows(IAE, () -> s.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   219
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   220
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   221
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   222
    @Test(dataProvider = "socketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   223
    public <T> void socketAdapter(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   224
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   225
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   226
        try (Socket s = SocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   227
            expectThrows(IAE, () -> s.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   228
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   229
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   230
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   231
    // -- ServerSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   232
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   233
    @DataProvider(name = "serverSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   234
    public Object[][] serverSocketBadOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   235
        try (ServerSocket ss = new ServerSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   236
            return ss.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   237
                     .flatMap(NullsAndBadValues::socketOptionToBadValues)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   238
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   239
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   240
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   241
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   242
    @Test(dataProvider = "serverSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   243
    public <T> void serverSocket(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   244
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   245
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   246
        try (ServerSocket ss = new ServerSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   247
            expectThrows(IAE, () -> ss.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   248
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   249
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   250
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   251
    @Test(dataProvider = "serverSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   252
    public <T> void serverSocketAdapter(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   253
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   254
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   255
        if (option == IP_TOS)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   256
            return;  // SSC does not support IP_TOS
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   257
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   258
        try (ServerSocket ss = ServerSocketChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   259
            expectThrows(IAE, () -> ss.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   260
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   261
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   262
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   263
    // -- DatagramSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   264
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   265
    @DataProvider(name = "datagramSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   266
    public Object[][] datagramSocketBadOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   267
        try (DatagramSocket ds = new DatagramSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   268
            return ds.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   269
                     .flatMap(NullsAndBadValues::socketOptionToBadValues)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   270
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   271
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   272
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   273
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   274
    @Test(dataProvider = "datagramSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   275
    public <T> void datagramSocket(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   276
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   277
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   278
        try (DatagramSocket ds = new DatagramSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   279
            expectThrows(IAE, () -> ds.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   280
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   281
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   282
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   283
    @Test(dataProvider = "datagramSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   284
    public <T> void datagramSocketAdapter(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   285
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   286
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   287
        try (DatagramSocket ds = DatagramChannel.open().socket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   288
            expectThrows(IAE, () -> ds.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   289
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   290
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   291
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   292
    // -- MulticastSocket
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   293
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   294
    @DataProvider(name = "multicastSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   295
    public Object[][] multicastSocketBadOptionValues() throws Exception {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   296
        try (MulticastSocket ms = new MulticastSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   297
            return ms.supportedOptions().stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   298
                     .flatMap(NullsAndBadValues::socketOptionToBadValues)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   299
                     .toArray(Object[][]::new);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   300
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   301
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   302
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   303
    @Test(dataProvider = "multicastSocketBadOptionValues")
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   304
    public <T> void multicastSocket(SocketOption<T> option, T value)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   305
        throws Exception
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   306
    {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   307
        try (MulticastSocket ms = new MulticastSocket()) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   308
            expectThrows(IAE, () -> ms.setOption(option, value));
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   309
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   310
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   311
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   312
    // --
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   313
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   314
    static List<Object> listOf(Object... objs) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   315
        List<Object> l = new ArrayList<>();
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   316
        if (objs == null)
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   317
            l.add(null);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   318
        else
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   319
            Arrays.stream(objs).forEachOrdered(l::add);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   320
        return l;
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   321
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   322
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   323
    static Stream<Object[]> socketOptionToBadValues(SocketOption<?> socketOption) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   324
        List<Object> values = BAD_OPTION_VALUES.get(socketOption);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   325
        if (values == null) {
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   326
            Object[][] a = new Object[][] { new Object[] { socketOption, null } };
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   327
            return Stream.of(a);
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   328
        }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   329
        return values.stream()
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   330
                .flatMap(v -> Stream.of(new Object[][] { new Object[] { socketOption, v } }) );
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   331
    }
dd321e3596c0 8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff changeset
   332
}