Home | History | Annotate | Download | only in bidi
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 /*
      3 *******************************************************************************
      4 *   Copyright (C) 2007-2013, International Business Machines
      5 *   Corporation and others.  All Rights Reserved.
      6 *******************************************************************************
      7 */
      8 
      9 package android.icu.dev.test.bidi;
     10 
     11 import java.util.Arrays;
     12 
     13 import android.icu.text.Bidi;
     14 import android.icu.text.BidiRun;
     15 import org.junit.runner.RunWith;
     16 import android.icu.junit.IcuTestFmwkRunner;
     17 
     18 /**
     19  * Regression test for Bidi class override.
     20  *
     21  * @author Lina Kemmel, Matitiahu Allouche
     22  */
     23 
     24 @RunWith(IcuTestFmwkRunner.class)
     25 public class TestBidi extends BidiTest {
     26 
     27     private static final int MAXLEN = 256;
     28     private static final String levelString = "............................";
     29 
     30     public void testBidi() {
     31         Bidi bidi;
     32         Bidi bidiLine;
     33 
     34         logln("\nEntering TestBidi");
     35         bidi = new Bidi(MAXLEN, 0);
     36         bidiLine = new Bidi();
     37 
     38         doTests(bidi, bidiLine, false);
     39         doTests(bidi, bidiLine, true);
     40         doMisc();
     41         logln("\nExiting TestBidi");
     42     }
     43 
     44     private void doTests(Bidi bidi, Bidi bidiLine, boolean countRunsFirst) {
     45         int testNumber;
     46         String string;
     47         int lineStart;
     48         byte paraLevel;
     49         int bidiTestCount = TestData.testCount();
     50 
     51         for (testNumber = 0; testNumber < bidiTestCount; ++testNumber) {
     52             TestData test = TestData.getTestData(testNumber);
     53             string = getStringFromDirProps(test.dirProps);
     54             paraLevel = test.paraLevel;
     55             try {
     56                 bidi.setPara(string, paraLevel, null);
     57                 logln("Bidi.setPara(tests[" + testNumber + "] OK, direction "
     58                         + bidi.getDirection() + " paraLevel "
     59                         + paraLevel);
     60             } catch (Exception e) {
     61                 errln("Bidi.setPara(tests[" + testNumber + "] failed, direction "
     62                         + bidi.getDirection() + " paraLevel "
     63                         + paraLevel);
     64             }
     65             lineStart = test.lineStart;
     66             if (lineStart == -1) {
     67                 doTest(bidi, testNumber, test, 0, countRunsFirst);
     68             } else {
     69                 try {
     70                     bidiLine = bidi.setLine(lineStart, test.lineLimit);
     71                     logln("Bidi.setLine(" + lineStart + ", " + test.lineLimit
     72                             + "), in tests[" + testNumber + "] OK, direction "
     73                             + bidiLine.getDirection() + " paraLevel "
     74                             + bidiLine.getBaseLevel());
     75                     doTest(bidiLine, testNumber, test, lineStart, countRunsFirst);
     76                 } catch (Exception e)  {
     77                     errln("Bidi.setLine(" + lineStart + ", " + test.lineLimit
     78                             + "), in runAll test[" + testNumber + "] failed");
     79                 }
     80                 /* do it again using createLineBidi instead of setLine */
     81                 try {
     82                     bidiLine = bidi.createLineBidi(lineStart, test.lineLimit);
     83                     logln("Bidi.createLineBidi(" + lineStart + ", " + test.lineLimit
     84                             + "), in tests[" + testNumber + "] OK, direction "
     85                             + bidiLine.getDirection() + " paraLevel "
     86                             + bidiLine.getBaseLevel());
     87                     doTest(bidiLine, testNumber, test, lineStart, countRunsFirst);
     88                 } catch (Exception e)  {
     89                     errln("Bidi.createLineBidi(" + lineStart + ", " + test.lineLimit
     90                             + "), in runAll test[" + testNumber + "] failed");
     91                 }
     92             }
     93         }
     94     }
     95 
     96     private void doTest(Bidi bidi, int testNumber, TestData test,
     97                         int lineStart, boolean countRunsFirst) {
     98         short[] dirProps = test.dirProps;
     99         byte[] levels = test.levels;
    100         int[] visualMap = test.visualMap;
    101         int i, len = bidi.getLength(), logicalIndex = -1, runCount = 0;
    102         byte level, level2;
    103 
    104         if (countRunsFirst) {
    105             logln("Calling Bidi.countRuns() first.");
    106             try {
    107                 runCount = bidi.countRuns();
    108             } catch (IllegalStateException e) {
    109                 errln("Bidi.countRuns(test[" + testNumber + "]) failed");
    110             }
    111         } else {
    112             logln("Calling Bidi.getLogicalMap() first.");
    113         }
    114 
    115         _testReordering(bidi, testNumber);
    116 
    117         for (i = 0; i < len; ++i) {
    118             logln(i + "  " + bidi.getLevelAt(i) + "  " + levelString
    119                     + TestData.dirPropNames[dirProps[lineStart + i]] + "  "
    120                     + bidi.getVisualIndex(i));
    121         }
    122 
    123         log("\n-----levels:");
    124         for (i = 0; i < len; ++i) {
    125             if (i > 0) {
    126                 log(",");
    127             }
    128             log(" " + bidi.getLevelAt(i));
    129         }
    130 
    131         log("\n--reordered:");
    132         for (i = 0; i < len; ++i) {
    133             if (i > 0) {
    134                 log(",");
    135             }
    136             log(" " + bidi.getVisualIndex(i));
    137         }
    138         log("\n");
    139 
    140         assertEquals("\nFailure in Bidi.getDirection(test[" + testNumber + "])",
    141                      test.direction, bidi.getDirection());
    142         assertEquals("\nFailure in Bidi.getParaLevel(test[" + testNumber + "])",
    143                      test.resultLevel, bidi.getParaLevel());
    144 
    145         for (i = 0; i < len; ++i) {
    146             assertEquals("\nFailure in Bidi.getLevelAt(" + i +
    147                          ") in test[" + testNumber + "]",
    148                          levels[i], bidi.getLevelAt(i));
    149         }
    150 
    151         for (i = 0; i < len; ++i) {
    152             try {
    153                 logicalIndex = bidi.getVisualIndex(i);
    154             } catch (Throwable th) {
    155                 errln("Bidi.getVisualIndex(" + i + ") in test[" + testNumber
    156                         + "] failed");
    157             }
    158             if(visualMap[i] != logicalIndex) {
    159                 assertEquals("\nFailure in Bidi.getVisualIndex(" + i +
    160                              ") in test[" + testNumber + "])",
    161                              visualMap[i], logicalIndex);
    162             }
    163         }
    164 
    165         if (!countRunsFirst) {
    166             try {
    167                 runCount = bidi.countRuns();
    168             } catch (IllegalStateException e) {
    169                 errln("Bidi.countRuns(test[" + testNumber + "]) failed");
    170             }
    171         }
    172 
    173         BidiRun run;
    174 
    175         for (logicalIndex = 0; logicalIndex < len; ) {
    176             level = bidi.getLevelAt(logicalIndex);
    177             run = bidi.getLogicalRun(logicalIndex);
    178             logicalIndex = run.getLimit();
    179             level2 = run.getEmbeddingLevel();
    180             assertEquals("Logical " + run.toString() +
    181                          " in test[" + testNumber + "]: wrong level",
    182                          level, level2);
    183             if (--runCount < 0) {
    184                 errln("Bidi.getLogicalRun(test[" + testNumber
    185                       + "]): wrong number of runs compared to Bidi.countRuns() = "
    186                       + bidi.countRuns());
    187             }
    188         }
    189         if (runCount != 0) {
    190             errln("Bidi.getLogicalRun(test[" + testNumber
    191                     + "]): wrong number of runs compared to Bidi.countRuns() = "
    192                     + bidi.countRuns());
    193         }
    194 
    195         log("\n\n");
    196     }
    197 
    198     private void _testReordering(Bidi bidi, int testNumber) {
    199         int[] logicalMap1;
    200         int[] logicalMap2;
    201         int[] logicalMap3;
    202         int[] visualMap1;
    203         int[] visualMap2;
    204         int[] visualMap3;
    205         int[] visualMap4 = new int[MAXLEN];
    206         byte[] levels;
    207         int i, length = bidi.getLength(),
    208                destLength = bidi.getResultLength();
    209         int runCount, visualIndex, logicalIndex = -1, logicalStart, runLength;
    210         boolean odd;
    211 
    212         if(length <= 0) {
    213             return;
    214         }
    215         /* get the logical and visual maps from the object */
    216         logicalMap1 = bidi.getLogicalMap();
    217         if (logicalMap1 == null) {
    218             errln("getLogicalMap in test " + testNumber + " is null");
    219             logicalMap1 = new int[0];
    220         }
    221 
    222         visualMap1 = bidi.getVisualMap();
    223 
    224         if (visualMap1 == null) {
    225             errln("getVisualMap() in test " + testNumber + " is null");
    226             visualMap1 = new int[0];
    227         }
    228 
    229         /* invert them both */
    230         visualMap2 = Bidi.invertMap(logicalMap1);
    231         logicalMap2 = Bidi.invertMap(visualMap1);
    232 
    233         /* get them from the levels array, too */
    234         levels = bidi.getLevels();
    235 
    236         if (levels == null || levels.length != length) {
    237             errln("getLevels() in test " + testNumber + " failed");
    238         }
    239 
    240         logicalMap3 = Bidi.reorderLogical(levels);
    241         visualMap3 = Bidi.reorderVisual(levels);
    242 
    243         /* get the visual map from the runs, too */
    244         try {
    245             runCount = bidi.countRuns();
    246         } catch (IllegalStateException e) {
    247             errln("countRuns() in test " + testNumber + " failed");
    248             runCount = 0;
    249         }
    250 
    251         logln("\n---- " + runCount + " runs");
    252         visualIndex = 0;
    253         BidiRun run;
    254         for (i = 0; i < runCount; ++i) {
    255             run = bidi.getVisualRun(i);
    256             if (run == null) {
    257                 errln("null visual run encountered at index " + i +
    258                       ", in test " + testNumber);
    259                 continue;
    260             }
    261             odd = run.isOddRun();
    262             logicalStart = run.getStart();
    263             runLength = run.getLength();
    264             log("(" + (run.isOddRun() ? "R" : "L"));
    265             log(" @" + run.getStart() + '[' + run.getLength() + "])\n");
    266             if (!odd) {
    267                 do {    /* LTR */
    268                     visualMap4[visualIndex++] = logicalStart++;
    269                 } while (--runLength > 0);
    270             } else {
    271                 logicalStart += runLength;  /* logicalLimit */
    272                 do {    /* RTL */
    273                     visualMap4[visualIndex++] = --logicalStart;
    274                 } while (--runLength > 0);
    275             }
    276         }
    277         log("\n");
    278 
    279         /* print all the maps */
    280         logln("logical maps:");
    281         for (i = 0; i < length; ++i) {
    282             log(logicalMap1[i] + " ");
    283         }
    284         log("\n");
    285         for (i = 0; i < length; ++i) {
    286             log(logicalMap2[i] + " ");
    287         }
    288         log("\n");
    289         for (i = 0; i < length; ++i) {
    290             log(logicalMap3[i] + " ");
    291         }
    292 
    293         log("\nvisual maps:\n");
    294         for (i = 0; i < destLength; ++i) {
    295             log(visualMap1[i] + " ");
    296         }
    297         log("\n");
    298         for (i = 0; i < destLength; ++i) {
    299             log(visualMap2[i] + " ");
    300         }
    301         log("\n");
    302         for (i = 0; i < length; ++i) {
    303             log(visualMap3[i] + " ");
    304         }
    305         log("\n");
    306         for (i = 0; i < length; ++i) {
    307             log(visualMap4[i] + " ");
    308         }
    309         log("\n");
    310 
    311         /* check that the indexes are the same between these and Bidi.getLogical/VisualIndex() */
    312         for (i = 0; i < length; ++i) {
    313             if (logicalMap1[i] != logicalMap2[i]) {
    314                 errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i +
    315                       "] == " + logicalMap1[i] + ") != (logicalMap2[" + i +
    316                       "] == " + logicalMap2[i] + ")");
    317             }
    318             if (logicalMap1[i] != logicalMap3[i]) {
    319                 errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i +
    320                       "] == " + logicalMap1[i] + ") != (logicalMap3[" + i +
    321                       "] == " + logicalMap3[i] + ")");
    322             }
    323             if (visualMap1[i] != visualMap2[i]) {
    324                 errln("Error in tests[" + testNumber + "]: (visualMap1[" + i +
    325                       "] == " + visualMap1[i] + ") != (visualMap2[" + i +
    326                       "] == " + visualMap2[i] + ")");
    327             }
    328             if (visualMap1[i] != visualMap3[i]) {
    329                 errln("Error in tests[" + testNumber + "]: (visualMap1[" + i +
    330                       "] == " + visualMap1[i] + ") != (visualMap3[" + i +
    331                       "] == " + visualMap3[i] + ")");
    332             }
    333             if (visualMap1[i] != visualMap4[i]) {
    334                 errln("Error in tests[" + testNumber + "]: (visualMap1[" + i +
    335                       "] == " + visualMap1[i] + ") != (visualMap4[" + i +
    336                       "] == " + visualMap4[i] + ")");
    337             }
    338             try {
    339                 visualIndex = bidi.getVisualIndex(i);
    340             } catch (Exception e) {
    341                 errln("Bidi.getVisualIndex(" + i + ") failed in tests[" +
    342                       testNumber + "]");
    343             }
    344             if (logicalMap1[i] != visualIndex) {
    345                 errln("Error in tests[" + testNumber + "]: (logicalMap1[" + i +
    346                       "] == " + logicalMap1[i] + ") != (Bidi.getVisualIndex(" + i +
    347                       ") == " + visualIndex + ")");
    348             }
    349             try {
    350                 logicalIndex = bidi.getLogicalIndex(i);
    351             } catch (Exception e) {
    352                 errln("Bidi.getLogicalIndex(" + i + ") failed in tests[" +
    353                       testNumber + "]");
    354             }
    355             if (visualMap1[i] != logicalIndex) {
    356                 errln("Error in tests[" + testNumber + "]: (visualMap1[" + i +
    357                       "] == " + visualMap1[i] + ") != (Bidi.getLogicalIndex(" + i +
    358                       ") == " + logicalIndex + ")");
    359             }
    360         }
    361     }
    362 
    363     private String getStringFromDirProps(short[] dirProps) {
    364         int i;
    365 
    366         if (dirProps == null) {
    367             return null;
    368         }
    369         int length = dirProps.length;
    370         char[] buffer = new char[length];
    371 
    372         /* this part would have to be modified for UTF-x */
    373         for (i = 0; i < length; ++i) {
    374             buffer[i] = charFromDirProp[dirProps[i]];
    375         }
    376         return new String(buffer);
    377     }
    378 
    379     private void doMisc() {
    380     /* Miscellaneous tests to exercize less popular code paths */
    381         Bidi bidi = new Bidi(120, 66), bidiLine;
    382 
    383         assertEquals("\nwriteReverse should return an empty string",
    384                      "", Bidi.writeReverse("", 0));
    385 
    386         bidi.setPara("", Bidi.LTR, null);
    387         assertEquals("\nwriteReordered should return an empty string",
    388                      "", bidi.writeReordered(0));
    389 
    390         bidi.setPara("abc", Bidi.LTR, null);
    391         assertEquals("\ngetRunStart should return 0",
    392                      0, bidi.getRunStart(0));
    393         assertEquals("\ngetRunLimit should return 3",
    394                      3, bidi.getRunLimit(0));
    395 
    396         bidi.setPara("abc          ", Bidi.RTL, null);
    397         bidiLine = bidi.setLine(0, 6);
    398         for (int i = 3; i < 6; i++) {
    399             assertEquals("\nTrailing space at " + i + " should get paragraph level",
    400                          Bidi.RTL, bidiLine.getLevelAt(i));
    401         }
    402 
    403         bidi.setPara("abc       def", Bidi.RTL, null);
    404         bidiLine = bidi.setLine(0, 6);
    405         for (int i = 3; i < 6; i++) {
    406             assertEquals("\nTrailing space at " + i + " should get paragraph level",
    407                          Bidi.RTL, bidiLine.getLevelAt(i));
    408         }
    409 
    410         bidi.setPara("abcdefghi    ", Bidi.RTL, null);
    411         bidiLine = bidi.setLine(0, 6);
    412         for (int i = 3; i < 6; i++) {
    413             assertEquals("\nTrailing char at " + i + " should get level 2",
    414                          2, bidiLine.getLevelAt(i));
    415         }
    416 
    417         bidi.setReorderingOptions(Bidi.OPTION_REMOVE_CONTROLS);
    418         bidi.setPara("\u200eabc       def", Bidi.RTL, null);
    419         bidiLine = bidi.setLine(0, 6);
    420         assertEquals("\nWrong result length", 5, bidiLine.getResultLength());
    421 
    422         bidi.setPara("abcdefghi", Bidi.LTR, null);
    423         bidiLine = bidi.setLine(0, 6);
    424         assertEquals("\nWrong direction #1", Bidi.LTR, bidiLine.getDirection());
    425 
    426         bidi.setPara("", Bidi.LTR, null);
    427         byte[] levels = bidi.getLevels();
    428         assertEquals("\nWrong number of level elements", 0, levels.length);
    429         assertEquals("\nWrong number of runs #1", 0, bidi.countRuns());
    430 
    431         bidi.setPara("          ", Bidi.RTL, null);
    432         bidiLine = bidi.setLine(0, 6);
    433         assertEquals("\nWrong number of runs #2", 1, bidiLine.countRuns());
    434 
    435         bidi.setPara("a\u05d0        bc", Bidi.RTL, null);
    436         bidiLine = bidi.setLine(0, 6);
    437         assertEquals("\nWrong direction #2", Bidi.MIXED, bidi.getDirection());
    438         assertEquals("\nWrong direction #3", Bidi.MIXED, bidiLine.getDirection());
    439         assertEquals("\nWrong number of runs #3", 2, bidiLine.countRuns());
    440 
    441         int[] map = Bidi.reorderLogical(null);
    442         assertTrue("\nWe should have got a null map #1", map == null);
    443         map = Bidi.reorderLogical(new byte[] {0,126, 127});
    444         assertTrue("\nWe should have got a null map #2", map == null);
    445         map = Bidi.reorderVisual(null);
    446         assertTrue("\nWe should have got a null map #3", map == null);
    447         map = Bidi.reorderVisual(new byte[] {0, -1, 4});
    448         assertTrue("\nWe should have got a null map #4", map == null);
    449 
    450         map = Bidi.invertMap(null);
    451         assertTrue("\nWe should have got a null map #5", map == null);
    452         map = Bidi.invertMap(new int[] {0,1,-1,5,4});
    453         assertTrue("\nUnexpected inverted Map",
    454                    Arrays.equals(map, new int[] {0,1,-1,-1,4,3}));
    455 
    456         bidi.setPara("", Bidi.LTR, null);
    457         map = bidi.getLogicalMap();
    458         assertTrue("\nMap should have length==0 #1", map.length == 0);
    459         map = bidi.getVisualMap();
    460         assertTrue("\nMap should have length==0 #2", map.length == 0);
    461 
    462         /* test BidiRun.toString and allocation of run memory > 1 */
    463         bidi.setPara("abc", Bidi.LTR, null);
    464         assertEquals("\nWrong run display", "BidiRun 0 - 3 @ 0",
    465                      bidi.getLogicalRun(0).toString());
    466 
    467         /* test REMOVE_BIDI_CONTROLS together with DO_MIRRORING */
    468         bidi.setPara("abc\u200e", Bidi.LTR, null);
    469         String out = bidi.writeReordered(Bidi.REMOVE_BIDI_CONTROLS | Bidi.DO_MIRRORING);
    470         assertEquals("\nWrong result #1", "abc", out);
    471 
    472         /* test inverse Bidi with marks and contextual orientation */
    473         bidi.setReorderingMode(Bidi.REORDER_INVERSE_LIKE_DIRECT);
    474         bidi.setReorderingOptions(Bidi.OPTION_INSERT_MARKS);
    475         bidi.setPara("", Bidi.LEVEL_DEFAULT_RTL, null);
    476         out = bidi.writeReordered(0);
    477         assertEquals("\nWrong result #2", "", out);
    478         bidi.setPara("   ", Bidi.LEVEL_DEFAULT_RTL, null);
    479         out = bidi.writeReordered(0);
    480         assertEquals("\nWrong result #3", "   ", out);
    481         bidi.setPara("abc", Bidi.LEVEL_DEFAULT_RTL, null);
    482         out = bidi.writeReordered(0);
    483         assertEquals("\nWrong result #4", "abc", out);
    484         bidi.setPara("\u05d0\u05d1", Bidi.LEVEL_DEFAULT_RTL, null);
    485         out = bidi.writeReordered(0);
    486         assertEquals("\nWrong result #5", "\u05d1\u05d0", out);
    487         bidi.setPara("abc \u05d0\u05d1", Bidi.LEVEL_DEFAULT_RTL, null);
    488         out = bidi.writeReordered(0);
    489         assertEquals("\nWrong result #6", "\u05d1\u05d0 abc", out);
    490         bidi.setPara("\u05d0\u05d1 abc", Bidi.LEVEL_DEFAULT_RTL, null);
    491         out = bidi.writeReordered(0);
    492         assertEquals("\nWrong result #7", "\u200fabc \u05d1\u05d0", out);
    493         bidi.setPara("\u05d0\u05d1 abc .-=", Bidi.LEVEL_DEFAULT_RTL, null);
    494         out = bidi.writeReordered(0);
    495         assertEquals("\nWrong result #8", "\u200f=-. abc \u05d1\u05d0", out);
    496         bidi.orderParagraphsLTR(true);
    497         bidi.setPara("\n\r   \n\rabc\n\u05d0\u05d1\rabc \u05d2\u05d3\n\r" +
    498                      "\u05d4\u05d5 abc\n\u05d6\u05d7 abc .-=\r\n" +
    499                      "-* \u05d8\u05d9 abc .-=", Bidi.LEVEL_DEFAULT_RTL, null);
    500         out = bidi.writeReordered(0);
    501         assertEquals("\nWrong result #9",
    502                      "\n\r   \n\rabc\n\u05d1\u05d0\r\u05d3\u05d2 abc\n\r" +
    503                      "\u200fabc \u05d5\u05d4\n\u200f=-. abc \u05d7\u05d6\r\n" +
    504                      "\u200f=-. abc \u05d9\u05d8 *-", out);
    505 
    506         bidi.setPara("\u05d0 \t", Bidi.LTR, null);
    507         out = bidi.writeReordered(0);
    508         assertEquals("\nWrong result #10", "\u05D0\u200e \t", out);
    509         bidi.setPara("\u05d0 123 \t\u05d1 123 \u05d2", Bidi.LTR, null);
    510         out = bidi.writeReordered(0);
    511         assertEquals("\nWrong result #11", "\u05d0 \u200e123\u200e \t\u05d2 123 \u05d1", out);
    512         bidi.setPara("\u05d0 123 \u0660\u0661 ab", Bidi.LTR, null);
    513         out = bidi.writeReordered(0);
    514         assertEquals("\nWrong result #12", "\u05d0 \u200e123 \u200e\u0660\u0661 ab", out);
    515         bidi.setPara("ab \t", Bidi.RTL, null);
    516         out = bidi.writeReordered(0);
    517         assertEquals("\nWrong result #13", "\u200f\t ab", out);
    518 
    519         /* check exceeding para level */
    520         bidi = new Bidi();
    521         bidi.setPara("A\u202a\u05d0\u202aC\u202c\u05d1\u202cE", (byte)(Bidi.MAX_EXPLICIT_LEVEL - 1), null);
    522         assertEquals("\nWrong level at index 2", Bidi.MAX_EXPLICIT_LEVEL, bidi.getLevelAt(2));
    523 
    524         /* check 1-char runs with RUNS_ONLY */
    525         bidi.setReorderingMode(Bidi.REORDER_RUNS_ONLY);
    526         bidi.setPara("a \u05d0 b \u05d1 c \u05d2 d ", Bidi.LTR, null);
    527         assertEquals("\nWrong number of runs #4", 14, bidi.countRuns());
    528 
    529         /* test testGetBaseDirection to verify fast string direction detection function */
    530         /* mixed start with L */
    531         String mixedEnglishFirst = "\u0061\u0627\u0032\u06f3\u0061\u0034";
    532         assertEquals("\nWrong direction through fast detection #1", Bidi.LTR, Bidi.getBaseDirection(mixedEnglishFirst));
    533         /* mixed start with AL */
    534         String mixedArabicFirst = "\u0661\u0627\u0662\u06f3\u0061\u0664";
    535         assertEquals("\nWrong direction through fast detection #2", Bidi.RTL, Bidi.getBaseDirection(mixedArabicFirst));
    536         /* mixed Start with R */
    537         String mixedHebrewFirst = "\u05EA\u0627\u0662\u06f3\u0061\u0664";
    538         assertEquals("\nWrong direction through fast detection #3", Bidi.RTL, Bidi.getBaseDirection(mixedHebrewFirst));
    539         /* all AL (Arabic. Persian) */
    540         String persian = "\u0698\u067E\u0686\u06AF";
    541         assertEquals("\nWrong direction through fast detection #4", Bidi.RTL, Bidi.getBaseDirection(persian));
    542         /* all R (Hebrew etc.) */
    543         String hebrew = "\u0590\u05D5\u05EA\u05F1";
    544         assertEquals("\nWrong direction through fast detection #5", Bidi.RTL, Bidi.getBaseDirection(hebrew));
    545         /* all L (English) */
    546         String english = "\u0071\u0061\u0066";
    547         assertEquals("\nWrong direction through fast detection #6", Bidi.LTR, Bidi.getBaseDirection(english));
    548         /* mixed start with weak AL an then L */
    549         String startWeakAL = "\u0663\u0071\u0061\u0066";
    550         assertEquals("\nWrong direction through fast detection #7", Bidi.LTR, Bidi.getBaseDirection(startWeakAL));
    551         /* mixed start with weak L and then AL */
    552         String startWeakL = "\u0031\u0698\u067E\u0686\u06AF";
    553         assertEquals("\nWrong direction through fast detection #8", Bidi.RTL, Bidi.getBaseDirection(startWeakL));
    554         /* empty */
    555         String empty = "";
    556         assertEquals("\nWrong direction through fast detection #9", Bidi.NEUTRAL, Bidi.getBaseDirection(empty));
    557         /* surrogate character */
    558         String surrogateChar = "\uD800\uDC00";
    559         assertEquals("\nWrong direction through fast detection #10", Bidi.LTR, Bidi.getBaseDirection(surrogateChar));
    560         /* all weak L (English digits) */
    561         String allEnglishDigits = "\u0031\u0032\u0033";
    562         assertEquals("\nWrong direction through fast detection #11", Bidi.NEUTRAL, Bidi.getBaseDirection(allEnglishDigits));
    563         /* all weak AL (Arabic digits) */
    564         String allArabicDigits = "\u0663\u0664\u0665";
    565         assertEquals("\nWrong direction through fast detection #12", Bidi.NEUTRAL, Bidi.getBaseDirection(allArabicDigits));
    566         /* null string */
    567         String nullString = null;
    568         assertEquals("\nWrong direction through fast detection #13", Bidi.NEUTRAL, Bidi.getBaseDirection(nullString));
    569         /* first L (English) others are R (Hebrew etc.) */
    570         String startEnglishOthersHebrew = "\u0071\u0590\u05D5\u05EA\u05F1";
    571         assertEquals("\nWrong direction through fast detection #14", Bidi.LTR, Bidi.getBaseDirection(startEnglishOthersHebrew));
    572         /* last R (Hebrew etc.) others are weak L (English Digits) */
    573         String lastHebrewOthersEnglishDigit = "\u0031\u0032\u0033\u05F1";
    574         assertEquals("\nWrong direction through fast detection #15", Bidi.RTL, Bidi.getBaseDirection(lastHebrewOthersEnglishDigit));
    575     }
    576 
    577 
    578     public static void main(String[] args) {
    579         try {
    580             new TestBidi().run(args);
    581         }
    582         catch (Exception e) {
    583             System.out.println(e);
    584         }
    585     }
    586 }
    587