]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/bidi/TestFailureRecovery.java
Added flags.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / bidi / TestFailureRecovery.java
1 /*
2 *******************************************************************************
3 *   Copyright (C) 2007-2013, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 *******************************************************************************
6 */
7
8 package com.ibm.icu.dev.test.bidi;
9
10 import com.ibm.icu.text.Bidi;
11
12 /**
13  * Regression test for Bidi failure recovery
14  *
15  * @author Lina Kemmel, Matitiahu Allouche
16  */
17
18 public class TestFailureRecovery extends BidiTest {
19
20     public void testFailureRecovery()
21     {
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
26         //try {
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());
32         //}
33         try {
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());
39         }
40         try {
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: "
45                   + e.getMessage());
46         }
47         bidi = new Bidi();
48         try {
49             bidi.setLine(0, 1);
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: "
53                   + e.getMessage());
54         }
55         try {
56             bidi.getDirection();
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: "
60                   + e.getMessage());
61         }
62         bidi.setPara("abc", Bidi.LTR, null);
63         try {
64             bidi.getLevelAt(3);
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: "
68                   + e.getMessage());
69         }
70         try {
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: "
75                   + e.getMessage());
76         }
77         bidi = new Bidi(2, 1);
78         try {
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: "
83                   + e.getMessage());
84         }
85         try {
86             bidi.setPara("=2", Bidi.RTL, null);
87             bidi.countRuns();
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: "
91                   + e.getMessage());
92         }
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");
97         }
98         bidi.setReorderingMode(9999);
99         if (rm != bidi.getReorderingMode()) {
100             errln("setReorderingMode with bad argument #2 should have no effect");
101         }
102         /* Try a surrogate char */
103         bidi = new Bidi();
104         bidi.setPara("\uD800\uDC00", Bidi.RTL, null);
105         if (bidi.getDirection() != Bidi.MIXED) {
106             errln("getDirection for 1st surrogate char should be MIXED");
107         }
108         byte[] levels = new byte[] {6,5,4};
109         try {
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: "
114                   + e.getMessage());
115         }
116
117         logln("\nExiting TestFailureRecovery\n");
118     }
119
120
121     public static void main(String[] args) {
122         try {
123             new TestFailureRecovery().run(args);
124         }
125         catch (Exception e) {
126             System.out.println(e);
127         }
128     }
129 }