Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/nio/cs/ISCIITest.java
38839 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/* @test24@bug 432817825@summary Performs baseline and regression test on the ISCII91 charset26*/2728import java.io.*;2930public class ISCIITest {3132private static void failureReport() {33System.err.println ("Failed ISCII91 Regression Test");34}3536private static void mapEquiv(int start,37int end,38String testName)39throws Exception40{41byte[] singleByte = new byte[1];42byte[] encoded = new byte[1];4344for (int i = start; i <= end; i++ ) {45singleByte[0] = (byte) i;46try {47String unicodeStr =48new String (singleByte,"ISCII91");4950if (i != (int)unicodeStr.charAt(0)) {51System.err.println ("FAILED ISCII91 Regression test"52+ "input byte is " + i );53throw new Exception("");54}55encoded = unicodeStr.getBytes("ISCII91");5657if (encoded[0] != singleByte[0]) {58System.err.println("Encoding error " + testName);59throw new Exception("Failed ISCII91 Regression test");60}6162} catch (UnsupportedEncodingException e) {63failureReport();64}65}66return;67}6869private static void checkUnmapped(int start,70int end,71String testName)72throws Exception {7374byte[] singleByte = new byte[1];7576for (int i = start; i <= end; i++ ) {77singleByte[0] = (byte) i;78try {79String unicodeStr = new String (singleByte, "ISCII91");8081if (unicodeStr.charAt(0) != '\uFFFD') {82System.err.println("FAILED " + testName +83"input byte is " + i );84throw new Exception ("Failed ISCII91 regression test");85}86} catch (UnsupportedEncodingException e) {87System.err.println("Unsupported character encoding");88}89}90return;91}9293/*94*95*/96private static void checkRange(int start, int end,97char[] expectChars,98String testName)99throws Exception {100byte[] singleByte = new byte[1];101byte[] encoded = new byte[1];102int lookupOffset = 0;103104for (int i=start; i <= end; i++ ) {105singleByte[0] = (byte) i;106String unicodeStr = new String (singleByte, "ISCII91");107if (unicodeStr.charAt(0) != expectChars[lookupOffset++]) {108throw new Exception ("Failed ISCII91 Regression Test");109}110encoded = unicodeStr.getBytes("ISCII");111}112return;113}114115/*116* Tests the ISCII91 Indic character encoding117* as per IS 13194:1991 Bureau of Indian Standards.118*/119120private static void test () throws Exception {121122try {123124125// ISCII91 is an 8-byte encoding which retains the ASCII126// mappings in the lower half.127128mapEquiv(0, 0x7f, "7 bit ASCII range");129130// Checks a range of characters which are unmappable according131// to the standards.132133checkUnmapped(0x81, 0x9f, "UNMAPPED");134135// Vowel Modifier chars can be used to modify the vowel136// sound of the preceding consonant, vowel or matra character.137138byte[] testByte = new byte[1];139char[] vowelModChars = {140'\u0901', // Vowel modifier Chandrabindu141'\u0902', // Vowel modifier Anuswar142'\u0903' // Vowel modifier Visarg143};144145checkRange(0xa1, 0xa3, vowelModChars, "INDIC VOWEL MODIFIER CHARS");146147char[] expectChars = {148'\u0905', // a4 -- Vowel A149'\u0906', // a5 -- Vowel AA150'\u0907', // a6 -- Vowel I151'\u0908', // a7 -- Vowel II152'\u0909', // a8 -- Vowel U153'\u090a', // a9 -- Vowel UU154'\u090b', // aa -- Vowel RI155'\u090e', // ab -- Vowel E ( Southern Scripts )156'\u090f', // ac -- Vowel EY157'\u0910', // ad -- Vowel AI158'\u090d', // ae -- Vowel AYE ( Devanagari Script )159'\u0912', // af -- Vowel O ( Southern Scripts )160'\u0913', // b0 -- Vowel OW161'\u0914', // b1 -- Vowel AU162'\u0911', // b2 -- Vowel AWE ( Devanagari Script )163};164165checkRange(0xa4, 0xb2, expectChars, "INDIC VOWELS");166167char[] expectConsChars =168{169'\u0915', // b3 -- Consonant KA170'\u0916', // b4 -- Consonant KHA171'\u0917', // b5 -- Consonant GA172'\u0918', // b6 -- Consonant GHA173'\u0919', // b7 -- Consonant NGA174'\u091a', // b8 -- Consonant CHA175'\u091b', // b9 -- Consonant CHHA176'\u091c', // ba -- Consonant JA177'\u091d', // bb -- Consonant JHA178'\u091e', // bc -- Consonant JNA179'\u091f', // bd -- Consonant Hard TA180'\u0920', // be -- Consonant Hard THA181'\u0921', // bf -- Consonant Hard DA182'\u0922', // c0 -- Consonant Hard DHA183'\u0923', // c1 -- Consonant Hard NA184'\u0924', // c2 -- Consonant Soft TA185'\u0925', // c3 -- Consonant Soft THA186'\u0926', // c4 -- Consonant Soft DA187'\u0927', // c5 -- Consonant Soft DHA188'\u0928', // c6 -- Consonant Soft NA189'\u0929', // c7 -- Consonant NA ( Tamil )190'\u092a', // c8 -- Consonant PA191'\u092b', // c9 -- Consonant PHA192'\u092c', // ca -- Consonant BA193'\u092d', // cb -- Consonant BHA194'\u092e', // cc -- Consonant MA195'\u092f', // cd -- Consonant YA196'\u095f', // ce -- Consonant JYA ( Bengali, Assamese & Oriya )197'\u0930', // cf -- Consonant RA198'\u0931', // d0 -- Consonant Hard RA ( Southern Scripts )199'\u0932', // d1 -- Consonant LA200'\u0933', // d2 -- Consonant Hard LA201'\u0934', // d3 -- Consonant ZHA ( Tamil & Malayalam )202'\u0935', // d4 -- Consonant VA203'\u0936', // d5 -- Consonant SHA204'\u0937', // d6 -- Consonant Hard SHA205'\u0938', // d7 -- Consonant SA206'\u0939', // d8 -- Consonant HA207};208209checkRange(0xb3, 0xd8, expectConsChars, "INDIC CONSONANTS");210211char[] matraChars = {212'\u093e', // da -- Vowel Sign AA213'\u093f', // db -- Vowel Sign I214'\u0940', // dc -- Vowel Sign II215'\u0941', // dd -- Vowel Sign U216'\u0942', // de -- Vowel Sign UU217'\u0943', // df -- Vowel Sign RI218'\u0946', // e0 -- Vowel Sign E ( Southern Scripts )219'\u0947', // e1 -- Vowel Sign EY220'\u0948', // e2 -- Vowel Sign AI221'\u0945', // e3 -- Vowel Sign AYE ( Devanagari Script )222'\u094a', // e4 -- Vowel Sign O ( Southern Scripts )223'\u094b', // e5 -- Vowel Sign OW224'\u094c', // e6 -- Vowel Sign AU225'\u0949' // e7 -- Vowel Sign AWE ( Devanagari Script )226};227228// Matras or Vowel signs alter the implicit229// vowel sound associated with an Indic consonant.230231checkRange(0xda, 0xe7, matraChars, "INDIC MATRAS");232233char[] loneContextModifierChars = {234'\u094d', // e8 -- Vowel Omission Sign ( Halant )235'\u093c', // e9 -- Diacritic Sign ( Nukta )236'\u0964' // ea -- Full Stop ( Viram, Northern Scripts )237};238239checkRange(0xe8, 0xea,240loneContextModifierChars, "LONE INDIC CONTEXT CHARS");241242243// Test Indic script numeral chars244// (as opposed to international numerals)245246char[] expectNumeralChars =247{248'\u0966', // f1 -- Digit 0249'\u0967', // f2 -- Digit 1250'\u0968', // f3 -- Digit 2251'\u0969', // f4 -- Digit 3252'\u096a', // f5 -- Digit 4253'\u096b', // f6 -- Digit 5254'\u096c', // f7 -- Digit 6255'\u096d', // f8 -- Digit 7256'\u096e', // f9 -- Digit 8257'\u096f' // fa -- Digit 9258};259260checkRange(0xf1, 0xfa,261expectNumeralChars, "NUMERAL/DIGIT CHARACTERS");262int lookupOffset = 0;263264char[] expectNuktaSub = {265'\u0950',266'\u090c',267'\u0961',268'\u0960',269'\u0962',270'\u0963',271'\u0944',272'\u093d'273};274275/*276* ISCII uses a number of code extension techniques277* to access a number of lesser used characters.278* The Nukta character which ordinarily signifies279* a diacritic is used in combination with existing280* characters to escape them to a different character.281* value.282*/283284byte[] codeExtensionBytes = {285(byte)0xa1 , (byte)0xe9, // Chandrabindu + Nukta286// =>DEVANAGARI OM SIGN287(byte)0xa6 , (byte)0xe9, // Vowel I + Nukta288// => DEVANAGARI VOCALIC L289(byte)0xa7 , (byte)0xe9, // Vowel II + Nukta290// => DEVANAGARI VOCALIC LL291(byte)0xaa , (byte)0xe9, // Vowel RI + Nukta292// => DEVANAGARI VOCALIC RR293(byte)0xdb , (byte)0xe9, // Vowel sign I + Nukta294// => DEVANAGARI VOWEL SIGN VOCALIC L295(byte)0xdc , (byte)0xe9, // Vowel sign II + Nukta296// => DEVANAGARI VOWEL SIGN VOCALIC LL297298(byte)0xdf , (byte)0xe9, // Vowel sign Vocalic R + Nukta299// => DEVANAGARI VOWEL SIGN VOCALIC RR300(byte)0xea , (byte)0xe9 // Full stop/Phrase separator + Nukta301// => DEVANAGARI SIGN AVAGRAHA302};303304lookupOffset = 0;305byte[] bytePair = new byte[2];306307for (int i=0; i < (codeExtensionBytes.length)/2; i++ ) {308bytePair[0] = (byte) codeExtensionBytes[lookupOffset++];309bytePair[1] = (byte) codeExtensionBytes[lookupOffset++];310311String unicodeStr = new String (bytePair,"ISCII91");312if (unicodeStr.charAt(0) != expectNuktaSub[i]) {313throw new Exception("Failed Nukta Sub");314}315}316317lookupOffset = 0;318byte[] comboBytes = {319(byte)0xe8 , (byte)0xe8, //HALANT + HALANT320(byte)0xe8 , (byte)0xe9 //HALANT + NUKTA aka. Soft Halant321};322char[] expectCombChars = {323'\u094d',324'\u200c',325'\u094d',326'\u200d'327};328329for (int i=0; i < (comboBytes.length)/2; i++ ) {330bytePair[0] = (byte) comboBytes[lookupOffset++];331bytePair[1] = (byte) comboBytes[lookupOffset];332String unicodeStr = new String (bytePair, "ISCII91");333if (unicodeStr.charAt(0) != expectCombChars[lookupOffset-1]334&& unicodeStr.charAt(1) != expectCombChars[lookupOffset]) {335throw new Exception("Failed ISCII91 Regression Test");336}337lookupOffset++;338}339340} catch (UnsupportedEncodingException e) {341System.err.println ("ISCII91 encoding not supported");342throw new Exception ("Failed ISCII91 Regression Test");343}344}345346public static void main (String[] args) throws Exception {347test();348}349}350351352