796
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
796
|
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 |
*
|
5506
|
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.
|
796
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
@bug 4328178
|
|
26 |
@summary Performs baseline and regression test on the ISCII91 charset
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.io.*;
|
|
30 |
|
|
31 |
public class ISCIITest {
|
|
32 |
|
|
33 |
private static void failureReport() {
|
|
34 |
System.err.println ("Failed ISCII91 Regression Test");
|
|
35 |
}
|
|
36 |
|
|
37 |
private static void mapEquiv(int start,
|
|
38 |
int end,
|
|
39 |
String testName)
|
|
40 |
throws Exception
|
|
41 |
{
|
|
42 |
byte[] singleByte = new byte[1];
|
|
43 |
byte[] encoded = new byte[1];
|
|
44 |
|
|
45 |
for (int i = start; i <= end; i++ ) {
|
|
46 |
singleByte[0] = (byte) i;
|
|
47 |
try {
|
|
48 |
String unicodeStr =
|
|
49 |
new String (singleByte,"ISCII91");
|
|
50 |
|
|
51 |
if (i != (int)unicodeStr.charAt(0)) {
|
|
52 |
System.err.println ("FAILED ISCII91 Regression test"
|
|
53 |
+ "input byte is " + i );
|
|
54 |
throw new Exception("");
|
|
55 |
}
|
|
56 |
encoded = unicodeStr.getBytes("ISCII91");
|
|
57 |
|
|
58 |
if (encoded[0] != singleByte[0]) {
|
|
59 |
System.err.println("Encoding error " + testName);
|
|
60 |
throw new Exception("Failed ISCII91 Regression test");
|
|
61 |
}
|
|
62 |
|
|
63 |
} catch (UnsupportedEncodingException e) {
|
|
64 |
failureReport();
|
|
65 |
}
|
|
66 |
}
|
|
67 |
return;
|
|
68 |
}
|
|
69 |
|
|
70 |
private static void checkUnmapped(int start,
|
|
71 |
int end,
|
|
72 |
String testName)
|
|
73 |
throws Exception {
|
|
74 |
|
|
75 |
byte[] singleByte = new byte[1];
|
|
76 |
|
|
77 |
for (int i = start; i <= end; i++ ) {
|
|
78 |
singleByte[0] = (byte) i;
|
|
79 |
try {
|
|
80 |
String unicodeStr = new String (singleByte, "ISCII91");
|
|
81 |
|
|
82 |
if (unicodeStr.charAt(0) != '\uFFFD') {
|
|
83 |
System.err.println("FAILED " + testName +
|
|
84 |
"input byte is " + i );
|
|
85 |
throw new Exception ("Failed ISCII91 regression test");
|
|
86 |
}
|
|
87 |
} catch (UnsupportedEncodingException e) {
|
|
88 |
System.err.println("Unsupported character encoding");
|
|
89 |
}
|
|
90 |
}
|
|
91 |
return;
|
|
92 |
}
|
|
93 |
|
|
94 |
/*
|
|
95 |
*
|
|
96 |
*/
|
|
97 |
private static void checkRange(int start, int end,
|
|
98 |
char[] expectChars,
|
|
99 |
String testName)
|
|
100 |
throws Exception {
|
|
101 |
byte[] singleByte = new byte[1];
|
|
102 |
byte[] encoded = new byte[1];
|
|
103 |
int lookupOffset = 0;
|
|
104 |
|
|
105 |
for (int i=start; i <= end; i++ ) {
|
|
106 |
singleByte[0] = (byte) i;
|
|
107 |
String unicodeStr = new String (singleByte, "ISCII91");
|
|
108 |
if (unicodeStr.charAt(0) != expectChars[lookupOffset++]) {
|
|
109 |
throw new Exception ("Failed ISCII91 Regression Test");
|
|
110 |
}
|
|
111 |
encoded = unicodeStr.getBytes("ISCII");
|
|
112 |
}
|
|
113 |
return;
|
|
114 |
}
|
|
115 |
|
|
116 |
/*
|
|
117 |
* Tests the ISCII91 Indic character encoding
|
|
118 |
* as per IS 13194:1991 Bureau of Indian Standards.
|
|
119 |
*/
|
|
120 |
|
|
121 |
private static void test () throws Exception {
|
|
122 |
|
|
123 |
try {
|
|
124 |
|
|
125 |
|
|
126 |
// ISCII91 is an 8-byte encoding which retains the ASCII
|
|
127 |
// mappings in the lower half.
|
|
128 |
|
|
129 |
mapEquiv(0, 0x7f, "7 bit ASCII range");
|
|
130 |
|
|
131 |
// Checks a range of characters which are unmappable according
|
|
132 |
// to the standards.
|
|
133 |
|
|
134 |
checkUnmapped(0x81, 0x9f, "UNMAPPED");
|
|
135 |
|
|
136 |
// Vowel Modifier chars can be used to modify the vowel
|
|
137 |
// sound of the preceding consonant, vowel or matra character.
|
|
138 |
|
|
139 |
byte[] testByte = new byte[1];
|
|
140 |
char[] vowelModChars = {
|
|
141 |
'\u0901', // Vowel modifier Chandrabindu
|
|
142 |
'\u0902', // Vowel modifier Anuswar
|
|
143 |
'\u0903' // Vowel modifier Visarg
|
|
144 |
};
|
|
145 |
|
|
146 |
checkRange(0xa1, 0xa3, vowelModChars, "INDIC VOWEL MODIFIER CHARS");
|
|
147 |
|
|
148 |
char[] expectChars = {
|
|
149 |
'\u0905', // a4 -- Vowel A
|
|
150 |
'\u0906', // a5 -- Vowel AA
|
|
151 |
'\u0907', // a6 -- Vowel I
|
|
152 |
'\u0908', // a7 -- Vowel II
|
|
153 |
'\u0909', // a8 -- Vowel U
|
|
154 |
'\u090a', // a9 -- Vowel UU
|
|
155 |
'\u090b', // aa -- Vowel RI
|
|
156 |
'\u090e', // ab -- Vowel E ( Southern Scripts )
|
|
157 |
'\u090f', // ac -- Vowel EY
|
|
158 |
'\u0910', // ad -- Vowel AI
|
|
159 |
'\u090d', // ae -- Vowel AYE ( Devanagari Script )
|
|
160 |
'\u0912', // af -- Vowel O ( Southern Scripts )
|
|
161 |
'\u0913', // b0 -- Vowel OW
|
|
162 |
'\u0914', // b1 -- Vowel AU
|
|
163 |
'\u0911', // b2 -- Vowel AWE ( Devanagari Script )
|
|
164 |
};
|
|
165 |
|
|
166 |
checkRange(0xa4, 0xb2, expectChars, "INDIC VOWELS");
|
|
167 |
|
|
168 |
char[] expectConsChars =
|
|
169 |
{
|
|
170 |
'\u0915', // b3 -- Consonant KA
|
|
171 |
'\u0916', // b4 -- Consonant KHA
|
|
172 |
'\u0917', // b5 -- Consonant GA
|
|
173 |
'\u0918', // b6 -- Consonant GHA
|
|
174 |
'\u0919', // b7 -- Consonant NGA
|
|
175 |
'\u091a', // b8 -- Consonant CHA
|
|
176 |
'\u091b', // b9 -- Consonant CHHA
|
|
177 |
'\u091c', // ba -- Consonant JA
|
|
178 |
'\u091d', // bb -- Consonant JHA
|
|
179 |
'\u091e', // bc -- Consonant JNA
|
|
180 |
'\u091f', // bd -- Consonant Hard TA
|
|
181 |
'\u0920', // be -- Consonant Hard THA
|
|
182 |
'\u0921', // bf -- Consonant Hard DA
|
|
183 |
'\u0922', // c0 -- Consonant Hard DHA
|
|
184 |
'\u0923', // c1 -- Consonant Hard NA
|
|
185 |
'\u0924', // c2 -- Consonant Soft TA
|
|
186 |
'\u0925', // c3 -- Consonant Soft THA
|
|
187 |
'\u0926', // c4 -- Consonant Soft DA
|
|
188 |
'\u0927', // c5 -- Consonant Soft DHA
|
|
189 |
'\u0928', // c6 -- Consonant Soft NA
|
|
190 |
'\u0929', // c7 -- Consonant NA ( Tamil )
|
|
191 |
'\u092a', // c8 -- Consonant PA
|
|
192 |
'\u092b', // c9 -- Consonant PHA
|
|
193 |
'\u092c', // ca -- Consonant BA
|
|
194 |
'\u092d', // cb -- Consonant BHA
|
|
195 |
'\u092e', // cc -- Consonant MA
|
|
196 |
'\u092f', // cd -- Consonant YA
|
|
197 |
'\u095f', // ce -- Consonant JYA ( Bengali, Assamese & Oriya )
|
|
198 |
'\u0930', // cf -- Consonant RA
|
|
199 |
'\u0931', // d0 -- Consonant Hard RA ( Southern Scripts )
|
|
200 |
'\u0932', // d1 -- Consonant LA
|
|
201 |
'\u0933', // d2 -- Consonant Hard LA
|
|
202 |
'\u0934', // d3 -- Consonant ZHA ( Tamil & Malayalam )
|
|
203 |
'\u0935', // d4 -- Consonant VA
|
|
204 |
'\u0936', // d5 -- Consonant SHA
|
|
205 |
'\u0937', // d6 -- Consonant Hard SHA
|
|
206 |
'\u0938', // d7 -- Consonant SA
|
|
207 |
'\u0939', // d8 -- Consonant HA
|
|
208 |
};
|
|
209 |
|
|
210 |
checkRange(0xb3, 0xd8, expectConsChars, "INDIC CONSONANTS");
|
|
211 |
|
|
212 |
char[] matraChars = {
|
|
213 |
'\u093e', // da -- Vowel Sign AA
|
|
214 |
'\u093f', // db -- Vowel Sign I
|
|
215 |
'\u0940', // dc -- Vowel Sign II
|
|
216 |
'\u0941', // dd -- Vowel Sign U
|
|
217 |
'\u0942', // de -- Vowel Sign UU
|
|
218 |
'\u0943', // df -- Vowel Sign RI
|
|
219 |
'\u0946', // e0 -- Vowel Sign E ( Southern Scripts )
|
|
220 |
'\u0947', // e1 -- Vowel Sign EY
|
|
221 |
'\u0948', // e2 -- Vowel Sign AI
|
|
222 |
'\u0945', // e3 -- Vowel Sign AYE ( Devanagari Script )
|
|
223 |
'\u094a', // e4 -- Vowel Sign O ( Southern Scripts )
|
|
224 |
'\u094b', // e5 -- Vowel Sign OW
|
|
225 |
'\u094c', // e6 -- Vowel Sign AU
|
|
226 |
'\u0949' // e7 -- Vowel Sign AWE ( Devanagari Script )
|
|
227 |
};
|
|
228 |
|
|
229 |
// Matras or Vowel signs alter the implicit
|
|
230 |
// vowel sound associated with an Indic consonant.
|
|
231 |
|
|
232 |
checkRange(0xda, 0xe7, matraChars, "INDIC MATRAS");
|
|
233 |
|
|
234 |
char[] loneContextModifierChars = {
|
|
235 |
'\u094d', // e8 -- Vowel Omission Sign ( Halant )
|
|
236 |
'\u093c', // e9 -- Diacritic Sign ( Nukta )
|
|
237 |
'\u0964' // ea -- Full Stop ( Viram, Northern Scripts )
|
|
238 |
};
|
|
239 |
|
|
240 |
checkRange(0xe8, 0xea,
|
|
241 |
loneContextModifierChars, "LONE INDIC CONTEXT CHARS");
|
|
242 |
|
|
243 |
|
|
244 |
// Test Indic script numeral chars
|
|
245 |
// (as opposed to international numerals)
|
|
246 |
|
|
247 |
char[] expectNumeralChars =
|
|
248 |
{
|
|
249 |
'\u0966', // f1 -- Digit 0
|
|
250 |
'\u0967', // f2 -- Digit 1
|
|
251 |
'\u0968', // f3 -- Digit 2
|
|
252 |
'\u0969', // f4 -- Digit 3
|
|
253 |
'\u096a', // f5 -- Digit 4
|
|
254 |
'\u096b', // f6 -- Digit 5
|
|
255 |
'\u096c', // f7 -- Digit 6
|
|
256 |
'\u096d', // f8 -- Digit 7
|
|
257 |
'\u096e', // f9 -- Digit 8
|
|
258 |
'\u096f' // fa -- Digit 9
|
|
259 |
};
|
|
260 |
|
|
261 |
checkRange(0xf1, 0xfa,
|
|
262 |
expectNumeralChars, "NUMERAL/DIGIT CHARACTERS");
|
|
263 |
int lookupOffset = 0;
|
|
264 |
|
|
265 |
char[] expectNuktaSub = {
|
|
266 |
'\u0950',
|
|
267 |
'\u090c',
|
|
268 |
'\u0961',
|
|
269 |
'\u0960',
|
|
270 |
'\u0962',
|
|
271 |
'\u0963',
|
|
272 |
'\u0944',
|
|
273 |
'\u093d'
|
|
274 |
};
|
|
275 |
|
|
276 |
/*
|
|
277 |
* ISCII uses a number of code extension techniques
|
|
278 |
* to access a number of lesser used characters.
|
|
279 |
* The Nukta character which ordinarily signifies
|
|
280 |
* a diacritic is used in combination with existing
|
|
281 |
* characters to escape them to a different character.
|
|
282 |
* value.
|
|
283 |
*/
|
|
284 |
|
|
285 |
byte[] codeExtensionBytes = {
|
|
286 |
(byte)0xa1 , (byte)0xe9, // Chandrabindu + Nukta
|
|
287 |
// =>DEVANAGARI OM SIGN
|
|
288 |
(byte)0xa6 , (byte)0xe9, // Vowel I + Nukta
|
|
289 |
// => DEVANAGARI VOCALIC L
|
|
290 |
(byte)0xa7 , (byte)0xe9, // Vowel II + Nukta
|
|
291 |
// => DEVANAGARI VOCALIC LL
|
|
292 |
(byte)0xaa , (byte)0xe9, // Vowel RI + Nukta
|
|
293 |
// => DEVANAGARI VOCALIC RR
|
|
294 |
(byte)0xdb , (byte)0xe9, // Vowel sign I + Nukta
|
|
295 |
// => DEVANAGARI VOWEL SIGN VOCALIC L
|
|
296 |
(byte)0xdc , (byte)0xe9, // Vowel sign II + Nukta
|
|
297 |
// => DEVANAGARI VOWEL SIGN VOCALIC LL
|
|
298 |
|
|
299 |
(byte)0xdf , (byte)0xe9, // Vowel sign Vocalic R + Nukta
|
|
300 |
// => DEVANAGARI VOWEL SIGN VOCALIC RR
|
|
301 |
(byte)0xea , (byte)0xe9 // Full stop/Phrase separator + Nukta
|
|
302 |
// => DEVANAGARI SIGN AVAGRAHA
|
|
303 |
};
|
|
304 |
|
|
305 |
lookupOffset = 0;
|
|
306 |
byte[] bytePair = new byte[2];
|
|
307 |
|
|
308 |
for (int i=0; i < (codeExtensionBytes.length)/2; i++ ) {
|
|
309 |
bytePair[0] = (byte) codeExtensionBytes[lookupOffset++];
|
|
310 |
bytePair[1] = (byte) codeExtensionBytes[lookupOffset++];
|
|
311 |
|
|
312 |
String unicodeStr = new String (bytePair,"ISCII91");
|
|
313 |
if (unicodeStr.charAt(0) != expectNuktaSub[i]) {
|
|
314 |
throw new Exception("Failed Nukta Sub");
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
lookupOffset = 0;
|
|
319 |
byte[] comboBytes = {
|
|
320 |
(byte)0xe8 , (byte)0xe8, //HALANT + HALANT
|
|
321 |
(byte)0xe8 , (byte)0xe9 //HALANT + NUKTA aka. Soft Halant
|
|
322 |
};
|
|
323 |
char[] expectCombChars = {
|
|
324 |
'\u094d',
|
|
325 |
'\u200c',
|
|
326 |
'\u094d',
|
|
327 |
'\u200d'
|
|
328 |
};
|
|
329 |
|
|
330 |
for (int i=0; i < (comboBytes.length)/2; i++ ) {
|
|
331 |
bytePair[0] = (byte) comboBytes[lookupOffset++];
|
|
332 |
bytePair[1] = (byte) comboBytes[lookupOffset];
|
|
333 |
String unicodeStr = new String (bytePair, "ISCII91");
|
|
334 |
if (unicodeStr.charAt(0) != expectCombChars[lookupOffset-1]
|
|
335 |
&& unicodeStr.charAt(1) != expectCombChars[lookupOffset]) {
|
|
336 |
throw new Exception("Failed ISCII91 Regression Test");
|
|
337 |
}
|
|
338 |
lookupOffset++;
|
|
339 |
}
|
|
340 |
|
|
341 |
} catch (UnsupportedEncodingException e) {
|
|
342 |
System.err.println ("ISCII91 encoding not supported");
|
|
343 |
throw new Exception ("Failed ISCII91 Regression Test");
|
|
344 |
}
|
|
345 |
}
|
|
346 |
|
|
347 |
public static void main (String[] args) throws Exception {
|
|
348 |
test();
|
|
349 |
}
|
|
350 |
}
|