Skip to content

Commit

Permalink
8289797: tools/launcher/I18NArgTest.java fails on Japanese Windows en…
Browse files Browse the repository at this point in the history
…vironment

Backport-of: a11477ce259d6d2a053117a2300ebb171145cfde
  • Loading branch information
TheRealMDoerr committed Aug 9, 2023
1 parent a5cdc22 commit 6349de6
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions test/jdk/tools/launcher/I18NArgTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.HexFormat;
import java.nio.charset.StandardCharsets;

public class I18NArgTest extends TestHelper {
public static void main(String... args) throws IOException {
Expand Down Expand Up @@ -66,21 +68,21 @@ static void execTest(int unicodeValue) {
execTest("*" + unicodeStr + unicodeStr + "*", hexValue + hexValue);
execTest("?" + unicodeStr + unicodeStr + "?", hexValue + hexValue);

execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "61" + hexValue);
execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "61" + hexValue);
execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "61"+ hexValue);
execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "61"+ hexValue);
execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "61"+ hexValue);
execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "61"+ hexValue);
execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "61"+ hexValue);
execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "0061" + hexValue);
execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "0061" + hexValue);
execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "0061"+ hexValue);
execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "0061"+ hexValue);
execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "0061"+ hexValue);
execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "0061"+ hexValue);
execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "0061"+ hexValue);

execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "b1" + hexValue);
execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "b1" + hexValue);
execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "b1"+ hexValue);
execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "b1"+ hexValue);
execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "b1"+ hexValue);
execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "b1"+ hexValue);
execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "b1"+ hexValue);
execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "00b1" + hexValue);
execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "00b1" + hexValue);
execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "00b1"+ hexValue);
execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "00b1"+ hexValue);
execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "00b1"+ hexValue);
execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "00b1"+ hexValue);
execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "00b1"+ hexValue);
}

static void execTest(String unicodeStr, String hexValue) {
Expand All @@ -97,12 +99,21 @@ static void execTest(String unicodeStr, String hexValue) {

// Test via JDK_JAVA_OPTIONS
Map<String, String> env = new HashMap<>();
String cmd = "-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath() +
" -Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath() +
" -cp " + TEST_CLASSES_DIR.getAbsolutePath() +
" I18NArgTest " + unicodeStr + " " + hexValue;
env.put("JDK_JAVA_OPTIONS", cmd);
tr = doExec(env, javaCmd);
String sysPropName = "foo.bar";
// When pass "-Dfoo.bar=<unicodestr>" via the JDK_JAVA_OPTIONS environment variable,
// we expect that system property value to be passed along to the main method with the
// correct encoding
// If <unicodestr> contains space or tab, it should be enclosed with double quotes.
if (unicodeStr.contains(" ") || unicodeStr.contains("\t")) {
unicodeStr = "\"" + unicodeStr + "\"";
}
String jdkJavaOpts = "-D" + sysPropName + "=" + unicodeStr;
env.put("JDK_JAVA_OPTIONS", jdkJavaOpts);
tr = doExec(env,javaCmd,
"-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath(),
"-Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath(),
"-cp", TEST_CLASSES_DIR.getAbsolutePath(),
"I18NArgTest", unicodeStr, hexValue, sysPropName);
System.out.println(tr.testOutput);
if (!tr.isOK()) {
System.err.println(tr);
Expand All @@ -113,10 +124,7 @@ static void execTest(String unicodeStr, String hexValue) {
static void testCharacters(String... args) {
String input = args[0];
String expected = args[1];
String hexValue = "";
for (int i = 0; i < input.length(); i++) {
hexValue = hexValue.concat(Integer.toHexString((int)input.charAt(i)));
}
var hexValue = HexFormat.of().formatHex(input.getBytes(StandardCharsets.UTF_16));
System.out.println("input:" + input);
System.out.println("expected:" + expected);
System.out.println("obtained:" + hexValue);
Expand All @@ -125,5 +133,20 @@ static void testCharacters(String... args) {
"expected:" + expected + " obtained:" + hexValue;
throw new RuntimeException(message);
}
if (args.length == 3) {
// verify the value of the system property matches the expected value
String sysPropName = args[2];
String sysPropVal = System.getProperty(sysPropName);
if (sysPropVal == null) {
throw new RuntimeException("Missing system property " + sysPropName);
}
var sysPropHexVal = HexFormat.of().formatHex(sysPropVal.getBytes(StandardCharsets.UTF_16));
System.out.println("System property " + sysPropName + " computed hex value: "
+ sysPropHexVal);
if (!sysPropHexVal.contains(expected)) {
throw new RuntimeException("Unexpected value in system property, expected "
+ expected + ", but got " + sysPropHexVal);
}
}
}
}

1 comment on commit 6349de6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.