UnloadAllInstruments.java revision 8729:0242fce0f717
159243Sobrien/*
259243Sobrien * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
359243Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
459243Sobrien *
559243Sobrien * This code is free software; you can redistribute it and/or modify it
659243Sobrien * under the terms of the GNU General Public License version 2 only, as
759243Sobrien * published by the Free Software Foundation.
859243Sobrien *
959243Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT
1059243Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1159243Sobrien * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1259243Sobrien * version 2 for more details (a copy is included in the LICENSE file that
1359243Sobrien * accompanied this code).
1459243Sobrien *
1559243Sobrien * You should have received a copy of the GNU General Public License version
1659243Sobrien * 2 along with this work; if not, write to the Free Software Foundation,
1759243Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1859243Sobrien *
1959243Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2059243Sobrien * or visit www.oracle.com if you need additional information or have any
2159243Sobrien * questions.
2259243Sobrien */
2359243Sobrien
2459243Sobrien/* @test
2559243Sobrien   @summary Test SoftSynthesizer unloadAllInstruments method */
2659243Sobrien
2759243Sobrienimport javax.sound.midi.MidiDevice;
2859243Sobrienimport javax.sound.midi.MidiUnavailableException;
2959243Sobrienimport javax.sound.midi.Patch;
3059243Sobrienimport javax.sound.midi.Soundbank;
3159243Sobrienimport javax.sound.sampled.*;
3259243Sobrienimport javax.sound.midi.MidiDevice.Info;
3359243Sobrien
3459243Sobrienimport com.sun.media.sound.*;
3559243Sobrien
3659243Sobrienpublic class UnloadAllInstruments {
3759243Sobrien
3859243Sobrien    private static void assertEquals(Object a, Object b) throws Exception
3959243Sobrien    {
4059243Sobrien        if(!a.equals(b))
4159243Sobrien            throw new RuntimeException("assertEquals fails!");
4259243Sobrien    }
4359243Sobrien
4459243Sobrien    private static void assertTrue(boolean value) throws Exception
4559243Sobrien    {
4659243Sobrien        if(!value)
4759243Sobrien            throw new RuntimeException("assertTrue fails!");
4859243Sobrien    }
4959243Sobrien
5059243Sobrien    public static void main(String[] args) throws Exception {
5159243Sobrien        AudioSynthesizer synth = new SoftSynthesizer();
5259243Sobrien        synth.openStream(null, null);
5359243Sobrien        Soundbank defsbk = synth.getDefaultSoundbank();
5459243Sobrien        if(defsbk != null)
5559243Sobrien        {
5659243Sobrien            synth.unloadAllInstruments(defsbk);
5759243Sobrien            assertTrue(synth.getLoadedInstruments().length == 0);
5859243Sobrien            synth.loadAllInstruments(defsbk);
5959243Sobrien            assertTrue(synth.getLoadedInstruments().length != 0);
6059243Sobrien            synth.unloadAllInstruments(defsbk);
6159243Sobrien            assertTrue(synth.getLoadedInstruments().length == 0);
6259243Sobrien        }
6359243Sobrien        synth.close();
6459243Sobrien
6559243Sobrien    }
6659243Sobrien}
6759243Sobrien