Path: blob/master/test/jdk/javax/sound/sampled/Clip/Open/ClipOpenBug.java
41159 views
/*1* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;2425import javax.sound.sampled.AudioFormat;26import javax.sound.sampled.AudioInputStream;27import javax.sound.sampled.AudioSystem;28import javax.sound.sampled.Clip;29import javax.sound.sampled.DataLine;30import javax.sound.sampled.FloatControl;3132/**33* @test34* @bug 447944435* @summary Verify that the error string of Clip.open() is meaningful36*/37public class ClipOpenBug {3839public static void main(String args[]) throws Exception {40boolean res = true;41try {42AudioInputStream ais = new AudioInputStream(43new ByteArrayInputStream(new byte[2000]),44new AudioFormat(8000.0f, 8, 1, false, false), 2000); //45AudioFormat format = ais.getFormat();46DataLine.Info info = new DataLine.Info(Clip.class, format,47((int) ais.getFrameLength()48* format49.getFrameSize()));50Clip clip = (Clip) AudioSystem.getLine(info);51clip.open();52FloatControl rateControl = (FloatControl) clip.getControl(53FloatControl.Type.SAMPLE_RATE);54int c = 0;55while (c++ < 10) {56clip.stop();57clip.setFramePosition(0);58clip.start();59for (float frq = 22000; frq < 44100; frq = frq + 100) {60try {61Thread.currentThread().sleep(20);62} catch (Exception e) {63break;64}65rateControl.setValue(frq);66}67}68} catch (Exception ex) {69ex.printStackTrace();70res = ex.getMessage().indexOf(71"This method should not have been invoked!") < 0;72}73if (res) {74System.out.println("Test passed");75} else {76System.out.println("Test failed");77throw new Exception("Test failed");78}79}80}818283