Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Bidi/BidiConformance.java
38813 views
/*1* Copyright (c) 2009, 2012, 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 685011326* @summary confirm the behavior of new Bidi implementation. (Backward compatibility)27*/2829import java.awt.font.NumericShaper;30import java.awt.font.TextAttribute;31import java.text.AttributedString;32import java.text.Bidi;33import java.util.Arrays;3435public class BidiConformance {3637/* internal flags */38private static boolean error = false;39private static boolean verbose = false;40private static boolean abort = false;4142public static void main(String[] args) {43for (int i = 0; i < args.length; i++) {44String arg = args[i];45if (arg.equals("-verbose")) {46verbose = true;47} else if (arg.equals("-abort")) {48abort = true;49}50}5152BidiConformance bc = new BidiConformance();53bc.test();5455if (error) {56throw new RuntimeException("Failed.");57} else {58System.out.println("Passed.");59}60}6162private void test() {63testConstants();64testConstructors();65testMethods();6667testMethods4Constructor1(); // Bidi(AttributedCharacterIterator)68testMethods4Constructor2(); // Bidi(String, int)69testMethods4Constructor3(); // Bidi(char[], ...)70}7172private void testConstants() {73System.out.println("*** Test constants");7475checkResult("Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT",76-2, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);77checkResult("Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT",78-1, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);79checkResult("Bidi.DIRECTION_LEFT_TO_RIGHT",800, Bidi.DIRECTION_LEFT_TO_RIGHT);81checkResult("Bidi.DIRECTION_RIGHT_TO_LEFT",821, Bidi.DIRECTION_RIGHT_TO_LEFT);83}8485private void testConstructors() {86System.out.println("*** Test constructors");8788testConstructor1(); // Bidi(AttributedCharacterIterator)89testConstructor2(); // Bidi(String, int)90testConstructor3(); // Bidi(char[], ...)91}9293private void testMethods() {94System.out.println("*** Test methods");9596testMethod_createLineBidi1();97testMethod_createLineBidi2();98testMethod_getLevelAt();99testMethod_getRunLevel();100testMethod_getRunLimit();101testMethod_getRunStart();102testMethod_reorderVisually1();103testMethod_reorderVisually2();104testMethod_requiresBidi();105}106107private void testMethods4Constructor1() {108System.out.println("*** Test methods for constructor 1");109110String paragraph;111Bidi bidi;112NumericShaper ns = NumericShaper.getShaper(NumericShaper.ARABIC);113114for (int textNo = 0; textNo < data4Constructor1.length; textNo++) {115paragraph = data4Constructor1[textNo][0];116int start = paragraph.indexOf('<')+1;117int limit = paragraph.indexOf('>');118int testNo;119120System.out.println("*** Test textNo=" + textNo +121": Bidi(AttributedCharacterIterator\"" +122toReadableString(paragraph) + "\") " +123" start=" + start + ", limit=" + limit);124125// Test 0126testNo = 0;127System.out.println(" Test#" + testNo +": RUN_DIRECTION_LTR");128AttributedString astr = new AttributedString(paragraph);129astr.addAttribute(TextAttribute.RUN_DIRECTION,130TextAttribute.RUN_DIRECTION_LTR);131bidi = new Bidi(astr.getIterator());132133callTestEachMethod4Constructor1(textNo, testNo, bidi);134135// Test 1136++testNo;137System.out.println(" Test#" + testNo +138": RUN_DIRECTION_LTR, BIDI_EMBEDDING(1)");139astr = new AttributedString(paragraph);140astr.addAttribute(TextAttribute.RUN_DIRECTION,141TextAttribute.RUN_DIRECTION_LTR);142astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),143start, limit);144bidi = new Bidi(astr.getIterator());145callTestEachMethod4Constructor1(textNo, testNo, bidi);146147// Test 2148++testNo;149System.out.println(" Test#" + testNo +150": RUN_DIERCTION_LTR, BIDI_EMBEDDING(2)");151astr = new AttributedString(paragraph);152astr.addAttribute(TextAttribute.RUN_DIRECTION,153TextAttribute.RUN_DIRECTION_LTR);154astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),155start, limit);156bidi = new Bidi(astr.getIterator());157callTestEachMethod4Constructor1(textNo, testNo, bidi);158159// Test 3160++testNo;161System.out.println(" Test#" + testNo +162": RUN_DIRECTIOIN_LTR, BIDI_EMBEDDING(-3)");163astr = new AttributedString(paragraph);164astr.addAttribute(TextAttribute.RUN_DIRECTION,165TextAttribute.RUN_DIRECTION_LTR);166astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),167start, limit);168bidi = new Bidi(astr.getIterator());169callTestEachMethod4Constructor1(textNo, testNo, bidi);170171// Test 4172++testNo;173System.out.println(" Test#" + testNo +174": RUN_DIRECTION_LTR, BIDI_EMBEDDING(-4)");175astr = new AttributedString(paragraph);176astr.addAttribute(TextAttribute.RUN_DIRECTION,177TextAttribute.RUN_DIRECTION_LTR);178astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),179start, limit);180bidi = new Bidi(astr.getIterator());181callTestEachMethod4Constructor1(textNo, testNo, bidi);182183// Test 5184++testNo;185System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL");186astr = new AttributedString(paragraph);187astr.addAttribute(TextAttribute.RUN_DIRECTION,188TextAttribute.RUN_DIRECTION_RTL);189bidi = new Bidi(astr.getIterator());190callTestEachMethod4Constructor1(textNo, testNo, bidi);191192// Test 6193++testNo;194System.out.println(" Test#" + testNo +195": RUN_DIRECTION_RTL, BIDI_EMBEDDING(1)");196astr = new AttributedString(paragraph);197astr.addAttribute(TextAttribute.RUN_DIRECTION,198TextAttribute.RUN_DIRECTION_RTL);199astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),200start, limit);201try {202bidi = new Bidi(astr.getIterator());203callTestEachMethod4Constructor1(textNo, testNo, bidi);204}205catch (IllegalArgumentException e) {206errorHandling(" Unexpected exception: " + e);207}208209// Test 7210++testNo;211System.out.println(" Test#" + testNo +212": RUN_DIRECTION_RTL, BIDI_EMBEDDING(2)");213astr = new AttributedString(paragraph);214astr.addAttribute(TextAttribute.RUN_DIRECTION,215TextAttribute.RUN_DIRECTION_RTL);216astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),217start, limit);218try {219bidi = new Bidi(astr.getIterator());220callTestEachMethod4Constructor1(textNo, testNo, bidi);221}222catch (IllegalArgumentException e) {223errorHandling(" Unexpected exception: " + e);224}225226// Test 8227++testNo;228System.out.println(" Test#" + testNo +229": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-3)");230astr = new AttributedString(paragraph);231astr.addAttribute(TextAttribute.RUN_DIRECTION,232TextAttribute.RUN_DIRECTION_RTL);233astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),234start, limit);235try {236bidi = new Bidi(astr.getIterator());237callTestEachMethod4Constructor1(textNo, testNo, bidi);238}239catch (IllegalArgumentException e) {240errorHandling(" Unexpected exception: " + e);241}242243// Test 9244++testNo;245System.out.println(" Test#" + testNo +246": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-4)");247astr = new AttributedString(paragraph);248astr.addAttribute(TextAttribute.RUN_DIRECTION,249TextAttribute.RUN_DIRECTION_RTL);250astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),251start, limit);252try {253bidi = new Bidi(astr.getIterator());254callTestEachMethod4Constructor1(textNo, testNo, bidi);255}256catch (IllegalArgumentException e) {257errorHandling(" Unexpected exception: " + e);258}259260// Test 10261++testNo;262System.out.println(" Test#" + testNo +263": TextAttribute not specified");264astr = new AttributedString(paragraph);265bidi = new Bidi(astr.getIterator());266callTestEachMethod4Constructor1(textNo, testNo, bidi);267268// Test 11269++testNo;270System.out.println(" Test#" + testNo +271": RUN_DIRECTION_LTR, NUMERIC_SHAPING(ARABIC)");272astr = new AttributedString(paragraph);273astr.addAttribute(TextAttribute.RUN_DIRECTION,274TextAttribute.RUN_DIRECTION_LTR);275astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);276bidi = new Bidi(astr.getIterator());277callTestEachMethod4Constructor1(textNo, testNo, bidi);278279// Test 12280++testNo;281System.out.println(" Test#" + testNo +282": RUN_DIRECTION_RTL, NUMERIC_SHAPING(ARABIC)");283astr = new AttributedString(paragraph);284astr.addAttribute(TextAttribute.RUN_DIRECTION,285TextAttribute.RUN_DIRECTION_RTL);286astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);287bidi = new Bidi(astr.getIterator());288callTestEachMethod4Constructor1(textNo, testNo, bidi);289}290}291292private void testMethods4Constructor2() {293System.out.println("*** Test methods for constructor 2");294295String paragraph;296Bidi bidi;297298for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {299paragraph = data4Constructor2[textNo][0];300for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {301int flag = FLAGS[flagNo];302303System.out.println("*** Test textNo=" + textNo +304": Bidi(\"" + toReadableString(paragraph) +305"\", " + getFlagName(flag) + ")");306307bidi = new Bidi(paragraph, flag);308callTestEachMethod4Constructor2(textNo, flagNo, bidi);309}310}311}312313private void testMethods4Constructor3() {314System.out.println("*** Test methods for constructor 3");315316String paragraph;317Bidi bidi;318319for (int textNo = 0; textNo < data4Constructor3.length; textNo++) {320paragraph = data4Constructor3[textNo][0];321char[] c = paragraph.toCharArray();322int start = paragraph.indexOf('<')+1;323byte[][] embeddings = (c.length < emb4Constructor3[1][0].length) ?324emb4Constructor3[0] : emb4Constructor3[1];325for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {326int flag = FLAGS[flagNo];327for (int embNo = 0; embNo < embeddings.length; embNo++) {328int dataNo = flagNo * FLAGS.length + embNo;329330System.out.println("*** Test textNo=" + textNo +331": Bidi(char[]\"" + toReadableString(paragraph) +332"\", 0, embeddings={" + toString(embeddings[embNo]) +333"}, " + c.length + ", " +334getFlagName(flag) + ")" + " dataNo=" + dataNo);335336try {337bidi = new Bidi(c, 0, embeddings[embNo], 0,338c.length, flag);339callTestEachMethod4Constructor3(textNo, dataNo, bidi);340}341catch (Exception e) {342errorHandling(" Unexpected exception: " + e);343}344}345}346}347}348349private void testConstructor1() {350Bidi bidi;351352try {353bidi = new Bidi(null);354errorHandling("Bidi((AttributedCharacterIterator)null) " +355"should throw an IAE.");356}357catch (IllegalArgumentException e) {358}359catch (NullPointerException e) {360errorHandling("Bidi((AttributedCharacterIterator)null) " +361"should not throw an NPE but an IAE.");362}363364String paragraph = data4Constructor1[1][0];365int start = paragraph.indexOf('<')+1;366int limit = paragraph.indexOf('>');367AttributedString astr = new AttributedString(paragraph);368astr.addAttribute(TextAttribute.RUN_DIRECTION,369TextAttribute.RUN_DIRECTION_RTL);370astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-61),371start, limit);372try {373bidi = new Bidi(astr.getIterator());374for (int i = start; i < limit; i++) {375if (bidi.getLevelAt(i) != 61) {376errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +377i + ") should not be " + bidi.getLevelAt(i) +378" but 60 when BIDI_EMBEDDING is -61.");379}380}381}382catch (Exception e) {383errorHandling(" Unexpected exception: " + e);384}385386astr = new AttributedString(paragraph);387astr.addAttribute(TextAttribute.RUN_DIRECTION,388TextAttribute.RUN_DIRECTION_RTL);389astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-62),390start, limit);391try {392bidi = new Bidi(astr.getIterator());393for (int i = start; i < limit; i++) {394if (bidi.getLevelAt(i) != 1) {395errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +396"should be 1 when BIDI_EMBEDDING is -62.");397}398}399}400catch (Exception e) {401errorHandling(" Unexpected exception: " + e);402}403404astr = new AttributedString(paragraph);405astr.addAttribute(TextAttribute.RUN_DIRECTION,406TextAttribute.RUN_DIRECTION_RTL);407astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(60),408start, limit);409try {410bidi = new Bidi(astr.getIterator());411for (int i = start; i < limit; i++) {412if (bidi.getLevelAt(i) != 61) {413errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +414"should be 61 when BIDI_EMBEDDING is 60.");415}416}417}418catch (Exception e) {419errorHandling(" Unexpected exception: " + e);420}421422astr = new AttributedString(paragraph);423astr.addAttribute(TextAttribute.RUN_DIRECTION,424TextAttribute.RUN_DIRECTION_RTL);425astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(61),426start, limit);427try {428bidi = new Bidi(astr.getIterator());429for (int i = start; i < limit; i++) {430if (bidi.getLevelAt(i) != 61) {431errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +432i + ") should not be " + bidi.getLevelAt(i) +433" but 61 when BIDI_EMBEDDING is 61.");434}435}436}437catch (Exception e) {438errorHandling(" Unexpected exception: " + e);439}440441astr = new AttributedString(paragraph);442astr.addAttribute(TextAttribute.RUN_DIRECTION,443TextAttribute.RUN_DIRECTION_RTL);444astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(62),445start, limit);446try {447bidi = new Bidi(astr.getIterator());448for (int i = start; i < limit; i++) {449if (bidi.getLevelAt(i) != 1) {450errorHandling("Bidi(AttributedCharacterIterator).getLevelAt()" +451" should not be " + bidi.getLevelAt(i) +452" but 1 when BIDI_EMBEDDING is 62.");453}454}455}456catch (Exception e) {457errorHandling(" Unexpected exception: " + e);458}459}460461private void testConstructor2() {462Bidi bidi;463464try {465bidi = new Bidi(null, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);466errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT)" +467" should throw an IAE.");468}469catch (IllegalArgumentException e) {470}471catch (NullPointerException e) {472errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT) " +473"should not throw an NPE but an IAE.");474}475476try {477bidi = new Bidi("abc", -3);478}479catch (Exception e) {480errorHandling("Bidi(\"abc\", -3) should not throw an exception: " +481e);482}483484try {485bidi = new Bidi("abc", 2);486}487catch (Exception e) {488errorHandling("Bidi(\"abc\", 2) should not throw an exception: " +489e);490}491}492493private void testConstructor3() {494char[] text = {'a', 'b', 'c', 'd', 'e'};495byte[] embeddings = {0, 0, 0, 0, 0};496Bidi bidi;497498try {499bidi = new Bidi(null, 0, embeddings, 0, 5,500Bidi.DIRECTION_LEFT_TO_RIGHT);501errorHandling("Bidi(char[], ...) should throw an IAE " +502"when text=null.");503}504catch (IllegalArgumentException e) {505}506catch (NullPointerException e) {507errorHandling("Bidi(char[], ...) should not throw an NPE " +508"but an IAE when text=null.");509}510511try {512bidi = new Bidi(text, -1, embeddings, 0, 5,513Bidi.DIRECTION_LEFT_TO_RIGHT);514errorHandling("Bidi(char[], ...) should throw an IAE " +515"when textStart is incorrect(-1: too small).");516}517catch (IllegalArgumentException e) {518}519catch (ArrayIndexOutOfBoundsException e) {520errorHandling("Bidi(char[], ...) should not throw an NPE " +521"but an IAE when textStart is incorrect(-1: too small).");522}523524try {525bidi = new Bidi(text, 4, embeddings, 0, 2,526Bidi.DIRECTION_LEFT_TO_RIGHT);527errorHandling("Bidi(char[], ...) should throw an IAE " +528"when textStart is incorrect(4: too large).");529}530catch (IllegalArgumentException e) {531}532catch (ArrayIndexOutOfBoundsException e) {533errorHandling("Bidi(char[], ...) should not throw an NPE " +534"but an IAE when textStart is incorrect(4: too large).");535}536537byte[] actualLevels = new byte[text.length];538byte[] validEmbeddings1 = {0, -61, -60, -2, -1};539byte[] expectedLevels1 = {0, 61, 60, 2, 1};540try {541bidi = new Bidi(text, 0, validEmbeddings1, 0, 5,542Bidi.DIRECTION_LEFT_TO_RIGHT);543for (int i = 0; i < text.length; i++) {544actualLevels[i] = (byte)bidi.getLevelAt(i);545}546if (!Arrays.equals(expectedLevels1, actualLevels)) {547errorHandling("Bidi(char[], ...).getLevelAt()" +548" should be {" + toString(actualLevels) +549"} when embeddings are {" +550toString(expectedLevels1) + "}.");551}552}553catch (Exception e) {554errorHandling("Bidi(char[], ...) should not throw an exception " +555"when embeddings is valid(-61).");556}557558byte[] validEmbeddings2 = {0, 61, 60, 2, 1};559byte[] expectedLevels2 = {0, 62, 60, 2, 2};560try {561bidi = new Bidi(text, 0, validEmbeddings2, 0, 5,562Bidi.DIRECTION_LEFT_TO_RIGHT);563for (int i = 0; i < text.length; i++) {564actualLevels[i] = (byte)bidi.getLevelAt(i);565}566if (!Arrays.equals(expectedLevels2, actualLevels)) {567errorHandling("Bidi(char[], ...).getLevelAt()" +568" should be {" + toString(actualLevels) +569"} when embeddings are {" +570toString(expectedLevels2) + "}.");571}572}573catch (Exception e) {574errorHandling("Bidi(char[], ...) should not throw an exception " +575"when embeddings is valid(61).");576}577578byte[] invalidEmbeddings1 = {0, -62, 0, 0, 0};579try {580bidi = new Bidi(text, 0, invalidEmbeddings1, 0, 5,581Bidi.DIRECTION_LEFT_TO_RIGHT);582if (bidi.getLevelAt(1) != 0) {583errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +584"when embeddings[1] is -62.");585}586}587catch (Exception e) {588errorHandling("Bidi(char[], ...) should not throw an exception " +589"even when embeddings includes -62.");590}591592byte[] invalidEmbeddings2 = {0, 62, 0, 0, 0};593try {594bidi = new Bidi(text, 0, invalidEmbeddings2, 0, 5,595Bidi.DIRECTION_LEFT_TO_RIGHT);596if (bidi.getLevelAt(1) != 0) {597errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +598"when embeddings[1] is 62.");599}600}601catch (Exception e) {602errorHandling("Bidi(char[], ...) should not throw an exception " +603"even when embeddings includes 62.");604}605606try {607bidi = new Bidi(text, 0, embeddings, 0, -1,608Bidi.DIRECTION_LEFT_TO_RIGHT);609errorHandling("Bidi(char[], ...) should throw an IAE " +610"when paragraphLength=-1(too small).");611}612catch (IllegalArgumentException e) {613}614catch (NegativeArraySizeException e) {615errorHandling("Bidi(char[], ...) should not throw an NASE " +616"but an IAE when paragraphLength=-1(too small).");617}618619try {620bidi = new Bidi(text, 0, embeddings, 0, 6,621Bidi.DIRECTION_LEFT_TO_RIGHT);622errorHandling("Bidi(char[], ...) should throw an IAE " +623"when paragraphLength=6(too large).");624}625catch (IllegalArgumentException e) {626}627catch (ArrayIndexOutOfBoundsException e) {628errorHandling("Bidi(char[], ...) should not throw an AIOoBE " +629"but an IAE when paragraphLength=6(too large).");630}631632try {633bidi = new Bidi(text, 0, embeddings, 0, 4, -3);634}635catch (Exception e) {636errorHandling("Bidi(char[], ...) should not throw an exception " +637"even when flag=-3(too small).");638}639640try {641bidi = new Bidi(text, 0, embeddings, 0, 5, 2);642}643catch (Exception e) {644errorHandling("Bidi(char[], ...) should not throw an exception " +645"even when flag=2(too large).");646}647}648649private void callTestEachMethod4Constructor1(int textNo,650int testNo,651Bidi bidi) {652testEachMethod(bidi,653data4Constructor1[textNo][0],654data4Constructor1[textNo][testNo+1],655baseIsLTR4Constructor1[textNo][testNo],656isLTR_isRTL4Constructor1[textNo][0][testNo],657isLTR_isRTL4Constructor1[textNo][1][testNo]);658}659660private void callTestEachMethod4Constructor2(int textNo,661int flagNo,662Bidi bidi) {663testEachMethod(bidi,664data4Constructor2[textNo][0],665data4Constructor2[textNo][flagNo+1],666baseIsLTR4Constructor2[textNo][flagNo],667isLTR_isRTL4Constructor2[textNo][0][flagNo],668isLTR_isRTL4Constructor2[textNo][1][flagNo]);669}670671private void callTestEachMethod4Constructor3(int textNo,672int dataNo,673Bidi bidi) {674testEachMethod(bidi,675data4Constructor3[textNo][0],676data4Constructor3[textNo][dataNo+1],677baseIsLTR4Constructor3[textNo][dataNo],678isLTR_isRTL4Constructor3[textNo][0][dataNo],679isLTR_isRTL4Constructor3[textNo][1][dataNo]);680}681682private StringBuilder sb = new StringBuilder();683private void testEachMethod(Bidi bidi,684String text,685String expectedLevels,686boolean expectedBaseIsLTR,687boolean expectedIsLTR,688boolean expectedIsRTL689) {690/* Test baseIsLeftToRight() */691boolean actualBoolean = bidi.baseIsLeftToRight();692checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);693694/* Test getBaseLevel() */695int expectedInt = (expectedBaseIsLTR) ? 0 : 1;696int actualInt = bidi.getBaseLevel();697checkResult("getBaseLevel()", expectedInt, actualInt);698699/* Test getLength() */700expectedInt = text.length();701actualInt = bidi.getLength();702checkResult("getLength()", expectedInt, actualInt);703704/* Test getLevelAt() */705sb.setLength(0);706for (int i = 0; i < text.length(); i++) {707sb.append(bidi.getLevelAt(i));708}709checkResult("getLevelAt()", expectedLevels, sb.toString());710711/* Test getRunCount() */712expectedInt = getRunCount(expectedLevels);713actualInt = bidi.getRunCount();714checkResult("getRunCount()", expectedInt, actualInt);715716/* Test getRunLevel(), getRunLimit() and getRunStart() */717if (expectedInt == actualInt) {718int runCount = expectedInt;719int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);720int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);721int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);722int[] actualRunLevels = new int[runCount];723int[] actualRunLimits = new int[runCount];724int[] actualRunStarts = new int[runCount];725726for (int k = 0; k < runCount; k++) {727actualRunLevels[k] = bidi.getRunLevel(k);728actualRunLimits[k] = bidi.getRunLimit(k);729actualRunStarts[k] = bidi.getRunStart(k);730}731732checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);733checkResult("getRunStart()", expectedRunStarts, actualRunStarts);734checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);735}736737/* Test isLeftToRight() */738boolean expectedBoolean = expectedIsLTR;739actualBoolean = bidi.isLeftToRight();740checkResult("isLeftToRight()", expectedBoolean, actualBoolean);741742/* Test isMixed() */743expectedBoolean = !(expectedIsLTR || expectedIsRTL);744actualBoolean = bidi.isMixed();745checkResult("isMixed()", expectedBoolean, actualBoolean);746747/* Test isRightToLeft() */748expectedBoolean = expectedIsRTL;749actualBoolean = bidi.isRightToLeft();750checkResult("isRightToLeft()", expectedBoolean, actualBoolean);751}752753private int getRunCount(String levels) {754int len = levels.length();755char c = levels.charAt(0);756int runCount = 1;757758for (int index = 1; index < len; index++) {759if (levels.charAt(index) != c) {760runCount++;761c = levels.charAt(index);762}763}764765return runCount;766}767768private int[] getRunLevels_int(int runCount, String levels) {769int[] array = new int[runCount];770int len = levels.length();771char c = levels.charAt(0);772int i = 0;773array[i++] = c - '0';774775for (int index = 1; index < len; index++) {776if (levels.charAt(index) != c) {777c = levels.charAt(index);778array[i++] = c - '0';779}780}781782return array;783}784785private byte[] getRunLevels_byte(int runCount, String levels) {786byte[] array = new byte[runCount];787int len = levels.length();788char c = levels.charAt(0);789int i = 0;790array[i++] = (byte)(c - '0');791792for (int index = 1; index < len; index++) {793if (levels.charAt(index) != c) {794c = levels.charAt(index);795array[i++] = (byte)(c - '0');796}797}798799return array;800}801802private int[] getRunLimits(int runCount, String levels) {803int[] array = new int[runCount];804int len = levels.length();805char c = levels.charAt(0);806int i = 0;807808for (int index = 1; index < len; index++) {809if (levels.charAt(index) != c) {810c = levels.charAt(index);811array[i++] = index;812}813}814array[i] = len;815816return array;817}818819private int[] getRunStarts(int runCount, String levels) {820int[] array = new int[runCount];821int len = levels.length();822char c = levels.charAt(0);823int i = 1;824825for (int index = 1; index < len; index++) {826if (levels.charAt(index) != c) {827c = levels.charAt(index);828array[i++] = index;829}830}831832return array;833}834835private String[] getObjects(int runCount, String text, String levels) {836String[] array = new String[runCount];837int[] runLimits = getRunLimits(runCount, levels);838int runStart = 0;839840for (int i = 0; i < runCount; i++) {841array[i] = text.substring(runStart, runLimits[i]);842runStart = runLimits[i];843}844845return array;846}847848private void testMethod_createLineBidi1() {849System.out.println("*** Test createLineBidi() 1");850851String str = " ABC 123. " + HebrewABC + " " + NKo123 + ". ABC 123";852853int lineStart = str.indexOf('.') + 2;854int lineLimit = str.lastIndexOf('.') + 2;855Bidi bidi = new Bidi(str, FLAGS[0]);856Bidi lineBidi = bidi.createLineBidi(lineStart, lineLimit);857858checkResult("getBaseLevel()",859bidi.getBaseLevel(), lineBidi.getBaseLevel());860checkResult("getLevelAt(5)",861bidi.getLevelAt(lineStart+5), lineBidi.getLevelAt(5));862}863864private void testMethod_createLineBidi2() {865System.out.println("*** Test createLineBidi() 2");866867Bidi bidi = new Bidi(data4Constructor1[0][0], FLAGS[0]);868int len = data4Constructor1[0][0].length();869870try {871Bidi lineBidi = bidi.createLineBidi(0, len);872}873catch (Exception e) {874errorHandling("createLineBidi(0, textLength)" +875" should not throw an exception.");876}877878try {879Bidi lineBidi = bidi.createLineBidi(-1, len);880errorHandling("createLineBidi(-1, textLength)" +881" should throw an IAE.");882}883catch (IllegalArgumentException e) {884}885886try {887Bidi lineBidi = bidi.createLineBidi(0, len+1);888errorHandling("createLineBidi(0, textLength+1)" +889" should throw an IAE.");890}891catch (IllegalArgumentException e) {892}893}894895/*896* Confirm that getLevelAt() doesn't throw an exception for invalid offset897* unlike ICU4J.898*/899private void testMethod_getLevelAt() {900System.out.println("*** Test getLevelAt()");901902Bidi bidi = new Bidi(data4Constructor1[1][0], FLAGS[0]);903int len = data4Constructor1[1][0].length();904905try {906int level = bidi.getLevelAt(-1);907if (level != bidi.getBaseLevel()) {908errorHandling("getLevelAt(-1) returned a wrong level." +909" Expected=" + bidi.getBaseLevel() + ", got=" + level);910}911}912catch (Exception e) {913errorHandling("getLevelAt(-1) should not throw an exception.");914}915916try {917int level = bidi.getLevelAt(len+1);918if (level != bidi.getBaseLevel()) {919errorHandling("getLevelAt(textLength+1)" +920" returned a wrong level." +921" Expected=" + bidi.getBaseLevel() + ", got=" + level);922}923}924catch (Exception e) {925errorHandling("getLevelAt(-1) should not throw an exception.");926}927}928929private void testMethod_getRunLevel() {930System.out.println("*** Test getRunLevel()");931932String str = "ABC 123";933Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);934try {935if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)936bidi.getRunLevel(0) != 0 || // runCount - 1937bidi.getRunLevel(1) != 0 || // runCount (out of range)938bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)939errorHandling("Incorrect getRunLevel() value(s).");940}941}942catch (Exception e) {943errorHandling("getRunLevel() should not throw an exception: " + e);944}945946str = "ABC " + HebrewABC + " 123";947bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);948try {949if (bidi.getRunLevel(-1) != 0 || // runCount - 4 (out of range)950bidi.getRunLevel(0) != 0 || // runCount - 3951bidi.getRunLevel(1) != 1 || // runCount - 2952bidi.getRunLevel(2) != 2 || // runCount - 1953bidi.getRunLevel(3) != 0 || // runCount (out of range)954bidi.getRunLevel(4) != 0) { // runCount + 1 (out of range)955errorHandling("Incorrect getRunLevel() value(s).");956}957}958catch (Exception e) {959errorHandling("getRunLevel() should not throw an exception: " + e);960}961962str = "ABC";963bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);964try {965if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)966bidi.getRunLevel(0) != 0 || // runCount - 1967bidi.getRunLevel(1) != 0 || // runCount (out of range)968bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)969errorHandling("Incorrect getRunLevel() value(s).");970}971}972catch (Exception e) {973errorHandling("getRunLevel() should not throw an exception: " + e);974}975976str = "ABC";977bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);978try {979if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)980bidi.getRunLevel(0) != 2 || // runCount - 1981bidi.getRunLevel(1) != 1 || // runCount (out of range)982bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)983errorHandling("Incorrect getRunLevel() value(s).");984}985}986catch (Exception e) {987errorHandling("getRunLevel() should not throw an exception: " + e);988}989990str = "ABC";991bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);992try {993if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)994bidi.getRunLevel(0) != 0 || // runCount - 1995bidi.getRunLevel(1) != 0 || // runCount (out of range)996bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)997errorHandling("Incorrect getRunLevel() value(s).");998}999}1000catch (Exception e) {1001errorHandling("getRunLevel() should not throw an exception: " + e);1002}10031004str = "ABC";1005bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);1006try {1007if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)1008bidi.getRunLevel(0) != 0 || // runCount - 11009bidi.getRunLevel(1) != 0 || // runCount (out of range)1010bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)1011errorHandling("Incorrect getRunLevel() value(s).");1012}1013}1014catch (Exception e) {1015errorHandling("getRunLevel() should not throw an exception: " + e);1016}10171018str = HebrewABC;1019bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);1020try {1021if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)1022bidi.getRunLevel(0) != 1 || // runCount - 11023bidi.getRunLevel(1) != 0 || // runCount (out of range)1024bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)1025errorHandling("Incorrect getRunLevel() value(s).");1026}1027}1028catch (Exception e) {1029errorHandling("getRunLevel() should not throw an exception: " + e);1030}10311032str = HebrewABC;1033bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);1034try {1035if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1036bidi.getRunLevel(0) != 1 || // runCount - 11037bidi.getRunLevel(1) != 1 || // runCount (out of range)1038bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1039errorHandling("Incorrect getRunLevel() value(s).");1040}1041}1042catch (Exception e) {1043errorHandling("getRunLevel() should not throw an exception: " + e);1044}10451046str = HebrewABC;1047bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);1048try {1049if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1050bidi.getRunLevel(0) != 1 || // runCount - 11051bidi.getRunLevel(1) != 1 || // runCount (out of range)1052bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1053errorHandling("Incorrect getRunLevel() value(s).");1054}1055}1056catch (Exception e) {1057errorHandling("getRunLevel() should not throw an exception: " + e);1058}10591060str = HebrewABC;1061bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);1062try {1063if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)1064bidi.getRunLevel(0) != 1 || // runCount - 11065bidi.getRunLevel(1) != 1 || // runCount (out of range)1066bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)1067errorHandling("Incorrect getRunLevel() value(s).");1068}1069}1070catch (Exception e) {1071errorHandling("getRunLevel() should not throw an exception: " + e);1072}1073}10741075private void testMethod_getRunLimit() {1076System.out.println("*** Test getRunLimit()");10771078String str = "ABC 123";1079int length = str.length();1080Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);10811082try {1083if (bidi.getRunLimit(-1) != length || // runCount - 21084bidi.getRunLimit(0) != length || // runCount - 11085bidi.getRunLimit(1) != length || // runCount1086bidi.getRunLimit(2) != length) { // runCount + 11087errorHandling("getRunLimit() should return " + length +1088" when getRunCount() is 1.");1089}1090}1091catch (Exception e) {1092errorHandling("getRunLimit() should not throw an exception " +1093"when getRunCount() is 1.");1094}10951096str = "ABC " + ArabicABC + " 123";1097length = str.length();1098bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);10991100try {1101bidi.getRunLimit(-1);1102errorHandling("getRunLimit() should throw an AIOoBE " +1103"when run is -1(too small).");1104}1105catch (ArrayIndexOutOfBoundsException e) {1106}1107catch (IllegalArgumentException e) {1108errorHandling("getRunLimit() should not throw an IAE " +1109"but an AIOoBE when run is -1(too small).");1110}11111112try {1113bidi.getRunLimit(0);1114bidi.getRunLimit(1);1115bidi.getRunLimit(2);1116}1117catch (ArrayIndexOutOfBoundsException e) {1118errorHandling("getRunLimit() should not throw an AIOOBE " +1119"when run is from 0 to 2(runCount-1).");1120}11211122try {1123bidi.getRunLimit(3);1124errorHandling("getRunLimit() should throw an AIOoBE " +1125"when run is 3(same as runCount).");1126}1127catch (ArrayIndexOutOfBoundsException e) {1128}1129catch (IllegalArgumentException e) {1130errorHandling("getRunLimit() should not throw an IAE " +1131"but an AIOoBE when run is 3(same as runCount).");1132}1133}11341135private void testMethod_getRunStart() {1136System.out.println("*** Test getRunStart()");11371138String str = "ABC 123";1139int length = str.length();1140Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);11411142try {1143if (bidi.getRunStart(-1) != 0 || // runCount - 21144bidi.getRunStart(0) != 0 || // runCount - 11145bidi.getRunStart(1) != 0 || // runCount1146bidi.getRunStart(2) != 0) { // runCount + 11147errorHandling("getRunStart() should return 0" +1148" when getRunCount() is 1.");1149}1150}1151catch (Exception e) {1152errorHandling("getRunLimit() should not throw an exception" +1153" when getRunCount() is 1.");1154}11551156str = "ABC " + NKoABC + " 123";1157length = str.length();1158bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);11591160try {1161bidi.getRunStart(-1);1162errorHandling("getRunStart() should throw an AIOoBE" +1163" when run is -1(too small).");1164}1165catch (ArrayIndexOutOfBoundsException e) {1166}1167catch (IllegalArgumentException e) {1168errorHandling("getRunStart() should not throw an IAE " +1169"but an AIOoBE when run is -1(too small).");1170}11711172try {1173bidi.getRunStart(0);1174bidi.getRunStart(1);1175bidi.getRunStart(2);1176}1177catch (ArrayIndexOutOfBoundsException e) {1178errorHandling("getRunStart() should not throw an AIOOBE " +1179"when run is from 0 to 2(runCount-1).");1180}11811182try {1183if (bidi.getRunStart(3) != length) {1184errorHandling("getRunStart() should return " + length +1185" when run is 3(same as runCount).");1186}1187}1188catch (Exception e) {1189errorHandling("getRunStart() should not throw an exception " +1190"when run is 3(same as runCount).");1191}11921193try {1194bidi.getRunStart(4);1195errorHandling("getRunStart() should throw an AIOoBE " +1196"when run is runCount+1(too large).");1197}1198catch (ArrayIndexOutOfBoundsException e) {1199}1200catch (IllegalArgumentException e) {1201errorHandling("getRunStart() should not throw an IAE " +1202"but an AIOoBE when run is runCount+1(too large).");1203}1204}12051206private void testMethod_reorderVisually1() {1207System.out.println("*** Test reorderVisually() 1");12081209for (int textNo = 0; textNo < data4reorderVisually.length; textNo++) {1210Object[] objects = data4reorderVisually[textNo][0];1211byte[] levels = getLevels(data4reorderVisually[textNo]);1212Object[] expectedObjects = data4reorderVisually[textNo][2];12131214Bidi.reorderVisually(levels, 0, objects, 0, objects.length);12151216checkResult("textNo=" + textNo + ": reorderVisually(levels=[" +1217toString(levels) + "], objects=[" + toString(objects) + "])",1218expectedObjects, objects);1219}1220}12211222private void testMethod_reorderVisually2() {1223System.out.println("*** Test reorderVisually() 2");12241225Object[] objects = data4reorderVisually[0][0];1226byte[] levels = getLevels(data4reorderVisually[0]);1227int count = objects.length;1228int llen = levels.length;1229int olen = objects.length;12301231try {1232Bidi.reorderVisually(null, 0, objects, 0, count);1233errorHandling("reorderVisually() should throw a NPE " +1234"when levels is null.");1235}1236catch (NullPointerException e) {1237}12381239try {1240Bidi.reorderVisually(levels, -1, objects, 0, count);1241errorHandling("reorderVisually() should throw an IAE " +1242"when levelStart is -1.");1243}1244catch (IllegalArgumentException e) {1245}1246catch (ArrayIndexOutOfBoundsException e) {1247errorHandling("reorderVisually() should not throw an AIOoBE " +1248"but an IAE when levelStart is -1.");1249}12501251try {1252Bidi.reorderVisually(levels, llen, objects, 0, count);1253errorHandling("reorderVisually() should throw an IAE " +1254"when levelStart is 6(levels.length).");1255}1256catch (IllegalArgumentException e) {1257}1258catch (ArrayIndexOutOfBoundsException e) {1259errorHandling("reorderVisually() should not throw an AIOoBE " +1260"but an IAE when levelStart is 6(levels.length).");1261}12621263try {1264Bidi.reorderVisually(levels, 0, null, 0, count);1265errorHandling("reorderVisually() should throw a NPE" +1266" when objects is null.");1267}1268catch (NullPointerException e) {1269}12701271try {1272Bidi.reorderVisually(levels, 0, objects, -1, count);1273errorHandling("reorderVisually() should throw an IAE" +1274" when objectStart is -1.");1275}1276catch (IllegalArgumentException e) {1277}1278catch (ArrayIndexOutOfBoundsException e) {1279errorHandling("reorderVisually() should not throw an AIOoBE " +1280"but an IAE when objectStart is -1.");1281}12821283try {1284Bidi.reorderVisually(levels, 0, objects, 6, objects.length);1285errorHandling("reorderVisually() should throw an IAE " +1286"when objectStart is 6(objects.length).");1287}1288catch (IllegalArgumentException e) {1289}12901291try {1292Bidi.reorderVisually(levels, 0, objects, 0, -1);1293errorHandling("reorderVisually() should throw an IAE " +1294"when count is -1.");1295}1296catch (IllegalArgumentException e) {1297}1298catch (NegativeArraySizeException e) {1299errorHandling("reorderVisually() should not throw an NASE " +1300"but an IAE when count is -1.");1301}13021303try {1304Bidi.reorderVisually(levels, 0, objects, 0, count+1);1305errorHandling("reorderVisually() should throw an IAE " +1306"when count is 7(objects.length+1).");1307}1308catch (IllegalArgumentException e) {1309}1310catch (ArrayIndexOutOfBoundsException e) {1311errorHandling("reorderVisually() should not throw an AIOoBE " +1312"but an IAE when count is 7(objects.length+1).");1313}13141315try {1316Bidi.reorderVisually(levels, 0, objects, 0, 0);1317checkResult("reorderVisually(count=0)",1318data4reorderVisually[0][0], objects);1319}1320catch (Exception e) {1321errorHandling("reorderVisually() should not throw an exception" +1322" when count is 0.");1323}1324}13251326private void testMethod_requiresBidi() {1327System.out.println("*** Test requiresBidi()");13281329String paragraph;1330char[] text;1331Bidi bidi;13321333for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {1334paragraph = data4Constructor2[textNo][0];1335text = paragraph.toCharArray();1336boolean rBidi = Bidi.requiresBidi(text, 0, text.length);1337if (rBidi != requiresBidi4Constructor2[textNo]) {1338error = true;1339System.err.println("Unexpected requiresBidi() value" +1340" for requiresBidi(\"" + paragraph + "\", " + 0 + ", " +1341text.length + ")." +1342"\n Expected: " + requiresBidi4Constructor2[textNo] +1343"\n Got : " + rBidi);1344} else if (verbose) {1345System.out.println(" Okay : requiresBidi() for" +1346" requiresBidi(\"" + paragraph + "\", " + 0 + ", " +1347text.length + ") Got: " + rBidi);1348}1349}13501351char[] txt = {'A', 'B', 'C', 'D', 'E'};1352int textLength = txt.length;13531354try {1355Bidi.requiresBidi(txt, -1, textLength);1356errorHandling("requiresBidi() should throw an IAE" +1357" when start is -1(too small).");1358}1359catch (IllegalArgumentException e) {1360}1361catch (ArrayIndexOutOfBoundsException e) {1362errorHandling("requiresBidi() should not throw an AIOoBE " +1363"but an IAE when start is -1(too small).");1364}13651366try {1367Bidi.requiresBidi(txt, textLength, textLength);1368}1369catch (Exception e) {1370errorHandling("requiresBidi() should not throw an exception " +1371"when start is textLength.");1372}13731374try {1375Bidi.requiresBidi(txt, textLength+1, textLength);1376errorHandling("requiresBidi() should throw an IAE" +1377" when start is textLength+1(too large).");1378}1379catch (IllegalArgumentException e) {1380}13811382try {1383Bidi.requiresBidi(txt, 0, -1);1384errorHandling("requiresBidi() should throw an IAE" +1385" when limit is -1(too small).");1386}1387catch (IllegalArgumentException e) {1388}13891390try {1391Bidi.requiresBidi(txt, 0, textLength+1);1392errorHandling("requiresBidi() should throw an IAE" +1393" when limit is textLength+1(too large).");1394}1395catch (IllegalArgumentException e) {1396}1397catch (ArrayIndexOutOfBoundsException e) {1398errorHandling("requiresBidi() should not throw an AIOoBE " +1399"but an IAE when limit is textLength+1(too large).");1400}1401}14021403private void checkResult(String name,1404int expectedValue,1405int actualValue) {1406if (expectedValue != actualValue) {1407errorHandling("Unexpected " + name + " value." +1408" Expected: " + expectedValue + " Got: " + actualValue);1409} else if (verbose) {1410System.out.println(" Okay : " + name + " = " + actualValue);1411}1412}14131414private void checkResult(String name,1415boolean expectedValue,1416boolean actualValue) {1417if (expectedValue != actualValue) {1418errorHandling("Unexpected " + name + " value." +1419" Expected: " + expectedValue + " Got: " + actualValue);1420} else if (verbose) {1421System.out.println(" Okay : " + name + " = " + actualValue);1422}1423}14241425private void checkResult(String name,1426String expectedValue,1427String actualValue) {1428if (!expectedValue.equals(actualValue)) {1429errorHandling("Unexpected " + name + " value." +1430"\n\tExpected: \"" + expectedValue + "\"" +1431"\n\tGot: \"" + actualValue + "\"");1432} else if (verbose) {1433System.out.println(" Okay : " + name + " = \"" +1434actualValue + "\"");1435}1436}14371438private void checkResult(String name,1439int[] expectedValues,1440int[] actualValues) {1441if (!Arrays.equals(expectedValues, actualValues)) {1442errorHandling("Unexpected " + name + " value." +1443"\n\tExpected: " + toString(expectedValues) + "" +1444"\n\tGot: " + toString(actualValues) + "");1445} else if (verbose) {1446System.out.println(" Okay : " + name + " = " +1447toString(actualValues));1448}1449}14501451private void checkResult(String name,1452Object[] expectedValues,1453Object[] actualValues) {1454if (!Arrays.equals(expectedValues, actualValues)) {1455errorHandling("Unexpected " + name + " value." +1456"\n\tExpected: [" + toString(expectedValues) +1457"]\n\tGot: [" + toString(actualValues) + "]");1458} else if (verbose) {1459System.out.println(" Okay : " + name + " Reordered objects = [" +1460toString(actualValues) + "]");1461}1462}14631464private void errorHandling(String msg) {1465if (abort) {1466throw new RuntimeException("Error: " + msg);1467} else {1468error = true;1469System.err.println("**Error:" + msg);1470}1471}14721473private String toString(int[] values) {1474StringBuilder sb = new StringBuilder();1475for (int i = 0; i < values.length-1; i++) {1476sb.append((int)values[i]);1477sb.append(' ');1478}1479sb.append((int)values[values.length-1]);14801481return sb.toString();1482}14831484private String toString(byte[] values) {1485StringBuilder sb = new StringBuilder();1486for (int i = 0; i < values.length-1; i++) {1487sb.append((byte)values[i]);1488sb.append(' ');1489}1490sb.append((byte)values[values.length-1]);14911492return sb.toString();1493}14941495private String toString(Object[] values) {1496StringBuilder sb = new StringBuilder();1497String name;14981499for (int i = 0; i < values.length-1; i++) {1500if ((name = getStringName((String)values[i])) != null) {1501sb.append(name);1502sb.append(", ");1503} else {1504sb.append('"');1505sb.append((String)values[i]);1506sb.append("\", ");1507}1508}1509if ((name = getStringName((String)values[values.length-1])) != null) {1510sb.append(name);1511} else {1512sb.append('"');1513sb.append((String)values[values.length-1]);1514sb.append('\"');1515}15161517return sb.toString();1518}15191520private String getStringName(String str) {1521if (ArabicABC.equals(str)) return "ArabicABC";1522else if (Arabic123.equals(str)) return "Arabic123";1523else if (PArabicABC.equals(str)) return "ArabicABC(Presentation form)";1524else if (HebrewABC.equals(str)) return "HebrewABC";1525else if (KharoshthiABC.equals(str)) return "KharoshthiABC(RTL)";1526else if (Kharoshthi123.equals(str)) return "Kharoshthi123(RTL)";1527else if (NKoABC.equals(str)) return "NKoABC(RTL)";1528else if (NKo123.equals(str)) return "NKo123(RTL)";1529else if (OsmanyaABC.equals(str)) return "OsmanyaABC(LTR)";1530else if (Osmanya123.equals(str)) return "Osmanya123(LTR)";1531else return null;1532}15331534private String getFlagName(int flag) {1535if (flag == -2 || flag == 0x7e) return FLAGNAMES[0];1536else if (flag == -1 || flag == 0x7f) return FLAGNAMES[1];1537else if (flag == 0) return FLAGNAMES[2];1538else if (flag == 1) return FLAGNAMES[3];1539else return "Unknown(0x" + Integer.toHexString(flag) + ")";1540}15411542private String toReadableString(String str) {1543String s = str;15441545s = s.replaceAll(ArabicABC, "ArabicABC");1546s = s.replaceAll(Arabic123, "Arabic123");1547s = s.replaceAll(PArabicABC, "ArabicABC(Presentation form)");1548s = s.replaceAll(HebrewABC, "HebrewABC");1549s = s.replaceAll(KharoshthiABC, "KharoshthiABC");1550s = s.replaceAll(Kharoshthi123, "Kharoshthi123");1551s = s.replaceAll(NKoABC, "NKoABC");1552s = s.replaceAll(NKo123, "NKo123");1553s = s.replaceAll(OsmanyaABC, "OsmanyaABC");1554s = s.replaceAll(Osmanya123, "Osmanya123");15551556return s;1557}15581559private byte[] getLevels(Object[][] data) {1560int levelLength = data[0].length;1561byte[] array = new byte[levelLength];1562int textIndex = 0;15631564for (int i = 0; i < levelLength; i++) {1565array[i] = (byte)(((String)data[1][0]).charAt(textIndex) - '0');1566textIndex += ((String)data[0][i]).length();1567}15681569return array;1570}157115721573/* Bidi pubilc constants */1574private static final int[] FLAGS = {1575Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT, // -2 (0x7e in ICU4J)1576Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT, // -1 (0x7f in ICU4J)1577Bidi.DIRECTION_LEFT_TO_RIGHT, // 01578Bidi.DIRECTION_RIGHT_TO_LEFT // 11579};15801581/* Bidi pubilc constants names */1582private static final String[] FLAGNAMES = {1583"DIRECTION_DEFAULT_LEFT_TO_RIGHT", // -21584"DIRECTION_DEFAULT_RIGHT_TO_LEFT", // -11585"DIRECTION_LEFT_TO_RIGHT", // 01586"DIRECTION_RIGHT_TO_LEFT", // 11587};15881589/* Bidirectional Character Types */1590private static final char L = '\u200E';1591private static final char R = '\u202F';1592private static final char LRE = '\u202A';1593private static final char RLE = '\u202B';1594private static final char PDF = '\u202C';1595private static final char LRO = '\u202D';1596private static final char RLO = '\u202E';15971598/*1599* 0x05D0-0x05EA: [R] Hewbrew letters (Strong)1600* 0x0627-0x063A: [AL] Arabic letters (Strong)1601* 0x0660-0x0669: [AN] Arabic-Indic digits (Weak)1602* 0x07CA-0x07E7: [R] NKo letters (Strong)1603* 0x07C0-0x07C9: [R] NKo digits (Strong)1604* 0xFE50-0xFEFF: [AL] Arabic presentaion form (Strong)1605* 0x10480-0x1049D: [L] Osmanya letters (Strong)1606* 0x104A0-0x104A9: [L] Osmanya digits (Strong)1607* 0x10A10-0x10A33: [R] Kharoshthi letters (Strong)1608* 0x10A40-0x10A43: [R] Kharoshthi digits (Strong)1609*1610* 0x200E: [L] Left-to-right mark (Implicit, Strong)1611* 0x200F: [R] Right-to-left mark (Implicit, Strong)1612* 0x202A: [LRE] Left-to-right embedding (Explicit, Strong)1613* 0x202B: [RLE] Right-to-left embedding (Explicit, Strong)1614* 0x202C: [PDF] Pop directional formatting (Explicit, Weak)1615* 0x202D: [LRO] Left-to-right override (Explicit, Strong)1616* 0x202E: [RLO] Right-to-left override (Explicit, Strong)1617*/16181619/* Right-to-left */1620private static String ArabicABC = "\u0627\u0628\u0629";1621private static String Arabic123 = "\u0661\u0662\u0663";1622private static String PArabicABC = "\uFE97\uFE92\uFE8E";1623private static String HebrewABC = "\u05D0\u05D1\u05D2";1624private static String KharoshthiABC =1625new String(Character.toChars(0x10A10)) +1626new String(Character.toChars(0x10A11)) +1627new String(Character.toChars(0x10A12));1628private static String Kharoshthi123 =1629new String(Character.toChars(0x10A40)) +1630new String(Character.toChars(0x10A41)) +1631new String(Character.toChars(0x10A42));1632private static String NKoABC = "\u07CA\u07CB\u07CC";1633private static String NKo123 = "\u07C1\u07C2\u07C3";16341635/* Left-to-right */1636private static String OsmanyaABC =1637new String(Character.toChars(0x10480)) +1638new String(Character.toChars(0x10481)) +1639new String(Character.toChars(0x10482));1640private static String Osmanya123 =1641new String(Character.toChars(0x104A0)) +1642new String(Character.toChars(0x104A1)) +1643new String(Character.toChars(0x104A2));16441645/* --------------------------------------------------------------------- */16461647/*1648* Test data for Bidi(char[], ...) constructor and methods1649*/16501651/* Text for Bidi processing and its levels */1652private static String[][] data4Constructor1 = {1653/* For Text #0 */1654{"abc <ABC XYZ> xyz.",1655"000000000000000000", "000002222222000000", "000000000000000000",1656"000003333333000000", "000000000000000000",1657"222222222222222221", "222222222222222221", "222222222222222221",1658"222113333333112221", "222224444444222221",1659"000000000000000000", "000000000000000000", "222222222222222221"},16601661/* For Text #1 */1662{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",1663"000001111111000000", "000001111111000000", "000003333333000000",1664"000003333333000000", "000000000000000000",1665"222111111111112221", "222111111111112221", "222223333333222221",1666"222113333333112221", "222224444444222221",1667"000001111111000000", "000001111111000000", "222111111111112221"},16681669/* For Text #2 */1670{NKoABC + " <ABC XYZ> " + NKo123 + ".",1671"111000000000001110", "111112222222111110", "111002222222001110",1672"111113333333111110", "111004444444001110",1673"111112222222111111", "111112222222111111", "111112222222111111",1674"111111111111111111", "111114444444111111",1675"111112222222111111", "111000000000001110", "111112222222111111"},16761677/* For Text #3 */1678{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",1679"111111111222111110", "111111111222111110", "111003333444001110",1680"111113333333111110", "111004444444001110",1681"111111111222111111", "111111111222111111", "111113333444111111",1682"111111111111111111", "111114444444111111",1683"111111111222111111", "111111111222111110", "111111111222111111"},16841685/* For Text #4 */1686{"abc <" + NKoABC + " 123> xyz.",1687"000001111222000000", "000001111222000000", "000003333444000000",1688"000003333333000000", "000000000000000000",1689"222111111222112221", "222111111222112221", "222223333444222221",1690"222113333333112221", "222224444444222221",1691"000001111222000000", "000001111222000000", "222111111222112221"},16921693/* For Text #5 */1694{"abc <ABC " + NKo123 + "> xyz.",1695"000000000111000000", "000002221111000000", "000002222333000000",1696"000003333333000000", "000000000000000000",1697"222222221111112221", "222222221111112221", "222222222333222221",1698"222113333333112221", "222224444444222221",1699"000000000111000000", "000000000111000000", "222222221111112221"},17001701/* For Text #6 */1702{ArabicABC + " <" + NKoABC + " 123" + "> " + Arabic123 + ".",1703"111111111222112220", "111111111222112220", "111003333444002220",1704"111113333333112220", "111004444444002220",1705"111111111222112221", "111111111222112221", "111113333444112221",1706"111113333333112221", "111114444444112221",1707"111111111222112221", "111111111222112220", "111111111222112221"},17081709/* For Text #7 */1710{ArabicABC + " <XYZ " + NKoABC + "> " + Arabic123 + ".",1711"111000000111112220", "111112221111112220", "111002222333002220",1712"111113333333112220", "111004444444002220",1713"111112221111112221", "111112221111112221", "111112222333112221",1714"111113333333112221", "111114444444112221",1715"111112221111112221", "111000000111112220", "111112221111112221"},17161717/* For Text #8 */1718{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +1719Osmanya123 + ".",1720"000000001111111111111000000000", "000000001111111111111000000000",1721"000000003333333333333000000000", "000000003333333333333000000000",1722"000000000000000000000000000000",1723"222222111111111111111112222221", "222222111111111111111112222221",1724"222222223333333333333222222221", "222222113333333333333112222221",1725"222222224444444444444222222221",1726"000000001111111111111000000000", "000000001111111111111000000000",1727"222222111111111111111112222221"},17281729/* For Text #9 */1730{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +1731Kharoshthi123 + ".",1732"111111000000000000000001111110", "111111112222222222222111111110",1733"111111002222222222222001111110", "111111113333333333333111111110",1734"111111004444444444444001111110",1735"111111112222222222222111111111", "111111112222222222222111111111",1736"111111112222222222222111111111", "111111111111111111111111111111",1737"111111114444444444444111111111",1738"111111112222222222222111111111", "111111000000000000000001111110",1739"111111112222222222222111111111"},1740};17411742/* Golden data for baseIsLeftToRight() results */1743private static boolean[][] baseIsLTR4Constructor1 = {1744/* For Text #0 */1745{true, true, true, true, true,1746false, false, false, false, false,1747true, true, false},17481749/* For Text #1 */1750{true, true, true, true, true,1751false, false, false, false, false,1752true, true, false},17531754/* For Text #2 */1755{true, true, true, true, true,1756false, false, false, false, false,1757false, true, false},17581759/* For Text #3 */1760{true, true, true, true, true,1761false, false, false, false, false,1762false, true, false},17631764/* For Text #4 */1765{true, true, true, true, true,1766false, false, false, false, false,1767true, true, false},17681769/* For Text #5 */1770{true, true, true, true, true,1771false, false, false, false, false,1772true, true, false},17731774/* For Text #6 */1775{true, true, true, true, true,1776false, false, false, false, false,1777false, true, false},17781779/* For Text #7 */1780{true, true, true, true, true,1781false, false, false, false, false,1782false, true, false},17831784/* For Text #8 */1785{true, true, true, true, true,1786false, false, false, false, false,1787true, true, false},17881789/* For Text #9 */1790{true, true, true, true, true,1791false, false, false, false, false,1792false, true, false},1793};17941795/* Golden data for isLeftToRight() & isRightToLeft() results */1796private static boolean[][][] isLTR_isRTL4Constructor1 = {1797/* For Text #0 */1798/* isLeftToRight() results */1799{{true, false, true, false, true,1800false, false, false, false, false,1801true, true, false},1802/* isRightToLeft() results */1803{false, false, false, false, false,1804false, false, false, false, false,1805false, false, false}},18061807/* For Text #1 */1808/* isLeftToRight() results */1809{{false, false, false, false, true,1810false, false, false, false, false,1811false, false, false},1812/* isRightToLeft() results */1813{false, false, false, false, false,1814false, false, false, false, false,1815false, false, false}},18161817/* For Text #2 */1818/* isLeftToRight() results */1819{{false, false, false, false, false,1820false, false, false, false, false,1821false, false, false},1822/* isRightToLeft() results */1823{false, false, false, false, false,1824false, false, false, true, false,1825false, false, false}},18261827/* For Text #3 */1828/* isLeftToRight() results */1829{{false, false, false, false, false,1830false, false, false, false, false,1831false, false, false},1832/* isRightToLeft() results */1833{false, false, false, false, false,1834false, false, false, true, false,1835false, false, false}},18361837/* For Text #4 */1838/* isLeftToRight() results */1839{{false, false, false, false, true,1840false, false, false, false, false,1841false, false, false},1842/* isRightToLeft() results */1843{false, false, false, false, false,1844false, false, false, false, false,1845false, false, false}},18461847/* For Text #5 */1848/* isLeftToRight() results */1849{{false, false, false, false, true,1850false, false, false, false, false,1851false, false, false},1852/* isRightToLeft() results */1853{false, false, false, false, false,1854false, false, false, false, false,1855false, false, false}},18561857/* For Text #6 */1858/* isLeftToRight() results */1859{{false, false, false, false, false,1860false, false, false, false, false,1861false, false, false},1862/* isRightToLeft() results */1863{false, false, false, false, false,1864false, false, false, false, false,1865false, false, false}},18661867/* For Text #7 */1868/* isLeftToRight() results */1869{{false, false, false, false, false,1870false, false, false, false, false,1871false, false, false},1872/* isRightToLeft() results */1873{false, false, false, false, false,1874false, false, false, false, false,1875false, false, false}},18761877/* For Text #8 */1878/* isLeftToRight() results */1879{{false, false, false, false, true,1880false, false, false, false, false,1881false, false, false},1882/* isRightToLeft() results */1883{false, false, false, false, false,1884false, false, false, false, false,1885false, false, false}},18861887/* For Text #9 */1888/* isLeftToRight() results */1889{{false, false, false, false, false,1890false, false, false, false, false,1891false, false, false},1892/* isRightToLeft() results */1893{false, false, false, false, false,1894false, false, false, true, false,1895false, false, false}},1896};18971898/* --------------------------------------------------------------------- */18991900/*1901* Test data for Bidi(String, int) constructor and methods1902*/19031904/* Text for Bidi processing and its levels */1905private static String[][] data4Constructor2 = {1906/* For Text #0 */1907{" ABC 123.",1908"000000000", "000000000", "000000000", "122222221"},19091910/* For Text #1 */1911{" ABC " + HebrewABC + " " + NKo123 + " 123.",1912"00000111111112220", "00000111111112220", "00000111111112220",1913"12221111111112221"},19141915/* For Text #2 */1916{" ABC " + ArabicABC + " " + Arabic123 + " 123.",1917"00000111122212220", "00000111122212220", "00000111122212220",1918"12221111122212221"},19191920/* For Text #3 */1921{" " + NKoABC + " ABC 123 " + NKo123 + ".",1922"11111222222211111", "11111222222211111", "01110000000001110",1923"11111222222211111"},19241925/* For Text #4 */1926{" " + ArabicABC + " ABC 123 " + Arabic123 + ".",1927"11111222222212221", "11111222222212221", "01110000000002220",1928"11111222222212221"},19291930/* For Text #5 */1931{" " + HebrewABC + " " + NKo123 + ".",1932"111111111", "111111111", "011111110", "111111111"},19331934/* For Text #6 */1935{" " + ArabicABC + " " + Arabic123 + ".",1936"111112221", "111112221", "011112220", "111112221"},19371938/* For Text #7 */1939{" " + KharoshthiABC + " " + Kharoshthi123 + ".",1940"111111111111111", "111111111111111", "011111111111110",1941"111111111111111"},19421943/* For Text #8 */1944{L + HebrewABC + " " + NKo123 + ".",1945"011111110", "011111110", "011111110", "211111111"},19461947/* For Text #9 */1948{R + "ABC " + Osmanya123 + ".",1949"000000000000", "000000000000", "000000000000", "122222222221"},19501951/* For Text #10 */1952{"ABC " + PArabicABC + " " + PArabicABC + " 123",1953"000011111111222", "000011111111222", "000011111111222",1954"222111111111222"},19551956/* For Text #11 */1957{RLE + "ABC " + HebrewABC + " " + NKo123 + "." + PDF,1958"22221111111110", "22221111111110", "22221111111110",1959"44443333333331"},19601961/* For Text #12 */1962{"He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF + ".\"",1963"000000000222211111111000", "000000000222211111111000",1964"000000000222211111111000", "222222211444433333333111"},19651966/* For Text #13 */1967{LRO + "He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF +1968".\"" + PDF,1969"22222222224444333333332220", "22222222224444333333332220",1970"22222222224444333333332220", "22222222224444333333332221"},19711972/* For Text #14 */1973{LRO + "He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF +1974".\"", // PDF missing1975"2222222222444433333333222", "2222222222444433333333222",1976"2222222222444433333333222", "2222222222444433333333222"},19771978/* For Text #15 */1979{"Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +1980" " + NKo123 + PDF + "\"" + PDF + "'?",1981"0000000000000222222222244443333333322000",1982"0000000000000222222222244443333333322000",1983"0000000000000222222222244443333333322000",1984"2222222222222222222222244443333333322111"},19851986/* For Text #16 */1987{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +1988HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?" + PDF,1989"111111111111112222222222444433333333221110",1990"111111111111112222222222444433333333221110",1991"111111111111112222222222444433333333221110",1992"333333333333334444444444666655555555443331"},19931994/* For Text #17 */1995{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +1996HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?", // PDF missing1997"11111111111111222222222244443333333322111",1998"11111111111111222222222244443333333322111",1999"11111111111111222222222244443333333322111",2000"33333333333333444444444466665555555544333"},20012002/* For Text #18 */2003{" ABC (" + ArabicABC + " " + Arabic123 + ") 123.",2004"0000001111222112220", "0000001111222112220",2005"0000001111222112220", "1222111111222112221"},20062007/* For Text #19 */2008{" " + HebrewABC + " (ABC 123) " + NKo123 + ".",2009"1111112222222111111", "1111112222222111111",2010"0111000000000001110", "1111112222222111111"},20112012/* For Text #20 */2013{" He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF + ".\" ",2014"00000000002222111111110000", "00000000002222111111110000",2015"00000000002222111111110000", "12222222114444333333331111"},20162017/* For Text #21 */2018{" Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +2019" " + NKo123 + PDF + "\"" + PDF + "'? ",2020"000000000000002222222222444433333333220000",2021"000000000000002222222222444433333333220000",2022"000000000000002222222222444433333333220000",2023"122222222222222222222222444433333333221111"},20242025/* For Text #22 */2026{RLE + OsmanyaABC + " " + KharoshthiABC + " " + Kharoshthi123 + "." +2027PDF,2028"22222221111111111111110", "22222221111111111111110",2029"22222221111111111111110", "44444443333333333333331"},2030};20312032/* Golden data for baseIsLeftToRight() results */2033private static boolean[][] baseIsLTR4Constructor2 = {2034/* For Text #0 - $4 */2035{true, true, true, false},2036{true, true, true, false},2037{true, true, true, false},2038{false, false, true, false},2039{false, false, true, false},20402041/* For Text #5 - $9 */2042{false, false, true, false},2043{false, false, true, false},2044{false, false, true, false},2045{true, true, true, false},2046{true, true, true, false},20472048/* For Text #10 - $14 */2049{true, true, true, false},2050{true, true, true, false},2051{true, true, true, false},2052{true, true, true, false},2053{true, true, true, false},20542055/* For Text #15 - $19 */2056{true, true, true, false},2057{true, true, true, false},2058{true, true, true, false},2059{true, true, true, false},2060{false, false, true, false},20612062/* For Text #20 - $22 */2063{true, true, true, false},2064{true, true, true, false},2065{true, true, true, false},2066};20672068/* Golden data for isLeftToRight() & isRightToLeft() results */2069private static boolean[][][] isLTR_isRTL4Constructor2 = {2070/* isLeftToRight() results & isRightToLeft() results */2071/* For Text #0 - $4 */2072{{true, true, true, false}, {false, false, false, false}},2073{{false, false, false, false}, {false, false, false, false}},2074{{false, false, false, false}, {false, false, false, false}},2075{{false, false, false, false}, {false, false, false, false}},2076{{false, false, false, false}, {false, false, false, false}},20772078/* For Text #5 - $9 */2079{{false, false, false, false}, {true, true, false, true }},2080{{false, false, false, false}, {false, false, false, false}},2081{{false, false, false, false}, {true, true, false, true }},2082{{false, false, false, false}, {false, false, false, false}},2083{{true, true, true, false}, {false, false, false, false}},20842085/* For Text #10 - $14 */2086{{false, false, false, false}, {false, false, false, false}},2087{{false, false, false, false}, {false, false, false, false}},2088{{false, false, false, false}, {false, false, false, false}},2089{{false, false, false, false}, {false, false, false, false}},2090{{false, false, false, false}, {false, false, false, false}},20912092/* For Text #15 - $19 */2093{{false, false, false, false}, {false, false, false, false}},2094{{false, false, false, false}, {false, false, false, false}},2095{{false, false, false, false}, {false, false, false, false}},2096{{false, false, false, false}, {false, false, false, false}},2097{{false, false, false, false}, {false, false, false, false}},20982099/* For Text #20 - $22 */2100{{false, false, false, false}, {false, false, false, false}},2101{{false, false, false, false}, {false, false, false, false}},2102{{false, false, false, false}, {false, false, false, false}},2103};21042105/* Golden data for requiresBidi() results */2106private static boolean[] requiresBidi4Constructor2 = {2107/* For Text #0 - $9 */2108false, true, true, true, true,2109true, true, true, true, false,21102111/* For Text #10 - $19 */2112true, true, true, true, true,2113true, true, true, true, true,21142115/* For Text #20 - $22 */2116true, true, true,2117};21182119/* --------------------------------------------------------------------- */21202121/*2122* Test data for Bidi(char[], ...) constructor and methods2123*/21242125/* Enbeddings */2126private static byte[][][] emb4Constructor3 = {2127/* Embeddings for paragraphs which don't include surrogate pairs. */2128{{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},2129{0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0},2130{0, 0, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, 0, 0, 0, 0, 0, 0},2131{0, 0, 0, 0, 0, -4, -4, -4, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0}},21322133/* Embeddings for paragraphs which include surrogate pairs. */2134{{ 0, 0, 0, 0, 0, 0, 0, 0,21351, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,21360, 0, 0, 0, 0, 0, 0, 0, 0},2137{ 0, 0, 0, 0, 0, 0, 0, 0,21382, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,21390, 0, 0, 0, 0, 0, 0, 0, 0},2140{ 0, 0, 0, 0, 0, 0, 0, 0,2141-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,21420, 0, 0, 0, 0, 0, 0, 0, 0},2143{ 0, 0, 0, 0, 0, 0, 0, 0,2144-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,21450, 0, 0, 0, 0, 0, 0, 0, 0}},2146};21472148/* Text for Bidi processing and its levels */2149private static String[][] data4Constructor3 = {2150/* For Text #0 */2151{"abc <ABC XYZ> xyz.",2152/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2153"000002222222000000", "000000000000000000",2154"000003333333000000", "000000000000000000",2155/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2156"222222222222222221", "222222222222222221",2157"222113333333112221", "222224444444222221",2158/* DIRECTION_LEFT_TO_RIGHT */2159"000002222222000000", "000000000000000000",2160"000003333333000000", "000000000000000000",2161/* DIRECTION_RIGHT_TO_LEFT */2162"222222222222222221", "222222222222222221",2163"222113333333112221", "222224444444222221"},21642165/* For Text #1 */2166{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",2167/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2168"000001111111000000", "000003333333000000",2169"000003333333000000", "000000000000000000",2170/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2171"222111111111112221", "222223333333222221",2172"222113333333112221", "222224444444222221",2173/* DIRECTION_LEFT_TO_RIGHT */2174"000001111111000000", "000003333333000000",2175"000003333333000000", "000000000000000000",2176/* DIRECTION_RIGHT_TO_LEFT */2177"222111111111112221", "222223333333222221",2178"222113333333112221", "222224444444222221"},21792180/* For Text #2 */2181{NKoABC + " <ABC XYZ> " + NKo123 + ".",2182/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2183"111112222222111111", "111112222222111111",2184"111111111111111111", "111114444444111111",2185/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2186"111112222222111111", "111112222222111111",2187"111111111111111111", "111114444444111111",2188/* DIRECTION_LEFT_TO_RIGHT */2189"111112222222111110", "111002222222001110",2190"111113333333111110", "111004444444001110",2191/* DIRECTION_RIGHT_TO_LEFT */2192"111112222222111111", "111112222222111111",2193"111111111111111111", "111114444444111111"},21942195/* For Text #3 */2196{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",2197/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2198"111111111222111111", "111113333444111111",2199"111111111111111111", "111114444444111111",2200/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2201"111111111222111111", "111113333444111111",2202"111111111111111111", "111114444444111111",2203/* DIRECTION_LEFT_TO_RIGHT */2204"111111111222111110", "111003333444001110",2205"111113333333111110", "111004444444001110",2206/* DIRECTION_RIGHT_TO_LEFT */2207"111111111222111111", "111113333444111111",2208"111111111111111111", "111114444444111111"},22092210/* For Text #4 */2211{"abc <123 456> xyz.",2212/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2213"000002221222000000", "000000000000000000",2214"000003333333000000", "000000000000000000",2215/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2216"222222222222222221", "222222222222222221",2217"222113333333112221", "222224444444222221",2218/* DIRECTION_LEFT_TO_RIGHT */2219"000002221222000000", "000000000000000000",2220"000003333333000000", "000000000000000000",2221/* DIRECTION_RIGHT_TO_LEFT */2222"222222222222222221", "222222222222222221",2223"222113333333112221", "222224444444222221"},22242225/* For Text #5 */2226{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +2227Osmanya123 + ".",2228/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2229"000000001111111111111000000000", "000000003333333333333000000000",2230"000000003333333333333000000000", "000000000000000000000000000000",2231/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2232"222222111111111111111112222221", "222222223333333333333222222221",2233"222222113333333333333112222221", "222222224444444444444222222221",2234/* DIRECTION_LEFT_TO_RIGHT */2235"000000001111111111111000000000", "000000003333333333333000000000",2236"000000003333333333333000000000", "000000000000000000000000000000",2237/* DIRECTION_RIGHT_TO_LEFT */2238"222222111111111111111112222221", "222222223333333333333222222221",2239"222222113333333333333112222221", "222222224444444444444222222221"},22402241/* For Text #6 */2242{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +2243Kharoshthi123 + ".",2244/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */2245"111111112222222222222111111111", "111111112222222222222111111111",2246"111111111111111111111111111111", "111111114444444444444111111111",2247/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */2248"111111112222222222222111111111", "111111112222222222222111111111",2249"111111111111111111111111111111", "111111114444444444444111111111",2250/* DIRECTION_LEFT_TO_RIGHT */2251"111111112222222222222111111110", "111111002222222222222001111110",2252"111111113333333333333111111110", "111111004444444444444001111110",2253/* DIRECTION_RIGHT_TO_LEFT */2254"111111112222222222222111111111", "111111112222222222222111111111",2255"111111111111111111111111111111", "111111114444444444444111111111"},2256};22572258/* Golden data for baseIsLeftToRight() results */2259private static boolean[][] baseIsLTR4Constructor3 = {2260/* For Text #0 */2261{true, true, true, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2262true, true, true, true, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2263true, true, true, true, // DIRECTION_LEFT_TO_RIGHT2264false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT22652266/* For Text #1 */2267{true, true, true, true,2268true, true, true, true,2269true, true, true, true,2270false, false, false, false},22712272/* For Text #2 */2273{false, false, false, false,2274false, false, false, false,2275true, true, true, true,2276false, false, false, false},22772278/* For Text #3 */2279{false, false, false, false,2280false, false, false, false,2281true, true, true, true,2282false, false, false, false},22832284/* For Text #4 */2285{true, true, true, true,2286true, true, true, true,2287true, true, true, true,2288false, false, false, false},22892290/* For Text #5 */2291{true, true, true, true,2292true, true, true, true,2293true, true, true, true,2294false, false, false, false},22952296/* For Text #6 */2297{false, false, false, false,2298false, false, false, false,2299true, true, true, true,2300false, false, false, false},2301};23022303/* Golden data for isLeftToRight() & isRightToLeft() results */2304private static boolean[][][] isLTR_isRTL4Constructor3 = {2305/* For Text #0 */2306/* isLeftToRight() results */2307{{false, true, false, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2308false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2309false, true, false, true, // DIRECTION_LEFT_TO_RIGHT2310false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT2311/* isRightToLeft() results */2312{false, false, false, false, // DIRECTION_DEFAULT_LEFT_TO_RIGHT2313false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT2314false, false, false, false, // DIRECTION_LEFT_TO_RIGHT2315false, false, false, false}}, // DIRECTION_RIGHT_TO_LEFTT23162317/* For Text #1 */2318/* isLeftToRight() results */2319{{false, false, false, true,2320false, false, false, false,2321false, false, false, true,2322false, false, false, false},2323/* isRightToLeft() results */2324{false, false, false, false,2325false, false, false, false,2326false, false, false, false,2327false, false, false, false}},23282329/* For Text #2 */2330/* isLeftToRight() results */2331{{false, false, false, false,2332false, false, false, false,2333false, false, false, false,2334false, false, false, false},2335/* isRightToLeft() results */2336{false, false, true, false,2337false, false, true, false,2338false, false, false, false,2339false, false, true, false}},23402341/* For Text #3 */2342/* isLeftToRight() results */2343{{false, false, false, false,2344false, false, false, false,2345false, false, false, false,2346false, false, false, false},2347/* isRightToLeft() results */2348{false, false, true, false,2349false, false, true, false,2350false, false, false, false,2351false, false, true, false}},23522353/* For Text #4 */2354/* isLeftToRight() results */2355{{false, true, false, true,2356false, false, false, false,2357false, true, false, true,2358false, false, false, false },2359/* isRightToLeft() results */2360{false, false, false, false,2361false, false, false, false,2362false, false, false, false,2363false, false, false, false}},23642365/* For Text #5 */2366/* isLeftToRight() results */2367{{false, false, false, true,2368false, false, false, false,2369false, false, false, true,2370false, false, false, false},2371/* isRightToLeft() results */2372{false, false, false, false,2373false, false, false, false,2374false, false, false, false,2375false, false, false, false}},23762377/* For Text #6 */2378/* isLeftToRight() results */2379{{false, false, false, false,2380false, false, false, false,2381false, false, false, false,2382false, false, false, false},2383/* isRightToLeft() results */2384{false, false, true, false,2385false, false, true, false,2386false, false, false, false,2387false, false, true, false}},2388};23892390/* --------------------------------------------------------------------- */23912392/*2393* Test data for reorderVisually() methods2394*/23952396private static Object[][][] data4reorderVisually = {2397{{"ABC", " ", "abc", " ", ArabicABC, "."}, // Original text2398{"000000001110"}, // levels2399{"ABC", " ", "abc", " ", ArabicABC, "."}}, // Reordered text24002401{{"ABC", " ", HebrewABC, " ", NKoABC, "."},2402{"222111111111"},2403{".", NKoABC, " ", HebrewABC, " ", "ABC"}},24042405{{OsmanyaABC, " ", HebrewABC, " ", KharoshthiABC, "."},2406{"222222111111111111"},2407{".", KharoshthiABC, " ", HebrewABC, " ", OsmanyaABC,}},24082409{{"ABC", " ", Osmanya123, " ", "\"", OsmanyaABC, " ", Kharoshthi123,2410" ", KharoshthiABC, ".", "\""},2411{"0000000000002222221111111111111100"},2412{"ABC", " ", Osmanya123, " ", "\"", KharoshthiABC, " ", Kharoshthi123,2413" ", OsmanyaABC, ".", "\""}},2414};24152416}241724182419