Path: blob/master/test/jdk/javax/sound/sampled/Lines/GetLine.java
41153 views
/*1* Copyright (c) 2003, 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.AudioPermission;24import javax.sound.sampled.AudioSystem;25import javax.sound.sampled.DataLine;26import javax.sound.sampled.Line;27import javax.sound.sampled.LineUnavailableException;28import javax.sound.sampled.SourceDataLine;2930/**31* @test32* @bug 493283533* @summary REGRESSION: IAE for supported line in AudioSystem.getLine()34*/35public class GetLine {3637static boolean isSoundAccessDenied = false;38static {39SecurityManager securityManager = System.getSecurityManager();40if (securityManager != null) {41try {42securityManager.checkPermission(new AudioPermission("*"));43} catch (SecurityException e) {44isSoundAccessDenied = true;45}46}47}4849static final int STATUS_PASSED = 0;50static final int STATUS_FAILED = 2;51static final int STATUS_TEMP = 95;52static java.io.PrintStream log = System.err;5354public static void main(String argv[]) throws Exception {55if (run(argv, System.out) == STATUS_FAILED) {56throw new Exception("Test FAILED");57}58System.out.println("Test passed.");59}6061public static int run(String argv[], java.io.PrintStream out) {62String testCaseID = "LineListener2001";6364log.println("===== " + testCaseID + " =====");6566boolean failed = false;67Line l = null;68697071// get the default SourceDataLine7273DataLine.Info s_info = new DataLine.Info(SourceDataLine.class, null);74Line.Info infos[] = AudioSystem.getSourceLineInfo( s_info );7576if( infos.length < 1 ) {77log.println("Line.Info array == 0");78return STATUS_PASSED;79}80try {81l = AudioSystem.getLine(infos[0]);82} catch(SecurityException lue) {83log.println("SecurityException");84return STATUS_PASSED;85} catch (LineUnavailableException e1) {86log.println("LUE");87return STATUS_PASSED;88} catch (IllegalArgumentException iae) {89log.println("IllegalArgumentException should not be thrown "90+ "for supported line");91iae.printStackTrace(log);92return STATUS_FAILED;93}94out.println("Passed.");95return STATUS_PASSED;96}9798}99100101