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