author | serb |
Tue, 29 May 2018 11:22:21 -0700 | |
changeset 50349 | b3a654c6fbcc |
permissions | -rw-r--r-- |
50349
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
1 |
/* |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
4 |
* |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
8 |
* |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
14 |
* |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
18 |
* |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
21 |
* questions. |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
22 |
*/ |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
23 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
24 |
import java.nio.file.Paths; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
25 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
26 |
import com.sun.media.sound.JDK13Services; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
27 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
28 |
/** |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
29 |
* @test |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
30 |
* @bug 8201279 |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
31 |
* @run main/othervm/policy=negative.policy DefaultPropertiesNegative |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
32 |
* @summary this test checks that "javax.sound.config.file" will be ignored if |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
33 |
* the user has no access to the properties file |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
34 |
* @modules java.desktop/com.sun.media.sound |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
35 |
*/ |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
36 |
public class DefaultPropertiesNegative { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
37 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
38 |
private static final Class[] lineTypeClasses = { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
39 |
javax.sound.sampled.SourceDataLine.class, |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
40 |
javax.sound.sampled.TargetDataLine.class, |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
41 |
javax.sound.sampled.Clip.class, |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
42 |
javax.sound.sampled.Port.class, |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
43 |
}; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
44 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
46 |
boolean allOk = true; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
47 |
String path = Paths.get(System.getProperty("test.src", "."), |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
48 |
"testdata", "conf", "sound.properties") |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
49 |
.toAbsolutePath().normalize().toString(); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
50 |
System.setProperty("javax.sound.config.file", path); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
51 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
52 |
for (int i = 0; i < lineTypeClasses.length; i++) { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
53 |
Class cls = lineTypeClasses[i]; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
54 |
// properties file, both provider class name and instance name |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
55 |
String result = JDK13Services.getDefaultProviderClassName(cls); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
56 |
if (result != null) { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
57 |
out("type " + cls + " failed: provider class should be 'null' " |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
58 |
+ "but is '" + result + "'!"); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
59 |
allOk = false; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
60 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
61 |
result = JDK13Services.getDefaultInstanceName(cls); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
62 |
if (result != null) { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
63 |
out("type " + cls + " failed: instance name should be 'null' " |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
64 |
+ "but is '" + result + "'!"); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
65 |
allOk = false; |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
66 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
67 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
68 |
if (! allOk) { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
69 |
throw new Exception("Test failed"); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
70 |
} else { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
71 |
out("Test passed"); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
72 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
73 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
74 |
|
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
75 |
private static void out(String message) { |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
76 |
System.out.println(message); |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
77 |
} |
b3a654c6fbcc
8201279: javax.sound tests should not set java.home system property
serb
parents:
diff
changeset
|
78 |
} |