Path: blob/master/test/jdk/sun/nio/cs/LatinCharReplacementTWTest.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 4658679 487964425@summary Checks replacement logic within EUC-TW decoder26*/2728/*29* Tests goodness of fix for bugID 4658679: EUC-TW decoder should30* perform replacement when it encounters latin chars outside the31* normal US-ASCII range. For example: Isolated occurrences of32* French accented chars. See bugID: 4658679.33*/34import java.io.*;35public class LatinCharReplacementTWTest {36public static void main(String[] args) throws Exception {37final String bugID = "4658679";38// Attempt to decode39byte[] input = { (byte)0xa1,40(byte)0xf0,41(byte)'r',42(byte)'e',43(byte)'s',44(byte)0xe9, // illegal within EUC-TW45(byte)'r',46(byte)'v',47(byte)0xe9, // illegal within EUC-TW48(byte)'s',49(byte)0xa2,50(byte)0xf851};5253char[] expected = { (char) 0xa7,54(char) 'r',55(char) 'e',56(char) 's',57(char) 0xFFFD, // replacement for accented lowercase e58(char) 'r',59(char) 'v',60(char) 0xFFFD, // replacement for accented lowercase e61(char) 's',62(char) 0xb0 };6364ByteArrayInputStream bais = new ByteArrayInputStream(input);65InputStreamReader isr = new InputStreamReader(bais, "x-EUC-TW");6667char[] decoded = new char[128];68int numChars = isr.read(decoded);6970if (numChars != expected.length) {71throw new Exception("failure of test for bug " + bugID);72}7374for (int i = 0 ; i < numChars; i++) {75if (decoded[i] != expected[i])76throw new Exception("failure of test for bug " + bugID);77}78}79}808182