Path: blob/master/test/jdk/sun/nio/cs/SJISCanEncode.java
41149 views
/*1* Copyright (c) 2008, 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/* @test24* @bug 491370225* @summary validates canEncode(char c) method for sun.nio.cs.Shift_JIS26* @modules jdk.charsets27*/282930import java.nio.*;31import java.nio.charset.*;3233public class SJISCanEncode {34private Charset cs;35private CharsetEncoder encoder;3637private void canEncodeTest(char inputChar,38boolean expectedResult)39throws Exception {40String msg = "err: Shift_JIS canEncode() return value ";4142if (encoder.canEncode(inputChar) != expectedResult) {43throw new Exception(msg + !(expectedResult) +44": " + Integer.toHexString((int)inputChar));45}46}4748public static void main(String[] args) throws Exception {49SJISCanEncode test = new SJISCanEncode();50test.cs = Charset.forName("SJIS");51test.encoder = test.cs.newEncoder();5253// us-ascii (mappable by Shift_JIS)54test.canEncodeTest('\u0001', true);5556// Halfwidth Katakana57test.canEncodeTest('\uFF01', true);5859// CJK ideograph60test.canEncodeTest('\u4E9C', true);6162//Hiragana63test.canEncodeTest('\u3041', true);64// fullwidth Katakana65test.canEncodeTest('\u30A1', true);6667// U+0080 should be unmappable68// U+4000 is a BMP character not covered by Shift_JISe6970test.canEncodeTest('\u0080', false);71test.canEncodeTest('\u4000', false);72}73}747576