SJISPropTest.java revision 2362
2115N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2115N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2115N/A *
2115N/A * This code is free software; you can redistribute it and/or modify it
2115N/A * under the terms of the GNU General Public License version 2 only, as
2115N/A * published by the Free Software Foundation.
2115N/A *
2115N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2115N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2115N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2115N/A * version 2 for more details (a copy is included in the LICENSE file that
2115N/A * accompanied this code).
2115N/A *
2115N/A * You should have received a copy of the GNU General Public License version
2115N/A * 2 along with this work; if not, write to the Free Software Foundation,
2115N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2115N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2115N/A */
2115N/A
2115N/A/*
2115N/A *
2115N/A *
2115N/A * Regression test class run by CheckSJISMappingProp.sh to verify
2115N/A * that sun.nio.cs.map property is correctly interpreted in
2115N/A * multibyte Japanese locales
2115N/A *
2115N/A */
2115N/A
2115N/Apublic class SJISPropTest {
2115N/A public static void main(String[] args) throws Exception {
2115N/A boolean sjisIsMS932 = false;
2115N/A
2115N/A if (args[0].equals("MS932"))
2115N/A sjisIsMS932 = true;
2115N/A byte[] testBytes = { (byte)0x81, (byte)0x60 };
2115N/A
2115N/A // JIS X based Shift_JIS and Windows-31J differ
2115N/A // in a number of mappings including this one.
2115N/A
2115N/A String expectedMS932 = new String("\uFF5E");
2115N/A String expectedSJIS = new String("\u301C");
2115N/A
2115N/A // Alias "shift_jis" will map to Windows-31J
2115N/A // if the sun.nio.cs.map system property is defined as
2115N/A // "Windows-31J/Shift_JIS". This should work in all
2115N/A // multibyte (especially Japanese) locales.
2115N/A
2115N/A String s = new String(testBytes, "shift_jis");
2115N/A
2115N/A if (sjisIsMS932 && !s.equals(expectedMS932))
2115N/A throw new Exception("not MS932");
2115N/A else if (!sjisIsMS932 && !s.equals(expectedSJIS))
2115N/A throw new Exception("not SJIS");
2115N/A }
2115N/A}