]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/bidi/TestReorderRunsOnly.java
Added flags.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / bidi / TestReorderRunsOnly.java
1 /*
2 *******************************************************************************
3 *   Copyright (C) 2001-2007, 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 variants to the UBA.
14  *
15  * @author Lina Kemmel, Matitiahu Allouche
16  */
17
18 public class TestReorderRunsOnly extends BidiTest {
19
20
21     static class TestCase {
22         String textIn;
23         String textOut[][];
24         int noroundtrip[];
25
26         TestCase(String in, String[][] out, int[] nrd) {
27             this.textIn = in;
28             this.textOut = out;
29             this.noroundtrip = nrd;
30         }
31     }
32
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"}},
37                      new int[] {0, 0}),
38         new TestCase("abcGHI",          // 1
39                      new String[][] {{"GHIabc", "GHIabc"}, {"GHIabc", "GHIabc"}},
40                      new int[] {0, 0}),
41         new TestCase("a.>67->",         // 2
42                      new String[][] {{"<-67<.a", "<-67<.a"}, {"<-67<.a", "<-67<.a"}},
43                      new int[] {0, 0}),
44         new TestCase("-=%$123/ *",      // 3
45                      new String[][] {{"* /%$123=-", "* /%$123=-"},
46                                      {"* /%$123=-", "* /%$123=-"}},
47                      new int[] {0, 0}),
48         new TestCase("abc->12..>JKL",   // 4
49                      new String[][] {{"JKL<..12<-abc", "JKL<..abc->12"},
50                                      {"JKL<..12<-abc", "JKL<..abc->12"}},
51                      new int[] {0, 0}),
52         new TestCase("JKL->12..>abc",   // 5
53                      new String[][] {{"abc<..JKL->12", "abc<..12<-JKL"},
54                                      {"abc<..JKL->12", "abc<..12<-JKL"}},
55                      new int[] {0, 0}),
56         new TestCase("123->abc",        // 6
57                      new String[][] {{"abc<-123", "abc<-123"},
58                                      {"abc&<-123", "abc<-123"}},
59                      new int[] {1, 0}),
60         new TestCase("123->JKL",        // 7
61                      new String[][] {{"JKL<-123", "123->JKL"},
62                                      {"JKL<-123", "JKL<-@123"}},
63                      new int[] {0, 1}),
64         new TestCase("*>12.>34->JKL",   // 8
65                      new String[][] {{"JKL<-34<.12<*", "12.>34->JKL<*"},
66                                      {"JKL<-34<.12<*", "JKL<-@34<.12<*"}},
67                      new int[] {0, 1}),
68         new TestCase("*>67.>89->JKL",   // 9
69                      new String[][] {{"67.>89->JKL<*", "67.>89->JKL<*"},
70                                      {"67.>89->JKL<*", "67.>89->JKL<*"}},
71                      new int[] {0, 0}),
72         new TestCase("* /abc-=$%123",   // 10
73                      new String[][] {{"$%123=-abc/ *", "abc-=$%123/ *"},
74                                      {"$%123=-abc/ *", "abc-=$%123/ *"}},
75                      new int[] {0, 0}),
76         new TestCase("* /$%def-=123",   // 11
77                      new String[][] {{"123=-def%$/ *", "def-=123%$/ *"},
78                                      {"123=-def%$/ *", "def-=123%$/ *"}},
79                      new int[] {0, 0}),
80         new TestCase("-=GHI* /123%$",   // 12
81                      new String[][] {{"GHI* /123%$=-", "123%$/ *GHI=-"},
82                                      {"GHI* /123%$=-", "123%$/ *GHI=-"}},
83                      new int[] {0, 0}),
84         new TestCase("-=%$JKL* /123",   // 13
85                      new String[][] {{"JKL* /%$123=-", "123/ *JKL$%=-"},
86                                      {"JKL* /%$123=-", "123/ *JKL$%=-"}},
87                      new int[] {0, 0}),
88         new TestCase("ab =#CD *?450",   // 14
89                      new String[][] {{"CD *?450#= ab", "450?* CD#= ab"},
90                                      {"CD *?450#= ab", "450?* CD#= ab"}},
91                      new int[] {0, 0}),
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"}},
95                      new int[] {0, 0}),
96         new TestCase("abc-=%$LMN* /123",// 16
97                      new String[][] {{"LMN* /%$123=-abc", "123/ *LMN$%=-abc"},
98                                      {"LMN* /%$123=-abc", "123/ *LMN$%=-abc"}},
99                      new int[] {0, 0}),
100         new TestCase("123->JKL&MN&P",   // 17
101                      new String[][] {{"JKLMNP<-123", "123->JKLMNP"},
102                                      {"JKLMNP<-123", "JKLMNP<-@123"}},
103                      new int[] {0, 1}),
104         new TestCase("123",             // 18   just one run
105                      new String[][] {{"123", "123"},
106                                      {"123", "123"}},
107                      new int[] {0, 0})
108     };
109
110     public void testReorderRunsOnly() {
111
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;
117         byte level;
118
119         logln("\nEntering TestReorderRunsOnly\n");
120         bidi.setReorderingMode(Bidi.REORDER_RUNS_ONLY);
121         bidiL2V.setReorderingOptions(Bidi.OPTION_REMOVE_CONTROLS);
122
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);
132                     level = (byte)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));
140
141                     if ((option == 0) && (testCases[i].noroundtrip[level] > 0)) {
142                         continue;
143                     }
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));
157                 }
158             }
159         }
160
161         /* test with null or empty text */
162         int paras;
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);
175
176         logln("\nExiting TestReorderRunsOnly\n");
177     }
178
179
180     public static void main(String[] args) {
181         try {
182             new TestReorderRunsOnly().run(args);
183         }
184         catch (Exception e) {
185             System.out.println(e);
186         }
187     }
188
189 }
190