Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Bidi/BidiConformance.java
41149 views
1
/*
2
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6850113 8032446 8255242
27
* @summary confirm the behavior of new Bidi implementation. (Backward compatibility)
28
* @modules java.desktop
29
*/
30
31
import java.awt.font.NumericShaper;
32
import java.awt.font.TextAttribute;
33
import java.text.AttributedString;
34
import java.text.Bidi;
35
import java.util.Arrays;
36
37
public class BidiConformance {
38
39
/* internal flags */
40
private static boolean error = false;
41
private static boolean verbose = false;
42
private static boolean abort = false;
43
44
private static final byte MAX_EXPLICIT_LEVEL = 125;
45
46
public static void main(String[] args) {
47
for (int i = 0; i < args.length; i++) {
48
String arg = args[i];
49
if (arg.equals("-verbose")) {
50
verbose = true;
51
} else if (arg.equals("-abort")) {
52
abort = true;
53
}
54
}
55
56
BidiConformance bc = new BidiConformance();
57
bc.test();
58
59
if (error) {
60
throw new RuntimeException("Failed.");
61
} else {
62
System.out.println("Passed.");
63
}
64
}
65
66
private void test() {
67
testConstants();
68
testConstructors();
69
testMethods();
70
71
testMethods4Constructor1(); // Bidi(AttributedCharacterIterator)
72
testMethods4Constructor2(); // Bidi(String, int)
73
testMethods4Constructor3(); // Bidi(char[], ...)
74
}
75
76
private void testConstants() {
77
System.out.println("*** Test constants");
78
79
checkResult("Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT",
80
-2, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
81
checkResult("Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT",
82
-1, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
83
checkResult("Bidi.DIRECTION_LEFT_TO_RIGHT",
84
0, Bidi.DIRECTION_LEFT_TO_RIGHT);
85
checkResult("Bidi.DIRECTION_RIGHT_TO_LEFT",
86
1, Bidi.DIRECTION_RIGHT_TO_LEFT);
87
}
88
89
private void testConstructors() {
90
System.out.println("*** Test constructors");
91
92
testConstructor1(); // Bidi(AttributedCharacterIterator)
93
testConstructor2(); // Bidi(String, int)
94
testConstructor3(); // Bidi(char[], ...)
95
}
96
97
private void testMethods() {
98
System.out.println("*** Test methods");
99
100
testMethod_createLineBidi1();
101
testMethod_createLineBidi2();
102
testMethod_getLevelAt();
103
testMethod_getRunLevel();
104
testMethod_getRunLimit();
105
testMethod_getRunStart();
106
testMethod_reorderVisually1();
107
testMethod_reorderVisually2();
108
testMethod_requiresBidi();
109
}
110
111
private void testMethods4Constructor1() {
112
System.out.println("*** Test methods for constructor 1");
113
114
String paragraph;
115
Bidi bidi;
116
NumericShaper ns = NumericShaper.getShaper(NumericShaper.ARABIC);
117
118
for (int textNo = 0; textNo < data4Constructor1.length; textNo++) {
119
paragraph = data4Constructor1[textNo][0];
120
int start = paragraph.indexOf('<')+1;
121
int limit = paragraph.indexOf('>');
122
int testNo;
123
124
System.out.println("*** Test textNo=" + textNo +
125
": Bidi(AttributedCharacterIterator\"" +
126
toReadableString(paragraph) + "\") " +
127
" start=" + start + ", limit=" + limit);
128
129
// Test 0
130
testNo = 0;
131
System.out.println(" Test#" + testNo +": RUN_DIRECTION_LTR");
132
AttributedString astr = new AttributedString(paragraph);
133
astr.addAttribute(TextAttribute.RUN_DIRECTION,
134
TextAttribute.RUN_DIRECTION_LTR);
135
bidi = new Bidi(astr.getIterator());
136
137
callTestEachMethod4Constructor1(textNo, testNo, bidi);
138
139
// Test 1
140
++testNo;
141
System.out.println(" Test#" + testNo +
142
": RUN_DIRECTION_LTR, BIDI_EMBEDDING(1)");
143
astr = new AttributedString(paragraph);
144
astr.addAttribute(TextAttribute.RUN_DIRECTION,
145
TextAttribute.RUN_DIRECTION_LTR);
146
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),
147
start, limit);
148
bidi = new Bidi(astr.getIterator());
149
callTestEachMethod4Constructor1(textNo, testNo, bidi);
150
151
// Test 2
152
++testNo;
153
System.out.println(" Test#" + testNo +
154
": RUN_DIERCTION_LTR, BIDI_EMBEDDING(2)");
155
astr = new AttributedString(paragraph);
156
astr.addAttribute(TextAttribute.RUN_DIRECTION,
157
TextAttribute.RUN_DIRECTION_LTR);
158
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),
159
start, limit);
160
bidi = new Bidi(astr.getIterator());
161
callTestEachMethod4Constructor1(textNo, testNo, bidi);
162
163
// Test 3
164
++testNo;
165
System.out.println(" Test#" + testNo +
166
": RUN_DIRECTIOIN_LTR, BIDI_EMBEDDING(-3)");
167
astr = new AttributedString(paragraph);
168
astr.addAttribute(TextAttribute.RUN_DIRECTION,
169
TextAttribute.RUN_DIRECTION_LTR);
170
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),
171
start, limit);
172
bidi = new Bidi(astr.getIterator());
173
callTestEachMethod4Constructor1(textNo, testNo, bidi);
174
175
// Test 4
176
++testNo;
177
System.out.println(" Test#" + testNo +
178
": RUN_DIRECTION_LTR, BIDI_EMBEDDING(-4)");
179
astr = new AttributedString(paragraph);
180
astr.addAttribute(TextAttribute.RUN_DIRECTION,
181
TextAttribute.RUN_DIRECTION_LTR);
182
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),
183
start, limit);
184
bidi = new Bidi(astr.getIterator());
185
callTestEachMethod4Constructor1(textNo, testNo, bidi);
186
187
// Test 5
188
++testNo;
189
System.out.println(" Test#" + testNo + ": RUN_DIRECTION_RTL");
190
astr = new AttributedString(paragraph);
191
astr.addAttribute(TextAttribute.RUN_DIRECTION,
192
TextAttribute.RUN_DIRECTION_RTL);
193
bidi = new Bidi(astr.getIterator());
194
callTestEachMethod4Constructor1(textNo, testNo, bidi);
195
196
// Test 6
197
++testNo;
198
System.out.println(" Test#" + testNo +
199
": RUN_DIRECTION_RTL, BIDI_EMBEDDING(1)");
200
astr = new AttributedString(paragraph);
201
astr.addAttribute(TextAttribute.RUN_DIRECTION,
202
TextAttribute.RUN_DIRECTION_RTL);
203
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(1),
204
start, limit);
205
try {
206
bidi = new Bidi(astr.getIterator());
207
callTestEachMethod4Constructor1(textNo, testNo, bidi);
208
}
209
catch (IllegalArgumentException e) {
210
errorHandling(" Unexpected exception: " + e);
211
}
212
213
// Test 7
214
++testNo;
215
System.out.println(" Test#" + testNo +
216
": RUN_DIRECTION_RTL, BIDI_EMBEDDING(2)");
217
astr = new AttributedString(paragraph);
218
astr.addAttribute(TextAttribute.RUN_DIRECTION,
219
TextAttribute.RUN_DIRECTION_RTL);
220
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(2),
221
start, limit);
222
try {
223
bidi = new Bidi(astr.getIterator());
224
callTestEachMethod4Constructor1(textNo, testNo, bidi);
225
}
226
catch (IllegalArgumentException e) {
227
errorHandling(" Unexpected exception: " + e);
228
}
229
230
// Test 8
231
++testNo;
232
System.out.println(" Test#" + testNo +
233
": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-3)");
234
astr = new AttributedString(paragraph);
235
astr.addAttribute(TextAttribute.RUN_DIRECTION,
236
TextAttribute.RUN_DIRECTION_RTL);
237
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-3),
238
start, limit);
239
try {
240
bidi = new Bidi(astr.getIterator());
241
callTestEachMethod4Constructor1(textNo, testNo, bidi);
242
}
243
catch (IllegalArgumentException e) {
244
errorHandling(" Unexpected exception: " + e);
245
}
246
247
// Test 9
248
++testNo;
249
System.out.println(" Test#" + testNo +
250
": RUN_DIRECTION_RTL, BIDI_EMBEDDING(-4)");
251
astr = new AttributedString(paragraph);
252
astr.addAttribute(TextAttribute.RUN_DIRECTION,
253
TextAttribute.RUN_DIRECTION_RTL);
254
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-4),
255
start, limit);
256
try {
257
bidi = new Bidi(astr.getIterator());
258
callTestEachMethod4Constructor1(textNo, testNo, bidi);
259
}
260
catch (IllegalArgumentException e) {
261
errorHandling(" Unexpected exception: " + e);
262
}
263
264
// Test 10
265
++testNo;
266
System.out.println(" Test#" + testNo +
267
": TextAttribute not specified");
268
astr = new AttributedString(paragraph);
269
bidi = new Bidi(astr.getIterator());
270
callTestEachMethod4Constructor1(textNo, testNo, bidi);
271
272
// Test 11
273
++testNo;
274
System.out.println(" Test#" + testNo +
275
": RUN_DIRECTION_LTR, NUMERIC_SHAPING(ARABIC)");
276
astr = new AttributedString(paragraph);
277
astr.addAttribute(TextAttribute.RUN_DIRECTION,
278
TextAttribute.RUN_DIRECTION_LTR);
279
astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
280
bidi = new Bidi(astr.getIterator());
281
callTestEachMethod4Constructor1(textNo, testNo, bidi);
282
283
// Test 12
284
++testNo;
285
System.out.println(" Test#" + testNo +
286
": RUN_DIRECTION_RTL, NUMERIC_SHAPING(ARABIC)");
287
astr = new AttributedString(paragraph);
288
astr.addAttribute(TextAttribute.RUN_DIRECTION,
289
TextAttribute.RUN_DIRECTION_RTL);
290
astr.addAttribute(TextAttribute.NUMERIC_SHAPING, ns);
291
bidi = new Bidi(astr.getIterator());
292
callTestEachMethod4Constructor1(textNo, testNo, bidi);
293
}
294
}
295
296
private void testMethods4Constructor2() {
297
System.out.println("*** Test methods for constructor 2");
298
299
String paragraph;
300
Bidi bidi;
301
302
for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {
303
paragraph = data4Constructor2[textNo][0];
304
for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {
305
int flag = FLAGS[flagNo];
306
307
System.out.println("*** Test textNo=" + textNo +
308
": Bidi(\"" + toReadableString(paragraph) +
309
"\", " + getFlagName(flag) + ")");
310
311
bidi = new Bidi(paragraph, flag);
312
callTestEachMethod4Constructor2(textNo, flagNo, bidi);
313
}
314
}
315
}
316
317
private void testMethods4Constructor3() {
318
System.out.println("*** Test methods for constructor 3");
319
320
String paragraph;
321
Bidi bidi;
322
323
for (int textNo = 0; textNo < data4Constructor3.length; textNo++) {
324
paragraph = data4Constructor3[textNo][0];
325
char[] c = paragraph.toCharArray();
326
int start = paragraph.indexOf('<')+1;
327
byte[][] embeddings = (c.length < emb4Constructor3[1][0].length) ?
328
emb4Constructor3[0] : emb4Constructor3[1];
329
for (int flagNo = 0; flagNo < FLAGS.length; flagNo++) {
330
int flag = FLAGS[flagNo];
331
for (int embNo = 0; embNo < embeddings.length; embNo++) {
332
int dataNo = flagNo * FLAGS.length + embNo;
333
334
System.out.println("*** Test textNo=" + textNo +
335
": Bidi(char[]\"" + toReadableString(paragraph) +
336
"\", 0, embeddings={" + toString(embeddings[embNo]) +
337
"}, " + c.length + ", " +
338
getFlagName(flag) + ")" + " dataNo=" + dataNo);
339
340
try {
341
bidi = new Bidi(c, 0, embeddings[embNo], 0,
342
c.length, flag);
343
callTestEachMethod4Constructor3(textNo, dataNo, bidi);
344
}
345
catch (Exception e) {
346
errorHandling(" Unexpected exception: " + e);
347
}
348
}
349
}
350
}
351
}
352
353
private void testConstructor1() {
354
Bidi bidi;
355
356
try {
357
bidi = new Bidi(null);
358
errorHandling("Bidi((AttributedCharacterIterator)null) " +
359
"should throw an IAE.");
360
}
361
catch (IllegalArgumentException e) {
362
}
363
catch (NullPointerException e) {
364
errorHandling("Bidi((AttributedCharacterIterator)null) " +
365
"should not throw an NPE but an IAE.");
366
}
367
368
String paragraph = data4Constructor1[1][0];
369
int start = paragraph.indexOf('<')+1;
370
int limit = paragraph.indexOf('>');
371
AttributedString astr = new AttributedString(paragraph);
372
astr.addAttribute(TextAttribute.RUN_DIRECTION,
373
TextAttribute.RUN_DIRECTION_RTL);
374
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-MAX_EXPLICIT_LEVEL),
375
start, limit);
376
try {
377
bidi = new Bidi(astr.getIterator());
378
for (int i = start; i < limit; i++) {
379
if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {
380
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +
381
i + ") should not be " + bidi.getLevelAt(i) +
382
" but MAX_EXPLICIT_LEVEL-1 when BIDI_EMBEDDING is -MAX_EXPLICIT_LEVEL.");
383
}
384
}
385
}
386
catch (Exception e) {
387
errorHandling(" Unexpected exception: " + e);
388
}
389
390
astr = new AttributedString(paragraph);
391
astr.addAttribute(TextAttribute.RUN_DIRECTION,
392
TextAttribute.RUN_DIRECTION_RTL);
393
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(-(MAX_EXPLICIT_LEVEL+1)),
394
start, limit);
395
try {
396
bidi = new Bidi(astr.getIterator());
397
for (int i = start; i < limit; i++) {
398
if (bidi.getLevelAt(i) != 1) {
399
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +
400
"should be 1 when BIDI_EMBEDDING is -(MAX_EXPLICIT_LEVEL+1).");
401
}
402
}
403
}
404
catch (Exception e) {
405
errorHandling(" Unexpected exception: " + e);
406
}
407
408
astr = new AttributedString(paragraph);
409
astr.addAttribute(TextAttribute.RUN_DIRECTION,
410
TextAttribute.RUN_DIRECTION_RTL);
411
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL-1),
412
start, limit);
413
try {
414
bidi = new Bidi(astr.getIterator());
415
for (int i = start; i < limit; i++) {
416
if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {
417
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt() " +
418
"should be MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL-1.");
419
}
420
}
421
}
422
catch (Exception e) {
423
errorHandling(" Unexpected exception: " + e);
424
}
425
426
astr = new AttributedString(paragraph);
427
astr.addAttribute(TextAttribute.RUN_DIRECTION,
428
TextAttribute.RUN_DIRECTION_RTL);
429
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL),
430
start, limit);
431
try {
432
bidi = new Bidi(astr.getIterator());
433
for (int i = start; i < limit; i++) {
434
if (bidi.getLevelAt(i) != MAX_EXPLICIT_LEVEL) {
435
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +
436
i + ") should not be " + bidi.getLevelAt(i) +
437
" but MAX_EXPLICIT_LEVEL when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL.");
438
}
439
}
440
}
441
catch (Exception e) {
442
errorHandling(" Unexpected exception: " + e);
443
}
444
445
astr = new AttributedString(paragraph);
446
astr.addAttribute(TextAttribute.RUN_DIRECTION,
447
TextAttribute.RUN_DIRECTION_RTL);
448
astr.addAttribute(TextAttribute.BIDI_EMBEDDING, new Integer(MAX_EXPLICIT_LEVEL+1),
449
start, limit);
450
try {
451
bidi = new Bidi(astr.getIterator());
452
for (int i = start; i < limit; i++) {
453
if (bidi.getLevelAt(i) != 1) {
454
errorHandling("Bidi(AttributedCharacterIterator).getLevelAt(" +
455
i + ") should not be " + bidi.getLevelAt(i) +
456
" but 1 when BIDI_EMBEDDING is MAX_EXPLICIT_LEVEL+1.");
457
}
458
}
459
}
460
catch (Exception e) {
461
errorHandling(" Unexpected exception: " + e);
462
}
463
}
464
465
private void testConstructor2() {
466
Bidi bidi;
467
468
try {
469
bidi = new Bidi(null, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
470
errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT)" +
471
" should throw an IAE.");
472
}
473
catch (IllegalArgumentException e) {
474
}
475
catch (NullPointerException e) {
476
errorHandling("Bidi((String)null, DIRECTION_DEFAULT_LEFT_TO_RIGHT) " +
477
"should not throw an NPE but an IAE.");
478
}
479
480
try {
481
bidi = new Bidi("abc", -3);
482
}
483
catch (Exception e) {
484
errorHandling("Bidi(\"abc\", -3) should not throw an exception: " +
485
e);
486
}
487
488
try {
489
bidi = new Bidi("abc", 2);
490
}
491
catch (Exception e) {
492
errorHandling("Bidi(\"abc\", 2) should not throw an exception: " +
493
e);
494
}
495
}
496
497
private void testConstructor3() {
498
char[] text = {'a', 'b', 'c', 'd', 'e'};
499
byte[] embeddings = {0, 0, 0, 0, 0};
500
Bidi bidi;
501
502
try {
503
bidi = new Bidi(null, 0, embeddings, 0, 5,
504
Bidi.DIRECTION_LEFT_TO_RIGHT);
505
errorHandling("Bidi(char[], ...) should throw an IAE " +
506
"when text=null.");
507
}
508
catch (IllegalArgumentException e) {
509
}
510
catch (NullPointerException e) {
511
errorHandling("Bidi(char[], ...) should not throw an NPE " +
512
"but an IAE when text=null.");
513
}
514
515
try {
516
bidi = new Bidi(text, -1, embeddings, 0, 5,
517
Bidi.DIRECTION_LEFT_TO_RIGHT);
518
errorHandling("Bidi(char[], ...) should throw an IAE " +
519
"when textStart is incorrect(-1: too small).");
520
}
521
catch (IllegalArgumentException e) {
522
}
523
catch (ArrayIndexOutOfBoundsException e) {
524
errorHandling("Bidi(char[], ...) should not throw an NPE " +
525
"but an IAE when textStart is incorrect(-1: too small).");
526
}
527
528
try {
529
bidi = new Bidi(text, 4, embeddings, 0, 2,
530
Bidi.DIRECTION_LEFT_TO_RIGHT);
531
errorHandling("Bidi(char[], ...) should throw an IAE " +
532
"when textStart is incorrect(4: too large).");
533
}
534
catch (IllegalArgumentException e) {
535
}
536
catch (ArrayIndexOutOfBoundsException e) {
537
errorHandling("Bidi(char[], ...) should not throw an NPE " +
538
"but an IAE when textStart is incorrect(4: too large).");
539
}
540
541
byte[] actualLevels = new byte[text.length];
542
byte[] validEmbeddings1 = {0, -MAX_EXPLICIT_LEVEL, -(MAX_EXPLICIT_LEVEL-1), -2, -1};
543
byte[] expectedLevels1 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 2, 1};
544
try {
545
bidi = new Bidi(text, 0, validEmbeddings1, 0, 5,
546
Bidi.DIRECTION_LEFT_TO_RIGHT);
547
for (int i = 0; i < text.length; i++) {
548
actualLevels[i] = (byte)bidi.getLevelAt(i);
549
}
550
if (!Arrays.equals(expectedLevels1, actualLevels)) {
551
errorHandling("Bidi(char[], ...).getLevelAt()" +
552
" should be {" + toString(actualLevels) +
553
"} when embeddings are {" +
554
toString(expectedLevels1) + "}.");
555
}
556
}
557
catch (Exception e) {
558
errorHandling("Bidi(char[], ...) should not throw an exception " +
559
"when embeddings is valid(-MAX_EXPLICIT_LEVEL).");
560
}
561
562
byte[] validEmbeddings2 = {0, MAX_EXPLICIT_LEVEL, MAX_EXPLICIT_LEVEL-1, 2, 1};
563
byte[] expectedLevels2 = {0, MAX_EXPLICIT_LEVEL+1, MAX_EXPLICIT_LEVEL-1, 2, 2};
564
try {
565
bidi = new Bidi(text, 0, validEmbeddings2, 0, 5,
566
Bidi.DIRECTION_LEFT_TO_RIGHT);
567
for (int i = 0; i < text.length; i++) {
568
actualLevels[i] = (byte)bidi.getLevelAt(i);
569
}
570
if (!Arrays.equals(expectedLevels2, actualLevels)) {
571
errorHandling("Bidi(char[], ...).getLevelAt()" +
572
" should be {" + toString(actualLevels) +
573
"} when embeddings are {" +
574
toString(expectedLevels2) + "}.");
575
}
576
}
577
catch (Exception e) {
578
errorHandling("Bidi(char[], ...) should not throw an exception " +
579
"when embeddings is valid(MAX_EXPLICIT_LEVEL).");
580
}
581
582
byte[] invalidEmbeddings1 = {0, -(MAX_EXPLICIT_LEVEL+1), 0, 0, 0};
583
try {
584
bidi = new Bidi(text, 0, invalidEmbeddings1, 0, 5,
585
Bidi.DIRECTION_LEFT_TO_RIGHT);
586
if (bidi.getLevelAt(1) != 0) {
587
errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +
588
"when embeddings[1] is -(MAX_EXPLICIT_LEVEL+1).");
589
}
590
}
591
catch (Exception e) {
592
errorHandling("Bidi(char[], ...) should not throw an exception " +
593
"even when embeddings includes -(MAX_EXPLICIT_LEVEL+1).");
594
}
595
596
byte[] invalidEmbeddings2 = {0, MAX_EXPLICIT_LEVEL+1, 0, 0, 0};
597
try {
598
bidi = new Bidi(text, 0, invalidEmbeddings2, 0, 5,
599
Bidi.DIRECTION_LEFT_TO_RIGHT);
600
if (bidi.getLevelAt(1) != 0) {
601
errorHandling("Bidi(char[], ...).getLevelAt(1) should be 0 " +
602
"when embeddings[1] is MAX_EXPLICIT_LEVEL+1.");
603
}
604
}
605
catch (Exception e) {
606
errorHandling("Bidi(char[], ...) should not throw an exception " +
607
"even when embeddings includes MAX_EXPLICIT_LEVEL+1.");
608
}
609
610
try {
611
bidi = new Bidi(text, 0, embeddings, 0, -1,
612
Bidi.DIRECTION_LEFT_TO_RIGHT);
613
errorHandling("Bidi(char[], ...) should throw an IAE " +
614
"when paragraphLength=-1(too small).");
615
}
616
catch (IllegalArgumentException e) {
617
}
618
catch (NegativeArraySizeException e) {
619
errorHandling("Bidi(char[], ...) should not throw an NASE " +
620
"but an IAE when paragraphLength=-1(too small).");
621
}
622
623
try {
624
bidi = new Bidi(text, 0, embeddings, 0, 6,
625
Bidi.DIRECTION_LEFT_TO_RIGHT);
626
errorHandling("Bidi(char[], ...) should throw an IAE " +
627
"when paragraphLength=6(too large).");
628
}
629
catch (IllegalArgumentException e) {
630
}
631
catch (ArrayIndexOutOfBoundsException e) {
632
errorHandling("Bidi(char[], ...) should not throw an AIOoBE " +
633
"but an IAE when paragraphLength=6(too large).");
634
}
635
636
try {
637
bidi = new Bidi(text, 0, embeddings, 0, 4, -3);
638
}
639
catch (Exception e) {
640
errorHandling("Bidi(char[], ...) should not throw an exception " +
641
"even when flag=-3(too small).");
642
}
643
644
try {
645
bidi = new Bidi(text, 0, embeddings, 0, 5, 2);
646
}
647
catch (Exception e) {
648
errorHandling("Bidi(char[], ...) should not throw an exception " +
649
"even when flag=2(too large).");
650
}
651
}
652
653
private void callTestEachMethod4Constructor1(int textNo,
654
int testNo,
655
Bidi bidi) {
656
testEachMethod(bidi,
657
data4Constructor1[textNo][0],
658
data4Constructor1[textNo][testNo+1],
659
baseIsLTR4Constructor1[textNo][testNo],
660
isLTR_isRTL4Constructor1[textNo][0][testNo],
661
isLTR_isRTL4Constructor1[textNo][1][testNo]);
662
}
663
664
private void callTestEachMethod4Constructor2(int textNo,
665
int flagNo,
666
Bidi bidi) {
667
testEachMethod(bidi,
668
data4Constructor2[textNo][0],
669
data4Constructor2[textNo][flagNo+1],
670
baseIsLTR4Constructor2[textNo][flagNo],
671
isLTR_isRTL4Constructor2[textNo][0][flagNo],
672
isLTR_isRTL4Constructor2[textNo][1][flagNo]);
673
}
674
675
private void callTestEachMethod4Constructor3(int textNo,
676
int dataNo,
677
Bidi bidi) {
678
testEachMethod(bidi,
679
data4Constructor3[textNo][0],
680
data4Constructor3[textNo][dataNo+1],
681
baseIsLTR4Constructor3[textNo][dataNo],
682
isLTR_isRTL4Constructor3[textNo][0][dataNo],
683
isLTR_isRTL4Constructor3[textNo][1][dataNo]);
684
}
685
686
private StringBuilder sb = new StringBuilder();
687
private void testEachMethod(Bidi bidi,
688
String text,
689
String expectedLevels,
690
boolean expectedBaseIsLTR,
691
boolean expectedIsLTR,
692
boolean expectedIsRTL
693
) {
694
/* Test baseIsLeftToRight() */
695
boolean actualBoolean = bidi.baseIsLeftToRight();
696
checkResult("baseIsLeftToRight()", expectedBaseIsLTR, actualBoolean);
697
698
/* Test getBaseLevel() */
699
int expectedInt = (expectedBaseIsLTR) ? 0 : 1;
700
int actualInt = bidi.getBaseLevel();
701
checkResult("getBaseLevel()", expectedInt, actualInt);
702
703
/* Test getLength() */
704
expectedInt = text.length();
705
actualInt = bidi.getLength();
706
checkResult("getLength()", expectedInt, actualInt);
707
708
/* Test getLevelAt() */
709
sb.setLength(0);
710
for (int i = 0; i < text.length(); i++) {
711
sb.append(bidi.getLevelAt(i));
712
}
713
checkResult("getLevelAt()", expectedLevels, sb.toString());
714
715
/* Test getRunCount() */
716
expectedInt = getRunCount(expectedLevels);
717
actualInt = bidi.getRunCount();
718
checkResult("getRunCount()", expectedInt, actualInt);
719
720
/* Test getRunLevel(), getRunLimit() and getRunStart() */
721
if (expectedInt == actualInt) {
722
int runCount = expectedInt;
723
int[] expectedRunLevels = getRunLevels_int(runCount, expectedLevels);
724
int[] expectedRunLimits = getRunLimits(runCount, expectedLevels);
725
int[] expectedRunStarts = getRunStarts(runCount, expectedLevels);
726
int[] actualRunLevels = new int[runCount];
727
int[] actualRunLimits = new int[runCount];
728
int[] actualRunStarts = new int[runCount];
729
730
for (int k = 0; k < runCount; k++) {
731
actualRunLevels[k] = bidi.getRunLevel(k);
732
actualRunLimits[k] = bidi.getRunLimit(k);
733
actualRunStarts[k] = bidi.getRunStart(k);
734
}
735
736
checkResult("getRunLevel()", expectedRunLevels, actualRunLevels);
737
checkResult("getRunStart()", expectedRunStarts, actualRunStarts);
738
checkResult("getRunLimit()", expectedRunLimits, actualRunLimits);
739
}
740
741
/* Test isLeftToRight() */
742
boolean expectedBoolean = expectedIsLTR;
743
actualBoolean = bidi.isLeftToRight();
744
checkResult("isLeftToRight()", expectedBoolean, actualBoolean);
745
746
/* Test isMixed() */
747
expectedBoolean = !(expectedIsLTR || expectedIsRTL);
748
actualBoolean = bidi.isMixed();
749
checkResult("isMixed()", expectedBoolean, actualBoolean);
750
751
/* Test isRightToLeft() */
752
expectedBoolean = expectedIsRTL;
753
actualBoolean = bidi.isRightToLeft();
754
checkResult("isRightToLeft()", expectedBoolean, actualBoolean);
755
}
756
757
private int getRunCount(String levels) {
758
int len = levels.length();
759
char c = levels.charAt(0);
760
int runCount = 1;
761
762
for (int index = 1; index < len; index++) {
763
if (levels.charAt(index) != c) {
764
runCount++;
765
c = levels.charAt(index);
766
}
767
}
768
769
return runCount;
770
}
771
772
private int[] getRunLevels_int(int runCount, String levels) {
773
int[] array = new int[runCount];
774
int len = levels.length();
775
char c = levels.charAt(0);
776
int i = 0;
777
array[i++] = c - '0';
778
779
for (int index = 1; index < len; index++) {
780
if (levels.charAt(index) != c) {
781
c = levels.charAt(index);
782
array[i++] = c - '0';
783
}
784
}
785
786
return array;
787
}
788
789
private byte[] getRunLevels_byte(int runCount, String levels) {
790
byte[] array = new byte[runCount];
791
int len = levels.length();
792
char c = levels.charAt(0);
793
int i = 0;
794
array[i++] = (byte)(c - '0');
795
796
for (int index = 1; index < len; index++) {
797
if (levels.charAt(index) != c) {
798
c = levels.charAt(index);
799
array[i++] = (byte)(c - '0');
800
}
801
}
802
803
return array;
804
}
805
806
private int[] getRunLimits(int runCount, String levels) {
807
int[] array = new int[runCount];
808
int len = levels.length();
809
char c = levels.charAt(0);
810
int i = 0;
811
812
for (int index = 1; index < len; index++) {
813
if (levels.charAt(index) != c) {
814
c = levels.charAt(index);
815
array[i++] = index;
816
}
817
}
818
array[i] = len;
819
820
return array;
821
}
822
823
private int[] getRunStarts(int runCount, String levels) {
824
int[] array = new int[runCount];
825
int len = levels.length();
826
char c = levels.charAt(0);
827
int i = 1;
828
829
for (int index = 1; index < len; index++) {
830
if (levels.charAt(index) != c) {
831
c = levels.charAt(index);
832
array[i++] = index;
833
}
834
}
835
836
return array;
837
}
838
839
private String[] getObjects(int runCount, String text, String levels) {
840
String[] array = new String[runCount];
841
int[] runLimits = getRunLimits(runCount, levels);
842
int runStart = 0;
843
844
for (int i = 0; i < runCount; i++) {
845
array[i] = text.substring(runStart, runLimits[i]);
846
runStart = runLimits[i];
847
}
848
849
return array;
850
}
851
852
private void testMethod_createLineBidi1() {
853
System.out.println("*** Test createLineBidi() 1");
854
855
String str = " ABC 123. " + HebrewABC + " " + NKo123 + ". ABC 123";
856
857
int lineStart = str.indexOf('.') + 2;
858
int lineLimit = str.lastIndexOf('.') + 2;
859
Bidi bidi = new Bidi(str, FLAGS[0]);
860
Bidi lineBidi = bidi.createLineBidi(lineStart, lineLimit);
861
862
checkResult("getBaseLevel()",
863
bidi.getBaseLevel(), lineBidi.getBaseLevel());
864
checkResult("getLevelAt(5)",
865
bidi.getLevelAt(lineStart+5), lineBidi.getLevelAt(5));
866
}
867
868
private void testMethod_createLineBidi2() {
869
System.out.println("*** Test createLineBidi() 2");
870
871
Bidi bidi = new Bidi(data4Constructor1[0][0], FLAGS[0]);
872
int len = data4Constructor1[0][0].length();
873
874
try {
875
Bidi lineBidi = bidi.createLineBidi(0, len);
876
}
877
catch (Exception e) {
878
errorHandling("createLineBidi(0, textLength)" +
879
" should not throw an exception.");
880
}
881
882
try {
883
Bidi lineBidi = bidi.createLineBidi(-1, len);
884
errorHandling("createLineBidi(-1, textLength)" +
885
" should throw an IAE.");
886
}
887
catch (IllegalArgumentException e) {
888
}
889
890
try {
891
Bidi lineBidi = bidi.createLineBidi(0, len+1);
892
errorHandling("createLineBidi(0, textLength+1)" +
893
" should throw an IAE.");
894
}
895
catch (IllegalArgumentException e) {
896
}
897
}
898
899
/*
900
* Confirm that getLevelAt() doesn't throw an exception for invalid offset
901
* unlike ICU4J.
902
*/
903
private void testMethod_getLevelAt() {
904
System.out.println("*** Test getLevelAt()");
905
906
Bidi bidi = new Bidi(data4Constructor1[1][0], FLAGS[0]);
907
int len = data4Constructor1[1][0].length();
908
909
try {
910
int level = bidi.getLevelAt(-1);
911
if (level != bidi.getBaseLevel()) {
912
errorHandling("getLevelAt(-1) returned a wrong level." +
913
" Expected=" + bidi.getBaseLevel() + ", got=" + level);
914
}
915
}
916
catch (Exception e) {
917
errorHandling("getLevelAt(-1) should not throw an exception.");
918
}
919
920
try {
921
int level = bidi.getLevelAt(len+1);
922
if (level != bidi.getBaseLevel()) {
923
errorHandling("getLevelAt(textLength+1)" +
924
" returned a wrong level." +
925
" Expected=" + bidi.getBaseLevel() + ", got=" + level);
926
}
927
}
928
catch (Exception e) {
929
errorHandling("getLevelAt(-1) should not throw an exception.");
930
}
931
}
932
933
private void testMethod_getRunLevel() {
934
System.out.println("*** Test getRunLevel()");
935
936
String str = "ABC 123";
937
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
938
try {
939
if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)
940
bidi.getRunLevel(0) != 0 || // runCount - 1
941
bidi.getRunLevel(1) != 0 || // runCount (out of range)
942
bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)
943
errorHandling("Incorrect getRunLevel() value(s).");
944
}
945
}
946
catch (Exception e) {
947
errorHandling("getRunLevel() should not throw an exception: " + e);
948
}
949
950
str = "ABC " + HebrewABC + " 123";
951
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
952
try {
953
if (bidi.getRunLevel(-1) != 0 || // runCount - 4 (out of range)
954
bidi.getRunLevel(0) != 0 || // runCount - 3
955
bidi.getRunLevel(1) != 1 || // runCount - 2
956
bidi.getRunLevel(2) != 2 || // runCount - 1
957
bidi.getRunLevel(3) != 0 || // runCount (out of range)
958
bidi.getRunLevel(4) != 0) { // runCount + 1 (out of range)
959
errorHandling("Incorrect getRunLevel() value(s).");
960
}
961
}
962
catch (Exception e) {
963
errorHandling("getRunLevel() should not throw an exception: " + e);
964
}
965
966
str = "ABC";
967
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
968
try {
969
if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)
970
bidi.getRunLevel(0) != 0 || // runCount - 1
971
bidi.getRunLevel(1) != 0 || // runCount (out of range)
972
bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)
973
errorHandling("Incorrect getRunLevel() value(s).");
974
}
975
}
976
catch (Exception e) {
977
errorHandling("getRunLevel() should not throw an exception: " + e);
978
}
979
980
str = "ABC";
981
bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);
982
try {
983
if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)
984
bidi.getRunLevel(0) != 2 || // runCount - 1
985
bidi.getRunLevel(1) != 1 || // runCount (out of range)
986
bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)
987
errorHandling("Incorrect getRunLevel() value(s).");
988
}
989
}
990
catch (Exception e) {
991
errorHandling("getRunLevel() should not throw an exception: " + e);
992
}
993
994
str = "ABC";
995
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
996
try {
997
if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)
998
bidi.getRunLevel(0) != 0 || // runCount - 1
999
bidi.getRunLevel(1) != 0 || // runCount (out of range)
1000
bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)
1001
errorHandling("Incorrect getRunLevel() value(s).");
1002
}
1003
}
1004
catch (Exception e) {
1005
errorHandling("getRunLevel() should not throw an exception: " + e);
1006
}
1007
1008
str = "ABC";
1009
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
1010
try {
1011
if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)
1012
bidi.getRunLevel(0) != 0 || // runCount - 1
1013
bidi.getRunLevel(1) != 0 || // runCount (out of range)
1014
bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)
1015
errorHandling("Incorrect getRunLevel() value(s).");
1016
}
1017
}
1018
catch (Exception e) {
1019
errorHandling("getRunLevel() should not throw an exception: " + e);
1020
}
1021
1022
str = HebrewABC;
1023
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
1024
try {
1025
if (bidi.getRunLevel(-1) != 0 || // runCount - 2 (out of range)
1026
bidi.getRunLevel(0) != 1 || // runCount - 1
1027
bidi.getRunLevel(1) != 0 || // runCount (out of range)
1028
bidi.getRunLevel(2) != 0) { // runCount + 1 (out of range)
1029
errorHandling("Incorrect getRunLevel() value(s).");
1030
}
1031
}
1032
catch (Exception e) {
1033
errorHandling("getRunLevel() should not throw an exception: " + e);
1034
}
1035
1036
str = HebrewABC;
1037
bidi = new Bidi(str, Bidi.DIRECTION_RIGHT_TO_LEFT);
1038
try {
1039
if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)
1040
bidi.getRunLevel(0) != 1 || // runCount - 1
1041
bidi.getRunLevel(1) != 1 || // runCount (out of range)
1042
bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)
1043
errorHandling("Incorrect getRunLevel() value(s).");
1044
}
1045
}
1046
catch (Exception e) {
1047
errorHandling("getRunLevel() should not throw an exception: " + e);
1048
}
1049
1050
str = HebrewABC;
1051
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
1052
try {
1053
if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)
1054
bidi.getRunLevel(0) != 1 || // runCount - 1
1055
bidi.getRunLevel(1) != 1 || // runCount (out of range)
1056
bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)
1057
errorHandling("Incorrect getRunLevel() value(s).");
1058
}
1059
}
1060
catch (Exception e) {
1061
errorHandling("getRunLevel() should not throw an exception: " + e);
1062
}
1063
1064
str = HebrewABC;
1065
bidi = new Bidi(str, Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
1066
try {
1067
if (bidi.getRunLevel(-1) != 1 || // runCount - 2 (out of range)
1068
bidi.getRunLevel(0) != 1 || // runCount - 1
1069
bidi.getRunLevel(1) != 1 || // runCount (out of range)
1070
bidi.getRunLevel(2) != 1) { // runCount + 1 (out of range)
1071
errorHandling("Incorrect getRunLevel() value(s).");
1072
}
1073
}
1074
catch (Exception e) {
1075
errorHandling("getRunLevel() should not throw an exception: " + e);
1076
}
1077
}
1078
1079
private void testMethod_getRunLimit() {
1080
System.out.println("*** Test getRunLimit()");
1081
1082
String str = "ABC 123";
1083
int length = str.length();
1084
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
1085
1086
try {
1087
if (bidi.getRunLimit(-1) != length || // runCount - 2
1088
bidi.getRunLimit(0) != length || // runCount - 1
1089
bidi.getRunLimit(1) != length || // runCount
1090
bidi.getRunLimit(2) != length) { // runCount + 1
1091
errorHandling("getRunLimit() should return " + length +
1092
" when getRunCount() is 1.");
1093
}
1094
}
1095
catch (Exception e) {
1096
errorHandling("getRunLimit() should not throw an exception " +
1097
"when getRunCount() is 1.");
1098
}
1099
1100
str = "ABC " + ArabicABC + " 123";
1101
length = str.length();
1102
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
1103
1104
try {
1105
bidi.getRunLimit(-1);
1106
errorHandling("getRunLimit() should throw an AIOoBE " +
1107
"when run is -1(too small).");
1108
}
1109
catch (ArrayIndexOutOfBoundsException e) {
1110
}
1111
catch (IllegalArgumentException e) {
1112
errorHandling("getRunLimit() should not throw an IAE " +
1113
"but an AIOoBE when run is -1(too small).");
1114
}
1115
1116
try {
1117
bidi.getRunLimit(0);
1118
bidi.getRunLimit(1);
1119
bidi.getRunLimit(2);
1120
}
1121
catch (ArrayIndexOutOfBoundsException e) {
1122
errorHandling("getRunLimit() should not throw an AIOOBE " +
1123
"when run is from 0 to 2(runCount-1).");
1124
}
1125
1126
try {
1127
bidi.getRunLimit(3);
1128
errorHandling("getRunLimit() should throw an AIOoBE " +
1129
"when run is 3(same as runCount).");
1130
}
1131
catch (ArrayIndexOutOfBoundsException e) {
1132
}
1133
catch (IllegalArgumentException e) {
1134
errorHandling("getRunLimit() should not throw an IAE " +
1135
"but an AIOoBE when run is 3(same as runCount).");
1136
}
1137
}
1138
1139
private void testMethod_getRunStart() {
1140
System.out.println("*** Test getRunStart()");
1141
1142
String str = "ABC 123";
1143
int length = str.length();
1144
Bidi bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
1145
1146
try {
1147
if (bidi.getRunStart(-1) != 0 || // runCount - 2
1148
bidi.getRunStart(0) != 0 || // runCount - 1
1149
bidi.getRunStart(1) != 0 || // runCount
1150
bidi.getRunStart(2) != 0) { // runCount + 1
1151
errorHandling("getRunStart() should return 0" +
1152
" when getRunCount() is 1.");
1153
}
1154
}
1155
catch (Exception e) {
1156
errorHandling("getRunLimit() should not throw an exception" +
1157
" when getRunCount() is 1.");
1158
}
1159
1160
str = "ABC " + NKoABC + " 123";
1161
length = str.length();
1162
bidi = new Bidi(str, Bidi.DIRECTION_LEFT_TO_RIGHT);
1163
1164
try {
1165
bidi.getRunStart(-1);
1166
errorHandling("getRunStart() should throw an AIOoBE" +
1167
" when run is -1(too small).");
1168
}
1169
catch (ArrayIndexOutOfBoundsException e) {
1170
}
1171
catch (IllegalArgumentException e) {
1172
errorHandling("getRunStart() should not throw an IAE " +
1173
"but an AIOoBE when run is -1(too small).");
1174
}
1175
1176
try {
1177
bidi.getRunStart(0);
1178
bidi.getRunStart(1);
1179
bidi.getRunStart(2);
1180
}
1181
catch (ArrayIndexOutOfBoundsException e) {
1182
errorHandling("getRunStart() should not throw an AIOOBE " +
1183
"when run is from 0 to 2(runCount-1).");
1184
}
1185
1186
try {
1187
if (bidi.getRunStart(3) != length) {
1188
errorHandling("getRunStart() should return " + length +
1189
" when run is 3(same as runCount).");
1190
}
1191
}
1192
catch (Exception e) {
1193
errorHandling("getRunStart() should not throw an exception " +
1194
"when run is 3(same as runCount).");
1195
}
1196
1197
try {
1198
bidi.getRunStart(4);
1199
errorHandling("getRunStart() should throw an AIOoBE " +
1200
"when run is runCount+1(too large).");
1201
}
1202
catch (ArrayIndexOutOfBoundsException e) {
1203
}
1204
catch (IllegalArgumentException e) {
1205
errorHandling("getRunStart() should not throw an IAE " +
1206
"but an AIOoBE when run is runCount+1(too large).");
1207
}
1208
}
1209
1210
private void testMethod_reorderVisually1() {
1211
System.out.println("*** Test reorderVisually() 1");
1212
1213
for (int textNo = 0; textNo < data4reorderVisually.length; textNo++) {
1214
Object[] objects = data4reorderVisually[textNo][0];
1215
byte[] levels = getLevels(data4reorderVisually[textNo]);
1216
Object[] expectedObjects = data4reorderVisually[textNo][2];
1217
1218
Bidi.reorderVisually(levels, 0, objects, 0, objects.length);
1219
1220
checkResult("textNo=" + textNo + ": reorderVisually(levels=[" +
1221
toString(levels) + "], objects=[" + toString(objects) + "])",
1222
expectedObjects, objects);
1223
}
1224
}
1225
1226
private void testMethod_reorderVisually2() {
1227
System.out.println("*** Test reorderVisually() 2");
1228
1229
Object[] objects = data4reorderVisually[0][0];
1230
byte[] levels = getLevels(data4reorderVisually[0]);
1231
int count = objects.length;
1232
int llen = levels.length;
1233
int olen = objects.length;
1234
1235
try {
1236
Bidi.reorderVisually(null, 0, objects, 0, count);
1237
errorHandling("reorderVisually() should throw a NPE " +
1238
"when levels is null.");
1239
}
1240
catch (NullPointerException e) {
1241
}
1242
1243
try {
1244
Bidi.reorderVisually(levels, -1, objects, 0, count);
1245
errorHandling("reorderVisually() should throw an IAE " +
1246
"when levelStart is -1.");
1247
}
1248
catch (IllegalArgumentException e) {
1249
if (!e.getMessage().equals(
1250
"Value levelStart -1 is out of range 0 to " + (llen - 1))) {
1251
errorHandling("reorderVisually() should throw an IAE" +
1252
" mentioning levelStart is beyond the levels range. Message: " + e.getMessage());
1253
}
1254
}
1255
catch (ArrayIndexOutOfBoundsException e) {
1256
errorHandling("reorderVisually() should not throw an AIOoBE " +
1257
"but an IAE when levelStart is -1.");
1258
}
1259
1260
try {
1261
Bidi.reorderVisually(levels, llen, objects, 0, count);
1262
errorHandling("reorderVisually() should throw an IAE " +
1263
"when levelStart is 6(levels.length).");
1264
}
1265
catch (IllegalArgumentException e) {
1266
if (!e.getMessage().equals(
1267
"Value levelStart " + llen + " is out of range 0 to " + (llen - 1))) {
1268
errorHandling("reorderVisually() should throw an IAE" +
1269
" mentioning levelStart is beyond the levels range. Message: " + e.getMessage());
1270
}
1271
}
1272
catch (ArrayIndexOutOfBoundsException e) {
1273
errorHandling("reorderVisually() should not throw an AIOoBE " +
1274
"but an IAE when levelStart is 6(levels.length).");
1275
}
1276
1277
try {
1278
Bidi.reorderVisually(levels, 0, null, 0, count);
1279
errorHandling("reorderVisually() should throw a NPE" +
1280
" when objects is null.");
1281
}
1282
catch (NullPointerException e) {
1283
}
1284
1285
try {
1286
Bidi.reorderVisually(levels, 0, objects, -1, count);
1287
errorHandling("reorderVisually() should throw an IAE" +
1288
" when objectStart is -1.");
1289
}
1290
catch (IllegalArgumentException e) {
1291
if (!e.getMessage().equals(
1292
"Value objectStart -1 is out of range 0 to " + (olen - 1))) {
1293
errorHandling("reorderVisually() should throw an IAE" +
1294
" mentioning objectStart is beyond the objects range. Message: " + e.getMessage());
1295
}
1296
}
1297
catch (ArrayIndexOutOfBoundsException e) {
1298
errorHandling("reorderVisually() should not throw an AIOoBE " +
1299
"but an IAE when objectStart is -1.");
1300
}
1301
1302
try {
1303
Bidi.reorderVisually(levels, 0, objects, 6, objects.length);
1304
errorHandling("reorderVisually() should throw an IAE " +
1305
"when objectStart is 6(objects.length).");
1306
}
1307
catch (IllegalArgumentException e) {
1308
if (!e.getMessage().equals(
1309
"Value objectStart 6 is out of range 0 to " + (olen - 1))) {
1310
errorHandling("reorderVisually() should throw an IAE" +
1311
" mentioning objectStart is beyond the objects range. Message: " + e.getMessage());
1312
}
1313
}
1314
1315
try {
1316
Bidi.reorderVisually(levels, 0, objects, 0, -1);
1317
errorHandling("reorderVisually() should throw an IAE " +
1318
"when count is -1.");
1319
}
1320
catch (IllegalArgumentException e) {
1321
if (!e.getMessage().equals(
1322
"Value count -1 is less than zero, or objectStart + count " +
1323
"is beyond objects length " + olen)) {
1324
errorHandling("reorderVisually() should throw an IAE" +
1325
" mentioning objectStart/count is beyond the objects range. Message: " + e.getMessage());
1326
}
1327
}
1328
catch (NegativeArraySizeException e) {
1329
errorHandling("reorderVisually() should not throw an NASE " +
1330
"but an IAE when count is -1.");
1331
}
1332
1333
try {
1334
Bidi.reorderVisually(levels, 0, objects, 0, count+1);
1335
errorHandling("reorderVisually() should throw an IAE " +
1336
"when count is 7(objects.length+1).");
1337
}
1338
catch (IllegalArgumentException e) {
1339
if (!e.getMessage().equals(
1340
"Value count " + (count + 1) + " is less than zero, or objectStart + count " +
1341
"is beyond objects length " + olen)) {
1342
errorHandling("reorderVisually() should throw an IAE" +
1343
" mentioning objectStart/count is beyond the objects range. Message: " + e.getMessage());
1344
}
1345
}
1346
catch (ArrayIndexOutOfBoundsException e) {
1347
errorHandling("reorderVisually() should not throw an AIOoBE " +
1348
"but an IAE when count is 7(objects.length+1).");
1349
}
1350
1351
try {
1352
Bidi.reorderVisually(levels, 0, objects, 0, 0);
1353
checkResult("reorderVisually(count=0)",
1354
data4reorderVisually[0][0], objects);
1355
}
1356
catch (Exception e) {
1357
errorHandling("reorderVisually() should not throw an exception" +
1358
" when count is 0.");
1359
}
1360
}
1361
1362
private void testMethod_requiresBidi() {
1363
System.out.println("*** Test requiresBidi()");
1364
1365
String paragraph;
1366
char[] text;
1367
Bidi bidi;
1368
1369
for (int textNo = 0; textNo < data4Constructor2.length; textNo++) {
1370
paragraph = data4Constructor2[textNo][0];
1371
text = paragraph.toCharArray();
1372
boolean rBidi = Bidi.requiresBidi(text, 0, text.length);
1373
if (rBidi != requiresBidi4Constructor2[textNo]) {
1374
error = true;
1375
System.err.println("Unexpected requiresBidi() value" +
1376
" for requiresBidi(\"" + paragraph + "\", " + 0 + ", " +
1377
text.length + ")." +
1378
"\n Expected: " + requiresBidi4Constructor2[textNo] +
1379
"\n Got : " + rBidi);
1380
} else if (verbose) {
1381
System.out.println(" Okay : requiresBidi() for" +
1382
" requiresBidi(\"" + paragraph + "\", " + 0 + ", " +
1383
text.length + ") Got: " + rBidi);
1384
}
1385
}
1386
1387
char[] txt = {'A', 'B', 'C', 'D', 'E'};
1388
int textLength = txt.length;
1389
1390
try {
1391
Bidi.requiresBidi(txt, -1, textLength);
1392
errorHandling("requiresBidi() should throw an IAE" +
1393
" when start is -1(too small).");
1394
}
1395
catch (IllegalArgumentException e) {
1396
}
1397
catch (ArrayIndexOutOfBoundsException e) {
1398
errorHandling("requiresBidi() should not throw an AIOoBE " +
1399
"but an IAE when start is -1(too small).");
1400
}
1401
1402
try {
1403
Bidi.requiresBidi(txt, textLength, textLength);
1404
}
1405
catch (Exception e) {
1406
errorHandling("requiresBidi() should not throw an exception " +
1407
"when start is textLength.");
1408
}
1409
1410
try {
1411
Bidi.requiresBidi(txt, textLength+1, textLength);
1412
errorHandling("requiresBidi() should throw an IAE" +
1413
" when start is textLength+1(too large).");
1414
}
1415
catch (IllegalArgumentException e) {
1416
}
1417
1418
try {
1419
Bidi.requiresBidi(txt, 0, -1);
1420
errorHandling("requiresBidi() should throw an IAE" +
1421
" when limit is -1(too small).");
1422
}
1423
catch (IllegalArgumentException e) {
1424
}
1425
1426
try {
1427
Bidi.requiresBidi(txt, 0, textLength+1);
1428
errorHandling("requiresBidi() should throw an IAE" +
1429
" when limit is textLength+1(too large).");
1430
}
1431
catch (IllegalArgumentException e) {
1432
if (!e.getMessage().equals(
1433
"Value start 0 is out of range 0 to " + (textLength + 1) +
1434
", or limit " + (textLength + 1) + " is beyond the text length " + textLength)) {
1435
errorHandling("requiresBidi() should throw an IAE" +
1436
" mentioning limit is beyond the text length. Message: " + e.getMessage());
1437
}
1438
}
1439
catch (ArrayIndexOutOfBoundsException e) {
1440
errorHandling("requiresBidi() should not throw an AIOoBE " +
1441
"but an IAE when limit is textLength+1(too large).");
1442
}
1443
}
1444
1445
private void checkResult(String name,
1446
int expectedValue,
1447
int actualValue) {
1448
if (expectedValue != actualValue) {
1449
errorHandling("Unexpected " + name + " value." +
1450
" Expected: " + expectedValue + " Got: " + actualValue);
1451
} else if (verbose) {
1452
System.out.println(" Okay : " + name + " = " + actualValue);
1453
}
1454
}
1455
1456
private void checkResult(String name,
1457
boolean expectedValue,
1458
boolean actualValue) {
1459
if (expectedValue != actualValue) {
1460
errorHandling("Unexpected " + name + " value." +
1461
" Expected: " + expectedValue + " Got: " + actualValue);
1462
} else if (verbose) {
1463
System.out.println(" Okay : " + name + " = " + actualValue);
1464
}
1465
}
1466
1467
private void checkResult(String name,
1468
String expectedValue,
1469
String actualValue) {
1470
if (!expectedValue.equals(actualValue)) {
1471
errorHandling("Unexpected " + name + " value." +
1472
"\n\tExpected: \"" + expectedValue + "\"" +
1473
"\n\tGot: \"" + actualValue + "\"");
1474
} else if (verbose) {
1475
System.out.println(" Okay : " + name + " = \"" +
1476
actualValue + "\"");
1477
}
1478
}
1479
1480
private void checkResult(String name,
1481
int[] expectedValues,
1482
int[] actualValues) {
1483
if (!Arrays.equals(expectedValues, actualValues)) {
1484
errorHandling("Unexpected " + name + " value." +
1485
"\n\tExpected: " + toString(expectedValues) + "" +
1486
"\n\tGot: " + toString(actualValues) + "");
1487
} else if (verbose) {
1488
System.out.println(" Okay : " + name + " = " +
1489
toString(actualValues));
1490
}
1491
}
1492
1493
private void checkResult(String name,
1494
Object[] expectedValues,
1495
Object[] actualValues) {
1496
if (!Arrays.equals(expectedValues, actualValues)) {
1497
errorHandling("Unexpected " + name + " value." +
1498
"\n\tExpected: [" + toString(expectedValues) +
1499
"]\n\tGot: [" + toString(actualValues) + "]");
1500
} else if (verbose) {
1501
System.out.println(" Okay : " + name + " Reordered objects = [" +
1502
toString(actualValues) + "]");
1503
}
1504
}
1505
1506
private void errorHandling(String msg) {
1507
if (abort) {
1508
throw new RuntimeException("Error: " + msg);
1509
} else {
1510
error = true;
1511
System.err.println("**Error:" + msg);
1512
}
1513
}
1514
1515
private String toString(int[] values) {
1516
StringBuilder sb = new StringBuilder();
1517
for (int i = 0; i < values.length-1; i++) {
1518
sb.append((int)values[i]);
1519
sb.append(' ');
1520
}
1521
sb.append((int)values[values.length-1]);
1522
1523
return sb.toString();
1524
}
1525
1526
private String toString(byte[] values) {
1527
StringBuilder sb = new StringBuilder();
1528
for (int i = 0; i < values.length-1; i++) {
1529
sb.append((byte)values[i]);
1530
sb.append(' ');
1531
}
1532
sb.append((byte)values[values.length-1]);
1533
1534
return sb.toString();
1535
}
1536
1537
private String toString(Object[] values) {
1538
StringBuilder sb = new StringBuilder();
1539
String name;
1540
1541
for (int i = 0; i < values.length-1; i++) {
1542
if ((name = getStringName((String)values[i])) != null) {
1543
sb.append(name);
1544
sb.append(", ");
1545
} else {
1546
sb.append('"');
1547
sb.append((String)values[i]);
1548
sb.append("\", ");
1549
}
1550
}
1551
if ((name = getStringName((String)values[values.length-1])) != null) {
1552
sb.append(name);
1553
} else {
1554
sb.append('"');
1555
sb.append((String)values[values.length-1]);
1556
sb.append('\"');
1557
}
1558
1559
return sb.toString();
1560
}
1561
1562
private String getStringName(String str) {
1563
if (ArabicABC.equals(str)) return "ArabicABC";
1564
else if (Arabic123.equals(str)) return "Arabic123";
1565
else if (PArabicABC.equals(str)) return "ArabicABC(Presentation form)";
1566
else if (HebrewABC.equals(str)) return "HebrewABC";
1567
else if (KharoshthiABC.equals(str)) return "KharoshthiABC(RTL)";
1568
else if (Kharoshthi123.equals(str)) return "Kharoshthi123(RTL)";
1569
else if (NKoABC.equals(str)) return "NKoABC(RTL)";
1570
else if (NKo123.equals(str)) return "NKo123(RTL)";
1571
else if (OsmanyaABC.equals(str)) return "OsmanyaABC(LTR)";
1572
else if (Osmanya123.equals(str)) return "Osmanya123(LTR)";
1573
else return null;
1574
}
1575
1576
private String getFlagName(int flag) {
1577
if (flag == -2 || flag == 0x7e) return FLAGNAMES[0];
1578
else if (flag == -1 || flag == 0x7f) return FLAGNAMES[1];
1579
else if (flag == 0) return FLAGNAMES[2];
1580
else if (flag == 1) return FLAGNAMES[3];
1581
else return "Unknown(0x" + Integer.toHexString(flag) + ")";
1582
}
1583
1584
private String toReadableString(String str) {
1585
String s = str;
1586
1587
s = s.replaceAll(ArabicABC, "ArabicABC");
1588
s = s.replaceAll(Arabic123, "Arabic123");
1589
s = s.replaceAll(PArabicABC, "ArabicABC(Presentation form)");
1590
s = s.replaceAll(HebrewABC, "HebrewABC");
1591
s = s.replaceAll(KharoshthiABC, "KharoshthiABC");
1592
s = s.replaceAll(Kharoshthi123, "Kharoshthi123");
1593
s = s.replaceAll(NKoABC, "NKoABC");
1594
s = s.replaceAll(NKo123, "NKo123");
1595
s = s.replaceAll(OsmanyaABC, "OsmanyaABC");
1596
s = s.replaceAll(Osmanya123, "Osmanya123");
1597
1598
return s;
1599
}
1600
1601
private byte[] getLevels(Object[][] data) {
1602
int levelLength = data[0].length;
1603
byte[] array = new byte[levelLength];
1604
int textIndex = 0;
1605
1606
for (int i = 0; i < levelLength; i++) {
1607
array[i] = (byte)(((String)data[1][0]).charAt(textIndex) - '0');
1608
textIndex += ((String)data[0][i]).length();
1609
}
1610
1611
return array;
1612
}
1613
1614
1615
/* Bidi pubilc constants */
1616
private static final int[] FLAGS = {
1617
Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT, // -2 (0x7e in ICU4J)
1618
Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT, // -1 (0x7f in ICU4J)
1619
Bidi.DIRECTION_LEFT_TO_RIGHT, // 0
1620
Bidi.DIRECTION_RIGHT_TO_LEFT // 1
1621
};
1622
1623
/* Bidi pubilc constants names */
1624
private static final String[] FLAGNAMES = {
1625
"DIRECTION_DEFAULT_LEFT_TO_RIGHT", // -2
1626
"DIRECTION_DEFAULT_RIGHT_TO_LEFT", // -1
1627
"DIRECTION_LEFT_TO_RIGHT", // 0
1628
"DIRECTION_RIGHT_TO_LEFT", // 1
1629
};
1630
1631
/* Bidirectional Character Types */
1632
private static final char L = '\u200E';
1633
private static final char R = '\u202F';
1634
private static final char LRE = '\u202A';
1635
private static final char RLE = '\u202B';
1636
private static final char PDF = '\u202C';
1637
private static final char LRO = '\u202D';
1638
private static final char RLO = '\u202E';
1639
private static final char LRI = '\u2066';
1640
private static final char RLI = '\u2067';
1641
private static final char FSI = '\u2068';
1642
private static final char PDI = '\u2069';
1643
1644
/*
1645
* 0x05D0-0x05EA: [R] Hewbrew letters (Strong)
1646
* 0x0627-0x063A: [AL] Arabic letters (Strong)
1647
* 0x0660-0x0669: [AN] Arabic-Indic digits (Weak)
1648
* 0x07CA-0x07E7: [R] NKo letters (Strong)
1649
* 0x07C0-0x07C9: [R] NKo digits (Strong)
1650
* 0xFE50-0xFEFF: [AL] Arabic presentaion form (Strong)
1651
* 0x10480-0x1049D: [L] Osmanya letters (Strong)
1652
* 0x104A0-0x104A9: [L] Osmanya digits (Strong)
1653
* 0x10A10-0x10A33: [R] Kharoshthi letters (Strong)
1654
* 0x10A40-0x10A43: [R] Kharoshthi digits (Strong)
1655
*
1656
* 0x200E: [L] Left-to-right mark (Implicit, Strong)
1657
* 0x200F: [R] Right-to-left mark (Implicit, Strong)
1658
* 0x202A: [LRE] Left-to-right embedding (Explicit, Strong)
1659
* 0x202B: [RLE] Right-to-left embedding (Explicit, Strong)
1660
* 0x202C: [PDF] Pop directional formatting (Explicit, Weak)
1661
* 0x202D: [LRO] Left-to-right override (Explicit, Strong)
1662
* 0x202E: [RLO] Right-to-left override (Explicit, Strong)
1663
*/
1664
1665
/* Right-to-left */
1666
private static String ArabicABC = "\u0627\u0628\u0629";
1667
private static String Arabic123 = "\u0661\u0662\u0663";
1668
private static String PArabicABC = "\uFE97\uFE92\uFE8E";
1669
private static String HebrewABC = "\u05D0\u05D1\u05D2";
1670
private static String KharoshthiABC =
1671
new String(Character.toChars(0x10A10)) +
1672
new String(Character.toChars(0x10A11)) +
1673
new String(Character.toChars(0x10A12));
1674
private static String Kharoshthi123 =
1675
new String(Character.toChars(0x10A40)) +
1676
new String(Character.toChars(0x10A41)) +
1677
new String(Character.toChars(0x10A42));
1678
private static String NKoABC = "\u07CA\u07CB\u07CC";
1679
private static String NKo123 = "\u07C1\u07C2\u07C3";
1680
1681
/* Left-to-right */
1682
private static String OsmanyaABC =
1683
new String(Character.toChars(0x10480)) +
1684
new String(Character.toChars(0x10481)) +
1685
new String(Character.toChars(0x10482));
1686
private static String Osmanya123 =
1687
new String(Character.toChars(0x104A0)) +
1688
new String(Character.toChars(0x104A1)) +
1689
new String(Character.toChars(0x104A2));
1690
1691
/* --------------------------------------------------------------------- */
1692
1693
/*
1694
* Test data for Bidi(char[], ...) constructor and methods
1695
*/
1696
1697
/* Text for Bidi processing and its levels */
1698
private static String[][] data4Constructor1 = {
1699
/* For Text #0 */
1700
{"abc <ABC XYZ> xyz.",
1701
"000000000000000000", "000002222222000000", "000000000000000000",
1702
"000003333333000000", "000000000000000000",
1703
"222222222222222221", "222222222222222221", "222222222222222221",
1704
"222113333333112221", "222224444444222221",
1705
"000000000000000000", "000000000000000000", "222222222222222221"},
1706
1707
/* For Text #1 */
1708
{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",
1709
"000001111111000000", "000001111111000000", "000003333333000000",
1710
"000003333333000000", "000000000000000000",
1711
"222111111111112221", "222111111111112221", "222223333333222221",
1712
"222113333333112221", "222224444444222221",
1713
"000001111111000000", "000001111111000000", "222111111111112221"},
1714
1715
/* For Text #2 */
1716
{NKoABC + " <ABC XYZ> " + NKo123 + ".",
1717
"111000000000001110", "111112222222111110", "111002222222001110",
1718
"111113333333111110", "111004444444001110",
1719
"111112222222111111", "111112222222111111", "111112222222111111",
1720
"111111111111111111", "111114444444111111",
1721
"111112222222111111", "111000000000001110", "111112222222111111"},
1722
1723
/* For Text #3 */
1724
{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",
1725
"111111111222111110", "111111111222111110", "111003333444001110",
1726
"111113333333111110", "111004444444001110",
1727
"111111111222111111", "111111111222111111", "111113333444111111",
1728
"111111111111111111", "111114444444111111",
1729
"111111111222111111", "111111111222111110", "111111111222111111"},
1730
1731
/* For Text #4 */
1732
{"abc <" + NKoABC + " 123> xyz.",
1733
"000001111222000000", "000001111222000000", "000003333444000000",
1734
"000003333333000000", "000000000000000000",
1735
"222111111222112221", "222111111222112221", "222223333444222221",
1736
"222113333333112221", "222224444444222221",
1737
"000001111222000000", "000001111222000000", "222111111222112221"},
1738
1739
/* For Text #5 */
1740
{"abc <ABC " + NKo123 + "> xyz.",
1741
"000000000111000000", "000002221111000000", "000002222333000000",
1742
"000003333333000000", "000000000000000000",
1743
"222222221111112221", "222222221111112221", "222222222333222221",
1744
"222113333333112221", "222224444444222221",
1745
"000000000111000000", "000000000111000000", "222222221111112221"},
1746
1747
/* For Text #6 */
1748
{ArabicABC + " <" + NKoABC + " 123" + "> " + Arabic123 + ".",
1749
"111111111222112220", "111111111222112220", "111003333444002220",
1750
"111113333333112220", "111004444444002220",
1751
"111111111222112221", "111111111222112221", "111113333444112221",
1752
"111113333333112221", "111114444444112221",
1753
"111111111222112221", "111111111222112220", "111111111222112221"},
1754
1755
/* For Text #7 */
1756
{ArabicABC + " <XYZ " + NKoABC + "> " + Arabic123 + ".",
1757
"111000000111112220", "111112221111112220", "111002222333002220",
1758
"111113333333112220", "111004444444002220",
1759
"111112221111112221", "111112221111112221", "111112222333112221",
1760
"111113333333112221", "111114444444112221",
1761
"111112221111112221", "111000000111112220", "111112221111112221"},
1762
1763
/* For Text #8 */
1764
{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +
1765
Osmanya123 + ".",
1766
"000000001111111111111000000000", "000000001111111111111000000000",
1767
"000000003333333333333000000000", "000000003333333333333000000000",
1768
"000000000000000000000000000000",
1769
"222222111111111111111112222221", "222222111111111111111112222221",
1770
"222222223333333333333222222221", "222222113333333333333112222221",
1771
"222222224444444444444222222221",
1772
"000000001111111111111000000000", "000000001111111111111000000000",
1773
"222222111111111111111112222221"},
1774
1775
/* For Text #9 */
1776
{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +
1777
Kharoshthi123 + ".",
1778
"111111000000000000000001111110", "111111112222222222222111111110",
1779
"111111002222222222222001111110", "111111113333333333333111111110",
1780
"111111004444444444444001111110",
1781
"111111112222222222222111111111", "111111112222222222222111111111",
1782
"111111112222222222222111111111", "111111111111111111111111111111",
1783
"111111114444444444444111111111",
1784
"111111112222222222222111111111", "111111000000000000000001111110",
1785
"111111112222222222222111111111"},
1786
};
1787
1788
/* Golden data for baseIsLeftToRight() results */
1789
private static boolean[][] baseIsLTR4Constructor1 = {
1790
/* For Text #0 */
1791
{true, true, true, true, true,
1792
false, false, false, false, false,
1793
true, true, false},
1794
1795
/* For Text #1 */
1796
{true, true, true, true, true,
1797
false, false, false, false, false,
1798
true, true, false},
1799
1800
/* For Text #2 */
1801
{true, true, true, true, true,
1802
false, false, false, false, false,
1803
false, true, false},
1804
1805
/* For Text #3 */
1806
{true, true, true, true, true,
1807
false, false, false, false, false,
1808
false, true, false},
1809
1810
/* For Text #4 */
1811
{true, true, true, true, true,
1812
false, false, false, false, false,
1813
true, true, false},
1814
1815
/* For Text #5 */
1816
{true, true, true, true, true,
1817
false, false, false, false, false,
1818
true, true, false},
1819
1820
/* For Text #6 */
1821
{true, true, true, true, true,
1822
false, false, false, false, false,
1823
false, true, false},
1824
1825
/* For Text #7 */
1826
{true, true, true, true, true,
1827
false, false, false, false, false,
1828
false, true, false},
1829
1830
/* For Text #8 */
1831
{true, true, true, true, true,
1832
false, false, false, false, false,
1833
true, true, false},
1834
1835
/* For Text #9 */
1836
{true, true, true, true, true,
1837
false, false, false, false, false,
1838
false, true, false},
1839
};
1840
1841
/* Golden data for isLeftToRight() & isRightToLeft() results */
1842
private static boolean[][][] isLTR_isRTL4Constructor1 = {
1843
/* For Text #0 */
1844
/* isLeftToRight() results */
1845
{{true, false, true, false, true,
1846
false, false, false, false, false,
1847
true, true, false},
1848
/* isRightToLeft() results */
1849
{false, false, false, false, false,
1850
false, false, false, false, false,
1851
false, false, false}},
1852
1853
/* For Text #1 */
1854
/* isLeftToRight() results */
1855
{{false, false, false, false, true,
1856
false, false, false, false, false,
1857
false, false, false},
1858
/* isRightToLeft() results */
1859
{false, false, false, false, false,
1860
false, false, false, false, false,
1861
false, false, false}},
1862
1863
/* For Text #2 */
1864
/* isLeftToRight() results */
1865
{{false, false, false, false, false,
1866
false, false, false, false, false,
1867
false, false, false},
1868
/* isRightToLeft() results */
1869
{false, false, false, false, false,
1870
false, false, false, true, false,
1871
false, false, false}},
1872
1873
/* For Text #3 */
1874
/* isLeftToRight() results */
1875
{{false, false, false, false, false,
1876
false, false, false, false, false,
1877
false, false, false},
1878
/* isRightToLeft() results */
1879
{false, false, false, false, false,
1880
false, false, false, true, false,
1881
false, false, false}},
1882
1883
/* For Text #4 */
1884
/* isLeftToRight() results */
1885
{{false, false, false, false, true,
1886
false, false, false, false, false,
1887
false, false, false},
1888
/* isRightToLeft() results */
1889
{false, false, false, false, false,
1890
false, false, false, false, false,
1891
false, false, false}},
1892
1893
/* For Text #5 */
1894
/* isLeftToRight() results */
1895
{{false, false, false, false, true,
1896
false, false, false, false, false,
1897
false, false, false},
1898
/* isRightToLeft() results */
1899
{false, false, false, false, false,
1900
false, false, false, false, false,
1901
false, false, false}},
1902
1903
/* For Text #6 */
1904
/* isLeftToRight() results */
1905
{{false, false, false, false, false,
1906
false, false, false, false, false,
1907
false, false, false},
1908
/* isRightToLeft() results */
1909
{false, false, false, false, false,
1910
false, false, false, false, false,
1911
false, false, false}},
1912
1913
/* For Text #7 */
1914
/* isLeftToRight() results */
1915
{{false, false, false, false, false,
1916
false, false, false, false, false,
1917
false, false, false},
1918
/* isRightToLeft() results */
1919
{false, false, false, false, false,
1920
false, false, false, false, false,
1921
false, false, false}},
1922
1923
/* For Text #8 */
1924
/* isLeftToRight() results */
1925
{{false, false, false, false, true,
1926
false, false, false, false, false,
1927
false, false, false},
1928
/* isRightToLeft() results */
1929
{false, false, false, false, false,
1930
false, false, false, false, false,
1931
false, false, false}},
1932
1933
/* For Text #9 */
1934
/* isLeftToRight() results */
1935
{{false, false, false, false, false,
1936
false, false, false, false, false,
1937
false, false, false},
1938
/* isRightToLeft() results */
1939
{false, false, false, false, false,
1940
false, false, false, true, false,
1941
false, false, false}},
1942
};
1943
1944
/* --------------------------------------------------------------------- */
1945
1946
/*
1947
* Test data for Bidi(String, int) constructor and methods
1948
*/
1949
1950
/* Text for Bidi processing and its levels */
1951
private static String[][] data4Constructor2 = {
1952
/* For Text #0 */
1953
{" ABC 123.",
1954
"000000000", "000000000", "000000000", "122222221"},
1955
1956
/* For Text #1 */
1957
{" ABC " + HebrewABC + " " + NKo123 + " 123.",
1958
"00000111111112220", "00000111111112220", "00000111111112220",
1959
"12221111111112221"},
1960
1961
/* For Text #2 */
1962
{" ABC " + ArabicABC + " " + Arabic123 + " 123.",
1963
"00000111122212220", "00000111122212220", "00000111122212220",
1964
"12221111122212221"},
1965
1966
/* For Text #3 */
1967
{" " + NKoABC + " ABC 123 " + NKo123 + ".",
1968
"11111222222211111", "11111222222211111", "01110000000001110",
1969
"11111222222211111"},
1970
1971
/* For Text #4 */
1972
{" " + ArabicABC + " ABC 123 " + Arabic123 + ".",
1973
"11111222222212221", "11111222222212221", "01110000000002220",
1974
"11111222222212221"},
1975
1976
/* For Text #5 */
1977
{" " + HebrewABC + " " + NKo123 + ".",
1978
"111111111", "111111111", "011111110", "111111111"},
1979
1980
/* For Text #6 */
1981
{" " + ArabicABC + " " + Arabic123 + ".",
1982
"111112221", "111112221", "011112220", "111112221"},
1983
1984
/* For Text #7 */
1985
{" " + KharoshthiABC + " " + Kharoshthi123 + ".",
1986
"111111111111111", "111111111111111", "011111111111110",
1987
"111111111111111"},
1988
1989
/* For Text #8 */
1990
{L + HebrewABC + " " + NKo123 + ".",
1991
"011111110", "011111110", "011111110", "211111111"},
1992
1993
/* For Text #9 */
1994
{R + "ABC " + Osmanya123 + ".",
1995
"000000000000", "000000000000", "000000000000", "122222222221"},
1996
1997
/* For Text #10 */
1998
{"ABC " + PArabicABC + " " + PArabicABC + " 123",
1999
"000011111111222", "000011111111222", "000011111111222",
2000
"222111111111222"},
2001
2002
/* For Text #11 */
2003
{RLE + "ABC " + HebrewABC + " " + NKo123 + "." + PDF,
2004
"22221111111110", "22221111111110", "22221111111110",
2005
"44443333333331"},
2006
2007
/* For Text #12 */
2008
{"He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF + ".\"",
2009
"000000000222211111111000", "000000000222211111111000",
2010
"000000000222211111111000", "222222211444433333333111"},
2011
2012
/* For Text #13 */
2013
{LRO + "He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF +
2014
".\"" + PDF,
2015
"22222222224444333333332220", "22222222224444333333332220",
2016
"22222222224444333333332220", "22222222224444333333332221"},
2017
2018
/* For Text #14 */
2019
{LRO + "He said \"" + RLE + "ABC " + HebrewABC + " " + NKo123 + PDF +
2020
".\"", // PDF missing
2021
"2222222222444433333333222", "2222222222444433333333222",
2022
"2222222222444433333333222", "2222222222444433333333222"},
2023
2024
/* For Text #15 */
2025
{"Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +
2026
" " + NKo123 + PDF + "\"" + PDF + "'?",
2027
"0000000000000222222222244443333333322000",
2028
"0000000000000222222222244443333333322000",
2029
"0000000000000222222222244443333333322000",
2030
"2222222222222222222222244443333333322111"},
2031
2032
/* For Text #16 */
2033
{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +
2034
HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?" + PDF,
2035
"111111111111112222222222444433333333221110",
2036
"111111111111112222222222444433333333221110",
2037
"111111111111112222222222444433333333221110",
2038
"333333333333334444444444666655555555443331"},
2039
2040
/* For Text #17 */
2041
{RLO + "Did you say '" + LRE + "he said \"" + RLE + "ABC " +
2042
HebrewABC + " " + NKo123 + PDF + "\"" + PDF + "'?", // PDF missing
2043
"11111111111111222222222244443333333322111",
2044
"11111111111111222222222244443333333322111",
2045
"11111111111111222222222244443333333322111",
2046
"33333333333333444444444466665555555544333"},
2047
2048
/* For Text #18 */
2049
{" ABC (" + ArabicABC + " " + Arabic123 + ") 123.",
2050
"0000001111222002220", "0000001111222002220",
2051
"0000001111222002220", "1222111111222112221"},
2052
2053
/* For Text #19 */
2054
{" " + HebrewABC + " (ABC 123) " + NKo123 + ".",
2055
"1111112222222111111", "1111112222222111111",
2056
"0111000000000001110", "1111112222222111111"},
2057
2058
/* For Text #20 */
2059
{" He said \"" + RLE + "ABC " + NKoABC + " " + NKo123 + PDF + ".\" ",
2060
"00000000002222111111110000", "00000000002222111111110000",
2061
"00000000002222111111110000", "12222222114444333333331111"},
2062
2063
/* For Text #21 */
2064
{" Did you say '" + LRE + "he said \"" + RLE + "ABC " + HebrewABC +
2065
" " + NKo123 + PDF + "\"" + PDF + "'? ",
2066
"000000000000002222222222444433333333220000",
2067
"000000000000002222222222444433333333220000",
2068
"000000000000002222222222444433333333220000",
2069
"122222222222222222222222444433333333221111"},
2070
2071
/* For Text #22 */
2072
{RLE + OsmanyaABC + " " + KharoshthiABC + " " + Kharoshthi123 + "." +
2073
PDF,
2074
"22222221111111111111110", "22222221111111111111110",
2075
"22222221111111111111110", "44444443333333333333331"},
2076
2077
/* For Text #23 */
2078
{" ABC (" + Arabic123 + " " + ArabicABC + ") 123.",
2079
"0000002221111002220", "0000002221111002220",
2080
"0000002221111002220", "1222112221111112221"},
2081
2082
/* For Text #24 */
2083
{" 123 (" + ArabicABC + " " + Arabic123 + ") ABC.",
2084
"1222111111222112221", "1222111111222112221",
2085
"0000001111222000000", "1222111111222112221"},
2086
2087
/* For Text #25 */
2088
{" 123 (" + Arabic123 + " " + ArabicABC + ") ABC.",
2089
"1222112221111112221", "1222112221111112221",
2090
"0000002221111000000", "1222112221111112221"},
2091
2092
/* For Text #26 */
2093
{" " + ArabicABC + " (ABC 123) " + Arabic123 + ".",
2094
"1111112222222112221", "1111112222222112221",
2095
"0111000000000002220", "1111112222222112221"},
2096
2097
/* For Text #27 */
2098
{" " + ArabicABC + " (123 ABC) " + Arabic123 + ".",
2099
"1111112221222112221", "1111112221222112221",
2100
"0111002220000002220", "1111112221222112221"},
2101
2102
/* For Text #28 */
2103
{" " + Arabic123 + " (ABC 123) " + ArabicABC + ".",
2104
"0222000000000001110", "0222000000000001110",
2105
"0222000000000001110", "1222112222222111111"},
2106
2107
/* For Text #29 */
2108
{" " + Arabic123 + " (123 ABC) " + ArabicABC + ".",
2109
"0222000000000001110", "0222000000000001110",
2110
"0222000000000001110", "1222112221222111111"},
2111
2112
/* For Text #30 */
2113
{RLI + "ABC " + ArabicABC + " " + ArabicABC + "." + PDI,
2114
"02221111111110", "14443333333331",
2115
"02221111111110", "14443333333331"},
2116
2117
/* For Text #31 */
2118
{"ABC abc \"" + RLI + "IJK " + ArabicABC + " " + ArabicABC + PDI +
2119
".\" \"" + RLI + ArabicABC + " " + ArabicABC + PDI + ",\" xyz XYZ.",
2120
"0000000000222111111110000001111111000000000000",
2121
"0000000000222111111110000001111111000000000000",
2122
"0000000000222111111110000001111111000000000000",
2123
"2222222222444333333332222223333333222222222221"},
2124
2125
/* For Text #32 */
2126
{ArabicABC + " " + ArabicABC + " '" + LRI + "abc def \"" + RLI +
2127
"xyz " + ArabicABC + " " + ArabicABC + PDI + "\"" + PDI + "'?",
2128
"111111111122222222224443333333322111",
2129
"111111111122222222224443333333322111",
2130
"111111100022222222224443333333322000",
2131
"111111111122222222224443333333322111"},
2132
2133
/* For Text #33 */
2134
{FSI + Arabic123 + " ABC " + ArabicABC + " " + ArabicABC + "." + PDI,
2135
"044422222333333320", "144422222333333321",
2136
"044422222333333320", "144422222333333321"},
2137
2138
/* For Text #34 */
2139
{FSI + "123 ABC " + ArabicABC + " " + ArabicABC + "." + PDI,
2140
"022222222333333320", "122222222333333321",
2141
"022222222333333320", "122222222333333321"},
2142
2143
/* For Text #35 */
2144
{FSI + "123 " + ArabicABC + " ABC " + ArabicABC + "." + PDI,
2145
"022211111222111110", "144433333444333331",
2146
"022211111222111110", "144433333444333331"},
2147
2148
/* For Text #36 */
2149
{FSI + Arabic123 + " " + ArabicABC + " ABC " + ArabicABC + "." + PDI,
2150
"022211111222111110", "144433333444333331",
2151
"022211111222111110", "144433333444333331"},
2152
2153
/* For Text #37 */
2154
{FSI + Arabic123 + " 123." + PDI,
2155
"0444222220", "1444222221", "0444222220", "1444222221"},
2156
2157
/* For Text #38 */
2158
{FSI + "123 " + Arabic123 + "." + PDI,
2159
"0222244420", "1222244421", "0222244420", "1222244421"},
2160
};
2161
2162
/* Golden data for baseIsLeftToRight() results */
2163
private static boolean[][] baseIsLTR4Constructor2 = {
2164
/* For Text #0 - $4 */
2165
{true, true, true, false},
2166
{true, true, true, false},
2167
{true, true, true, false},
2168
{false, false, true, false},
2169
{false, false, true, false},
2170
2171
/* For Text #5 - $9 */
2172
{false, false, true, false},
2173
{false, false, true, false},
2174
{false, false, true, false},
2175
{true, true, true, false},
2176
{true, true, true, false},
2177
2178
/* For Text #10 - $14 */
2179
{true, true, true, false},
2180
{true, true, true, false},
2181
{true, true, true, false},
2182
{true, true, true, false},
2183
{true, true, true, false},
2184
2185
/* For Text #15 - $19 */
2186
{true, true, true, false},
2187
{true, true, true, false},
2188
{true, true, true, false},
2189
{true, true, true, false},
2190
{false, false, true, false},
2191
2192
/* For Text #20 - $24 */
2193
{true, true, true, false},
2194
{true, true, true, false},
2195
{true, true, true, false},
2196
{true, true, true, false},
2197
{false, false, true, false},
2198
2199
/* For Text #25 - $29 */
2200
{false, false, true, false},
2201
{false, false, true, false},
2202
{false, false, true, false},
2203
{true, true, true, false},
2204
{true, true, true, false},
2205
2206
/* For Text #30 - $34 */
2207
{true, false, true, false},
2208
{true, true, true, false},
2209
{false, false, true, false},
2210
{true, false, true, false},
2211
{true , false, true, false},
2212
2213
/* For Text #35 - $38 */
2214
{true, false, true, false},
2215
{true, false, true, false},
2216
{true, false, true, false},
2217
{true, false, true, false},
2218
};
2219
2220
/* Golden data for isLeftToRight() & isRightToLeft() results */
2221
private static boolean[][][] isLTR_isRTL4Constructor2 = {
2222
/* isLeftToRight() results & isRightToLeft() results */
2223
/* For Text #0 - $4 */
2224
{{true, true, true, false}, {false, false, false, false}},
2225
{{false, false, false, false}, {false, false, false, false}},
2226
{{false, false, false, false}, {false, false, false, false}},
2227
{{false, false, false, false}, {false, false, false, false}},
2228
{{false, false, false, false}, {false, false, false, false}},
2229
2230
/* For Text #5 - $9 */
2231
{{false, false, false, false}, {true, true, false, true }},
2232
{{false, false, false, false}, {false, false, false, false}},
2233
{{false, false, false, false}, {true, true, false, true }},
2234
{{false, false, false, false}, {false, false, false, false}},
2235
{{true, true, true, false}, {false, false, false, false}},
2236
2237
/* For Text #10 - $14 */
2238
{{false, false, false, false}, {false, false, false, false}},
2239
{{false, false, false, false}, {false, false, false, false}},
2240
{{false, false, false, false}, {false, false, false, false}},
2241
{{false, false, false, false}, {false, false, false, false}},
2242
{{false, false, false, false}, {false, false, false, false}},
2243
2244
/* For Text #15 - $19 */
2245
{{false, false, false, false}, {false, false, false, false}},
2246
{{false, false, false, false}, {false, false, false, false}},
2247
{{false, false, false, false}, {false, false, false, false}},
2248
{{false, false, false, false}, {false, false, false, false}},
2249
{{false, false, false, false}, {false, false, false, false}},
2250
2251
/* For Text #20 - $24 */
2252
{{false, false, false, false}, {false, false, false, false}},
2253
{{false, false, false, false}, {false, false, false, false}},
2254
{{false, false, false, false}, {false, false, false, false}},
2255
{{false, false, false, false}, {false, false, false, false}},
2256
{{false, false, false, false}, {false, false, false, false}},
2257
2258
/* For Text #25 - $29 */
2259
{{false, false, false, false}, {false, false, false, false}},
2260
{{false, false, false, false}, {false, false, false, false}},
2261
{{false, false, false, false}, {false, false, false, false}},
2262
{{false, false, false, false}, {false, false, false, false}},
2263
{{false, false, false, false}, {false, false, false, false}},
2264
2265
/* For Text #30 - $34 */
2266
{{false, false, false, false}, {false, false, false, false}},
2267
{{false, false, false, false}, {false, false, false, false}},
2268
{{false, false, false, false}, {false, false, false, false}},
2269
{{false, false, false, false}, {false, false, false, false}},
2270
{{false, false, false, false}, {false, false, false, false}},
2271
2272
/* For Text #35 - $37 */
2273
{{false, false, false, false}, {false, false, false, false}},
2274
{{false, false, false, false}, {false, false, false, false}},
2275
{{false, false, false, false}, {false, false, false, false}},
2276
{{false, false, false, false}, {false, false, false, false}},
2277
};
2278
2279
/* Golden data for requiresBidi() results */
2280
private static boolean[] requiresBidi4Constructor2 = {
2281
/* For Text #0 - $9 */
2282
false, true, true, true, true,
2283
true, true, true, true, false,
2284
2285
/* For Text #10 - $19 */
2286
true, true, true, true, true,
2287
true, true, true, true, true,
2288
2289
/* For Text #20 - $29 */
2290
true, true, true, true, true,
2291
true, true, true, true, true,
2292
2293
/* For Text #30 - $37 */
2294
true, true, true, true, true,
2295
true, true, true, true,
2296
};
2297
2298
/* --------------------------------------------------------------------- */
2299
2300
/*
2301
* Test data for Bidi(char[], ...) constructor and methods
2302
*/
2303
2304
/* Enbeddings */
2305
private static byte[][][] emb4Constructor3 = {
2306
/* Embeddings for paragraphs which don't include surrogate pairs. */
2307
{{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
2308
{0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0},
2309
{0, 0, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, 0, 0, 0, 0, 0, 0},
2310
{0, 0, 0, 0, 0, -4, -4, -4, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0}},
2311
2312
/* Embeddings for paragraphs which include surrogate pairs. */
2313
{{ 0, 0, 0, 0, 0, 0, 0, 0,
2314
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2315
0, 0, 0, 0, 0, 0, 0, 0, 0},
2316
{ 0, 0, 0, 0, 0, 0, 0, 0,
2317
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2318
0, 0, 0, 0, 0, 0, 0, 0, 0},
2319
{ 0, 0, 0, 0, 0, 0, 0, 0,
2320
-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
2321
0, 0, 0, 0, 0, 0, 0, 0, 0},
2322
{ 0, 0, 0, 0, 0, 0, 0, 0,
2323
-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
2324
0, 0, 0, 0, 0, 0, 0, 0, 0}},
2325
};
2326
2327
/* Text for Bidi processing and its levels */
2328
private static String[][] data4Constructor3 = {
2329
/* For Text #0 */
2330
{"abc <ABC XYZ> xyz.",
2331
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2332
"000002222222000000", "000000000000000000",
2333
"000003333333000000", "000000000000000000",
2334
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2335
"222222222222222221", "222222222222222221",
2336
"222113333333112221", "222224444444222221",
2337
/* DIRECTION_LEFT_TO_RIGHT */
2338
"000002222222000000", "000000000000000000",
2339
"000003333333000000", "000000000000000000",
2340
/* DIRECTION_RIGHT_TO_LEFT */
2341
"222222222222222221", "222222222222222221",
2342
"222113333333112221", "222224444444222221"},
2343
2344
/* For Text #1 */
2345
{"ABC <" + HebrewABC + " " + NKo123 + "> XYZ.",
2346
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2347
"000001111111000000", "000003333333000000",
2348
"000003333333000000", "000000000000000000",
2349
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2350
"222111111111112221", "222223333333222221",
2351
"222113333333112221", "222224444444222221",
2352
/* DIRECTION_LEFT_TO_RIGHT */
2353
"000001111111000000", "000003333333000000",
2354
"000003333333000000", "000000000000000000",
2355
/* DIRECTION_RIGHT_TO_LEFT */
2356
"222111111111112221", "222223333333222221",
2357
"222113333333112221", "222224444444222221"},
2358
2359
/* For Text #2 */
2360
{NKoABC + " <ABC XYZ> " + NKo123 + ".",
2361
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2362
"111112222222111111", "111112222222111111",
2363
"111111111111111111", "111114444444111111",
2364
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2365
"111112222222111111", "111112222222111111",
2366
"111111111111111111", "111114444444111111",
2367
/* DIRECTION_LEFT_TO_RIGHT */
2368
"111112222222111110", "111002222222001110",
2369
"111113333333111110", "111004444444001110",
2370
/* DIRECTION_RIGHT_TO_LEFT */
2371
"111112222222111111", "111112222222111111",
2372
"111111111111111111", "111114444444111111"},
2373
2374
/* For Text #3 */
2375
{HebrewABC + " <" + ArabicABC + " " + Arabic123 + "> " + NKo123 + ".",
2376
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2377
"111111111222111111", "111113333444111111",
2378
"111111111111111111", "111114444444111111",
2379
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2380
"111111111222111111", "111113333444111111",
2381
"111111111111111111", "111114444444111111",
2382
/* DIRECTION_LEFT_TO_RIGHT */
2383
"111111111222111110", "111003333444001110",
2384
"111113333333111110", "111004444444001110",
2385
/* DIRECTION_RIGHT_TO_LEFT */
2386
"111111111222111111", "111113333444111111",
2387
"111111111111111111", "111114444444111111"},
2388
2389
/* For Text #4 */
2390
{"abc <123 456> xyz.",
2391
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2392
"000002221222000000", "000000000000000000",
2393
"000003333333000000", "000000000000000000",
2394
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2395
"222222222222222221", "222222222222222221",
2396
"222113333333112221", "222224444444222221",
2397
/* DIRECTION_LEFT_TO_RIGHT */
2398
"000002221222000000", "000000000000000000",
2399
"000003333333000000", "000000000000000000",
2400
/* DIRECTION_RIGHT_TO_LEFT */
2401
"222222222222222221", "222222222222222221",
2402
"222113333333112221", "222224444444222221"},
2403
2404
/* For Text #5 */
2405
{OsmanyaABC + " <" + KharoshthiABC + " " + Kharoshthi123 + "> " +
2406
Osmanya123 + ".",
2407
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2408
"000000001111111111111000000000", "000000003333333333333000000000",
2409
"000000003333333333333000000000", "000000000000000000000000000000",
2410
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2411
"222222111111111111111112222221", "222222223333333333333222222221",
2412
"222222113333333333333112222221", "222222224444444444444222222221",
2413
/* DIRECTION_LEFT_TO_RIGHT */
2414
"000000001111111111111000000000", "000000003333333333333000000000",
2415
"000000003333333333333000000000", "000000000000000000000000000000",
2416
/* DIRECTION_RIGHT_TO_LEFT */
2417
"222222111111111111111112222221", "222222223333333333333222222221",
2418
"222222113333333333333112222221", "222222224444444444444222222221"},
2419
2420
/* For Text #6 */
2421
{KharoshthiABC + " <" + OsmanyaABC + " " + Osmanya123 + "> " +
2422
Kharoshthi123 + ".",
2423
/* DIRECTION_DEFAULT_LEFT_TO_RIGHT */
2424
"111111112222222222222111111111", "111111112222222222222111111111",
2425
"111111111111111111111111111111", "111111114444444444444111111111",
2426
/* DIRECTION_DEFAULT_RIGHT_TO_LEFT */
2427
"111111112222222222222111111111", "111111112222222222222111111111",
2428
"111111111111111111111111111111", "111111114444444444444111111111",
2429
/* DIRECTION_LEFT_TO_RIGHT */
2430
"111111112222222222222111111110", "111111002222222222222001111110",
2431
"111111113333333333333111111110", "111111004444444444444001111110",
2432
/* DIRECTION_RIGHT_TO_LEFT */
2433
"111111112222222222222111111111", "111111112222222222222111111111",
2434
"111111111111111111111111111111", "111111114444444444444111111111"},
2435
};
2436
2437
/* Golden data for baseIsLeftToRight() results */
2438
private static boolean[][] baseIsLTR4Constructor3 = {
2439
/* For Text #0 */
2440
{true, true, true, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT
2441
true, true, true, true, // DIRECTION_DEFAULT_RIGHT_TO_LEFT
2442
true, true, true, true, // DIRECTION_LEFT_TO_RIGHT
2443
false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT
2444
2445
/* For Text #1 */
2446
{true, true, true, true,
2447
true, true, true, true,
2448
true, true, true, true,
2449
false, false, false, false},
2450
2451
/* For Text #2 */
2452
{false, false, false, false,
2453
false, false, false, false,
2454
true, true, true, true,
2455
false, false, false, false},
2456
2457
/* For Text #3 */
2458
{false, false, false, false,
2459
false, false, false, false,
2460
true, true, true, true,
2461
false, false, false, false},
2462
2463
/* For Text #4 */
2464
{true, true, true, true,
2465
true, true, true, true,
2466
true, true, true, true,
2467
false, false, false, false},
2468
2469
/* For Text #5 */
2470
{true, true, true, true,
2471
true, true, true, true,
2472
true, true, true, true,
2473
false, false, false, false},
2474
2475
/* For Text #6 */
2476
{false, false, false, false,
2477
false, false, false, false,
2478
true, true, true, true,
2479
false, false, false, false},
2480
};
2481
2482
/* Golden data for isLeftToRight() & isRightToLeft() results */
2483
private static boolean[][][] isLTR_isRTL4Constructor3 = {
2484
/* For Text #0 */
2485
/* isLeftToRight() results */
2486
{{false, true, false, true, // DIRECTION_DEFAULT_LEFT_TO_RIGHT
2487
false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT
2488
false, true, false, true, // DIRECTION_LEFT_TO_RIGHT
2489
false, false, false, false}, // DIRECTION_RIGHT_TO_LEFT
2490
/* isRightToLeft() results */
2491
{false, false, false, false, // DIRECTION_DEFAULT_LEFT_TO_RIGHT
2492
false, false, false, false, // DIRECTION_DEFAULT_RIGHT_TO_LEFT
2493
false, false, false, false, // DIRECTION_LEFT_TO_RIGHT
2494
false, false, false, false}}, // DIRECTION_RIGHT_TO_LEFTT
2495
2496
/* For Text #1 */
2497
/* isLeftToRight() results */
2498
{{false, false, false, true,
2499
false, false, false, false,
2500
false, false, false, true,
2501
false, false, false, false},
2502
/* isRightToLeft() results */
2503
{false, false, false, false,
2504
false, false, false, false,
2505
false, false, false, false,
2506
false, false, false, false}},
2507
2508
/* For Text #2 */
2509
/* isLeftToRight() results */
2510
{{false, false, false, false,
2511
false, false, false, false,
2512
false, false, false, false,
2513
false, false, false, false},
2514
/* isRightToLeft() results */
2515
{false, false, true, false,
2516
false, false, true, false,
2517
false, false, false, false,
2518
false, false, true, false}},
2519
2520
/* For Text #3 */
2521
/* isLeftToRight() results */
2522
{{false, false, false, false,
2523
false, false, false, false,
2524
false, false, false, false,
2525
false, false, false, false},
2526
/* isRightToLeft() results */
2527
{false, false, true, false,
2528
false, false, true, false,
2529
false, false, false, false,
2530
false, false, true, false}},
2531
2532
/* For Text #4 */
2533
/* isLeftToRight() results */
2534
{{false, true, false, true,
2535
false, false, false, false,
2536
false, true, false, true,
2537
false, false, false, false },
2538
/* isRightToLeft() results */
2539
{false, false, false, false,
2540
false, false, false, false,
2541
false, false, false, false,
2542
false, false, false, false}},
2543
2544
/* For Text #5 */
2545
/* isLeftToRight() results */
2546
{{false, false, false, true,
2547
false, false, false, false,
2548
false, false, false, true,
2549
false, false, false, false},
2550
/* isRightToLeft() results */
2551
{false, false, false, false,
2552
false, false, false, false,
2553
false, false, false, false,
2554
false, false, false, false}},
2555
2556
/* For Text #6 */
2557
/* isLeftToRight() results */
2558
{{false, false, false, false,
2559
false, false, false, false,
2560
false, false, false, false,
2561
false, false, false, false},
2562
/* isRightToLeft() results */
2563
{false, false, true, false,
2564
false, false, true, false,
2565
false, false, false, false,
2566
false, false, true, false}},
2567
};
2568
2569
/* --------------------------------------------------------------------- */
2570
2571
/*
2572
* Test data for reorderVisually() methods
2573
*/
2574
2575
private static Object[][][] data4reorderVisually = {
2576
{{"ABC", " ", "abc", " ", ArabicABC, "."}, // Original text
2577
{"000000001110"}, // levels
2578
{"ABC", " ", "abc", " ", ArabicABC, "."}}, // Reordered text
2579
2580
{{"ABC", " ", HebrewABC, " ", NKoABC, "."},
2581
{"222111111111"},
2582
{".", NKoABC, " ", HebrewABC, " ", "ABC"}},
2583
2584
{{OsmanyaABC, " ", HebrewABC, " ", KharoshthiABC, "."},
2585
{"222222111111111111"},
2586
{".", KharoshthiABC, " ", HebrewABC, " ", OsmanyaABC,}},
2587
2588
{{"ABC", " ", Osmanya123, " ", "\"", OsmanyaABC, " ", Kharoshthi123,
2589
" ", KharoshthiABC, ".", "\""},
2590
{"0000000000002222221111111111111100"},
2591
{"ABC", " ", Osmanya123, " ", "\"", KharoshthiABC, " ", Kharoshthi123,
2592
" ", OsmanyaABC, ".", "\""}},
2593
};
2594
2595
}
2596
2597