1/*
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/* @test
25   @bug 4658679 4879644
26   @summary Checks replacement logic within EUC-TW decoder
27*/
28
29/*
30 * Tests goodness of fix for bugID 4658679: EUC-TW decoder should
31 * perform replacement when it encounters latin chars outside the
32 * normal US-ASCII range. For example: Isolated occurrences of
33 * French accented chars. See bugID: 4658679.
34 */
35import java.io.*;
36public class LatinCharReplacementTWTest {
37    public static void  main(String[] args) throws Exception {
38        final String bugID = "4658679";
39        // Attempt to decode
40        byte[] input = { (byte)0xa1,
41                         (byte)0xf0,
42                         (byte)'r',
43                         (byte)'e',
44                         (byte)'s',
45                         (byte)0xe9,  // illegal within EUC-TW
46                         (byte)'r',
47                         (byte)'v',
48                         (byte)0xe9,  // illegal within EUC-TW
49                         (byte)'s',
50                         (byte)0xa2,
51                         (byte)0xf8
52                       };
53
54        char[] expected = { (char) 0xa7,
55                         (char) 'r',
56                         (char) 'e',
57                         (char) 's',
58                         (char) 0xFFFD,  // replacement for accented lowercase e
59                         (char) 'r',
60                         (char) 'v',
61                         (char) 0xFFFD,  // replacement for accented lowercase e
62                         (char) 's',
63                         (char) 0xb0 };
64
65        ByteArrayInputStream bais = new ByteArrayInputStream(input);
66        InputStreamReader isr = new InputStreamReader(bais, "x-EUC-TW");
67
68        char[] decoded = new char[128];
69        int numChars = isr.read(decoded);
70
71        if (numChars != expected.length) {
72            throw new Exception("failure of test for bug " + bugID);
73        }
74
75        for (int i = 0 ; i < numChars; i++) {
76           if (decoded[i] != expected[i])
77                throw new Exception("failure of test for bug " + bugID);
78        }
79    }
80}
81