Path: blob/master/test/jdk/javax/sound/midi/MidiSystem/GetSequencer.java
41154 views
/*1* Copyright (c) 2003, 2016, 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*/2223import java.util.List;2425import javax.sound.midi.MidiSystem;26import javax.sound.midi.MidiUnavailableException;27import javax.sound.midi.Sequencer;28import javax.sound.midi.Transmitter;2930/**31* @test32* @bug 493140033* @summary Clarify default connections in default sequencer34*/35public class GetSequencer {3637static boolean failed = false;3839public static void main(String args[]) throws Exception {40doTest(1);41doTest(2);42doTest(3);4344if (failed) throw new Exception("Test FAILED!");45out("test OK");46}4748public static void doTest(int mode) {49Sequencer seq = null;50boolean connected = false;5152try {53switch (mode) {54case 1:55seq = MidiSystem.getSequencer();56connected = true;57break;58case 2:59seq = MidiSystem.getSequencer(false);60connected = false;61break;62case 3:63seq = MidiSystem.getSequencer(true);64connected = true;65break;66}67out("Testing Sequencer "+seq);68if (connected) {69out(" opened in connected mode.");70} else {71out(" opened in non-connected mode.");72}73System.out.println(" opening...");74seq.open();75} catch (MidiUnavailableException mue) {76System.err.println("MidiUnavailableException was thrown: " + mue);77System.err.println(" could not test this sequencer.");78return;79}8081try {82List<Transmitter> transmitters = seq.getTransmitters();83int size = transmitters.size();84out(" transmitters.size()="+size);85if (size != 1 && connected) {86out(" should have 1 connection! Failed.");87failed = true;88}89if (size != 0 && !connected) {90out(" should have 0 connections! Failed.");91failed = true;92}93out(" closing...");94seq.close();95transmitters = seq.getTransmitters();96size = transmitters.size();97out(" transmitters.size()="+size);98if (size != 0) {99out(" should have 0 connections! Failed.");100failed = true;101}102103out(" opening again...");104seq.open();105transmitters = seq.getTransmitters();106size = transmitters.size();107out(" transmitters.size()="+size);108if (size != 1 && connected) {109out(" should have 1 connection! Failed.");110failed = true;111}112if (size != 0 && !connected) {113out(" should have 0 connections! Failed.");114failed = true;115}116} catch (Exception e) {117System.err.println(" unexpectedException was thrown: " + e);118System.err.println(" causes this test to FAIL.");119failed = true;120}121seq.close();122}123124static void out(String s) {125System.out.println(s);126}127}128129130