Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/I18NArgTest.java
38833 views
/*1* Copyright (c) 2013, 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 801611026* @summary verify Japanese character in an argument are treated correctly27* @compile -XDignore.symbol.file I18NArgTest.java28* @run main I18NArgTest29*/30import java.io.IOException;3132public class I18NArgTest extends TestHelper {33public static void main(String... args) throws IOException {34if (!isWindows) {35return;36}37if (!"MS932".equals(System.getProperty("sun.jnu.encoding"))) {38System.err.println("MS932 encoding not set, test skipped");39return;40}41if (args.length == 0) {42execTest(0x30bd); // MS932 Katakana SO, 0x835C43} else {44testCharacters(args);45}46}47static void execTest(int unicodeValue) {48String hexValue = Integer.toHexString(unicodeValue);49String unicodeStr = Character.toString((char)unicodeValue);50execTest("\"" + unicodeStr + "\"", hexValue);51execTest("\\" + unicodeStr + "\\", hexValue);52execTest(" " + unicodeStr + " ", hexValue);53execTest("'" + unicodeStr + "'", hexValue);54execTest("\t" + unicodeStr + "\t", hexValue);55execTest("*" + unicodeStr + "*", hexValue);56execTest("?" + unicodeStr + "?", hexValue);5758execTest("\"" + unicodeStr + unicodeStr + "\"", hexValue + hexValue);59execTest("\\" + unicodeStr + unicodeStr + "\\", hexValue + hexValue);60execTest(" " + unicodeStr + unicodeStr + " ", hexValue + hexValue);61execTest("'" + unicodeStr + unicodeStr + "'", hexValue + hexValue);62execTest("\t" + unicodeStr + unicodeStr + "\t", hexValue + hexValue);63execTest("*" + unicodeStr + unicodeStr + "*", hexValue + hexValue);64execTest("?" + unicodeStr + unicodeStr + "?", hexValue + hexValue);6566execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "61" + hexValue);67execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "61" + hexValue);68execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "61"+ hexValue);69execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "61"+ hexValue);70execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "61"+ hexValue);71execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "61"+ hexValue);72execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "61"+ hexValue);7374execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "b1" + hexValue);75execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "b1" + hexValue);76execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "b1"+ hexValue);77execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "b1"+ hexValue);78execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "b1"+ hexValue);79execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "b1"+ hexValue);80execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "b1"+ hexValue);81}82static void execTest(String unicodeStr, String hexValue) {83TestResult tr = doExec(javaCmd,84"-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath(),85"-Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath(),86"-cp", TEST_CLASSES_DIR.getAbsolutePath(),87"I18NArgTest", unicodeStr, hexValue);88System.out.println(tr.testOutput);89if (!tr.isOK()) {90System.err.println(tr);91throw new RuntimeException("test fails");92}93}94static void testCharacters(String... args) {95String input = args[0];96String expected = args[1];97String hexValue = "";98for (int i = 0; i < input.length(); i++) {99hexValue = hexValue.concat(Integer.toHexString((int)input.charAt(i)));100}101System.out.println("input:" + input);102System.out.println("expected:" + expected);103System.out.println("obtained:" + hexValue);104if (!hexValue.contains(expected)) {105String message = "Error: output does not contain expected value" +106"expected:" + expected + " obtained:" + hexValue;107throw new RuntimeException(message);108}109}110}111112113