Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/MidiSystem/DefaultProperties.java
38853 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* @summary RFE: Setting the default MixerProvider. Test the retrieving and31* parsing of properties. This is a part of the test for 4776511.32* @run main/othervm DefaultProperties33*/34public class DefaultProperties {3536private static final Class[] lineTypeClasses = {37javax.sound.midi.Receiver.class,38javax.sound.midi.Transmitter.class,39javax.sound.midi.Sequencer.class,40javax.sound.midi.Synthesizer.class,41};4243public static void main(String[] args) throws Exception {44boolean allOk = true;45File file = new File(System.getProperty("test.src", "."), "testdata");46System.setProperty("java.home", file.getCanonicalPath());4748for (int i = 0; i < lineTypeClasses.length; i++) {49Class cls = lineTypeClasses[i];50String propertyName = cls.getName();51String result;52String provClassName;53String instanceName;5455// properties file, both provider class name and instance name56provClassName = "xyz";57instanceName = "123";58result = JDK13Services.getDefaultProviderClassName(cls);59if (! provClassName.equals(result)) {60out("type " + cls + " failed: provider class should be '" +61provClassName + "' but is '" + result + "'!");62allOk = false;63}64result = JDK13Services.getDefaultInstanceName(cls);65if (! instanceName.equals(result)) {66out("type " + cls + " failed: instance name should be '" +67instanceName + "' but is '" + result + "'!");68allOk = false;69}7071// system property, provider class name only, no trailing hash72provClassName = "abc";73System.setProperty(propertyName, provClassName);74result = JDK13Services.getDefaultProviderClassName(cls);75if (! provClassName.equals(result)) {76out("type " + cls + " failed: provider class should be '" +77provClassName + "' but is '" + result + "'!");78allOk = false;79}80result = JDK13Services.getDefaultInstanceName(cls);81if (result != null) {82out("type " + cls + " failed: instance name should be " +83"null but is '" + result + "'!");84allOk = false;85}8687// system property, provider class name only, trailing hash88provClassName = "def";89System.setProperty(propertyName, provClassName + "#");90result = JDK13Services.getDefaultProviderClassName(cls);91if (! provClassName.equals(result)) {92out("type " + cls + " failed: provider class should be '" +93provClassName + "' but is '" + result + "'!");94allOk = false;95}96result = JDK13Services.getDefaultInstanceName(cls);97if (result != null) {98out("type " + cls + " failed: instance name should be " +99"null but is '" + result + "'!");100allOk = false;101}102103// system property, instance name only104instanceName = "ghi";105System.setProperty(propertyName, "#" + instanceName);106result = JDK13Services.getDefaultProviderClassName(cls);107if (result != null) {108out("type " + cls + " failed: provider class should be " +109"null but is '" + result + "'!");110allOk = false;111}112result = JDK13Services.getDefaultInstanceName(cls);113if (! instanceName.equals(result)) {114out("type " + cls + " failed: instance name should be '" +115instanceName + "' but is '" + result + "'!");116allOk = false;117}118119// system property, both provider class and instance name120provClassName = "jkl";121instanceName = "mno";122System.setProperty(propertyName, provClassName + "#" + instanceName);123result = JDK13Services.getDefaultProviderClassName(cls);124if (! provClassName.equals(result)) {125out("type " + cls + "failed: provider class should be '" +126provClassName + "' but is '" + result + "'!");127allOk = false;128}129result = JDK13Services.getDefaultInstanceName(cls);130if (! instanceName.equals(result)) {131out("type " + cls + "failed: instance name should be '" +132instanceName + "' but is '" + result + "'!");133allOk = false;134}135136// system property, empty137System.setProperty(propertyName, "");138result = JDK13Services.getDefaultProviderClassName(cls);139if (result != null) {140out("type " + cls + " failed: provider class should be " +141"null but is '" + result + "'!");142allOk = false;143}144result = JDK13Services.getDefaultInstanceName(cls);145if (result != null) {146out("type " + cls + "failed: instance name should be " +147"null but is '" + result + "'!");148allOk = false;149}150}151if (! allOk) {152throw new Exception("Test failed");153} else {154out("Test passed");155}156}157158private static void out(String message) {159System.out.println(message);160}161}162163164165