1 /* 2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.util.List; 25 26 import javax.sound.midi.MidiSystem; 27 import javax.sound.midi.MidiUnavailableException; 28 import javax.sound.midi.Sequencer; 29 import javax.sound.midi.Transmitter; 30 31 /** 32 * @test 33 * @bug 4931400 34 * @summary Clarify default connections in default sequencer 35 */ 36 public class GetSequencer { 37 38 static boolean failed = false; 39 main(String args[])40 public static void main(String args[]) throws Exception { 41 doTest(1); 42 doTest(2); 43 doTest(3); 44 45 if (failed) throw new Exception("Test FAILED!"); 46 out("test OK"); 47 } 48 doTest(int mode)49 public static void doTest(int mode) { 50 Sequencer seq = null; 51 boolean connected = false; 52 53 try { 54 switch (mode) { 55 case 1: 56 seq = MidiSystem.getSequencer(); 57 connected = true; 58 break; 59 case 2: 60 seq = MidiSystem.getSequencer(false); 61 connected = false; 62 break; 63 case 3: 64 seq = MidiSystem.getSequencer(true); 65 connected = true; 66 break; 67 } 68 out("Testing Sequencer "+seq); 69 if (connected) { 70 out(" opened in connected mode."); 71 } else { 72 out(" opened in non-connected mode."); 73 } 74 System.out.println(" opening..."); 75 seq.open(); 76 } catch (MidiUnavailableException mue) { 77 System.err.println("MidiUnavailableException was thrown: " + mue); 78 System.err.println(" could not test this sequencer."); 79 return; 80 } 81 82 try { 83 List<Transmitter> transmitters = seq.getTransmitters(); 84 int size = transmitters.size(); 85 out(" transmitters.size()="+size); 86 if (size != 1 && connected) { 87 out(" should have 1 connection! Failed."); 88 failed = true; 89 } 90 if (size != 0 && !connected) { 91 out(" should have 0 connections! Failed."); 92 failed = true; 93 } 94 out(" closing..."); 95 seq.close(); 96 transmitters = seq.getTransmitters(); 97 size = transmitters.size(); 98 out(" transmitters.size()="+size); 99 if (size != 0) { 100 out(" should have 0 connections! Failed."); 101 failed = true; 102 } 103 104 out(" opening again..."); 105 seq.open(); 106 transmitters = seq.getTransmitters(); 107 size = transmitters.size(); 108 out(" transmitters.size()="+size); 109 if (size != 1 && connected) { 110 out(" should have 1 connection! Failed."); 111 failed = true; 112 } 113 if (size != 0 && !connected) { 114 out(" should have 0 connections! Failed."); 115 failed = true; 116 } 117 } catch (Exception e) { 118 System.err.println(" unexpectedException was thrown: " + e); 119 System.err.println(" causes this test to FAIL."); 120 failed = true; 121 } 122 seq.close(); 123 } 124 out(String s)125 static void out(String s) { 126 System.out.println(s); 127 } 128 } 129