TestMS5022X.java revision 395:bc9a0bba6e72
1/*
2 * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25   @bug 6173388 6319716
26   @summary Check full coverage encode/decode for Microsoft
27            ISO2022_JP variants MS50220, MS50221 and MSISO2022JP
28 */
29
30import java.io.*;
31import java.nio.charset.*;
32public class TestMS5022X {
33
34    private static String US_ASCII =
35        "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
36        "\b\t\n\u000B\f\r" +
37        "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
38        "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +
39        "\u0020\u0021\"\u0023\u0024\u0025\u0026\'" +
40        "\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F" +
41        "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037" +
42        "\u0038\u0039\u003A\u003B\u003C\u003D\u003E\u003F" +
43        "\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047" +
44        "\u0048\u0049\u004A\u004B\u004C\u004D\u004E\u004F" +
45        "\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057" +
46        "\u0058\u0059\u005A\u005B\\\u005D\u005E\u005F" +
47        "\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067" +
48        "\u0068\u0069\u006A\u006B\u006C\u006D\u006E\u006F" +
49        "\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077" +
50        "\u0078\u0079\u007A\u007B\u007C\u007D\u007E\u00A5\u203E";
51
52     // Subset of chars sourced from JISX0208:1983
53
54     private static String JISX0208SUBSET =
55        "\u3000\u3001\u3002\uFF0C\uFF0E\u30FB\uFF1A" +
56        "\uFF1B\uFF1F\uFF01\u309B\u309C\u00B4\uFF40\u00A8" +
57        "\uFF3E\uFFE3\uFF3F\u30FD\u30FE\u309D\u309E\u3003" +
58        "\u4EDD\u3005\u3006\u3007\u30FC\u2015\u2010\uFF0F" +    //u2014->u2015
59        "\uFF3C\u301C\u2016\uFF5C\u2026\u2025\u2018\u2019" +
60        "\u5C05\u5C07\u5C08\u5C0D\u5C13\u5C20\u5C22\u5C28" +
61        "\u5C38\u5C39\u5C41\u5C46\u5C4E\u5C53\u5C50\u5C4F" +
62        "\u5B71\u5C6C\u5C6E\u4E62\u5C76\u5C79\u5C8C\u5C91" +
63        "\u5C94\u599B\u5CAB\u5CBB\u5CB6\u5CBC\u5CB7\u5CC5" +
64        "\u5CBE\u5CC7\u5CD9\u5CE9\u5CFD\u5CFA\u5CED\u5D8C" +
65        "\u5CEA\u5D0B\u5D15\u5D17\u5D5C\u5D1F\u5D1B\u5D11" +
66        "\u5D14\u5D22\u5D1A\u5D19\u5D18\u5D4C\u5D52\u5D4E" +
67        "\u5D4B\u5D6C\u5D73\u5D76\u5D87\u5D84\u5D82\u5DA2" +
68        "\u5D9D\u5DAC\u5DAE\u5DBD\u5D90\u5DB7\u5DBC\u5DC9" +
69        "\u5DCD\u5DD3\u5DD2\u5DD6\u5DDB\u5DEB\u5DF2\u5DF5" +
70        "\u5E0B\u5E1A\u5E19\u5E11\u5E1B\u5E36\u5E37\u5E44" +
71        "\u5E43\u5E40\u5E4E\u5E57\u5E54\u5E5F\u5E62\u5E64" +
72        "\u5E47\u5E75\u5E76\u5E7A\u9EBC\u5E7F\u5EA0\u5EC1" +
73        "\u5EC2\u5EC8\u5ED0\u5ECF\u5ED6\u5EE3\u5EDD\u5EDA" +
74        "\u5EDB\u5EE2\u5EE1\u5EE8\u5EE9\u5EEC\u5EF1\u5EF3" +
75        "\u5EF0\u5EF4\u5EF8\u5EFE\u5F03\u5F09\u5F5D\u5F5C" +
76        "\u5F0B\u5F11\u5F16\u5F29\u5F2D\u5F38\u5F41\u5F48" +
77        "\u5F4C\u5F4E\u5F2F\u5F51\u5F56\u5F57\u5F59\u5F61" +
78        "\u5F6D\u5F73\u5F77\u5F83\u5F82\u5F7F\u5F8A\u5F88" +
79        "\u5F91\u5F87\u5F9E\u5F99\u5F98\u5FA0\u5FA8\u5FAD" +
80        "\u5FBC\u5FD6\u5FFB\u5FE4\u5FF8\u5FF1\u5FDD\u60B3" +
81        "\u5FFF\u6021\u6060\u6019\u6010\u6029\u600E\u6031" +
82        "\u62EE\u62F1\u6327\u6302\u6308\u62EF\u62F5\u6350" +
83        "\u633E\u634D\u641C\u634F\u6396\u638E\u6380\u63AB" +
84        "\u6376\u63A3\u638F\u6389\u639F\u63B5\u636B\u6369" +
85        "\u63BE\u63E9\u63C0\u63C6\u63E3\u63C9\u63D2\u63F6" +
86        "\u63C4\u6416\u6434\u6406\u6413\u6426\u6436\u651D" +
87        "\u6417\u6428\u640F\u6467\u646F\u6476\u644E\u652A" +
88        "\u6495\u6493\u64A5\u64A9\u6488\u64BC\u64DA\u64D2" +
89        "\u64C5\u64C7\u64BB\u64D8\u64C2\u64F1\u64E7\u8209" +
90        "\u64E0\u64E1\u62AC\u64E3\u64EF\u652C\u64F6\u64F4" +
91        "\u64F2\u64FA\u6500\u64FD\u6518\u651C\u6505\u6524" +
92        "\u6523\u652B\u6534\u6535\u6537\u6536\u6538\u754B" +
93        "\u6741\u6738\u6737\u6746\u675E\u6760\u6759\u6763" +
94        "\u6764\u6789\u6770\u67A9\u677C\u676A\u678C\u678B" +
95        "\u67A6\u67A1\u6785\u67B7\u67EF\u67B4\u67EC\u67B3" +
96        "\u67E9\u67B8\u67E4\u67DE\u67DD\u67E2\u67EE\u67B9" +
97        "\u67CE\u67C6\u67E7\u6A9C\u681E\u6846\u6829\u6840" +
98        "\u684D\u6832\u684E\u68B3\u682B\u6859\u6863\u6877" +
99        "\u687F\u689F\u688F\u68AD\u6894\u689D\u689B\u6883" +
100        "\u6AAE\u68B9\u6874\u68B5\u68A0\u68BA\u690F\u688D" +
101        "\u687E\u6901\u68CA\u6908\u68D8\u6922\u6926\u68E1" +
102        "\u690C\u68CD\u68D4\u68E7\u68D5\u6936\u6912\u6904" +
103        "\u68D7\u68E3\u6925\u68F9\u68E0\u68EF\u6928\u692A" +
104        "\u691A\u6923\u6921\u68C6\u6979\u6977\u695C\u6978" +
105        "\u6CD7\u6CC5\u6CDD\u6CAE\u6CB1\u6CBE\u6CBA\u6CDB" +
106        "\u6CEF\u6CD9\u6CEA\u6D1F\u884D\u6D36\u6D2B\u6D3D" +
107        "\u6D38\u6D19\u6D35\u6D33\u6D12\u6D0C\u6D63\u6D93" +
108        "\u6D64\u6D5A\u6D79\u6D59\u6D8E\u6D95\u6FE4\u6D85" +
109        "\u6DF9\u6E15\u6E0A\u6DB5\u6DC7\u6DE6\u6DB8\u6DC6" +
110        "\u6DEC\u6DDE\u6DCC\u6DE8\u6DD2\u6DC5\u6DFA\u6DD9" +
111        "\u724B\u7258\u7274\u727E\u7282\u7281\u7287\u7292" +
112        "\u7296\u72A2\u72A7\u72B9\u72B2\u72C3\u72C6\u72C4" +
113        "\u9D59\u9D72\u9D89\u9D87\u9DAB\u9D6F\u9D7A\u9D9A" +
114        "\u9DA4\u9DA9\u9DB2\u9DC4\u9DC1\u9DBB\u9DB8\u9DBA" +
115        "\u9DC6\u9DCF\u9DC2\u9DD9\u9DD3\u9DF8\u9DE6\u9DED" +
116        "\u9DEF\u9DFD\u9E1A\u9E1B\u9E1E\u9E75\u9E79\u9E7D" +
117        "\u9E81\u9E88\u9E8B\u9E8C\u9E92\u9E95\u9E91\u9E9D" +
118        "\u9EA5\u9EA9\u9EB8\u9EAA\u9EAD\u9761\u9ECC\u9ECE" +
119        "\u9ECF\u9ED0\u9ED4\u9EDC\u9EDE\u9EDD\u9EE0\u9EE5" +
120        "\u9EE8\u9EEF\u9EF4\u9EF6\u9EF7\u9EF9\u9EFB\u9EFC" +
121        "\u9EFD\u9F07\u9F08\u76B7\u9F15\u9F21\u9F2C\u9F3E" +
122        "\u9F4A\u9F52\u9F54\u9F63\u9F5F\u9F60\u9F61\u9F66" +
123        "\u9F67\u9F6C\u9F6A\u9F77\u9F72\u9F76\u9F95\u9F9C" +
124        "\u9FA0\u582F\u69C7\u9059\u7464\u51DC\u7199";
125
126    private static String JISX0201KATAKANA =
127        "\uFF61\uFF62\uFF63\uFF64" +
128        "\uFF65\uFF66\uFF67\uFF68\uFF69\uFF6A\uFF6B\uFF6C" +
129        "\uFF6D\uFF6E\uFF6F\uFF70\uFF71\uFF72\uFF73\uFF74" +
130        "\uFF75\uFF76\uFF77\uFF78\uFF79\uFF7A\uFF7B\uFF7C" +
131        "\uFF7D\uFF7E\uFF7F\uFF80\uFF81\uFF82\uFF83\uFF84" +
132        "\uFF85\uFF86\uFF87\uFF88\uFF89\uFF8A\uFF8B\uFF8C" +
133        "\uFF8D\uFF8E\uFF8F\uFF90\uFF91\uFF92\uFF93\uFF94" +
134        "\uFF95\uFF96\uFF97\uFF98\uFF99\uFF9A\uFF9B\uFF9C" +
135        "\uFF9D\uFF9E\uFF9F";
136
137    private static String JISX0208NECROW13 =
138        "\u2460\u2461\u2462\u2463\u2464\u2465\u2466\u2467" +
139        "\u2468\u2469\u246A\u246B\u246C\u246D\u246E\u246F" +
140        "\u2470\u2471\u2472\u2473\u2160\u2161\u2162\u2163" +
141        "\u2164\u2165\u2166\u2167\u2168\u2169\u3349\u3314" +
142        "\u3322\u334D\u3318\u3327\u3303\u3336\u3351\u3357" +
143        "\u330D\u3326\u3323\u332B\u334A\u333B\u339C\u339D" +
144        "\u339E\u338E\u338F\u33C4\u33A1\u337B\u301E\u301F" +
145        "\u2116\u33CD\u2121\u32A4\u32A5\u32A6\u32A7\u32A8" +
146        "\u3231\u3232\u3239\u337E\u337D\u337C" +
147        "\u222e\u2211\u221f\u22bf";
148
149    private static byte[] expectedBytes_US_ASCII = {
150        (byte)0x0, (byte)0x1, (byte)0x2, (byte)0x3,
151        (byte)0x4, (byte)0x5, (byte)0x6, (byte)0x7,
152        (byte)0x8, (byte)0x9, (byte)0xa, (byte)0xb,
153        (byte)0xc, (byte)0xd,
154        (byte)0x10, (byte)0x11, (byte)0x12, (byte)0x13,
155        (byte)0x14, (byte)0x15, (byte)0x16, (byte)0x17,
156        (byte)0x18, (byte)0x19, (byte)0x1a,
157        (byte)0x1c, (byte)0x1d, (byte)0x1e, (byte)0x1f,
158        (byte)0x20, (byte)0x21, (byte)0x22, (byte)0x23,
159        (byte)0x24, (byte)0x25, (byte)0x26, (byte)0x27,
160        (byte)0x28, (byte)0x29, (byte)0x2a, (byte)0x2b,
161        (byte)0x2c, (byte)0x2d, (byte)0x2e, (byte)0x2f,
162        (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x33,
163        (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37,
164        (byte)0x38, (byte)0x39, (byte)0x3a, (byte)0x3b,
165        (byte)0x3c, (byte)0x3d, (byte)0x3e, (byte)0x3f,
166        (byte)0x40, (byte)0x41, (byte)0x42, (byte)0x43,
167        (byte)0x44, (byte)0x45, (byte)0x46, (byte)0x47,
168        (byte)0x48, (byte)0x49, (byte)0x4a, (byte)0x4b,
169        (byte)0x4c, (byte)0x4d, (byte)0x4e, (byte)0x4f,
170        (byte)0x50, (byte)0x51, (byte)0x52, (byte)0x53,
171        (byte)0x54, (byte)0x55, (byte)0x56, (byte)0x57,
172        (byte)0x58, (byte)0x59, (byte)0x5a, (byte)0x5b,
173        (byte)0x5c, (byte)0x5d, (byte)0x5e, (byte)0x5f,
174        (byte)0x60, (byte)0x61, (byte)0x62, (byte)0x63,
175        (byte)0x64, (byte)0x65, (byte)0x66, (byte)0x67,
176        (byte)0x68, (byte)0x69, (byte)0x6a, (byte)0x6b,
177        (byte)0x6c, (byte)0x6d, (byte)0x6e, (byte)0x6f,
178        (byte)0x70, (byte)0x71, (byte)0x72, (byte)0x73,
179        (byte)0x74, (byte)0x75, (byte)0x76, (byte)0x77,
180        (byte)0x78, (byte)0x79, (byte)0x7a, (byte)0x7b,
181        (byte)0x7c, (byte)0x7d, (byte)0x7e, (byte)0x1b,
182        (byte)0x28, (byte)0x4a, (byte)0x5c, (byte)0x7e
183    };
184
185    private static byte[] expectedBytes_JISX0208SUBSET =
186    {
187        (byte)0x1b, (byte)0x24, (byte)0x42, (byte)0x21,
188        (byte)0x21, (byte)0x21,
189        (byte)0x22, (byte)0x21, (byte)0x23, (byte)0x21,
190        (byte)0x24, (byte)0x21, (byte)0x25, (byte)0x21,
191        (byte)0x26, (byte)0x21, (byte)0x27, (byte)0x21,
192        (byte)0x28, (byte)0x21, (byte)0x29, (byte)0x21,
193        (byte)0x2a, (byte)0x21, (byte)0x2b, (byte)0x21,
194        (byte)0x2c, (byte)0x21, (byte)0x2d, (byte)0x21,
195        (byte)0x2e, (byte)0x21, (byte)0x2f, (byte)0x21,
196        (byte)0x30, (byte)0x21, (byte)0x31, (byte)0x21,
197        (byte)0x32, (byte)0x21, (byte)0x33, (byte)0x21,
198        (byte)0x34, (byte)0x21, (byte)0x35, (byte)0x21,
199        (byte)0x36, (byte)0x21, (byte)0x37, (byte)0x21,
200        (byte)0x38, (byte)0x21, (byte)0x39, (byte)0x21,
201        (byte)0x3a, (byte)0x21, (byte)0x3b, (byte)0x21,
202        (byte)0x3c, (byte)0x21, (byte)0x3d, (byte)0x21,
203        (byte)0x3e, (byte)0x21, (byte)0x3f, (byte)0x21,
204        (byte)0x40, (byte)0x21, (byte)0x41, (byte)0x21,
205        (byte)0x42, (byte)0x21, (byte)0x43, (byte)0x21,
206        (byte)0x44, (byte)0x21, (byte)0x45, (byte)0x21,
207        (byte)0x46, (byte)0x21, (byte)0x47, (byte)0x55,
208        (byte)0x71, (byte)0x55, (byte)0x72, (byte)0x55,
209        (byte)0x73, (byte)0x55, (byte)0x74, (byte)0x55,
210        (byte)0x75, (byte)0x55, (byte)0x76, (byte)0x55,
211        (byte)0x77, (byte)0x55, (byte)0x78, (byte)0x55,
212        (byte)0x79, (byte)0x55, (byte)0x7a, (byte)0x55,
213        (byte)0x7b, (byte)0x55, (byte)0x7c, (byte)0x55,
214        (byte)0x7d, (byte)0x55, (byte)0x7e, (byte)0x56,
215        (byte)0x21, (byte)0x56, (byte)0x22, (byte)0x56,
216        (byte)0x23, (byte)0x56, (byte)0x24, (byte)0x56,
217        (byte)0x25, (byte)0x56, (byte)0x26, (byte)0x56,
218        (byte)0x27, (byte)0x56, (byte)0x28, (byte)0x56,
219        (byte)0x29, (byte)0x56, (byte)0x2a, (byte)0x56,
220        (byte)0x2b, (byte)0x56, (byte)0x2c, (byte)0x56,
221        (byte)0x2d, (byte)0x56, (byte)0x2e, (byte)0x56,
222        (byte)0x2f, (byte)0x56, (byte)0x30, (byte)0x56,
223        (byte)0x31, (byte)0x56, (byte)0x32, (byte)0x56,
224        (byte)0x33, (byte)0x56, (byte)0x34, (byte)0x56,
225        (byte)0x35, (byte)0x56, (byte)0x36, (byte)0x56,
226        (byte)0x37, (byte)0x56, (byte)0x38, (byte)0x56,
227        (byte)0x39, (byte)0x56, (byte)0x3a, (byte)0x56,
228        (byte)0x3b, (byte)0x56, (byte)0x3c, (byte)0x56,
229        (byte)0x3d, (byte)0x56, (byte)0x3e, (byte)0x56,
230        (byte)0x3f, (byte)0x56, (byte)0x40, (byte)0x56,
231        (byte)0x41, (byte)0x56, (byte)0x42, (byte)0x56,
232        (byte)0x43, (byte)0x56, (byte)0x44, (byte)0x56,
233        (byte)0x45, (byte)0x56, (byte)0x46, (byte)0x56,
234        (byte)0x47, (byte)0x56, (byte)0x48, (byte)0x56,
235        (byte)0x49, (byte)0x56, (byte)0x4a, (byte)0x56,
236        (byte)0x4b, (byte)0x56, (byte)0x4c, (byte)0x56,
237        (byte)0x4d, (byte)0x56, (byte)0x4e, (byte)0x56,
238        (byte)0x4f, (byte)0x56, (byte)0x50, (byte)0x56,
239        (byte)0x51, (byte)0x56, (byte)0x52, (byte)0x56,
240        (byte)0x53, (byte)0x56, (byte)0x54, (byte)0x56,
241        (byte)0x55, (byte)0x56, (byte)0x56, (byte)0x56,
242        (byte)0x57, (byte)0x56, (byte)0x58, (byte)0x56,
243        (byte)0x59, (byte)0x56, (byte)0x5a, (byte)0x56,
244        (byte)0x5b, (byte)0x56, (byte)0x5c, (byte)0x56,
245        (byte)0x5d, (byte)0x56, (byte)0x5e, (byte)0x56,
246        (byte)0x5f, (byte)0x56, (byte)0x60, (byte)0x56,
247        (byte)0x61, (byte)0x56, (byte)0x62, (byte)0x56,
248        (byte)0x63, (byte)0x56, (byte)0x64, (byte)0x56,
249        (byte)0x65, (byte)0x56, (byte)0x66, (byte)0x56,
250        (byte)0x67, (byte)0x56, (byte)0x68, (byte)0x56,
251        (byte)0x69, (byte)0x56, (byte)0x6a, (byte)0x56,
252        (byte)0x6b, (byte)0x56, (byte)0x6c, (byte)0x56,
253        (byte)0x6d, (byte)0x56, (byte)0x6e, (byte)0x56,
254        (byte)0x6f, (byte)0x56, (byte)0x70, (byte)0x56,
255        (byte)0x71, (byte)0x56, (byte)0x72, (byte)0x56,
256        (byte)0x73, (byte)0x56, (byte)0x74, (byte)0x56,
257        (byte)0x75, (byte)0x56, (byte)0x76, (byte)0x56,
258        (byte)0x77, (byte)0x56, (byte)0x78, (byte)0x56,
259        (byte)0x79, (byte)0x56, (byte)0x7a, (byte)0x56,
260        (byte)0x7b, (byte)0x56, (byte)0x7c, (byte)0x56,
261        (byte)0x7d, (byte)0x56, (byte)0x7e, (byte)0x57,
262        (byte)0x21, (byte)0x57, (byte)0x22, (byte)0x57,
263        (byte)0x23, (byte)0x57, (byte)0x24, (byte)0x57,
264        (byte)0x25, (byte)0x57, (byte)0x26, (byte)0x57,
265        (byte)0x27, (byte)0x57, (byte)0x28, (byte)0x57,
266        (byte)0x29, (byte)0x57, (byte)0x2a, (byte)0x57,
267        (byte)0x2b, (byte)0x57, (byte)0x2c, (byte)0x57,
268        (byte)0x2d, (byte)0x57, (byte)0x2e, (byte)0x57,
269        (byte)0x2f, (byte)0x57, (byte)0x30, (byte)0x57,
270        (byte)0x31, (byte)0x57, (byte)0x32, (byte)0x57,
271        (byte)0x33, (byte)0x57, (byte)0x34, (byte)0x57,
272        (byte)0x35, (byte)0x57, (byte)0x36, (byte)0x57,
273        (byte)0x37, (byte)0x57, (byte)0x38, (byte)0x57,
274        (byte)0x39, (byte)0x57, (byte)0x3a, (byte)0x57,
275        (byte)0x3b, (byte)0x57, (byte)0x3c, (byte)0x57,
276        (byte)0x3d, (byte)0x57, (byte)0x3e, (byte)0x57,
277        (byte)0x3f, (byte)0x57, (byte)0x40, (byte)0x57,
278        (byte)0x41, (byte)0x57, (byte)0x42, (byte)0x57,
279        (byte)0x43, (byte)0x57, (byte)0x44, (byte)0x57,
280        (byte)0x45, (byte)0x57, (byte)0x46, (byte)0x57,
281        (byte)0x47, (byte)0x57, (byte)0x48, (byte)0x57,
282        (byte)0x49, (byte)0x57, (byte)0x4a, (byte)0x57,
283        (byte)0x4b, (byte)0x57, (byte)0x4c, (byte)0x57,
284        (byte)0x4d, (byte)0x57, (byte)0x4e, (byte)0x57,
285        (byte)0x4f, (byte)0x57, (byte)0x50, (byte)0x57,
286        (byte)0x51, (byte)0x57, (byte)0x52, (byte)0x57,
287        (byte)0x53, (byte)0x57, (byte)0x54, (byte)0x57,
288        (byte)0x55, (byte)0x57, (byte)0x56, (byte)0x57,
289        (byte)0x57, (byte)0x57, (byte)0x58, (byte)0x57,
290        (byte)0x59, (byte)0x57, (byte)0x5a, (byte)0x57,
291        (byte)0x5b, (byte)0x57, (byte)0x5c, (byte)0x57,
292        (byte)0x5d, (byte)0x57, (byte)0x5e, (byte)0x57,
293        (byte)0x5f, (byte)0x57, (byte)0x60, (byte)0x57,
294        (byte)0x61, (byte)0x57, (byte)0x62, (byte)0x57,
295        (byte)0x63, (byte)0x57, (byte)0x64, (byte)0x59,
296        (byte)0x49, (byte)0x59, (byte)0x4a, (byte)0x59,
297        (byte)0x4b, (byte)0x59, (byte)0x4c, (byte)0x59,
298        (byte)0x4d, (byte)0x59, (byte)0x4e, (byte)0x59,
299        (byte)0x4f, (byte)0x59, (byte)0x50, (byte)0x59,
300        (byte)0x51, (byte)0x59, (byte)0x52, (byte)0x59,
301        (byte)0x53, (byte)0x59, (byte)0x54, (byte)0x59,
302        (byte)0x55, (byte)0x59, (byte)0x56, (byte)0x59,
303        (byte)0x57, (byte)0x59, (byte)0x58, (byte)0x59,
304        (byte)0x59, (byte)0x59, (byte)0x5a, (byte)0x59,
305        (byte)0x5b, (byte)0x59, (byte)0x5c, (byte)0x59,
306        (byte)0x5d, (byte)0x59, (byte)0x5e, (byte)0x59,
307        (byte)0x5f, (byte)0x59, (byte)0x60, (byte)0x59,
308        (byte)0x61, (byte)0x59, (byte)0x62, (byte)0x59,
309        (byte)0x63, (byte)0x59, (byte)0x64, (byte)0x59,
310        (byte)0x65, (byte)0x59, (byte)0x66, (byte)0x59,
311        (byte)0x67, (byte)0x59, (byte)0x68, (byte)0x59,
312        (byte)0x69, (byte)0x59, (byte)0x6a, (byte)0x59,
313        (byte)0x6b, (byte)0x59, (byte)0x6c, (byte)0x59,
314        (byte)0x6d, (byte)0x59, (byte)0x6e, (byte)0x59,
315        (byte)0x6f, (byte)0x59, (byte)0x70, (byte)0x59,
316        (byte)0x71, (byte)0x59, (byte)0x72, (byte)0x59,
317        (byte)0x73, (byte)0x59, (byte)0x74, (byte)0x59,
318        (byte)0x75, (byte)0x59, (byte)0x76, (byte)0x59,
319        (byte)0x77, (byte)0x59, (byte)0x78, (byte)0x59,
320        (byte)0x79, (byte)0x59, (byte)0x7a, (byte)0x59,
321        (byte)0x7b, (byte)0x59, (byte)0x7c, (byte)0x59,
322        (byte)0x7d, (byte)0x59, (byte)0x7e, (byte)0x5a,
323        (byte)0x21, (byte)0x5a, (byte)0x22, (byte)0x5a,
324        (byte)0x23, (byte)0x5a, (byte)0x24, (byte)0x5a,
325        (byte)0x25, (byte)0x5a, (byte)0x26, (byte)0x5a,
326        (byte)0x27, (byte)0x5a, (byte)0x28, (byte)0x5a,
327        (byte)0x29, (byte)0x5a, (byte)0x2a, (byte)0x5a,
328        (byte)0x2b, (byte)0x5a, (byte)0x2c, (byte)0x5a,
329        (byte)0x2d, (byte)0x5a, (byte)0x2e, (byte)0x5a,
330        (byte)0x2f, (byte)0x5a, (byte)0x30, (byte)0x5a,
331        (byte)0x31, (byte)0x5a, (byte)0x32, (byte)0x5a,
332        (byte)0x33, (byte)0x5a, (byte)0x34, (byte)0x5a,
333        (byte)0x35, (byte)0x5a, (byte)0x36, (byte)0x5a,
334        (byte)0x37, (byte)0x5a, (byte)0x38, (byte)0x5a,
335        (byte)0x39, (byte)0x5a, (byte)0x3a, (byte)0x5a,
336        (byte)0x3b, (byte)0x5a, (byte)0x3c, (byte)0x5a,
337        (byte)0x3d, (byte)0x5a, (byte)0x3e, (byte)0x5a,
338        (byte)0x3f, (byte)0x5a, (byte)0x40, (byte)0x5a,
339        (byte)0x41, (byte)0x5a, (byte)0x42, (byte)0x5b,
340        (byte)0x35, (byte)0x5b, (byte)0x36, (byte)0x5b,
341        (byte)0x37, (byte)0x5b, (byte)0x38, (byte)0x5b,
342        (byte)0x39, (byte)0x5b, (byte)0x3a, (byte)0x5b,
343        (byte)0x3b, (byte)0x5b, (byte)0x3c, (byte)0x5b,
344        (byte)0x3d, (byte)0x5b, (byte)0x3e, (byte)0x5b,
345        (byte)0x3f, (byte)0x5b, (byte)0x40, (byte)0x5b,
346        (byte)0x41, (byte)0x5b, (byte)0x42, (byte)0x5b,
347        (byte)0x43, (byte)0x5b, (byte)0x44, (byte)0x5b,
348        (byte)0x45, (byte)0x5b, (byte)0x46, (byte)0x5b,
349        (byte)0x47, (byte)0x5b, (byte)0x48, (byte)0x5b,
350        (byte)0x49, (byte)0x5b, (byte)0x4a, (byte)0x5b,
351        (byte)0x4b, (byte)0x5b, (byte)0x4c, (byte)0x5b,
352        (byte)0x4d, (byte)0x5b, (byte)0x4e, (byte)0x5b,
353        (byte)0x4f, (byte)0x5b, (byte)0x50, (byte)0x5b,
354        (byte)0x51, (byte)0x5b, (byte)0x52, (byte)0x5b,
355        (byte)0x53, (byte)0x5b, (byte)0x54, (byte)0x5b,
356        (byte)0x55, (byte)0x5b, (byte)0x56, (byte)0x5b,
357        (byte)0x57, (byte)0x5b, (byte)0x58, (byte)0x5b,
358        (byte)0x59, (byte)0x5b, (byte)0x5a, (byte)0x5b,
359        (byte)0x5b, (byte)0x5b, (byte)0x5c, (byte)0x5b,
360        (byte)0x5d, (byte)0x5b, (byte)0x5e, (byte)0x5b,
361        (byte)0x5f, (byte)0x5b, (byte)0x60, (byte)0x5b,
362        (byte)0x61, (byte)0x5b, (byte)0x62, (byte)0x5b,
363        (byte)0x63, (byte)0x5b, (byte)0x64, (byte)0x5b,
364        (byte)0x65, (byte)0x5b, (byte)0x66, (byte)0x5b,
365        (byte)0x67, (byte)0x5b, (byte)0x68, (byte)0x5b,
366        (byte)0x69, (byte)0x5b, (byte)0x6a, (byte)0x5b,
367        (byte)0x6b, (byte)0x5b, (byte)0x6c, (byte)0x5b,
368        (byte)0x6d, (byte)0x5b, (byte)0x6e, (byte)0x5b,
369        (byte)0x6f, (byte)0x5b, (byte)0x70, (byte)0x5b,
370        (byte)0x71, (byte)0x5b, (byte)0x72, (byte)0x5b,
371        (byte)0x73, (byte)0x5b, (byte)0x74, (byte)0x5b,
372        (byte)0x75, (byte)0x5b, (byte)0x76, (byte)0x5b,
373        (byte)0x77, (byte)0x5b, (byte)0x78, (byte)0x5b,
374        (byte)0x79, (byte)0x5b, (byte)0x7a, (byte)0x5b,
375        (byte)0x7b, (byte)0x5b, (byte)0x7c, (byte)0x5b,
376        (byte)0x7d, (byte)0x5b, (byte)0x7e, (byte)0x5c,
377        (byte)0x21, (byte)0x5c, (byte)0x22, (byte)0x5c,
378        (byte)0x23, (byte)0x5c, (byte)0x24, (byte)0x5c,
379        (byte)0x25, (byte)0x5c, (byte)0x26, (byte)0x5c,
380        (byte)0x27, (byte)0x5c, (byte)0x28, (byte)0x5c,
381        (byte)0x29, (byte)0x5c, (byte)0x2a, (byte)0x5c,
382        (byte)0x2b, (byte)0x5c, (byte)0x2c, (byte)0x5c,
383        (byte)0x2d, (byte)0x5c, (byte)0x2e, (byte)0x5c,
384        (byte)0x2f, (byte)0x5c, (byte)0x30, (byte)0x5c,
385        (byte)0x31, (byte)0x5c, (byte)0x32, (byte)0x5c,
386        (byte)0x33, (byte)0x5c, (byte)0x34, (byte)0x5c,
387        (byte)0x35, (byte)0x5c, (byte)0x36, (byte)0x5d,
388        (byte)0x79, (byte)0x5d, (byte)0x7a, (byte)0x5d,
389        (byte)0x7b, (byte)0x5d, (byte)0x7c, (byte)0x5d,
390        (byte)0x7d, (byte)0x5d, (byte)0x7e, (byte)0x5e,
391        (byte)0x21, (byte)0x5e, (byte)0x22, (byte)0x5e,
392        (byte)0x23, (byte)0x5e, (byte)0x24, (byte)0x5e,
393        (byte)0x25, (byte)0x5e, (byte)0x26, (byte)0x5e,
394        (byte)0x27, (byte)0x5e, (byte)0x28, (byte)0x5e,
395        (byte)0x29, (byte)0x5e, (byte)0x2a, (byte)0x5e,
396        (byte)0x2b, (byte)0x5e, (byte)0x2c, (byte)0x5e,
397        (byte)0x2d, (byte)0x5e, (byte)0x2e, (byte)0x5e,
398        (byte)0x2f, (byte)0x5e, (byte)0x30, (byte)0x5e,
399        (byte)0x31, (byte)0x5e, (byte)0x32, (byte)0x5e,
400        (byte)0x33, (byte)0x5e, (byte)0x34, (byte)0x5e,
401        (byte)0x35, (byte)0x5e, (byte)0x36, (byte)0x5e,
402        (byte)0x37, (byte)0x5e, (byte)0x38, (byte)0x5e,
403        (byte)0x39, (byte)0x5e, (byte)0x3a, (byte)0x5e,
404        (byte)0x3b, (byte)0x5e, (byte)0x3c, (byte)0x5e,
405        (byte)0x3d, (byte)0x5e, (byte)0x3e, (byte)0x5e,
406        (byte)0x3f, (byte)0x5e, (byte)0x40, (byte)0x5e,
407        (byte)0x41, (byte)0x5e, (byte)0x42, (byte)0x5e,
408        (byte)0x43, (byte)0x5e, (byte)0x44, (byte)0x5e,
409        (byte)0x45, (byte)0x5e, (byte)0x46, (byte)0x5e,
410        (byte)0x47, (byte)0x5e, (byte)0x48, (byte)0x5e,
411        (byte)0x49, (byte)0x5e, (byte)0x4a, (byte)0x60,
412        (byte)0x30, (byte)0x60, (byte)0x31, (byte)0x60,
413        (byte)0x32, (byte)0x60, (byte)0x33, (byte)0x60,
414        (byte)0x34, (byte)0x60, (byte)0x35, (byte)0x60,
415        (byte)0x36, (byte)0x60, (byte)0x37, (byte)0x60,
416        (byte)0x38, (byte)0x60, (byte)0x39, (byte)0x60,
417        (byte)0x3a, (byte)0x60, (byte)0x3b, (byte)0x60,
418        (byte)0x3c, (byte)0x60, (byte)0x3d, (byte)0x60,
419        (byte)0x3e, (byte)0x60, (byte)0x3f, (byte)0x73,
420        (byte)0x26, (byte)0x73, (byte)0x27, (byte)0x73,
421        (byte)0x28, (byte)0x73, (byte)0x29, (byte)0x73,
422        (byte)0x2a, (byte)0x73, (byte)0x2b, (byte)0x73,
423        (byte)0x2c, (byte)0x73, (byte)0x2d, (byte)0x73,
424        (byte)0x2e, (byte)0x73, (byte)0x2f, (byte)0x73,
425        (byte)0x30, (byte)0x73, (byte)0x31, (byte)0x73,
426        (byte)0x32, (byte)0x73, (byte)0x33, (byte)0x73,
427        (byte)0x34, (byte)0x73, (byte)0x35, (byte)0x73,
428        (byte)0x36, (byte)0x73, (byte)0x37, (byte)0x73,
429        (byte)0x38, (byte)0x73, (byte)0x39, (byte)0x73,
430        (byte)0x3a, (byte)0x73, (byte)0x3b, (byte)0x73,
431        (byte)0x3c, (byte)0x73, (byte)0x3d, (byte)0x73,
432        (byte)0x3e, (byte)0x73, (byte)0x3f, (byte)0x73,
433        (byte)0x40, (byte)0x73, (byte)0x41, (byte)0x73,
434        (byte)0x42, (byte)0x73, (byte)0x43, (byte)0x73,
435        (byte)0x44, (byte)0x73, (byte)0x45, (byte)0x73,
436        (byte)0x46, (byte)0x73, (byte)0x47, (byte)0x73,
437        (byte)0x48, (byte)0x73, (byte)0x49, (byte)0x73,
438        (byte)0x4a, (byte)0x73, (byte)0x4b, (byte)0x73,
439        (byte)0x4c, (byte)0x73, (byte)0x4d, (byte)0x73,
440        (byte)0x4e, (byte)0x73, (byte)0x4f, (byte)0x73,
441        (byte)0x50, (byte)0x73, (byte)0x51, (byte)0x73,
442        (byte)0x52, (byte)0x73, (byte)0x53, (byte)0x73,
443        (byte)0x54, (byte)0x73, (byte)0x55, (byte)0x73,
444        (byte)0x56, (byte)0x73, (byte)0x57, (byte)0x73,
445        (byte)0x58, (byte)0x73, (byte)0x59, (byte)0x73,
446        (byte)0x5a, (byte)0x73, (byte)0x5b, (byte)0x73,
447        (byte)0x5c, (byte)0x73, (byte)0x5d, (byte)0x73,
448        (byte)0x5e, (byte)0x73, (byte)0x5f, (byte)0x73,
449        (byte)0x60, (byte)0x73, (byte)0x61, (byte)0x73,
450        (byte)0x62, (byte)0x73, (byte)0x63, (byte)0x73,
451        (byte)0x64, (byte)0x73, (byte)0x65, (byte)0x73,
452        (byte)0x66, (byte)0x73, (byte)0x67, (byte)0x73,
453        (byte)0x68, (byte)0x73, (byte)0x69, (byte)0x73,
454        (byte)0x6a, (byte)0x73, (byte)0x6b, (byte)0x73,
455        (byte)0x6c, (byte)0x73, (byte)0x6d, (byte)0x73,
456        (byte)0x6e, (byte)0x73, (byte)0x6f, (byte)0x73,
457        (byte)0x70, (byte)0x73, (byte)0x71, (byte)0x73,
458        (byte)0x72, (byte)0x73, (byte)0x73, (byte)0x73,
459        (byte)0x74, (byte)0x73, (byte)0x75, (byte)0x73,
460        (byte)0x76, (byte)0x73, (byte)0x77, (byte)0x73,
461        (byte)0x78, (byte)0x73, (byte)0x79, (byte)0x73,
462        (byte)0x7a, (byte)0x73, (byte)0x7b, (byte)0x73,
463        (byte)0x7c, (byte)0x73, (byte)0x7d, (byte)0x73,
464        (byte)0x7e, (byte)0x74, (byte)0x21, (byte)0x74,
465        (byte)0x22, (byte)0x74, (byte)0x23, (byte)0x74,
466        (byte)0x24, (byte)0x74, (byte)0x25, (byte)0x74,
467        (byte)0x26
468    };
469
470    private static byte[] expectedBytes_JISX0201KATAKANA1 =
471    {
472        (byte)0x1b, (byte)0x28, (byte)0x49,
473        (byte)0x21, (byte)0x22, (byte)0x23, (byte)0x24,
474        (byte)0x25, (byte)0x26, (byte)0x27, (byte)0x28,
475        (byte)0x29, (byte)0x2a, (byte)0x2b, (byte)0x2c,
476        (byte)0x2d, (byte)0x2e, (byte)0x2f, (byte)0x30,
477        (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34,
478        (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38,
479        (byte)0x39, (byte)0x3a, (byte)0x3b, (byte)0x3c,
480        (byte)0x3d, (byte)0x3e, (byte)0x3f, (byte)0x40,
481        (byte)0x41, (byte)0x42, (byte)0x43, (byte)0x44,
482        (byte)0x45, (byte)0x46, (byte)0x47, (byte)0x48,
483        (byte)0x49, (byte)0x4a, (byte)0x4b, (byte)0x4c,
484        (byte)0x4d, (byte)0x4e, (byte)0x4f, (byte)0x50,
485        (byte)0x51, (byte)0x52, (byte)0x53, (byte)0x54,
486        (byte)0x55, (byte)0x56, (byte)0x57, (byte)0x58,
487        (byte)0x59, (byte)0x5a, (byte)0x5b, (byte)0x5c,
488        (byte)0x5d, (byte)0x5e, (byte)0x5f
489    };
490
491    private static byte[] expectedBytes_JISX0201KATAKANA2 =
492    {
493        (byte)0x1b, (byte)0x24, (byte)0x42,
494        (byte)0x21, (byte)0x23, (byte)0x21, (byte)0x56,
495        (byte)0x21, (byte)0x57, (byte)0x21, (byte)0x22,
496        (byte)0x21, (byte)0x26, (byte)0x25, (byte)0x72,
497        (byte)0x25, (byte)0x21, (byte)0x25, (byte)0x23,
498        (byte)0x25, (byte)0x25, (byte)0x25, (byte)0x27,
499        (byte)0x25, (byte)0x29, (byte)0x25, (byte)0x63,
500        (byte)0x25, (byte)0x65, (byte)0x25, (byte)0x67,
501        (byte)0x25, (byte)0x43, (byte)0x21, (byte)0x3c,
502        (byte)0x25, (byte)0x22, (byte)0x25, (byte)0x24,
503        (byte)0x25, (byte)0x26, (byte)0x25, (byte)0x28,
504        (byte)0x25, (byte)0x2a, (byte)0x25, (byte)0x2b,
505        (byte)0x25, (byte)0x2d, (byte)0x25, (byte)0x2f,
506        (byte)0x25, (byte)0x31, (byte)0x25, (byte)0x33,
507        (byte)0x25, (byte)0x35, (byte)0x25, (byte)0x37,
508        (byte)0x25, (byte)0x39, (byte)0x25, (byte)0x3b,
509        (byte)0x25, (byte)0x3d, (byte)0x25, (byte)0x3f,
510        (byte)0x25, (byte)0x41, (byte)0x25, (byte)0x44,
511        (byte)0x25, (byte)0x46, (byte)0x25, (byte)0x48,
512        (byte)0x25, (byte)0x4a, (byte)0x25, (byte)0x4b,
513        (byte)0x25, (byte)0x4c, (byte)0x25, (byte)0x4d,
514        (byte)0x25, (byte)0x4e, (byte)0x25, (byte)0x4f,
515        (byte)0x25, (byte)0x52, (byte)0x25, (byte)0x55,
516        (byte)0x25, (byte)0x58, (byte)0x25, (byte)0x5b,
517        (byte)0x25, (byte)0x5e, (byte)0x25, (byte)0x5f,
518        (byte)0x25, (byte)0x60, (byte)0x25, (byte)0x61,
519        (byte)0x25, (byte)0x62, (byte)0x25, (byte)0x64,
520        (byte)0x25, (byte)0x66, (byte)0x25, (byte)0x68,
521        (byte)0x25, (byte)0x69, (byte)0x25, (byte)0x6a,
522        (byte)0x25, (byte)0x6b, (byte)0x25, (byte)0x6c,
523        (byte)0x25, (byte)0x6d, (byte)0x25, (byte)0x6f,
524        (byte)0x25, (byte)0x73, (byte)0x21, (byte)0x2b,
525        (byte)0x21, (byte)0x2c,
526        (byte)0x1b, (byte)0x28, (byte)0x42
527    };
528
529    private static byte[] expectedBytes_JISX0208NECROW13 =
530    {
531        (byte)0x1b, (byte)0x24, (byte)0x42,
532        (byte)0x2d, (byte)0x21, (byte)0x2d, (byte)0x22,
533        (byte)0x2d, (byte)0x23, (byte)0x2d, (byte)0x24,
534        (byte)0x2d, (byte)0x25, (byte)0x2d, (byte)0x26,
535        (byte)0x2d, (byte)0x27, (byte)0x2d, (byte)0x28,
536        (byte)0x2d, (byte)0x29, (byte)0x2d, (byte)0x2a,
537        (byte)0x2d, (byte)0x2b, (byte)0x2d, (byte)0x2c,
538        (byte)0x2d, (byte)0x2d, (byte)0x2d, (byte)0x2e,
539        (byte)0x2d, (byte)0x2f, (byte)0x2d, (byte)0x30,
540        (byte)0x2d, (byte)0x31, (byte)0x2d, (byte)0x32,
541        (byte)0x2d, (byte)0x33, (byte)0x2d, (byte)0x34,
542        (byte)0x2d, (byte)0x35, (byte)0x2d, (byte)0x36,
543        (byte)0x2d, (byte)0x37, (byte)0x2d, (byte)0x38,
544        (byte)0x2d, (byte)0x39, (byte)0x2d, (byte)0x3a,
545        (byte)0x2d, (byte)0x3b, (byte)0x2d, (byte)0x3c,
546        (byte)0x2d, (byte)0x3d, (byte)0x2d, (byte)0x3e,
547        (byte)0x2d, (byte)0x40, (byte)0x2d, (byte)0x41,
548        (byte)0x2d, (byte)0x42, (byte)0x2d, (byte)0x43,
549        (byte)0x2d, (byte)0x44, (byte)0x2d, (byte)0x45,
550        (byte)0x2d, (byte)0x46, (byte)0x2d, (byte)0x47,
551        (byte)0x2d, (byte)0x48, (byte)0x2d, (byte)0x49,
552        (byte)0x2d, (byte)0x4a, (byte)0x2d, (byte)0x4b,
553        (byte)0x2d, (byte)0x4c, (byte)0x2d, (byte)0x4d,
554        (byte)0x2d, (byte)0x4e, (byte)0x2d, (byte)0x4f,
555        (byte)0x2d, (byte)0x50, (byte)0x2d, (byte)0x51,
556        (byte)0x2d, (byte)0x52, (byte)0x2d, (byte)0x53,
557        (byte)0x2d, (byte)0x54, (byte)0x2d, (byte)0x55,
558        (byte)0x2d, (byte)0x56, (byte)0x2d, (byte)0x5f,
559        (byte)0x2d, (byte)0x60, (byte)0x2d, (byte)0x61,
560        (byte)0x2d, (byte)0x62, (byte)0x2d, (byte)0x63,
561        (byte)0x2d, (byte)0x64, (byte)0x2d, (byte)0x65,
562        (byte)0x2d, (byte)0x66, (byte)0x2d, (byte)0x67,
563        (byte)0x2d, (byte)0x68, (byte)0x2d, (byte)0x69,
564        (byte)0x2d, (byte)0x6a, (byte)0x2d, (byte)0x6b,
565        (byte)0x2d, (byte)0x6c, (byte)0x2d, (byte)0x6d,
566        (byte)0x2d, (byte)0x6e, (byte)0x2d, (byte)0x6f,
567        (byte)0x2d, (byte)0x73, (byte)0x2d, (byte)0x74,
568        (byte)0x2d, (byte)0x78, (byte)0x2d, (byte)0x79,
569        (byte)0x1b, (byte)0x28, (byte)0x42
570    };
571
572
573    private static String MIXEDCONTENT =
574        "JA\u3000\u3002\u0062\uFF64PAN" +
575        "\uFF0C\uFF0E\u00A5\uFF65\uFF66X\u203E" +
576        "\u30FB\uFF67\u203E";
577
578    static byte[] mixedBytesExpected = {
579        (byte)0x4a, (byte)0x41, (byte)0x1b, (byte)0x24,
580        (byte)0x42, (byte)0x21, (byte)0x21, (byte)0x21,
581        (byte)0x23, (byte)0x1b, (byte)0x28, (byte)0x42,
582        (byte)0x62, (byte)0x1b, (byte)0x28, (byte)0x49,
583        (byte)0x24, (byte)0x1b, (byte)0x28, (byte)0x42,
584        (byte)0x50, (byte)0x41, (byte)0x4e, (byte)0x1b,
585        (byte)0x24, (byte)0x42, (byte)0x21, (byte)0x24,
586        (byte)0x21, (byte)0x25, (byte)0x1b, (byte)0x28,
587        (byte)0x4a, (byte)0x5c, (byte)0x1b, (byte)0x28,
588        (byte)0x49, (byte)0x25, (byte)0x26, (byte)0x1b,
589        (byte)0x28, (byte)0x42, (byte)0x58, (byte)0x1b,
590        (byte)0x28, (byte)0x4a, (byte)0x7e, (byte)0x1b,
591        (byte)0x24, (byte)0x42, (byte)0x21, (byte)0x26,
592        (byte)0x1b, (byte)0x28, (byte)0x49, (byte)0x27,
593        (byte)0x1b, (byte)0x28, (byte)0x4a, (byte)0x7e,
594        (byte)0x1b, (byte)0x28, (byte)0x42  };
595
596    private static byte[] repeatingEscapes = {
597        (byte)0x4a, (byte)0x41, (byte)0x1b, (byte)0x24,
598        (byte)0x42, (byte)0x1b, (byte)0x24, (byte)0x42,
599        (byte)0x21, (byte)0x21, (byte)0x21,
600        (byte)0x23, (byte)0x1b, (byte)0x28, (byte)0x42,
601        // embedded repeated iso-2022 escapes (see bugID 4879522)
602        (byte)0x1b, (byte)0x28, (byte)0x42,
603        (byte)0x62, (byte)0x1b, (byte)0x28, (byte)0x49,
604        (byte)0x0f, (byte)0x0e, (byte)0x0f,
605        (byte)0x1b, (byte)0x28, (byte)0x49,
606        (byte)0x24, (byte)0x1b, (byte)0x28, (byte)0x42,
607        (byte)0x50, (byte)0x41, (byte)0x4e,
608        // embedded shift chars (see bugID 4879522)
609        (byte)0x0e, (byte)0x0f,
610        (byte)0x1b,
611        (byte)0x24, (byte)0x42, (byte)0x21, (byte)0x24,
612        (byte)0x21, (byte)0x25, (byte)0x1b, (byte)0x28,
613        (byte)0x4a, (byte)0x5c, (byte)0x1b, (byte)0x28,
614        (byte)0x49, (byte)0x25, (byte)0x26, (byte)0x1b,
615        (byte)0x28, (byte)0x42, (byte)0x58, (byte)0x1b,
616        (byte)0x28, (byte)0x4a, (byte)0x7e, (byte)0x1b,
617        (byte)0x24, (byte)0x42, (byte)0x21, (byte)0x26,
618        (byte)0x1b, (byte)0x28, (byte)0x49, (byte)0x27,
619        (byte)0x1b, (byte)0x28, (byte)0x4a, (byte)0x7e,
620        (byte)0x1b, (byte)0x28, (byte)0x42  };
621
622    private static String JISX0212 =
623        "\u02d8\u6896\ue757";
624
625    private static byte[] expectedBytes_JISX0212 = {
626        (byte)0x1b, (byte)0x24, (byte)0x28, (byte)0x44,
627        (byte)0x22, (byte)0x2f, (byte)0x43, (byte)0x6f,
628        (byte)0x7e, (byte)0x7e,
629        (byte)0x1b, (byte)0x28, (byte)0x42
630    };
631
632    /*
633     * Tests the roundtrip integrity and expected encoding
634     * correctness for a String containing a substantial
635     * subset of MS5022X encodeable chars
636     */
637
638    private static void roundTrip(String name,
639                                  String testStr,
640                                  byte[] expectBytes)
641    throws Exception {
642        byte[] encodedBytes = testStr.getBytes(name);
643        if (encodedBytes.length != expectBytes.length) {
644            //System.out.printf("l1=%d, l2=%d\n",
645            //                  encodedBytes.length,expectBytes.length);
646            throw new Exception(name + " Encoder error");
647        }
648        for (int i = 0; i < expectBytes.length; i++) {
649
650            if (encodedBytes[i] != expectBytes[i])  {
651                //System.out.printf("--->");
652                //throw new Exception(name + " Encoder error");
653            }
654            //System.out.printf("%x, %x\n",
655            //encodedBytes[i],expectBytes[i]);
656        }
657        String decoded = new String(encodedBytes, name);
658        if (!decoded.equals(testStr)) {
659            throw new Exception(name + " Decoder error");
660        }
661        String decoded2 = new String(repeatingEscapes, name);
662        if (!decoded2.equals(MIXEDCONTENT)) {
663            throw new Exception(name + " Decoder error");
664        }
665     }
666
667    public static void main(String[] args) throws Exception {
668        String map = System.getProperty("sun.nio.cs.map");
669        if (map != null) {
670            map = map.toLowerCase(java.util.Locale.US);
671            Charset cs = Charset.forName("ISO-2022-JP");
672            if (map.indexOf("x-windows-50221/ISO-2022-jp") != -1 &&
673                !"x-windows-50220".equals(cs.name()) ||
674                map.indexOf("x-windows-50220/ISO-2022-jp") != -1 &&
675                !"x-windows-50220".equals(cs.name()) ||
676                map.indexOf("x-windows-iso2022jp/ISO-2022-jp") != -1 &&
677                !"x-windows-iso2022jp".equals(cs.name())) {
678                throw new Exception("Error: sun.nio.cs.map=" + map +
679                                    ", ISO-2022-JP=" + cs.name());
680            } else {
681                System.out.printf("ISO-2022-JP=%s\n", cs.name());
682            }
683        }
684
685        String testStr = US_ASCII +
686                         JISX0208SUBSET +
687                         JISX0201KATAKANA +
688                         JISX0208NECROW13;
689
690        byte[] expectedBytes= (new String(expectedBytes_US_ASCII, "ASCII") +
691                               new String(expectedBytes_JISX0208SUBSET, "ASCII") +
692                               new String(expectedBytes_JISX0201KATAKANA1, "ASCII") +
693                               new String(expectedBytes_JISX0208NECROW13, "ASCII")).
694          getBytes("ASCII");
695
696        //MS50221
697        roundTrip("MS50221", testStr, expectedBytes);
698        roundTrip("MS50221", JISX0212, expectedBytes_JISX0212);
699
700        //MS50220 without halfwidth kana
701        roundTrip("MS50220",
702                  US_ASCII + JISX0208SUBSET + JISX0208NECROW13,
703                  (new String(expectedBytes_US_ASCII, "ASCII") +
704                   new String(expectedBytes_JISX0208SUBSET, "ASCII") +
705                   new String(expectedBytes_JISX0208NECROW13,
706                              3,
707                              expectedBytes_JISX0208NECROW13.length - 3,
708                              "ASCII")).getBytes("ASCII"));
709        roundTrip("MS50220", JISX0212, expectedBytes_JISX0212);
710
711        // Try MS50220 with halfwidth kana encoding
712        byte[] encodedBytes = JISX0201KATAKANA.getBytes("MS50220");
713        if (encodedBytes.length != expectedBytes_JISX0201KATAKANA2.length) {
714            throw new Exception("MS50220 Encoder error");
715        }
716        for (int i = 0; i < expectedBytes_JISX0201KATAKANA2.length; i++) {
717            if (encodedBytes[i] != expectedBytes_JISX0201KATAKANA2[i])  {
718                throw new Exception("MS50220 Encoder error");
719            }
720        }
721
722        //x-windows-iso2022jp
723        testStr = testStr.replace('\u301E', '\u301D')
724                         .replace('\u301C', '\uFF4E')
725                         .replace('\u2016', '\u2225');
726        roundTrip("x-windows-iso2022jp",
727                  testStr,
728                  expectedBytes);
729
730        testStr = MIXEDCONTENT;
731        roundTrip("MS50221", testStr , mixedBytesExpected);
732
733        // Test for bugID 4913711
734        // ISO-2022-JP encoding of a single input char yields
735        // 8 output bytes. Prior to fix for 4913711 the
736        // max bytes per char value was underspecified as 5.0
737        // and the code below would have thrown a BufferOverflow
738        // exception. This test validates the fix for 4913711
739
740        testStr = "\u3042";
741        byte[] expected = { (byte)0x1b, (byte)0x24, (byte)0x42,
742                            (byte)0x24, (byte)0x22, (byte)0x1b,
743                            (byte)0x28, (byte)0x42 };
744        byte[] encoded = testStr.getBytes("MS50221");
745        for (int i = 0; i < expected.length; i++) {
746            if (encoded[i] != expected[i])
747               throw new Exception("MS50221 Decoder error");
748        }
749    }
750}
751