Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/SystemPropertiesTest/src/SysPropTest.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2022 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
import java.util.*;
24
import java.io.*;
25
import java.nio.charset.Charset;
26
import org.openj9.test.util.VersionCheck;
27
28
public class SysPropTest
29
{
30
/* TestVa»lue¡ */
31
static final byte[] inputBytes = { (byte)'T', (byte)'e', (byte)'s', (byte)'t', (byte)'V', (byte)'a', (byte)187, (byte)'l', (byte)'u', (byte)'e', (byte)161};
32
static final byte[] inputBytesUtf8 = { (byte)'T', (byte)'e', (byte)'s', (byte)'t', (byte)'V', (byte)'a', (byte)0xC2, (byte)187, (byte)'l', (byte)'u', (byte)'e', (byte)0xC2, (byte)161};
33
34
public static void main(String args[])
35
{
36
boolean isWindows = false;
37
if (args.length == 0) {
38
System.out.println("test failed");
39
return;
40
}
41
String argEncoding = args[0];
42
/* check -Dtestkey=TestVa?lue? */
43
try {
44
String osEncoding = "";
45
String strTestProp;
46
if (System.getProperty("os.name").contains("Windows")) {
47
isWindows = true;
48
}
49
50
/* On jdk18+ with JEP 400 UTF-8 by default, the non-ascii characters in the testkey property
51
* are converted to UTF8 by the test (not the JVM).
52
*/
53
final byte[] expectedBytes = ((VersionCheck.major() >= 18) && !isWindows) ? inputBytesUtf8 : inputBytes;
54
55
if (argEncoding.equals("DEFAULT")) {
56
osEncoding = System.getProperty("os.encoding");
57
}
58
59
/* Windows converts from the platform default to UTF8 internally to the VM and
60
* sets os.encoding to UTF8. To replicate this behavior, on Windows use the default encoding
61
* and not the os.encoding.
62
*/
63
if (osEncoding != null && osEncoding.length() != 0 && isWindows == false) {
64
strTestProp = new String(expectedBytes, osEncoding);
65
} else {
66
if ((argEncoding.equals("UTF-8") || argEncoding.equals("ISO-8859-1"))) {
67
strTestProp = new String(expectedBytes, argEncoding);
68
} else {
69
strTestProp = new String(expectedBytes, System.getProperty("native.encoding", Charset.defaultCharset().name()));
70
}
71
}
72
73
String strProp = System.getProperty("testkey");
74
if (strProp == null || strTestProp.compareTo(strProp) != 0) {
75
System.out.println("test failed");
76
System.out.println("os.encoding: " + System.getProperty("os.encoding"));
77
System.out.println("native.encoding: " + System.getProperty("native.encoding"));
78
System.out.println("defaultCharset(): " + Charset.defaultCharset().name());
79
System.out.println("file.encoding: " + System.getProperty("file.encoding"));
80
System.out.print("strProp : ");
81
for (int i = 0; i < strProp.length(); i++) {
82
System.out.print(Integer.toHexString(strProp.charAt(i)) + " ");
83
}
84
System.out.println();
85
System.out.print("strTestProp: ");
86
for (int i = 0; i < strTestProp.length(); i++) {
87
System.out.print(Integer.toHexString(strTestProp.charAt(i)) + " ");
88
}
89
System.out.println();
90
91
} else {
92
System.out.println("test succeeded");
93
}
94
} catch (UnsupportedEncodingException e) {
95
System.out.println("test failed");
96
e.printStackTrace();
97
}
98
}
99
}
100
101