Path: blob/master/test/jdk/tools/launcher/I18NArgTest.java
41144 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8016110 817083226* @summary verify Japanese character in an argument are treated correctly27* @compile -XDignore.symbol.file I18NArgTest.java28* @run main I18NArgTest29*/30import java.io.IOException;31import java.util.Map;32import java.util.HashMap;3334public class I18NArgTest extends TestHelper {35public static void main(String... args) throws IOException {36if (!isWindows) {37return;38}39if (!"MS932".equals(System.getProperty("sun.jnu.encoding"))) {40System.err.println("MS932 encoding not set, test skipped");41return;42}43if (args.length == 0) {44execTest(0x30bd); // MS932 Katakana SO, 0x835C45} else {46testCharacters(args);47}48}49static void execTest(int unicodeValue) {50String hexValue = Integer.toHexString(unicodeValue);51String unicodeStr = Character.toString((char)unicodeValue);52execTest("\"" + unicodeStr + "\"", hexValue);53execTest("\\" + unicodeStr + "\\", hexValue);54execTest(" " + unicodeStr + " ", hexValue);55execTest("'" + unicodeStr + "'", hexValue);56execTest("\t" + unicodeStr + "\t", hexValue);57execTest("*" + unicodeStr + "*", hexValue);58execTest("?" + unicodeStr + "?", hexValue);5960execTest("\"" + unicodeStr + unicodeStr + "\"", hexValue + hexValue);61execTest("\\" + unicodeStr + unicodeStr + "\\", hexValue + hexValue);62execTest(" " + unicodeStr + unicodeStr + " ", hexValue + hexValue);63execTest("'" + unicodeStr + unicodeStr + "'", hexValue + hexValue);64execTest("\t" + unicodeStr + unicodeStr + "\t", hexValue + hexValue);65execTest("*" + unicodeStr + unicodeStr + "*", hexValue + hexValue);66execTest("?" + unicodeStr + unicodeStr + "?", hexValue + hexValue);6768execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "61" + hexValue);69execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "61" + hexValue);70execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "61"+ hexValue);71execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "61"+ hexValue);72execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "61"+ hexValue);73execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "61"+ hexValue);74execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "61"+ hexValue);7576execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "b1" + hexValue);77execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "b1" + hexValue);78execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "b1"+ hexValue);79execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "b1"+ hexValue);80execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "b1"+ hexValue);81execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "b1"+ hexValue);82execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "b1"+ hexValue);83}8485static void execTest(String unicodeStr, String hexValue) {86TestResult tr = doExec(javaCmd,87"-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath(),88"-Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath(),89"-cp", TEST_CLASSES_DIR.getAbsolutePath(),90"I18NArgTest", unicodeStr, hexValue);91System.out.println(tr.testOutput);92if (!tr.isOK()) {93System.err.println(tr);94throw new RuntimeException("test fails");95}9697// Test via JDK_JAVA_OPTIONS98Map<String, String> env = new HashMap<>();99String cmd = "-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath() +100" -Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath() +101" -cp " + TEST_CLASSES_DIR.getAbsolutePath() +102" I18NArgTest " + unicodeStr + " " + hexValue;103env.put("JDK_JAVA_OPTIONS", cmd);104tr = doExec(env, javaCmd);105System.out.println(tr.testOutput);106if (!tr.isOK()) {107System.err.println(tr);108throw new RuntimeException("test fails");109}110}111112static void testCharacters(String... args) {113String input = args[0];114String expected = args[1];115String hexValue = "";116for (int i = 0; i < input.length(); i++) {117hexValue = hexValue.concat(Integer.toHexString((int)input.charAt(i)));118}119System.out.println("input:" + input);120System.out.println("expected:" + expected);121System.out.println("obtained:" + hexValue);122if (!hexValue.contains(expected)) {123String message = "Error: output does not contain expected value" +124"expected:" + expected + " obtained:" + hexValue;125throw new RuntimeException(message);126}127}128}129130131