Home | History | Annotate | Download | only in intltest
      1 /********************************************************************
      2  * COPYRIGHT:
      3  * Copyright (c) 2012-2013, International Business Machines Corporation
      4  * and others. All Rights Reserved.
      5  ********************************************************************/
      6 //
      7 //   file:  alphaindex.cpp
      8 //          Alphabetic Index Tests.
      9 //
     10 //   Note: please... no character literals cast to UChars.. use (UChar)0xZZZZ
     11 
     12 #include <stdio.h>  // for sprintf
     13 
     14 #include "intltest.h"
     15 #include "alphaindextst.h"
     16 
     17 #include "unicode/alphaindex.h"
     18 #include "unicode/coll.h"
     19 #include "unicode/localpointer.h"
     20 #include "unicode/tblcoll.h"
     21 #include "unicode/uniset.h"
     22 
     23 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
     24 
     25 // #include <string>
     26 // #include <iostream>
     27 
     28 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
     29 
     30 namespace {
     31 
     32 UnicodeString joinLabelsAndAppend(AlphabeticIndex::ImmutableIndex &index, UnicodeString &dest) {
     33     int32_t oldLength = dest.length();
     34     const AlphabeticIndex::Bucket *bucket;
     35     for (int32_t i = 0; (bucket = index.getBucket(i)) != NULL; ++i) {
     36         if (dest.length() > oldLength) {
     37             dest.append((UChar)0x3A);  // ':'
     38         }
     39         dest.append(bucket->getLabel());
     40     }
     41     return dest;
     42 }
     43 
     44 }  // namespace
     45 
     46 AlphabeticIndexTest::AlphabeticIndexTest() {
     47 }
     48 
     49 AlphabeticIndexTest::~AlphabeticIndexTest() {
     50 }
     51 
     52 void AlphabeticIndexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
     53 {
     54     if (exec) logln("TestSuite AlphabeticIndex: ");
     55     TESTCASE_AUTO_BEGIN;
     56     TESTCASE_AUTO(APITest);
     57     TESTCASE_AUTO(ManyLocalesTest);
     58     TESTCASE_AUTO(HackPinyinTest);
     59     TESTCASE_AUTO(TestBug9009);
     60     TESTCASE_AUTO(TestIndexCharactersList);
     61     TESTCASE_AUTO(TestHaniFirst);
     62     TESTCASE_AUTO(TestPinyinFirst);
     63     TESTCASE_AUTO(TestSchSt);
     64     TESTCASE_AUTO(TestNoLabels);
     65     TESTCASE_AUTO(TestChineseZhuyin);
     66     TESTCASE_AUTO_END;
     67 }
     68 
     69 #define TEST_CHECK_STATUS {if (U_FAILURE(status)) {dataerrln("%s:%d: Test failure.  status=%s", \
     70                                                               __FILE__, __LINE__, u_errorName(status)); return;}}
     71 
     72 #define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", __FILE__, __LINE__);};}
     73 
     74 //
     75 //  APITest.   Invoke every function at least once, and check that it does something.
     76 //             Does not attempt to check complete functionality.
     77 //
     78 void AlphabeticIndexTest::APITest() {
     79     //
     80     //  Simple constructor and destructor,  getBucketCount()
     81     //
     82     UErrorCode status = U_ZERO_ERROR;
     83     int32_t lc = 0;
     84     int32_t i  = 0;
     85     AlphabeticIndex *index = new AlphabeticIndex(Locale::getEnglish(), status);
     86     TEST_CHECK_STATUS;
     87     lc = index->getBucketCount(status);
     88     TEST_CHECK_STATUS;
     89     TEST_ASSERT(28 == lc);    // 26 letters plus two under/overflow labels.
     90     //printf("getBucketCount() == %d\n", lc);
     91     delete index;
     92 
     93     // Constructor from a Collator
     94     //
     95     status = U_ZERO_ERROR;
     96     RuleBasedCollator *coll = dynamic_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status));
     97     TEST_CHECK_STATUS;
     98     TEST_ASSERT(coll != NULL);
     99     index = new AlphabeticIndex(coll, status);
    100     TEST_CHECK_STATUS;
    101     TEST_ASSERT(coll == &index->getCollator());
    102     assertEquals("only the underflow label in an index built from a collator",
    103                  1, index->getBucketCount(status));
    104     TEST_CHECK_STATUS;
    105     delete index;
    106 
    107 
    108     // addLabels()
    109 
    110     status = U_ZERO_ERROR;
    111     index = new AlphabeticIndex(Locale::getEnglish(), status);
    112     TEST_CHECK_STATUS;
    113     UnicodeSet additions;
    114     additions.add((UChar32)0x410).add((UChar32)0x415);   // A couple of Cyrillic letters
    115     index->addLabels(additions, status);
    116     TEST_CHECK_STATUS;
    117     lc = index->getBucketCount(status);
    118     TEST_CHECK_STATUS;
    119     assertEquals("underflow, A-Z, inflow, 2 Cyrillic, overflow",
    120                  31, index->getBucketCount(status));
    121     // std::cout << lc << std::endl;
    122     delete index;
    123 
    124 
    125     // addLabels(Locale)
    126 
    127     status = U_ZERO_ERROR;
    128     index = new AlphabeticIndex(Locale::getEnglish(), status);
    129     TEST_CHECK_STATUS;
    130     AlphabeticIndex &aip = index->addLabels(Locale::getJapanese(), status);
    131     TEST_ASSERT(&aip == index);
    132     TEST_CHECK_STATUS;
    133     lc = index->getBucketCount(status);
    134     TEST_CHECK_STATUS;
    135     TEST_ASSERT(35 < lc);  // Japanese should add a bunch.  Don't rely on the exact value.
    136     delete index;
    137 
    138     // GetCollator(),  Get under/in/over flow labels
    139 
    140     status = U_ZERO_ERROR;
    141     index = new AlphabeticIndex(Locale::getGerman(), status);
    142     TEST_CHECK_STATUS;
    143     Collator *germanCol = Collator::createInstance(Locale::getGerman(), status);
    144     TEST_CHECK_STATUS;
    145     const RuleBasedCollator &indexCol = index->getCollator();
    146     TEST_ASSERT(*germanCol == indexCol);
    147     delete germanCol;
    148 
    149     UnicodeString ELLIPSIS;  ELLIPSIS.append((UChar32)0x2026);
    150     UnicodeString s = index->getUnderflowLabel();
    151     TEST_ASSERT(ELLIPSIS == s);
    152     s = index->getOverflowLabel();
    153     TEST_ASSERT(ELLIPSIS == s);
    154     s = index->getInflowLabel();
    155     TEST_ASSERT(ELLIPSIS == s);
    156     index->setOverflowLabel(UNICODE_STRING_SIMPLE("O"), status);
    157     index->setUnderflowLabel(UNICODE_STRING_SIMPLE("U"), status).setInflowLabel(UNICODE_STRING_SIMPLE("I"), status);
    158     s = index->getUnderflowLabel();
    159     TEST_ASSERT(UNICODE_STRING_SIMPLE("U") == s);
    160     s = index->getOverflowLabel();
    161     TEST_ASSERT(UNICODE_STRING_SIMPLE("O") == s);
    162     s = index->getInflowLabel();
    163     TEST_ASSERT(UNICODE_STRING_SIMPLE("I") == s);
    164 
    165 
    166 
    167 
    168     delete index;
    169 
    170 
    171 
    172     const UnicodeString adam = UNICODE_STRING_SIMPLE("Adam");
    173     const UnicodeString baker = UNICODE_STRING_SIMPLE("Baker");
    174     const UnicodeString charlie = UNICODE_STRING_SIMPLE("Charlie");
    175     const UnicodeString chad = UNICODE_STRING_SIMPLE("Chad");
    176     const UnicodeString zed  = UNICODE_STRING_SIMPLE("Zed");
    177     const UnicodeString Cyrillic = UNICODE_STRING_SIMPLE("\\u0410\\u0443\\u0435").unescape();
    178 
    179     // addRecord(), verify that it comes back out.
    180     //
    181     status = U_ZERO_ERROR;
    182     index = new AlphabeticIndex(Locale::getEnglish(), status);
    183     TEST_CHECK_STATUS;
    184     index->addRecord(UnicodeString("Adam"), this, status);
    185     UBool   b;
    186     TEST_CHECK_STATUS;
    187     index->resetBucketIterator(status);
    188     TEST_CHECK_STATUS;
    189     index->nextBucket(status);  // Move to underflow label
    190     index->nextBucket(status);  // Move to "A"
    191     TEST_CHECK_STATUS;
    192     const UnicodeString &label2 = index->getBucketLabel();
    193     UnicodeString A_STR = UNICODE_STRING_SIMPLE("A");
    194     TEST_ASSERT(A_STR == label2);
    195 
    196     b = index->nextRecord(status);
    197     TEST_CHECK_STATUS;
    198     TEST_ASSERT(b);
    199     const UnicodeString &itemName = index->getRecordName();
    200     TEST_ASSERT(adam == itemName);
    201 
    202     const void *itemContext = index->getRecordData();
    203     TEST_ASSERT(itemContext == this);
    204 
    205     delete index;
    206 
    207     // clearRecords, addRecord(), Iteration
    208 
    209     status = U_ZERO_ERROR;
    210     index = new AlphabeticIndex(Locale::getEnglish(), status);
    211     TEST_CHECK_STATUS;
    212     while (index->nextBucket(status)) {
    213         TEST_CHECK_STATUS;
    214         while (index->nextRecord(status)) {
    215             TEST_CHECK_STATUS;
    216             TEST_ASSERT(FALSE);   // No items have been added.
    217         }
    218         TEST_CHECK_STATUS;
    219     }
    220 
    221     index->addRecord(adam, NULL, status);
    222     index->addRecord(baker, NULL, status);
    223     index->addRecord(charlie, NULL, status);
    224     index->addRecord(chad, NULL, status);
    225     TEST_CHECK_STATUS;
    226     int itemCount = 0;
    227     index->resetBucketIterator(status);
    228     while (index->nextBucket(status)) {
    229         TEST_CHECK_STATUS;
    230         while (index->nextRecord(status)) {
    231             TEST_CHECK_STATUS;
    232             ++itemCount;
    233         }
    234     }
    235     TEST_CHECK_STATUS;
    236     TEST_ASSERT(itemCount == 4);
    237 
    238     TEST_ASSERT(index->nextBucket(status) == FALSE);
    239     index->resetBucketIterator(status);
    240     TEST_CHECK_STATUS;
    241     TEST_ASSERT(index->nextBucket(status) == TRUE);
    242 
    243     index->clearRecords(status);
    244     TEST_CHECK_STATUS;
    245     index->resetBucketIterator(status);
    246     while (index->nextBucket(status)) {
    247         TEST_CHECK_STATUS;
    248         while (index->nextRecord(status)) {
    249             TEST_ASSERT(FALSE);   // No items have been added.
    250         }
    251     }
    252     TEST_CHECK_STATUS;
    253     delete index;
    254 
    255     // getBucketLabel(), getBucketType()
    256 
    257     status = U_ZERO_ERROR;
    258     index = new AlphabeticIndex(Locale::getEnglish(), status);
    259     TEST_CHECK_STATUS;
    260     index->setUnderflowLabel(adam, status).setOverflowLabel(charlie, status);
    261     TEST_CHECK_STATUS;
    262     for (i=0; index->nextBucket(status); i++) {
    263         TEST_CHECK_STATUS;
    264         UnicodeString label = index->getBucketLabel();
    265         UAlphabeticIndexLabelType type = index->getBucketLabelType();
    266         if (i == 0) {
    267             TEST_ASSERT(type == U_ALPHAINDEX_UNDERFLOW);
    268             TEST_ASSERT(label == adam);
    269         } else if (i <= 26) {
    270             // Labels A - Z for English locale
    271             TEST_ASSERT(type == U_ALPHAINDEX_NORMAL);
    272             UnicodeString expectedLabel((UChar)(0x40 + i));
    273             TEST_ASSERT(expectedLabel == label);
    274         } else if (i == 27) {
    275             TEST_ASSERT(type == U_ALPHAINDEX_OVERFLOW);
    276             TEST_ASSERT(label == charlie);
    277         } else {
    278             TEST_ASSERT(FALSE);
    279         }
    280     }
    281     TEST_ASSERT(i==28);
    282     delete index;
    283 
    284     // getBucketIndex()
    285 
    286     status = U_ZERO_ERROR;
    287     index = new AlphabeticIndex(Locale::getEnglish(), status);
    288     TEST_CHECK_STATUS;
    289     int32_t n = index->getBucketIndex(adam, status);
    290     TEST_CHECK_STATUS;
    291     TEST_ASSERT(n == 1);    /*  Label #0 is underflow, 1 is A, etc. */
    292     n = index->getBucketIndex(baker, status);
    293     TEST_ASSERT(n == 2);
    294     n = index->getBucketIndex(Cyrillic, status);
    295     TEST_ASSERT(n == 27);   // Overflow label
    296     n = index->getBucketIndex(zed, status);
    297     TEST_ASSERT(n == 26);
    298 
    299     for (i=0; index->nextBucket(status); i++) {
    300         n = index->getBucketIndex();
    301         TEST_ASSERT(n == i);
    302         UnicodeString label = index->getBucketLabel();
    303         TEST_ASSERT(n == i);
    304     }
    305     TEST_ASSERT(i == 28);
    306 
    307     delete index;
    308     index = new AlphabeticIndex(Locale::createFromName("ru"), status);
    309     TEST_CHECK_STATUS;
    310     assertEquals("Russian index.getBucketCount()", 32, index->getBucketCount(status));
    311     // Latin-script names should go into the underflow label (0)
    312     // if the Russian collation does not use script reordering,
    313     // but into the overflow label (getBucketCount()-1)
    314     // if Russian sorts Cyrillic first.
    315     int32_t reorderCodes[20];
    316     int32_t expectedLatinIndex = 0;
    317     if (index->getCollator().getReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status) > 0) {
    318         expectedLatinIndex = index->getBucketCount(status) - 1;
    319     }
    320     n = index->getBucketIndex(adam, status);
    321     TEST_CHECK_STATUS;
    322     assertEquals("Russian index.getBucketIndex(adam)", expectedLatinIndex, n);
    323     n = index->getBucketIndex(baker, status);
    324     assertEquals("Russian index.getBucketIndex(baker)", expectedLatinIndex, n);
    325     n = index->getBucketIndex(Cyrillic, status);
    326     assertEquals("Russian index.getBucketIndex(Cyrillic)", 1, n);
    327     n = index->getBucketIndex(zed, status);
    328     assertEquals("Russian index.getBucketIndex(zed)", expectedLatinIndex, n);
    329 
    330     delete index;
    331 
    332 }
    333 
    334 
    335 static const char * KEY_LOCALES[] = {
    336             "en", "es", "de", "fr", "ja", "it", "tr", "pt", "zh", "nl",
    337             "pl", "ar", "ru", "zh_Hant", "ko", "th", "sv", "fi", "da",
    338             "he", "nb", "el", "hr", "bg", "sk", "lt", "vi", "lv", "sr",
    339             "pt_PT", "ro", "hu", "cs", "id", "sl", "fil", "fa", "uk",
    340             "ca", "hi", "et", "eu", "is", "sw", "ms", "bn", "am", "ta",
    341             "te", "mr", "ur", "ml", "kn", "gu", "or", ""};
    342 
    343 
    344 void AlphabeticIndexTest::ManyLocalesTest() {
    345     UErrorCode status = U_ZERO_ERROR;
    346     int32_t  lc = 0;
    347 
    348     for (int i=0; ; ++i) {
    349         status = U_ZERO_ERROR;
    350         const char *localeName = KEY_LOCALES[i];
    351         if (localeName[0] == 0) {
    352             break;
    353         }
    354         // std::cout <<  localeName << "  ";
    355         Locale loc = Locale::createFromName(localeName);
    356         AlphabeticIndex index(loc, status);
    357         TEST_CHECK_STATUS;
    358         lc = index.getBucketCount(status);
    359         TEST_CHECK_STATUS;
    360         // std::cout << "getBucketCount() == " << lc << std::endl;
    361 
    362         LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    363         TEST_CHECK_STATUS;
    364         TEST_ASSERT(lc == immIndex->getBucketCount());
    365 
    366         assertEquals("initial bucket index", -1, index.getBucketIndex());
    367         int32_t bucketIndex = 0;
    368         while (index.nextBucket(status)) {
    369             TEST_CHECK_STATUS;
    370             assertEquals("bucket index", bucketIndex, index.getBucketIndex());
    371             const UnicodeString &label = index.getBucketLabel();
    372             TEST_ASSERT(label.length()>0);
    373             // std::string ss;
    374             // std::cout << ":" << label.toUTF8String(ss);
    375             const AlphabeticIndex::Bucket *bucket = immIndex->getBucket(bucketIndex);
    376             TEST_ASSERT(bucket != NULL);
    377             assertEquals("bucket label vs. immutable: locale=" + UnicodeString(localeName) +
    378                          " index=" + bucketIndex,
    379                          label, bucket->getLabel());
    380             TEST_ASSERT(&label != &bucket->getLabel());  // not the same pointers
    381             UAlphabeticIndexLabelType labelType = index.getBucketLabelType();
    382             TEST_ASSERT(labelType == bucket->getLabelType());
    383             ++bucketIndex;
    384         }
    385         // std::cout << ":" << std::endl;
    386 
    387         TEST_ASSERT(immIndex->getBucketCount() == bucketIndex);
    388         TEST_ASSERT(immIndex->getBucket(-1) == NULL);
    389         TEST_ASSERT(immIndex->getBucket(bucketIndex) == NULL);
    390     }
    391 }
    392 
    393 
    394 // Test data for Pinyin based indexes.
    395 //  The Chinese characters should be distributed under latin labels in
    396 //  an index.
    397 
    398 static const char *pinyinTestData[] = {
    399         "\\u0101", "\\u5416", "\\u58ba", //
    400         "b", "\\u516b", "\\u62d4", "\\u8500", //
    401         "c", "\\u5693", "\\u7938", "\\u9e7e", //
    402         "d", "\\u5491", "\\u8fcf", "\\u964a", //
    403         "\\u0113","\\u59b8", "\\u92e8", "\\u834b", //
    404         "f", "\\u53d1", "\\u9197", "\\u99a5", //
    405         "g", "\\u7324", "\\u91d3", "\\u8142", //
    406         "h", "\\u598e", "\\u927f", "\\u593b", //
    407         "j", "\\u4e0c", "\\u6785", "\\u9d58", //
    408         "k", "\\u5494", "\\u958b", "\\u7a52", //
    409         "l", "\\u5783", "\\u62c9", "\\u9ba5", //
    410         "m", "\\u5638", "\\u9ebb", "\\u65c0", //
    411         "n", "\\u62ff", "\\u80ad", "\\u685b", //
    412         "\\u014D", "\\u5662", "\\u6bee", "\\u8bb4", //
    413         "p", "\\u5991", "\\u8019", "\\u8c31", //
    414         "q", "\\u4e03", "\\u6053", "\\u7f56", //
    415         "r", "\\u5465", "\\u72aa", "\\u6e03", //
    416         "s", "\\u4ee8", "\\u9491", "\\u93c1", //
    417         "t", "\\u4ed6", "\\u9248", "\\u67dd", //
    418         "w", "\\u5c72", "\\u5558", "\\u5a7a", //
    419         "x", "\\u5915", "\\u5438", "\\u6bbe", //
    420         "y", "\\u4e2b", "\\u82bd", "\\u8574", //
    421         "z", "\\u5e00", "\\u707d", "\\u5c0a",
    422         NULL
    423     };
    424 
    425 void AlphabeticIndexTest::HackPinyinTest() {
    426     UErrorCode status = U_ZERO_ERROR;
    427     AlphabeticIndex aindex(Locale::createFromName("zh"), status);
    428     TEST_CHECK_STATUS;
    429 
    430     UnicodeString names[sizeof(pinyinTestData) / sizeof(pinyinTestData[0])];
    431     int32_t  nameCount;
    432     for (nameCount=0; pinyinTestData[nameCount] != NULL; nameCount++) {
    433         names[nameCount] = UnicodeString(pinyinTestData[nameCount], -1, UnicodeString::kInvariant).unescape();
    434         aindex.addRecord(names[nameCount], &names[nameCount], status);
    435         TEST_CHECK_STATUS;
    436         if (U_FAILURE(status)) {
    437             return;
    438         }
    439     }
    440     TEST_ASSERT(nameCount == aindex.getRecordCount(status));
    441 
    442     // Weak checking:  make sure that none of the Chinese names landed in the overflow bucket
    443     //   of the index, and that the names are distributed among several buckets.
    444     //   (Exact expected data would be subject to change with evolution of the collation rules.)
    445 
    446     int32_t bucketCount = 0;
    447     int32_t filledBucketCount = 0;
    448     while (aindex.nextBucket(status)) {
    449         bucketCount++;
    450         UnicodeString label = aindex.getBucketLabel();
    451         // std::string s;
    452         // std::cout << label.toUTF8String(s) << ":  ";
    453 
    454         UBool  bucketHasContents = FALSE;
    455         while (aindex.nextRecord(status)) {
    456             bucketHasContents = TRUE;
    457             UnicodeString name = aindex.getRecordName();
    458             if (aindex.getBucketLabelType() != U_ALPHAINDEX_NORMAL) {
    459                 errln("File %s, Line %d, Name \"\\u%x\" is in an under or overflow bucket.",
    460                     __FILE__, __LINE__, name.char32At(0));
    461             }
    462             // s.clear();
    463             // std::cout << aindex.getRecordName().toUTF8String(s) << " ";
    464         }
    465         if (bucketHasContents) {
    466             filledBucketCount++;
    467         }
    468         // std::cout << std::endl;
    469     }
    470     TEST_ASSERT(bucketCount > 25);
    471     TEST_ASSERT(filledBucketCount > 15);
    472 }
    473 
    474 
    475 void AlphabeticIndexTest::TestBug9009() {
    476     UErrorCode status = U_ZERO_ERROR;
    477     Locale loc("root");
    478     AlphabeticIndex aindex(loc, status);
    479     TEST_CHECK_STATUS;
    480     aindex.nextBucket(status);  // Crash here before bug was fixed.
    481     TEST_CHECK_STATUS;
    482 }
    483 
    484 static const char *localeAndIndexCharactersLists[][2] = {
    485     /* Arabic*/ {"ar", "\\u0627:\\u0628:\\u062A:\\u062B:\\u062C:\\u062D:\\u062E:\\u062F:\\u0630:\\u0631:\\u0632:\\u0633:\\u0634:\\u0635:\\u0636:\\u0637:\\u0638:\\u0639:\\u063A:\\u0641:\\u0642:\\u0643:\\u0644:\\u0645:\\u0646:\\u0647:\\u0648:\\u064A"},
    486     /* Bulgarian*/  {"bg", "\\u0410:\\u0411:\\u0412:\\u0413:\\u0414:\\u0415:\\u0416:\\u0417:\\u0418:\\u0419:\\u041A:\\u041B:\\u041C:\\u041D:\\u041E:\\u041F:\\u0420:\\u0421:\\u0422:\\u0423:\\u0424:\\u0425:\\u0426:\\u0427:\\u0428:\\u0429:\\u042E:\\u042F"},
    487     /* Catalan*/    {"ca", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    488     /* Czech*/  {"cs", "A:B:C:\\u010C:D:E:F:G:H:CH:I:J:K:L:M:N:O:P:Q:R:\\u0158:S:\\u0160:T:U:V:W:X:Y:Z:\\u017D"},
    489     /* Danish*/ {"da", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:\\u00C6:\\u00D8:\\u00C5"},
    490     /* German*/ {"de", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    491     /* Greek*/  {"el", "\\u0391:\\u0392:\\u0393:\\u0394:\\u0395:\\u0396:\\u0397:\\u0398:\\u0399:\\u039A:\\u039B:\\u039C:\\u039D:\\u039E:\\u039F:\\u03A0:\\u03A1:\\u03A3:\\u03A4:\\u03A5:\\u03A6:\\u03A7:\\u03A8:\\u03A9"},
    492     /* English*/    {"en", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    493     /* Spanish*/    {"es", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:\\u00D1:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    494     /* Estonian*/   {"et", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:\\u0160:Z:\\u017D:T:U:V:\\u00D5:\\u00C4:\\u00D6:\\u00DC:X:Y"},
    495     /* Finnish*/    {"fi", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:\\u00C5:\\u00C4:\\u00D6"},
    496     /* Filipino*/   {"fil", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    497     /* French*/ {"fr", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    498     /* Hebrew*/ {"he", "\\u05D0:\\u05D1:\\u05D2:\\u05D3:\\u05D4:\\u05D5:\\u05D6:\\u05D7:\\u05D8:\\u05D9:\\u05DB:\\u05DC:\\u05DE:\\u05E0:\\u05E1:\\u05E2:\\u05E4:\\u05E6:\\u05E7:\\u05E8:\\u05E9:\\u05EA"},
    499     /* Icelandic*/  {"is", "A:\\u00C1:B:C:D:\\u00D0:E:\\u00C9:F:G:H:I:\\u00CD:J:K:L:M:N:O:\\u00D3:P:Q:R:S:T:U:\\u00DA:V:W:X:Y:\\u00DD:Z:\\u00DE:\\u00C6:\\u00D6"},
    500     /* Italian*/    {"it", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    501     /* Japanese*/   {"ja", "\\u3042:\\u304B:\\u3055:\\u305F:\\u306A:\\u306F:\\u307E:\\u3084:\\u3089:\\u308F"},
    502     /* Korean*/ {"ko", "\\u3131:\\u3134:\\u3137:\\u3139:\\u3141:\\u3142:\\u3145:\\u3147:\\u3148:\\u314A:\\u314B:\\u314C:\\u314D:\\u314E"},
    503     /* Lithuanian*/ {"lt", "A:B:C:\\u010C:D:E:F:G:H:I:J:K:L:M:N:O:P:R:S:\\u0160:T:U:V:Z:\\u017D"},
    504     /* Latvian*/    {"lv", "A:B:C:\\u010C:D:E:F:G:\\u0122:H:I:J:K:\\u0136:L:\\u013B:M:N:\\u0145:O:P:Q:R:S:\\u0160:T:U:V:W:X:Z:\\u017D"},
    505     /* Norwegian Bokm\\u00E5l*/  {"nb", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:\\u00C6:\\u00D8:\\u00C5"},
    506     /* Dutch*/  {"nl", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    507     /* Polish*/ {"pl", "A:\\u0104:B:C:\\u0106:D:E:\\u0118:F:G:H:I:J:K:L:\\u0141:M:N:\\u0143:O:\\u00D3:P:Q:R:S:\\u015A:T:U:V:W:X:Y:Z:\\u0179:\\u017B"},
    508     /* Portuguese*/ {"pt", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    509     /* Romanian*/   {"ro", "A:\\u0102:\\u00C2:B:C:D:E:F:G:H:I:\\u00CE:J:K:L:M:N:O:P:Q:R:S:\\u0218:T:\\u021A:U:V:W:X:Y:Z"},
    510     /* Russian*/    {"ru", "\\u0410:\\u0411:\\u0412:\\u0413:\\u0414:\\u0415:\\u0416:\\u0417:\\u0418:\\u0419:\\u041A:\\u041B:\\u041C:\\u041D:\\u041E:\\u041F:\\u0420:\\u0421:\\u0422:\\u0423:\\u0424:\\u0425:\\u0426:\\u0427:\\u0428:\\u0429:\\u042B:\\u042D:\\u042E:\\u042F"},
    511     /* Slovak*/ {"sk", "A:\\u00C4:B:C:\\u010C:D:E:F:G:H:CH:I:J:K:L:M:N:O:\\u00D4:P:Q:R:S:\\u0160:T:U:V:W:X:Y:Z:\\u017D"},
    512     /* Slovenian*/  {"sl", "A:B:C:\\u010C:\\u0106:D:\\u0110:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:\\u0160:T:U:V:W:X:Y:Z:\\u017D"},
    513     /* Serbian*/    {"sr", "\\u0410:\\u0411:\\u0412:\\u0413:\\u0414:\\u0402:\\u0415:\\u0416:\\u0417:\\u0418:\\u0408:\\u041A:\\u041B:\\u0409:\\u041C:\\u041D:\\u040A:\\u041E:\\u041F:\\u0420:\\u0421:\\u0422:\\u040B:\\u0423:\\u0424:\\u0425:\\u0426:\\u0427:\\u040F:\\u0428"},
    514     /* Swedish*/    {"sv", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:\\u00C5:\\u00C4:\\u00D6"},
    515     /* Turkish*/    {"tr", "A:B:C:\\u00C7:D:E:F:G:H:I:\\u0130:J:K:L:M:N:O:\\u00D6:P:Q:R:S:\\u015E:T:U:\\u00DC:V:W:X:Y:Z"},
    516     /* Ukrainian*/  {"uk", "\\u0410:\\u0411:\\u0412:\\u0413:\\u0490:\\u0414:\\u0415:\\u0404:\\u0416:\\u0417:\\u0418:\\u0406:\\u0407:\\u0419:\\u041A:\\u041B:\\u041C:\\u041D:\\u041E:\\u041F:\\u0420:\\u0421:\\u0422:\\u0423:\\u0424:\\u0425:\\u0426:\\u0427:\\u0428:\\u0429:\\u042E:\\u042F"},
    517     /* Vietnamese*/ {"vi", "A:\\u0102:\\u00C2:B:C:D:\\u0110:E:\\u00CA:F:G:H:I:J:K:L:M:N:O:\\u00D4:\\u01A0:P:Q:R:S:T:U:\\u01AF:V:W:X:Y:Z"},
    518     /* Chinese*/    {"zh", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    519     /* Chinese (Traditional Han)*/  {"zh_Hant", "1\\u5283:2\\u5283:3\\u5283:4\\u5283:5\\u5283:6\\u5283:7\\u5283:8\\u5283:9\\u5283:10\\u5283:11\\u5283:12\\u5283:13\\u5283:14\\u5283:15\\u5283:16\\u5283:17\\u5283:18\\u5283:19\\u5283:20\\u5283:21\\u5283:22\\u5283:23\\u5283:24\\u5283:25\\u5283:26\\u5283:27\\u5283:28\\u5283:29\\u5283:30\\u5283:31\\u5283:32\\u5283:33\\u5283:35\\u5283:36\\u5283:39\\u5283:48\\u5283"},
    520 
    521     // As of ICU 52, ICU does not have collation data for the following language.
    522     // Therefore, constructing an AlphabeticIndex for it
    523     // ends up with a collator for the default locale
    524     // which makes the test unreliable. (see ticket #10277)
    525     // It exposes a bigger problem in that it may not be desirable for collation
    526     // to fall back to the default locale.
    527 
    528     // /* Basque*/ {"eu", "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z"},
    529 };
    530 
    531 void AlphabeticIndexTest::TestIndexCharactersList() {
    532     UErrorCode status = U_ZERO_ERROR;
    533     for (int32_t i = 0; i < LENGTHOF(localeAndIndexCharactersLists); ++i) {
    534         const char *(&localeAndIndexCharacters)[2] = localeAndIndexCharactersLists[i];
    535         const char *locale = localeAndIndexCharacters[0];
    536         UnicodeString expectedIndexCharacters
    537             = (UnicodeString("\\u2026:") + localeAndIndexCharacters[1] + ":\\u2026").unescape();
    538         AlphabeticIndex index(locale, status);
    539         TEST_CHECK_STATUS;
    540         LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    541         TEST_CHECK_STATUS;
    542 
    543         // Join the elements of the list to a string with delimiter ":"
    544         UnicodeString actualIndexCharacters;
    545         assertEquals(locale,
    546                      expectedIndexCharacters,
    547                      joinLabelsAndAppend(*immIndex, actualIndexCharacters));
    548         logln(locale + UnicodeString(": ") + actualIndexCharacters);
    549     }
    550 }
    551 
    552 void AlphabeticIndexTest::TestHaniFirst() {
    553     UErrorCode status = U_ZERO_ERROR;
    554     LocalPointer<RuleBasedCollator> coll(
    555         static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
    556 
    557     if (U_FAILURE(status)) {
    558         dataerrln("Failed Collator::createInstance call - %s", u_errorName(status));
    559         return;
    560     }
    561     int32_t reorderCodes[] = { USCRIPT_HAN };
    562     coll->setReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status);
    563     TEST_CHECK_STATUS;
    564     AlphabeticIndex index(coll.orphan(), status);
    565     TEST_CHECK_STATUS;
    566     assertEquals("getBucketCount()", 1, index.getBucketCount(status));   // ... (underflow only)
    567     index.addLabels(Locale::getEnglish(), status);
    568     assertEquals("getBucketCount()", 28, index.getBucketCount(status));  // ... A-Z ...
    569     int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), status);
    570     assertEquals("getBucketIndex(U+897F)", 0, bucketIndex);  // underflow bucket
    571     bucketIndex = index.getBucketIndex("i", status);
    572     assertEquals("getBucketIndex(i)", 9, bucketIndex);
    573     bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status);
    574     assertEquals("getBucketIndex(Greek alpha)", 27, bucketIndex);
    575     // TODO: Test with an unassigned code point (not just U+FFFF)
    576     // when unassigned code points are not in the Hani reordering group any more.
    577     // String unassigned = UTF16.valueOf(0x50005);
    578     bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status);
    579     assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex);
    580 }
    581 
    582 void AlphabeticIndexTest::TestPinyinFirst() {
    583     UErrorCode status = U_ZERO_ERROR;
    584     LocalPointer<RuleBasedCollator> coll(
    585         static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChinese(), status)));
    586     if (U_FAILURE(status)) {
    587         dataerrln("Failed Collator::createInstance call - %s", u_errorName(status));
    588         return;
    589     }
    590     int32_t reorderCodes[] = { USCRIPT_HAN };
    591     coll->setReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status);
    592     TEST_CHECK_STATUS;
    593     AlphabeticIndex index(coll.orphan(), status);
    594     TEST_CHECK_STATUS;
    595     assertEquals("getBucketCount()", 1, index.getBucketCount(status));   // ... (underflow only)
    596     index.addLabels(Locale::getChinese(), status);
    597     assertEquals("getBucketCount()", 28, index.getBucketCount(status));  // ... A-Z ...
    598     int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), status);
    599     assertEquals("getBucketIndex(U+897F)", (int32_t)((UChar)0x0058/*X*/ - (UChar)0x0041/*A*/ + 1), (int32_t)bucketIndex);
    600     bucketIndex = index.getBucketIndex("i", status);
    601     assertEquals("getBucketIndex(i)", 9, bucketIndex);
    602     bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status);
    603     assertEquals("getBucketIndex(Greek alpha)", (int32_t)27, bucketIndex);
    604     // TODO: Test with an unassigned code point (not just U+FFFF)
    605     // when unassigned code points are not in the Hani reordering group any more.
    606     // String unassigned = UTF16.valueOf(0x50005);
    607     bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status);
    608     assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex);
    609 }
    610 
    611 void AlphabeticIndexTest::TestSchSt() {
    612     UErrorCode status = U_ZERO_ERROR;
    613     AlphabeticIndex index(Locale::getGerman(), status);
    614     index.addLabels(UnicodeSet("[\\u00C6{Sch*}{St*}]", status), status);
    615     TEST_CHECK_STATUS;
    616     // ... A AE-ligature B-R S Sch St T-Z ...
    617     LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    618     TEST_CHECK_STATUS;
    619     assertEquals("getBucketCount()", 31, index.getBucketCount(status));
    620     assertEquals("immutable getBucketCount()", 31, immIndex->getBucketCount());
    621     static const struct TestCase {
    622         const char *name;
    623         int32_t bucketIndex;
    624         const char *bucketLabel;
    625     } testCases[] = {
    626         // name, bucket index, bucket label
    627         { "Adelbert", 1, "A" },
    628         { "Afrika", 1, "A" },
    629         { "\\u00C6sculap", 2, "\\u00C6" },
    630         { "Aesthet", 2, "\\u00C6" },
    631         { "Berlin", 3, "B" },
    632         { "Rilke", 19, "R" },
    633         { "Sacher", 20, "S" },
    634         { "Seiler", 20, "S" },
    635         { "Sultan", 20, "S" },
    636         { "Schiller", 21, "Sch" },
    637         { "Steiff", 22, "St" },
    638         { "Thomas", 23, "T" }
    639     };
    640     for (int32_t i = 0; i < LENGTHOF(testCases); ++i) {
    641         const TestCase &testCase = testCases[i];
    642         UnicodeString name = UnicodeString(testCase.name).unescape();
    643         UnicodeString label = UnicodeString(testCase.bucketLabel).unescape();
    644         char msg[100];
    645         sprintf(msg, "getBucketIndex(%s)", testCase.name);
    646         assertEquals(msg, testCase.bucketIndex, index.getBucketIndex(name, status));
    647         sprintf(msg, "immutable getBucketIndex(%s)", testCase.name);
    648         assertEquals(msg, testCase.bucketIndex, immIndex->getBucketIndex(name, status));
    649         sprintf(msg, "immutable bucket label (%s)", testCase.name);
    650         assertEquals(msg, label, immIndex->getBucket(testCase.bucketIndex)->getLabel());
    651     }
    652 }
    653 
    654 void AlphabeticIndexTest::TestNoLabels() {
    655     UErrorCode status = U_ZERO_ERROR;
    656     LocalPointer<RuleBasedCollator> coll(
    657         static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoot(), status)));
    658     TEST_CHECK_STATUS;
    659     AlphabeticIndex index(coll.orphan(), status);
    660     TEST_CHECK_STATUS;
    661     index.addRecord(UnicodeString((UChar)0x897f), NULL, status);
    662     index.addRecord("i", NULL, status);
    663     index.addRecord(UnicodeString((UChar)0x03B1), NULL, status);
    664     assertEquals("getBucketCount()", 1, index.getBucketCount(status));  // ...
    665     TEST_ASSERT(index.nextBucket(status));
    666     assertEquals("underflow label type", (int32_t)U_ALPHAINDEX_UNDERFLOW, index.getBucketLabelType());
    667     assertEquals("all records in the underflow bucket", (int32_t)3, index.getBucketRecordCount());
    668 }
    669 
    670 void AlphabeticIndexTest::TestChineseZhuyin() {
    671     UErrorCode status = U_ZERO_ERROR;
    672     char loc[100];
    673     uloc_forLanguageTag("zh-u-co-zhuyin", loc, LENGTHOF(loc), NULL, &status);
    674     AlphabeticIndex index(loc, status);
    675     LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    676     TEST_CHECK_STATUS;
    677     assertEquals("getBucketCount()", 38, immIndex->getBucketCount());
    678     assertEquals("label 1", UnicodeString((UChar)0x3105), immIndex->getBucket(1)->getLabel());
    679     assertEquals("label 2", UnicodeString((UChar)0x3106), immIndex->getBucket(2)->getLabel());
    680     assertEquals("label 3", UnicodeString((UChar)0x3107), immIndex->getBucket(3)->getLabel());
    681     assertEquals("label 4", UnicodeString((UChar)0x3108), immIndex->getBucket(4)->getLabel());
    682     assertEquals("label 5", UnicodeString((UChar)0x3109), immIndex->getBucket(5)->getLabel());
    683 }
    684 
    685 #endif
    686