jdk/test/javax/sound/sampled/Lines/GetLine.java
changeset 41905 e8e5df013c6e
equal deleted inserted replaced
41904:524d908e49ea 41905:e8e5df013c6e
       
     1 /*
       
     2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import javax.sound.sampled.AudioPermission;
       
    25 import javax.sound.sampled.AudioSystem;
       
    26 import javax.sound.sampled.DataLine;
       
    27 import javax.sound.sampled.Line;
       
    28 import javax.sound.sampled.LineUnavailableException;
       
    29 import javax.sound.sampled.SourceDataLine;
       
    30 
       
    31 /**
       
    32  * @test
       
    33  * @bug 4932835
       
    34  * @summary REGRESSION: IAE for supported line in AudioSystem.getLine()
       
    35  */
       
    36 public class GetLine {
       
    37 
       
    38     static boolean isSoundAccessDenied = false;
       
    39     static {
       
    40         SecurityManager securityManager = System.getSecurityManager();
       
    41         if (securityManager != null) {
       
    42             try {
       
    43                 securityManager.checkPermission(new AudioPermission("*"));
       
    44             } catch (SecurityException e) {
       
    45                 isSoundAccessDenied = true;
       
    46             }
       
    47         }
       
    48     }
       
    49 
       
    50     static final int STATUS_PASSED = 0;
       
    51     static final int STATUS_FAILED = 2;
       
    52     static final int STATUS_TEMP = 95;
       
    53     static java.io.PrintStream log = System.err;
       
    54 
       
    55     public static void main(String argv[]) throws Exception {
       
    56         if (run(argv, System.out) == STATUS_FAILED) {
       
    57             throw new Exception("Test FAILED");
       
    58         }
       
    59         System.out.println("Test passed.");
       
    60     }
       
    61 
       
    62     public static int run(String argv[], java.io.PrintStream out) {
       
    63         String testCaseID = "LineListener2001";
       
    64 
       
    65         log.println("===== " + testCaseID + " =====");
       
    66 
       
    67         boolean failed = false;
       
    68         Line l = null;
       
    69 
       
    70 
       
    71 
       
    72         // get the default SourceDataLine
       
    73 
       
    74         DataLine.Info s_info = new DataLine.Info(SourceDataLine.class, null);
       
    75         Line.Info infos[] = AudioSystem.getSourceLineInfo( s_info );
       
    76 
       
    77         if( infos.length < 1 ) {
       
    78             log.println("Line.Info array == 0");
       
    79             return STATUS_PASSED;
       
    80         }
       
    81         try {
       
    82             l = AudioSystem.getLine(infos[0]);
       
    83         } catch(SecurityException lue) {
       
    84             log.println("SecurityException");
       
    85             return STATUS_PASSED;
       
    86         } catch (LineUnavailableException e1) {
       
    87             log.println("LUE");
       
    88             return STATUS_PASSED;
       
    89         } catch (IllegalArgumentException iae) {
       
    90             log.println("IllegalArgumentException should not be thrown "
       
    91                      + "for supported line");
       
    92             iae.printStackTrace(log);
       
    93             return STATUS_FAILED;
       
    94         }
       
    95         out.println("Passed.");
       
    96         return STATUS_PASSED;
       
    97     }
       
    98 
       
    99 }