Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/sampled/AudioSystem/DefaultProperties.java
38855 views
/*1* Copyright (c) 2003, 2020, 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.File;2425import com.sun.media.sound.JDK13Services;2627/**28* @test29* @bug 477651130* @build DefaultProperties31* @run main/othervm DefaultProperties32* @summary RFE: Setting the default MixerProvider. Test the retrieving and33* parsing of properties.34*/35public class DefaultProperties {3637private static final Class[] lineTypeClasses = {38javax.sound.sampled.SourceDataLine.class,39javax.sound.sampled.TargetDataLine.class,40javax.sound.sampled.Clip.class,41javax.sound.sampled.Port.class,42};4344public static void main(String[] args) throws Exception {45boolean allOk = true;46File file = new File(System.getProperty("test.src", "."), "testdata");47System.setProperty("java.home", file.getCanonicalPath());4849for (int i = 0; i < lineTypeClasses.length; i++) {50Class cls = lineTypeClasses[i];51String propertyName = cls.getName();52String result;53String provClassName;54String instanceName;5556// properties file, both provider class name and instance name57provClassName = "xyz";58instanceName = "123";59result = JDK13Services.getDefaultProviderClassName(cls);60if (! provClassName.equals(result)) {61out("type " + cls + " failed: provider class should be '" +62provClassName + "' but is '" + result + "'!");63allOk = false;64}65result = JDK13Services.getDefaultInstanceName(cls);66if (! instanceName.equals(result)) {67out("type " + cls + " failed: instance name should be '" +68instanceName + "' but is '" + result + "'!");69allOk = false;70}7172// system property, provider class name only, no trailing hash73provClassName = "abc";74System.setProperty(propertyName, provClassName);75result = JDK13Services.getDefaultProviderClassName(cls);76if (! provClassName.equals(result)) {77out("type " + cls + " failed: provider class should be '" +78provClassName + "' but is '" + result + "'!");79allOk = false;80}81result = JDK13Services.getDefaultInstanceName(cls);82if (result != null) {83out("type " + cls + " failed: instance name should be " +84"null but is '" + result + "'!");85allOk = false;86}8788// system property, provider class name only, trailing hash89provClassName = "def";90System.setProperty(propertyName, provClassName + "#");91result = JDK13Services.getDefaultProviderClassName(cls);92if (! provClassName.equals(result)) {93out("type " + cls + " failed: provider class should be '" +94provClassName + "' but is '" + result + "'!");95allOk = false;96}97result = JDK13Services.getDefaultInstanceName(cls);98if (result != null) {99out("type " + cls + " failed: instance name should be " +100"null but is '" + result + "'!");101allOk = false;102}103104// system property, instance name only105instanceName = "ghi";106System.setProperty(propertyName, "#" + instanceName);107result = JDK13Services.getDefaultProviderClassName(cls);108if (result != null) {109out("type " + cls + " failed: provider class should be " +110"null but is '" + result + "'!");111allOk = false;112}113result = JDK13Services.getDefaultInstanceName(cls);114if (! instanceName.equals(result)) {115out("type " + cls + " failed: instance name should be '" +116instanceName + "' but is '" + result + "'!");117allOk = false;118}119120// system property, both provider class and instance name121provClassName = "jkl";122instanceName = "mno";123System.setProperty(propertyName, provClassName + "#" + instanceName);124result = JDK13Services.getDefaultProviderClassName(cls);125if (! provClassName.equals(result)) {126out("type " + cls + " failed: provider class should be '" +127provClassName + "' but is '" + result + "'!");128allOk = false;129}130result = JDK13Services.getDefaultInstanceName(cls);131if (! instanceName.equals(result)) {132out("type " + cls + " failed: instance name should be '" +133instanceName + "' but is '" + result + "'!");134allOk = false;135}136137// system property, empty138System.setProperty(propertyName, "");139result = JDK13Services.getDefaultProviderClassName(cls);140if (result != null) {141out("type " + cls + " failed: provider class should be " +142"null but is '" + result + "'!");143allOk = false;144}145result = JDK13Services.getDefaultInstanceName(cls);146if (result != null) {147out("type " + cls + " failed: instance name should be " +148"null but is '" + result + "'!");149allOk = false;150}151}152if (! allOk) {153throw new Exception("Test failed");154} else {155out("Test passed");156}157}158159private static void out(String message) {160System.out.println(message);161}162}163164165