1/* 2 * Copyright (c) 2004, 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 24import javax.sound.midi.MidiSystem; 25import javax.sound.midi.MidiUnavailableException; 26import javax.sound.midi.Synthesizer; 27 28/** 29 * @test 30 * @bug 5029790 31 * @summary Synthesizer.getLatency returns wrong value 32 */ 33public class SynthesizerGetLatency { 34 35 public static void main(String args[]) throws Exception { 36 Synthesizer synth = null; 37 boolean failed = false; 38 boolean notexec = false; 39 try { 40 synth = MidiSystem.getSynthesizer(); 41 System.out.println("Got synth: "+synth); 42 synth.open(); 43 44 int latency = (int) synth.getLatency(); 45 System.out.println(" -> latency: " 46 +latency 47 +" microseconds"); 48 if (latency < 5000 && latency > 0) { 49 System.out.println("## This latency is VERY small, probably due to this bug."); 50 System.out.println("## This causes failure of this test."); 51 failed = true; 52 } 53 } catch (MidiUnavailableException mue) { 54 System.err.println("MidiUnavailableException was " 55 +"thrown: " + mue); 56 System.out.println("could not test."); 57 notexec = true; 58 } catch(SecurityException se) { 59 se.printStackTrace(); 60 System.err.println("Sound access is not denied but " 61 + "SecurityException was thrown!"); 62 notexec = true; 63 } finally { 64 if (synth != null) synth.close(); 65 } 66 67 68 if (failed) { 69 throw new Exception("Test FAILED!"); 70 } 71 if (notexec) { 72 System.out.println("Test not failed."); 73 } else { 74 System.out.println("Test Passed."); 75 } 76 } 77} 78