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