1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8016110
  27  * @summary verify Japanese character in an argument are treated correctly
  28  * @compile -XDignore.symbol.file I18NArgTest.java
  29  * @run main I18NArgTest
  30  */
  31 import java.io.IOException;
  32 
  33 public class I18NArgTest extends TestHelper {
  34     public static void main(String... args) throws IOException {
  35         if (!isWindows) {
  36             return;
  37         }
  38         if (!"MS932".equals(System.getProperty("sun.jnu.encoding"))) {
  39             System.err.println("MS932 encoding not set, test skipped");
  40             return;
  41         }
  42         if (args.length == 0) {
  43             execTest(0x30bd); // MS932 Katakana SO, 0x835C
  44         } else {
  45             testCharacters(args);
  46         }
  47     }
  48     static void execTest(int unicodeValue) {
  49         String hexValue = Integer.toHexString(unicodeValue);
  50         String unicodeStr = Character.toString((char)unicodeValue);
  51         execTest("\"" + unicodeStr + "\"", hexValue);
  52         execTest("\\" + unicodeStr + "\\", hexValue);
  53         execTest(" " + unicodeStr + " ", hexValue);
  54         execTest("'" + unicodeStr + "'", hexValue);
  55         execTest("\t" + unicodeStr + "\t", hexValue);
  56         execTest("*" + unicodeStr + "*", hexValue);
  57         execTest("?" + unicodeStr + "?", hexValue);
  58 
  59         execTest("\"" + unicodeStr + unicodeStr + "\"", hexValue + hexValue);
  60         execTest("\\" + unicodeStr + unicodeStr + "\\", hexValue + hexValue);
  61         execTest(" " + unicodeStr + unicodeStr + " ", hexValue + hexValue);
  62         execTest("'" + unicodeStr + unicodeStr + "'", hexValue + hexValue);
  63         execTest("\t" + unicodeStr + unicodeStr + "\t", hexValue + hexValue);
  64         execTest("*" + unicodeStr + unicodeStr + "*", hexValue + hexValue);
  65         execTest("?" + unicodeStr + unicodeStr + "?", hexValue + hexValue);
  66 
  67         execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "61" + hexValue);
  68         execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "61" + hexValue);
  69         execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "61"+ hexValue);
  70         execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "61"+ hexValue);
  71         execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "61"+ hexValue);
  72         execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "61"+ hexValue);
  73         execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "61"+ hexValue);
  74 
  75         execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "b1" + hexValue);
  76         execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "b1" + hexValue);
  77         execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "b1"+ hexValue);
  78         execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "b1"+ hexValue);
  79         execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "b1"+ hexValue);
  80         execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "b1"+ hexValue);
  81         execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "b1"+ hexValue);
  82     }
  83     static void execTest(String unicodeStr, String hexValue) {
  84         TestResult tr = doExec(javaCmd,
  85                 "-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath(),
  86                 "-Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath(),
  87                 "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
  88                 "I18NArgTest", unicodeStr, hexValue);
  89         System.out.println(tr.testOutput);
  90         if (!tr.isOK()) {
  91             System.err.println(tr);
  92             throw new RuntimeException("test fails");
  93         }
  94     }
  95     static void testCharacters(String... args) {
  96         String input = args[0];
  97         String expected = args[1];
  98         String hexValue = "";
  99         for (int i = 0; i < input.length(); i++) {
 100             hexValue = hexValue.concat(Integer.toHexString((int)input.charAt(i)));
 101         }
 102         System.out.println("input:" + input);
 103         System.out.println("expected:" + expected);
 104         System.out.println("obtained:" + hexValue);
 105         if (!hexValue.contains(expected)) {
 106             String message = "Error: output does not contain expected value" +
 107                 "expected:" + expected + " obtained:" + hexValue;
 108             throw new RuntimeException(message);
 109         }
 110     }
 111 }