2 *******************************************************************************
\r
3 * Copyright (C) 2001-2007, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.dev.test.bidi;
\r
10 import com.ibm.icu.text.Bidi;
\r
13 * Regression test for variants to the UBA.
\r
15 * @author Lina Kemmel, Matitiahu Allouche
\r
18 public class TestReorderRunsOnly extends BidiTest {
\r
21 static class TestCase {
\r
26 TestCase(String in, String[][] out, int[] nrd) {
\r
29 this.noroundtrip = nrd;
\r
33 static final TestCase testCases[] = {
\r
34 new TestCase("ab 234 896 de", // 0
\r
35 new String[][] {{"de 896 ab 234", "de 896 ab 234"},
\r
36 {"ab 234 @896@ de", "de 896 ab 234"}},
\r
38 new TestCase("abcGHI", // 1
\r
39 new String[][] {{"GHIabc", "GHIabc"}, {"GHIabc", "GHIabc"}},
\r
41 new TestCase("a.>67->", // 2
\r
42 new String[][] {{"<-67<.a", "<-67<.a"}, {"<-67<.a", "<-67<.a"}},
\r
44 new TestCase("-=%$123/ *", // 3
\r
45 new String[][] {{"* /%$123=-", "* /%$123=-"},
\r
46 {"* /%$123=-", "* /%$123=-"}},
\r
48 new TestCase("abc->12..>JKL", // 4
\r
49 new String[][] {{"JKL<..12<-abc", "JKL<..abc->12"},
\r
50 {"JKL<..12<-abc", "JKL<..abc->12"}},
\r
52 new TestCase("JKL->12..>abc", // 5
\r
53 new String[][] {{"abc<..JKL->12", "abc<..12<-JKL"},
\r
54 {"abc<..JKL->12", "abc<..12<-JKL"}},
\r
56 new TestCase("123->abc", // 6
\r
57 new String[][] {{"abc<-123", "abc<-123"},
\r
58 {"abc&<-123", "abc<-123"}},
\r
60 new TestCase("123->JKL", // 7
\r
61 new String[][] {{"JKL<-123", "123->JKL"},
\r
62 {"JKL<-123", "JKL<-@123"}},
\r
64 new TestCase("*>12.>34->JKL", // 8
\r
65 new String[][] {{"JKL<-34<.12<*", "12.>34->JKL<*"},
\r
66 {"JKL<-34<.12<*", "JKL<-@34<.12<*"}},
\r
68 new TestCase("*>67.>89->JKL", // 9
\r
69 new String[][] {{"67.>89->JKL<*", "67.>89->JKL<*"},
\r
70 {"67.>89->JKL<*", "67.>89->JKL<*"}},
\r
72 new TestCase("* /abc-=$%123", // 10
\r
73 new String[][] {{"$%123=-abc/ *", "abc-=$%123/ *"},
\r
74 {"$%123=-abc/ *", "abc-=$%123/ *"}},
\r
76 new TestCase("* /$%def-=123", // 11
\r
77 new String[][] {{"123=-def%$/ *", "def-=123%$/ *"},
\r
78 {"123=-def%$/ *", "def-=123%$/ *"}},
\r
80 new TestCase("-=GHI* /123%$", // 12
\r
81 new String[][] {{"GHI* /123%$=-", "123%$/ *GHI=-"},
\r
82 {"GHI* /123%$=-", "123%$/ *GHI=-"}},
\r
84 new TestCase("-=%$JKL* /123", // 13
\r
85 new String[][] {{"JKL* /%$123=-", "123/ *JKL$%=-"},
\r
86 {"JKL* /%$123=-", "123/ *JKL$%=-"}},
\r
88 new TestCase("ab =#CD *?450", // 14
\r
89 new String[][] {{"CD *?450#= ab", "450?* CD#= ab"},
\r
90 {"CD *?450#= ab", "450?* CD#= ab"}},
\r
92 new TestCase("ab 234 896 de", // 15
\r
93 new String[][] {{"de 896 ab 234", "de 896 ab 234"},
\r
94 {"ab 234 @896@ de", "de 896 ab 234"}},
\r
96 new TestCase("abc-=%$LMN* /123",// 16
\r
97 new String[][] {{"LMN* /%$123=-abc", "123/ *LMN$%=-abc"},
\r
98 {"LMN* /%$123=-abc", "123/ *LMN$%=-abc"}},
\r
100 new TestCase("123->JKL&MN&P", // 17
\r
101 new String[][] {{"JKLMNP<-123", "123->JKLMNP"},
\r
102 {"JKLMNP<-123", "JKLMNP<-@123"}},
\r
104 new TestCase("123", // 18 just one run
\r
105 new String[][] {{"123", "123"},
\r
110 public void testReorderRunsOnly() {
\r
112 Bidi bidi = new Bidi();
\r
113 Bidi bidiL2V = new Bidi();
\r
114 String src, dest, visual1, visual2;
\r
115 String srcU16, destU16, visual1U16, visual2U16;
\r
116 int option, i, j, nCases;
\r
119 logln("\nEntering TestReorderRunsOnly\n");
\r
120 bidi.setReorderingMode(Bidi.REORDER_RUNS_ONLY);
\r
121 bidiL2V.setReorderingOptions(Bidi.OPTION_REMOVE_CONTROLS);
\r
123 for (option = 0; option < 2; option++) {
\r
124 bidi.setReorderingOptions(option == 0 ? Bidi.OPTION_REMOVE_CONTROLS
\r
125 : Bidi.OPTION_INSERT_MARKS);
\r
126 for (i = 0, nCases = testCases.length; i < nCases; i++) {
\r
127 src = testCases[i].textIn;
\r
128 srcU16 = pseudoToU16(src);
\r
129 for (j = 0; j < 2; j++) {
\r
130 logln("Now doing test for option " + option +
\r
131 ", case " + i + ", level " + j);
\r
133 bidi.setPara(srcU16, level, null);
\r
134 destU16 = bidi.writeReordered(Bidi.DO_MIRRORING);
\r
135 dest = u16ToPseudo(destU16);
\r
136 checkWhatYouCan(bidi, src, dest);
\r
137 assertEquals("Reorder runs only failed for case " + i,
\r
138 testCases[i].textOut[option][level],
\r
139 dest, src, null, null, Byte.toString(level));
\r
141 if ((option == 0) && (testCases[i].noroundtrip[level] > 0)) {
\r
144 bidiL2V.setPara(srcU16, level, null);
\r
145 visual1U16 = bidiL2V.writeReordered(Bidi.DO_MIRRORING);
\r
146 visual1 = u16ToPseudo(visual1U16);
\r
147 checkWhatYouCan(bidiL2V, src, visual1);
\r
148 bidiL2V.setPara(destU16, (byte)(level^1), null);
\r
149 visual2U16 = bidiL2V.writeReordered(Bidi.DO_MIRRORING);
\r
150 visual2 = u16ToPseudo(visual2U16);
\r
151 checkWhatYouCan(bidiL2V, dest, visual2);
\r
152 assertEquals("Round trip failed for case " + i,
\r
153 visual1, visual2, src,
\r
154 "REORDER_RUNS_ONLY (2)",
\r
155 option == 0 ? "0" : "OPTION_INSERT_MARKS",
\r
156 Byte.toString(level));
\r
161 /* test with null or empty text */
\r
163 bidi.setPara((String)null, Bidi.LTR, null);
\r
164 paras = bidi.countParagraphs();
\r
165 assertEquals("\nInvalid number of paras #1 (should be 0): ", 0, paras);
\r
166 bidi.setPara((char[])null, Bidi.LTR, null);
\r
167 paras = bidi.countParagraphs();
\r
168 assertEquals("\nInvalid number of paras #2 (should be 0): ", 0, paras);
\r
169 bidi.setPara("", Bidi.LTR, null);
\r
170 paras = bidi.countParagraphs();
\r
171 assertEquals("\nInvalid number of paras #3 (should be 0): ", 0, paras);
\r
172 bidi.setPara(new char[0], Bidi.LTR, null);
\r
173 paras = bidi.countParagraphs();
\r
174 assertEquals("\nInvalid number of paras #4 (should be 0): ", 0, paras);
\r
176 logln("\nExiting TestReorderRunsOnly\n");
\r
180 public static void main(String[] args) {
\r
182 new TestReorderRunsOnly().run(args);
\r
184 catch (Exception e) {
\r
185 System.out.println(e);
\r