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