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