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