]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/transrt.cpp
ICU-6.2.6.tar.gz
[apple/icu.git] / icuSources / test / intltest / transrt.cpp
1 /*
2 **********************************************************************
3 * Copyright (C) 2000-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 05/23/00 aliu Creation.
8 **********************************************************************
9 */
10
11 #include "unicode/utypes.h"
12
13 #if !UCONFIG_NO_TRANSLITERATION
14
15 #include "unicode/translit.h"
16 #include "rbt.h"
17 #include "unicode/calendar.h"
18 #include "unicode/uniset.h"
19 #include "unicode/uchar.h"
20 #include "unicode/normlzr.h"
21 #include "unicode/uchar.h"
22 #include "unicode/parseerr.h"
23 #include "unicode/usetiter.h"
24 #include "unicode/putil.h"
25 #include "unicode/uversion.h"
26 #include "unicode/locid.h"
27 #include "unicode/ulocdata.h"
28 #include "unicode/utf8.h"
29 #include "putilimp.h"
30 #include "cmemory.h"
31 #include "transrt.h"
32 #include "testutil.h"
33 #include <string.h>
34 #include <stdio.h>
35
36 #define CASE(id,test) case id: \
37 name = #test; \
38 if (exec) { \
39 logln(#test "---"); \
40 logln((UnicodeString)""); \
41 UDate t = uprv_getUTCtime(); \
42 test(); \
43 t = uprv_getUTCtime() - t; \
44 logln((UnicodeString)#test " took " + t/U_MILLIS_PER_DAY + " seconds"); \
45 } \
46 break
47
48 #define EXHAUSTIVE(id,test) case id: \
49 if(quick==FALSE){ \
50 name = #test; \
51 if (exec){ \
52 logln(#test "---"); \
53 logln((UnicodeString)""); \
54 test(); \
55 } \
56 }else{ \
57 name=""; \
58 } \
59 break
60 void
61 TransliteratorRoundTripTest::runIndexedTest(int32_t index, UBool exec,
62 const char* &name, char* /*par*/) {
63 switch (index) {
64 CASE(0, TestCyrillic);
65 // CASE(0,TestKana);
66 CASE(1,TestHiragana);
67 CASE(2,TestKatakana);
68 CASE(3,TestJamo);
69 CASE(4,TestHangul);
70 CASE(5,TestGreek);
71 CASE(6,TestGreekUNGEGN);
72 CASE(7,Testel);
73 CASE(8,TestDevanagariLatin);
74 CASE(9,TestInterIndic);
75 CASE(10, TestHebrew);
76 CASE(11, TestArabic);
77 CASE(12, TestHan);
78 default: name = ""; break;
79 }
80 }
81
82 //--------------------------------------------------------------------
83 // Time bomb - allows temporary behavior that expires at a given
84 // release
85 //--------------------------------------------------------------------
86 /*
87 static const UVersionInfo ICU_30 = {3,0,0,0};
88
89 static UBool isICUVersionAtLeast(const UVersionInfo x) {
90 UVersionInfo v;
91 u_getVersion(v);
92 return (uprv_memcmp(v, x, U_MAX_VERSION_LENGTH) >= 0);
93 }
94 */
95
96 //--------------------------------------------------------------------
97 // TransliteratorPointer
98 //--------------------------------------------------------------------
99
100 /**
101 * A transliterator pointer wrapper that deletes the contained
102 * pointer automatically when the wrapper goes out of scope.
103 * Sometimes called a "janitor" or "smart pointer".
104 */
105 class TransliteratorPointer {
106 Transliterator* t;
107 // disallowed:
108 TransliteratorPointer(const TransliteratorPointer& rhs);
109 TransliteratorPointer& operator=(const TransliteratorPointer& rhs);
110 public:
111 TransliteratorPointer(Transliterator* adopted) {
112 t = adopted;
113 }
114 ~TransliteratorPointer() {
115 delete t;
116 }
117 inline Transliterator* operator->() { return t; }
118 inline operator const Transliterator*() const { return t; }
119 inline operator Transliterator*() { return t; }
120 };
121
122 //--------------------------------------------------------------------
123 // Legal
124 //--------------------------------------------------------------------
125
126 class Legal {
127 public:
128 Legal() {}
129 virtual ~Legal() {}
130 virtual UBool is(const UnicodeString& /*sourceString*/) const {return TRUE;}
131 };
132
133 class LegalJamo : public Legal {
134 // any initial must be followed by a medial (or initial)
135 // any medial must follow an initial (or medial)
136 // any final must follow a medial (or final)
137 public:
138 LegalJamo() {}
139 virtual ~LegalJamo() {}
140 virtual UBool is(const UnicodeString& sourceString) const;
141 int getType(UChar c) const;
142 };
143
144 UBool LegalJamo::is(const UnicodeString& sourceString) const {
145 int t;
146 UnicodeString decomp;
147 UErrorCode ec = U_ZERO_ERROR;
148 Normalizer::decompose(sourceString, FALSE, 0, decomp, ec);
149 if (U_FAILURE(ec)) {
150 return FALSE;
151 }
152 for (int i = 0; i < decomp.length(); ++i) { // don't worry about surrogates
153 switch (getType(decomp.charAt(i))) {
154 case 0: t = getType(decomp.charAt(i+1));
155 if (t != 0 && t != 1) { return FALSE; }
156 break;
157 case 1: t = getType(decomp.charAt(i-1));
158 if (t != 0 && t != 1) { return FALSE; }
159 break;
160 case 2: t = getType(decomp.charAt(i-1));
161 if (t != 1 && t != 2) { return FALSE; }
162 break;
163 }
164 }
165 return TRUE;
166 }
167
168 int LegalJamo::getType(UChar c) const {
169 if (0x1100 <= c && c <= 0x1112)
170 return 0;
171 else if (0x1161 <= c && c <= 0x1175)
172 return 1;
173 else if (0x11A8 <= c && c <= 0x11C2)
174 return 2;
175 return -1; // other
176 }
177
178 class LegalGreek : public Legal {
179 UBool full;
180 public:
181 LegalGreek(UBool _full) { full = _full; }
182 virtual ~LegalGreek() {}
183
184 virtual UBool is(const UnicodeString& sourceString) const;
185
186 static UBool isVowel(UChar c);
187
188 static UBool isRho(UChar c);
189 };
190
191 UBool LegalGreek::is(const UnicodeString& sourceString) const {
192 UnicodeString decomp;
193 UErrorCode ec = U_ZERO_ERROR;
194 Normalizer::decompose(sourceString, FALSE, 0, decomp, ec);
195
196 // modern is simpler: don't care about anything but a grave
197 if (full == FALSE) {
198 // A special case which is legal but should be
199 // excluded from round trip
200 // if (sourceString == UnicodeString("\\u039C\\u03C0", "")) {
201 // return FALSE;
202 // }
203 for (int32_t i = 0; i < decomp.length(); ++i) {
204 UChar c = decomp.charAt(i);
205 // exclude all the accents
206 if (c == 0x0313 || c == 0x0314 || c == 0x0300 || c == 0x0302
207 || c == 0x0342 || c == 0x0345
208 ) return FALSE;
209 }
210 return TRUE;
211 }
212
213 // Legal greek has breathing marks IFF there is a vowel or RHO at the start
214 // IF it has them, it has exactly one.
215 // IF it starts with a RHO, then the breathing mark must come before the second letter.
216 // Since there are no surrogates in greek, don't worry about them
217 UBool firstIsVowel = FALSE;
218 UBool firstIsRho = FALSE;
219 UBool noLetterYet = TRUE;
220 int32_t breathingCount = 0;
221 int32_t letterCount = 0;
222 for (int32_t i = 0; i < decomp.length(); ++i) {
223 UChar c = decomp.charAt(i);
224 if (u_isalpha(c)) {
225 ++letterCount;
226 if (noLetterYet) {
227 noLetterYet = FALSE;
228 firstIsVowel = isVowel(c);
229 firstIsRho = isRho(c);
230 }
231 if (firstIsRho && letterCount == 2 && breathingCount == 0) {
232 return FALSE;
233 }
234 }
235 if (c == 0x0313 || c == 0x0314) {
236 ++breathingCount;
237 }
238 }
239
240 if (firstIsVowel || firstIsRho) return breathingCount == 1;
241 return breathingCount == 0;
242 }
243
244 UBool LegalGreek::isVowel(UChar c) {
245 switch (c) {
246 case 0x03B1:
247 case 0x03B5:
248 case 0x03B7:
249 case 0x03B9:
250 case 0x03BF:
251 case 0x03C5:
252 case 0x03C9:
253 case 0x0391:
254 case 0x0395:
255 case 0x0397:
256 case 0x0399:
257 case 0x039F:
258 case 0x03A5:
259 case 0x03A9:
260 return TRUE;
261 }
262 return FALSE;
263 }
264
265 UBool LegalGreek::isRho(UChar c) {
266 switch (c) {
267 case 0x03C1:
268 case 0x03A1:
269 return TRUE;
270 }
271 return FALSE;
272 }
273
274 // AbbreviatedUnicodeSetIterator Interface ---------------------------------------------
275
276 class AbbreviatedUnicodeSetIterator : public UnicodeSetIterator {
277 public :
278
279 AbbreviatedUnicodeSetIterator();
280 virtual ~AbbreviatedUnicodeSetIterator();
281 void reset(UnicodeSet& set, UBool abb = FALSE, int32_t density = 100);
282
283 /**
284 * ICU "poor man's RTTI", returns a UClassID for the actual class.
285 */
286 virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
287
288 /**
289 * ICU "poor man's RTTI", returns a UClassID for this class.
290 */
291 static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
292
293 private :
294 UBool abbreviated;
295 int32_t perRange;
296 virtual void loadRange(int32_t range);
297
298 /**
299 * The address of this static class variable serves as this class's ID
300 * for ICU "poor man's RTTI".
301 */
302 static const char fgClassID;
303 };
304
305 // AbbreviatedUnicodeSetIterator Implementation ---------------------------------------
306
307 const char AbbreviatedUnicodeSetIterator::fgClassID=0;
308
309 AbbreviatedUnicodeSetIterator::AbbreviatedUnicodeSetIterator() :
310 UnicodeSetIterator(), abbreviated(FALSE) {
311 }
312
313 AbbreviatedUnicodeSetIterator::~AbbreviatedUnicodeSetIterator() {
314 }
315
316 void AbbreviatedUnicodeSetIterator::reset(UnicodeSet& newSet, UBool abb, int32_t density) {
317 UnicodeSetIterator::reset(newSet);
318 abbreviated = abb;
319 perRange = newSet.getRangeCount();
320 if (perRange != 0) {
321 perRange = density / perRange;
322 }
323 }
324
325 void AbbreviatedUnicodeSetIterator::loadRange(int32_t myRange) {
326 UnicodeSetIterator::loadRange(myRange);
327 if (abbreviated && (endElement > nextElement + perRange)) {
328 endElement = nextElement + perRange;
329 }
330 }
331
332 //--------------------------------------------------------------------
333 // RTTest Interface
334 //--------------------------------------------------------------------
335
336 class RTTest : public IntlTest {
337
338 // PrintWriter out;
339
340 UnicodeString transliteratorID;
341 int32_t errorLimit;
342 int32_t errorCount;
343 int32_t pairLimit;
344 UnicodeSet sourceRange;
345 UnicodeSet targetRange;
346 UnicodeSet toSource;
347 UnicodeSet toTarget;
348 UnicodeSet roundtripExclusionsSet;
349 IntlTest* parent;
350 Legal* legalSource; // NOT owned
351 UnicodeSet badCharacters;
352
353 public:
354
355 /*
356 * create a test for the given script transliterator.
357 */
358 RTTest(const UnicodeString& transliteratorIDStr);
359
360 virtual ~RTTest();
361
362 void setErrorLimit(int32_t limit);
363
364 void setPairLimit(int32_t limit);
365
366 void test(const UnicodeString& sourceRange,
367 const UnicodeString& targetRange,
368 const char* roundtripExclusions,
369 IntlTest* parent,
370 UBool quick,
371 Legal* adoptedLegal,
372 int32_t density = 100);
373
374 private:
375
376 // Added to do better equality check.
377
378 static UBool isSame(const UnicodeString& a, const UnicodeString& b);
379
380 static UBool isCamel(const UnicodeString& a);
381
382 UBool checkIrrelevants(Transliterator *t, const UnicodeString& irrelevants);
383
384 void test2(UBool quick, int32_t density);
385
386 void logWrongScript(const UnicodeString& label,
387 const UnicodeString& from,
388 const UnicodeString& to);
389
390 void logNotCanonical(const UnicodeString& label,
391 const UnicodeString& from,
392 const UnicodeString& to,
393 const UnicodeString& fromCan,
394 const UnicodeString& toCan);
395
396 void logFails(const UnicodeString& label);
397
398 void logToRulesFails(const UnicodeString& label,
399 const UnicodeString& from,
400 const UnicodeString& to,
401 const UnicodeString& toCan);
402
403 void logRoundTripFailure(const UnicodeString& from,
404 const UnicodeString& toID,
405 const UnicodeString& to,
406 const UnicodeString& backID,
407 const UnicodeString& back);
408 };
409
410 //--------------------------------------------------------------------
411 // RTTest Implementation
412 //--------------------------------------------------------------------
413
414 /*
415 * create a test for the given script transliterator.
416 */
417 RTTest::RTTest(const UnicodeString& transliteratorIDStr) {
418 transliteratorID = transliteratorIDStr;
419 errorLimit = 500;
420 errorCount = 0;
421 pairLimit = 0x10000;
422 }
423
424 RTTest::~RTTest() {
425 }
426
427 void RTTest::setErrorLimit(int32_t limit) {
428 errorLimit = limit;
429 }
430
431 void RTTest::setPairLimit(int32_t limit) {
432 pairLimit = limit;
433 }
434
435 UBool RTTest::isSame(const UnicodeString& a, const UnicodeString& b) {
436 if (a == b) return TRUE;
437 if (a.caseCompare(b, U_FOLD_CASE_DEFAULT)==0 && isCamel(a)) return TRUE;
438 UnicodeString aa, bb;
439 UErrorCode ec = U_ZERO_ERROR;
440 Normalizer::decompose(a, FALSE, 0, aa, ec);
441 Normalizer::decompose(b, FALSE, 0, bb, ec);
442 if (aa == bb) return TRUE;
443 if (aa.caseCompare(bb, U_FOLD_CASE_DEFAULT)==0 && isCamel(aa)) return TRUE;
444 return FALSE;
445 }
446
447 UBool RTTest::isCamel(const UnicodeString& a) {
448 // see if string is of the form aB; e.g. lower, then upper or title
449 UChar32 cp;
450 UBool haveLower = FALSE;
451 for (int32_t i = 0; i < a.length(); i += UTF_CHAR_LENGTH(cp)) {
452 cp = a.char32At(i);
453 int8_t t = u_charType(cp);
454 switch (t) {
455 case U_UPPERCASE_LETTER:
456 if (haveLower) return TRUE;
457 break;
458 case U_TITLECASE_LETTER:
459 if (haveLower) return TRUE;
460 // drop through, since second letter is lower.
461 case U_LOWERCASE_LETTER:
462 haveLower = TRUE;
463 break;
464 }
465 }
466 return FALSE;
467 }
468
469 void RTTest::test(const UnicodeString& sourceRangeVal,
470 const UnicodeString& targetRangeVal,
471 const char* roundtripExclusions,
472 IntlTest* logVal, UBool quickRt,
473 Legal* adoptedLegal,
474 int32_t density)
475 {
476
477 UErrorCode status = U_ZERO_ERROR;
478
479 this->parent = logVal;
480 this->legalSource = adoptedLegal;
481
482 UnicodeSet neverOk("[:Other:]", status);
483 UnicodeSet okAnyway("[^[:Letter:]]", status);
484
485 if (U_FAILURE(status)) {
486 parent->errln("FAIL: Initializing UnicodeSet with [:Other:] or [^[:Letter:]]");
487 return;
488 }
489
490 this->sourceRange.clear();
491 this->sourceRange.applyPattern(sourceRangeVal, status);
492 if (U_FAILURE(status)) {
493 parent->errln("FAIL: UnicodeSet::applyPattern(" +
494 sourceRangeVal + ")");
495 return;
496 }
497 this->sourceRange.removeAll(neverOk);
498
499 this->targetRange.clear();
500 this->targetRange.applyPattern(targetRangeVal, status);
501 if (U_FAILURE(status)) {
502 parent->errln("FAIL: UnicodeSet::applyPattern(" +
503 targetRangeVal + ")");
504 return;
505 }
506 this->targetRange.removeAll(neverOk);
507
508 this->toSource.clear();
509 this->toSource.applyPattern(sourceRangeVal, status);
510 if (U_FAILURE(status)) {
511 parent->errln("FAIL: UnicodeSet::applyPattern(" +
512 sourceRangeVal + ")");
513 return;
514 }
515 this->toSource.addAll(okAnyway);
516
517 this->toTarget.clear();
518 this->toTarget.applyPattern(targetRangeVal, status);
519 if (U_FAILURE(status)) {
520 parent->errln("FAIL: UnicodeSet::applyPattern(" +
521 targetRangeVal + ")");
522 return;
523 }
524 this->toTarget.addAll(okAnyway);
525
526 this->roundtripExclusionsSet.clear();
527 if (roundtripExclusions != NULL && strlen(roundtripExclusions) > 0) {
528 this->roundtripExclusionsSet.applyPattern(roundtripExclusions, status);
529 if (U_FAILURE(status)) {
530 parent->errln("FAIL: UnicodeSet::applyPattern(%s)", roundtripExclusions);
531 return;
532 }
533 }
534
535 badCharacters.clear();
536 badCharacters.applyPattern("[:Other:]", status);
537 if (U_FAILURE(status)) {
538 parent->errln("FAIL: UnicodeSet::applyPattern([:Other:])");
539 return;
540 }
541
542 test2(quickRt, density);
543
544 if (errorCount > 0) {
545 char str[100];
546 int32_t length = transliteratorID.extract(str, 100, NULL, status);
547 str[length] = 0;
548 parent->errln("FAIL: %s errors: %d %s", str, errorCount, (errorCount > errorLimit ? " (at least!)" : " ")); // + ", see " + logFileName);
549 } else {
550 char str[100];
551 int32_t length = transliteratorID.extract(str, 100, NULL, status);
552 str[length] = 0;
553 parent->logln("%s ok", str);
554 }
555 }
556
557 UBool RTTest::checkIrrelevants(Transliterator *t,
558 const UnicodeString& irrelevants) {
559 for (int i = 0; i < irrelevants.length(); ++i) {
560 UChar c = irrelevants.charAt(i);
561 UnicodeString srcStr(c);
562 UnicodeString targ = srcStr;
563 t->transliterate(targ);
564 if (srcStr == targ) return TRUE;
565 }
566 return FALSE;
567 }
568
569 void RTTest::test2(UBool quickRt, int32_t density) {
570
571 UnicodeString srcStr, targ, reverse;
572 UErrorCode status = U_ZERO_ERROR;
573 UParseError parseError ;
574 TransliteratorPointer sourceToTarget(
575 Transliterator::createInstance(transliteratorID, UTRANS_FORWARD, parseError,
576 status));
577 if ((Transliterator *)sourceToTarget == NULL) {
578 parent->errln("FAIL: createInstance(" + transliteratorID +
579 ") returned NULL. Error: " + u_errorName(status)
580 + "\n\tpreContext : " + prettify(parseError.preContext)
581 + "\n\tpostContext : " + prettify(parseError.postContext));
582
583 return;
584 }
585 TransliteratorPointer targetToSource(sourceToTarget->createInverse(status));
586 if ((Transliterator *)targetToSource == NULL) {
587 parent->errln("FAIL: " + transliteratorID +
588 ".createInverse() returned NULL. Error:" + u_errorName(status)
589 + "\n\tpreContext : " + prettify(parseError.preContext)
590 + "\n\tpostContext : " + prettify(parseError.postContext));
591 return;
592 }
593
594 AbbreviatedUnicodeSetIterator usi;
595 AbbreviatedUnicodeSetIterator usi2;
596
597 parent->logln("Checking that at least one irrelevant character is not NFC'ed");
598 // string is from NFC_NO in the UCD
599 UnicodeString irrelevants = CharsToUnicodeString("\\u2000\\u2001\\u2126\\u212A\\u212B\\u2329");
600
601 if (checkIrrelevants(sourceToTarget, irrelevants) == FALSE) {
602 logFails("Source-Target, irrelevants");
603 }
604 if (checkIrrelevants(targetToSource, irrelevants) == FALSE) {
605 logFails("Target-Source, irrelevants");
606 }
607
608 if (!quickRt){
609 parent->logln("Checking that toRules works");
610 UnicodeString rules = "";
611
612 UParseError parseError;
613 rules = sourceToTarget->toRules(rules, TRUE);
614 // parent->logln((UnicodeString)"toRules => " + rules);
615 TransliteratorPointer sourceToTarget2(Transliterator::createFromRules(
616 "s2t2", rules,
617 UTRANS_FORWARD,
618 parseError, status));
619 if (U_FAILURE(status)) {
620 parent->errln("FAIL: createFromRules %s\n", u_errorName(status));
621 return;
622 }
623
624 rules = targetToSource->toRules(rules, FALSE);
625 TransliteratorPointer targetToSource2(Transliterator::createFromRules(
626 "t2s2", rules,
627 UTRANS_FORWARD,
628 parseError, status));
629 if (U_FAILURE(status)) {
630 parent->errln("FAIL: createFromRules %s\n", u_errorName(status));
631 return;
632 }
633
634 usi.reset(sourceRange);
635 for (;;) {
636 if (!usi.next() || usi.isString()) break;
637 UChar32 c = usi.getCodepoint();
638
639 UnicodeString srcStr((UChar32)c);
640 UnicodeString targ = srcStr;
641 sourceToTarget->transliterate(targ);
642 UnicodeString targ2 = srcStr;
643 sourceToTarget2->transliterate(targ2);
644 if (targ != targ2) {
645 logToRulesFails("Source-Target, toRules", srcStr, targ, targ2);
646 }
647 }
648
649 usi.reset(targetRange);
650 for (;;) {
651 if (!usi.next() || usi.isString()) break;
652 UChar32 c = usi.getCodepoint();
653
654 UnicodeString srcStr((UChar32)c);
655 UnicodeString targ = srcStr;
656 targetToSource->transliterate(targ);
657 UnicodeString targ2 = srcStr;
658 targetToSource2->transliterate(targ2);
659 if (targ != targ2) {
660 logToRulesFails("Target-Source, toRules", srcStr, targ, targ2);
661 }
662 }
663 }
664
665 parent->logln("Checking that all source characters convert to target - Singles");
666
667 UnicodeSet failSourceTarg;
668 usi.reset(sourceRange);
669 for (;;) {
670 if (!usi.next() || usi.isString()) break;
671 UChar32 c = usi.getCodepoint();
672
673 UnicodeString srcStr((UChar32)c);
674 UnicodeString targ = srcStr;
675 sourceToTarget->transliterate(targ);
676 if (toTarget.containsAll(targ) == FALSE
677 || badCharacters.containsSome(targ) == TRUE) {
678 UnicodeString targD;
679 Normalizer::decompose(targ, FALSE, 0, targD, status);
680 if (U_FAILURE(status)) {
681 parent->errln("FAIL: Internal error during decomposition %s\n", u_errorName(status));
682 return;
683 }
684 if (toTarget.containsAll(targD) == FALSE ||
685 badCharacters.containsSome(targD) == TRUE) {
686 logWrongScript("Source-Target", srcStr, targ);
687 failSourceTarg.add(c);
688 continue;
689 }
690 }
691
692 UnicodeString cs2;
693 Normalizer::decompose(srcStr, FALSE, 0, cs2, status);
694 if (U_FAILURE(status)) {
695 parent->errln("FAIL: Internal error during decomposition %s\n", u_errorName(status));
696 return;
697 }
698 UnicodeString targ2 = cs2;
699 sourceToTarget->transliterate(targ2);
700 if (targ != targ2) {
701 logNotCanonical("Source-Target", srcStr, targ,cs2, targ2);
702 }
703 }
704
705 parent->logln("Checking that all source characters convert to target - Doubles");
706
707 UnicodeSet sourceRangeMinusFailures(sourceRange);
708 sourceRangeMinusFailures.removeAll(failSourceTarg);
709
710 usi.reset(sourceRangeMinusFailures, quickRt, density);
711 for (;;) {
712 if (!usi.next() || usi.isString()) break;
713 UChar32 c = usi.getCodepoint();
714
715 usi2.reset(sourceRangeMinusFailures, quickRt, density);
716 for (;;) {
717 if (!usi2.next() || usi2.isString()) break;
718 UChar32 d = usi2.getCodepoint();
719
720 UnicodeString srcStr;
721 srcStr += (UChar32)c;
722 srcStr += (UChar32)d;
723 UnicodeString targ = srcStr;
724 sourceToTarget->transliterate(targ);
725 if (toTarget.containsAll(targ) == FALSE ||
726 badCharacters.containsSome(targ) == TRUE)
727 {
728 UnicodeString targD;
729 Normalizer::decompose(targ, FALSE, 0, targD, status);
730 if (U_FAILURE(status)) {
731 parent->errln("FAIL: Internal error during decomposition %s\n", u_errorName(status));
732 return;
733 }
734 if (toTarget.containsAll(targD) == FALSE ||
735 badCharacters.containsSome(targD) == TRUE) {
736 logWrongScript("Source-Target", srcStr, targ);
737 continue;
738 }
739 }
740 UnicodeString cs2;
741 Normalizer::decompose(srcStr, FALSE, 0, cs2, status);
742 if (U_FAILURE(status)) {
743 parent->errln("FAIL: Internal error during decomposition %s\n", u_errorName(status));
744 return;
745 }
746 UnicodeString targ2 = cs2;
747 sourceToTarget->transliterate(targ2);
748 if (targ != targ2) {
749 logNotCanonical("Source-Target", srcStr, targ, cs2,targ2);
750 }
751 }
752 }
753
754 parent->logln("Checking that target characters convert to source and back - Singles");
755
756 UnicodeSet failTargSource;
757 UnicodeSet failRound;
758
759 usi.reset(targetRange);
760 for (;;) {
761 if (!usi.next()) break;
762
763 if(usi.isString()){
764 srcStr = usi.getString();
765 }else{
766 srcStr = (UnicodeString)usi.getCodepoint();
767 }
768
769 UChar32 c = srcStr.char32At(0);
770
771 targ = srcStr;
772 targetToSource->transliterate(targ);
773 reverse = targ;
774 sourceToTarget->transliterate(reverse);
775
776 if (toSource.containsAll(targ) == FALSE ||
777 badCharacters.containsSome(targ) == TRUE) {
778 UnicodeString targD;
779 Normalizer::decompose(targ, FALSE, 0, targD, status);
780 if (U_FAILURE(status)) {
781 parent->errln("FAIL: Internal error during decomposition%s\n", u_errorName(status));
782 return;
783 }
784 if (toSource.containsAll(targD) == FALSE) {
785 logWrongScript("Target-Source", srcStr, targ);
786 failTargSource.add(c);
787 continue;
788 }
789 if (badCharacters.containsSome(targD) == TRUE) {
790 logWrongScript("Target-Source*", srcStr, targ);
791 failTargSource.add(c);
792 continue;
793 }
794 }
795 if (isSame(srcStr, reverse) == FALSE &&
796 roundtripExclusionsSet.contains(c) == FALSE
797 && roundtripExclusionsSet.contains(srcStr)==FALSE) {
798 logRoundTripFailure(srcStr,targetToSource->getID(), targ,sourceToTarget->getID(), reverse);
799 failRound.add(c);
800 continue;
801 }
802
803 UnicodeString targ2;
804 Normalizer::decompose(targ, FALSE, 0, targ2, status);
805 if (U_FAILURE(status)) {
806 parent->errln("FAIL: Internal error during decomposition%s\n", u_errorName(status));
807 return;
808 }
809 UnicodeString reverse2 = targ2;
810 sourceToTarget->transliterate(reverse2);
811 if (reverse != reverse2) {
812 logNotCanonical("Target-Source", targ, reverse, targ2, reverse2);
813 }
814 }
815
816 parent->logln("Checking that target characters convert to source and back - Doubles");
817 int32_t count = 0;
818
819 UnicodeSet targetRangeMinusFailures(targetRange);
820 targetRangeMinusFailures.removeAll(failTargSource);
821 targetRangeMinusFailures.removeAll(failRound);
822
823 usi.reset(targetRangeMinusFailures, quickRt, density);
824 UnicodeString targ2;
825 UnicodeString reverse2;
826 UnicodeString targD;
827 for (;;) {
828 if (!usi.next() || usi.isString()) break;
829 UChar32 c = usi.getCodepoint();
830 if (++count > pairLimit) {
831 //throw new TestTruncated("Test truncated at " + pairLimit + " x 64k pairs");
832 parent->logln("");
833 parent->logln((UnicodeString)"Test truncated at " + pairLimit + " x 64k pairs");
834 return;
835 }
836
837 usi2.reset(targetRangeMinusFailures, quickRt, density);
838 for (;;) {
839 if (!usi2.next() || usi2.isString())
840 break;
841 UChar32 d = usi2.getCodepoint();
842 srcStr.truncate(0); // empty the variable without construction/destruction
843 srcStr += c;
844 srcStr += d;
845
846 targ = srcStr;
847 targetToSource->transliterate(targ);
848 reverse = targ;
849 sourceToTarget->transliterate(reverse);
850
851 if (toSource.containsAll(targ) == FALSE ||
852 badCharacters.containsSome(targ) == TRUE)
853 {
854 targD.truncate(0); // empty the variable without construction/destruction
855 Normalizer::decompose(targ, FALSE, 0, targD, status);
856 if (U_FAILURE(status)) {
857 parent->errln("FAIL: Internal error during decomposition%s\n",
858 u_errorName(status));
859 return;
860 }
861 if (toSource.containsAll(targD) == FALSE
862 || badCharacters.containsSome(targD) == TRUE)
863 {
864 logWrongScript("Target-Source", srcStr, targ);
865 continue;
866 }
867 }
868 if (isSame(srcStr, reverse) == FALSE &&
869 roundtripExclusionsSet.contains(c) == FALSE&&
870 roundtripExclusionsSet.contains(d) == FALSE &&
871 roundtripExclusionsSet.contains(srcStr)== FALSE)
872 {
873 logRoundTripFailure(srcStr,targetToSource->getID(), targ, sourceToTarget->getID(),reverse);
874 continue;
875 }
876
877 targ2.truncate(0); // empty the variable without construction/destruction
878 Normalizer::decompose(targ, FALSE, 0, targ2, status);
879 if (U_FAILURE(status)) {
880 parent->errln("FAIL: Internal error during decomposition%s\n", u_errorName(status));
881 return;
882 }
883 reverse2 = targ2;
884 sourceToTarget->transliterate(reverse2);
885 if (reverse != reverse2) {
886 logNotCanonical("Target-Source", targ,reverse, targ2, reverse2);
887 }
888 }
889 }
890 parent->logln("");
891 }
892
893 void RTTest::logWrongScript(const UnicodeString& label,
894 const UnicodeString& from,
895 const UnicodeString& to) {
896 parent->errln((UnicodeString)"FAIL " +
897 label + ": " +
898 from + "(" + TestUtility::hex(from) + ") => " +
899 to + "(" + TestUtility::hex(to) + ")");
900 ++errorCount;
901 }
902
903 void RTTest::logNotCanonical(const UnicodeString& label,
904 const UnicodeString& from,
905 const UnicodeString& to,
906 const UnicodeString& fromCan,
907 const UnicodeString& toCan) {
908 parent->errln((UnicodeString)"FAIL (can.equiv)" +
909 label + ": " +
910 from + "(" + TestUtility::hex(from) + ") => " +
911 to + "(" + TestUtility::hex(to) + ")" +
912 fromCan + "(" + TestUtility::hex(fromCan) + ") => " +
913 toCan + " (" +
914 TestUtility::hex(toCan) + ")"
915 );
916 ++errorCount;
917 }
918
919 void RTTest::logFails(const UnicodeString& label) {
920 parent->errln((UnicodeString)"<br>FAIL " + label);
921 ++errorCount;
922 }
923
924 void RTTest::logToRulesFails(const UnicodeString& label,
925 const UnicodeString& from,
926 const UnicodeString& to,
927 const UnicodeString& otherTo)
928 {
929 parent->errln((UnicodeString)"FAIL: " +
930 label + ": " +
931 from + "(" + TestUtility::hex(from) + ") => " +
932 to + "(" + TestUtility::hex(to) + ")" +
933 "!=" +
934 otherTo + " (" +
935 TestUtility::hex(otherTo) + ")"
936 );
937 ++errorCount;
938 }
939
940
941 void RTTest::logRoundTripFailure(const UnicodeString& from,
942 const UnicodeString& toID,
943 const UnicodeString& to,
944 const UnicodeString& backID,
945 const UnicodeString& back) {
946 if (legalSource->is(from) == FALSE) return; // skip illegals
947
948 parent->errln((UnicodeString)"FAIL Roundtrip: " +
949 from + "(" + TestUtility::hex(from) + ") => " +
950 to + "(" + TestUtility::hex(to) + ") "+toID+" => " +
951 back + "(" + TestUtility::hex(back) + ") "+backID+" => ");
952 ++errorCount;
953 }
954
955 //--------------------------------------------------------------------
956 // Specific Tests
957 //--------------------------------------------------------------------
958
959 /*
960 Note: Unicode 3.2 added new Hiragana/Katakana characters:
961
962 3095..3096 ; 3.2 # [2] HIRAGANA LETTER SMALL KA..HIRAGANA LETTER SMALL KE
963 309F..30A0 ; 3.2 # [2] HIRAGANA DIGRAPH YORI..KATAKANA-HIRAGANA DOUBLE HYPHEN
964 30FF ; 3.2 # KATAKANA DIGRAPH KOTO
965 31F0..31FF ; 3.2 # [16] KATAKANA LETTER SMALL KU..KATAKANA LETTER SMALL RO
966
967 We will not add them to the rules until they are more supported (e.g. in fonts on Windows)
968 A bug has been filed to remind us to do this: #1979.
969 */
970
971 static const char KATAKANA[] = "[[[:katakana:][\\u30A1-\\u30FA\\u30FC]]-[\\u30FF\\u31F0-\\u31FF]]";
972 static const char HIRAGANA[] = "[[[:hiragana:][\\u3040-\\u3094]]-[\\u3095-\\u3096\\u309F-\\u30A0]]";
973 static const char LENGTH[] = "[\\u30FC]";
974 static const char HALFWIDTH_KATAKANA[] = "[\\uFF65-\\uFF9D]";
975 static const char KATAKANA_ITERATION[] = "[\\u30FD\\u30FE]";
976 static const char HIRAGANA_ITERATION[] = "[\\u309D\\u309E]";
977 static const int32_t TEMP_MAX=256;
978
979 void TransliteratorRoundTripTest::TestKana() {
980 RTTest test("Katakana-Hiragana");
981 Legal *legal = new Legal();
982 char temp[TEMP_MAX];
983 strcpy(temp, "[");
984 strcat(temp, HALFWIDTH_KATAKANA);
985 strcat(temp, LENGTH);
986 strcat(temp, "]");
987 test.test(KATAKANA, UnicodeString("[") + HIRAGANA + LENGTH + UnicodeString("]"),
988 temp,
989 this, quick, legal);
990 delete legal;
991 }
992
993 void TransliteratorRoundTripTest::TestHiragana() {
994 RTTest test("Latin-Hiragana");
995 Legal *legal = new Legal();
996 test.test(UnicodeString("[a-zA-Z]", ""),
997 HIRAGANA,
998 HIRAGANA_ITERATION, this, quick, legal);
999 delete legal;
1000 }
1001
1002 void TransliteratorRoundTripTest::TestKatakana() {
1003 RTTest test("Latin-Katakana");
1004 Legal *legal = new Legal();
1005 char temp[TEMP_MAX];
1006 strcpy(temp, "[");
1007 strcat(temp, KATAKANA_ITERATION);
1008 strcat(temp, HALFWIDTH_KATAKANA);
1009 strcat(temp, "]");
1010 test.test(UnicodeString("[a-zA-Z]", ""),
1011 KATAKANA,
1012 temp,
1013 this, quick, legal);
1014 delete legal;
1015 }
1016
1017 void TransliteratorRoundTripTest::TestJamo() {
1018 RTTest t("Latin-Jamo");
1019 Legal *legal = new LegalJamo();
1020 t.test(UnicodeString("[a-zA-Z]", ""),
1021 UnicodeString("[\\u1100-\\u1112 \\u1161-\\u1175 \\u11A8-\\u11C2]",
1022 ""),
1023 NULL, this, quick, legal);
1024 delete legal;
1025 }
1026
1027 void TransliteratorRoundTripTest::TestHangul() {
1028 RTTest t("Latin-Hangul");
1029 Legal *legal = new Legal();
1030 if (quick) t.setPairLimit(1000);
1031 t.test(UnicodeString("[a-zA-Z]", ""),
1032 UnicodeString("[\\uAC00-\\uD7A4]", ""),
1033 NULL, this, quick, legal, 1);
1034 delete legal;
1035 }
1036
1037
1038 #define ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \
1039 errln("error at file %s, line %d, status = %s", __FILE__, __LINE__, \
1040 u_errorName(status)); \
1041 return;}}
1042
1043
1044 static void writeStringInU8(FILE *out, const UnicodeString &s) {
1045 int i;
1046 for (i=0; i<s.length(); i=s.moveIndex32(i, 1)) {
1047 UChar32 c = s.char32At(i);
1048 uint8_t bufForOneChar[10];
1049 UBool isError = FALSE;
1050 int32_t destIdx = 0;
1051 U8_APPEND(bufForOneChar, destIdx, sizeof(bufForOneChar), c, isError);
1052 fwrite(bufForOneChar, 1, destIdx, out);
1053 }
1054 }
1055
1056
1057
1058
1059 void TransliteratorRoundTripTest::TestHan() {
1060 UErrorCode status = U_ZERO_ERROR;
1061
1062 // TODO: getExemplars() exists only as a C API, taking a USet.
1063 // The set API we need to use exists only on UnicodeSet, not on USet.
1064 // Do a hacky cast, knowing that a USet is really a UnicodeSet in
1065 // the implementation. Once USet gets the missing API, switch back
1066 // to using that.
1067 USet *USetExemplars = NULL;
1068 USetExemplars = uset_open(0, 0);
1069 USetExemplars = ulocdata_getExemplarSet(USetExemplars, "zh", 0, &status);
1070 ASSERT_SUCCESS(status);
1071 UnicodeSet *exemplars = (UnicodeSet *)USetExemplars;
1072
1073 UnicodeString source;
1074 UChar32 c;
1075 int i;
1076 for (i=0; ;i++) {
1077 // Add all of the Chinese exemplar chars to the string "source".
1078 c = exemplars->charAt(i);
1079 if (c == (UChar32)-1) {
1080 break;
1081 }
1082 source.append(c);
1083 }
1084
1085 // transform with Han translit
1086 Transliterator *hanTL = Transliterator::createInstance("Han-Latin", UTRANS_FORWARD, status);
1087 ASSERT_SUCCESS(status);
1088 UnicodeString target=source;
1089 hanTL->transliterate(target);
1090 // now verify that there are no Han characters left
1091 UnicodeSet allHan("[:han:]", status);
1092 ASSERT_SUCCESS(status);
1093 if (allHan.containsSome(target)) {
1094 errln("file %s, line %d, No Han must be left after Han-Latin transliteration",
1095 __FILE__, __LINE__);
1096 }
1097
1098 // check the pinyin translit
1099 Transliterator *pn = Transliterator::createInstance("Latin-NumericPinyin", UTRANS_FORWARD, status);
1100 ASSERT_SUCCESS(status);
1101 UnicodeString target2 = target;
1102 pn->transliterate(target2);
1103
1104 // verify that there are no marks
1105 Transliterator *nfc = Transliterator::createInstance("nfc", UTRANS_FORWARD, status);
1106 ASSERT_SUCCESS(status);
1107
1108 UnicodeString nfced = target2;
1109 nfc->transliterate(nfced);
1110 UnicodeSet allMarks("[:mark:]", status);
1111 ASSERT_SUCCESS(status);
1112 assertFalse("NumericPinyin must contain no marks", allMarks.containsSome(nfced));
1113
1114 // verify roundtrip
1115 Transliterator *np = pn->createInverse(status);
1116 ASSERT_SUCCESS(status);
1117 UnicodeString target3 = target;
1118 np->transliterate(target3);
1119 UBool roundtripOK = (target3.compare(target) == 0);
1120 assertTrue("NumericPinyin must roundtrip", roundtripOK);
1121 if (!roundtripOK) {
1122 const char *filename = "numeric-pinyin.log.txt";
1123 FILE *out = fopen(filename, "w");
1124 errln("Creating log file %s\n", filename);
1125 fprintf(out, "Pinyin: ");
1126 writeStringInU8(out, target);
1127 fprintf(out, "\nPinyin-Numeric-Pinyin: ");
1128 writeStringInU8(out, target2);
1129 fprintf(out, "\n");
1130 fclose(out);
1131 }
1132
1133 delete hanTL;
1134 delete pn;
1135 delete nfc;
1136 delete np;
1137 uset_close(USetExemplars);
1138 }
1139
1140
1141 void TransliteratorRoundTripTest::TestGreek() {
1142 // weiv removed the test and the fiter
1143 /*
1144 if (isICUVersionAtLeast(ICU_30)) {
1145 // We temporarily filter against Unicode 3.2, but we only do this
1146 // before version 3.0.
1147 errln("FAIL: TestGreek needs to be updated to remove Unicode 3.2 filter");
1148 return;
1149 } else {
1150 logln("Warning: TestGreek needs to be updated to remove Unicode 3.2 filter");
1151 }
1152 */
1153 RTTest test("Latin-Greek");
1154 LegalGreek *legal = new LegalGreek(TRUE);
1155
1156 test.test(UnicodeString("[a-zA-Z]", ""),
1157 UnicodeString("[\\u003B\\u00B7[[:Greek:]&[:Letter:]]-["
1158 "\\u1D26-\\u1D2A" // L& [5] GREEK LETTER SMALL CAPITAL GAMMA..GREEK LETTER SMALL CAPITAL PSI
1159 "\\u1D5D-\\u1D61" // Lm [5] MODIFIER LETTER SMALL BETA..MODIFIER LETTER SMALL CHI
1160 "\\u1D66-\\u1D6A" // L& [5] GREEK SUBSCRIPT SMALL LETTER BETA..GREEK SUBSCRIPT SMALL LETTER CHI
1161 "\\u03D7-\\u03EF" // \N{GREEK KAI SYMBOL}..\N{COPTIC SMALL LETTER DEI}
1162 "]]",
1163
1164 //UnicodeString("[[\\u003B\\u00B7[:Greek:]-[\\u0374\\u0385\\u1fcd\\u1fce\\u1fdd\\u1fde\\u1fed-\\u1fef\\u1ffd\\u03D7-\\u03EF]]&[:Age=3.2:]]",
1165 ""),
1166 "[\\u00B5\\u037A\\u03D0-\\u03F5\\u03f9]", /* exclusions */
1167 this, quick, legal, 50);
1168
1169
1170 delete legal;
1171 }
1172
1173
1174 void TransliteratorRoundTripTest::TestGreekUNGEGN() {
1175 // weiv removed the test and the fiter
1176 /*
1177 if (isICUVersionAtLeast(ICU_30)) {
1178 // We temporarily filter against Unicode 3.2, but we only do this
1179 // before version 3.0.
1180 errln("FAIL: TestGreekUNGEGN needs to be updated to remove Unicode 3.2 filter");
1181 return;
1182 } else {
1183 logln("Warning: TestGreekUNGEGN needs to be updated to remove Unicode 3.2 filter");
1184 }
1185 */
1186 RTTest test("Latin-Greek/UNGEGN");
1187 LegalGreek *legal = new LegalGreek(FALSE);
1188
1189 test.test(UnicodeString("[a-zA-Z]", ""),
1190 UnicodeString("[\\u003B\\u00B7[[:Greek:]&[:Letter:]]-["
1191 "\\u1D26-\\u1D2A" // L& [5] GREEK LETTER SMALL CAPITAL GAMMA..GREEK LETTER SMALL CAPITAL PSI
1192 "\\u1D5D-\\u1D61" // Lm [5] MODIFIER LETTER SMALL BETA..MODIFIER LETTER SMALL CHI
1193 "\\u1D66-\\u1D6A" // L& [5] GREEK SUBSCRIPT SMALL LETTER BETA..GREEK SUBSCRIPT SMALL LETTER CHI
1194 "\\u03D7-\\u03EF" // \N{GREEK KAI SYMBOL}..\N{COPTIC SMALL LETTER DEI}
1195 "]]",
1196 //UnicodeString("[[\\u003B\\u00B7[:Greek:]-[\\u0374\\u0385\\u1fce\\u1fde\\u03D7-\\u03EF]]&[:Age=3.2:]]",
1197 ""),
1198 "[\\u0385\\u00B5\\u037A\\u03D0-\\uFFFF {\\u039C\\u03C0}]", /* roundtrip exclusions */
1199 this, quick, legal);
1200
1201 delete legal;
1202 }
1203
1204 void TransliteratorRoundTripTest::Testel() {
1205 // weiv removed the test and the fiter
1206 /*
1207 if (isICUVersionAtLeast(ICU_30)) {
1208 // We temporarily filter against Unicode 3.2, but we only do this
1209 // before version 3.0.
1210 errln("FAIL: Testel needs to be updated to remove Unicode 3.2 filter");
1211 return;
1212 } else {
1213 logln("Warning: Testel needs to be updated to remove Unicode 3.2 filter");
1214 }
1215 */
1216 RTTest test("Latin-el");
1217 LegalGreek *legal = new LegalGreek(FALSE);
1218
1219 test.test(UnicodeString("[a-zA-Z]", ""),
1220 UnicodeString("[\\u003B\\u00B7[[:Greek:]&[:Letter:]]-["
1221 "\\u1D26-\\u1D2A" // L& [5] GREEK LETTER SMALL CAPITAL GAMMA..GREEK LETTER SMALL CAPITAL PSI
1222 "\\u1D5D-\\u1D61" // Lm [5] MODIFIER LETTER SMALL BETA..MODIFIER LETTER SMALL CHI
1223 "\\u1D66-\\u1D6A" // L& [5] GREEK SUBSCRIPT SMALL LETTER BETA..GREEK SUBSCRIPT SMALL LETTER CHI
1224 "\\u03D7-\\u03EF" // \N{GREEK KAI SYMBOL}..\N{COPTIC SMALL LETTER DEI}
1225 "]]",
1226 //UnicodeString("[[\\u003B\\u00B7[:Greek:]-[\\u0374\\u0385\\u1fce\\u1fde\\u03D7-\\u03EF]]&[:Age=3.2:]]",
1227 ""),
1228 "[\\u00B5\\u037A\\u03D0-\\uFFFF {\\u039C\\u03C0}]", /* exclusions */
1229 this, quick, legal);
1230
1231
1232 delete legal;
1233 }
1234
1235
1236 void TransliteratorRoundTripTest::TestArabic() {
1237 UnicodeString ARABIC("[\\u060C\\u061B\\u061F\\u0621\\u0627-\\u063A\\u0641-\\u0655\\u0660-\\u066C\\u067E\\u0686\\u0698\\u06A4\\u06AD\\u06AF\\u06CB-\\u06CC\\u06F0-\\u06F9]");
1238 Legal *legal = new Legal();
1239 RTTest test("Latin-Arabic");
1240 test.test("[a-zA-Z\\u02BE\\u02BF\\u207F]", ARABIC, "[a-zA-Z\\u02BE\\u02BF\\u207F]",this, quick, legal); //
1241 delete legal;
1242 }
1243 class LegalHebrew : public Legal {
1244 private:
1245 UnicodeSet FINAL;
1246 UnicodeSet NON_FINAL;
1247 UnicodeSet LETTER;
1248 public:
1249 LegalHebrew(UErrorCode& error);
1250 virtual ~LegalHebrew() {}
1251 virtual UBool is(const UnicodeString& sourceString) const;
1252 };
1253
1254 LegalHebrew::LegalHebrew(UErrorCode& error){
1255 FINAL.applyPattern("[\\u05DA\\u05DD\\u05DF\\u05E3\\u05E5]", error);
1256 NON_FINAL.applyPattern("[\\u05DB\\u05DE\\u05E0\\u05E4\\u05E6]", error);
1257 LETTER.applyPattern("[:letter:]", error);
1258 }
1259 UBool LegalHebrew::is(const UnicodeString& sourceString)const{
1260
1261 if (sourceString.length() == 0) return TRUE;
1262 // don't worry about surrogates.
1263 for (int i = 0; i < sourceString.length(); ++i) {
1264 UChar ch = sourceString.charAt(i);
1265 UChar next = i+1 == sourceString.length() ? 0x0000 : sourceString.charAt(i);
1266 if (FINAL.contains(ch)) {
1267 if (LETTER.contains(next)) return FALSE;
1268 } else if (NON_FINAL.contains(ch)) {
1269 if (!LETTER.contains(next)) return FALSE;
1270 }
1271 }
1272 return TRUE;
1273 }
1274 void TransliteratorRoundTripTest::TestHebrew() {
1275 //long start = System.currentTimeMillis();
1276 UErrorCode error = U_ZERO_ERROR;
1277 LegalHebrew* legal = new LegalHebrew(error);
1278 if(U_FAILURE(error)){
1279 errln("Could not construct LegalHebrew object. Error: %s", u_errorName(error));
1280 return;
1281 }
1282 RTTest test("Latin-Hebrew");
1283 test.test("[a-zA-Z\\u02BC\\u02BB]", "[[:hebrew:]-[\\u05BD\\uFB00-\\uFBFF]]", "[\\u05F0\\u05F1\\u05F2]", this, quick, legal);
1284 //showElapsed(start, "TestHebrew");
1285 delete legal;
1286 }
1287 void TransliteratorRoundTripTest::TestCyrillic() {
1288 RTTest test("Latin-Cyrillic");
1289 Legal *legal = new Legal();
1290
1291 test.test(UnicodeString("[a-zA-Z\\u0110\\u0111\\u02BA\\u02B9]", ""),
1292 UnicodeString("[[\\u0400-\\u045F] & [:Age=3.2:]]", ""), NULL, this, quick,
1293 legal);
1294
1295 delete legal;
1296 }
1297
1298
1299 // Inter-Indic Tests ----------------------------------
1300 class LegalIndic :public Legal{
1301 UnicodeSet vowelSignSet;
1302 UnicodeSet avagraha;
1303 UnicodeSet nukta;
1304 UnicodeSet virama;
1305 UnicodeSet sanskritStressSigns;
1306 UnicodeSet chandrabindu;
1307
1308 public:
1309 LegalIndic(){
1310 UErrorCode status = U_ZERO_ERROR;
1311 vowelSignSet.addAll( UnicodeSet("[\\u0902\\u0903\\u0904\\u093e-\\u094c\\u0962\\u0963]",status));/* Devanagari */
1312 vowelSignSet.addAll( UnicodeSet("[\\u0982\\u0983\\u09be-\\u09cc\\u09e2\\u09e3\\u09D7]",status));/* Bengali */
1313 vowelSignSet.addAll( UnicodeSet("[\\u0a02\\u0a03\\u0a3e-\\u0a4c\\u0a62\\u0a63\\u0a70\\u0a71]",status));/* Gurmukhi */
1314 vowelSignSet.addAll( UnicodeSet("[\\u0a82\\u0a83\\u0abe-\\u0acc\\u0ae2\\u0ae3]",status));/* Gujarati */
1315 vowelSignSet.addAll( UnicodeSet("[\\u0b02\\u0b03\\u0b3e-\\u0b4c\\u0b62\\u0b63\\u0b56\\u0b57]",status));/* Oriya */
1316 vowelSignSet.addAll( UnicodeSet("[\\u0b82\\u0b83\\u0bbe-\\u0bcc\\u0be2\\u0be3\\u0bd7]",status));/* Tamil */
1317 vowelSignSet.addAll( UnicodeSet("[\\u0c02\\u0c03\\u0c3e-\\u0c4c\\u0c62\\u0c63\\u0c55\\u0c56]",status));/* Telugu */
1318 vowelSignSet.addAll( UnicodeSet("[\\u0c82\\u0c83\\u0cbe-\\u0ccc\\u0ce2\\u0ce3\\u0cd5\\u0cd6]",status));/* Kannada */
1319 vowelSignSet.addAll( UnicodeSet("[\\u0d02\\u0d03\\u0d3e-\\u0d4c\\u0d62\\u0d63\\u0d57]",status));/* Malayalam */
1320
1321 avagraha.addAll(UnicodeSet("[\\u093d\\u09bd\\u0abd\\u0b3d\\u0cbd]",status));
1322 nukta.addAll(UnicodeSet("[\\u093c\\u09bc\\u0a3c\\u0abc\\u0b3c\\u0cbc]",status));
1323 virama.addAll(UnicodeSet("[\\u094d\\u09cd\\u0a4d\\u0acd\\u0b4d\\u0bcd\\u0c4d\\u0ccd\\u0d4d]",status));
1324 sanskritStressSigns.addAll(UnicodeSet("[\\u0951\\u0952\\u0953\\u0954]",status));
1325 chandrabindu.addAll(UnicodeSet("[\\u0901\\u0981\\u0A81\\u0b01\\u0c01]",status));
1326
1327 }
1328 virtual UBool is(const UnicodeString& sourceString) const;
1329 virtual ~LegalIndic() {};
1330 };
1331 UBool LegalIndic::is(const UnicodeString& sourceString) const{
1332 int cp=sourceString.charAt(0);
1333
1334 // A vowel sign cannot be the first char
1335 if(vowelSignSet.contains(cp)){
1336 return FALSE;
1337 }else if(avagraha.contains(cp)){
1338 return FALSE;
1339 }else if(virama.contains(cp)){
1340 return FALSE;
1341 }else if(nukta.contains(cp)){
1342 return FALSE;
1343 }else if(sanskritStressSigns.contains(cp)){
1344 return FALSE;
1345 }else if(chandrabindu.contains(cp) &&
1346 ((sourceString.length()>1) &&
1347 vowelSignSet.contains(sourceString.charAt(1)))){
1348 return FALSE;
1349 }
1350 return TRUE;
1351 }
1352
1353 static const char latinForIndic[] = "[['.0-9A-Za-z~\\u00C0-\\u00C5\\u00C7-\\u00CF\\u00D1-\\u00D6\\u00D9-\\u00DD"
1354 "\\u00E0-\\u00E5\\u00E7-\\u00EF\\u00F1-\\u00F6\\u00F9-\\u00FD\\u00FF-\\u010F"
1355 "\\u0112-\\u0125\\u0128-\\u0130\\u0134-\\u0137\\u0139-\\u013E\\u0143-\\u0148"
1356 "\\u014C-\\u0151\\u0154-\\u0165\\u0168-\\u017E\\u01A0-\\u01A1\\u01AF-\\u01B0"
1357 "\\u01CD-\\u01DC\\u01DE-\\u01E3\\u01E6-\\u01ED\\u01F0\\u01F4-\\u01F5\\u01F8-\\u01FB"
1358 "\\u0200-\\u021B\\u021E-\\u021F\\u0226-\\u0233\\u0303-\\u0304\\u0306\\u0314-\\u0315"
1359 "\\u0325\\u040E\\u0419\\u0439\\u045E\\u04C1-\\u04C2\\u04D0-\\u04D1\\u04D6-\\u04D7"
1360 "\\u04E2-\\u04E3\\u04EE-\\u04EF\\u1E00-\\u1E99\\u1EA0-\\u1EF9\\u1F01\\u1F03\\u1F05"
1361 "\\u1F07\\u1F09\\u1F0B\\u1F0D\\u1F0F\\u1F11\\u1F13\\u1F15\\u1F19\\u1F1B\\u1F1D\\u1F21"
1362 "\\u1F23\\u1F25\\u1F27\\u1F29\\u1F2B\\u1F2D\\u1F2F\\u1F31\\u1F33\\u1F35\\u1F37\\u1F39"
1363 "\\u1F3B\\u1F3D\\u1F3F\\u1F41\\u1F43\\u1F45\\u1F49\\u1F4B\\u1F4D\\u1F51\\u1F53\\u1F55"
1364 "\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F61\\u1F63\\u1F65\\u1F67\\u1F69\\u1F6B\\u1F6D"
1365 "\\u1F6F\\u1F81\\u1F83\\u1F85\\u1F87\\u1F89\\u1F8B\\u1F8D\\u1F8F\\u1F91\\u1F93\\u1F95"
1366 "\\u1F97\\u1F99\\u1F9B\\u1F9D\\u1F9F\\u1FA1\\u1FA3\\u1FA5\\u1FA7\\u1FA9\\u1FAB\\u1FAD"
1367 "\\u1FAF-\\u1FB1\\u1FB8-\\u1FB9\\u1FD0-\\u1FD1\\u1FD8-\\u1FD9\\u1FE0-\\u1FE1\\u1FE5"
1368 "\\u1FE8-\\u1FE9\\u1FEC\\u212A-\\u212B\\uE04D\\uE064]"
1369 "-[\\uE000-\\uE080 \\u01E2\\u01E3]& [[:latin:][:mark:]]]";
1370
1371 void TransliteratorRoundTripTest::TestDevanagariLatin() {
1372 {
1373 UErrorCode status = U_ZERO_ERROR;
1374 UParseError parseError;
1375 TransliteratorPointer t1(Transliterator::createInstance("[\\u0964-\\u0965\\u0981-\\u0983\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC\\u09BE-\\u09C4\\u09C7-\\u09C8\\u09CB-\\u09CD\\u09D7\\u09DC-\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09FA];NFD;Bengali-InterIndic;InterIndic-Gujarati;NFC;",UTRANS_FORWARD, parseError, status));
1376 if((Transliterator *)t1 != NULL){
1377 TransliteratorPointer t2(t1->createInverse(status));
1378 if(U_FAILURE(status)){
1379 errln("FAIL: could not create the Inverse:-( \n");
1380 }
1381 }else {
1382 errln("FAIL: could not create the transliterator. Error: %s\n", u_errorName(status));
1383 }
1384
1385 }
1386 RTTest test("Latin-Devanagari");
1387 Legal *legal = new LegalIndic();
1388
1389 test.test(UnicodeString(latinForIndic, ""),
1390 UnicodeString("[[:Devanagari:][\\u094d][\\u0964\\u0965]]", ""), "[\\u0965\\u0904]", this, quick,
1391 legal, 50);
1392
1393 delete legal;
1394 }
1395
1396 /* Defined this way for HP/UX11CC :-( */
1397 static const int32_t INTER_INDIC_ARRAY_WIDTH = 4;
1398 static const char * const interIndicArray[] = {
1399 "BENGALI-DEVANAGARI", "[:BENGALI:]", "[:Devanagari:]",
1400 "[\\u0904\\u0951-\\u0954\\u0943-\\u0949\\u094a\\u0962\\u0963\\u090D\\u090e\\u0911\\u0912\\u0929\\u0933\\u0934\\u0935\\u093d\\u0950\\u0958\\u0959\\u095a\\u095b\\u095e\\u09f0\\u09f1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1401
1402 "DEVANAGARI-BENGALI", "[:Devanagari:]", "[:BENGALI:]",
1403 "[\\u0951-\\u0954\\u0951-\\u0954\\u09D7\\u090D\\u090e\\u0911\\u0912\\u0929\\u0933\\u0934\\u0935\\u093d\\u0950\\u0958\\u0959\\u095a\\u095b\\u095e\\u09f0\\u09f1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1404
1405 "GURMUKHI-DEVANAGARI", "[:GURMUKHI:]", "[:Devanagari:]",
1406 "[\\u0904\\u0901\\u0902\\u0936\\u0933\\u0951-\\u0954\\u0902\\u0903\\u0943-\\u0949\\u094a\\u0962\\u0963\\u090B\\u090C\\u090D\\u090e\\u0911\\u0912\\u0934\\u0937\\u093D\\u0950\\u0960\\u0961\\u0a72\\u0a73\\u0a74]", /*roundtrip exclusions*/
1407
1408 "DEVANAGARI-GURMUKHI", "[:Devanagari:]", "[:GURMUKHI:]",
1409 "[\\u0904\\u0A02\\u0946\\u0A5C\\u0951-\\u0954\\u0A70\\u0A71\\u090B\\u090C\\u090D\\u090e\\u0911\\u0912\\u0934\\u0937\\u093D\\u0950\\u0960\\u0961\\u0a72\\u0a73\\u0a74]", /*roundtrip exclusions*/
1410
1411 "GUJARATI-DEVANAGARI", "[:GUJARATI:]", "[:Devanagari:]",
1412 "[\\u0946\\u094A\\u0962\\u0963\\u0951-\\u0954\\u0961\\u090c\\u090e\\u0912]", /*roundtrip exclusions*/
1413
1414 "DEVANAGARI-GUJARATI", "[:Devanagari:]", "[:GUJARATI:]",
1415 "[\\u0951-\\u0954\\u0961\\u090c\\u090e\\u0912]", /*roundtrip exclusions*/
1416
1417 "ORIYA-DEVANAGARI", "[:ORIYA:]", "[:Devanagari:]",
1418 "[\\u0904\\u0943-\\u094a\\u0962\\u0963\\u0951-\\u0954\\u0950\\u090D\\u090e\\u0912\\u0911\\u0931\\u0935]", /*roundtrip exclusions*/
1419
1420 "DEVANAGARI-ORIYA", "[:Devanagari:]", "[:ORIYA:]",
1421 "[\\u0b5f\\u0b56\\u0b57\\u0b70\\u0b71\\u0950\\u090D\\u090e\\u0912\\u0911\\u0931]", /*roundtrip exclusions*/
1422
1423 "Tamil-DEVANAGARI", "[:tamil:]", "[:Devanagari:]",
1424 "[\\u0901\\u0904\\u093c\\u0943-\\u094a\\u0951-\\u0954\\u0962\\u0963\\u090B\\u090C\\u090D\\u0911\\u0916\\u0917\\u0918\\u091B\\u091D\\u0920\\u0921\\u0922\\u0925\\u0926\\u0927\\u092B\\u092C\\u092D\\u0936\\u093d\\u0950[\\u0958-\\u0961]]", /*roundtrip exclusions*/
1425
1426 "DEVANAGARI-Tamil", "[:Devanagari:]", "[:tamil:]",
1427 "[\\u0bd7]", /*roundtrip exclusions*/
1428
1429 "Telugu-DEVANAGARI", "[:telugu:]", "[:Devanagari:]",
1430 "[\\u0904\\u093c\\u0950\\u0945\\u0949\\u0951-\\u0954\\u0962\\u0963\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1431
1432 "DEVANAGARI-TELUGU", "[:Devanagari:]", "[:TELUGU:]",
1433 "[\\u0c55\\u0c56\\u0950\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1434
1435 "KANNADA-DEVANAGARI", "[:KANNADA:]", "[:Devanagari:]",
1436 "[\\u0901\\u0904\\u0946\\u093c\\u0950\\u0945\\u0949\\u0951-\\u0954\\u0962\\u0963\\u0950\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1437
1438 "DEVANAGARI-KANNADA", "[:Devanagari:]", "[:KANNADA:]",
1439 "[{\\u0cb0\\u0cbc}{\\u0cb3\\u0cbc}\\u0cde\\u0cd5\\u0cd6\\u0950\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1440
1441 "MALAYALAM-DEVANAGARI", "[:MALAYALAM:]", "[:Devanagari:]",
1442 "[\\u0901\\u0904\\u094a\\u094b\\u094c\\u093c\\u0950\\u0944\\u0945\\u0949\\u0951-\\u0954\\u0962\\u0963\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1443
1444 "DEVANAGARI-MALAYALAM", "[:Devanagari:]", "[:MALAYALAM:]",
1445 "[\\u0d4c\\u0d57\\u0950\\u090D\\u0911\\u093d\\u0929\\u0934[\\u0958-\\u095f]]", /*roundtrip exclusions*/
1446
1447 "GURMUKHI-BENGALI", "[:GURMUKHI:]", "[:BENGALI:]",
1448 "[\\u0981\\u0982\\u09b6\\u09e2\\u09e3\\u09c3\\u09c4\\u09d7\\u098B\\u098C\\u09B7\\u09E0\\u09E1\\u09F0\\u09F1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1449
1450 "BENGALI-GURMUKHI", "[:BENGALI:]", "[:GURMUKHI:]",
1451 "[\\u0A02\\u0a5c\\u0a47\\u0a70\\u0a71\\u0A33\\u0A35\\u0A59\\u0A5A\\u0A5B\\u0A5E\\u0A72\\u0A73\\u0A74]", /*roundtrip exclusions*/
1452
1453 "GUJARATI-BENGALI", "[:GUJARATI:]", "[:BENGALI:]",
1454 "[\\u09d7\\u09e2\\u09e3\\u098c\\u09e1\\u09f0\\u09f1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1455
1456 "BENGALI-GUJARATI", "[:BENGALI:]", "[:GUJARATI:]",
1457 "[\\u0A82\\u0a83\\u0Ac9\\u0Ac5\\u0ac7\\u0A8D\\u0A91\\u0AB3\\u0AB5\\u0ABD\\u0AD0]", /*roundtrip exclusions*/
1458
1459 "ORIYA-BENGALI", "[:ORIYA:]", "[:BENGALI:]",
1460 "[\\u09c4\\u09e2\\u09e3\\u09f0\\u09f1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1461
1462 "BENGALI-ORIYA", "[:BENGALI:]", "[:ORIYA:]",
1463 "[\\u0b35\\u0b71\\u0b5f\\u0b56\\u0b33\\u0b3d]", /*roundtrip exclusions*/
1464
1465 "Tamil-BENGALI", "[:tamil:]", "[:BENGALI:]",
1466 "[\\u0981\\u09bc\\u09c3\\u09c4\\u09e2\\u09e3\\u09f0\\u09f1\\u098B\\u098C\\u0996\\u0997\\u0998\\u099B\\u099D\\u09A0\\u09A1\\u09A2\\u09A5\\u09A6\\u09A7\\u09AB\\u09AC\\u09AD\\u09B6\\u09DC\\u09DD\\u09DF\\u09E0\\u09E1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1467
1468 "BENGALI-Tamil", "[:BENGALI:]", "[:tamil:]",
1469 "[\\u0bc6\\u0bc7\\u0bca\\u0B8E\\u0B92\\u0BA9\\u0BB1\\u0BB3\\u0BB4\\u0BB5]", /*roundtrip exclusions*/
1470
1471 "Telugu-BENGALI", "[:telugu:]", "[:BENGALI:]",
1472 "[\\u09e2\\u09e3\\u09bc\\u09d7\\u09f0\\u09f1\\u09dc\\u09dd\\u09df\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1473
1474 "BENGALI-TELUGU", "[:BENGALI:]", "[:TELUGU:]",
1475 "[\\u0c55\\u0c56\\u0c47\\u0c46\\u0c4a\\u0C0E\\u0C12\\u0C31\\u0C33\\u0C35]", /*roundtrip exclusions*/
1476
1477 "KANNADA-BENGALI", "[:KANNADA:]", "[:BENGALI:]",
1478 "[\\u0981\\u09e2\\u09e3\\u09bc\\u09d7\\u09dc\\u09dd\\u09df\\u09f0\\u09f1\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1479
1480 "BENGALI-KANNADA", "[:BENGALI:]", "[:KANNADA:]",
1481 "[{\\u0cb0\\u0cbc}{\\u0cb3\\u0cbc}\\u0cc6\\u0cca\\u0cd5\\u0cd6\\u0cc7\\u0C8E\\u0C92\\u0CB1\\u0cb3\\u0cb5\\u0cde]", /*roundtrip exclusions*/
1482
1483 "MALAYALAM-BENGALI", "[:MALAYALAM:]", "[:BENGALI:]",
1484 "[\\u0981\\u09e2\\u09e3\\u09bc\\u09c4\\u09f0\\u09f1\\u09dc\\u09dd\\u09df\\u09dc\\u09dd\\u09df\\u09f2-\\u09fa]", /*roundtrip exclusions*/
1485
1486 "BENGALI-MALAYALAM", "[:BENGALI:]", "[:MALAYALAM:]",
1487 "[\\u0d46\\u0d4a\\u0d47\\u0d31-\\u0d35\\u0d0e\\u0d12]", /*roundtrip exclusions*/
1488
1489 "GUJARATI-GURMUKHI", "[:GUJARATI:]", "[:GURMUKHI:]",
1490 "[\\u0A02\\u0ab3\\u0ab6\\u0A70\\u0a71\\u0a82\\u0a83\\u0ac3\\u0ac4\\u0ac5\\u0ac9\\u0a5c\\u0a72\\u0a73\\u0a74\\u0a8b\\u0a8d\\u0a91\\u0abd]", /*roundtrip exclusions*/
1491
1492 "GURMUKHI-GUJARATI", "[:GURMUKHI:]", "[:GUJARATI:]",
1493 "[\\u0a5c\\u0A70\\u0a71\\u0a72\\u0a73\\u0a74\\u0a82\\u0a83\\u0a8b\\u0a8c\\u0a8d\\u0a91\\u0ab3\\u0ab6\\u0ab7\\u0abd\\u0ac3\\u0ac4\\u0ac5\\u0ac9\\u0ad0\\u0ae0\\u0ae1]", /*roundtrip exclusions*/
1494
1495 "ORIYA-GURMUKHI", "[:ORIYA:]", "[:GURMUKHI:]",
1496 "[\\u0A01\\u0A02\\u0a5c\\u0a21\\u0a47\\u0a71\\u0b02\\u0b03\\u0b33\\u0b36\\u0b43\\u0b56\\u0b57\\u0B0B\\u0B0C\\u0B37\\u0B3D\\u0B5F\\u0B60\\u0B61\\u0a35\\u0a72\\u0a73\\u0a74]", /*roundtrip exclusions*/
1497
1498 "GURMUKHI-ORIYA", "[:GURMUKHI:]", "[:ORIYA:]",
1499 "[\\u0b01\\u0b02\\u0b03\\u0b33\\u0b36\\u0b43\\u0b56\\u0b57\\u0B0B\\u0B0C\\u0B37\\u0B3D\\u0B5F\\u0B60\\u0B61\\u0b70\\u0b71]", /*roundtrip exclusions*/
1500
1501 "TAMIL-GURMUKHI", "[:TAMIL:]", "[:GURMUKHI:]",
1502 "[\\u0A01\\u0A02\\u0a33\\u0a36\\u0a3c\\u0a70\\u0a71\\u0a47\\u0A16\\u0A17\\u0A18\\u0A1B\\u0A1D\\u0A20\\u0A21\\u0A22\\u0A25\\u0A26\\u0A27\\u0A2B\\u0A2C\\u0A2D\\u0A59\\u0A5A\\u0A5B\\u0A5C\\u0A5E\\u0A72\\u0A73\\u0A74]", /*roundtrip exclusions*/
1503
1504 "GURMUKHI-TAMIL", "[:GURMUKHI:]", "[:TAMIL:]",
1505 "[\\u0b82\\u0bc6\\u0bca\\u0bd7\\u0bb7\\u0bb3\\u0b83\\u0B8E\\u0B92\\u0BA9\\u0BB1\\u0BB4]", /*roundtrip exclusions*/
1506
1507 "TELUGU-GURMUKHI", "[:TELUGU:]", "[:GURMUKHI:]",
1508 "[\\u0A02\\u0a33\\u0a36\\u0a3c\\u0a70\\u0a71\\u0A59\\u0A5A\\u0A5B\\u0A5C\\u0A5E\\u0A72\\u0A73\\u0A74]", /*roundtrip exclusions*/
1509
1510 "GURMUKHI-TELUGU", "[:GURMUKHI:]", "[:TELUGU:]",
1511 "[\\u0c01\\u0c02\\u0c03\\u0c33\\u0c36\\u0c44\\u0c43\\u0c46\\u0c4a\\u0c56\\u0c55\\u0C0B\\u0C0C\\u0C0E\\u0C12\\u0C31\\u0C37\\u0C60\\u0C61]", /*roundtrip exclusions*/
1512
1513 "KANNADA-GURMUKHI", "[:KANNADA:]", "[:GURMUKHI:]",
1514 "[\\u0A01\\u0A02\\u0a33\\u0a36\\u0a3c\\u0a70\\u0a71\\u0A59\\u0A5A\\u0A5B\\u0A5C\\u0A5E\\u0A72\\u0A73\\u0A74]", /*roundtrip exclusions*/
1515
1516 "GURMUKHI-KANNADA", "[:GURMUKHI:]", "[:KANNADA:]",
1517 "[{\\u0cb0\\u0cbc}{\\u0cb3\\u0cbc}\\u0c82\\u0c83\\u0cb3\\u0cb6\\u0cc4\\u0cc3\\u0cc6\\u0cca\\u0cd5\\u0cd6\\u0C8B\\u0C8C\\u0C8E\\u0C92\\u0CB1\\u0CB7\\u0cbd\\u0CE0\\u0CE1\\u0cde]", /*roundtrip exclusions*/
1518
1519 "MALAYALAM-GURMUKHI", "[:MALAYALAM:]", "[:GURMUKHI:]",
1520 "[\\u0A01\\u0A02\\u0a4b\\u0a4c\\u0a33\\u0a36\\u0a3c\\u0a70\\u0a71\\u0A59\\u0A5A\\u0A5B\\u0A5C\\u0A5E\\u0A72\\u0A73\\u0A74]", /*roundtrip exclusions*/
1521
1522 "GURMUKHI-MALAYALAM", "[:GURMUKHI:]", "[:MALAYALAM:]",
1523 "[\\u0d02\\u0d03\\u0d33\\u0d36\\u0d43\\u0d46\\u0d4a\\u0d4c\\u0d57\\u0D0B\\u0D0C\\u0D0E\\u0D12\\u0D31\\u0D34\\u0D37\\u0D60\\u0D61]", /*roundtrip exclusions*/
1524
1525 "GUJARATI-ORIYA", "[:GUJARATI:]", "[:ORIYA:]",
1526 "[\\u0b56\\u0b57\\u0B0C\\u0B5F\\u0B61\\u0b70\\u0b71]", /*roundtrip exclusions*/
1527
1528 "ORIYA-GUJARATI", "[:ORIYA:]", "[:GUJARATI:]",
1529 "[\\u0Ac4\\u0Ac5\\u0Ac9\\u0Ac7\\u0A8D\\u0A91\\u0AB5\\u0Ad0]", /*roundtrip exclusions*/
1530
1531 "TAMIL-GUJARATI", "[:TAMIL:]", "[:GUJARATI:]",
1532 "[\\u0A81\\u0a8c\\u0abc\\u0ac3\\u0Ac4\\u0Ac5\\u0Ac9\\u0Ac7\\u0A8B\\u0A8D\\u0A91\\u0A96\\u0A97\\u0A98\\u0A9B\\u0A9D\\u0AA0\\u0AA1\\u0AA2\\u0AA5\\u0AA6\\u0AA7\\u0AAB\\u0AAC\\u0AAD\\u0AB6\\u0ABD\\u0AD0\\u0AE0\\u0AE1]", /*roundtrip exclusions*/
1533
1534 "GUJARATI-TAMIL", "[:GUJARATI:]", "[:TAMIL:]",
1535 "[\\u0Bc6\\u0Bca\\u0Bd7\\u0B8E\\u0B92\\u0BA9\\u0BB1\\u0BB4]", /*roundtrip exclusions*/
1536
1537 "TELUGU-GUJARATI", "[:TELUGU:]", "[:GUJARATI:]",
1538 "[\\u0abc\\u0Ac5\\u0Ac9\\u0A8D\\u0A91\\u0ABD\\u0Ad0]", /*roundtrip exclusions*/
1539
1540 "GUJARATI-TELUGU", "[:GUJARATI:]", "[:TELUGU:]",
1541 "[\\u0c46\\u0c4a\\u0c55\\u0c56\\u0C0C\\u0C0E\\u0C12\\u0C31\\u0C61]", /*roundtrip exclusions*/
1542
1543 "KANNADA-GUJARATI", "[:KANNADA:]", "[:GUJARATI:]",
1544 "[\\u0A81\\u0abc\\u0Ac5\\u0Ac9\\u0A8D\\u0A91\\u0ABD\\u0Ad0]", /*roundtrip exclusions*/
1545
1546 "GUJARATI-KANNADA", "[:GUJARATI:]", "[:KANNADA:]",
1547 "[{\\u0cb0\\u0cbc}{\\u0cb3\\u0cbc}\\u0cc6\\u0cca\\u0cd5\\u0cd6\\u0C8C\\u0C8E\\u0C92\\u0CB1\\u0CDE\\u0CE1]", /*roundtrip exclusions*/
1548
1549 "MALAYALAM-GUJARATI", "[:MALAYALAM:]", "[:GUJARATI:]",
1550 "[\\u0A81\\u0ac4\\u0acb\\u0acc\\u0abc\\u0Ac5\\u0Ac9\\u0A8D\\u0A91\\u0ABD\\u0Ad0]", /*roundtrip exclusions*/
1551
1552 "GUJARATI-MALAYALAM", "[:GUJARATI:]", "[:MALAYALAM:]",
1553 "[\\u0d46\\u0d4a\\u0d4c\\u0d55\\u0d57\\u0D0C\\u0D0E\\u0D12\\u0D31\\u0D34\\u0D61]", /*roundtrip exclusions*/
1554
1555 "TAMIL-ORIYA", "[:TAMIL:]", "[:ORIYA:]",
1556 "[\\u0B01\\u0b3c\\u0b43\\u0b56\\u0B0B\\u0B0C\\u0B16\\u0B17\\u0B18\\u0B1B\\u0B1D\\u0B20\\u0B21\\u0B22\\u0B25\\u0B26\\u0B27\\u0B2B\\u0B2C\\u0B2D\\u0B36\\u0B3D\\u0B5C\\u0B5D\\u0B5F\\u0B60\\u0B61\\u0b70\\u0b71]", /*roundtrip exclusions*/
1557
1558 "ORIYA-TAMIL", "[:ORIYA:]", "[:TAMIL:]",
1559 "[\\u0bc6\\u0bca\\u0bc7\\u0B8E\\u0B92\\u0BA9\\u0BB1\\u0BB4\\u0BB5]", /*roundtrip exclusions*/
1560
1561 "TELUGU-ORIYA", "[:TELUGU:]", "[:ORIYA:]",
1562 "[\\u0b3c\\u0b57\\u0b56\\u0B3D\\u0B5C\\u0B5D\\u0B5F\\u0b70\\u0b71]", /*roundtrip exclusions*/
1563
1564 "ORIYA-TELUGU", "[:ORIYA:]", "[:TELUGU:]",
1565 "[\\u0c44\\u0c46\\u0c4a\\u0c55\\u0c47\\u0C0E\\u0C12\\u0C31\\u0C35]", /*roundtrip exclusions*/
1566
1567 "KANNADA-ORIYA", "[:KANNADA:]", "[:ORIYA:]",
1568 "[\\u0B01\\u0b3c\\u0b57\\u0B3D\\u0B5C\\u0B5D\\u0B5F\\u0b70\\u0b71]", /*roundtrip exclusions*/
1569
1570 "ORIYA-KANNADA", "[:ORIYA:]", "[:KANNADA:]",
1571 "[{\\u0cb0\\u0cbc}{\\u0cb3\\u0cbc}\\u0cc4\\u0cc6\\u0cca\\u0cd5\\u0cc7\\u0C8E\\u0C92\\u0CB1\\u0CB5\\u0CDE]", /*roundtrip exclusions*/
1572
1573 "MALAYALAM-ORIYA", "[:MALAYALAM:]", "[:ORIYA:]",
1574 "[\\u0B01\\u0b3c\\u0b56\\u0B3D\\u0B5C\\u0B5D\\u0B5F\\u0b70\\u0b71]", /*roundtrip exclusions*/
1575
1576 "ORIYA-MALAYALAM", "[:ORIYA:]", "[:MALAYALAM:]",
1577 "[\\u0D47\\u0D46\\u0D4a\\u0D0E\\u0D12\\u0D31\\u0D34\\u0D35]", /*roundtrip exclusions*/
1578
1579 "TELUGU-TAMIL", "[:TELUGU:]", "[:TAMIL:]",
1580 "[\\u0bd7\\u0ba9\\u0bb4]", /*roundtrip exclusions*/
1581
1582 "TAMIL-TELUGU", "[:TAMIL:]", "[:TELUGU:]",
1583 "[\\u0C01\\u0c43\\u0c44\\u0c46\\u0c47\\u0c55\\u0c56\\u0c66\\u0C0B\\u0C0C\\u0C16\\u0C17\\u0C18\\u0C1B\\u0C1D\\u0C20\\u0C21\\u0C22\\u0C25\\u0C26\\u0C27\\u0C2B\\u0C2C\\u0C2D\\u0C36\\u0C60\\u0C61]", /*roundtrip exclusions*/
1584
1585 "KANNADA-TAMIL", "[:KANNADA:]", "[:TAMIL:]",
1586 "[\\u0bd7\\u0bc6\\u0ba9\\u0bb4]", /*roundtrip exclusions*/
1587
1588 "TAMIL-KANNADA", "[:TAMIL:]", "[:KANNADA:]",
1589 "[\\u0cc3\\u0cc4\\u0cc6\\u0cc7\\u0cd5\\u0cd6\\u0C8B\\u0C8C\\u0C96\\u0C97\\u0C98\\u0C9B\\u0C9D\\u0CA0\\u0CA1\\u0CA2\\u0CA5\\u0CA6\\u0CA7\\u0CAB\\u0CAC\\u0CAD\\u0CB6\\u0cbc\\u0cbd\\u0CDE\\u0CE0\\u0CE1]", /*roundtrip exclusions*/
1590
1591 "MALAYALAM-TAMIL", "[:MALAYALAM:]", "[:TAMIL:]",
1592 "[\\u0ba9]", /*roundtrip exclusions*/
1593
1594 "TAMIL-MALAYALAM", "[:TAMIL:]", "[:MALAYALAM:]",
1595 "[\\u0d43\\u0d12\\u0D0B\\u0D0C\\u0D16\\u0D17\\u0D18\\u0D1B\\u0D1D\\u0D20\\u0D21\\u0D22\\u0D25\\u0D26\\u0D27\\u0D2B\\u0D2C\\u0D2D\\u0D36\\u0D60\\u0D61]", /*roundtrip exclusions*/
1596
1597 "KANNADA-TELUGU", "[:KANNADA:]", "[:TELUGU:]",
1598 "[\\u0C01\\u0c3f\\u0c46\\u0c48\\u0c4a]", /*roundtrip exclusions*/
1599
1600 "TELUGU-KANNADA", "[:TELUGU:]", "[:KANNADA:]",
1601 "[\\u0cc8\\u0cd5\\u0cd6\\u0cbc\\u0cbd\\u0CDE]", /*roundtrip exclusions*/
1602
1603 "MALAYALAM-TELUGU", "[:MALAYALAM:]", "[:TELUGU:]",
1604 "[\\u0C01\\u0c44\\u0c4a\\u0c4c\\u0c4b\\u0c55\\u0c56]", /*roundtrip exclusions*/
1605
1606 "TELUGU-MALAYALAM", "[:TELUGU:]", "[:MALAYALAM:]",
1607 "[\\u0d4c\\u0d57\\u0D34]", /*roundtrip exclusions*/
1608
1609 "MALAYALAM-KANNADA", "[:MALAYALAM:]", "[:KANNADA:]",
1610 "[\\u0cbc\\u0cbd\\u0cc4\\u0cc6\\u0cca\\u0ccc\\u0ccb\\u0cd5\\u0cd6\\u0cDe]", /*roundtrip exclusions*/
1611
1612 "KANNADA-MALAYALAM", "[:KANNADA:]", "[:MALAYALAM:]",
1613 "[\\u0d4c\\u0d57\\u0d46\\u0D34]", /*roundtrip exclusions*/
1614
1615 "Latin-Bengali",latinForIndic, "[[:Bengali:][\\u0964\\u0965]]",
1616 "[\\u0965\\u09f0-\\u09fa]" /*roundtrip exclusions*/ ,
1617
1618 "Latin-Gurmukhi", latinForIndic, "[[:Gurmukhi:][\\u0964\\u0965]]",
1619 "[\\u0a01\\u0965\\u0a02\\u0a72\\u0a73\\u0a74]" /*roundtrip exclusions*/,
1620
1621 "Latin-Gujarati",latinForIndic, "[[:Gujarati:][\\u0964\\u0965]]",
1622 "[\\u0965]" /*roundtrip exclusions*/,
1623
1624 "Latin-Oriya",latinForIndic, "[[:Oriya:][\\u0964\\u0965]]",
1625 "[\\u0965\\u0b70]" /*roundtrip exclusions*/,
1626
1627 "Latin-Tamil",latinForIndic, "[:Tamil:]",
1628 NULL /*roundtrip exclusions*/,
1629
1630 "Latin-Telugu",latinForIndic, "[:Telugu:]",
1631 NULL /*roundtrip exclusions*/,
1632
1633 "Latin-Kannada",latinForIndic, "[:Kannada:]",
1634 NULL /*roundtrip exclusions*/,
1635
1636 "Latin-Malayalam",latinForIndic, "[:Malayalam:]",
1637 NULL /*roundtrip exclusions*/
1638
1639 };
1640
1641 void TransliteratorRoundTripTest::TestDebug(const char* name,const char fromSet[],
1642 const char* toSet,const char* exclusions){
1643
1644 RTTest test(name);
1645 Legal *legal = new LegalIndic();
1646 test.test(UnicodeString(fromSet,""),UnicodeString(toSet,""),exclusions,this,quick,legal);
1647 }
1648
1649 void TransliteratorRoundTripTest::TestInterIndic() {
1650 //TestDebug("Latin-Gurmukhi", latinForIndic, "[:Gurmukhi:]","[\\u0965\\u0a02\\u0a72\\u0a73\\u0a74]",TRUE);
1651 int32_t num = (int32_t)(sizeof(interIndicArray)/(INTER_INDIC_ARRAY_WIDTH*sizeof(char*)));
1652 if(quick){
1653 logln("Testing only 5 of %i. Skipping rest (use -e for exhaustive)",num);
1654 num = 5;
1655 }
1656 for(int i = 0; i < num;i++){
1657 RTTest test(interIndicArray[i*INTER_INDIC_ARRAY_WIDTH + 0]);
1658 Legal *legal = new LegalIndic();
1659
1660 test.test( interIndicArray[i*INTER_INDIC_ARRAY_WIDTH + 1],
1661 interIndicArray[i*INTER_INDIC_ARRAY_WIDTH + 2],
1662 interIndicArray[i*INTER_INDIC_ARRAY_WIDTH + 3], // roundtrip exclusions
1663 this, quick, legal, 50);
1664
1665 delete legal;
1666 }
1667
1668 }
1669
1670 // end indic tests ----------------------------------------------------------
1671
1672 #endif /* #if !UCONFIG_NO_TRANSLITERATION */