Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/MidiSystem/DefaultProperties.java
38853 views
1
/*
2
* Copyright (c) 2003, 2020, 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 java.io.File;
25
26
import com.sun.media.sound.JDK13Services;
27
28
/**
29
* @test
30
* @bug 4776511
31
* @summary RFE: Setting the default MixerProvider. Test the retrieving and
32
* parsing of properties. This is a part of the test for 4776511.
33
* @run main/othervm DefaultProperties
34
*/
35
public class DefaultProperties {
36
37
private static final Class[] lineTypeClasses = {
38
javax.sound.midi.Receiver.class,
39
javax.sound.midi.Transmitter.class,
40
javax.sound.midi.Sequencer.class,
41
javax.sound.midi.Synthesizer.class,
42
};
43
44
public static void main(String[] args) throws Exception {
45
boolean allOk = true;
46
File file = new File(System.getProperty("test.src", "."), "testdata");
47
System.setProperty("java.home", file.getCanonicalPath());
48
49
for (int i = 0; i < lineTypeClasses.length; i++) {
50
Class cls = lineTypeClasses[i];
51
String propertyName = cls.getName();
52
String result;
53
String provClassName;
54
String instanceName;
55
56
// properties file, both provider class name and instance name
57
provClassName = "xyz";
58
instanceName = "123";
59
result = JDK13Services.getDefaultProviderClassName(cls);
60
if (! provClassName.equals(result)) {
61
out("type " + cls + " failed: provider class should be '" +
62
provClassName + "' but is '" + result + "'!");
63
allOk = false;
64
}
65
result = JDK13Services.getDefaultInstanceName(cls);
66
if (! instanceName.equals(result)) {
67
out("type " + cls + " failed: instance name should be '" +
68
instanceName + "' but is '" + result + "'!");
69
allOk = false;
70
}
71
72
// system property, provider class name only, no trailing hash
73
provClassName = "abc";
74
System.setProperty(propertyName, provClassName);
75
result = JDK13Services.getDefaultProviderClassName(cls);
76
if (! provClassName.equals(result)) {
77
out("type " + cls + " failed: provider class should be '" +
78
provClassName + "' but is '" + result + "'!");
79
allOk = false;
80
}
81
result = JDK13Services.getDefaultInstanceName(cls);
82
if (result != null) {
83
out("type " + cls + " failed: instance name should be " +
84
"null but is '" + result + "'!");
85
allOk = false;
86
}
87
88
// system property, provider class name only, trailing hash
89
provClassName = "def";
90
System.setProperty(propertyName, provClassName + "#");
91
result = JDK13Services.getDefaultProviderClassName(cls);
92
if (! provClassName.equals(result)) {
93
out("type " + cls + " failed: provider class should be '" +
94
provClassName + "' but is '" + result + "'!");
95
allOk = false;
96
}
97
result = JDK13Services.getDefaultInstanceName(cls);
98
if (result != null) {
99
out("type " + cls + " failed: instance name should be " +
100
"null but is '" + result + "'!");
101
allOk = false;
102
}
103
104
// system property, instance name only
105
instanceName = "ghi";
106
System.setProperty(propertyName, "#" + instanceName);
107
result = JDK13Services.getDefaultProviderClassName(cls);
108
if (result != null) {
109
out("type " + cls + " failed: provider class should be " +
110
"null but is '" + result + "'!");
111
allOk = false;
112
}
113
result = JDK13Services.getDefaultInstanceName(cls);
114
if (! instanceName.equals(result)) {
115
out("type " + cls + " failed: instance name should be '" +
116
instanceName + "' but is '" + result + "'!");
117
allOk = false;
118
}
119
120
// system property, both provider class and instance name
121
provClassName = "jkl";
122
instanceName = "mno";
123
System.setProperty(propertyName, provClassName + "#" + instanceName);
124
result = JDK13Services.getDefaultProviderClassName(cls);
125
if (! provClassName.equals(result)) {
126
out("type " + cls + "failed: provider class should be '" +
127
provClassName + "' but is '" + result + "'!");
128
allOk = false;
129
}
130
result = JDK13Services.getDefaultInstanceName(cls);
131
if (! instanceName.equals(result)) {
132
out("type " + cls + "failed: instance name should be '" +
133
instanceName + "' but is '" + result + "'!");
134
allOk = false;
135
}
136
137
// system property, empty
138
System.setProperty(propertyName, "");
139
result = JDK13Services.getDefaultProviderClassName(cls);
140
if (result != null) {
141
out("type " + cls + " failed: provider class should be " +
142
"null but is '" + result + "'!");
143
allOk = false;
144
}
145
result = JDK13Services.getDefaultInstanceName(cls);
146
if (result != null) {
147
out("type " + cls + "failed: instance name should be " +
148
"null but is '" + result + "'!");
149
allOk = false;
150
}
151
}
152
if (! allOk) {
153
throw new Exception("Test failed");
154
} else {
155
out("Test passed");
156
}
157
}
158
159
private static void out(String message) {
160
System.out.println(message);
161
}
162
}
163
164
165