Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/sampled/DataLine/LongFramePosition.java
38855 views
/*1* Copyright (c) 2004, 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 javax.sound.sampled.AudioFormat;24import javax.sound.sampled.AudioSystem;25import javax.sound.sampled.LineUnavailableException;26import javax.sound.sampled.SourceDataLine;2728/**29* @test30* @bug 504912931* @summary DataLine.getLongFramePosition32* @key headful33*/34public class LongFramePosition {3536public static void main(String[] args) throws Exception {37boolean failed = false;38try {39AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);40SourceDataLine sdl = AudioSystem.getSourceDataLine(format);41try {42sdl.open(format);43sdl.start();44sdl.write(new byte[16384], 0, 16384);45Thread.sleep(1000);46int intPos = sdl.getFramePosition();47long longPos = sdl.getLongFramePosition();48System.out.println("After 1 second: getFramePosition() = "+intPos);49System.out.println(" getLongFramePosition() = "+longPos);50if (intPos <= 0 || longPos <= 0) {51failed = true;52System.out.println("## FAILED: frame position did not advance, or negative!");53}54if (Math.abs(intPos - longPos) > 100) {55failed = true;56System.out.println("## FAILED: frame positions are not the same!");57}58} finally {59sdl.close();60}61} catch(LineUnavailableException e){62System.out.println(e);63System.out.println("Cannot execute test.");64return;65}66if (failed) throw new Exception("Test FAILED!");67System.out.println("Test Passed.");68}69}707172