Path: blob/master/test/jdk/java/net/SctpSanity.java
41145 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 823209725* @summary Basic sanity for creation of SCTP channels26* @modules jdk.sctp27* @run main/othervm SctpSanity 128* @run main/othervm SctpSanity 229* @run main/othervm SctpSanity 330*/3132import java.io.IOException;33import com.sun.nio.sctp.SctpChannel;34import com.sun.nio.sctp.SctpMultiChannel;35import com.sun.nio.sctp.SctpServerChannel;36import static java.lang.System.out;3738/**39* Tests creation of SCTP channels. The channels should either be created40* or not. The latter throwing an UnsupportedOperationException. No other41* behavior is acceptable. Minimally, exercises the JDK's native library42* loading on operating systems that provide an implementation, even if43* the system-level support is not configured.44*/45public class SctpSanity {4647public static void main(String... args) throws IOException {48switch (Integer.valueOf(args[0])) {49case 1: testSctpChannel(); break;50case 2: testSctpServerChannel(); break;51case 3: testSctpMultiChannel(); break;52default: throw new AssertionError("should not reach here");53}54}5556static void testSctpChannel() throws IOException {57try (SctpChannel channel = SctpChannel.open()) {58out.println("created SctpChannel:" + channel);59} catch (UnsupportedOperationException uoe) {60// ok - the platform does not support SCTP61out.println("ok, caught:" + uoe);62}63}6465static void testSctpServerChannel() throws IOException {66try (SctpServerChannel channel = SctpServerChannel.open()) {67out.println("created SctpServerChannel:" + channel);68} catch (UnsupportedOperationException uoe) {69// ok - the platform does not support SCTP70out.println("ok, caught:" + uoe);71}72}7374static void testSctpMultiChannel() throws IOException {75try (SctpMultiChannel channel = SctpMultiChannel.open()) {76out.println("created SctpMultiChannel:" + channel);77} catch (UnsupportedOperationException uoe) {78// ok - the platform does not support SCTP79out.println("ok, caught:" + uoe);80}81}82}83848586