Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/nio/cs/SJISCanEncode.java
38839 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*/272829import java.nio.*;30import java.nio.charset.*;3132public class SJISCanEncode {33private Charset cs;34private CharsetEncoder encoder;3536private void canEncodeTest(char inputChar,37boolean expectedResult)38throws Exception {39String msg = "err: Shift_JIS canEncode() return value ";4041if (encoder.canEncode(inputChar) != expectedResult) {42throw new Exception(msg + !(expectedResult) +43": " + Integer.toHexString((int)inputChar));44}45}4647public static void main(String[] args) throws Exception {48SJISCanEncode test = new SJISCanEncode();49test.cs = Charset.forName("SJIS");50test.encoder = test.cs.newEncoder();5152// us-ascii (mappable by Shift_JIS)53test.canEncodeTest('\u0001', true);5455// Halfwidth Katakana56test.canEncodeTest('\uFF01', true);5758// CJK ideograph59test.canEncodeTest('\u4E9C', true);6061//Hiragana62test.canEncodeTest('\u3041', true);63// fullwidth Katakana64test.canEncodeTest('\u30A1', true);6566// U+0080 should be unmappable67// U+4000 is a BMP character not covered by Shift_JISe6869test.canEncodeTest('\u0080', false);70test.canEncodeTest('\u4000', false);71}72}737475