Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/nio/cs/EuroConverter.java
38838 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/**24* @test25* @bug 411408026* @summary Make sure the euro converters, which are derived from27* existing converters, only differ from their parents at the expected28* code point.29*/3031import java.text.*;32import java.util.*;33import java.io.*;3435/* Author: Alan Liu36* 7/14/9837*/38public class EuroConverter {39public static void main(String args[]) throws Exception {40boolean pass = true;41char[] map = new char[256]; // map for the encoding42byte[] bytes = new byte[1]; // scratch43char[] chars = new char[1]; // scratch44for (int i=0; i<DATA.length; ) {45String euroEnc = DATA[i++];46String parentEnc = DATA[i++];47System.out.println("Checking encoder " + euroEnc + " against " + parentEnc);48String currentEnc = parentEnc;4950try {51// Fill map with parent values52for (int j=-128; j<128; ++j) {53bytes[0] = (byte)j;54char parentValue = new String(bytes, parentEnc).charAt(0);55// NOTE: 0x25 doesn't round trip on the EBCDIC code pages,56// so we don't check that code point in the sanity check.57if (j != 0x0025) {58chars[0] = parentValue;59int parentRoundTrip = new String(chars).getBytes(parentEnc)[0];60// This is a sanity check -- we aren't really testing the parent61// encoder here.62if (parentRoundTrip != j) {63pass = false;64System.out.println("Error: Encoder " + parentEnc +65" fails round-trip: " + j +66" -> \\u" + Integer.toHexString(parentValue) +67" -> " + parentRoundTrip);68}69}70map[(j+0x100)&0xFF] = parentValue;71}7273// Modify map with new expected values. Each pair has code point, parent value, euro value.74// Terminated by null.75while (DATA[i] != null) {76int codePoint = Integer.valueOf(DATA[i++], 16).intValue();77char expectedParentValue = DATA[i++].charAt(0);78char expectedEuroValue = DATA[i++].charAt(0);79// This is a sanity check -- we aren't really testing the parent80// encoder here.81if (map[codePoint] != expectedParentValue) {82pass = false;83System.out.println("Error: Encoder " + parentEnc +84" " + Integer.toHexString(codePoint) + " -> \\u" +85Integer.toHexString(map[codePoint]) + ", expected \\u" +86Integer.toHexString(expectedParentValue));87}88// Fill in new expected value89map[codePoint] = expectedEuroValue;90}91++i; // Skip over null at end of set9293// Now verify the euro encoder94currentEnc = euroEnc;95for (int j=-128; j<128; ++j) {96bytes[0] = (byte)j;97char euroValue = new String(bytes, euroEnc).charAt(0);98chars[0] = euroValue;99// NOTE: 0x15 doesn't round trip on the EBCDIC code pages,100// so we don't check that code point in the sanity check.101if (j != 0x0015) {102int euroRoundTrip = new String(chars).getBytes(euroEnc)[0];103if (euroRoundTrip != j) {104pass = false;105System.out.println("Error: Encoder " + euroEnc +106" fails round-trip at " + j);107}108}109// Compare against the map110if (euroValue != map[(j+0x100)&0xFF]) {111pass = false;112System.out.println("Error: Encoder " + euroEnc +113" " + Integer.toHexString((j+0x100)&0xFF) + " -> \\u" +114Integer.toHexString(euroValue) + ", expected \\u" +115Integer.toHexString(map[(j+0x100)&0xFF]));116}117}118} catch (UnsupportedEncodingException e) {119System.out.println("Unsupported encoding " + currentEnc);120pass = false;121while (i < DATA.length && DATA[i] != null) ++i;122++i; // Skip over null123}124}125if (!pass) {126throw new RuntimeException("Bug 4114080 - Euro encoder test failed");127}128}129static String[] DATA = {130// New converter, parent converter, [ code point that changed, parent code point value,131// euro code point value ], null132// Any number of changed code points may be specified, including zero.133"ISO8859_15_FDIS", "ISO8859_1",134"A4", "\u00A4", "\u20AC",135"A6", "\u00A6", "\u0160",136"A8", "\u00A8", "\u0161",137"B4", "\u00B4", "\u017D",138"B8", "\u00B8", "\u017E",139"BC", "\u00BC", "\u0152",140"BD", "\u00BD", "\u0153",141"BE", "\u00BE", "\u0178",142null,143// 923 is IBM's name for ISO 8859-15; make sure they're identical144"Cp923", "ISO8859_15_FDIS", null,145"Cp858", "Cp850", "D5", "\u0131", "\u20AC", null,146"Cp1140", "Cp037", "9F", "\u00A4", "\u20AC", null,147"Cp1141", "Cp273", "9F", "\u00A4", "\u20AC", null,148"Cp1142", "Cp277", "5A", "\u00A4", "\u20AC", null,149"Cp1143", "Cp278", "5A", "\u00A4", "\u20AC", null,150"Cp1144", "Cp280", "9F", "\u00A4", "\u20AC", null,151"Cp1145", "Cp284", "9F", "\u00A4", "\u20AC", null,152"Cp1146", "Cp285", "9F", "\u00A4", "\u20AC", null,153"Cp1147", "Cp297", "9F", "\u00A4", "\u20AC", null,154"Cp1148", "Cp500", "9F", "\u00A4", "\u20AC", null,155"Cp1149", "Cp871", "9F", "\u00A4", "\u20AC", null,156};157}158159160