Path: blob/master/test/jdk/java/text/Bidi/BidiConformance.java
41149 views
/*1* Copyright (c) 2009, 2020, 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/*24* @test25* @bug 6850113 8032446 825524226* @summary confirm the behavior of new Bidi implementation. (Backward compatibility)27* @modules java.desktop28*/2930import java.awt.font.NumericShaper;31import java.awt.font.TextAttribute;32import java.text.AttributedString;33import java.text.Bidi;34import java.util.Arrays;3536public class BidiConformance {3738/* internal flags */39private static boolean error = false;40private static boolean verbose = false;41private static boolean abort = false;4243private static final byte MAX_EXPLICIT_LEVEL = 125;4445public static void main(String[] args) {46for (int i = 0; i < args.length; i++) {47String arg = args[i];48if (arg.equals("-verbose")) {49verbose = true;50} else if (arg.equals("-abort")) {51abort = true;52}53}5455BidiConformance bc = new BidiConformance();56bc.test();5758if (error) {59throw new RuntimeException("Failed.");60} else {61System.out.println("Passed.");62}63}6465private void test() {66testConstants();67testConstructors();68testMethods();6970testMethods4Constructor1(); // Bidi(AttributedCharacterIterator)71testMethods4Constructor2(); // Bidi(String, int)72testMethods4Constructor3(); // Bidi(char[], ...)73}7475private void testConstants() {76System.out.println("*** Test constants");7778checkResult("Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT",79-2, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);80checkResult("Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT",81-1, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);82checkResult("Bidi.DIRECTION_LEFT_TO_RIGHT",830, Bidi.DIRECTION_LEFT_TO_RIGHT);84checkResult("Bidi.DIRECTION_RIGHT_TO_LEFT",851, Bidi.DIRECTION_RIGHT_TO_LEFT);86}8788private void testConstructors() {89System.out.println("*** Test constructors");9091testConstructor1(); // Bidi(AttributedCharacterIterator)92testConstructor2(); // Bidi(String, int)93testConstructor3(); // Bidi(char[], ...)94}9596private void testMethods() {97System.out.println("*** Test methods");9899testMethod_createLineBidi1();100testMethod_createLineBidi2();101testMethod_getLevelAt();102testMethod_getRunLevel();103testMethod_getRunLimit();104testMethod_getRunStart();105testMethod_reorderVisually1();106testMethod_reorderVisually2();107testMethod_requiresBidi();108}109110private void testMethods4Constructor1() {111System.out.println("*** Test methods for constructor 1");112113String paragraph;114Bidi bidi;115NumericShaper ns = NumericShaper.getShaper(NumericShaper.ARABIC);116117for (int textNo = 0; textNo < data4Constructor1.length; textNo++) {118paragraph = data4Constructor1[textNo][0];119int start = paragraph.indexOf('<')+1;120int limit = paragraph.indexOf('>');121int testNo;122123System.out.println("*** Test textNo=" + textNo +124": Bidi(AttributedCharacterIterator\"" +125toReadableString(paragraph) + "\") " +126" start=" + start + ", limit=" + limit);127128// Test 0129testNo = 0;130System.out.println(" Test#" + testNo +": RUN_DIRECTION_LTR");131AttributedString astr = new AttributedString(paragraph);132astr.addAttribute(TextAttribute.RUN_DIRECTION,133TextAttribute.RUN_DIRECTION_LTR);134bidi = new Bidi(astr.getIterator());135136callTestEachMethod4Constructor1(textNo, testNo, bidi);137138// Test 1139++testNo;140System.out.println(" Test#" + testNo +141": RUN_DIRECTION_LTR, BIDI_EMBEDDING(1)");142astr = new AttributedString(paragraph);143astr.addAttribute(TextAttribute.RUN_DIRECTION,144TextAttribute.RUN_DIRECTION_LTR);145astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),146start, limit);147bidi = new Bidi(astr.getIterator());148callTestEachMethod4Constructor1(textNo, testNo, bidi);149150// Test 2151++testNo;152System.out.println(" Test#" + testNo +153": RUN_DIERCTION_LTR, BIDI_EMBEDDING(2)");154astr = new AttributedString(paragraph);155astr.addAttribute(TextAttribute.RUN_DIRECTION,156TextAttribute.RUN_DIRECTION_LTR);157astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),158start, limit);159bidi = new Bidi(astr.getIterator());160callTestEachMethod4Constructor1(textNo, testNo, bidi);161162// Test 3163++testNo;164System.out.println(" Test#" + testNo +165": RUN_DIRECTIOIN_LTR, BIDI_EMBEDDING(-3)");166astr = new AttributedString(paragraph);167astr.addAttribute(TextAttribute.RUN_DIRECTION,168TextAttribute.RUN_DIRECTION_LTR);169astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),170start, limit);171bidi = new Bidi(astr.getIterator());172callTestEachMethod4Constructor1(textNo, testNo, bidi);173174// Test 4175++testNo;176System.out.println(" Test#" + testNo +177": RUN_DIRECTION_LTR, BIDI_EMBEDDING(-4)");178astr = new AttributedString(paragraph);179astr.addAttribute(TextAttribute.RUN_DIRECTION,180TextAttribute.RUN_DIRECTION_LTR);181astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),182start, limit);183bidi = new Bidi(astr.getIterator());184callTestEachMethod4Constructor1(textNo, testNo, bidi);185186// Test 5187++testNo;188System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL");189astr = new AttributedString(paragraph);190astr.addAttribute(TextAttribute.RUN_DIRECTION,191TextAttribute.RUN_DIRECTION_RTL);192bidi = new Bidi(astr.getIterator());193callTestEachMethod4Constructor1(textNo, testNo, bidi);194195// Test 6196++testNo;197System.out.println(" Test#" + testNo +198": RUN_DIRECTION_RTL, BIDI_EMBEDDING(1)");199astr = new AttributedString(paragraph);200astr.addAttribute(TextAttribute.RUN_DIRECTION,201TextAttribute.RUN_DIRECTION_RTL);202astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),203start, limit);204try {205bidi = new Bidi(astr.getIterator());206callTestEachMethod4Constructor1(textNo, testNo, bidi);207}208catch (IllegalArgumentException e) {209errorHandling(" Unexpected exception: " + e);210}211212// Test 7213++testNo;214System.out.println(" Test#" + testNo +215": RUN_DIRECTION_RTL, BIDI_EMBEDDING(2)");216astr = new AttributedString(paragraph);217astr.addAttribute(TextAttribute.RUN_DIRECTION,218TextAttribute.RUN_DIRECTION_RTL);219astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),220start, limit);221try {222bidi = new Bidi(astr.getIterator());223callTestEachMethod4Constructor1(textNo, testNo, bidi);224}225catch (IllegalArgumentException e) {226errorHandling(" Unexpected exception: " + e);227}228229// Test 8230++testNo;231System.out.println(" Test#" + testNo +232": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-3)");233astr = new AttributedString(paragraph);234astr.addAttribute(TextAttribute.RUN_DIRECTION,235TextAttribute.RUN_DIRECTION_RTL);236astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),237start, limit);238try {239bidi = new Bidi(astr.getIterator());240callTestEachMethod4Constructor1(textNo, testNo, bidi);241}242catch (IllegalArgumentException e) {243errorHandling(" Unexpected exception: " + e);244}245246// Test 9247++testNo;248System.out.println(" Test#" + testNo +249": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-4)");250astr = new AttributedString(paragraph);251astr.addAttribute(TextAttribute.RUN_DIRECTION,252TextAttribute.RUN_DIRECTION_RTL);253astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),254start, limit);255try {256bidi = new Bidi(astr.getIterator());257callTestEachMethod4Constructor1(textNo, testNo, bidi);258}259catch (IllegalArgumentException e) {260errorHandling(" Unexpected exception: " + e);261}262263// Test 10264++testNo;265System.out.println(" Test#" + testNo +266": TextAttribute not specified");267astr = new AttributedString(paragraph);268bidi = new Bidi(astr.getIterator());269callTestEachMethod4Constructor1(textNo, testNo, bidi);270271// Test 11272++testNo;273System.out.println(" Test#" + testNo +274": RUN_DIRECTION_LTR, NUMERIC_SHAPING(ARABIC)");275astr = new AttributedString(paragraph);276astr.addAttribute(TextAttribute.RUN_DIRECTION,277TextAttribute.RUN_DIRECTION_LTR);278astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);279bidi = new Bidi(astr.getIterator());280callTestEachMethod4Constructor1(textNo, testNo, bidi);281282// Test 12283++testNo;284System.out.println(" Test#" + testNo +285": RUN_DIRECTION_RTL, NUMERIC_SHAPING(ARABIC)");286astr = new AttributedString(paragraph);287astr.addAttribute(TextAttribute.RUN_DIRECTION,288TextAttribute.RUN_DIRECTION_RTL);289astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);290bidi = new Bidi(astr.getIterator());291callTestEachMethod4Constructor1(textNo, testNo, bidi);292}293}294295private void testMethods4Constructor2() {296System.out.println("*** Test methods for constructor 2");297298String paragraph;299Bidi bidi;300301for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {302paragraph = data4Constructor2[textNo][0];303for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {304int flag = FLAGS[flagNo];305306System.out.println("*** Test textNo=" + textNo +307": Bidi(\"" + toReadableString(paragraph) +308"\", " + getFlagName(flag) + ")");309310bidi = new Bidi(paragraph, flag);311callTestEachMethod4Constructor2(textNo, flagNo, bidi);312}313}314}315316private void testMethods4Constructor3() {317System.out.println("*** Test methods for constructor 3");318319String paragraph;320Bidi bidi;321322for (int textNo = 0; textNo < data4Constructor3.length; textNo++) {323paragraph = data4Constructor3[textNo][0];324char[] c = paragraph.toCharArray();325int start = paragraph.indexOf('<')+1;326byte[][] embeddings = (c.length < emb4Constructor3[1][0].length) ?327emb4Constructor3[0] : emb4Constructor3[1];328for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {329int flag = FLAGS[flagNo];330for (int embNo = 0; embNo < embeddings.length; embNo++) {331int dataNo = flagNo * FLAGS.length + embNo;332333System.out.println("*** Test textNo=" + textNo +334": Bidi(char[]\"" + toReadableString(paragraph) +335"\", 0, embeddings={" + toString(embeddings[embNo]) +336"}, " + c.length + ", " +337getFlagName(flag) + ")" + " dataNo=" + dataNo);338339try {340bidi = new Bidi(c, 0, embeddings[embNo], 0,341c.length, flag);342callTestEachMethod4Constructor3(textNo, dataNo, bidi);343}344catch (Exception e) {345errorHandling(" Unexpected exception: " + e);346}347}348}349}350}351352private void testConstructor1() {353Bidi bidi;354355try {356bidi = new Bidi(null);357errorHandling("Bidi((AttributedCharacterIterator)null) " +358"should throw an IAE.");359}360catch (IllegalArgumentException e) {361}362catch (NullPointerException e) {363errorHandling("Bidi((AttributedCharacterIterator)null) " +364"should not throw an NPE but an IAE.");365}366367String paragraph = data4Constructor1[1][0];368int start = paragraph.indexOf('<')+1;369int limit = paragraph.indexOf('>');370AttributedString astr = new AttributedString(paragraph);371astr.addAttribute(TextAttribute.RUN_DIRECTION,372TextAttribute.RUN_DIRECTION_RTL);373astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-MAX_EXPLICIT_LEVEL),374start, limit);375try {376bidi = new Bidi(astr.getIterator());377for (int i = start; i < limit; i++) {378if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {379errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +380i + ") should not be " + bidi.getLevelAt(i) +381" but MAX_EXPLICIT_LEVEL-1 when BIDI_EMBEDDING is -MAX_EXPLICIT_LEVEL.");382}383}384}385catch (Exception e) {386errorHandling(" Unexpected exception: " + e);387}388389astr = new AttributedString(paragraph);390astr.addAttribute(TextAttribute.RUN_DIRECTION,391TextAttribute.RUN_DIRECTION_RTL);392astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-(MAX_EXPLICIT_LEVEL+1)),393start, limit);394try {395bidi = new Bidi(astr.getIterator());396for (int i = start; i < limit; i++) {397if (bidi.getLevelAt(i) != 1) {398errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +399"should be 1 when BIDI_EMBEDDING is -(MAX_EXPLICIT_LEVEL+1).");400}401}402}403catch (Exception e) {404errorHandling(" Unexpected exception: " + e);405}406407astr = new AttributedString(paragraph);408astr.addAttribute(TextAttribute.RUN_DIRECTION,409TextAttribute.RUN_DIRECTION_RTL);410astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL-1),411start, limit);412try {413bidi = new Bidi(astr.getIterator());414for (int i = start; i < limit; i++) {415if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {416errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +417"should be MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL-1.");418}419}420}421catch (Exception e) {422errorHandling(" Unexpected exception: " + e);423}424425astr = new AttributedString(paragraph);426astr.addAttribute(TextAttribute.RUN_DIRECTION,427TextAttribute.RUN_DIRECTION_RTL);428astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL),429start, limit);430try {431bidi = new Bidi(astr.getIterator());432for (int i = start; i < limit; i++) {433if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {434errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +435i + ") should not be " + bidi.getLevelAt(i) +436" but MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL.");437}438}439}440catch (Exception e) {441errorHandling(" Unexpected exception: " + e);442}443444astr = new AttributedString(paragraph);445astr.addAttribute(TextAttribute.RUN_DIRECTION,446TextAttribute.RUN_DIRECTION_RTL);447astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL+1),448start, limit);449try {450bidi = new Bidi(astr.getIterator());451for (int i = start; i < limit; i++) {452if (bidi.getLevelAt(i) != 1) {453errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +454i + ") should not be " + bidi.getLevelAt(i) +455" but 1 when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL+1.");456}457}458}459catch (Exception e) {460errorHandling(" Unexpected exception: " + e);461}462}463464private void testConstructor2() {465Bidi bidi;466467try {468bidi = new Bidi(null, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);469errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT)" +470" should throw an IAE.");471}472catch (IllegalArgumentException e) {473}474catch (NullPointerException e) {475errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT) " +476"should not throw an NPE but an IAE.");477}478479try {480bidi = new Bidi("abc", -3);481}482catch (Exception e) {483errorHandling("Bidi(\"abc\", -3) should not throw an exception: " +484e);485}486487try {488bidi = new Bidi("abc", 2);489}490catch (Exception e) {491errorHandling("Bidi(\"abc\", 2) should not throw an exception: " +492e);493}494}495496private void testConstructor3() {497char[] text = {'a', 'b', 'c', 'd', 'e'};498byte[] embeddings = {0, 0, 0, 0, 0};499Bidi bidi;500501try {502bidi = new Bidi(null, 0, embeddings, 0, 5,503Bidi.DIRECTION_LEFT_TO_RIGHT);504errorHandling("Bidi(char[], ...) should throw an IAE " +505"when text=null.");506}507catch (IllegalArgumentException e) {508}509catch (NullPointerException e) {510errorHandling("Bidi(char[], ...) should not throw an NPE " +511"but an IAE when text=null.");512}513514try {515bidi = new Bidi(text, -1, embeddings, 0, 5,516Bidi.DIRECTION_LEFT_TO_RIGHT);517errorHandling("Bidi(char[], ...) should throw an IAE " +518"when textStart is incorrect(-1: too small).");519}520catch (IllegalArgumentException e) {521}522catch (ArrayIndexOutOfBoundsException e) {523errorHandling("Bidi(char[], ...) should not throw an NPE " +524"but an IAE when textStart is incorrect(-1: too small).");525}526527try {528bidi = new Bidi(text, 4, embeddings, 0, 2,529Bidi.DIRECTION_LEFT_TO_RIGHT);530errorHandling("Bidi(char[], ...) should throw an IAE " +531"when textStart is incorrect(4: too large).");532}533catch (IllegalArgumentException e) {534}535catch (ArrayIndexOutOfBoundsException e) {536errorHandling("Bidi(char[], ...) should not throw an NPE " +537"but an IAE when textStart is incorrect(4: too large).");538}539540byte[] actualLevels = new byte[text.length];541byte[] validEmbeddings1 = {0, -MAX_EXPLICIT_LEVEL, -(MAX_EXPLICIT_LEVEL-1), -2, -1};542byte[] expectedLevels1 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 2, 1};543try {544bidi = new Bidi(text, 0, validEmbeddings1, 0, 5,545Bidi.DIRECTION_LEFT_TO_RIGHT);546for (int i = 0; i < text.length; i++) {547actualLevels[i] = (byte)bidi.getLevelAt(i);548}549if (!Arrays.equals(expectedLevels1, actualLevels)) {550errorHandling("Bidi(char[], ...).getLevelAt()" +551" should be {" + toString(actualLevels) +552"} when embeddings are {" +553toString(expectedLevels1) + "}.");554}555}556catch (Exception e) {557errorHandling("Bidi(char[], ...) should not throw an exception " +558"when embeddings is valid(-MAX_EXPLICIT_LEVEL).");559}560561byte[] validEmbeddings2 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 2, 1};562byte[] expectedLevels2 = {0, MAX_EXPLICIT_LEVEL+1, MAX_EXPLICIT_LEVEL-1, 2, 2};563try {564bidi = new Bidi(text, 0, validEmbeddings2, 0, 5,565Bidi.DIRECTION_LEFT_TO_RIGHT);566for (int i = 0; i < text.length; i++) {567actualLevels[i] = (byte)bidi.getLevelAt(i);568}569if (!Arrays.equals(expectedLevels2, actualLevels)) {570errorHandling("Bidi(char[], ...).getLevelAt()" +571" should be {" + toString(actualLevels) +572"} when embeddings are {" +573toString(expectedLevels2) + "}.");574}575}576catch (Exception e) {577errorHandling("Bidi(char[], ...) should not throw an exception " +578"when embeddings is valid(MAX_EXPLICIT_LEVEL).");579}580581byte[] invalidEmbeddings1 = {0, -(MAX_EXPLICIT_LEVEL+1), 0, 0, 0};582try {583bidi = new Bidi(text, 0, invalidEmbeddings1, 0, 5,584Bidi.DIRECTION_LEFT_TO_RIGHT);585if (bidi.getLevelAt(1) != 0) {586errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +587"when embeddings[1] is -(MAX_EXPLICIT_LEVEL+1).");588}589}590catch (Exception e) {591errorHandling("Bidi(char[], ...) should not throw an exception " +592"even when embeddings includes -(MAX_EXPLICIT_LEVEL+1).");593}594595byte[] invalidEmbeddings2 = {0, MAX_EXPLICIT_LEVEL+1, 0, 0, 0};596try {597bidi = new Bidi(text, 0, invalidEmbeddings2, 0, 5,598Bidi.DIRECTION_LEFT_TO_RIGHT);599if (bidi.getLevelAt(1) != 0) {600errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +601"when embeddings[1] is MAX_EXPLICIT_LEVEL+1.");602}603}604catch (Exception e) {605errorHandling("Bidi(char[], ...) should not throw an exception " +606"even when embeddings includes MAX_EXPLICIT_LEVEL+1.");607}608609try {610bidi = new Bidi(text, 0, embeddings, 0, -1,611Bidi.DIRECTION_LEFT_TO_RIGHT);612errorHandling("Bidi(char[], ...) should throw an IAE " +613"when paragraphLength=-1(too small).");614}615catch (IllegalArgumentException e) {616}617catch (NegativeArraySizeException e) {618errorHandling("Bidi(char[], ...) should not throw an NASE " +619"but an IAE when paragraphLength=-1(too small).");620}621622try {623bidi = new Bidi(text, 0, embeddings, 0, 6,624Bidi.DIRECTION_LEFT_TO_RIGHT);625errorHandling("Bidi(char[], ...) should throw an IAE " +626"when paragraphLength=6(too large).");627}628catch (IllegalArgumentException e) {629}630catch (ArrayIndexOutOfBoundsException e) {631errorHandling("Bidi(char[], ...) should not throw an AIOoBE " +632"but an IAE when paragraphLength=6(too large).");633}634635try {636bidi = new Bidi(text, 0, embeddings, 0, 4, -3);637}638catch (Exception e) {639errorHandling("Bidi(char[], ...) should not throw an exception " +640"even when flag=-3(too small).");641}642643try {644bidi = new Bidi(text, 0, embeddings, 0, 5, 2);645}646catch (Exception e) {647errorHandling("Bidi(char[], ...) should not throw an exception " +648"even when flag=2(too large).");649}650}651652private void callTestEachMethod4Constructor1(int textNo,653int testNo,654Bidi bidi) {655testEachMethod(bidi,656data4Constructor1[textNo][0],657data4Constructor1[textNo][testNo+1],658baseIsLTR4Constructor1[textNo][testNo],659isLTR_isRTL4Constructor1[textNo][0][testNo],660isLTR_isRTL4Constructor1[textNo][1][testNo]);661}662663private void callTestEachMethod4Constructor2(int textNo,664int flagNo,665Bidi bidi) {666testEachMethod(bidi,667data4Constructor2[textNo][0],668data4Constructor2[textNo][flagNo+1],669baseIsLTR4Constructor2[textNo][flagNo],670isLTR_isRTL4Constructor2[textNo][0][flagNo],671isLTR_isRTL4Constructor2[textNo][1][flagNo]);672}673674private void callTestEachMethod4Constructor3(int textNo,675int dataNo,676Bidi bidi) {677testEachMethod(bidi,678data4Constructor3[textNo][0],679data4Constructor3[textNo][dataNo+1],680baseIsLTR4Constructor3[textNo][dataNo],681isLTR_isRTL4Constructor3[textNo][0][dataNo],682isLTR_isRTL4Constructor3[textNo][1][dataNo]);683}684685private StringBuilder sb = new StringBuilder();686private void testEachMethod(Bidi bidi,687String text,688String expectedLevels,689boolean expectedBaseIsLTR,690boolean expectedIsLTR,691boolean expectedIsRTL692) {693/* Test baseIsLeftToRight() */694boolean actualBoolean = bidi.baseIsLeftToRight();695checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);696697/* Test getBaseLevel() */698int expectedInt = (expectedBaseIsLTR) ? 0 : 1;699int actualInt = bidi.getBaseLevel();700checkResult("getBaseLevel()", expectedInt, actualInt);701702/* Test getLength() */703expectedInt = text.length();704actualInt = bidi.getLength();705checkResult("getLength()", expectedInt, actualInt);706707/* Test getLevelAt() */708sb.setLength(0);709for (int i = 0; i < text.length(); i++) {710sb.append(bidi.getLevelAt(i));711}712checkResult("getLevelAt()", expectedLevels, sb.toString());713714/* Test getRunCount() */715expectedInt = getRunCount(expectedLevels);716actualInt = bidi.getRunCount();717checkResult("getRunCount()", expectedInt, actualInt);718719/* Test getRunLevel(), getRunLimit() and getRunStart() */720if (expectedInt == actualInt) {721int runCount = expectedInt;722int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);723int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);724int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);725int[] actualRunLevels = new int[runCount];726int[] actualRunLimits = new int[runCount];727int[] actualRunStarts = new int[runCount];728729for (int k = 0; k < runCount; k++) {730actualRunLevels[k] = bidi.getRunLevel(k);731actualRunLimits[k] = bidi.getRunLimit(k);732actualRunStarts[k] = bidi.getRunStart(k);733}734735checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);736checkResult("getRunStart()", expectedRunStarts, actualRunStarts);737checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);738}739740/* Test isLeftToRight() */741boolean expectedBoolean = expectedIsLTR;742actualBoolean = bidi.isLeftToRight();743checkResult("isLeftToRight()", expectedBoolean, actualBoolean);744745/* Test isMixed() */746expectedBoolean = !(expectedIsLTR || expectedIsRTL);747actualBoolean = bidi.isMixed();748checkResult("isMixed()", expectedBoolean, actualBoolean);749750/* Test isRightToLeft() */751expectedBoolean = expectedIsRTL;752actualBoolean = bidi.isRightToLeft();753checkResult("isRightToLeft()", expectedBoolean, actualBoolean);754}755756private int getRunCount(String levels) {757int len = levels.length();758char c = levels.charAt(0);759int runCount = 1;760761for (int index = 1; index < len; index++) {762if (levels.charAt(index) != c) {763runCount++;764c = levels.charAt(index);765}766}767768return runCount;769}770771private int[] getRunLevels_int(int runCount, String levels) {772int[] array = new int[runCount];773int len = levels.length();774char c = levels.charAt(0);775int i = 0;776array[i++] = c - '0';777778for (int index = 1; index < len; index++) {779if (levels.charAt(index) != c) {780c = levels.charAt(index);781array[i++] = c - '0';782}783}784785return array;786}787788private byte[] getRunLevels_byte(int runCount, String levels) {789byte[] array = new byte[runCount];790int len = levels.length();791char c = levels.charAt(0);792int i = 0;793array[i++] = (byte)(c - '0');794795for (int index = 1; index < len; index++) {796if (levels.charAt(index) != c) {797c = levels.charAt(index);798array[i++] = (byte)(c - '0');799}800}801802return array;803}804805private int[] getRunLimits(int runCount, String levels) {806int[] array = new int[runCount];807int len = levels.length();808char c = levels.charAt(0);809int i = 0;810811for (int index = 1; index < len; index++) {812if (levels.charAt(index) != c) {813c = levels.charAt(index);814array[i++] = index;815}816}817array[i] = len;818819return array;820}821822private int[] getRunStarts(int runCount, String levels) {823int[] array = new int[runCount];824int len = levels.length();825char c = levels.charAt(0);826int i = 1;827828for (int index = 1; index < len; index++) {829if (levels.charAt(index) != c) {830c = levels.charAt(index);831array[i++] = index;832}833}834835return array;836}837838private String[] getObjects(int runCount, String text, String levels) {839String[] array = new String[runCount];840int[] runLimits = getRunLimits(runCount, levels);841int runStart = 0;842843for (int i = 0; i < runCount; i++) {844array[i] = text.substring(runStart, runLimits[i]);845runStart = runLimits[i];846}847848return array;849}850851private void testMethod_createLineBidi1() {852System.out.println("*** Test createLineBidi() 1");853854String str = " ABC 123. " + HebrewABC + " " + NKo123 + ". ABC 123";855856int lineStart = str.indexOf('.') + 2;857int lineLimit = str.lastIndexOf('.') + 2;858Bidi bidi = new Bidi(str, FLAGS[0]);859Bidi lineBidi = bidi.createLineBidi(lineStart, lineLimit);860861checkResult("getBaseLevel()",862bidi.getBaseLevel(), lineBidi.getBaseLevel());863checkResult("getLevelAt(5)",864bidi.getLevelAt(lineStart+5), lineBidi.getLevelAt(5));865}866867private void testMethod_createLineBidi2() {868System.out.println("*** Test createLineBidi() 2");869870Bidi bidi = new Bidi(data4Constructor1[0][0], FLAGS[0]);871int len = data4Constructor1[0][0].length();872873try {874Bidi lineBidi = bidi.createLineBidi(0, len);875}876catch (Exception e) {877errorHandling("createLineBidi(0, textLength)" +878" should not throw an exception.");879}880881try {882Bidi lineBidi = bidi.createLineBidi(-1, len);883errorHandling("createLineBidi(-1, textLength)" +884" should throw an IAE.");885}886catch (IllegalArgumentException e) {887}888889try {890Bidi lineBidi = bidi.createLineBidi(0, len+1);891errorHandling("createLineBidi(0, textLength+1)" +892" should throw an IAE.");893}894catch (IllegalArgumentException e) {895}896}897898/*899* Confirm that getLevelAt() doesn't throw an exception for invalid offset900* unlike ICU4J.901*/902private void testMethod_getLevelAt() {903System.out.println("*** Test getLevelAt()");904905Bidi bidi = new Bidi(data4Constructor1[1][0], FLAGS[0]);906int len = data4Constructor1[1][0].length();907908try {909int level = bidi.getLevelAt(-1);910if (level != bidi.getBaseLevel()) {911errorHandling("getLevelAt(-1) returned a wrong level." +912" Expected=" + bidi.getBaseLevel() + ", got=" + level);913}914}915catch (Exception e) {916errorHandling("getLevelAt(-1) should not throw an exception.");917}918919try {920int level = bidi.getLevelAt(len+1);921if (level != bidi.getBaseLevel()) {922errorHandling("getLevelAt(textLength+1)" +923" returned a wrong level." +924" Expected=" + bidi.getBaseLevel() + ", got=" + level);925}926}927catch (Exception e) {928errorHandling("getLevelAt(-1) should not throw an exception.");929}930}931932private void testMethod_getRunLevel() {933System.out.println("*** Test getRunLevel()");934935String str = "ABC 123";936Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);937try {938if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)939bidi.getRunLevel(0) != 0 || // runCount - 1940bidi.getRunLevel(1) != 0 || // runCount (out of range)941bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)942errorHandling("Incorrect getRunLevel() value(s).");943}944}945catch (Exception e) {946errorHandling("getRunLevel() should not throw an exception: " + e);947}948949str = "ABC " + HebrewABC + " 123";950bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);951try {952if (bidi.getRunLevel(-1) != 0 || // runCount - 4 (out of range)953bidi.getRunLevel(0) != 0 || // runCount - 3954bidi.getRunLevel(1) != 1 || // runCount - 2955bidi.getRunLevel(2) != 2 || // runCount - 1956bidi.getRunLevel(3) != 0 || // runCount (out of range)957bidi.getRunLevel(4) != 0) { // runCount + 1 (out of range)958errorHandling("Incorrect getRunLevel() value(s).");959}960}961catch (Exception e) {962errorHandling("getRunLevel() should not throw an exception: " + e);963}964965str = "ABC";966bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);967try {968if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)969bidi.getRunLevel(0) != 0 || // runCount - 1970bidi.getRunLevel(1) != 0 || // runCount (out of range)971bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)972errorHandling("Incorrect getRunLevel() value(s).");973}974}975catch (Exception e) {976errorHandling("getRunLevel() should not throw an exception: " + e);977}978979str = "ABC";980bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);981try {982if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)983bidi.getRunLevel(0) != 2 || // runCount - 1984bidi.getRunLevel(1) != 1 || // runCount (out of range)985bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)986errorHandling("Incorrect getRunLevel() value(s).");987}988}989catch (Exception e) {990errorHandling("getRunLevel() should not throw an exception: " + e);991}992993str = "ABC";994bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);995try {996if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)997bidi.getRunLevel(0) != 0 || // runCount - 1998bidi.getRunLevel(1) != 0 || // runCount (out of range)999bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)1000errorHandling("Incorrect getRunLevel() value(s).");1001}1002}1003catch (Exception e) {1004errorHandling("getRunLevel() should not throw an exception: " + e);1005}10061007str = "ABC";1008bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);1009try {1010if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)1011bidi.getRunLevel(0) != 0 || // runCount - 11012bidi.getRunLevel(1) != 0 || // runCount (out of range)1013bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)1014errorHandling("Incorrect getRunLevel() value(s).");1015}1016}1017catch (Exception e) {1018errorHandling("getRunLevel() should not throw an exception: " + e);1019}10201021str = HebrewABC;1022bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);1023try {1024if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)1025bidi.getRunLevel(0) != 1 || // runCount - 11026bidi.getRunLevel(1) != 0 || // runCount (out of range)1027bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)1028errorHandling("Incorrect getRunLevel() value(s).");1029}1030}1031catch (Exception e) {1032errorHandling("getRunLevel() should not throw an exception: " + e);1033}10341035str = HebrewABC;1036bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);1037try {1038if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1039bidi.getRunLevel(0) != 1 || // runCount - 11040bidi.getRunLevel(1) != 1 || // runCount (out of range)1041bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1042errorHandling("Incorrect getRunLevel() value(s).");1043}1044}1045catch (Exception e) {1046errorHandling("getRunLevel() should not throw an exception: " + e);1047}10481049str = HebrewABC;1050bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);1051try {1052if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1053bidi.getRunLevel(0) != 1 || // runCount - 11054bidi.getRunLevel(1) != 1 || // runCount (out of range)1055bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1056errorHandling("Incorrect getRunLevel() value(s).");1057}1058}1059catch (Exception e) {1060errorHandling("getRunLevel() should not throw an exception: " + e);1061}10621063str = HebrewABC;1064bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);1065try {1066if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1067bidi.getRunLevel(0) != 1 || // runCount - 11068bidi.getRunLevel(1) != 1 || // runCount (out of range)1069bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1070errorHandling("Incorrect getRunLevel() value(s).");1071}1072}1073catch (Exception e) {1074errorHandling("getRunLevel() should not throw an exception: " + e);1075}1076}10771078private void testMethod_getRunLimit() {1079System.out.println("*** Test getRunLimit()");10801081String str = "ABC 123";1082int length = str.length();1083Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);10841085try {1086if (bidi.getRunLimit(-1) != length || // runCount - 21087bidi.getRunLimit(0) != length || // runCount - 11088bidi.getRunLimit(1) != length || // runCount1089bidi.getRunLimit(2) != length) { // runCount + 11090errorHandling("getRunLimit() should return " + length +1091" when getRunCount() is 1.");1092}1093}1094catch (Exception e) {1095errorHandling("getRunLimit() should not throw an exception " +1096"when getRunCount() is 1.");1097}10981099str = "ABC " + ArabicABC + " 123";1100length = str.length();1101bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);11021103try {1104bidi.getRunLimit(-1);1105errorHandling("getRunLimit() should throw an AIOoBE " +1106"when run is -1(too small).");1107}1108catch (ArrayIndexOutOfBoundsException e) {1109}1110catch (IllegalArgumentException e) {1111errorHandling("getRunLimit() should not throw an IAE " +1112"but an AIOoBE when run is -1(too small).");1113}11141115try {1116bidi.getRunLimit(0);1117bidi.getRunLimit(1);1118bidi.getRunLimit(2);1119}1120catch (ArrayIndexOutOfBoundsException e) {1121errorHandling("getRunLimit() should not throw an AIOOBE " +1122"when run is from 0 to 2(runCount-1).");1123}11241125try {1126bidi.getRunLimit(3);1127errorHandling("getRunLimit() should throw an AIOoBE " +1128"when run is 3(same as runCount).");1129}1130catch (ArrayIndexOutOfBoundsException e) {1131}1132catch (IllegalArgumentException e) {1133errorHandling("getRunLimit() should not throw an IAE " +1134"but an AIOoBE when run is 3(same as runCount).");1135}1136}11371138private void testMethod_getRunStart() {1139System.out.println("*** Test getRunStart()");11401141String str = "ABC 123";1142int length = str.length();1143Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);11441145try {1146if (bidi.getRunStart(-1) != 0 || // runCount - 21147bidi.getRunStart(0) != 0 || // runCount - 11148bidi.getRunStart(1) != 0 || // runCount1149bidi.getRunStart(2) != 0) { // runCount + 11150errorHandling("getRunStart() should return 0" +1151" when getRunCount() is 1.");1152}1153}1154catch (Exception e) {1155errorHandling("getRunLimit() should not throw an exception" +1156" when getRunCount() is 1.");1157}11581159str = "ABC " + NKoABC + " 123";1160length = str.length();1161bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);11621163try {1164bidi.getRunStart(-1);1165errorHandling("getRunStart() should throw an AIOoBE" +1166" when run is -1(too small).");1167}1168catch (ArrayIndexOutOfBoundsException e) {1169}1170catch (IllegalArgumentException e) {1171errorHandling("getRunStart() should not throw an IAE " +1172"but an AIOoBE when run is -1(too small).");1173}11741175try {1176bidi.getRunStart(0);1177bidi.getRunStart(1);1178bidi.getRunStart(2);1179}1180catch (ArrayIndexOutOfBoundsException e) {1181errorHandling("getRunStart() should not throw an AIOOBE " +1182"when run is from 0 to 2(runCount-1).");1183}11841185try {1186if (bidi.getRunStart(3) != length) {1187errorHandling("getRunStart() should return " + length +1188" when run is 3(same as runCount).");1189}1190}1191catch (Exception e) {1192errorHandling("getRunStart() should not throw an exception " +1193"when run is 3(same as runCount).");1194}11951196try {1197bidi.getRunStart(4);1198errorHandling("getRunStart() should throw an AIOoBE " +1199"when run is runCount+1(too large).");1200}1201catch (ArrayIndexOutOfBoundsException e) {1202}1203catch (IllegalArgumentException e) {1204errorHandling("getRunStart() should not throw an IAE " +1205"but an AIOoBE when run is runCount+1(too large).");1206}1207}12081209private void testMethod_reorderVisually1() {1210System.out.println("*** Test reorderVisually() 1");12111212for (int textNo = 0; textNo < data4reorderVisually.length; textNo++) {1213Object[] objects = data4reorderVisually[textNo][0];1214byte[] levels = getLevels(data4reorderVisually[textNo]);1215Object[] expectedObjects = data4reorderVisually[textNo][2];12161217Bidi.reorderVisually(levels, 0, objects, 0, objects.length);12181219checkResult("textNo=" + textNo + ": reorderVisually(levels=[" +1220toString(levels) + "], objects=[" + toString(objects) + "])",1221expectedObjects, objects);1222}1223}12241225private void testMethod_reorderVisually2() {1226System.out.println("*** Test reorderVisually() 2");12271228Object[] objects = data4reorderVisually[0][0];1229byte[] levels = getLevels(data4reorderVisually[0]);1230int count = objects.length;1231int llen = levels.length;1232int olen = objects.length;12331234try {1235Bidi.reorderVisually(null, 0, objects, 0, count);1236errorHandling("reorderVisually() should throw a NPE " +1237"when levels is null.");1238}1239catch (NullPointerException e) {1240}12411242try {1243Bidi.reorderVisually(levels, -1, objects, 0, count);1244errorHandling("reorderVisually() should throw an IAE " +1245"when levelStart is -1.");1246}1247catch (IllegalArgumentException e) {1248if (!e.getMessage().equals(1249"Value levelStart -1 is out of range 0 to " + (llen - 1))) {1250errorHandling("reorderVisually() should throw an IAE" +1251" mentioning levelStart is beyond the levels range. Message: " + e.getMessage());1252}1253}1254catch (ArrayIndexOutOfBoundsException e) {1255errorHandling("reorderVisually() should not throw an AIOoBE " +1256"but an IAE when levelStart is -1.");1257}12581259try {1260Bidi.reorderVisually(levels, llen, objects, 0, count);1261errorHandling("reorderVisually() should throw an IAE " +1262"when levelStart is 6(levels.length).");1263}1264catch (IllegalArgumentException e) {1265if (!e.getMessage().equals(1266"Value levelStart " + llen + " is out of range 0 to " + (llen - 1))) {1267errorHandling("reorderVisually() should throw an IAE" +1268" mentioning levelStart is beyond the levels range. Message: " + e.getMessage());1269}1270}1271catch (ArrayIndexOutOfBoundsException e) {1272errorHandling("reorderVisually() should not throw an AIOoBE " +1273"but an IAE when levelStart is 6(levels.length).");1274}12751276try {1277Bidi.reorderVisually(levels, 0, null, 0, count);1278errorHandling("reorderVisually() should throw a NPE" +1279" when objects is null.");1280}1281catch (NullPointerException e) {1282}12831284try {1285Bidi.reorderVisually(levels, 0, objects, -1, count);1286errorHandling("reorderVisually() should throw an IAE" +1287" when objectStart is -1.");1288}1289catch (IllegalArgumentException e) {1290if (!e.getMessage().equals(1291"Value objectStart -1 is out of range 0 to " + (olen - 1))) {1292errorHandling("reorderVisually() should throw an IAE" +1293" mentioning objectStart is beyond the objects range. Message: " + e.getMessage());1294}1295}1296catch (ArrayIndexOutOfBoundsException e) {1297errorHandling("reorderVisually() should not throw an AIOoBE " +1298"but an IAE when objectStart is -1.");1299}13001301try {1302Bidi.reorderVisually(levels, 0, objects, 6, objects.length);1303errorHandling("reorderVisually() should throw an IAE " +1304"when objectStart is 6(objects.length).");1305}1306catch (IllegalArgumentException e) {1307if (!e.getMessage().equals(1308"Value objectStart 6 is out of range 0 to " + (olen - 1))) {1309errorHandling("reorderVisually() should throw an IAE" +1310" mentioning objectStart is beyond the objects range. Message: " + e.getMessage());1311}1312}13131314try {1315Bidi.reorderVisually(levels, 0, objects, 0, -1);1316errorHandling("reorderVisually() should throw an IAE " +1317"when count is -1.");1318}1319catch (IllegalArgumentException e) {1320if (!e.getMessage().equals(1321"Value count -1 is less than zero, or objectStart + count " +1322"is beyond objects length " + olen)) {1323errorHandling("reorderVisually() should throw an IAE" +1324" mentioning objectStart/count is beyond the objects range. Message: " + e.getMessage());1325}1326}1327catch (NegativeArraySizeException e) {1328errorHandling("reorderVisually() should not throw an NASE " +1329"but an IAE when count is -1.");1330}13311332try {1333Bidi.reorderVisually(levels, 0, objects, 0, count+1);1334errorHandling("reorderVisually() should throw an IAE " +1335"when count is 7(objects.length+1).");1336}1337catch (IllegalArgumentException e) {1338if (!e.getMessage().equals(1339"Value count " + (count + 1) + " is less than zero, or objectStart + count " +1340"is beyond objects length " + olen)) {1341errorHandling("reorderVisually() should throw an IAE" +1342" mentioning objectStart/count is beyond the objects range. Message: " + e.getMessage());1343}1344}1345catch (ArrayIndexOutOfBoundsException e) {1346errorHandling("reorderVisually() should not throw an AIOoBE " +1347"but an IAE when count is 7(objects.length+1).");1348}13491350try {1351Bidi.reorderVisually(levels, 0, objects, 0, 0);1352checkResult("reorderVisually(count=0)",1353data4reorderVisually[0][0], objects);1354}1355catch (Exception e) {1356errorHandling("reorderVisually() should not throw an exception" +1357" when count is 0.");1358}1359}13601361private void testMethod_requiresBidi() {1362System.out.println("*** Test requiresBidi()");13631364String paragraph;1365char[] text;1366Bidi bidi;13671368for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {1369paragraph = data4Constructor2[textNo][0];1370text = paragraph.toCharArray();1371boolean rBidi = Bidi.requiresBidi(text, 0, text.length);1372if (rBidi != requiresBidi4Constructor2[textNo]) {1373error = true;1374System.err.println("Unexpected requiresBidi() value" +1375" for requiresBidi(\"" + paragraph + "\", " + 0 + ", " +1376text.length + ")." +1377"\n Expected: " + requiresBidi4Constructor2[textNo] +1378"\n Got : " + rBidi);1379} else if (verbose) {1380System.out.println(" Okay : requiresBidi() for" +1381" requiresBidi(\"" + paragraph + "\", " + 0 + ", " +1382text.length + ") Got: " + rBidi);1383}1384}13851386char[] txt = {'A', 'B', 'C', 'D', 'E'};1387int textLength = txt.length;13881389try {1390Bidi.requiresBidi(txt, -1, textLength);1391errorHandling("requiresBidi() should throw an IAE" +1392" when start is -1(too small).");1393}1394catch (IllegalArgumentException e) {1395}1396catch (ArrayIndexOutOfBoundsException e) {1397errorHandling("requiresBidi() should not throw an AIOoBE " +1398"but an IAE when start is -1(too small).");1399}14001401try {1402Bidi.requiresBidi(txt, textLength, textLength);1403}1404catch (Exception e) {1405errorHandling("requiresBidi() should not throw an exception " +1406"when start is textLength.");1407}14081409try {1410Bidi.requiresBidi(txt, textLength+1, textLength);1411errorHandling("requiresBidi() should throw an IAE" +1412" when start is textLength+1(too large).");1413}1414catch (IllegalArgumentException e) {1415}14161417try {1418Bidi.requiresBidi(txt, 0, -1);1419errorHandling("requiresBidi() should throw an IAE" +1420" when limit is -1(too small).");1421}1422catch (IllegalArgumentException e) {1423}14241425try {1426Bidi.requiresBidi(txt, 0, textLength+1);1427errorHandling("requiresBidi() should throw an IAE" +1428" when limit is textLength+1(too large).");1429}1430catch (IllegalArgumentException e) {1431if (!e.getMessage().equals(1432"Value start 0 is out of range 0 to " + (textLength + 1) +1433", or limit " + (textLength + 1) + " is beyond the text length " + textLength)) {1434errorHandling("requiresBidi() should throw an IAE" +1435" mentioning limit is beyond the text length. Message: " + e.getMessage());1436}1437}1438catch (ArrayIndexOutOfBoundsException e) {1439errorHandling("requiresBidi() should not throw an AIOoBE " +1440"but an IAE when limit is textLength+1(too large).");1441}1442}14431444private void checkResult(String name,1445int expectedValue,1446int actualValue) {1447if (expectedValue != actualValue) {1448errorHandling("Unexpected " + name + " value." +1449" Expected: " + expectedValue + " Got: " + actualValue);1450} else if (verbose) {1451System.out.println(" Okay : " + name + " = " + actualValue);1452}1453}14541455private void checkResult(String name,1456boolean expectedValue,1457boolean actualValue) {1458if (expectedValue != actualValue) {1459errorHandling("Unexpected " + name + " value." +1460" Expected: " + expectedValue + " Got: " + actualValue);1461} else if (verbose) {1462System.out.println(" Okay : " + name + " = " + actualValue);1463}1464}14651466private void checkResult(String name,1467String expectedValue,1468String actualValue) {1469if (!expectedValue.equals(actualValue)) {1470errorHandling("Unexpected " + name + " value." +1471"\n\tExpected: \"" + expectedValue + "\"" +1472"\n\tGot: \"" + actualValue + "\"");1473} else if (verbose) {1474System.out.println(" Okay : " + name + " = \"" +1475actualValue + "\"");1476}1477}14781479private void checkResult(String name,1480int[] expectedValues,1481int[] actualValues) {1482if (!Arrays.equals(expectedValues, actualValues)) {1483errorHandling("Unexpected " + name + " value." +1484"\n\tExpected: " + toString(expectedValues) + "" +1485"\n\tGot: " + toString(actualValues) + "");1486} else if (verbose) {1487System.out.println(" Okay : " + name + " = " +1488toString(actualValues));1489}1490}14911492private void checkResult(String name,1493Object[] expectedValues,1494Object[] actualValues) {1495if (!Arrays.equals(expectedValues, actualValues)) {1496errorHandling("Unexpected " + name + " value." +1497"\n\tExpected: [" + toString(expectedValues) +1498"]\n\tGot: [" + toString(actualValues) + "]");1499} else if (verbose) {1500System.out.println(" Okay : " + name + " Reordered objects = [" +1501toString(actualValues) + "]");1502}1503}15041505private void errorHandling(String msg) {1506if (abort) {1507throw new RuntimeException("Error: " + msg);1508} else {1509error = true;1510System.err.println("**Error:" + msg);1511}1512}15131514private String toString(int[] values) {1515StringBuilder sb = new StringBuilder();1516for (int i = 0; i < values.length-1; i++) {1517sb.append((int)values[i]);1518sb.append(' ');1519}1520sb.append((int)values[values.length-1]);15211522return sb.toString();1523}15241525private String toString(byte[] values) {1526StringBuilder sb = new StringBuilder();1527for (int i = 0; i < values.length-1; i++) {1528sb.append((byte)values[i]);1529sb.append(' ');1530}1531sb.append((byte)values[values.length-1]);15321533return sb.toString();1534}15351536private String toString(Object[] values) {1537StringBuilder sb = new StringBuilder();1538String name;15391540for (int i = 0; i < values.length-1; i++) {1541if ((name = getStringName((String)values[i])) != null) {1542sb.append(name);1543sb.append(", ");1544} else {1545sb.append('"');1546sb.append((String)values[i]);1547sb.append("\", ");1548}1549}1550if ((name = getStringName((String)values[values.length-1])) != null) {1551sb.append(name);1552} else {1553sb.append('"');1554sb.append((String)values[values.length-1]);1555sb.append('\"');1556}15571558return sb.toString();1559}15601561private String getStringName(String str) {1562if (ArabicABC.equals(str)) return "ArabicABC";1563else if (Arabic123.equals(str)) return "Arabic123";1564else if (PArabicABC.equals(str)) return "ArabicABC(Presentation form)";1565else if (HebrewABC.equals(str)) return "HebrewABC";1566else if (KharoshthiABC.equals(str)) return "KharoshthiABC(RTL)";1567else if (Kharoshthi123.equals(str)) return "Kharoshthi123(RTL)";1568else if (NKoABC.equals(str)) return "NKoABC(RTL)";1569else if (NKo123.equals(str)) return "NKo123(RTL)";1570else if (OsmanyaABC.equals(str)) return "OsmanyaABC(LTR)";1571else if (Osmanya123.equals(str)) return "Osmanya123(LTR)";1572else return null;1573}15741575private String getFlagName(int flag) {1576if (flag == -2 || flag == 0x7e) return FLAGNAMES[0];1577else if (flag == -1 || flag == 0x7f) return FLAGNAMES[1];1578else if (flag == 0) return FLAGNAMES[2];1579else if (flag == 1) return FLAGNAMES[3];1580else return "Unknown(0x" + Integer.toHexString(flag) + ")";1581}15821583private String toReadableString(String str) {1584String s = str;15851586s = s.replaceAll(ArabicABC, "ArabicABC");1587s = s.replaceAll(Arabic123, "Arabic123");1588s = s.replaceAll(PArabicABC, "ArabicABC(Presentation form)");1589s = s.replaceAll(HebrewABC, "HebrewABC");1590s = s.replaceAll(KharoshthiABC, "KharoshthiABC");1591s = s.replaceAll(Kharoshthi123, "Kharoshthi123");1592s = s.replaceAll(NKoABC, "NKoABC");1593s = s.replaceAll(NKo123, "NKo123");1594s = s.replaceAll(OsmanyaABC, "OsmanyaABC");1595s = s.replaceAll(Osmanya123, "Osmanya123");15961597return s;1598}15991600private byte[] getLevels(Object[][] data) {1601int levelLength = data[0].length;1602byte[] array = new byte[levelLength];1603int textIndex = 0;16041605for (int i = 0; i < levelLength; i++) {1606array[i] = (byte)(((String)data[1][0]).charAt(textIndex) - '0');1607textIndex += ((String)data[0][i]).length();1608}16091610return array;1611}161216131614/* Bidi pubilc constants */1615private static final int[] FLAGS = {1616Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT, // -2 (0x7e in ICU4J)1617Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT, // -1 (0x7f in ICU4J)1618Bidi.DIRECTION_LEFT_TO_RIGHT, // 01619Bidi.DIRECTION_RIGHT_TO_LEFT // 11620};16211622/* Bidi pubilc constants names */1623private static final String[] FLAGNAMES = {1624"DIRECTION_DEFAULT_LEFT_TO_RIGHT", // -21625"DIRECTION_DEFAULT_RIGHT_TO_LEFT", // -11626"DIRECTION_LEFT_TO_RIGHT", // 01627"DIRECTION_RIGHT_TO_LEFT", // 11628};16291630/* Bidirectional Character Types */1631private static final char L = '\u200E';1632private static final char R = '\u202F';1633private static final char LRE = '\u202A';1634private static final char RLE = '\u202B';1635private static final char PDF = '\u202C';1636private static final char LRO = '\u202D';1637private static final char RLO = '\u202E';1638private static final char LRI = '\u2066';1639private static final char RLI = '\u2067';1640private static final char FSI = '\u2068';1641private static final char PDI = '\u2069';16421643/*1644* 0x05D0-0x05EA: [R] Hewbrew letters (Strong)1645* 0x0627-0x063A: [AL] Arabic letters (Strong)1646* 0x0660-0x0669: [AN] Arabic-Indic digits (Weak)1647* 0x07CA-0x07E7: [R] NKo letters (Strong)1648* 0x07C0-0x07C9: [R] NKo digits (Strong)1649* 0xFE50-0xFEFF: [AL] Arabic presentaion form (Strong)1650* 0x10480-0x1049D: [L] Osmanya letters (Strong)1651* 0x104A0-0x104A9: [L] Osmanya digits (Strong)1652* 0x10A10-0x10A33: [R] Kharoshthi letters (Strong)1653* 0x10A40-0x10A43: [R] Kharoshthi digits (Strong)1654*1655* 0x200E: [L] Left-to-right mark (Implicit, Strong)1656* 0x200F: [R] Right-to-left mark (Implicit, Strong)1657* 0x202A: [LRE] Left-to-right embedding (Explicit, Strong)1658* 0x202B: [RLE] Right-to-left embedding (Explicit, Strong)1659* 0x202C: [PDF] Pop directional formatting (Explicit, Weak)1660* 0x202D: [LRO] Left-to-right override (Explicit, Strong)1661* 0x202E: [RLO] Right-to-left override (Explicit, Strong)1662*/16631664/* Right-to-left */1665private static String ArabicABC = "\u0627\u0628\u0629";1666private static String Arabic123 = "\u0661\u0662\u0663";1667private static String PArabicABC = "\uFE97\uFE92\uFE8E";1668private static String HebrewABC = "\u05D0\u05D1\u05D2";1669private static String KharoshthiABC =1670new String(Character.toChars(0x10A10)) +1671new String(Character.toChars(0x10A11)) +1672new String(Character.toChars(0x10A12));1673private static String Kharoshthi123 =1674new String(Character.toChars(0x10A40)) +1675new String(Character.toChars(0x10A41)) +1676new String(Character.toChars(0x10A42));1677private static String NKoABC = "\u07CA\u07CB\u07CC";1678private static String NKo123 = "\u07C1\u07C2\u07C3";16791680/* Left-to-right */1681private static String OsmanyaABC =1682new String(Character.toChars(0x10480)) +1683new String(Character.toChars(0x10481)) +1684new String(Character.toChars(0x10482));1685private static String Osmanya123 =1686new String(Character.toChars(0x104A0)) +1687new String(Character.toChars(0x104A1)) +1688new String(Character.toChars(0x104A2));16891690/* --------------------------------------------------------------------- */16911692/*1693* Test data for Bidi(char[], ...) constructor and methods1694*/16951696/* Text for Bidi processing and its levels */1697private static String[][] data4Constructor1 = {1698/* For Text #0 */1699{"abc <ABC XYZ> xyz.",1700"000000000000000000", "000002222222000000", "000000000000000000",1701"000003333333000000", "000000000000000000",1702"222222222222222221", "222222222222222221", "222222222222222221",1703"222113333333112221", "222224444444222221",1704"000000000000000000", "000000000000000000", "222222222222222221"},17051706/* For Text #1 */1707{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",1708"000001111111000000", "000001111111000000", "000003333333000000",1709"000003333333000000", "000000000000000000",1710"222111111111112221", "222111111111112221", "222223333333222221",1711"222113333333112221", "222224444444222221",1712"000001111111000000", "000001111111000000", "222111111111112221"},17131714/* For Text #2 */1715{NKoABC + " <ABC XYZ> " + NKo123 + ".",1716"111000000000001110", "111112222222111110", "111002222222001110",1717"111113333333111110", "111004444444001110",1718"111112222222111111", "111112222222111111", "111112222222111111",1719"111111111111111111", "111114444444111111",1720"111112222222111111", "111000000000001110", "111112222222111111"},17211722/* For Text #3 */1723{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",1724"111111111222111110", "111111111222111110", "111003333444001110",1725"111113333333111110", "111004444444001110",1726"111111111222111111", "111111111222111111", "111113333444111111",1727"111111111111111111", "111114444444111111",1728"111111111222111111", "111111111222111110", "111111111222111111"},17291730/* For Text #4 */1731{"abc <" + NKoABC + " 123> xyz.",1732"000001111222000000", "000001111222000000", "000003333444000000",1733"000003333333000000", "000000000000000000",1734"222111111222112221", "222111111222112221", "222223333444222221",1735"222113333333112221", "222224444444222221",1736"000001111222000000", "000001111222000000", "222111111222112221"},17371738/* For Text #5 */1739{"abc <ABC " + NKo123 + "> xyz.",1740"000000000111000000", "000002221111000000", "000002222333000000",1741"000003333333000000", "000000000000000000",1742"222222221111112221", "222222221111112221", "222222222333222221",1743"222113333333112221", "222224444444222221",1744"000000000111000000", "000000000111000000", "222222221111112221"},17451746/* For Text #6 */1747{ArabicABC + " <" + NKoABC + " 123" + "> " + Arabic123 + ".",1748"111111111222112220", "111111111222112220", "111003333444002220",1749"111113333333112220", "111004444444002220",1750"111111111222112221", "111111111222112221", "111113333444112221",1751"111113333333112221", "111114444444112221",1752"111111111222112221", "111111111222112220", "111111111222112221"},17531754/* For Text #7 */1755{ArabicABC + " <XYZ " + NKoABC + "> " + Arabic123 + ".",1756"111000000111112220", "111112221111112220", "111002222333002220",1757"111113333333112220", "111004444444002220",1758"111112221111112221", "111112221111112221", "111112222333112221",1759"111113333333112221", "111114444444112221",1760"111112221111112221", "111000000111112220", "111112221111112221"},17611762/* For Text #8 */1763{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +1764Osmanya123 + ".",1765"000000001111111111111000000000", "000000001111111111111000000000",1766"000000003333333333333000000000", "000000003333333333333000000000",1767"000000000000000000000000000000",1768"222222111111111111111112222221", "222222111111111111111112222221",1769"222222223333333333333222222221", "222222113333333333333112222221",1770"222222224444444444444222222221",1771"000000001111111111111000000000", "000000001111111111111000000000",1772"222222111111111111111112222221"},17731774/* For Text #9 */1775{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +1776Kharoshthi123 + ".",1777"111111000000000000000001111110", "111111112222222222222111111110",1778"111111002222222222222001111110", "111111113333333333333111111110",1779"111111004444444444444001111110",1780"111111112222222222222111111111", "111111112222222222222111111111",1781"111111112222222222222111111111", "111111111111111111111111111111",1782"111111114444444444444111111111",1783"111111112222222222222111111111", "111111000000000000000001111110",1784"111111112222222222222111111111"},1785};17861787/* Golden data for baseIsLeftToRight() results */1788private static boolean[][] baseIsLTR4Constructor1 = {1789/* For Text #0 */1790{true, true, true, true, true,1791false, false, false, false, false,1792true, true, false},17931794/* For Text #1 */1795{true, true, true, true, true,1796false, false, false, false, false,1797true, true, false},17981799/* For Text #2 */1800{true, true, true, true, true,1801false, false, false, false, false,1802false, true, false},18031804/* For Text #3 */1805{true, true, true, true, true,1806false, false, false, false, false,1807false, true, false},18081809/* For Text #4 */1810{true, true, true, true, true,1811false, false, false, false, false,1812true, true, false},18131814/* For Text #5 */1815{true, true, true, true, true,1816false, false, false, false, false,1817true, true, false},18181819/* For Text #6 */1820{true, true, true, true, true,1821false, false, false, false, false,1822false, true, false},18231824/* For Text #7 */1825{true, true, true, true, true,1826false, false, false, false, false,1827false, true, false},18281829/* For Text #8 */1830{true, true, true, true, true,1831false, false, false, false, false,1832true, true, false},18331834/* For Text #9 */1835{true, true, true, true, true,1836false, false, false, false, false,1837false, true, false},1838};18391840/* Golden data for isLeftToRight() & isRightToLeft() results */1841private static boolean[][][] isLTR_isRTL4Constructor1 = {1842/* For Text #0 */1843/* isLeftToRight() results */1844{{true, false, true, false, true,1845false, false, false, false, false,1846true, true, false},1847/* isRightToLeft() results */1848{false, false, false, false, false,1849false, false, false, false, false,1850false, false, false}},18511852/* For Text #1 */1853/* isLeftToRight() results */1854{{false, false, false, false, true,1855false, false, false, false, false,1856false, false, false},1857/* isRightToLeft() results */1858{false, false, false, false, false,1859false, false, false, false, false,1860false, false, false}},18611862/* For Text #2 */1863/* isLeftToRight() results */1864{{false, false, false, false, false,1865false, false, false, false, false,1866false, false, false},1867/* isRightToLeft() results */1868{false, false, false, false, false,1869false, false, false, true, false,1870false, false, false}},18711872/* For Text #3 */1873/* isLeftToRight() results */1874{{false, false, false, false, false,1875false, false, false, false, false,1876false, false, false},1877/* isRightToLeft() results */1878{false, false, false, false, false,1879false, false, false, true, false,1880false, false, false}},18811882/* For Text #4 */1883/* isLeftToRight() results */1884{{false, false, false, false, true,1885false, false, false, false, false,1886false, false, false},1887/* isRightToLeft() results */1888{false, false, false, false, false,1889false, false, false, false, false,1890false, false, false}},18911892/* For Text #5 */1893/* isLeftToRight() results */1894{{false, false, false, false, true,1895false, false, false, false, false,1896false, false, false},1897/* isRightToLeft() results */1898{false, false, false, false, false,1899false, false, false, false, false,1900false, false, false}},19011902/* For Text #6 */1903/* isLeftToRight() results */1904{{false, false, false, false, false,1905false, false, false, false, false,1906false, false, false},1907/* isRightToLeft() results */1908{false, false, false, false, false,1909false, false, false, false, false,1910false, false, false}},19111912/* For Text #7 */1913/* isLeftToRight() results */1914{{false, false, false, false, false,1915false, false, false, false, false,1916false, false, false},1917/* isRightToLeft() results */1918{false, false, false, false, false,1919false, false, false, false, false,1920false, false, false}},19211922/* For Text #8 */1923/* isLeftToRight() results */1924{{false, false, false, false, true,1925false, false, false, false, false,1926false, false, false},1927/* isRightToLeft() results */1928{false, false, false, false, false,1929false, false, false, false, false,1930false, false, false}},19311932/* For Text #9 */1933/* isLeftToRight() results */1934{{false, false, false, false, false,1935false, false, false, false, false,1936false, false, false},1937/* isRightToLeft() results */1938{false, false, false, false, false,1939false, false, false, true, false,1940false, false, false}},1941};19421943/* --------------------------------------------------------------------- */19441945/*1946* Test data for Bidi(String, int) constructor and methods1947*/19481949/* Text for Bidi processing and its levels */1950private static String[][] data4Constructor2 = {1951/* For Text #0 */1952{" ABC 123.",1953"000000000", "000000000", "000000000", "122222221"},19541955/* For Text #1 */1956{" ABC " + HebrewABC + " " + NKo123 + " 123.",1957"00000111111112220", "00000111111112220", "00000111111112220",1958"12221111111112221"},19591960/* For Text #2 */1961{" ABC " + ArabicABC + " " + Arabic123 + " 123.",1962"00000111122212220", "00000111122212220", "00000111122212220",1963"12221111122212221"},19641965/* For Text #3 */1966{" " + NKoABC + " ABC 123 " + NKo123 + ".",1967"11111222222211111", "11111222222211111", "01110000000001110",1968"11111222222211111"},19691970/* For Text #4 */1971{" " + ArabicABC + " ABC 123 " + Arabic123 + ".",1972"11111222222212221", "11111222222212221", "01110000000002220",1973"11111222222212221"},19741975/* For Text #5 */1976{" " + HebrewABC + " " + NKo123 + ".",1977"111111111", "111111111", "011111110", "111111111"},19781979/* For Text #6 */1980{" " + ArabicABC + " " + Arabic123 + ".",1981"111112221", "111112221", "011112220", "111112221"},19821983/* For Text #7 */1984{" " + KharoshthiABC + " " + Kharoshthi123 + ".",1985"111111111111111", "111111111111111", "011111111111110",1986"111111111111111"},19871988/* For Text #8 */1989{L + HebrewABC + " " + NKo123 + ".",1990"011111110", "011111110", "011111110", "211111111"},19911992/* For Text #9 */1993{R + "ABC " + Osmanya123 + ".",1994"000000000000", "000000000000", "000000000000", "122222222221"},19951996/* For Text #10 */1997{"ABC " + PArabicABC + " " + PArabicABC + " 123",1998"000011111111222", "000011111111222", "000011111111222",1999"222111111111222"},20002001/* For Text #11 */2002{RLE + "ABC " + HebrewABC + " " + NKo123 + "." + PDF,2003"22221111111110", "22221111111110", "22221111111110",2004"44443333333331"},20052006/* For Text #12 */2007{"He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF + ".\"",2008"000000000222211111111000", "000000000222211111111000",2009"000000000222211111111000", "222222211444433333333111"},20102011/* For Text #13 */2012{LRO + "He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF +2013".\"" + PDF,2014"22222222224444333333332220", "22222222224444333333332220",2015"22222222224444333333332220", "22222222224444333333332221"},20162017/* For Text #14 */2018{LRO + "He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF +2019".\"", // PDF missing2020"2222222222444433333333222", "2222222222444433333333222",2021"2222222222444433333333222", "2222222222444433333333222"},20222023/* For Text #15 */2024{"Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +2025" " + NKo123 + PDF + "\"" + PDF + "'?",2026"0000000000000222222222244443333333322000",2027"0000000000000222222222244443333333322000",2028"0000000000000222222222244443333333322000",2029"2222222222222222222222244443333333322111"},20302031/* For Text #16 */2032{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +2033HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?" + PDF,2034"111111111111112222222222444433333333221110",2035"111111111111112222222222444433333333221110",2036"111111111111112222222222444433333333221110",2037"333333333333334444444444666655555555443331"},20382039/* For Text #17 */2040{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +2041HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?", // PDF missing2042"11111111111111222222222244443333333322111",2043"11111111111111222222222244443333333322111",2044"11111111111111222222222244443333333322111",2045"33333333333333444444444466665555555544333"},20462047/* For Text #18 */2048{" ABC (" + ArabicABC + " " + Arabic123 + ") 123.",2049"0000001111222002220", "0000001111222002220",2050"0000001111222002220", "1222111111222112221"},20512052/* For Text #19 */2053{" " + HebrewABC + " (ABC 123) " + NKo123 + ".",2054"1111112222222111111", "1111112222222111111",2055"0111000000000001110", "1111112222222111111"},20562057/* For Text #20 */2058{" He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF + ".\" ",2059"00000000002222111111110000", "00000000002222111111110000",2060"00000000002222111111110000", "12222222114444333333331111"},20612062/* For Text #21 */2063{" Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +2064" " + NKo123 + PDF + "\"" + PDF + "'? ",2065"000000000000002222222222444433333333220000",2066"000000000000002222222222444433333333220000",2067"000000000000002222222222444433333333220000",2068"122222222222222222222222444433333333221111"},20692070/* For Text #22 */2071{RLE + OsmanyaABC + " " + KharoshthiABC + " " + Kharoshthi123 + "." +2072PDF,2073"22222221111111111111110", "22222221111111111111110",2074"22222221111111111111110", "44444443333333333333331"},20752076/* For Text #23 */2077{" ABC (" + Arabic123 + " " + ArabicABC + ") 123.",2078"0000002221111002220", "0000002221111002220",2079"0000002221111002220", "1222112221111112221"},20802081/* For Text #24 */2082{" 123 (" + ArabicABC + " " + Arabic123 + ") ABC.",2083"1222111111222112221", "1222111111222112221",2084"0000001111222000000", "1222111111222112221"},20852086/* For Text #25 */2087{" 123 (" + Arabic123 + " " + ArabicABC + ") ABC.",2088"1222112221111112221", "1222112221111112221",2089"0000002221111000000", "1222112221111112221"},20902091/* For Text #26 */2092{" " + ArabicABC + " (ABC 123) " + Arabic123 + ".",2093"1111112222222112221", "1111112222222112221",2094"0111000000000002220", "1111112222222112221"},20952096/* For Text #27 */2097{" " + ArabicABC + " (123 ABC) " + Arabic123 + ".",2098"1111112221222112221", "1111112221222112221",2099"0111002220000002220", "1111112221222112221"},21002101/* For Text #28 */2102{" " + Arabic123 + " (ABC 123) " + ArabicABC + ".",2103"0222000000000001110", "0222000000000001110",2104"0222000000000001110", "1222112222222111111"},21052106/* For Text #29 */2107{" " + Arabic123 + " (123 ABC) " + ArabicABC + ".",2108"0222000000000001110", "0222000000000001110",2109"0222000000000001110", "1222112221222111111"},21102111/* For Text #30 */2112{RLI + "ABC " + ArabicABC + " " + ArabicABC + "." + PDI,2113"02221111111110", "14443333333331",2114"02221111111110", "14443333333331"},21152116/* For Text #31 */2117{"ABC abc \"" + RLI + "IJK " + ArabicABC + " " + ArabicABC + PDI +2118".\" \"" + RLI + ArabicABC + " " + ArabicABC + PDI + ",\" xyz XYZ.",2119"0000000000222111111110000001111111000000000000",2120"0000000000222111111110000001111111000000000000",2121"0000000000222111111110000001111111000000000000",2122"2222222222444333333332222223333333222222222221"},21232124/* For Text #32 */2125{ArabicABC + " " + ArabicABC + " '" + LRI + "abc def \"" + RLI +2126"xyz " + ArabicABC + " " + ArabicABC + PDI + "\"" + PDI + "'?",2127"111111111122222222224443333333322111",2128"111111111122222222224443333333322111",2129"111111100022222222224443333333322000",2130"111111111122222222224443333333322111"},21312132/* For Text #33 */2133{FSI + Arabic123 + " ABC " + ArabicABC + " " + ArabicABC + "." + PDI,2134"044422222333333320", "144422222333333321",2135"044422222333333320", "144422222333333321"},21362137/* For Text #34 */2138{FSI + "123 ABC " + ArabicABC + " " + ArabicABC + "." + PDI,2139"022222222333333320", "122222222333333321",2140"022222222333333320", "122222222333333321"},21412142/* For Text #35 */2143{FSI + "123 " + ArabicABC + " ABC " + ArabicABC + "." + PDI,2144"022211111222111110", "144433333444333331",2145"022211111222111110", "144433333444333331"},21462147/* For Text #36 */2148{FSI + Arabic123 + " " + ArabicABC + " ABC " + ArabicABC + "." + PDI,2149"022211111222111110", "144433333444333331",2150"022211111222111110", "144433333444333331"},21512152/* For Text #37 */2153{FSI + Arabic123 + " 123." + PDI,2154"0444222220", "1444222221", "0444222220", "1444222221"},21552156/* For Text #38 */2157{FSI + "123 " + Arabic123 + "." + PDI,2158"0222244420", "1222244421", "0222244420", "1222244421"},2159};21602161/* Golden data for baseIsLeftToRight() results */2162private static boolean[][] baseIsLTR4Constructor2 = {2163/* For Text #0 - $4 */2164{true, true, true, false},2165{true, true, true, false},2166{true, true, true, false},2167{false, false, true, false},2168{false, false, true, false},21692170/* For Text #5 - $9 */2171{false, false, true, false},2172{false, false, true, false},2173{false, false, true, false},2174{true, true, true, false},2175{true, true, true, false},21762177/* For Text #10 - $14 */2178{true, true, true, false},2179{true, true, true, false},2180{true, true, true, false},2181{true, true, true, false},2182{true, true, true, false},21832184/* For Text #15 - $19 */2185{true, true, true, false},2186{true, true, true, false},2187{true, true, true, false},2188{true, true, true, false},2189{false, false, true, false},21902191/* For Text #20 - $24 */2192{true, true, true, false},2193{true, true, true, false},2194{true, true, true, false},2195{true, true, true, false},2196{false, false, true, false},21972198/* For Text #25 - $29 */2199{false, false, true, false},2200{false, false, true, false},2201{false, false, true, false},2202{true, true, true, false},2203{true, true, true, false},22042205/* For Text #30 - $34 */2206{true, false, true, false},2207{true, true, true, false},2208{false, false, true, false},2209{true, false, true, false},2210{true , false, true, false},22112212/* For Text #35 - $38 */2213{true, false, true, false},2214{true, false, true, false},2215{true, false, true, false},2216{true, false, true, false},2217};22182219/* Golden data for isLeftToRight() & isRightToLeft() results */2220private static boolean[][][] isLTR_isRTL4Constructor2 = {2221/* isLeftToRight() results & isRightToLeft() results */2222/* For Text #0 - $4 */2223{{true, true, true, false}, {false, false, false, false}},2224{{false, false, false, false}, {false, false, false, false}},2225{{false, false, false, false}, {false, false, false, false}},2226{{false, false, false, false}, {false, false, false, false}},2227{{false, false, false, false}, {false, false, false, false}},22282229/* For Text #5 - $9 */2230{{false, false, false, false}, {true, true, false, true }},2231{{false, false, false, false}, {false, false, false, false}},2232{{false, false, false, false}, {true, true, false, true }},2233{{false, false, false, false}, {false, false, false, false}},2234{{true, true, true, false}, {false, false, false, false}},22352236/* For Text #10 - $14 */2237{{false, false, false, false}, {false, false, false, false}},2238{{false, false, false, false}, {false, false, false, false}},2239{{false, false, false, false}, {false, false, false, false}},2240{{false, false, false, false}, {false, false, false, false}},2241{{false, false, false, false}, {false, false, false, false}},22422243/* For Text #15 - $19 */2244{{false, false, false, false}, {false, false, false, false}},2245{{false, false, false, false}, {false, false, false, false}},2246{{false, false, false, false}, {false, false, false, false}},2247{{false, false, false, false}, {false, false, false, false}},2248{{false, false, false, false}, {false, false, false, false}},22492250/* For Text #20 - $24 */2251{{false, false, false, false}, {false, false, false, false}},2252{{false, false, false, false}, {false, false, false, false}},2253{{false, false, false, false}, {false, false, false, false}},2254{{false, false, false, false}, {false, false, false, false}},2255{{false, false, false, false}, {false, false, false, false}},22562257/* For Text #25 - $29 */2258{{false, false, false, false}, {false, false, false, false}},2259{{false, false, false, false}, {false, false, false, false}},2260{{false, false, false, false}, {false, false, false, false}},2261{{false, false, false, false}, {false, false, false, false}},2262{{false, false, false, false}, {false, false, false, false}},22632264/* For Text #30 - $34 */2265{{false, false, false, false}, {false, false, false, false}},2266{{false, false, false, false}, {false, false, false, false}},2267{{false, false, false, false}, {false, false, false, false}},2268{{false, false, false, false}, {false, false, false, false}},2269{{false, false, false, false}, {false, false, false, false}},22702271/* For Text #35 - $37 */2272{{false, false, false, false}, {false, false, false, false}},2273{{false, false, false, false}, {false, false, false, false}},2274{{false, false, false, false}, {false, false, false, false}},2275{{false, false, false, false}, {false, false, false, false}},2276};22772278/* Golden data for requiresBidi() results */2279private static boolean[] requiresBidi4Constructor2 = {2280/* For Text #0 - $9 */2281false, true, true, true, true,2282true, true, true, true, false,22832284/* For Text #10 - $19 */2285true, true, true, true, true,2286true, true, true, true, true,22872288/* For Text #20 - $29 */2289true, true, true, true, true,2290true, true, true, true, true,22912292/* For Text #30 - $37 */2293true, true, true, true, true,2294true, true, true, true,2295};22962297/* --------------------------------------------------------------------- */22982299/*2300* Test data for Bidi(char[], ...) constructor and methods2301*/23022303/* Enbeddings */2304private static byte[][][] emb4Constructor3 = {2305/* Embeddings for paragraphs which don't include surrogate pairs. */2306{{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},2307{0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0},2308{0, 0, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, 0, 0, 0, 0, 0, 0},2309{0, 0, 0, 0, 0, -4, -4, -4, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0}},23102311/* Embeddings for paragraphs which include surrogate pairs. */2312{{ 0, 0, 0, 0, 0, 0, 0, 0,23131, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,23140, 0, 0, 0, 0, 0, 0, 0, 0},2315{ 0, 0, 0, 0, 0, 0, 0, 0,23162, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,23170, 0, 0, 0, 0, 0, 0, 0, 0},2318{ 0, 0, 0, 0, 0, 0, 0, 0,2319-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,23200, 0, 0, 0, 0, 0, 0, 0, 0},2321{ 0, 0, 0, 0, 0, 0, 0, 0,2322-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,23230, 0, 0, 0, 0, 0, 0, 0, 0}},2324};23252326/* Text for Bidi processing and its levels */2327private static String[][] data4Constructor3 = {2328/* For Text #0 */2329{"abc <ABC XYZ> xyz.",2330/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2331"000002222222000000", "000000000000000000",2332"000003333333000000", "000000000000000000",2333/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2334"222222222222222221", "222222222222222221",2335"222113333333112221", "222224444444222221",2336/* DIRECTION_LEFT_TO_RIGHT */2337"000002222222000000", "000000000000000000",2338"000003333333000000", "000000000000000000",2339/* DIRECTION_RIGHT_TO_LEFT */2340"222222222222222221", "222222222222222221",2341"222113333333112221", "222224444444222221"},23422343/* For Text #1 */2344{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",2345/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2346"000001111111000000", "000003333333000000",2347"000003333333000000", "000000000000000000",2348/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2349"222111111111112221", "222223333333222221",2350"222113333333112221", "222224444444222221",2351/* DIRECTION_LEFT_TO_RIGHT */2352"000001111111000000", "000003333333000000",2353"000003333333000000", "000000000000000000",2354/* DIRECTION_RIGHT_TO_LEFT */2355"222111111111112221", "222223333333222221",2356"222113333333112221", "222224444444222221"},23572358/* For Text #2 */2359{NKoABC + " <ABC XYZ> " + NKo123 + ".",2360/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2361"111112222222111111", "111112222222111111",2362"111111111111111111", "111114444444111111",2363/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2364"111112222222111111", "111112222222111111",2365"111111111111111111", "111114444444111111",2366/* DIRECTION_LEFT_TO_RIGHT */2367"111112222222111110", "111002222222001110",2368"111113333333111110", "111004444444001110",2369/* DIRECTION_RIGHT_TO_LEFT */2370"111112222222111111", "111112222222111111",2371"111111111111111111", "111114444444111111"},23722373/* For Text #3 */2374{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",2375/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2376"111111111222111111", "111113333444111111",2377"111111111111111111", "111114444444111111",2378/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2379"111111111222111111", "111113333444111111",2380"111111111111111111", "111114444444111111",2381/* DIRECTION_LEFT_TO_RIGHT */2382"111111111222111110", "111003333444001110",2383"111113333333111110", "111004444444001110",2384/* DIRECTION_RIGHT_TO_LEFT */2385"111111111222111111", "111113333444111111",2386"111111111111111111", "111114444444111111"},23872388/* For Text #4 */2389{"abc <123 456> xyz.",2390/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2391"000002221222000000", "000000000000000000",2392"000003333333000000", "000000000000000000",2393/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2394"222222222222222221", "222222222222222221",2395"222113333333112221", "222224444444222221",2396/* DIRECTION_LEFT_TO_RIGHT */2397"000002221222000000", "000000000000000000",2398"000003333333000000", "000000000000000000",2399/* DIRECTION_RIGHT_TO_LEFT */2400"222222222222222221", "222222222222222221",2401"222113333333112221", "222224444444222221"},24022403/* For Text #5 */2404{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +2405Osmanya123 + ".",2406/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2407"000000001111111111111000000000", "000000003333333333333000000000",2408"000000003333333333333000000000", "000000000000000000000000000000",2409/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2410"222222111111111111111112222221", "222222223333333333333222222221",2411"222222113333333333333112222221", "222222224444444444444222222221",2412/* DIRECTION_LEFT_TO_RIGHT */2413"000000001111111111111000000000", "000000003333333333333000000000",2414"000000003333333333333000000000", "000000000000000000000000000000",2415/* DIRECTION_RIGHT_TO_LEFT */2416"222222111111111111111112222221", "222222223333333333333222222221",2417"222222113333333333333112222221", "222222224444444444444222222221"},24182419/* For Text #6 */2420{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +2421Kharoshthi123 + ".",2422/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2423"111111112222222222222111111111", "111111112222222222222111111111",2424"111111111111111111111111111111", "111111114444444444444111111111",2425/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2426"111111112222222222222111111111", "111111112222222222222111111111",2427"111111111111111111111111111111", "111111114444444444444111111111",2428/* DIRECTION_LEFT_TO_RIGHT */2429"111111112222222222222111111110", "111111002222222222222001111110",2430"111111113333333333333111111110", "111111004444444444444001111110",2431/* DIRECTION_RIGHT_TO_LEFT */2432"111111112222222222222111111111", "111111112222222222222111111111",2433"111111111111111111111111111111", "111111114444444444444111111111"},2434};24352436/* Golden data for baseIsLeftToRight() results */2437private static boolean[][] baseIsLTR4Constructor3 = {2438/* For Text #0 */2439{true, true, true, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2440true, true, true, true, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2441true, true, true, true, // DIRECTION_LEFT_TO_RIGHT2442false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT24432444/* For Text #1 */2445{true, true, true, true,2446true, true, true, true,2447true, true, true, true,2448false, false, false, false},24492450/* For Text #2 */2451{false, false, false, false,2452false, false, false, false,2453true, true, true, true,2454false, false, false, false},24552456/* For Text #3 */2457{false, false, false, false,2458false, false, false, false,2459true, true, true, true,2460false, false, false, false},24612462/* For Text #4 */2463{true, true, true, true,2464true, true, true, true,2465true, true, true, true,2466false, false, false, false},24672468/* For Text #5 */2469{true, true, true, true,2470true, true, true, true,2471true, true, true, true,2472false, false, false, false},24732474/* For Text #6 */2475{false, false, false, false,2476false, false, false, false,2477true, true, true, true,2478false, false, false, false},2479};24802481/* Golden data for isLeftToRight() & isRightToLeft() results */2482private static boolean[][][] isLTR_isRTL4Constructor3 = {2483/* For Text #0 */2484/* isLeftToRight() results */2485{{false, true, false, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2486false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2487false, true, false, true, // DIRECTION_LEFT_TO_RIGHT2488false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT2489/* isRightToLeft() results */2490{false, false, false, false, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2491false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2492false, false, false, false, // DIRECTION_LEFT_TO_RIGHT2493false, false, false, false}}, // DIRECTION_RIGHT_TO_LEFTT24942495/* For Text #1 */2496/* isLeftToRight() results */2497{{false, false, false, true,2498false, false, false, false,2499false, false, false, true,2500false, false, false, false},2501/* isRightToLeft() results */2502{false, false, false, false,2503false, false, false, false,2504false, false, false, false,2505false, false, false, false}},25062507/* For Text #2 */2508/* isLeftToRight() results */2509{{false, false, false, false,2510false, false, false, false,2511false, false, false, false,2512false, false, false, false},2513/* isRightToLeft() results */2514{false, false, true, false,2515false, false, true, false,2516false, false, false, false,2517false, false, true, false}},25182519/* For Text #3 */2520/* isLeftToRight() results */2521{{false, false, false, false,2522false, false, false, false,2523false, false, false, false,2524false, false, false, false},2525/* isRightToLeft() results */2526{false, false, true, false,2527false, false, true, false,2528false, false, false, false,2529false, false, true, false}},25302531/* For Text #4 */2532/* isLeftToRight() results */2533{{false, true, false, true,2534false, false, false, false,2535false, true, false, true,2536false, false, false, false },2537/* isRightToLeft() results */2538{false, false, false, false,2539false, false, false, false,2540false, false, false, false,2541false, false, false, false}},25422543/* For Text #5 */2544/* isLeftToRight() results */2545{{false, false, false, true,2546false, false, false, false,2547false, false, false, true,2548false, false, false, false},2549/* isRightToLeft() results */2550{false, false, false, false,2551false, false, false, false,2552false, false, false, false,2553false, false, false, false}},25542555/* For Text #6 */2556/* isLeftToRight() results */2557{{false, false, false, false,2558false, false, false, false,2559false, false, false, false,2560false, false, false, false},2561/* isRightToLeft() results */2562{false, false, true, false,2563false, false, true, false,2564false, false, false, false,2565false, false, true, false}},2566};25672568/* --------------------------------------------------------------------- */25692570/*2571* Test data for reorderVisually() methods2572*/25732574private static Object[][][] data4reorderVisually = {2575{{"ABC", " ", "abc", " ", ArabicABC, "."}, // Original text2576{"000000001110"}, // levels2577{"ABC", " ", "abc", " ", ArabicABC, "."}}, // Reordered text25782579{{"ABC", " ", HebrewABC, " ", NKoABC, "."},2580{"222111111111"},2581{".", NKoABC, " ", HebrewABC, " ", "ABC"}},25822583{{OsmanyaABC, " ", HebrewABC, " ", KharoshthiABC, "."},2584{"222222111111111111"},2585{".", KharoshthiABC, " ", HebrewABC, " ", OsmanyaABC,}},25862587{{"ABC", " ", Osmanya123, " ", "\"", OsmanyaABC, " ", Kharoshthi123,2588" ", KharoshthiABC, ".", "\""},2589{"0000000000002222221111111111111100"},2590{"ABC", " ", Osmanya123, " ", "\"", KharoshthiABC, " ", Kharoshthi123,2591" ", OsmanyaABC, ".", "\""}},2592};25932594}259525962597