Home | History | Annotate | Download | only in bidi
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5 *******************************************************************************
      6 *   Copyright (C) 2007-2013, International Business Machines
      7 *   Corporation and others.  All Rights Reserved.
      8 *******************************************************************************
      9 */
     10 
     11 package android.icu.dev.test.bidi;
     12 
     13 import org.junit.Test;
     14 
     15 import android.icu.text.Bidi;
     16 import android.icu.testsharding.MainTestShard;
     17 
     18 /**
     19  * Regression test for Bidi failure recovery
     20  *
     21  * @author Lina Kemmel, Matitiahu Allouche
     22  */
     23 
     24 @MainTestShard
     25 public class TestFailureRecovery extends BidiFmwk {
     26 
     27     @Test
     28     public void testFailureRecovery()
     29     {
     30         logln("\nEntering TestFailureRecovery\n");
     31         Bidi bidi = new Bidi();
     32         // Skip the following test since there are no invalid values
     33         // between MAX_EXPLICIT_LEVEL+1 and LEVEL_DEFAULT_LTR
     34         //try {
     35         //    bidi.setPara("abc", (byte)(Bidi.LEVEL_DEFAULT_LTR - 1), null);
     36         //    errln("Bidi.setPara did not fail when passed too big para level");
     37         //} catch (IllegalArgumentException e) {
     38         //    logln("OK: Got exception for bidi.setPara(..., Bidi.LEVEL_DEFAULT_LTR - 1, ...)"
     39         //            + " as expected: " + e.getMessage());
     40         //}
     41         try {
     42             bidi.setPara("abc", (byte)(-1), null);
     43             errln("Bidi.setPara did not fail when passed negative para level");
     44         } catch (IllegalArgumentException e) {
     45             logln("OK: Got exception for bidi.setPara(..., -1, ...)"
     46                     + " as expected: " + e.getMessage());
     47         }
     48         try {
     49             Bidi.writeReverse(null, 0);
     50             errln("Bidi.writeReverse did not fail when passed a null string");
     51         } catch (IllegalArgumentException e) {
     52             logln("OK: Got exception for Bidi.writeReverse(null) as expected: "
     53                   + e.getMessage());
     54         }
     55         bidi = new Bidi();
     56         try {
     57             bidi.setLine(0, 1);
     58             errln("bidi.setLine did not fail when called before valid setPara()");
     59         } catch (IllegalStateException e) {
     60             logln("OK: Got exception for Bidi.setLine(0, 1) as expected: "
     61                   + e.getMessage());
     62         }
     63         try {
     64             bidi.getDirection();
     65             errln("bidi.getDirection did not fail when called before valid setPara()");
     66         } catch (IllegalStateException e) {
     67             logln("OK: Got exception for Bidi.getDirection() as expected: "
     68                   + e.getMessage());
     69         }
     70         bidi.setPara("abc", Bidi.LTR, null);
     71         try {
     72             bidi.getLevelAt(3);
     73             errln("bidi.getLevelAt did not fail when called with bad argument");
     74         } catch (IllegalArgumentException e) {
     75             logln("OK: Got exception for Bidi.getLevelAt(3) as expected: "
     76                   + e.getMessage());
     77         }
     78         try {
     79             bidi = new Bidi(-1, 0);
     80             errln("Bidi constructor did not fail when called with bad argument");
     81         } catch (IllegalArgumentException e) {
     82             logln("OK: Got exception for Bidi(-1,0) as expected: "
     83                   + e.getMessage());
     84         }
     85         bidi = new Bidi(2, 1);
     86         try {
     87             bidi.setPara("abc", Bidi.LTR, null);
     88             errln("setPara did not fail when called with text too long");
     89         } catch (OutOfMemoryError e) {
     90             logln("OK: Got exception for setPara(\"abc\") as expected: "
     91                   + e.getMessage());
     92         }
     93         try {
     94             bidi.setPara("=2", Bidi.RTL, null);
     95             bidi.countRuns();
     96             errln("countRuns did not fail when called for too many runs");
     97         } catch (OutOfMemoryError e) {
     98             logln("OK: Got exception for countRuns as expected: "
     99                   + e.getMessage());
    100         }
    101         int rm = bidi.getReorderingMode();
    102         bidi.setReorderingMode(Bidi.REORDER_DEFAULT - 1);
    103         if (rm != bidi.getReorderingMode()) {
    104             errln("setReorderingMode with bad argument #1 should have no effect");
    105         }
    106         bidi.setReorderingMode(9999);
    107         if (rm != bidi.getReorderingMode()) {
    108             errln("setReorderingMode with bad argument #2 should have no effect");
    109         }
    110         /* Try a surrogate char */
    111         bidi = new Bidi();
    112         bidi.setPara("\uD800\uDC00", Bidi.RTL, null);
    113         if (bidi.getDirection() != Bidi.MIXED) {
    114             errln("getDirection for 1st surrogate char should be MIXED");
    115         }
    116         byte[] levels = new byte[] {6,5,4};
    117         try {
    118             bidi.setPara("abc", (byte)5, levels);
    119             errln("setPara did not fail when called with bad levels");
    120         } catch (IllegalArgumentException e) {
    121             logln("OK: Got exception for setPara(..., levels) as expected: "
    122                   + e.getMessage());
    123         }
    124 
    125         logln("\nExiting TestFailureRecovery\n");
    126     }
    127 }
    128