Path: blob/master/test/jdk/javax/sound/midi/Devices/ReceiverTransmitterAvailable.java
41152 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 javax.sound.midi.MidiDevice;24import javax.sound.midi.MidiSystem;25import javax.sound.midi.MidiUnavailableException;26import javax.sound.midi.Receiver;27import javax.sound.midi.Transmitter;2829/**30* @test31* @bug 461651732* @summary Receiver.send() does not work properly33*/34public class ReceiverTransmitterAvailable {3536private static boolean isTestExecuted;37private static boolean isTestPassed;3839public static void main(String[] args) throws Exception {40out("#4616517: Receiver.send() does not work properly");41doAllTests();42if (isTestExecuted) {43if (isTestPassed) {44out("Test PASSED.");45} else {46throw new Exception("Test FAILED.");47}48} else {49out("Test NOT FAILED");50}51}5253private static void doAllTests() {54boolean problemOccured = false;55boolean succeeded = true;56MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();57for (int i = 0; i < infos.length; i++) {58MidiDevice device = null;59try {60device = MidiSystem.getMidiDevice(infos[i]);61succeeded &= doTest(device);62} catch (MidiUnavailableException e) {63out("exception occured; cannot test");64problemOccured = true;65}66}67if (infos.length == 0) {68out("Soundcard does not exist or sound drivers not installed!");69out("This test requires sound drivers for execution.");70}71isTestExecuted = !problemOccured;72isTestPassed = succeeded;73}7475private static boolean doTest(MidiDevice device) {76boolean succeeded = true;77out("Testing: " + device);78boolean expectingReceivers = (device.getMaxReceivers() != 0);79boolean expectingTransmitters = (device.getMaxTransmitters() != 0);80try {81Receiver rec = device.getReceiver();82rec.close();83if (! expectingReceivers) {84out("no exception on getting Receiver");85succeeded = false;86}87} catch (MidiUnavailableException e) {88if (expectingReceivers) {89out("Exception on getting Receiver: " + e);90succeeded = false;91}92}93try {94Transmitter trans = device.getTransmitter();95trans.close();96if (! expectingTransmitters) {97out("no exception on getting Transmitter");98succeeded = false;99}100} catch (MidiUnavailableException e) {101if (expectingTransmitters) {102out("Exception on getting Transmitter: " + e);103succeeded = false;104}105}106return succeeded;107}108109private static void out(String message) {110System.out.println(message);111}112}113114115