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 android.icu.text.Bidi; 12 import org.junit.runner.RunWith; 13 import android.icu.junit.IcuTestFmwkRunner; 14 15 /** 16 * Regression test for Bidi failure recovery 17 * 18 * @author Lina Kemmel, Matitiahu Allouche 19 */ 20 21 @RunWith(IcuTestFmwkRunner.class) 22 public class TestFailureRecovery extends BidiTest { 23 24 public void testFailureRecovery() 25 { 26 logln("\nEntering TestFailureRecovery\n"); 27 Bidi bidi = new Bidi(); 28 // Skip the following test since there are no invalid values 29 // between MAX_EXPLICIT_LEVEL+1 and LEVEL_DEFAULT_LTR 30 //try { 31 // bidi.setPara("abc", (byte)(Bidi.LEVEL_DEFAULT_LTR - 1), null); 32 // errln("Bidi.setPara did not fail when passed too big para level"); 33 //} catch (IllegalArgumentException e) { 34 // logln("OK: Got exception for bidi.setPara(..., Bidi.LEVEL_DEFAULT_LTR - 1, ...)" 35 // + " as expected: " + e.getMessage()); 36 //} 37 try { 38 bidi.setPara("abc", (byte)(-1), null); 39 errln("Bidi.setPara did not fail when passed negative para level"); 40 } catch (IllegalArgumentException e) { 41 logln("OK: Got exception for bidi.setPara(..., -1, ...)" 42 + " as expected: " + e.getMessage()); 43 } 44 try { 45 Bidi.writeReverse(null, 0); 46 errln("Bidi.writeReverse did not fail when passed a null string"); 47 } catch (IllegalArgumentException e) { 48 logln("OK: Got exception for Bidi.writeReverse(null) as expected: " 49 + e.getMessage()); 50 } 51 bidi = new Bidi(); 52 try { 53 bidi.setLine(0, 1); 54 errln("bidi.setLine did not fail when called before valid setPara()"); 55 } catch (IllegalStateException e) { 56 logln("OK: Got exception for Bidi.setLine(0, 1) as expected: " 57 + e.getMessage()); 58 } 59 try { 60 bidi.getDirection(); 61 errln("bidi.getDirection did not fail when called before valid setPara()"); 62 } catch (IllegalStateException e) { 63 logln("OK: Got exception for Bidi.getDirection() as expected: " 64 + e.getMessage()); 65 } 66 bidi.setPara("abc", Bidi.LTR, null); 67 try { 68 bidi.getLevelAt(3); 69 errln("bidi.getLevelAt did not fail when called with bad argument"); 70 } catch (IllegalArgumentException e) { 71 logln("OK: Got exception for Bidi.getLevelAt(3) as expected: " 72 + e.getMessage()); 73 } 74 try { 75 bidi = new Bidi(-1, 0); 76 errln("Bidi constructor did not fail when called with bad argument"); 77 } catch (IllegalArgumentException e) { 78 logln("OK: Got exception for Bidi(-1,0) as expected: " 79 + e.getMessage()); 80 } 81 bidi = new Bidi(2, 1); 82 try { 83 bidi.setPara("abc", Bidi.LTR, null); 84 errln("setPara did not fail when called with text too long"); 85 } catch (OutOfMemoryError e) { 86 logln("OK: Got exception for setPara(\"abc\") as expected: " 87 + e.getMessage()); 88 } 89 try { 90 bidi.setPara("=2", Bidi.RTL, null); 91 bidi.countRuns(); 92 errln("countRuns did not fail when called for too many runs"); 93 } catch (OutOfMemoryError e) { 94 logln("OK: Got exception for countRuns as expected: " 95 + e.getMessage()); 96 } 97 int rm = bidi.getReorderingMode(); 98 bidi.setReorderingMode(Bidi.REORDER_DEFAULT - 1); 99 if (rm != bidi.getReorderingMode()) { 100 errln("setReorderingMode with bad argument #1 should have no effect"); 101 } 102 bidi.setReorderingMode(9999); 103 if (rm != bidi.getReorderingMode()) { 104 errln("setReorderingMode with bad argument #2 should have no effect"); 105 } 106 /* Try a surrogate char */ 107 bidi = new Bidi(); 108 bidi.setPara("\uD800\uDC00", Bidi.RTL, null); 109 if (bidi.getDirection() != Bidi.MIXED) { 110 errln("getDirection for 1st surrogate char should be MIXED"); 111 } 112 byte[] levels = new byte[] {6,5,4}; 113 try { 114 bidi.setPara("abc", (byte)5, levels); 115 errln("setPara did not fail when called with bad levels"); 116 } catch (IllegalArgumentException e) { 117 logln("OK: Got exception for setPara(..., levels) as expected: " 118 + e.getMessage()); 119 } 120 121 logln("\nExiting TestFailureRecovery\n"); 122 } 123 124 125 public static void main(String[] args) { 126 try { 127 new TestFailureRecovery().run(args); 128 } 129 catch (Exception e) { 130 System.out.println(e); 131 } 132 } 133 } 134