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