395N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
395N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
395N/A *
395N/A * This code is free software; you can redistribute it and/or modify it
395N/A * under the terms of the GNU General Public License version 2 only, as
395N/A * published by the Free Software Foundation.
395N/A *
395N/A * This code is distributed in the hope that it will be useful, but WITHOUT
395N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
395N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
395N/A * version 2 for more details (a copy is included in the LICENSE file that
395N/A * accompanied this code).
395N/A *
395N/A * You should have received a copy of the GNU General Public License version
395N/A * 2 along with this work; if not, write to the Free Software Foundation,
395N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
395N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
395N/A */
395N/A
395N/A/**
395N/A * @test
395N/A * @bug 4114080
395N/A * @summary Make sure the euro converters, which are derived from
395N/A * existing converters, only differ from their parents at the expected
395N/A * code point.
395N/A */
395N/A
395N/Aimport java.text.*;
395N/Aimport java.util.*;
395N/Aimport java.io.*;
395N/A
395N/A/* Author: Alan Liu
395N/A * 7/14/98
395N/A */
395N/Apublic class EuroConverter {
395N/A public static void main(String args[]) throws Exception {
395N/A boolean pass = true;
395N/A char[] map = new char[256]; // map for the encoding
395N/A byte[] bytes = new byte[1]; // scratch
395N/A char[] chars = new char[1]; // scratch
395N/A for (int i=0; i<DATA.length; ) {
395N/A String euroEnc = DATA[i++];
395N/A String parentEnc = DATA[i++];
395N/A System.out.println("Checking encoder " + euroEnc + " against " + parentEnc);
395N/A String currentEnc = parentEnc;
395N/A
395N/A try {
395N/A // Fill map with parent values
395N/A for (int j=-128; j<128; ++j) {
395N/A bytes[0] = (byte)j;
395N/A char parentValue = new String(bytes, parentEnc).charAt(0);
395N/A // NOTE: 0x25 doesn't round trip on the EBCDIC code pages,
395N/A // so we don't check that code point in the sanity check.
395N/A if (j != 0x0025) {
395N/A chars[0] = parentValue;
395N/A int parentRoundTrip = new String(chars).getBytes(parentEnc)[0];
395N/A // This is a sanity check -- we aren't really testing the parent
395N/A // encoder here.
395N/A if (parentRoundTrip != j) {
395N/A pass = false;
395N/A System.out.println("Error: Encoder " + parentEnc +
395N/A " fails round-trip: " + j +
395N/A " -> \\u" + Integer.toHexString(parentValue) +
395N/A " -> " + parentRoundTrip);
395N/A }
395N/A }
395N/A map[(j+0x100)&0xFF] = parentValue;
395N/A }
395N/A
395N/A // Modify map with new expected values. Each pair has code point, parent value, euro value.
395N/A // Terminated by null.
395N/A while (DATA[i] != null) {
395N/A int codePoint = Integer.valueOf(DATA[i++], 16).intValue();
395N/A char expectedParentValue = DATA[i++].charAt(0);
395N/A char expectedEuroValue = DATA[i++].charAt(0);
395N/A // This is a sanity check -- we aren't really testing the parent
395N/A // encoder here.
395N/A if (map[codePoint] != expectedParentValue) {
395N/A pass = false;
395N/A System.out.println("Error: Encoder " + parentEnc +
395N/A " " + Integer.toHexString(codePoint) + " -> \\u" +
395N/A Integer.toHexString(map[codePoint]) + ", expected \\u" +
395N/A Integer.toHexString(expectedParentValue));
395N/A }
395N/A // Fill in new expected value
395N/A map[codePoint] = expectedEuroValue;
395N/A }
395N/A ++i; // Skip over null at end of set
395N/A
395N/A // Now verify the euro encoder
395N/A currentEnc = euroEnc;
395N/A for (int j=-128; j<128; ++j) {
395N/A bytes[0] = (byte)j;
395N/A char euroValue = new String(bytes, euroEnc).charAt(0);
395N/A chars[0] = euroValue;
395N/A // NOTE: 0x15 doesn't round trip on the EBCDIC code pages,
395N/A // so we don't check that code point in the sanity check.
395N/A if (j != 0x0015) {
395N/A int euroRoundTrip = new String(chars).getBytes(euroEnc)[0];
395N/A if (euroRoundTrip != j) {
395N/A pass = false;
395N/A System.out.println("Error: Encoder " + euroEnc +
395N/A " fails round-trip at " + j);
395N/A }
395N/A }
395N/A // Compare against the map
395N/A if (euroValue != map[(j+0x100)&0xFF]) {
395N/A pass = false;
395N/A System.out.println("Error: Encoder " + euroEnc +
395N/A " " + Integer.toHexString((j+0x100)&0xFF) + " -> \\u" +
395N/A Integer.toHexString(euroValue) + ", expected \\u" +
395N/A Integer.toHexString(map[(j+0x100)&0xFF]));
395N/A }
395N/A }
395N/A } catch (UnsupportedEncodingException e) {
395N/A System.out.println("Unsupported encoding " + currentEnc);
395N/A pass = false;
395N/A while (i < DATA.length && DATA[i] != null) ++i;
395N/A ++i; // Skip over null
395N/A }
395N/A }
395N/A if (!pass) {
395N/A throw new RuntimeException("Bug 4114080 - Euro encoder test failed");
395N/A }
395N/A }
395N/A static String[] DATA = {
395N/A // New converter, parent converter, [ code point that changed, parent code point value,
395N/A // euro code point value ], null
395N/A // Any number of changed code points may be specified, including zero.
395N/A "ISO8859_15_FDIS", "ISO8859_1",
395N/A "A4", "\u00A4", "\u20AC",
395N/A "A6", "\u00A6", "\u0160",
395N/A "A8", "\u00A8", "\u0161",
395N/A "B4", "\u00B4", "\u017D",
395N/A "B8", "\u00B8", "\u017E",
395N/A "BC", "\u00BC", "\u0152",
395N/A "BD", "\u00BD", "\u0153",
395N/A "BE", "\u00BE", "\u0178",
395N/A null,
395N/A // 923 is IBM's name for ISO 8859-15; make sure they're identical
395N/A "Cp923", "ISO8859_15_FDIS", null,
395N/A "Cp858", "Cp850", "D5", "\u0131", "\u20AC", null,
395N/A "Cp1140", "Cp037", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1141", "Cp273", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1142", "Cp277", "5A", "\u00A4", "\u20AC", null,
395N/A "Cp1143", "Cp278", "5A", "\u00A4", "\u20AC", null,
395N/A "Cp1144", "Cp280", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1145", "Cp284", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1146", "Cp285", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1147", "Cp297", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1148", "Cp500", "9F", "\u00A4", "\u20AC", null,
395N/A "Cp1149", "Cp871", "9F", "\u00A4", "\u20AC", null,
395N/A };
395N/A}