Path: blob/master/test/functional/cmdLineTests/SystemPropertiesTest/src/SysPropTest.java
6004 views
/*******************************************************************************1* Copyright (c) 2001, 2022 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122import java.util.*;23import java.io.*;24import java.nio.charset.Charset;25import org.openj9.test.util.VersionCheck;2627public class SysPropTest28{29/* TestVa»lue¡ */30static 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};31static 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};3233public static void main(String args[])34{35boolean isWindows = false;36if (args.length == 0) {37System.out.println("test failed");38return;39}40String argEncoding = args[0];41/* check -Dtestkey=TestVa?lue? */42try {43String osEncoding = "";44String strTestProp;45if (System.getProperty("os.name").contains("Windows")) {46isWindows = true;47}4849/* On jdk18+ with JEP 400 UTF-8 by default, the non-ascii characters in the testkey property50* are converted to UTF8 by the test (not the JVM).51*/52final byte[] expectedBytes = ((VersionCheck.major() >= 18) && !isWindows) ? inputBytesUtf8 : inputBytes;5354if (argEncoding.equals("DEFAULT")) {55osEncoding = System.getProperty("os.encoding");56}5758/* Windows converts from the platform default to UTF8 internally to the VM and59* sets os.encoding to UTF8. To replicate this behavior, on Windows use the default encoding60* and not the os.encoding.61*/62if (osEncoding != null && osEncoding.length() != 0 && isWindows == false) {63strTestProp = new String(expectedBytes, osEncoding);64} else {65if ((argEncoding.equals("UTF-8") || argEncoding.equals("ISO-8859-1"))) {66strTestProp = new String(expectedBytes, argEncoding);67} else {68strTestProp = new String(expectedBytes, System.getProperty("native.encoding", Charset.defaultCharset().name()));69}70}7172String strProp = System.getProperty("testkey");73if (strProp == null || strTestProp.compareTo(strProp) != 0) {74System.out.println("test failed");75System.out.println("os.encoding: " + System.getProperty("os.encoding"));76System.out.println("native.encoding: " + System.getProperty("native.encoding"));77System.out.println("defaultCharset(): " + Charset.defaultCharset().name());78System.out.println("file.encoding: " + System.getProperty("file.encoding"));79System.out.print("strProp : ");80for (int i = 0; i < strProp.length(); i++) {81System.out.print(Integer.toHexString(strProp.charAt(i)) + " ");82}83System.out.println();84System.out.print("strTestProp: ");85for (int i = 0; i < strTestProp.length(); i++) {86System.out.print(Integer.toHexString(strTestProp.charAt(i)) + " ");87}88System.out.println();8990} else {91System.out.println("test succeeded");92}93} catch (UnsupportedEncodingException e) {94System.out.println("test failed");95e.printStackTrace();96}97}98}99100101