2719N/A/*
2719N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2719N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2719N/A *
2719N/A * This code is free software; you can redistribute it and/or modify it
2719N/A * under the terms of the GNU General Public License version 2 only, as
2719N/A * published by the Free Software Foundation. Oracle designates this
2719N/A * particular file as subject to the "Classpath" exception as provided
2719N/A * by Oracle in the LICENSE file that accompanied this code.
2719N/A *
2719N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2719N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2719N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2719N/A * version 2 for more details (a copy is included in the LICENSE file that
2719N/A * accompanied this code).
2719N/A *
2719N/A * You should have received a copy of the GNU General Public License version
2719N/A * 2 along with this work; if not, write to the Free Software Foundation,
2719N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2719N/A *
2719N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2719N/A * or visit www.oracle.com if you need additional information or have any
2719N/A * questions.
2719N/A */
2719N/A
2719N/A/**
2719N/A * @test
2719N/A * @bug 4933700
2719N/A * @summary Tests that default devices return MidiDeviceTransmitter/Receiver and returned objects return correct MidiDevice
2719N/A * @compile -source 1.7 TestAllDevices.java
2719N/A * @run main TestAllDevices
2719N/A * @author Alex Menkov
2719N/A */
2719N/A
2719N/Aimport javax.sound.midi.MidiDevice;
2719N/Aimport javax.sound.midi.MidiDeviceReceiver;
2719N/Aimport javax.sound.midi.MidiDeviceTransmitter;
2719N/Aimport javax.sound.midi.MidiSystem;
2719N/Aimport javax.sound.midi.MidiUnavailableException;
2719N/Aimport javax.sound.midi.Receiver;
2719N/Aimport javax.sound.midi.Transmitter;
2719N/A
2719N/A
2719N/Apublic class TestAllDevices {
2719N/A
2719N/A static boolean failed = false;
2719N/A
2719N/A public static void main(String[] args) throws Exception {
2719N/A out("default receiver:");
2719N/A try {
2719N/A Receiver recv = MidiSystem.getReceiver();
2719N/A out(" receiver: " + recv);
2719N/A if (recv instanceof MidiDeviceReceiver) {
2719N/A out(" OK");
2719N/A } else {
2719N/A out(" ERROR: not an instance of MidiDeviceReceiver");
2719N/A failed = true;
2719N/A }
2719N/A } catch (MidiUnavailableException ex) {
2719N/A // this is not an error
2719N/A out(" receiver: MidiUnavailableException (test NOT failed)");
2719N/A }
2719N/A
2719N/A out("default transmitter:");
2719N/A try {
2719N/A Transmitter tran = MidiSystem.getTransmitter();
2719N/A out(" transmitter: " + tran);
2719N/A if (tran instanceof MidiDeviceTransmitter) {
2719N/A out(" OK");
2719N/A } else {
2719N/A out(" ERROR: not an instance of MidiDeviceTransmitter");
2719N/A failed = true;
2719N/A }
2719N/A } catch (MidiUnavailableException ex) {
2719N/A // this is not an error
2719N/A out(" transmitter: MidiUnavailableException (test NOT failed)");
2719N/A }
2719N/A
2719N/A MidiDevice.Info[] infos = MidiSystem .getMidiDeviceInfo();
2719N/A for (MidiDevice.Info info: infos) {
2719N/A out(info.toString() + ":");
2719N/A try {
2719N/A MidiDevice dev = MidiSystem.getMidiDevice(info);
2719N/A dev.open();
2719N/A
2719N/A try {
2719N/A Receiver recv = dev.getReceiver();
2719N/A out(" receiver: " + recv);
2719N/A if (recv instanceof MidiDeviceReceiver) {
2719N/A MidiDeviceReceiver devRecv = (MidiDeviceReceiver)recv;
2719N/A MidiDevice retDev = devRecv.getMidiDevice();
2719N/A if (retDev == dev) {
2719N/A out(" OK");
2719N/A } else {
2719N/A out(" ERROR: getMidiDevice returned incorrect device: " + retDev);
2719N/A failed = true;
2719N/A }
2719N/A } else {
2719N/A out(" ERROR: not an instance of MidiDeviceReceiver");
2719N/A failed = true;
2719N/A }
2719N/A } catch (MidiUnavailableException ex) {
2719N/A // this is not an error
2719N/A out(" receiver: MidiUnavailableException (test NOT failed)");
2719N/A }
2719N/A
2719N/A try {
2719N/A Transmitter tran = dev.getTransmitter();
2719N/A out(" transmitter: " + tran);
2719N/A if (tran instanceof MidiDeviceTransmitter) {
2719N/A MidiDeviceTransmitter devTran = (MidiDeviceTransmitter)tran;
2719N/A MidiDevice retDev = devTran.getMidiDevice();
2719N/A if (retDev == dev) {
2719N/A out(" OK");
2719N/A } else {
2719N/A out(" ERROR: getMidiDevice retur4ned incorrect device: " + retDev);
2719N/A failed = true;
2719N/A }
2719N/A } else {
2719N/A out(" ERROR: not an instance of MidiDeviceTransmitter");
2719N/A failed = true;
2719N/A }
2719N/A } catch (MidiUnavailableException ex) {
2719N/A // this is not an error
2719N/A out(" transmitter: MidiUnavailableException (test NOT failed)");
2719N/A }
2719N/A
2719N/A dev.close();
2719N/A } catch (MidiUnavailableException ex) {
2719N/A out(" device: MidiUnavailableException (test NOT failed)");
2719N/A }
2719N/A }
2719N/A
2719N/A if (failed) {
2719N/A throw new Exception("Test failed.");
2719N/A }
2719N/A }
2719N/A
2719N/A static void out(String s) {
2719N/A System.out.println(s);
2719N/A }
2719N/A
2719N/A}