Path: blob/master/test/jdk/javax/sound/sampled/Controls/FloatControl/FloatControlBug.java
41154 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;31import javax.sound.sampled.LineUnavailableException;32import javax.sound.sampled.Mixer;3334/**35* @test36* @bug 438565437* @summary Check that the MASTER_GAIN control has a valid precision38*/39//public class test047 extends TRTest40public class FloatControlBug {4142private Clip theClip;4344boolean testPassed = true;4546private AudioFormat.Encoding theEncoding = AudioFormat.Encoding.PCM_SIGNED;4748private float theSampleRate = 44100;4950private int theSampleSize = 16;5152private int theNumberOfChannels = 1;5354private int theFrameSize = 2;5556private float theFrameRate = 44100;5758private boolean isBigEndian = false;5960//_______________________________________________61// Method: runTest62//_______________________________________________63public boolean runTest() {64AudioInputStream theAudioInputStream = new AudioInputStream(65new ByteArrayInputStream(new byte[0]),66new AudioFormat(44100.0f, 16, 2, true, false), 441000);6768AudioFormat theAudioFormat = theAudioInputStream.getFormat();6970DataLine.Info info = new DataLine.Info(Clip.class, theAudioFormat,71AudioSystem.NOT_SPECIFIED);72try {73theClip = (Clip) AudioSystem.getLine(info);74theClip.open(theAudioInputStream);75FloatControl theFloatControl = (FloatControl) (theClip.getControl(76FloatControl.Type.MASTER_GAIN));77float theFloatControlPrecision = theFloatControl.getPrecision();78System.out.println(79"theFloatControlPrecision: " + theFloatControlPrecision);80System.out.println("Minimum: " + theFloatControl.getMinimum());81System.out.println("Maximum: " + theFloatControl.getMaximum());82System.out.println("Value : " + theFloatControl.getValue());83testPassed = theFloatControlPrecision > 0;84} catch (LineUnavailableException e) {85e.printStackTrace();86testPassed = true;87} catch (Exception e) {88e.printStackTrace();89testPassed = false;90}91return testPassed;92}9394//_______________________________________________95// Method: main96//_______________________________________________97public static void main(String[] args) throws Exception {98//test047 thisTest = new test047();99if (isSoundcardInstalled()) {100FloatControlBug thisTest = new FloatControlBug();101boolean testResult = thisTest.runTest();102if (testResult) {103System.out.println("Test passed");104} else {105System.out.println("Test failed");106throw new Exception("Test failed");107}108}109}110111/**112* Returns true if at least one soundcard is correctly installed113* on the system.114*/115public static boolean isSoundcardInstalled() {116boolean result = false;117try {118Mixer.Info[] mixers = AudioSystem.getMixerInfo();119if (mixers.length > 0) {120result = AudioSystem.getSourceDataLine(null) != null;121}122} catch (Exception e) {123System.err.println("Exception occured: " + e);124}125if (!result) {126System.err.println(127"Soundcard does not exist or sound drivers not installed!");128System.err.println(129"This test requires sound drivers for execution.");130}131return result;132}133}134135136