Path: blob/master/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/DefaultProperties.java
41161 views
/*1* Copyright (c) 2003, 2018, 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.nio.file.Paths;2425import com.sun.media.sound.JDK13Services;2627/**28* @test29* @bug 4776511 820127930* @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* @run main/othervm/policy=java.policy DefaultProperties34* @modules java.desktop/com.sun.media.sound35*/36public class DefaultProperties {3738private static final Class[] lineTypeClasses = {39javax.sound.midi.Receiver.class,40javax.sound.midi.Transmitter.class,41javax.sound.midi.Sequencer.class,42javax.sound.midi.Synthesizer.class,43};4445public static void main(String[] args) throws Exception {46boolean allOk = true;47String path = Paths.get(System.getProperty("test.src", "."),48"testdata", "conf", "sound.properties")49.toAbsolutePath().normalize().toString();50System.setProperty("javax.sound.config.file", path);5152for (int i = 0; i < lineTypeClasses.length; i++) {53Class cls = lineTypeClasses[i];54String propertyName = cls.getName();55String result;56String provClassName;57String instanceName;5859// properties file, both provider class name and instance name60provClassName = "xyz";61instanceName = "123";62result = JDK13Services.getDefaultProviderClassName(cls);63if (! provClassName.equals(result)) {64out("type " + cls + " failed: provider class should be '" +65provClassName + "' but is '" + result + "'!");66allOk = false;67}68result = JDK13Services.getDefaultInstanceName(cls);69if (! instanceName.equals(result)) {70out("type " + cls + " failed: instance name should be '" +71instanceName + "' but is '" + result + "'!");72allOk = false;73}7475// system property, provider class name only, no trailing hash76provClassName = "abc";77System.setProperty(propertyName, provClassName);78result = JDK13Services.getDefaultProviderClassName(cls);79if (! provClassName.equals(result)) {80out("type " + cls + " failed: provider class should be '" +81provClassName + "' but is '" + result + "'!");82allOk = false;83}84result = JDK13Services.getDefaultInstanceName(cls);85if (result != null) {86out("type " + cls + " failed: instance name should be " +87"null but is '" + result + "'!");88allOk = false;89}9091// system property, provider class name only, trailing hash92provClassName = "def";93System.setProperty(propertyName, provClassName + "#");94result = JDK13Services.getDefaultProviderClassName(cls);95if (! provClassName.equals(result)) {96out("type " + cls + " failed: provider class should be '" +97provClassName + "' but is '" + result + "'!");98allOk = false;99}100result = JDK13Services.getDefaultInstanceName(cls);101if (result != null) {102out("type " + cls + " failed: instance name should be " +103"null but is '" + result + "'!");104allOk = false;105}106107// system property, instance name only108instanceName = "ghi";109System.setProperty(propertyName, "#" + instanceName);110result = JDK13Services.getDefaultProviderClassName(cls);111if (result != null) {112out("type " + cls + " failed: provider class should be " +113"null but is '" + result + "'!");114allOk = false;115}116result = JDK13Services.getDefaultInstanceName(cls);117if (! instanceName.equals(result)) {118out("type " + cls + " failed: instance name should be '" +119instanceName + "' but is '" + result + "'!");120allOk = false;121}122123// system property, both provider class and instance name124provClassName = "jkl";125instanceName = "mno";126System.setProperty(propertyName, provClassName + "#" + instanceName);127result = JDK13Services.getDefaultProviderClassName(cls);128if (! provClassName.equals(result)) {129out("type " + cls + "failed: provider class should be '" +130provClassName + "' but is '" + result + "'!");131allOk = false;132}133result = JDK13Services.getDefaultInstanceName(cls);134if (! instanceName.equals(result)) {135out("type " + cls + "failed: instance name should be '" +136instanceName + "' but is '" + result + "'!");137allOk = false;138}139140// system property, empty141System.setProperty(propertyName, "");142result = JDK13Services.getDefaultProviderClassName(cls);143if (result != null) {144out("type " + cls + " failed: provider class should be " +145"null but is '" + result + "'!");146allOk = false;147}148result = JDK13Services.getDefaultInstanceName(cls);149if (result != null) {150out("type " + cls + "failed: instance name should be " +151"null but is '" + result + "'!");152allOk = false;153}154}155if (! allOk) {156throw new Exception("Test failed");157} else {158out("Test passed");159}160}161162private static void out(String message) {163System.out.println(message);164}165}166167168169