UnloadAllInstruments.java revision 829
903N/A/*
903N/A * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
903N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
903N/A *
903N/A * This code is free software; you can redistribute it and/or modify it
903N/A * under the terms of the GNU General Public License version 2 only, as
903N/A * published by the Free Software Foundation. Sun designates this
903N/A * particular file as subject to the "Classpath" exception as provided
903N/A * by Sun in the LICENSE file that accompanied this code.
903N/A *
903N/A * This code is distributed in the hope that it will be useful, but WITHOUT
903N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
903N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
903N/A * version 2 for more details (a copy is included in the LICENSE file that
903N/A * accompanied this code).
903N/A *
903N/A * You should have received a copy of the GNU General Public License version
903N/A * 2 along with this work; if not, write to the Free Software Foundation,
903N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
903N/A *
903N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
903N/A * CA 95054 USA or visit www.sun.com if you need additional information or
903N/A * have any questions.
903N/A */
903N/A
903N/A/* @test
1480N/A @summary Test SoftSynthesizer unloadAllInstruments method */
903N/A
903N/Aimport javax.sound.midi.MidiDevice;
903N/Aimport javax.sound.midi.MidiUnavailableException;
903N/Aimport javax.sound.midi.Patch;
903N/Aimport javax.sound.midi.Soundbank;
903N/Aimport javax.sound.sampled.*;
903N/Aimport javax.sound.midi.MidiDevice.Info;
903N/A
903N/Aimport com.sun.media.sound.*;
903N/A
903N/Apublic class UnloadAllInstruments {
903N/A
903N/A private static void assertEquals(Object a, Object b) throws Exception
903N/A {
903N/A if(!a.equals(b))
903N/A throw new RuntimeException("assertEquals fails!");
903N/A }
903N/A
903N/A private static void assertTrue(boolean value) throws Exception
903N/A {
903N/A if(!value)
903N/A throw new RuntimeException("assertTrue fails!");
903N/A }
903N/A
903N/A public static void main(String[] args) throws Exception {
903N/A AudioSynthesizer synth = new SoftSynthesizer();
903N/A synth.openStream(null, null);
903N/A Soundbank defsbk = synth.getDefaultSoundbank();
903N/A if(defsbk != null)
903N/A {
903N/A assertTrue(synth.getLoadedInstruments().length == 0);
903N/A synth.unloadAllInstruments(defsbk);
903N/A assertTrue(synth.getAvailableInstruments().length == 0);
903N/A synth.loadAllInstruments(defsbk);
903N/A assertTrue(synth.getLoadedInstruments().length != 0);
903N/A synth.unloadAllInstruments(defsbk);
903N/A assertTrue(synth.getLoadedInstruments().length == 0);
903N/A }
synth.close();
}
}