2 *******************************************************************************
3 * Copyright (C) 2007-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 package com.ibm.icu.dev.test.bidi;
10 import com.ibm.icu.text.Bidi;
13 * Regression test for Bidi failure recovery
15 * @author Lina Kemmel, Matitiahu Allouche
18 public class TestFailureRecovery extends BidiTest {
20 public void testFailureRecovery()
22 logln("\nEntering TestFailureRecovery\n");
23 Bidi bidi = new Bidi();
24 // Skip the following test since there are no invalid values
25 // between MAX_EXPLICIT_LEVEL+1 and LEVEL_DEFAULT_LTR
27 // bidi.setPara("abc", (byte)(Bidi.LEVEL_DEFAULT_LTR - 1), null);
28 // errln("Bidi.setPara did not fail when passed too big para level");
29 //} catch (IllegalArgumentException e) {
30 // logln("OK: Got exception for bidi.setPara(..., Bidi.LEVEL_DEFAULT_LTR - 1, ...)"
31 // + " as expected: " + e.getMessage());
34 bidi.setPara("abc", (byte)(-1), null);
35 errln("Bidi.setPara did not fail when passed negative para level");
36 } catch (IllegalArgumentException e) {
37 logln("OK: Got exception for bidi.setPara(..., -1, ...)"
38 + " as expected: " + e.getMessage());
41 Bidi.writeReverse(null, 0);
42 errln("Bidi.writeReverse did not fail when passed a null string");
43 } catch (IllegalArgumentException e) {
44 logln("OK: Got exception for Bidi.writeReverse(null) as expected: "
50 errln("bidi.setLine did not fail when called before valid setPara()");
51 } catch (IllegalStateException e) {
52 logln("OK: Got exception for Bidi.setLine(0, 1) as expected: "
57 errln("bidi.getDirection did not fail when called before valid setPara()");
58 } catch (IllegalStateException e) {
59 logln("OK: Got exception for Bidi.getDirection() as expected: "
62 bidi.setPara("abc", Bidi.LTR, null);
65 errln("bidi.getLevelAt did not fail when called with bad argument");
66 } catch (IllegalArgumentException e) {
67 logln("OK: Got exception for Bidi.getLevelAt(3) as expected: "
71 bidi = new Bidi(-1, 0);
72 errln("Bidi constructor did not fail when called with bad argument");
73 } catch (IllegalArgumentException e) {
74 logln("OK: Got exception for Bidi(-1,0) as expected: "
77 bidi = new Bidi(2, 1);
79 bidi.setPara("abc", Bidi.LTR, null);
80 errln("setPara did not fail when called with text too long");
81 } catch (OutOfMemoryError e) {
82 logln("OK: Got exception for setPara(\"abc\") as expected: "
86 bidi.setPara("=2", Bidi.RTL, null);
88 errln("countRuns did not fail when called for too many runs");
89 } catch (OutOfMemoryError e) {
90 logln("OK: Got exception for countRuns as expected: "
93 int rm = bidi.getReorderingMode();
94 bidi.setReorderingMode(Bidi.REORDER_DEFAULT - 1);
95 if (rm != bidi.getReorderingMode()) {
96 errln("setReorderingMode with bad argument #1 should have no effect");
98 bidi.setReorderingMode(9999);
99 if (rm != bidi.getReorderingMode()) {
100 errln("setReorderingMode with bad argument #2 should have no effect");
102 /* Try a surrogate char */
104 bidi.setPara("\uD800\uDC00", Bidi.RTL, null);
105 if (bidi.getDirection() != Bidi.MIXED) {
106 errln("getDirection for 1st surrogate char should be MIXED");
108 byte[] levels = new byte[] {6,5,4};
110 bidi.setPara("abc", (byte)5, levels);
111 errln("setPara did not fail when called with bad levels");
112 } catch (IllegalArgumentException e) {
113 logln("OK: Got exception for setPara(..., levels) as expected: "
117 logln("\nExiting TestFailureRecovery\n");
121 public static void main(String[] args) {
123 new TestFailureRecovery().run(args);
125 catch (Exception e) {
126 System.out.println(e);