]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/collate/src/com/ibm/icu/dev/test/search/SearchTest.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / collate / src / com / ibm / icu / dev / test / search / SearchTest.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2000-2010, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 \r
8 /**\r
9  * Port From:   ICU4C v2.1 : collate/StringSearchTest\r
10  * Source File: $ICU4CRoot/source/test/intltest/srchtest.cpp\r
11  **/\r
12 \r
13 package com.ibm.icu.dev.test.search;\r
14 \r
15 import java.text.StringCharacterIterator;\r
16 import java.util.Locale;\r
17 \r
18 import com.ibm.icu.dev.test.TestFmwk;\r
19 import com.ibm.icu.text.BreakIterator;\r
20 import com.ibm.icu.text.Collator;\r
21 import com.ibm.icu.text.RuleBasedCollator;\r
22 import com.ibm.icu.text.SearchIterator;\r
23 import com.ibm.icu.text.StringSearch;\r
24 \r
25 public class SearchTest extends TestFmwk {\r
26 \r
27     //inner class\r
28     static class SearchData {\r
29         SearchData(String text, String pattern, String coll, int strength, String breaker,\r
30                    int[] offset, int[] size) {\r
31             this.text = text;\r
32             this.pattern = pattern;\r
33             this.collator = coll;\r
34             this.strength = strength;\r
35             this.breaker = breaker;\r
36             this.offset = offset;\r
37             this.size = size;\r
38         }\r
39         String              text;\r
40         String              pattern;\r
41         String              collator;\r
42         int                 strength;\r
43         String              breaker;\r
44         int[]               offset;\r
45         int[]               size;\r
46     }\r
47 \r
48     RuleBasedCollator m_en_us_;\r
49     RuleBasedCollator m_fr_fr_;\r
50     RuleBasedCollator m_de_;\r
51     RuleBasedCollator m_es_;\r
52     BreakIterator     m_en_wordbreaker_;\r
53     BreakIterator     m_en_characterbreaker_;\r
54 \r
55     static SearchData[] BASIC = {\r
56         new SearchData("xxxxxxxxxxxxxxxxxxxx",          "fisher",       null, Collator.TERTIARY, null, new int[] {-1},            new int[]{0}),\r
57         new SearchData("silly spring string",           "string",       null, Collator.TERTIARY, null, new int[]{13, -1},         new int[]{6}),\r
58         new SearchData("silly spring string string",    "string",       null, Collator.TERTIARY, null, new int[]{13, 20, -1},     new int[]{6, 6}),\r
59         new SearchData("silly string spring string",    "string",       null, Collator.TERTIARY, null, new int[]{6, 20, -1},      new int[]{6, 6}),\r
60         new SearchData("string spring string",          "string",       null, Collator.TERTIARY, null, new int[]{0, 14, -1},      new int[]{6, 6}),\r
61         new SearchData("Scott Ganyo",                   "c",            null, Collator.TERTIARY, null, new int[]{1, -1},          new int[]{1}),\r
62         new SearchData("Scott Ganyo",                   " ",            null, Collator.TERTIARY, null, new int[]{5, -1},          new int[]{1}),\r
63         new SearchData("\u0300\u0325",                  "\u0300",       null, Collator.TERTIARY, null, new int[]{-1},             new int[]{0}),\r
64         new SearchData("a\u0300\u0325",                 "\u0300",       null, Collator.TERTIARY, null, new int[]{-1},             new int[]{0}),\r
65         new SearchData("a\u0300\u0325",                 "\u0300\u0325", null, Collator.TERTIARY, null, new int[]{1, -1},          new int[]{2}),\r
66         new SearchData("a\u0300b",                      "\u0300",       null, Collator.TERTIARY, null, new int[]{1, -1},          new int[]{1}),\r
67         new SearchData("\u00c9",                        "e",            null, Collator.PRIMARY,  null, new int[]{0, -1},          new int[]{1}),\r
68         new SearchData(null,                            null,           null, Collator.TERTIARY, null, new int[]{-1},             new int[]{0})\r
69     };\r
70 \r
71     SearchData BREAKITERATOREXACT[] = {\r
72         new SearchData("foxy fox", "fox", null, Collator.TERTIARY, "characterbreaker", new int[] {0, 5, -1}, new int[] {3, 3}),\r
73         new SearchData("foxy fox", "fox", null, Collator.TERTIARY, "wordbreaker", new int[] {5, -1}, new int[] {3}),\r
74         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, "characterbreaker", new int[] {10, 14, -1}, new int[] {3, 2}),\r
75         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, "wordbreaker", new int[] {10, -1}, new int[] {3}),\r
76         new SearchData("Channel, another channel, more channels, and one last Channel", "Channel", "es", Collator.TERTIARY,\r
77              "wordbreaker", new int[] {0, 54, -1}, new int[] {7, 7}),\r
78         /* jitterbug 1745 */\r
79         new SearchData("testing that \u00e9 does not match e", "e", null, Collator.TERTIARY,\r
80             "characterbreaker", new int[] {1, 17, 30, -1}, new int[] {1, 1, 1}),\r
81         new SearchData("testing that string ab\u00e9cd does not match e", "e", null, Collator.TERTIARY,\r
82             "characterbreaker", new int[] {1, 28, 41, -1}, new int[] {1, 1, 1}),\r
83         new SearchData("\u00c9", "e", "fr", Collator.PRIMARY,  "characterbreaker", new int[]{0, -1}, new int[]{1}),\r
84         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
85     };\r
86 \r
87     SearchData BREAKITERATORCANONICAL[] = {\r
88         new SearchData("foxy fox", "fox", null, Collator.TERTIARY, "characterbreaker", new int[] {0, 5, -1}, new int[] {3, 3}),\r
89         new SearchData("foxy fox", "fox", null, Collator.TERTIARY, "wordbreaker", new int[] {5, -1}, new int[] {3}),\r
90         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, "characterbreaker", new int[] {10, 14, -1}, new int[] {3, 2}),\r
91         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, "wordbreaker", new int[] {10, -1}, new int[] {3}),\r
92         new SearchData("Channel, another channel, more channels, and one last Channel", "Channel", "es", Collator.TERTIARY, "wordbreaker",\r
93                        new int[] {0, 54, -1}, new int[] {7, 7}),\r
94         /* jitterbug 1745 */\r
95         new SearchData("testing that \u00e9 does not match e", "e", null, Collator.TERTIARY,\r
96             "characterbreaker", new int[] {1, 17, 30, -1}, new int[] {1, 1, 1}),\r
97         new SearchData("testing that string ab\u00e9cd does not match e", "e", null,\r
98              Collator.TERTIARY, "characterbreaker", new int[] {1, 28, 41, -1}, new int[] {1, 1, 1}),\r
99         new SearchData("\u00c9", "e", "fr", Collator.PRIMARY,  "characterbreaker", new int[]{0, -1}, new int[]{1}),\r
100         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
101     };\r
102 \r
103     SearchData BASICCANONICAL[] = {\r
104         new SearchData("xxxxxxxxxxxxxxxxxxxx", "fisher", null, Collator.TERTIARY, null, new int[] {-1}, new int [] {0}),\r
105         new SearchData("silly spring string", "string", null, Collator.TERTIARY, null, new int[] {13, -1}, new int[] {6}),\r
106         new SearchData("silly spring string string", "string", null, Collator.TERTIARY, null, new int[] {13, 20, -1}, new int[] {6, 6}),\r
107         new SearchData("silly string spring string", "string", null, Collator.TERTIARY, null, new int[] {6, 20, -1}, new int[] {6, 6}),\r
108         new SearchData("string spring string", "string", null, Collator.TERTIARY, null, new int[] {0, 14, -1}, new int[] {6, 6}),\r
109         new SearchData("Scott Ganyo", "c", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {1}),\r
110         new SearchData("Scott Ganyo", " ", null, Collator.TERTIARY, null, new int[] {5, -1}, new int[] {1}),\r
111         new SearchData("\u0300\u0325", "\u0300", null, Collator.TERTIARY, null, new int [] {0, -1}, new int[] {2}),\r
112         new SearchData("a\u0300\u0325", "\u0300", null, Collator.TERTIARY, null, new int [] {1, -1}, new int[] {2}),\r
113         new SearchData("a\u0300\u0325", "\u0300\u0325", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[]{2}),\r
114         new SearchData("a\u0300b", "\u0300", null, Collator.TERTIARY, null, new int[]{1, -1}, new int[] {1}),\r
115         new SearchData("a\u0300\u0325b", "\u0300b", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {3}),\r
116         new SearchData("\u0325\u0300A\u0325\u0300", "\u0300A\u0300", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {5}),\r
117         new SearchData("\u0325\u0300A\u0325\u0300", "\u0325A\u0325", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {5}),\r
118         new SearchData("a\u0300\u0325b\u0300\u0325c \u0325b\u0300 \u0300b\u0325", "\u0300b\u0325", null, Collator.TERTIARY, null,\r
119             new int[] {1, 12, -1}, new int[] {5, 3}),\r
120         new SearchData("\u00c4\u0323", "A\u0323\u0308", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
121         new SearchData("\u0308\u0323", "\u0323\u0308", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
122         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
123     };\r
124 \r
125     SearchData COLLATOR[] = {\r
126         /* english */\r
127         new SearchData("fox fpx", "fox", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {3}),\r
128         /* tailored */\r
129         new SearchData("fox fpx", "fox", null, Collator.PRIMARY, null, new int[] {0, 4, -1}, new int[] {3, 3}),\r
130         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
131     };\r
132 \r
133     String TESTCOLLATORRULE = "& o,O ; p,P";\r
134     String EXTRACOLLATIONRULE = " & ae ; \u00e4 & AE ; \u00c4 & oe ; \u00f6 & OE ; \u00d6 & ue ; \u00fc & UE ; \u00dc";\r
135 \r
136 \r
137     SearchData COLLATORCANONICAL[] = {\r
138         /* english */\r
139         new SearchData("fox fpx", "fox", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {3}),\r
140         /* tailored */\r
141         new SearchData("fox fpx", "fox", null, Collator.PRIMARY, null, new int[] {0, 4, -1}, new int[] {3, 3}),\r
142         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
143     };\r
144 \r
145     SearchData COMPOSITEBOUNDARIES[] = {\r
146         new SearchData("\u00C0", "A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
147         new SearchData("A\u00C0C", "A", null, Collator.TERTIARY, null, new int[]  {0, 1, -1}, new int[]  {1, 1}),\r
148         new SearchData("\u00C0A", "A", null, Collator.TERTIARY, null, new int[] {0, 1, -1}, new int[] {1, 1}),\r
149         new SearchData("B\u00C0", "A", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {1}),\r
150         new SearchData("\u00C0B", "A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
151         new SearchData("\u00C0", "\u0300", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
152         new SearchData("\u0300\u00C0", "\u0300", null, Collator.TERTIARY, null, new int[] {0, 1, -1}, new int[] {1, 1}),\r
153         new SearchData("\u00C0\u0300", "\u0300", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
154         /* A + 030A + 0301 */\r
155         new SearchData("\u01FA", "\u01FA", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
156         new SearchData("\u01FA", "\u030A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
157         new SearchData("\u01FA", "A\u030A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
158         new SearchData("\u01FA", "\u030AA", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
159         new SearchData("\u01FA", "\u0301", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
160         new SearchData("\u01FA", "A\u0301", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
161         new SearchData("\u01FA", "\u0301A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
162         new SearchData("\u01FA", "\u030A\u0301", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
163         new SearchData("A\u01FA", "A\u030A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
164         new SearchData("\u01FAA", "\u0301A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
165         new SearchData("\u0F73", "\u0F73", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
166         new SearchData("\u0F73", "\u0F71", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
167         new SearchData("\u0F73", "\u0F72", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
168         new SearchData("\u0F73", "\u0F71\u0F72", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
169         new SearchData("A\u0F73", "A\u0F71", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
170         new SearchData("\u0F73A", "\u0F72A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
171         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
172     };\r
173 \r
174     SearchData COMPOSITEBOUNDARIESCANONICAL[] = {\r
175         new SearchData("\u00C0", "A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
176         new SearchData("A\u00C0C", "A", null, Collator.TERTIARY, null, new int[] {0, 1, -1}, new int[] {1, 1}),\r
177         new SearchData("\u00C0A", "A", null, Collator.TERTIARY, null, new int[] {0, 1, -1}, new int[] {1, 1}),\r
178         new SearchData("B\u00C0", "A", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {1}),\r
179         new SearchData("\u00C0B", "A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
180         new SearchData("\u00C0", "\u0300", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
181         new SearchData("\u0300\u00C0", "\u0300", null, Collator.TERTIARY, null, new int[] {0, 1, -1}, new int[] {1, 1}),\r
182         /* \u0300 blocked by \u0300 */\r
183         new SearchData("\u00C0\u0300", "\u0300", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
184         /* A + 030A + 0301 */\r
185         new SearchData("\u01FA", "\u01FA", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
186         new SearchData("\u01FA", "\u030A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
187         new SearchData("\u01FA", "A\u030A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
188         new SearchData("\u01FA", "\u030AA", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
189         new SearchData("\u01FA", "\u0301", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
190         /* blocked accent */\r
191         new SearchData("\u01FA", "A\u0301", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
192         new SearchData("\u01FA", "\u0301A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
193         new SearchData("\u01FA", "\u030A\u0301", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
194         new SearchData("A\u01FA", "A\u030A", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {1}),\r
195         new SearchData("\u01FAA", "\u0301A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
196         new SearchData("\u0F73", "\u0F73", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
197         new SearchData("\u0F73", "\u0F71", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
198         new SearchData("\u0F73", "\u0F72", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
199         new SearchData("\u0F73", "\u0F71\u0F72", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {1}),\r
200         new SearchData("A\u0F73", "A\u0F71", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
201         new SearchData("\u0F73A", "\u0F72A", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
202         new SearchData("\u01FA A\u0301\u030A A\u030A\u0301 A\u030A \u01FA", "A\u030A",\r
203             null, Collator.TERTIARY, null, new int[] {0, 6, 10, 13, -1}, new int[] {1, 3, 2, 1}),\r
204         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
205     };\r
206 \r
207     SearchData SUPPLEMENTARY[] = {\r
208         /* 012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890012345678901234567890123456789 */\r
209         new SearchData("abc \uD800\uDC00 \uD800\uDC01 \uD801\uDC00 \uD800\uDC00abc abc\uD800\uDC00 \uD800\uD800\uDC00 \uD800\uDC00\uDC00",\r
210             "\uD800\uDC00", null, Collator.TERTIARY, null, \r
211             new int[] {4, 13, 22, 26, 29, -1}, new int[] {2, 2, 2, 2, 2}),\r
212         new SearchData("and\uD834\uDDB9this sentence", "\uD834\uDDB9", null, \r
213                        Collator.TERTIARY, null, new int[] {3, -1}, \r
214                        new int[] {2}),\r
215         new SearchData("and \uD834\uDDB9 this sentence", " \uD834\uDDB9 ", \r
216                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
217                        new int[] {4}),\r
218         new SearchData("and-\uD834\uDDB9-this sentence", "-\uD834\uDDB9-", \r
219                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
220                        new int[] {4}),\r
221         new SearchData("and,\uD834\uDDB9,this sentence", ",\uD834\uDDB9,", \r
222                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
223                        new int[] {4}),\r
224         new SearchData("and?\uD834\uDDB9?this sentence", "?\uD834\uDDB9?", \r
225                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
226                        new int[] {4}),\r
227         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
228     };\r
229 \r
230     String CONTRACTIONRULE = "&z = ab/c < AB < X\u0300 < ABC < X\u0300\u0315";\r
231 \r
232     SearchData CONTRACTION[] = {\r
233         /* common discontiguous */\r
234         new SearchData("A\u0300\u0315", "\u0300", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
235         new SearchData("A\u0300\u0315", "\u0300\u0315", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
236         /* contraction prefix */\r
237         new SearchData("AB\u0315C", "A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
238         new SearchData("AB\u0315C", "AB", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
239         new SearchData("AB\u0315C", "\u0315", null, Collator.TERTIARY, null, new int[] {2, -1}, new int[] {1}),\r
240         /* discontiguous problem here for backwards iteration.\r
241         accents not found because discontiguous stores all information */\r
242         new SearchData("X\u0300\u0319\u0315", "\u0319", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
243          /* ends not with a contraction character */\r
244         new SearchData("X\u0315\u0300D", "\u0300\u0315", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
245         new SearchData("X\u0315\u0300D", "X\u0300\u0315", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {3}),\r
246         new SearchData("X\u0300\u031A\u0315D", "X\u0300", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
247         /* blocked discontiguous */\r
248         new SearchData("X\u0300\u031A\u0315D", "\u031A\u0315D", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
249         new SearchData("ab", "z", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
250         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
251     };\r
252 \r
253     SearchData CONTRACTIONCANONICAL[] = {\r
254         /* common discontiguous */\r
255         new SearchData("A\u0300\u0315", "\u0300", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
256         new SearchData("A\u0300\u0315", "\u0300\u0315", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
257         /* contraction prefix */\r
258         new SearchData("AB\u0315C", "A", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
259         new SearchData("AB\u0315C", "AB", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
260         new SearchData("AB\u0315C", "\u0315", null, Collator.TERTIARY, null, new int[] {2, -1}, new int[] {1}),\r
261         /* discontiguous problem here for backwards iteration.\r
262         forwards gives 0, 4 but backwards give 1, 3 */\r
263         /* {"X\u0300\u0319\u0315", "\u0319", null, Collator.TERTIARY, null, {0, -1},\r
264         {4}}, */\r
265 \r
266          /* ends not with a contraction character */\r
267         new SearchData("X\u0315\u0300D", "\u0300\u0315", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
268         new SearchData("X\u0315\u0300D", "X\u0300\u0315", null, Collator.TERTIARY, null,\r
269             new int[] {0, -1}, new int[] {3}),\r
270         new SearchData("X\u0300\u031A\u0315D", "X\u0300", null, Collator.TERTIARY, null,\r
271             new int[] {0, -1}, new int[] {4}),\r
272         /* blocked discontiguous */\r
273         new SearchData("X\u0300\u031A\u0315D", "\u031A\u0315D", null, Collator.TERTIARY, null,\r
274             new int[] {1, -1}, new int[] {4}),\r
275         new SearchData("ab", "z", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
276         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
277     };\r
278 \r
279     SearchData MATCH[] = {\r
280         new SearchData("a busy bee is a very busy beeee", "bee", null, Collator.TERTIARY, null,\r
281         new int[] {7, 26, -1}, new int[] {3, 3}),\r
282         /* 012345678901234567890123456789012345678901234567890 */\r
283         new SearchData("a busy bee is a very busy beeee with no bee life", "bee", null,\r
284             Collator.TERTIARY, null, new int[] {7, 26, 40, -1}, new int[] {3, 3, 3}),\r
285         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
286     };\r
287 \r
288     String IGNORABLERULE = "&a = \u0300";\r
289 \r
290     SearchData IGNORABLE[] = {\r
291         new SearchData("\u0300\u0315 \u0300\u0315 ", "\u0300", null, Collator.PRIMARY, null,\r
292             new int[] {0, 3, -1}, new int[] {2, 2}),\r
293         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
294     };\r
295     \r
296     SearchData DIACTRICMATCH[] = {\r
297         new SearchData("\u0061\u0061\u00E1", "\u0061\u00E1", null, Collator.SECONDARY, null,\r
298             new int[] {1, -1}, new int[] {2}),   \r
299         new SearchData("\u0020\u00C2\u0303\u0020\u0041\u0061\u1EAA\u0041\u0302\u0303\u00C2\u0303\u1EAB\u0061\u0302\u0303\u00E2\u0303\uD806\uDC01\u0300\u0020",\r
300             "\u00C2\u0303", null, Collator.PRIMARY, null, new int[] {1, 4, 5, 6, 7, 10, 12, 13, 16,-1}, new int[] {2, 1, 1, 1, 3, 2, 1, 3, 2}),\r
301         new SearchData("\u03BA\u03B1\u03B9\u0300\u0020\u03BA\u03B1\u1F76", "\u03BA\u03B1\u03B9", null, Collator.PRIMARY, null,\r
302                 new int[] {0, 5, -1}, new int[] {4, 3}),   \r
303         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
304     };\r
305 \r
306     SearchData NORMCANONICAL[] = {\r
307         new SearchData("\u0300\u0325", "\u0300", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
308         new SearchData("\u0300\u0325", "\u0325", null, Collator.TERTIARY, null, new int[] {0, -1}, new int[] {2}),\r
309         new SearchData("a\u0300\u0325", "\u0325\u0300", null, Collator.TERTIARY, null, new int[] {1, -1},\r
310             new int[] {2}),\r
311         new SearchData("a\u0300\u0325", "\u0300\u0325", null, Collator.TERTIARY, null, new int[] {1, -1},\r
312             new int[] {2}),\r
313         new SearchData("a\u0300\u0325", "\u0325", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
314         new SearchData("a\u0300\u0325", "\u0300", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
315         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
316     };\r
317 \r
318     SearchData NORMEXACT[] = {\r
319         new SearchData("a\u0300\u0325", "\u0325\u0300", null, Collator.TERTIARY, null, new int[] {1, -1}, new int[] {2}),\r
320         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
321     };\r
322 \r
323     SearchData NONNORMEXACT[] = {\r
324         new SearchData("a\u0300\u0325", "\u0325\u0300", null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0}),\r
325         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
326     };\r
327 \r
328     SearchData OVERLAP[] = {\r
329         new SearchData("abababab", "abab", null, Collator.TERTIARY, null, new int[] {0, 2, 4, -1}, new int[] {4, 4, 4}),\r
330         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
331     };\r
332 \r
333     SearchData NONOVERLAP[] = {\r
334         new SearchData("abababab", "abab", null, Collator.TERTIARY, null, new int[] {0, 4, -1}, new int[] {4, 4}),\r
335         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
336     };\r
337 \r
338     SearchData OVERLAPCANONICAL[] = {\r
339         new SearchData("abababab", "abab", null, Collator.TERTIARY, null, new int[] {0, 2, 4, -1},\r
340                         new int[] {4, 4, 4}),\r
341         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
342     };\r
343 \r
344     SearchData NONOVERLAPCANONICAL[] = {\r
345         new SearchData("abababab", "abab", null, Collator.TERTIARY, null, new int[] {0, 4, -1}, new int[] {4, 4}),\r
346         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
347     };\r
348 \r
349     SearchData PATTERNCANONICAL[] = {\r
350         new SearchData("The quick brown fox jumps over the lazy foxes", "the", null,\r
351                        Collator.PRIMARY, null, new int[] {0, 31, -1}, new int[] {3, 3}),\r
352         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", null,\r
353                        Collator.PRIMARY, null, new int[] {16, 40, -1}, new int[] {3, 3}),\r
354         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
355     };\r
356 \r
357     SearchData PATTERN[] = {\r
358         new SearchData("The quick brown fox jumps over the lazy foxes", "the", null,\r
359                        Collator.PRIMARY, null, new int[] {0, 31, -1}, new int[] {3, 3}),\r
360         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", null,\r
361                        Collator.PRIMARY, null, new int[] {16, 40, -1}, new int[] {3, 3}),\r
362         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
363     };\r
364 \r
365     SearchData STRENGTH[] = {\r
366         /*012345678901234567890123456789012345678901234567890123456789*/\r
367         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", "en",\r
368                        Collator.PRIMARY, null, new int[] {16, 40, -1}, new int[] {3, 3}),\r
369         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", "en",\r
370                        Collator.PRIMARY, "wordbreaker", new int[] {16, -1}, new int[] {3}),\r
371         new SearchData("blackbirds Pat p\u00E9ch\u00E9 p\u00EAche p\u00E9cher p\u00EAcher Tod T\u00F6ne black Tofu blackbirds Ton PAT toehold blackbird black-bird pat toe big Toe",\r
372                        "peche", "fr", Collator.PRIMARY, null, new int[] {15, 21, 27, 34, -1}, new int[] {5, 5, 5, 5}),\r
373         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, null,\r
374                         new int[] {10, 14, -1}, new int[] {3, 2}),\r
375         new SearchData("A channel, another CHANNEL, more Channels, and one last channel...", "channel", "es",\r
376                         Collator.PRIMARY, null, new int[] {2, 19, 33, 56, -1}, new int[] {7, 7, 7, 7}),\r
377         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
378     };\r
379 \r
380     SearchData STRENGTHCANONICAL[] = {\r
381         /*012345678901234567890123456789012345678901234567890123456789 */\r
382         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", "en",\r
383                        Collator.PRIMARY, null, new int[] {16, 40, -1}, new int[] {3, 3}),\r
384         new SearchData("The quick brown fox jumps over the lazy foxes", "fox", "en",\r
385                        Collator.PRIMARY, "wordbreaker", new int[] {16, -1}, new int[] {3}),\r
386         new SearchData("blackbirds Pat p\u00E9ch\u00E9 p\u00EAche p\u00E9cher p\u00EAcher Tod T\u00F6ne black Tofu blackbirds Ton PAT toehold blackbird black-bird pat toe big Toe",\r
387                        "peche", "fr", Collator.PRIMARY, null, new int[] {15, 21, 27, 34, -1}, new int[] {5, 5, 5, 5}),\r
388         new SearchData("This is a toe T\u00F6ne", "toe", "de", Collator.PRIMARY, null,\r
389                        new int[] {10, 14, -1}, new int[] {3, 2}),\r
390         new SearchData("A channel, another CHANNEL, more Channels, and one last channel...", "channel", "es",\r
391                        Collator.PRIMARY, null, new int[]{2, 19, 33, 56, -1}, new int[] {7, 7, 7, 7}),\r
392         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[]{0})\r
393     };\r
394 \r
395     SearchData SUPPLEMENTARYCANONICAL[] = {\r
396         /*012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890012345678901234567890123456789 */\r
397         new SearchData("abc \uD800\uDC00 \uD800\uDC01 \uD801\uDC00 \uD800\uDC00abc abc\uD800\uDC00 \uD800\uD800\uDC00 \uD800\uDC00\uDC00",\r
398                        "\uD800\uDC00", null, Collator.TERTIARY, null, new int[] {4, 13, 22, 26, 29, -1},\r
399                        new int[] {2, 2, 2, 2, 2}),\r
400         new SearchData("and\uD834\uDDB9this sentence", "\uD834\uDDB9", null, \r
401                        Collator.TERTIARY, null, new int[] {3, -1}, \r
402                        new int[] {2}),\r
403         new SearchData("and \uD834\uDDB9 this sentence", " \uD834\uDDB9 ", \r
404                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
405                        new int[] {4}),\r
406         new SearchData("and-\uD834\uDDB9-this sentence", "-\uD834\uDDB9-", \r
407                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
408                        new int[] {4}),\r
409         new SearchData("and,\uD834\uDDB9,this sentence", ",\uD834\uDDB9,", \r
410                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
411                        new int[] {4}),\r
412         new SearchData("and?\uD834\uDDB9?this sentence", "?\uD834\uDDB9?", \r
413                        null, Collator.TERTIARY, null, new int[] {3, -1}, \r
414                        new int[] {4}),\r
415         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
416     };\r
417 \r
418     static SearchData VARIABLE[] = {\r
419         /*012345678901234567890123456789012345678901234567890123456789*/\r
420         new SearchData("blackbirds black blackbirds blackbird black-bird", "blackbird", null, Collator.TERTIARY,   null,\r
421         new int[] {0, 17, 28, 38, -1}, new int[] {9, 9, 9, 10}),\r
422 \r
423         /* to see that it doesn't go into an infinite loop if the start of text\r
424         is a ignorable character */\r
425         new SearchData(" on",                                              "go",        null, Collator.TERTIARY,   null,\r
426                        new int[] {-1}, new int[]{0}),\r
427         new SearchData("abcdefghijklmnopqrstuvwxyz",                       "   ",       null, Collator.PRIMARY,    null,\r
428                         new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1},\r
429                         new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),\r
430 \r
431         /* testing tightest match */\r
432         new SearchData(" abc  a bc   ab c    a  bc     ab  c",             "abc",       null, Collator.QUATERNARY, null,\r
433                        new int[]{1, -1}, new int[] {3}),\r
434         /*012345678901234567890123456789012345678901234567890123456789 */\r
435         new SearchData(" abc  a bc   ab c    a  bc     ab  c",             "abc",       null, Collator.SECONDARY,  null,\r
436                        new int[] {1, 6, 13, 21, 31, -1}, new int[] {3, 4, 4, 5, 5}),\r
437 \r
438         /* totally ignorable text */\r
439         new SearchData("           ---------------",                       "abc",       null, Collator.SECONDARY,  null,\r
440                        new int[] {-1}, new int[] {0}),\r
441         new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[] {0})\r
442     };\r
443 \r
444     static SearchData TEXTCANONICAL[] = {\r
445         new SearchData("the foxy brown fox",                               "fox",       null, Collator.TERTIARY,   null,\r
446                        new int[] {4, 15, -1}, new int[] {3, 3}),\r
447         new SearchData("the quick brown fox",                              "fox",       null, Collator.TERTIARY,   null,\r
448                        new int[] {16, -1}, new int[]{3}),\r
449         new SearchData(null, null, null, Collator.TERTIARY,null, new int[] {-1}, new int[] {0})\r
450     };\r
451 \r
452     /**\r
453      * Constructor\r
454      */\r
455     public SearchTest()\r
456     {\r
457 \r
458     }\r
459 \r
460     protected void init()throws Exception{\r
461         m_en_us_ = (RuleBasedCollator)Collator.getInstance(Locale.US);\r
462         m_fr_fr_ = (RuleBasedCollator)Collator.getInstance(Locale.FRANCE);\r
463         m_de_ = (RuleBasedCollator)Collator.getInstance(new Locale("de", "DE"));\r
464         m_es_ = (RuleBasedCollator)Collator.getInstance(new Locale("es", "ES"));\r
465         m_en_wordbreaker_ = BreakIterator.getWordInstance();\r
466         m_en_characterbreaker_ = BreakIterator.getCharacterInstance();\r
467         String rules = m_de_.getRules() + EXTRACOLLATIONRULE;\r
468         m_de_ = new RuleBasedCollator(rules);\r
469         rules = m_es_.getRules() + EXTRACOLLATIONRULE;\r
470         m_es_ = new RuleBasedCollator(rules);\r
471 \r
472     }\r
473     public static void main(String[] args) throws Exception {\r
474         new SearchTest().run(args);\r
475         // new SearchTest().TestContraction();\r
476     }\r
477 \r
478     RuleBasedCollator getCollator(String collator) {\r
479         if (collator == null) {\r
480             return m_en_us_;\r
481         } if (collator.equals("fr")) {\r
482             return m_fr_fr_;\r
483         } else if (collator.equals("de")) {\r
484             return m_de_;\r
485         } else if (collator.equals("es")) {\r
486             return m_es_;\r
487         } else {\r
488             return m_en_us_;\r
489         }\r
490     }\r
491 \r
492     BreakIterator getBreakIterator(String breaker) {\r
493         if (breaker == null) {\r
494             return null;\r
495         } if (breaker.equals("wordbreaker")) {\r
496             return m_en_wordbreaker_;\r
497         } else {\r
498             return m_en_characterbreaker_;\r
499         }\r
500     }\r
501 \r
502     boolean assertCanonicalEqual(SearchData search) {\r
503         Collator      collator = getCollator(search.collator);\r
504         BreakIterator breaker  = getBreakIterator(search.breaker);\r
505         StringSearch  strsrch;\r
506 \r
507         String text = search.text;\r
508         String  pattern = search.pattern;\r
509 \r
510         if (breaker != null) {\r
511             breaker.setText(text);\r
512         }\r
513         collator.setStrength(search.strength);\r
514         try {\r
515             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), (RuleBasedCollator)collator, breaker);\r
516             strsrch.setCanonical(true);\r
517         } catch (Exception e) {\r
518             errln("Error opening string search" + e.getMessage());\r
519             return false;\r
520         }\r
521 \r
522         if (!assertEqualWithStringSearch(strsrch, search)) {\r
523             collator.setStrength(Collator.TERTIARY);\r
524             return false;\r
525         }\r
526         collator.setStrength(Collator.TERTIARY);\r
527         return true;\r
528     }\r
529 \r
530     boolean assertEqual(SearchData search) {\r
531         Collator      collator = getCollator(search.collator);\r
532         BreakIterator breaker  = getBreakIterator(search.breaker);\r
533         StringSearch  strsrch;\r
534 \r
535         String text = search.text;\r
536         String  pattern = search.pattern;\r
537 \r
538         if (breaker != null) {\r
539             breaker.setText(text);\r
540         }\r
541         collator.setStrength(search.strength);\r
542         try {\r
543             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), (RuleBasedCollator)collator, breaker);\r
544         } catch (Exception e) {\r
545             errln("Error opening string search " + e.getMessage());\r
546             return false;\r
547         }\r
548 \r
549         if (!assertEqualWithStringSearch(strsrch, search)) {\r
550             collator.setStrength(Collator.TERTIARY);\r
551             return false;\r
552         }\r
553         collator.setStrength(Collator.TERTIARY);\r
554         return true;\r
555     }\r
556 \r
557     boolean assertEqualWithAttribute(SearchData search, boolean canonical, boolean overlap) {\r
558         Collator      collator = getCollator(search.collator);\r
559         BreakIterator breaker  = getBreakIterator(search.breaker);\r
560         StringSearch  strsrch;\r
561 \r
562         String text = search.text;\r
563         String  pattern = search.pattern;\r
564 \r
565         if (breaker != null) {\r
566             breaker.setText(text);\r
567         }\r
568         collator.setStrength(search.strength);\r
569         try {\r
570             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), (RuleBasedCollator)collator, breaker);\r
571             strsrch.setCanonical(canonical);\r
572             strsrch.setOverlapping(overlap);\r
573         } catch (Exception e) {\r
574             errln("Error opening string search " + e.getMessage());\r
575             return false;\r
576         }\r
577 \r
578         if (!assertEqualWithStringSearch(strsrch, search)) {\r
579             collator.setStrength(Collator.TERTIARY);\r
580             return false;\r
581         }\r
582         collator.setStrength(Collator.TERTIARY);\r
583         return true;\r
584     }\r
585 \r
586     boolean assertEqualWithStringSearch(StringSearch strsrch, SearchData search) {\r
587         int           count       = 0;\r
588         int   matchindex  = search.offset[count];\r
589         String matchtext;\r
590 \r
591         if (strsrch.getMatchStart() != SearchIterator.DONE ||\r
592             strsrch.getMatchLength() != 0) {\r
593             errln("Error with the initialization of match start and length");\r
594         }\r
595         // start of following matches\r
596         while (matchindex >= 0) {\r
597             int matchlength = search.size[count];\r
598             strsrch.next();\r
599             //int x = strsrch.getMatchStart();\r
600             if (matchindex != strsrch.getMatchStart() ||\r
601                 matchlength != strsrch.getMatchLength()) {\r
602                 errln("Text: " + search.text);\r
603                 errln("Pattern: " + strsrch.getPattern());\r
604                 errln("Error following match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
605                 return false;\r
606             }\r
607             count ++;\r
608 \r
609             matchtext = strsrch.getMatchedText();\r
610             String targetText = search.text;\r
611             if (matchlength > 0 &&\r
612                 targetText.substring(matchindex, matchindex + matchlength).compareTo(matchtext) != 0) {\r
613                 errln("Error getting following matched text");\r
614             }\r
615 \r
616             matchindex = search.offset[count];\r
617         }\r
618         strsrch.next();\r
619         if (strsrch.getMatchStart() != SearchIterator.DONE ||\r
620             strsrch.getMatchLength() != 0) {\r
621                 errln("Text: " + search.text);\r
622                 errln("Pattern: " + strsrch.getPattern());\r
623                 errln("Error following match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
624                 return false;\r
625         }\r
626         // start of preceding matches\r
627         count = count == 0 ? 0 : count - 1;\r
628         matchindex = search.offset[count];\r
629         while (matchindex >= 0) {\r
630             int matchlength = search.size[count];\r
631             strsrch.previous();\r
632             if (matchindex != strsrch.getMatchStart() ||\r
633                 matchlength != strsrch.getMatchLength()) {\r
634                 errln("Text: " + search.text);\r
635                 errln("Pattern: " + strsrch.getPattern());\r
636                 errln("Error following match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
637                 return false;\r
638             }\r
639 \r
640             matchtext = strsrch.getMatchedText();\r
641             String targetText = search.text;\r
642             if (matchlength > 0 &&\r
643                 targetText.substring(matchindex, matchindex + matchlength).compareTo(matchtext) != 0) {\r
644                 errln("Error getting following matched text");\r
645             }\r
646 \r
647             matchindex = count > 0 ? search.offset[count - 1] : -1;\r
648             count --;\r
649         }\r
650         strsrch.previous();\r
651         if (strsrch.getMatchStart() != SearchIterator.DONE ||\r
652             strsrch.getMatchLength() != 0) {\r
653                 errln("Text: " + search.text);\r
654                 errln("Pattern: " + strsrch.getPattern());\r
655                 errln("Error following match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
656                 return false;\r
657         }\r
658         return true;\r
659     }\r
660 \r
661     public void TestConstructor()\r
662     {\r
663         String pattern = "pattern";\r
664         String text = "text";\r
665         StringCharacterIterator textiter = new StringCharacterIterator(text);\r
666         Collator defaultcollator = Collator.getInstance();\r
667         BreakIterator breaker = BreakIterator.getCharacterInstance();\r
668         breaker.setText(text);\r
669         StringSearch search = new StringSearch(pattern, text);\r
670         if (!search.getPattern().equals(pattern)\r
671             || !search.getTarget().equals(textiter)\r
672             || !search.getCollator().equals(defaultcollator)\r
673             /*|| !search.getBreakIterator().equals(breaker)*/) {\r
674             errln("StringSearch(String, String) error");\r
675         }\r
676         search = new StringSearch(pattern, textiter, m_fr_fr_);\r
677         if (!search.getPattern().equals(pattern)\r
678             || !search.getTarget().equals(textiter)\r
679             || !search.getCollator().equals(m_fr_fr_)\r
680             /*|| !search.getBreakIterator().equals(breaker)*/) {\r
681             errln("StringSearch(String, StringCharacterIterator, "\r
682                   + "RuleBasedCollator) error");\r
683         }\r
684         Locale de = new Locale("de", "DE");\r
685         breaker = BreakIterator.getCharacterInstance(de);\r
686         breaker.setText(text);\r
687         search = new StringSearch(pattern, textiter, de);\r
688         if (!search.getPattern().equals(pattern)\r
689             || !search.getTarget().equals(textiter)\r
690             || !search.getCollator().equals(Collator.getInstance(de))\r
691             /*|| !search.getBreakIterator().equals(breaker)*/) {\r
692             errln("StringSearch(String, StringCharacterIterator, Locale) "\r
693                   + "error");\r
694         }\r
695 \r
696         search = new StringSearch(pattern, textiter, m_fr_fr_,\r
697                                   m_en_wordbreaker_);\r
698         if (!search.getPattern().equals(pattern)\r
699             || !search.getTarget().equals(textiter)\r
700             || !search.getCollator().equals(m_fr_fr_)\r
701             || !search.getBreakIterator().equals(m_en_wordbreaker_)) {\r
702             errln("StringSearch(String, StringCharacterIterator, Locale) "\r
703                   + "error");\r
704         }\r
705     }\r
706 \r
707     public void TestBasic() {\r
708         int count = 0;\r
709         while (BASIC[count].text != null) {\r
710             if (!assertEqual(BASIC[count])) {\r
711                 errln("Error at test number " + count);\r
712             }\r
713             count ++;\r
714         }\r
715     }\r
716 \r
717     public void TestBreakIterator() {\r
718 \r
719         String text = BREAKITERATOREXACT[0].text;\r
720         String pattern = BREAKITERATOREXACT[0].pattern;\r
721         StringSearch strsrch = null;\r
722         try {\r
723             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
724         } catch (Exception e) {\r
725             errln("Error opening string search");\r
726             return;\r
727         }\r
728 \r
729         strsrch.setBreakIterator(null);\r
730         if (strsrch.getBreakIterator() != null) {\r
731             errln("Error usearch_getBreakIterator returned wrong object");\r
732         }\r
733 \r
734         strsrch.setBreakIterator(m_en_characterbreaker_);\r
735         if (!strsrch.getBreakIterator().equals(m_en_characterbreaker_)) {\r
736             errln("Error usearch_getBreakIterator returned wrong object");\r
737         }\r
738 \r
739         strsrch.setBreakIterator(m_en_wordbreaker_);\r
740         if (!strsrch.getBreakIterator().equals(m_en_wordbreaker_)) {\r
741             errln("Error usearch_getBreakIterator returned wrong object");\r
742         }\r
743 \r
744         int count = 0;\r
745         while (count < 4) {\r
746             // special purposes for tests numbers 0-3\r
747             SearchData        search   = BREAKITERATOREXACT[count];\r
748             RuleBasedCollator collator = getCollator(search.collator);\r
749             BreakIterator     breaker  = getBreakIterator(search.breaker);\r
750                   //StringSearch      strsrch;\r
751 \r
752             text = search.text;\r
753             pattern = search.pattern;\r
754             if (breaker != null) {\r
755                 breaker.setText(text);\r
756             }\r
757             collator.setStrength(search.strength);\r
758             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, breaker);\r
759             if (strsrch.getBreakIterator() != breaker) {\r
760                 errln("Error setting break iterator");\r
761             }\r
762             if (!assertEqualWithStringSearch(strsrch, search)) {\r
763                 collator.setStrength(Collator.TERTIARY);\r
764             }\r
765             search   = BREAKITERATOREXACT[count + 1];\r
766             breaker  = getBreakIterator(search.breaker);\r
767             if (breaker != null) {\r
768                 breaker.setText(text);\r
769             }\r
770             strsrch.setBreakIterator(breaker);\r
771             if (strsrch.getBreakIterator() != breaker) {\r
772                 errln("Error setting break iterator");\r
773             }\r
774             strsrch.reset();\r
775             if (!assertEqualWithStringSearch(strsrch, search)) {\r
776                  errln("Error at test number " + count);\r
777             }\r
778             count += 2;\r
779         }\r
780         count = 0;\r
781         while (BREAKITERATOREXACT[count].text != null) {\r
782             if (!assertEqual(BREAKITERATOREXACT[count])) {\r
783                 errln("Error at test number " + count);\r
784             }\r
785              count++;\r
786         }\r
787     }\r
788 \r
789     public void TestBreakIteratorCanonical() {\r
790         int        count  = 0;\r
791         while (count < 4) {\r
792             // special purposes for tests numbers 0-3\r
793             SearchData     search   = BREAKITERATORCANONICAL[count];\r
794 \r
795             String text = search.text;\r
796             String pattern = search.pattern;\r
797             RuleBasedCollator collator = getCollator(search.collator);\r
798             collator.setStrength(search.strength);\r
799 \r
800             BreakIterator breaker = getBreakIterator(search.breaker);\r
801             StringSearch  strsrch = null;\r
802             try {\r
803                 strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, breaker);\r
804             } catch (Exception e) {\r
805                 errln("Error creating string search data");\r
806                 return;\r
807             }\r
808             strsrch.setCanonical(true);\r
809             if (!strsrch.getBreakIterator().equals(breaker)) {\r
810                 errln("Error setting break iterator");\r
811                 return;\r
812             }\r
813             if (!assertEqualWithStringSearch(strsrch, search)) {\r
814                 collator.setStrength(Collator.TERTIARY);\r
815                 return;\r
816             }\r
817             search  = BREAKITERATOREXACT[count + 1];\r
818             breaker = getBreakIterator(search.breaker);\r
819             breaker.setText(strsrch.getTarget());\r
820             strsrch.setBreakIterator(breaker);\r
821             if (!strsrch.getBreakIterator().equals(breaker)) {\r
822                 errln("Error setting break iterator");\r
823                 return;\r
824             }\r
825             strsrch.reset();\r
826             strsrch.setCanonical(true);\r
827             if (!assertEqualWithStringSearch(strsrch, search)) {\r
828                  errln("Error at test number " + count);\r
829                  return;\r
830             }\r
831             count += 2;\r
832         }\r
833         count = 0;\r
834         while (BREAKITERATORCANONICAL[count].text != null) {\r
835              if (!assertEqual(BREAKITERATORCANONICAL[count])) {\r
836                  errln("Error at test number " + count);\r
837                  return;\r
838              }\r
839              count++;\r
840         }\r
841     }\r
842 \r
843     public void TestCanonical() {\r
844         int count = 0;\r
845         while (BASICCANONICAL[count].text != null) {\r
846             if (!assertCanonicalEqual(BASICCANONICAL[count])) {\r
847                 errln("Error at test number " + count);\r
848             }\r
849             count ++;\r
850         }\r
851     }\r
852 \r
853     public void TestCollator() {\r
854         // test collator that thinks "o" and "p" are the same thing\r
855         String text = COLLATOR[0].text;\r
856         String pattern  = COLLATOR[0].pattern;\r
857         StringSearch strsrch = null;\r
858         try {\r
859             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
860         } catch (Exception e) {\r
861             errln("Error opening string search ");\r
862             return;\r
863         }\r
864         if (!assertEqualWithStringSearch(strsrch, COLLATOR[0])) {\r
865             return;\r
866         }\r
867         String rules = TESTCOLLATORRULE;\r
868         RuleBasedCollator tailored = null;\r
869         try {\r
870             tailored = new RuleBasedCollator(rules);\r
871             tailored.setStrength(COLLATOR[1].strength);\r
872         } catch (Exception e) {\r
873             errln("Error opening rule based collator ");\r
874             return;\r
875         }\r
876 \r
877         strsrch.setCollator(tailored);\r
878         if (!strsrch.getCollator().equals(tailored)) {\r
879             errln("Error setting rule based collator");\r
880         }\r
881         strsrch.reset();\r
882         if (!assertEqualWithStringSearch(strsrch, COLLATOR[1])) {\r
883             return;\r
884         }\r
885         strsrch.setCollator(m_en_us_);\r
886         strsrch.reset();\r
887         if (!strsrch.getCollator().equals(m_en_us_)) {\r
888             errln("Error setting rule based collator");\r
889         }\r
890         if (!assertEqualWithStringSearch(strsrch, COLLATOR[0])) {\r
891            errln("Error searching collator test");\r
892         }\r
893     }\r
894 \r
895     public void TestCollatorCanonical() {\r
896         /* test collator that thinks "o" and "p" are the same thing */\r
897         String text = COLLATORCANONICAL[0].text;\r
898         String pattern = COLLATORCANONICAL[0].pattern;\r
899 \r
900         StringSearch strsrch = null;\r
901         try {\r
902             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
903             strsrch.setCanonical(true);\r
904         } catch (Exception e) {\r
905             errln("Error opening string search ");\r
906         }\r
907 \r
908         if (!assertEqualWithStringSearch(strsrch, COLLATORCANONICAL[0])) {\r
909             return;\r
910         }\r
911 \r
912         String rules = TESTCOLLATORRULE;\r
913         RuleBasedCollator tailored = null;\r
914         try {\r
915             tailored = new RuleBasedCollator(rules);\r
916             tailored.setStrength(COLLATORCANONICAL[1].strength);\r
917             tailored.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
918         } catch (Exception e) {\r
919             errln("Error opening rule based collator ");\r
920         }\r
921 \r
922         strsrch.setCollator(tailored);\r
923         if (!strsrch.getCollator().equals(tailored)) {\r
924             errln("Error setting rule based collator");\r
925         }\r
926         strsrch.reset();\r
927         strsrch.setCanonical(true);\r
928         if (!assertEqualWithStringSearch(strsrch, COLLATORCANONICAL[1])) {\r
929             logln("COLLATORCANONICAL[1] failed");  // Error should already be reported.\r
930         }\r
931         strsrch.setCollator(m_en_us_);\r
932         strsrch.reset();\r
933         if (!strsrch.getCollator().equals(m_en_us_)) {\r
934             errln("Error setting rule based collator");\r
935         }\r
936         if (!assertEqualWithStringSearch(strsrch, COLLATORCANONICAL[0])) {\r
937             logln("COLLATORCANONICAL[0] failed");  // Error should already be reported.\r
938         }\r
939     }\r
940 \r
941     public void TestCompositeBoundaries() {\r
942         int count = 0;\r
943         while (COMPOSITEBOUNDARIES[count].text != null) {\r
944             // logln("composite " + count);\r
945             if (!assertEqual(COMPOSITEBOUNDARIES[count])) {\r
946                 errln("Error at test number " + count);\r
947             }\r
948             count++;\r
949         }\r
950     }\r
951 \r
952     public void TestCompositeBoundariesCanonical() {\r
953         int count = 0;\r
954         while (COMPOSITEBOUNDARIESCANONICAL[count].text != null) {\r
955             // logln("composite " + count);\r
956             if (!assertCanonicalEqual(COMPOSITEBOUNDARIESCANONICAL[count])) {\r
957                 errln("Error at test number " + count);\r
958             }\r
959             count++;\r
960         }\r
961     }\r
962 \r
963     public void TestContraction() {\r
964         String rules = CONTRACTIONRULE;\r
965         RuleBasedCollator collator = null;\r
966         try {\r
967             collator = new RuleBasedCollator(rules);\r
968             collator.setStrength(Collator.TERTIARY);\r
969             collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
970         } catch (Exception e) {\r
971             errln("Error opening collator ");\r
972         }\r
973         String text = "text";\r
974         String pattern = "pattern";\r
975         StringSearch strsrch = null;\r
976         try {\r
977             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);\r
978         } catch (Exception e) {\r
979             errln("Error opening string search ");\r
980         }\r
981 \r
982         int count = 0;\r
983         while (CONTRACTION[count].text != null) {\r
984             text = CONTRACTION[count].text;\r
985             pattern = CONTRACTION[count].pattern;\r
986             strsrch.setTarget(new StringCharacterIterator(text));\r
987             strsrch.setPattern(pattern);\r
988             if (!assertEqualWithStringSearch(strsrch, CONTRACTION[count])) {\r
989                 errln("Error at test number " + count);\r
990             }\r
991             count++;\r
992         }\r
993     }\r
994 \r
995     public void TestContractionCanonical() {\r
996         String rules = CONTRACTIONRULE;\r
997         RuleBasedCollator collator = null;\r
998         try {\r
999             collator = new RuleBasedCollator(rules);\r
1000             collator.setStrength(Collator.TERTIARY);\r
1001             collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
1002         } catch (Exception e) {\r
1003             errln("Error opening collator ");\r
1004         }\r
1005         String text = "text";\r
1006         String pattern = "pattern";\r
1007         StringSearch strsrch = null;\r
1008         try {\r
1009             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);\r
1010             strsrch.setCanonical(true);\r
1011         } catch (Exception e) {\r
1012             errln("Error opening string search");\r
1013         }\r
1014 \r
1015         int count = 0;\r
1016         while (CONTRACTIONCANONICAL[count].text != null) {\r
1017             text = CONTRACTIONCANONICAL[count].text;\r
1018             pattern = CONTRACTIONCANONICAL[count].pattern;\r
1019             strsrch.setTarget(new StringCharacterIterator(text));\r
1020             strsrch.setPattern(pattern);\r
1021             if (!assertEqualWithStringSearch(strsrch, CONTRACTIONCANONICAL[count])) {\r
1022                 errln("Error at test number " + count);\r
1023             }\r
1024             count++;\r
1025         }\r
1026     }\r
1027 \r
1028     public void TestGetMatch() {\r
1029         SearchData search = MATCH[0];\r
1030         String text = search.text;\r
1031         String pattern = search.pattern;\r
1032 \r
1033         StringSearch strsrch = null;\r
1034         try {\r
1035             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1036         } catch (Exception e) {\r
1037             errln("Error opening string search ");\r
1038             return;\r
1039         }\r
1040 \r
1041         int           count      = 0;\r
1042         int   matchindex = search.offset[count];\r
1043         String matchtext;\r
1044         while (matchindex >= 0) {\r
1045             int matchlength = search.size[count];\r
1046             strsrch.next();\r
1047             if (matchindex != strsrch.getMatchStart() ||\r
1048                 matchlength != strsrch.getMatchLength()) {\r
1049                 errln("Text: " + search.text);\r
1050                 errln("Pattern: " + strsrch.getPattern());\r
1051                 errln("Error match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
1052                 return;\r
1053             }\r
1054             count++;\r
1055 \r
1056             matchtext = strsrch.getMatchedText();\r
1057             if (matchtext.length() != matchlength){\r
1058                 errln("Error getting match text");\r
1059             }\r
1060             matchindex = search.offset[count];\r
1061         }\r
1062         strsrch.next();\r
1063         if (strsrch.getMatchStart()  != StringSearch.DONE ||\r
1064             strsrch.getMatchLength() != 0) {\r
1065             errln("Error end of match not found");\r
1066         }\r
1067         matchtext = strsrch.getMatchedText();\r
1068         if (matchtext != null) {\r
1069             errln("Error getting null matches");\r
1070         }\r
1071     }\r
1072 \r
1073     public void TestGetSetAttribute() {\r
1074         String  pattern = "pattern";\r
1075         String  text = "text";\r
1076         StringSearch  strsrch = null;\r
1077         try {\r
1078             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1079         } catch (Exception e) {\r
1080             errln("Error opening search");\r
1081             return;\r
1082         }\r
1083 \r
1084         if (strsrch.isOverlapping()) {\r
1085             errln("Error default overlaping should be false");\r
1086         }\r
1087         strsrch.setOverlapping(true);\r
1088         if (!strsrch.isOverlapping()) {\r
1089             errln("Error setting overlap true");\r
1090         }\r
1091         strsrch.setOverlapping(false);\r
1092         if (strsrch.isOverlapping()) {\r
1093             errln("Error setting overlap false");\r
1094         }\r
1095 \r
1096         strsrch.setCanonical(true);\r
1097         if (!strsrch.isCanonical()) {\r
1098             errln("Error setting canonical match true");\r
1099         }\r
1100         strsrch.setCanonical(false);\r
1101         if (strsrch.isCanonical()) {\r
1102             errln("Error setting canonical match false");\r
1103         }\r
1104 \r
1105     }\r
1106 \r
1107     public void TestGetSetOffset() {\r
1108         String  pattern = "1234567890123456";\r
1109         String  text  = "12345678901234567890123456789012";\r
1110         StringSearch  strsrch = null;\r
1111         try {\r
1112             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1113         } catch (Exception e) {\r
1114             errln("Error opening search");\r
1115 \r
1116             return;\r
1117         }\r
1118 \r
1119         /* testing out of bounds error */\r
1120         try {\r
1121             strsrch.setIndex(-1);\r
1122             errln("Error expecting set offset error");\r
1123         } catch (IndexOutOfBoundsException e) {\r
1124             logln("PASS: strsrch.setIndex(-1) failed as expected");\r
1125         }\r
1126 \r
1127         try {\r
1128             strsrch.setIndex(128);\r
1129             errln("Error expecting set offset error");\r
1130         } catch (IndexOutOfBoundsException e) {\r
1131             logln("PASS: strsrch.setIndex(128) failed as expected");\r
1132         }\r
1133 \r
1134         int index   = 0;\r
1135         while (BASIC[index].text != null) {\r
1136             SearchData  search      = BASIC[index ++];\r
1137 \r
1138             text =search.text;\r
1139             pattern = search.pattern;\r
1140             strsrch.setTarget(new StringCharacterIterator(text));\r
1141             strsrch.setPattern(pattern);\r
1142             strsrch.getCollator().setStrength(search.strength);\r
1143             strsrch.reset();\r
1144 \r
1145             int count = 0;\r
1146             int matchindex  = search.offset[count];\r
1147 \r
1148             while (matchindex >= 0) {\r
1149                 int matchlength = search.size[count];\r
1150                 strsrch.next();\r
1151                 if (matchindex != strsrch.getMatchStart() ||\r
1152                     matchlength != strsrch.getMatchLength()) {\r
1153                     errln("Text: " + text);\r
1154                     errln("Pattern: " + strsrch.getPattern());\r
1155                     errln("Error match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
1156                     return;\r
1157                 }\r
1158                 matchindex = search.offset[count + 1] == -1 ? -1 :\r
1159                              search.offset[count + 2];\r
1160                 if (search.offset[count + 1] != -1) {\r
1161                     strsrch.setIndex(search.offset[count + 1] + 1);\r
1162                     if (strsrch.getIndex() != search.offset[count + 1] + 1) {\r
1163                         errln("Error setting offset\n");\r
1164                         return;\r
1165                     }\r
1166                 }\r
1167 \r
1168                 count += 2;\r
1169             }\r
1170             strsrch.next();\r
1171             if (strsrch.getMatchStart() != StringSearch.DONE) {\r
1172                 errln("Text: " + text);\r
1173                 errln("Pattern: " + strsrch.getPattern());\r
1174                 errln("Error match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
1175                 return;\r
1176             }\r
1177         }\r
1178         strsrch.getCollator().setStrength(Collator.TERTIARY);\r
1179     }\r
1180 \r
1181     public void TestGetSetOffsetCanonical() {\r
1182 \r
1183         String  text = "text";\r
1184         String  pattern = "pattern";\r
1185         StringSearch  strsrch = null;\r
1186         try {\r
1187             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1188         } catch (Exception e) {\r
1189             errln("Fail to open StringSearch!");\r
1190             return;\r
1191         }\r
1192         strsrch.setCanonical(true);\r
1193         /* testing out of bounds error */\r
1194         try {\r
1195             strsrch.setIndex(-1);\r
1196             errln("Error expecting set offset error");\r
1197         } catch (IndexOutOfBoundsException e) {\r
1198             logln("PASS: strsrch.setIndex(-1) failed as expected");\r
1199         }\r
1200         try {\r
1201             strsrch.setIndex(128);\r
1202             errln("Error expecting set offset error");\r
1203         } catch (IndexOutOfBoundsException e) {\r
1204             logln("PASS: strsrch.setIndex(128) failed as expected");\r
1205         }\r
1206 \r
1207         int   index   = 0;\r
1208         while (BASICCANONICAL[index].text != null) {\r
1209             SearchData  search      = BASICCANONICAL[index ++];\r
1210             if (BASICCANONICAL[index].text == null) {\r
1211                 // skip the last one\r
1212                 break;\r
1213             }\r
1214 \r
1215             text = search.text;\r
1216             pattern = search.pattern;\r
1217             strsrch.setTarget(new StringCharacterIterator(text));\r
1218             strsrch.setPattern(pattern);\r
1219             int         count       = 0;\r
1220             int matchindex  = search.offset[count];\r
1221             while (matchindex >= 0) {\r
1222                 int matchlength = search.size[count];\r
1223                 strsrch.next();\r
1224                 if (matchindex != strsrch.getMatchStart() ||\r
1225                     matchlength != strsrch.getMatchLength()) {\r
1226                     errln("Text: " + text);\r
1227                     errln("Pattern: " + strsrch.getPattern());\r
1228                     errln("Error match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
1229                     return;\r
1230                 }\r
1231                 matchindex = search.offset[count + 1] == -1 ? -1 :\r
1232                              search.offset[count + 2];\r
1233                 if (search.offset[count + 1] != -1) {\r
1234                     strsrch.setIndex(search.offset[count + 1] + 1);\r
1235                     if (strsrch.getIndex() != search.offset[count + 1] + 1) {\r
1236                         errln("Error setting offset");\r
1237                         return;\r
1238                     }\r
1239                 }\r
1240 \r
1241                 count += 2;\r
1242             }\r
1243             strsrch.next();\r
1244             if (strsrch.getMatchStart() != StringSearch.DONE) {\r
1245                 errln("Text: " + text);\r
1246                 errln("Pattern: %s" + strsrch.getPattern());\r
1247                 errln("Error match found at " + strsrch.getMatchStart() + ", " + strsrch.getMatchLength());\r
1248                 return;\r
1249             }\r
1250         }\r
1251         strsrch.getCollator().setStrength(Collator.TERTIARY);\r
1252     }\r
1253 \r
1254     public void TestIgnorable() {\r
1255         String rules = IGNORABLERULE;\r
1256         int        count  = 0;\r
1257         RuleBasedCollator collator = null;\r
1258         try {\r
1259             collator = new RuleBasedCollator(rules);\r
1260             collator.setStrength(IGNORABLE[count].strength);\r
1261             collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
1262         } catch (Exception e) {\r
1263             errln("Error opening collator ");\r
1264             return;\r
1265         }\r
1266         String pattern = "pattern";\r
1267         String text = "text";\r
1268         StringSearch strsrch = null;\r
1269         try {\r
1270             strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);\r
1271         } catch (Exception e) {\r
1272             errln("Error opening string search ");\r
1273             return;\r
1274         }\r
1275 \r
1276         while (IGNORABLE[count].text != null) {\r
1277             text = IGNORABLE[count].text;\r
1278             pattern = IGNORABLE[count].pattern;\r
1279             strsrch.setTarget(new StringCharacterIterator(text));\r
1280             strsrch.setPattern(pattern);\r
1281             if (!assertEqualWithStringSearch(strsrch, IGNORABLE[count])) {\r
1282                 errln("Error at test number " + count);\r
1283             }\r
1284             count++;\r
1285         }\r
1286     }\r
1287 \r
1288     public void TestInitialization() {\r
1289         String  pattern;\r
1290         String  text;\r
1291         String  temp = "a";\r
1292         StringSearch  result;\r
1293 \r
1294         /* simple test on the pattern ce construction */\r
1295         pattern = temp + temp;\r
1296         text = temp + temp + temp;\r
1297         try {\r
1298             result = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1299         } catch (Exception e) {\r
1300             errln("Error opening search ");\r
1301             return;\r
1302         }\r
1303 \r
1304         /* testing if an extremely large pattern will fail the initialization */\r
1305         pattern = "";\r
1306         for (int count = 0; count < 512; count ++) {\r
1307             pattern += temp;\r
1308         }\r
1309         try {\r
1310             result = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1311             logln("pattern:" + result.getPattern());\r
1312         } catch (Exception e) {\r
1313             errln("Fail: an extremely large pattern will fail the initialization");\r
1314             return;\r
1315         }\r
1316     }\r
1317 \r
1318     public void TestNormCanonical() {\r
1319         m_en_us_.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
1320         int count = 0;\r
1321         while (NORMCANONICAL[count].text != null) {\r
1322             if (!assertCanonicalEqual(NORMCANONICAL[count])) {\r
1323                 errln("Error at test number " + count);\r
1324             }\r
1325             count++;\r
1326         }\r
1327         m_en_us_.setDecomposition(Collator.NO_DECOMPOSITION);\r
1328     }\r
1329 \r
1330     public void TestNormExact() {\r
1331         int count = 0;\r
1332         m_en_us_.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
1333         while (BASIC[count].text != null) {\r
1334             if (!assertEqual(BASIC[count])) {\r
1335                 errln("Error at test number " + count);\r
1336             }\r
1337             count++;\r
1338         }\r
1339         count = 0;\r
1340         while (NORMEXACT[count].text != null) {\r
1341             if (!assertEqual(NORMEXACT[count])) {\r
1342                 errln("Error at test number " + count);\r
1343             }\r
1344             count++;\r
1345         }\r
1346         m_en_us_.setDecomposition(Collator.NO_DECOMPOSITION);\r
1347         count = 0;\r
1348         while (NONNORMEXACT[count].text != null) {\r
1349             if (!assertEqual(NONNORMEXACT[count])) {\r
1350                 errln("Error at test number " + count);\r
1351             }\r
1352             count++;\r
1353         }\r
1354     }\r
1355 \r
1356     public void TestOpenClose() {\r
1357         StringSearch            result;\r
1358         BreakIterator           breakiter = m_en_wordbreaker_;\r
1359         String           pattern = "";\r
1360         String           text = "";\r
1361         String           temp  = "a";\r
1362         StringCharacterIterator  chariter= new StringCharacterIterator(text);\r
1363 \r
1364         /* testing null arguments */\r
1365         try {\r
1366             result = new StringSearch(pattern, new StringCharacterIterator(text), null, null);\r
1367             errln("Error: null arguments should produce an error");\r
1368         } catch (Exception e) {\r
1369             logln("PASS: null arguments failed as expected");\r
1370         }\r
1371 \r
1372         chariter.setText(text);\r
1373         try {\r
1374             result = new StringSearch(pattern, chariter, null, null);\r
1375             errln("Error: null arguments should produce an error");\r
1376         } catch (Exception e) {\r
1377             logln("PASS: null arguments failed as expected");\r
1378         }\r
1379 \r
1380         text  = String.valueOf(0x1);\r
1381         try {\r
1382             result = new StringSearch(pattern, new StringCharacterIterator(text), null, null);\r
1383             errln("Error: Empty pattern should produce an error");\r
1384         } catch (Exception e) {\r
1385             logln("PASS: Empty pattern failed as expected");\r
1386         }\r
1387 \r
1388         chariter.setText(text);\r
1389         try {\r
1390             result = new StringSearch(pattern, chariter, null, null);\r
1391             errln("Error: Empty pattern should produce an error");\r
1392         } catch (Exception e) {\r
1393             logln("PASS: Empty pattern failed as expected");\r
1394         }\r
1395 \r
1396         text = "";\r
1397         pattern =temp;\r
1398         try {\r
1399             result = new StringSearch(pattern, new StringCharacterIterator(text), null, null);\r
1400             errln("Error: Empty text should produce an error");\r
1401         } catch (Exception e) {\r
1402             logln("PASS: Empty text failed as expected");\r
1403         }\r
1404 \r
1405         chariter.setText(text);\r
1406         try {\r
1407             result = new StringSearch(pattern, chariter, null, null);\r
1408             errln("Error: Empty text should produce an error");\r
1409         } catch (Exception e) {\r
1410             logln("PASS: Empty text failed as expected");\r
1411         }\r
1412 \r
1413         text += temp;\r
1414         try {\r
1415             result = new StringSearch(pattern, new StringCharacterIterator(text), null, null);\r
1416             errln("Error: null arguments should produce an error");\r
1417         } catch (Exception e) {\r
1418             logln("PASS: null arguments failed as expected");\r
1419         }\r
1420 \r
1421         chariter.setText(text);\r
1422         try {\r
1423             result = new StringSearch(pattern, chariter, null, null);\r
1424             errln("Error: null arguments should produce an error");\r
1425         } catch (Exception e) {\r
1426             logln("PASS: null arguments failed as expected");\r
1427         }\r
1428 \r
1429         try {\r
1430             result = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, null);\r
1431         } catch (Exception e) {\r
1432             errln("Error: null break iterator is valid for opening search");\r
1433         }\r
1434 \r
1435         try {\r
1436             result = new StringSearch(pattern, chariter, m_en_us_, null);\r
1437         } catch (Exception e) {\r
1438             errln("Error: null break iterator is valid for opening search");\r
1439         }\r
1440 \r
1441         try {\r
1442             result = new StringSearch(pattern, new StringCharacterIterator(text), Locale.ENGLISH);\r
1443         } catch (Exception e) {\r
1444             errln("Error: null break iterator is valid for opening search");\r
1445         }\r
1446 \r
1447         try {\r
1448             result = new StringSearch(pattern, chariter, Locale.ENGLISH);\r
1449         } catch (Exception e) {\r
1450             errln("Error: null break iterator is valid for opening search");\r
1451         }\r
1452 \r
1453         try {\r
1454             result = new StringSearch(pattern, new StringCharacterIterator(text), m_en_us_, breakiter);\r
1455         } catch (Exception e) {\r
1456             errln("Error: Break iterator is valid for opening search");\r
1457         }\r
1458 \r
1459         try {\r
1460             result = new StringSearch(pattern, chariter, m_en_us_, null);\r
1461             logln("pattern:" + result.getPattern());\r
1462         } catch (Exception e) {\r
1463             errln("Error: Break iterator is valid for opening search");\r
1464         }\r
1465     }\r
1466 \r
1467     public void TestOverlap() {\r
1468         int count = 0;\r
1469         while (OVERLAP[count].text != null) {\r
1470             if (!assertEqualWithAttribute(OVERLAP[count], false, true)) {\r
1471                 errln("Error at overlap test number " + count);\r
1472             }\r
1473             count++;\r
1474         }\r
1475         count = 0;\r
1476         while (NONOVERLAP[count].text != null) {\r
1477             if (!assertEqual(NONOVERLAP[count])) {\r
1478                 errln("Error at non overlap test number " + count);\r
1479             }\r
1480             count++;\r
1481         }\r
1482 \r
1483         count = 0;\r
1484         while (count < 1) {\r
1485             SearchData search = (OVERLAP[count]);\r
1486             String text = search.text;\r
1487             String pattern = search.pattern;\r
1488 \r
1489             RuleBasedCollator collator = getCollator(search.collator);\r
1490             StringSearch strsrch = null;\r
1491             try {\r
1492                 strsrch  = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);\r
1493             } catch (Exception e) {\r
1494                 errln("error open StringSearch");\r
1495                 return;\r
1496             }\r
1497 \r
1498             strsrch.setOverlapping(true);\r
1499             if (!strsrch.isOverlapping()) {\r
1500                 errln("Error setting overlap option");\r
1501             }\r
1502             if (!assertEqualWithStringSearch(strsrch, search)) {\r
1503                 return;\r
1504             }\r
1505 \r
1506             search = NONOVERLAP[count];\r
1507             strsrch.setOverlapping(false);\r
1508             if (strsrch.isOverlapping()) {\r
1509                 errln("Error setting overlap option");\r
1510             }\r
1511             strsrch.reset();\r
1512             if (!assertEqualWithStringSearch(strsrch, search)) {\r
1513                 errln("Error at test number " + count);\r
1514              }\r
1515             count ++;\r
1516         }\r
1517     }\r
1518 \r
1519     public void TestOverlapCanonical() {\r
1520         int count = 0;\r
1521         while (OVERLAPCANONICAL[count].text != null) {\r
1522             if (!assertEqualWithAttribute(OVERLAPCANONICAL[count], true,\r
1523                                           true)) {\r
1524                 errln("Error at overlap test number %d" + count);\r
1525             }\r
1526             count ++;\r
1527         }\r
1528         count = 0;\r
1529         while (NONOVERLAP[count].text != null) {\r
1530             if (!assertCanonicalEqual(NONOVERLAPCANONICAL[count])) {\r
1531                 errln("Error at non overlap test number %d" + count);\r
1532             }\r
1533             count ++;\r
1534         }\r
1535 \r
1536         count = 0;\r
1537         while (count < 1) {\r
1538                  /* UChar       temp[128];\r
1539             const SearchData *search = &(OVERLAPCANONICAL[count]);\r
1540                   UErrorCode  status = U_ZERO_ERROR;*/\r
1541             SearchData search = OVERLAPCANONICAL[count];\r
1542 \r
1543             /*u_unescape(search.text, temp, 128);\r
1544             UnicodeString text;\r
1545             text.setTo(temp, u_strlen(temp));\r
1546             u_unescape(search.pattern, temp, 128);\r
1547             UnicodeString pattern;\r
1548             pattern.setTo(temp, u_strlen(temp));*/\r
1549             RuleBasedCollator collator = getCollator(search.collator);\r
1550             StringSearch strsrch = new StringSearch(search.pattern, new StringCharacterIterator(search.text), collator, null);\r
1551             strsrch.setCanonical(true);\r
1552             strsrch.setOverlapping(true);\r
1553             if (strsrch.isOverlapping() != true) {\r
1554                 errln("Error setting overlap option");\r
1555             }\r
1556             if (!assertEqualWithStringSearch(strsrch, search)) {\r
1557                 strsrch = null;\r
1558                 return;\r
1559             }\r
1560             search = NONOVERLAPCANONICAL[count];\r
1561             strsrch.setOverlapping(false);\r
1562             if (strsrch.isOverlapping() != false) {\r
1563                 errln("Error setting overlap option");\r
1564             }\r
1565             strsrch.reset();\r
1566             if (!assertEqualWithStringSearch(strsrch, search)) {\r
1567                 strsrch = null;\r
1568                 errln("Error at test number %d" + count);\r
1569              }\r
1570 \r
1571             count ++;\r
1572             strsrch = null;\r
1573         }\r
1574     }\r
1575 \r
1576     public void TestPattern() {\r
1577         m_en_us_.setStrength(PATTERN[0].strength);\r
1578         StringSearch strsrch = new StringSearch(PATTERN[0].pattern, new StringCharacterIterator(PATTERN[0].text), m_en_us_, null);\r
1579 \r
1580         /*if (U_FAILURE(status)) {\r
1581             errln("Error opening string search %s", u_errorName(status));\r
1582             m_en_us_.setStrength(getECollationStrength(UCOL_TERTIARY));\r
1583             if (strsrch != NULL) {\r
1584                 delete strsrch;\r
1585             }\r
1586             return;\r
1587         }*/\r
1588 \r
1589         if (strsrch.getPattern() != PATTERN[0].pattern) {\r
1590             errln("Error setting pattern");\r
1591         }\r
1592         if (!assertEqualWithStringSearch(strsrch, PATTERN[0])) {\r
1593             m_en_us_.setStrength(Collator.TERTIARY);\r
1594             if (strsrch != null) {\r
1595                 strsrch = null;\r
1596             }\r
1597             return;\r
1598         }\r
1599 \r
1600         strsrch.setPattern(PATTERN[1].pattern);\r
1601         if (PATTERN[1].pattern != strsrch.getPattern()) {\r
1602             errln("Error setting pattern");\r
1603             m_en_us_.setStrength(Collator.TERTIARY);\r
1604             if (strsrch != null) {\r
1605                 strsrch = null;\r
1606             }\r
1607             return;\r
1608         }\r
1609         strsrch.reset();\r
1610 \r
1611         if (!assertEqualWithStringSearch(strsrch, PATTERN[1])) {\r
1612             m_en_us_.setStrength(Collator.TERTIARY);\r
1613             if (strsrch != null) {\r
1614                 strsrch = null;\r
1615             }\r
1616             return;\r
1617         }\r
1618 \r
1619         strsrch.setPattern(PATTERN[0].pattern);\r
1620         if (PATTERN[0].pattern != strsrch.getPattern()) {\r
1621             errln("Error setting pattern");\r
1622             m_en_us_.setStrength(Collator.TERTIARY);\r
1623             if (strsrch != null) {\r
1624                 strsrch = null;\r
1625             }\r
1626             return;\r
1627         }\r
1628             strsrch.reset();\r
1629 \r
1630         if (!assertEqualWithStringSearch(strsrch, PATTERN[0])) {\r
1631             m_en_us_.setStrength(Collator.TERTIARY);\r
1632             if (strsrch != null) {\r
1633                 strsrch = null;\r
1634             }\r
1635             return;\r
1636         }\r
1637         /* enormous pattern size to see if this crashes */\r
1638         String pattern = "";\r
1639         for (int templength = 0; templength != 512; templength ++) {\r
1640             pattern += 0x61;\r
1641         }\r
1642         try{\r
1643             strsrch.setPattern(pattern);\r
1644         }catch(Exception e) {\r
1645             errln("Error setting pattern with size 512");\r
1646         }\r
1647 \r
1648         m_en_us_.setStrength(Collator.TERTIARY);\r
1649         if (strsrch != null) {\r
1650             strsrch = null;\r
1651         }\r
1652     }\r
1653 \r
1654     public void TestPatternCanonical() {\r
1655         //StringCharacterIterator text = new StringCharacterIterator(PATTERNCANONICAL[0].text);\r
1656         m_en_us_.setStrength(PATTERNCANONICAL[0].strength);\r
1657         StringSearch strsrch = new StringSearch(PATTERNCANONICAL[0].pattern, new StringCharacterIterator(PATTERNCANONICAL[0].text),\r
1658                                                 m_en_us_, null);\r
1659         strsrch.setCanonical(true);\r
1660 \r
1661         if (PATTERNCANONICAL[0].pattern != strsrch.getPattern()) {\r
1662             errln("Error setting pattern");\r
1663         }\r
1664         if (!assertEqualWithStringSearch(strsrch, PATTERNCANONICAL[0])) {\r
1665             m_en_us_.setStrength(Collator.TERTIARY);\r
1666             strsrch = null;\r
1667             return;\r
1668         }\r
1669 \r
1670         strsrch.setPattern(PATTERNCANONICAL[1].pattern);\r
1671         if (PATTERNCANONICAL[1].pattern != strsrch.getPattern()) {\r
1672             errln("Error setting pattern");\r
1673             m_en_us_.setStrength(Collator.TERTIARY);\r
1674             strsrch = null;\r
1675             return;\r
1676         }\r
1677         strsrch.reset();\r
1678         strsrch.setCanonical(true);\r
1679 \r
1680         if (!assertEqualWithStringSearch(strsrch, PATTERNCANONICAL[1])) {\r
1681             m_en_us_.setStrength(Collator.TERTIARY);\r
1682             strsrch = null;\r
1683             return;\r
1684         }\r
1685 \r
1686         strsrch.setPattern(PATTERNCANONICAL[0].pattern);\r
1687         if (PATTERNCANONICAL[0].pattern != strsrch.getPattern()) {\r
1688             errln("Error setting pattern");\r
1689             m_en_us_.setStrength(Collator.TERTIARY);\r
1690             strsrch = null;\r
1691             return;\r
1692         }\r
1693 \r
1694         strsrch.reset();\r
1695         strsrch.setCanonical(true);\r
1696         if (!assertEqualWithStringSearch(strsrch, PATTERNCANONICAL[0])) {\r
1697             m_en_us_.setStrength(Collator.TERTIARY);\r
1698             strsrch = null;\r
1699             return;\r
1700         }\r
1701     }\r
1702 \r
1703     public void TestReset() {\r
1704         StringCharacterIterator text = new StringCharacterIterator("fish fish");\r
1705         String pattern = "s";\r
1706 \r
1707         StringSearch  strsrch = new StringSearch(pattern, text, m_en_us_, null);\r
1708         strsrch.setOverlapping(true);\r
1709         strsrch.setCanonical(true);\r
1710         strsrch.setIndex(9);\r
1711         strsrch.reset();\r
1712         if (strsrch.isCanonical() || strsrch.isOverlapping() ||\r
1713             strsrch.getIndex() != 0 || strsrch.getMatchLength() != 0 ||\r
1714             strsrch.getMatchStart() != SearchIterator.DONE) {\r
1715                 errln("Error resetting string search");\r
1716         }\r
1717 \r
1718         strsrch.previous();\r
1719         if (strsrch.getMatchStart() != 7 || strsrch.getMatchLength() != 1) {\r
1720             errln("Error resetting string search\n");\r
1721         }\r
1722     }\r
1723 \r
1724     public void TestSetMatch() {\r
1725         int count = 0;\r
1726         while (MATCH[count].text != null) {\r
1727             SearchData     search = MATCH[count];\r
1728             StringSearch strsrch = new StringSearch(search.pattern, new StringCharacterIterator(search.text),\r
1729                                                     m_en_us_, null);\r
1730 \r
1731             int size = 0;\r
1732             while (search.offset[size] != -1) {\r
1733                 size ++;\r
1734             }\r
1735 \r
1736             if (strsrch.first() != search.offset[0]) {\r
1737                 errln("Error getting first match");\r
1738             }\r
1739             if (strsrch.last() != search.offset[size -1]) {\r
1740                 errln("Error getting last match");\r
1741             }\r
1742 \r
1743             int index = 0;\r
1744             while (index < size) {\r
1745                 if (index + 2 < size) {\r
1746                     if (strsrch.following(search.offset[index + 2] - 1) != search.offset[index + 2]) {\r
1747                         errln("Error getting following match at index " + (search.offset[index + 2]-1));\r
1748                     }\r
1749                 }\r
1750                 if (index + 1 < size) {\r
1751                     if (strsrch.preceding(search.offset[index + 1] + search.size[index + 1] + 1) != search.offset[index + 1]) {\r
1752                         errln("Error getting preceeding match at index " + (search.offset[index + 1] + 1));\r
1753                     }\r
1754                 }\r
1755                 index += 2;\r
1756             }\r
1757 \r
1758             if (strsrch.following(search.text.length()) != SearchIterator.DONE) {\r
1759                 errln("Error expecting out of bounds match");\r
1760             }\r
1761             if (strsrch.preceding(0) != SearchIterator.DONE) {\r
1762                 errln("Error expecting out of bounds match");\r
1763             }\r
1764             count ++;\r
1765             strsrch = null;\r
1766         }\r
1767     }\r
1768 \r
1769     public void TestStrength() {\r
1770         int count = 0;\r
1771         while (STRENGTH[count].text != null) {\r
1772             if (count == 3) count ++;\r
1773             if (!assertEqual(STRENGTH[count])) {\r
1774                 errln("Error at test number " + count);\r
1775             }\r
1776             count ++;\r
1777         }\r
1778     }\r
1779 \r
1780     public void TestStrengthCanonical() {\r
1781         int count = 0;\r
1782         while (STRENGTHCANONICAL[count].text != null) {\r
1783             if (count == 3) count ++;\r
1784             if (!assertCanonicalEqual(STRENGTHCANONICAL[count])) {\r
1785                 errln("Error at test number" + count);\r
1786             }\r
1787             count ++;\r
1788         }\r
1789     }\r
1790 \r
1791     public void TestSupplementary() {\r
1792         int count = 0;\r
1793         while (SUPPLEMENTARY[count].text != null) {\r
1794             if (!assertEqual(SUPPLEMENTARY[count])) {\r
1795                 errln("Error at test number " + count);\r
1796             }\r
1797             count ++;\r
1798         }\r
1799     }\r
1800 \r
1801     public void TestSupplementaryCanonical() {\r
1802         int count = 0;\r
1803         while (SUPPLEMENTARYCANONICAL[count].text != null) {\r
1804             if (!assertCanonicalEqual(SUPPLEMENTARYCANONICAL[count])) {\r
1805                 errln("Error at test number" + count);\r
1806             }\r
1807             count ++;\r
1808         }\r
1809     }\r
1810 \r
1811     public void TestText() {\r
1812         SearchData TEXT[] = {\r
1813             new SearchData("the foxy brown fox", "fox", null, Collator.TERTIARY, null, new int[] {4, 15, -1}, new int[] {3, 3}),\r
1814             new SearchData("the quick brown fox", "fox", null, Collator.TERTIARY, null, new int[] {16, -1}, new int[] {3}),\r
1815             new SearchData(null, null, null, Collator.TERTIARY, null, new int[] {-1}, new int[]{0})\r
1816         };\r
1817         StringCharacterIterator t = new StringCharacterIterator(TEXT[0].text);\r
1818         StringSearch strsrch = new StringSearch(TEXT[0].pattern, t, m_en_us_, null);\r
1819 \r
1820         if (!t.equals(strsrch.getTarget())) {\r
1821             errln("Error setting text");\r
1822         }\r
1823         if (!assertEqualWithStringSearch(strsrch, TEXT[0])) {\r
1824             errln("Error at assertEqualWithStringSearch");\r
1825             return;\r
1826         }\r
1827 \r
1828         t = new StringCharacterIterator(TEXT[1].text);\r
1829         strsrch.setTarget(t);\r
1830         if (!t.equals(strsrch.getTarget())) {\r
1831             errln("Error setting text");\r
1832             return;\r
1833         }\r
1834 \r
1835         if (!assertEqualWithStringSearch(strsrch, TEXT[1])) {\r
1836             errln("Error at assertEqualWithStringSearch");\r
1837             return;\r
1838         }\r
1839     }\r
1840 \r
1841     public void TestTextCanonical() {\r
1842         StringCharacterIterator t = new StringCharacterIterator(TEXTCANONICAL[0].text);\r
1843         StringSearch strsrch = new StringSearch(TEXTCANONICAL[0].pattern, t, m_en_us_, null);\r
1844         strsrch.setCanonical(true);\r
1845 \r
1846         if (!t.equals(strsrch.getTarget())) {\r
1847             errln("Error setting text");\r
1848         }\r
1849         if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[0])) {\r
1850             strsrch = null;\r
1851             return;\r
1852         }\r
1853 \r
1854         t = new StringCharacterIterator(TEXTCANONICAL[1].text);\r
1855         strsrch.setTarget(t);\r
1856         if (!t.equals(strsrch.getTarget())) {\r
1857             errln("Error setting text");\r
1858             strsrch = null;\r
1859             return;\r
1860         }\r
1861 \r
1862         if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[1])) {\r
1863             strsrch = null;\r
1864             return;\r
1865         }\r
1866 \r
1867         t = new StringCharacterIterator(TEXTCANONICAL[0].text);\r
1868         strsrch.setTarget(t);\r
1869         if (!t.equals(strsrch.getTarget())) {\r
1870             errln("Error setting text");\r
1871             strsrch = null;\r
1872             return;\r
1873         }\r
1874 \r
1875         if (!assertEqualWithStringSearch(strsrch, TEXTCANONICAL[0])) {\r
1876             errln("Error at assertEqualWithStringSearch");\r
1877             strsrch = null;\r
1878             return;\r
1879         }\r
1880     }\r
1881 \r
1882     public void TestVariable() {\r
1883         int count = 0;\r
1884         m_en_us_.setAlternateHandlingShifted(true);\r
1885         while (VARIABLE[count].text != null) {\r
1886             // logln("variable" + count);\r
1887             if (!assertEqual(VARIABLE[count])) {\r
1888                 errln("Error at test number " + count);\r
1889             }\r
1890             count ++;\r
1891         }\r
1892         m_en_us_.setAlternateHandlingShifted(false);\r
1893     }\r
1894 \r
1895     public void TestVariableCanonical() {\r
1896         int count = 0;\r
1897         m_en_us_.setAlternateHandlingShifted(true);\r
1898         while (VARIABLE[count].text != null) {\r
1899             // logln("variable " + count);\r
1900             if (!assertCanonicalEqual(VARIABLE[count])) {\r
1901                 errln("Error at test number " + count);\r
1902             }\r
1903             count ++;\r
1904         }\r
1905         m_en_us_.setAlternateHandlingShifted(false);\r
1906     }\r
1907 \r
1908     public void TestSubClass()\r
1909     {\r
1910         class TestSearch extends SearchIterator\r
1911         {\r
1912             String pattern;\r
1913             String text;\r
1914 \r
1915             TestSearch(StringCharacterIterator target, BreakIterator breaker,\r
1916                        String pattern)\r
1917             {\r
1918                 super(target, breaker);\r
1919                 this.pattern = pattern;\r
1920                 StringBuffer buffer = new StringBuffer();\r
1921                 while (targetText.getIndex() != targetText.getEndIndex()) {\r
1922                     buffer.append(targetText.current());\r
1923                     targetText.next();\r
1924                 }\r
1925                 text = buffer.toString();\r
1926                 targetText.setIndex(targetText.getBeginIndex());\r
1927             }\r
1928             protected int handleNext(int start)\r
1929             {\r
1930                 int match = text.indexOf(pattern, start);\r
1931                 if (match < 0) {\r
1932                     targetText.last();\r
1933                     return DONE;\r
1934                 }\r
1935                 targetText.setIndex(match);\r
1936                 setMatchLength(pattern.length());\r
1937                 return match;\r
1938             }\r
1939             protected int handlePrevious(int start)\r
1940             {\r
1941                 int match = text.lastIndexOf(pattern, start - 1);\r
1942                 if (match < 0) {\r
1943                     targetText.setIndex(0);\r
1944                     return DONE;\r
1945                 }\r
1946                 targetText.setIndex(match);\r
1947                 setMatchLength(pattern.length());\r
1948                 return match;\r
1949             }\r
1950 \r
1951             public int getIndex()\r
1952             {\r
1953                 int result = targetText.getIndex();\r
1954                 if (result < 0 || result >= text.length()) {\r
1955                     return DONE;\r
1956                 }\r
1957                 return result;\r
1958             }\r
1959         }\r
1960 \r
1961         TestSearch search = new TestSearch(\r
1962                             new StringCharacterIterator("abc abcd abc"),\r
1963                             null, "abc");\r
1964         int expected[] = {0, 4, 9};\r
1965         for (int i = 0; i < expected.length; i ++) {\r
1966             if (search.next() != expected[i]) {\r
1967                 errln("Error getting next match");\r
1968             }\r
1969             if (search.getMatchLength() != search.pattern.length()) {\r
1970                 errln("Error getting next match length");\r
1971             }\r
1972         }\r
1973         if (search.next() != SearchIterator.DONE) {\r
1974             errln("Error should have reached the end of the iteration");\r
1975         }\r
1976         for (int i = expected.length - 1; i >= 0; i --) {\r
1977             if (search.previous() != expected[i]) {\r
1978                 errln("Error getting next match");\r
1979             }\r
1980             if (search.getMatchLength() != search.pattern.length()) {\r
1981                 errln("Error getting next match length");\r
1982             }\r
1983         }\r
1984         if (search.previous() != SearchIterator.DONE) {\r
1985             errln("Error should have reached the start of the iteration");\r
1986         }\r
1987     }\r
1988     \r
1989     //Test for ticket 5024\r
1990     public void TestDiactricMatch() {\r
1991         String pattern = "pattern";\r
1992         String text = "text";\r
1993         StringSearch strsrch = null;\r
1994         int count = 0;\r
1995         try {\r
1996             strsrch = new StringSearch(pattern, text);\r
1997         } catch (Exception e) {\r
1998             errln("Error opening string search ");\r
1999             return;\r
2000         }\r
2001 \r
2002         while (DIACTRICMATCH[count].text != null) {\r
2003             strsrch.setCollator(getCollator(DIACTRICMATCH[count].collator));\r
2004             strsrch.getCollator().setStrength(DIACTRICMATCH[count].strength);\r
2005             strsrch.setBreakIterator(getBreakIterator(DIACTRICMATCH[count].breaker));\r
2006             strsrch.reset();\r
2007             text = DIACTRICMATCH[count].text;\r
2008             pattern = DIACTRICMATCH[count].pattern;\r
2009             strsrch.setTarget(new StringCharacterIterator(text));\r
2010             strsrch.setPattern(pattern);\r
2011             if (!assertEqualWithStringSearch(strsrch, DIACTRICMATCH[count])) {\r
2012                 errln("Error at test number " + count);\r
2013             }\r
2014             count++;\r
2015         }\r
2016     }\r
2017 }