Path: blob/master/test/jdk/sun/nio/cs/SurrogateTestEUCTW.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 484709725@summary Check surrogate coverage of EUC_TW26*/2728/*29* Tests the full surrogate mapping roundtrip fidelity of the30* EUC-TW charset coder updated to support the additional31* planes 4,5,6,7,1532*33* byte->char mappings are contained in external files34* using plane{x}.surrogate as the convention for the input filenames35*36*/3738import java.io.*;39public class SurrogateTestEUCTW {4041private static final String testRootDir42= System.getProperty("test.src", ".");4344public static void main(String[] args) throws Exception {45char[] surrogatePair = new char[2];46int[] expectBytes = new int[4];4748// Iterate test over each supported CNS-11643 plane49// containing supplementary character mappings5051String[] testPlane = { "3", "4", "5", "6" ,"7", "15" };5253for (int i = 0 ; i < testPlane.length; i++) {54FileReader f = new FileReader(testRootDir +55System.getProperty("file.separator")56+ "SurrogateTestEUCTW.plane"57+ testPlane[i]58+ ".surrogates");59BufferedReader r = new BufferedReader(f);60String line;6162while ((line = r.readLine()) != null) {63int charValue = Integer.parseInt(line.substring(9,14), 16);64surrogatePair[0] = (char) ((charValue - 0x10000) / 0x40065+ 0xd800);66surrogatePair[1] = (char) ((charValue - 0x10000) % 0x40067+ 0xdc00);68// Synthesize 4 byte expected byte values from CNS input values69expectBytes[0] = 0x8E;70expectBytes[1] = 0xA0 + Integer.parseInt(testPlane[i]);71expectBytes[2] = 0x80 | Integer.parseInt(line.substring(2,4), 16);72expectBytes[3] = 0x80 | Integer.parseInt(line.substring(4,6), 16);7374String testStr = new String(surrogatePair);75byte[] encodedBytes = testStr.getBytes("EUC-TW");7677for (int x = 0 ; x < 4 ; x++) {78if (encodedBytes[x] != (byte)(expectBytes[x] & 0xff)) {79throw new Exception("EUC_TW Surrogate Encoder error");80}81}8283// Next: test round-trip fidelity84String decoded = new String(encodedBytes, "EUC-TW");8586if (!decoded.equals(testStr)) {87throw new Exception("EUCTW Decoder error");88}89}90r.close();91f.close();92}93}94}959697