2 *******************************************************************************
\r
3 * Copyright (C) 1999-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.dev.test.lang;
\r
10 import com.ibm.icu.dev.test.TestFmwk;
\r
11 import com.ibm.icu.lang.UScript;
\r
12 import com.ibm.icu.lang.UScriptRun;
\r
14 public class TestUScriptRun extends TestFmwk
\r
16 public TestUScriptRun()
\r
21 public static void main(String[] args) throws Exception {
\r
22 new TestUScriptRun().run(args);
\r
25 private static final class RunTestData
\r
30 public RunTestData(String theText, int theScriptCode)
\r
33 runScript = theScriptCode;
\r
37 private static final RunTestData[][] m_testData = {
\r
39 new RunTestData("\u0020\u0946\u0939\u093F\u0928\u094D\u0926\u0940\u0020", UScript.DEVANAGARI),
\r
40 new RunTestData("\u0627\u0644\u0639\u0631\u0628\u064A\u0629\u0020", UScript.ARABIC),
\r
41 new RunTestData("\u0420\u0443\u0441\u0441\u043A\u0438\u0439\u0020", UScript.CYRILLIC),
\r
42 new RunTestData("English (", UScript.LATIN),
\r
43 new RunTestData("\u0E44\u0E17\u0E22", UScript.THAI),
\r
44 new RunTestData(") ", UScript.LATIN),
\r
45 new RunTestData("\u6F22\u5B75", UScript.HAN),
\r
46 new RunTestData("\u3068\u3072\u3089\u304C\u306A\u3068", UScript.HIRAGANA),
\r
47 new RunTestData("\u30AB\u30BF\u30AB\u30CA", UScript.KATAKANA),
\r
48 new RunTestData("\uD801\uDC00\uD801\uDC01\uD801\uDC02\uD801\uDC03", UScript.DESERET),
\r
51 new RunTestData("((((((((((abc))))))))))", UScript.LATIN)
\r
55 private static final String padding = "This string is used for padding...";
\r
57 private void CheckScriptRuns(UScriptRun scriptRun, int[] runStarts, RunTestData[] testData)
\r
59 int run, runStart, runLimit;
\r
62 /* iterate over all the runs */
\r
64 while (scriptRun.next()) {
\r
65 runStart = scriptRun.getScriptStart();
\r
66 runLimit = scriptRun.getScriptLimit();
\r
67 runScript = scriptRun.getScriptCode();
\r
69 if (runStart != runStarts[run]) {
\r
70 errln("Incorrect start offset for run " + run + ": expected " + runStarts[run] + ", got " + runStart);
\r
73 if (runLimit != runStarts[run + 1]) {
\r
74 errln("Incorrect limit offset for run " + run + ": expected " + runStarts[run + 1] + ", got " + runLimit);
\r
77 if (runScript != testData[run].runScript) {
\r
78 errln("Incorrect script for run " + run + ": expected \"" + UScript.getName(testData[run].runScript) + "\", got \"" + UScript.getName(runScript) + "\"");
\r
83 /* stop when we've seen all the runs we expect to see */
\r
84 if (run >= testData.length) {
\r
89 /* Complain if we didn't see then number of runs we expected */
\r
90 if (run != testData.length) {
\r
91 errln("Incorrect number of runs: expected " + testData.length + ", got " + run);
\r
95 public void TestContstruction()
\r
97 UScriptRun scriptRun = null;
\r
98 char[] nullChars = null, dummyChars = {'d', 'u', 'm', 'm', 'y'};
\r
99 String nullString = null, dummyString = new String(dummyChars);
\r
102 scriptRun = new UScriptRun(nullString, 0, 100);
\r
103 errln("new UScriptRun(nullString, 0, 100) did not produce an IllegalArgumentException!");
\r
104 } catch (IllegalArgumentException iae) {
\r
105 logln("PASS: UScriptRun failed as expected");
\r
109 scriptRun = new UScriptRun(nullString, 100, 0);
\r
110 errln("new UScriptRun(nullString, 100, 0) did not produce an IllegalArgumentException!");
\r
111 } catch (IllegalArgumentException iae) {
\r
112 logln("PASS: UScriptRun failed as expected");
\r
116 scriptRun = new UScriptRun(nullString, 0, -100);
\r
117 errln("new UScriptRun(nullString, 0, -100) did not produce an IllegalArgumentException!");
\r
118 } catch (IllegalArgumentException iae) {
\r
119 logln("PASS: UScriptRun failed as expected");
\r
123 scriptRun = new UScriptRun(nullString, -100, 0);
\r
124 errln("new UScriptRun(nullString, -100, 0) did not produce an IllegalArgumentException!");
\r
125 } catch (IllegalArgumentException iae) {
\r
126 logln("PASS: UScriptRun failed as expected");
\r
130 scriptRun = new UScriptRun(nullChars, 0, 100);
\r
131 errln("new UScriptRun(nullChars, 0, 100) did not produce an IllegalArgumentException!");
\r
132 } catch (IllegalArgumentException iae) {
\r
133 logln("PASS: UScriptRun failed as expected");
\r
137 scriptRun = new UScriptRun(nullChars, 100, 0);
\r
138 errln("new UScriptRun(nullChars, 100, 0) did not produce an IllegalArgumentException!");
\r
139 } catch (IllegalArgumentException iae) {
\r
140 logln("PASS: UScriptRun failed as expected");
\r
144 scriptRun = new UScriptRun(nullChars, 0, -100);
\r
145 errln("new UScriptRun(nullChars, 0, -100) did not produce an IllegalArgumentException!");
\r
146 } catch (IllegalArgumentException iae) {
\r
147 logln("PASS: UScriptRun failed as expected");
\r
151 scriptRun = new UScriptRun(nullChars, -100, 0);
\r
152 errln("new UScriptRun(nullChars, -100, 0) did not produce an IllegalArgumentException!");
\r
153 } catch (IllegalArgumentException iae) {
\r
154 logln("PASS: UScriptRun failed as expected");
\r
158 scriptRun = new UScriptRun(dummyString, 0, 6);
\r
159 errln("new UScriptRun(dummyString, 0, 6) did not produce an IllegalArgumentException!");
\r
160 } catch (IllegalArgumentException iae) {
\r
161 logln("PASS: UScriptRun failed as expected");
\r
165 scriptRun = new UScriptRun(dummyString, 6, 0);
\r
166 errln("new UScriptRun(dummy, 6, 0) did not produce an IllegalArgumentException!");
\r
167 }catch (IllegalArgumentException iae) {
\r
168 logln("PASS: UScriptRun failed as expected");
\r
172 scriptRun = new UScriptRun(dummyString, 0, -100);
\r
173 errln("new UScriptRun(dummyString, 0, -100) did not produce an IllegalArgumentException!");
\r
174 } catch (IllegalArgumentException iae) {
\r
175 logln("PASS: UScriptRun failed as expected");
\r
179 scriptRun = new UScriptRun(dummyString, -100, 0);
\r
180 errln("new UScriptRun(dummy, -100, 0) did not produce an IllegalArgumentException!");
\r
181 } catch (IllegalArgumentException iae) {
\r
182 logln("PASS: UScriptRun failed as expected");
\r
186 scriptRun = new UScriptRun(dummyChars, 0, 6);
\r
187 errln("new UScriptRun(dummyChars, 0, 6) did not produce an IllegalArgumentException!");
\r
188 } catch (IllegalArgumentException iae) {
\r
189 logln("PASS: UScriptRun failed as expected");
\r
193 scriptRun = new UScriptRun(dummyChars, 6, 0);
\r
194 errln("new UScriptRun(dummyChars, 6, 0) did not produce an IllegalArgumentException!");
\r
195 }catch (IllegalArgumentException iae) {
\r
196 logln("PASS: UScriptRun failed as expected");
\r
200 scriptRun = new UScriptRun(dummyChars, 0, -100);
\r
201 errln("new UScriptRun(dummyChars, 0, -100) did not produce an IllegalArgumentException!");
\r
202 } catch (IllegalArgumentException iae) {
\r
203 logln("PASS: UScriptRun failed as expected");
\r
207 scriptRun = new UScriptRun(dummyChars, -100, 0);
\r
208 errln("new UScriptRun(dummy, -100, 0) did not produce an IllegalArgumentException!");
\r
209 } catch (IllegalArgumentException iae) {
\r
210 logln("PASS: UScriptRun failed as expected");
\r
212 if(scriptRun!=null){
\r
213 errln("Did not get the expected Exception");
\r
217 public void TestReset()
\r
219 UScriptRun scriptRun = null;
\r
220 char[] dummy = {'d', 'u', 'm', 'm', 'y'};
\r
223 scriptRun = new UScriptRun();
\r
224 } catch (IllegalArgumentException iae) {
\r
225 errln("new UScriptRun() produced an IllegalArgumentException!");
\r
229 scriptRun.reset(0, 100);
\r
230 errln("scriptRun.reset(0, 100) did not produce an IllegalArgumentException!");
\r
231 } catch (IllegalArgumentException iae) {
\r
232 logln("PASS: scriptRun.reset failed as expected");
\r
236 scriptRun.reset(100, 0);
\r
237 errln("scriptRun.reset(100, 0) did not produce an IllegalArgumentException!");
\r
238 } catch (IllegalArgumentException iae) {
\r
239 logln("PASS: scriptRun.reset failed as expected");
\r
243 scriptRun.reset(0, -100);
\r
244 errln("scriptRun.reset(0, -100) did not produce an IllegalArgumentException!");
\r
245 } catch (IllegalArgumentException iae) {
\r
246 logln("PASS: scriptRun.reset failed as expected");
\r
250 scriptRun.reset(-100, 0);
\r
251 errln("scriptRun.reset(-100, 0) did not produce an IllegalArgumentException!");
\r
252 } catch (IllegalArgumentException iae) {
\r
253 logln("PASS: scriptRun.reset failed as expected");
\r
257 scriptRun.reset(dummy, 0, 6);
\r
258 errln("scriptRun.reset(dummy, 0, 6) did not produce an IllegalArgumentException!");
\r
259 } catch (IllegalArgumentException iae) {
\r
260 logln("PASS: scriptRun.reset failed as expected");
\r
264 scriptRun.reset(dummy, 6, 0);
\r
265 errln("scriptRun.reset(dummy, 6, 0) did not produce an IllegalArgumentException!");
\r
266 }catch (IllegalArgumentException iae) {
\r
267 logln("PASS: scriptRun.reset failed as expected");
\r
271 scriptRun.reset(dummy, 0, -100);
\r
272 errln("scriptRun.reset(dummy, 0, -100) did not produce an IllegalArgumentException!");
\r
273 } catch (IllegalArgumentException iae) {
\r
274 logln("PASS: scriptRun.reset failed as expected");
\r
278 scriptRun.reset(dummy, -100, 0);
\r
279 errln("scriptRun.reset(dummy, -100, 0) did not produce an IllegalArgumentException!");
\r
280 } catch (IllegalArgumentException iae) {
\r
281 logln("PASS: scriptRun.reset failed as expected");
\r
285 scriptRun.reset(dummy, 0, dummy.length);
\r
286 } catch (IllegalArgumentException iae) {
\r
287 errln("scriptRun.reset(dummy, 0, dummy.length) produced an IllegalArgumentException!");
\r
292 scriptRun.reset(0, 6);
\r
293 errln("scriptRun.reset(0, 6) did not produce an IllegalArgumentException!");
\r
294 } catch (IllegalArgumentException iae) {
\r
295 logln("PASS: scriptRun.reset failed as expected");
\r
299 scriptRun.reset(6, 0);
\r
300 errln("scriptRun.reset(6, 0) did not produce an IllegalArgumentException!");
\r
301 } catch (IllegalArgumentException iae) {
\r
302 logln("PASS: scriptRun.reset failed as expected");
\r
306 scriptRun.reset(dummy, 0, dummy.length);
\r
308 } catch(IllegalArgumentException iae){
\r
309 errln("scriptRun.reset() produced an IllegalArgumentException!");
\r
313 scriptRun.reset((char[]) null);
\r
314 } catch(IllegalArgumentException iae){
\r
315 errln("scriptRun.reset((char[])null) produced an IllegalArgumentException!");
\r
319 scriptRun.reset((String) null);
\r
320 } catch(IllegalArgumentException iae){
\r
321 errln("scriptRun.reset((String)null) produced an IllegalArgumentException!");
\r
325 public void TestRuns()
\r
327 for (int i = 0; i < m_testData.length; i += 1) {
\r
328 RunTestData[] test = m_testData[i];
\r
329 int stringLimit = 0;
\r
330 int[] runStarts = new int[test.length + 1];
\r
331 String testString = "";
\r
332 UScriptRun scriptRun = null;
\r
335 * Fill in the test string and the runStarts array.
\r
337 for (int run = 0; run < test.length; run += 1) {
\r
338 runStarts[run] = stringLimit;
\r
339 stringLimit += test[run].runText.length();
\r
340 testString += test[run].runText;
\r
343 /* The limit of the last run */
\r
344 runStarts[test.length] = stringLimit;
\r
347 scriptRun = new UScriptRun(testString);
\r
348 CheckScriptRuns(scriptRun, runStarts, test);
\r
349 } catch (IllegalArgumentException iae) {
\r
350 errln("new UScriptRun(testString) produced an IllegalArgumentException!");
\r
355 CheckScriptRuns(scriptRun, runStarts, test);
\r
356 } catch (IllegalArgumentException iae) {
\r
357 errln("scriptRun.reset() on a valid UScriptRun produced an IllegalArgumentException!");
\r
361 scriptRun = new UScriptRun(testString.toCharArray());
\r
362 CheckScriptRuns(scriptRun, runStarts, test);
\r
363 } catch (IllegalArgumentException iae) {
\r
364 errln("new UScriptRun(testString.toCharArray()) produced an IllegalArgumentException!");
\r
369 CheckScriptRuns(scriptRun, runStarts, test);
\r
370 } catch (IllegalArgumentException iae) {
\r
371 errln("scriptRun.reset() on a valid UScriptRun produced an IllegalArgumentException!");
\r
375 scriptRun = new UScriptRun();
\r
377 if (scriptRun.next()) {
\r
378 errln("scriptRun.next() on an empty UScriptRun returned true!");
\r
380 } catch (IllegalArgumentException iae) {
\r
381 errln("new UScriptRun() produced an IllegalArgumentException!");
\r
385 scriptRun.reset(testString, 0, testString.length());
\r
386 CheckScriptRuns(scriptRun, runStarts, test);
\r
387 } catch (IllegalArgumentException iae) {
\r
388 errln("scriptRun.reset(testString, 0, testString.length) produced an IllegalArgumentException!");
\r
392 scriptRun.reset(testString.toCharArray(), 0, testString.length());
\r
393 CheckScriptRuns(scriptRun, runStarts, test);
\r
394 } catch (IllegalArgumentException iae) {
\r
395 errln("scriptRun.reset(testString.toCharArray(), 0, testString.length) produced an IllegalArgumentException!");
\r
398 String paddedTestString = padding + testString + padding;
\r
399 int startOffset = padding.length();
\r
400 int count = testString.length();
\r
402 for (int run = 0; run < runStarts.length; run += 1) {
\r
403 runStarts[run] += startOffset;
\r
407 scriptRun.reset(paddedTestString, startOffset, count);
\r
408 CheckScriptRuns(scriptRun, runStarts, test);
\r
409 } catch (IllegalArgumentException iae) {
\r
410 errln("scriptRun.reset(paddedTestString, startOffset, count) produced an IllegalArgumentException!");
\r
414 scriptRun.reset(paddedTestString.toCharArray(), startOffset, count);
\r
415 CheckScriptRuns(scriptRun, runStarts, test);
\r
416 } catch (IllegalArgumentException iae) {
\r
417 errln("scriptRun.reset(paddedTestString.toCharArray(), startOffset, count) produced an IllegalArgumentException!");
\r
420 /* Tests "public final void reset()" */
\r
421 // Tests when "while (stackIsNotEmpty())" is true
\r
423 UScriptRun usr = new UScriptRun((String)null);
\r
425 } catch (Exception e){
\r
426 errln("scriptRun.reset() was not suppose to produce an exception.");
\r