Path: blob/master/test/jdk/javax/sound/sampled/Clip/Endpoint/ClipSetEndPoint.java
41161 views
/*1* Copyright (c) 2005, 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.LineUnavailableException;31import javax.sound.sampled.Mixer;3233/**34* @test35* @bug 438592836* @summary Verify that an endpoint -1 in Clip does not throw an exception37*/38//public class test048 extends TRTest39public class ClipSetEndPoint {4041private Clip theClip;4243boolean testPassed = true;4445//_______________________________________________46// Method: runTest47//_______________________________________________48public boolean runTest() {49AudioInputStream theAudioInputStream = new AudioInputStream(50new ByteArrayInputStream(new byte[2000]),51new AudioFormat(8000.0f, 8, 1, false, false), 2000); //5253AudioFormat theAudioFormat = theAudioInputStream.getFormat();5455DataLine.Info info = new DataLine.Info(Clip.class, theAudioFormat,56AudioSystem.NOT_SPECIFIED);57try {58theClip = (Clip) AudioSystem.getLine(info);59theClip.open(theAudioInputStream);6061int theStartLoopPoint = 0;62int theEndLoopPoint = -1; // -1 signifies the last frame6364theClip.setLoopPoints(theStartLoopPoint, theEndLoopPoint);65//theClip.start();66} catch (LineUnavailableException e) {67e.printStackTrace();68testPassed = true;69} catch (Exception e) {70e.printStackTrace();71testPassed = false;72}73return testPassed;74}7576//_______________________________________________77// Method: main78//_______________________________________________79public static void main(String[] args) throws Exception {80if (isSoundcardInstalled()) {81ClipSetEndPoint thisTest = new ClipSetEndPoint();82boolean testResult = thisTest.runTest();83if (testResult) {84System.out.println("Test passed");85} else {86System.out.println("Test failed");87throw new Exception("Test failed");88}89}90}9192/**93* Returns true if at least one soundcard is correctly installed94* on the system.95*/96public static boolean isSoundcardInstalled() {97boolean result = false;98try {99Mixer.Info[] mixers = AudioSystem.getMixerInfo();100if (mixers.length > 0) {101result = AudioSystem.getSourceDataLine(null) != null;102}103} catch (Exception e) {104System.err.println("Exception occured: " + e);105}106if (!result) {107System.err.println(108"Soundcard does not exist or sound drivers not installed!");109System.err.println(110"This test requires sound drivers for execution.");111}112return result;113}114}115116117