Path: blob/master/test/jdk/javax/sound/midi/MidiDeviceConnectors/TestAllDevices.java
41154 views
/*1* Copyright (c) 2010, 2014, 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/**24* @test25* @bug 493370026* @summary Tests that default devices return MidiDeviceTransmitter/Receiver and returned objects return correct MidiDevice27* @compile TestAllDevices.java28* @run main TestAllDevices29* @author Alex Menkov30*/3132import javax.sound.midi.MidiDevice;33import javax.sound.midi.MidiDeviceReceiver;34import javax.sound.midi.MidiDeviceTransmitter;35import javax.sound.midi.MidiSystem;36import javax.sound.midi.MidiUnavailableException;37import javax.sound.midi.Receiver;38import javax.sound.midi.Transmitter;394041public class TestAllDevices {4243static boolean failed = false;4445public static void main(String[] args) throws Exception {46out("default receiver:");47try {48Receiver recv = MidiSystem.getReceiver();49out(" receiver: " + recv);50if (recv instanceof MidiDeviceReceiver) {51out(" OK");52} else {53out(" ERROR: not an instance of MidiDeviceReceiver");54failed = true;55}56} catch (MidiUnavailableException ex) {57// this is not an error58out(" receiver: MidiUnavailableException (test NOT failed)");59}6061out("default transmitter:");62try {63Transmitter tran = MidiSystem.getTransmitter();64out(" transmitter: " + tran);65if (tran instanceof MidiDeviceTransmitter) {66out(" OK");67} else {68out(" ERROR: not an instance of MidiDeviceTransmitter");69failed = true;70}71} catch (MidiUnavailableException ex) {72// this is not an error73out(" transmitter: MidiUnavailableException (test NOT failed)");74}7576MidiDevice.Info[] infos = MidiSystem .getMidiDeviceInfo();77for (MidiDevice.Info info: infos) {78out(info.toString() + ":");79try {80MidiDevice dev = MidiSystem.getMidiDevice(info);81dev.open();8283try {84Receiver recv = dev.getReceiver();85out(" receiver: " + recv);86if (recv instanceof MidiDeviceReceiver) {87MidiDeviceReceiver devRecv = (MidiDeviceReceiver)recv;88MidiDevice retDev = devRecv.getMidiDevice();89if (retDev == dev) {90out(" OK");91} else {92out(" ERROR: getMidiDevice returned incorrect device: " + retDev);93failed = true;94}95} else {96out(" ERROR: not an instance of MidiDeviceReceiver");97failed = true;98}99} catch (MidiUnavailableException ex) {100// this is not an error101out(" receiver: MidiUnavailableException (test NOT failed)");102}103104try {105Transmitter tran = dev.getTransmitter();106out(" transmitter: " + tran);107if (tran instanceof MidiDeviceTransmitter) {108MidiDeviceTransmitter devTran = (MidiDeviceTransmitter)tran;109MidiDevice retDev = devTran.getMidiDevice();110if (retDev == dev) {111out(" OK");112} else {113out(" ERROR: getMidiDevice retur4ned incorrect device: " + retDev);114failed = true;115}116} else {117out(" ERROR: not an instance of MidiDeviceTransmitter");118failed = true;119}120} catch (MidiUnavailableException ex) {121// this is not an error122out(" transmitter: MidiUnavailableException (test NOT failed)");123}124125dev.close();126} catch (MidiUnavailableException ex) {127out(" device: MidiUnavailableException (test NOT failed)");128}129}130131if (failed) {132throw new Exception("Test failed.");133}134}135136static void out(String s) {137System.out.println(s);138}139140}141142143