< prev index next >

test/javax/sound/midi/Synthesizer/bug4685396.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import javax.sound.midi.Instrument;
  25 import javax.sound.midi.MidiSystem;

  26 import javax.sound.midi.Soundbank;
  27 import javax.sound.midi.Synthesizer;
  28 
  29 /**
  30  * @test
  31  * @bug 4685396
  32  * @summary Tests that Synthesizer.remapInstrument works
  33  * @run main bug4685396
  34  * @key headful
  35  */
  36 public class bug4685396 {
  37 
  38     static Synthesizer synth = null;
  39 
  40     public static boolean isInstrumentExist(Instrument inst, Instrument[] insts) {
  41         for (int i = 0; i < insts.length; i++) {
  42             if (inst.equals(insts[i]))
  43                 return true;
  44         }
  45         return false;
  46     }
  47 
  48     static boolean test(
  49             boolean reloadInstr,    // reload all instruments?
  50             boolean unloadFrom,     // unload "from" instrument?
  51             boolean unloadTo        // unload "to" instrument?
  52             ) throws Exception
  53     {
  54         log("Starting test: reloadInstr=" + reloadInstr
  55                 + ", unloadFrom=" + unloadFrom
  56                 + ", unloadTo=" + unloadTo
  57                 + "");
  58 
  59         log("  creating synthesizer...");
  60         synth = MidiSystem.getSynthesizer();
  61         log("  opening synthesizer...");
  62         synth.open();
  63 
  64         Soundbank sbank = synth.getDefaultSoundbank();
  65         if (sbank == null)
  66             throw new RuntimeException("ERROR: Could not get default soundbank");
  67 
  68         if (reloadInstr) {
  69             synth.unloadAllInstruments(sbank);
  70             synth.loadAllInstruments(sbank);
  71         }
  72 
  73         Instrument[] instrs = synth.getLoadedInstruments();


 147 
 148         return bOK;
 149     }
 150 
 151     static void cleanup() {
 152         if (synth != null) {
 153             synth.close();
 154             synth = null;
 155         }
 156     }
 157 
 158     static boolean runTest(
 159             boolean reloadInstr,    // reload all instruments?
 160             boolean unloadTo,       // unload "to" instrument?
 161             boolean unloadFrom      // unload "from" instrument?
 162             )
 163     {
 164         boolean success = false;
 165         try {
 166             success = test(reloadInstr, unloadFrom, unloadTo);



 167         } catch (Exception ex) {
 168             log("Exception: " + ex.toString());
 169         }
 170         cleanup();
 171         return success;
 172     }
 173 
 174     public static void main(String args[]) throws Exception {
 175         boolean failed = false;
 176         if (!runTest(true, false, false))
 177             failed = true;
 178         if (!runTest(true, false, true))
 179             failed = true;
 180         if (!runTest(true, true, false))
 181             failed = true;
 182         if (!runTest(true, true, true))
 183             failed = true;
 184 
 185         if (failed) {
 186             throw new RuntimeException("Test FAILED.");
 187         }
 188         log("Test sucessfully passed.");
 189     }
 190 
 191 
 192     // helper routines
 193     static long startTime = currentTimeMillis();
 194     static long currentTimeMillis() {


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import javax.sound.midi.Instrument;
  25 import javax.sound.midi.MidiSystem;
  26 import javax.sound.midi.MidiUnavailableException;
  27 import javax.sound.midi.Soundbank;
  28 import javax.sound.midi.Synthesizer;
  29 
  30 /**
  31  * @test
  32  * @bug 4685396
  33  * @summary Tests that Synthesizer.remapInstrument works
  34  * @run main bug4685396

  35  */
  36 public class bug4685396 {
  37 
  38     static Synthesizer synth = null;
  39 
  40     public static boolean isInstrumentExist(Instrument inst, Instrument[] insts) {
  41         for (int i = 0; i < insts.length; i++) {
  42             if (inst.equals(insts[i]))
  43                 return true;
  44         }
  45         return false;
  46     }
  47 
  48     static boolean test(
  49             boolean reloadInstr,    // reload all instruments?
  50             boolean unloadFrom,     // unload "from" instrument?
  51             boolean unloadTo        // unload "to" instrument?
  52             ) throws MidiUnavailableException {

  53         log("Starting test: reloadInstr=" + reloadInstr
  54                 + ", unloadFrom=" + unloadFrom
  55                 + ", unloadTo=" + unloadTo
  56                 + "");
  57 
  58         log("  creating synthesizer...");
  59         synth = MidiSystem.getSynthesizer();
  60         log("  opening synthesizer...");
  61         synth.open();
  62 
  63         Soundbank sbank = synth.getDefaultSoundbank();
  64         if (sbank == null)
  65             throw new RuntimeException("ERROR: Could not get default soundbank");
  66 
  67         if (reloadInstr) {
  68             synth.unloadAllInstruments(sbank);
  69             synth.loadAllInstruments(sbank);
  70         }
  71 
  72         Instrument[] instrs = synth.getLoadedInstruments();


 146 
 147         return bOK;
 148     }
 149 
 150     static void cleanup() {
 151         if (synth != null) {
 152             synth.close();
 153             synth = null;
 154         }
 155     }
 156 
 157     static boolean runTest(
 158             boolean reloadInstr,    // reload all instruments?
 159             boolean unloadTo,       // unload "to" instrument?
 160             boolean unloadFrom      // unload "from" instrument?
 161             )
 162     {
 163         boolean success = false;
 164         try {
 165             success = test(reloadInstr, unloadFrom, unloadTo);
 166         } catch (final MidiUnavailableException ignored) {
 167             // the test is not applicable
 168             success = true;
 169         } catch (Exception ex) {
 170             log("Exception: " + ex.toString());
 171         }
 172         cleanup();
 173         return success;
 174     }
 175 
 176     public static void main(String args[]) {
 177         boolean failed = false;
 178         if (!runTest(true, false, false))
 179             failed = true;
 180         if (!runTest(true, false, true))
 181             failed = true;
 182         if (!runTest(true, true, false))
 183             failed = true;
 184         if (!runTest(true, true, true))
 185             failed = true;
 186 
 187         if (failed) {
 188             throw new RuntimeException("Test FAILED.");
 189         }
 190         log("Test sucessfully passed.");
 191     }
 192 
 193 
 194     // helper routines
 195     static long startTime = currentTimeMillis();
 196     static long currentTimeMillis() {


< prev index next >