Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: source/test/intltest/alphaindextst.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/intltest/alphaindextst.h ('k') | source/test/intltest/apicoll.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 2012-2013, International Business Machines Corporation 3 * Copyright (c) 2012-2014, International Business Machines Corporation
4 * and others. All Rights Reserved. 4 * and others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 // 6 //
7 // file: alphaindex.cpp 7 // file: alphaindextst.cpp
8 // Alphabetic Index Tests. 8 // Alphabetic Index Tests.
9 // 9 //
10 // Note: please... no character literals cast to UChars.. use (UChar)0xZZZZ 10 // Note: please... no character literals cast to UChars.. use (UChar)0xZZZZ
11 11
12 #include <stdio.h> // for sprintf 12 #include <stdio.h> // for sprintf
13 13
14 #include "intltest.h" 14 #include "intltest.h"
15 #include "alphaindextst.h" 15 #include "alphaindextst.h"
16 #include "cmemory.h"
16 17
17 #include "unicode/alphaindex.h" 18 #include "unicode/alphaindex.h"
18 #include "unicode/coll.h" 19 #include "unicode/coll.h"
19 #include "unicode/localpointer.h" 20 #include "unicode/localpointer.h"
20 #include "unicode/tblcoll.h" 21 #include "unicode/tblcoll.h"
21 #include "unicode/uniset.h" 22 #include "unicode/uniset.h"
22 23
23 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION 24 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
24 25
25 // #include <string> 26 // #include <string>
26 // #include <iostream> 27 // #include <iostream>
27 28
28 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
29
30 namespace { 29 namespace {
31 30
32 UnicodeString joinLabelsAndAppend(AlphabeticIndex::ImmutableIndex &index, Unicod eString &dest) { 31 UnicodeString joinLabelsAndAppend(AlphabeticIndex::ImmutableIndex &index, Unicod eString &dest) {
33 int32_t oldLength = dest.length(); 32 int32_t oldLength = dest.length();
34 const AlphabeticIndex::Bucket *bucket; 33 const AlphabeticIndex::Bucket *bucket;
35 for (int32_t i = 0; (bucket = index.getBucket(i)) != NULL; ++i) { 34 for (int32_t i = 0; (bucket = index.getBucket(i)) != NULL; ++i) {
36 if (dest.length() > oldLength) { 35 if (dest.length() > oldLength) {
37 dest.append((UChar)0x3A); // ':' 36 dest.append((UChar)0x3A); // ':'
38 } 37 }
39 dest.append(bucket->getLabel()); 38 dest.append(bucket->getLabel());
(...skipping 16 matching lines...) Expand all
56 TESTCASE_AUTO(APITest); 55 TESTCASE_AUTO(APITest);
57 TESTCASE_AUTO(ManyLocalesTest); 56 TESTCASE_AUTO(ManyLocalesTest);
58 TESTCASE_AUTO(HackPinyinTest); 57 TESTCASE_AUTO(HackPinyinTest);
59 TESTCASE_AUTO(TestBug9009); 58 TESTCASE_AUTO(TestBug9009);
60 TESTCASE_AUTO(TestIndexCharactersList); 59 TESTCASE_AUTO(TestIndexCharactersList);
61 TESTCASE_AUTO(TestHaniFirst); 60 TESTCASE_AUTO(TestHaniFirst);
62 TESTCASE_AUTO(TestPinyinFirst); 61 TESTCASE_AUTO(TestPinyinFirst);
63 TESTCASE_AUTO(TestSchSt); 62 TESTCASE_AUTO(TestSchSt);
64 TESTCASE_AUTO(TestNoLabels); 63 TESTCASE_AUTO(TestNoLabels);
65 TESTCASE_AUTO(TestChineseZhuyin); 64 TESTCASE_AUTO(TestChineseZhuyin);
65 TESTCASE_AUTO(TestJapaneseKanji);
66 TESTCASE_AUTO(TestChineseUnihan);
66 TESTCASE_AUTO_END; 67 TESTCASE_AUTO_END;
67 } 68 }
68 69
69 #define TEST_CHECK_STATUS {if (U_FAILURE(status)) {dataerrln("%s:%d: Test failur e. status=%s", \ 70 #define TEST_CHECK_STATUS {if (U_FAILURE(status)) {dataerrln("%s:%d: Test failur e. status=%s", \
70 __FILE__, __LINE__ , u_errorName(status)); return;}} 71 __FILE__, __LINE__ , u_errorName(status)); return;}}
71 72
72 #define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", _ _FILE__, __LINE__);};} 73 #define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("%s:%d: Test failure \n", _ _FILE__, __LINE__);};}
73 74
74 // 75 //
75 // APITest. Invoke every function at least once, and check that it does somet hing. 76 // APITest. Invoke every function at least once, and check that it does somet hing.
(...skipping 10 matching lines...) Expand all
86 TEST_CHECK_STATUS; 87 TEST_CHECK_STATUS;
87 lc = index->getBucketCount(status); 88 lc = index->getBucketCount(status);
88 TEST_CHECK_STATUS; 89 TEST_CHECK_STATUS;
89 TEST_ASSERT(28 == lc); // 26 letters plus two under/overflow labels. 90 TEST_ASSERT(28 == lc); // 26 letters plus two under/overflow labels.
90 //printf("getBucketCount() == %d\n", lc); 91 //printf("getBucketCount() == %d\n", lc);
91 delete index; 92 delete index;
92 93
93 // Constructor from a Collator 94 // Constructor from a Collator
94 // 95 //
95 status = U_ZERO_ERROR; 96 status = U_ZERO_ERROR;
96 RuleBasedCollator *coll = dynamic_cast<RuleBasedCollator *>(Collator::create Instance(Locale::getChinese(), status)); 97 RuleBasedCollator *coll = dynamic_cast<RuleBasedCollator *>(
98 Collator::createInstance(Locale::getGerman(), status));
97 TEST_CHECK_STATUS; 99 TEST_CHECK_STATUS;
98 TEST_ASSERT(coll != NULL); 100 TEST_ASSERT(coll != NULL);
99 index = new AlphabeticIndex(coll, status); 101 index = new AlphabeticIndex(coll, status);
100 TEST_CHECK_STATUS; 102 TEST_CHECK_STATUS;
101 TEST_ASSERT(coll == &index->getCollator()); 103 TEST_ASSERT(coll == &index->getCollator());
102 assertEquals("only the underflow label in an index built from a collator", 104 assertEquals("only the underflow label in an index built from a collator",
103 1, index->getBucketCount(status)); 105 1, index->getBucketCount(status));
104 TEST_CHECK_STATUS; 106 TEST_CHECK_STATUS;
105 delete index; 107 delete index;
106 108
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 delete index; 309 delete index;
308 index = new AlphabeticIndex(Locale::createFromName("ru"), status); 310 index = new AlphabeticIndex(Locale::createFromName("ru"), status);
309 TEST_CHECK_STATUS; 311 TEST_CHECK_STATUS;
310 assertEquals("Russian index.getBucketCount()", 32, index->getBucketCount(sta tus)); 312 assertEquals("Russian index.getBucketCount()", 32, index->getBucketCount(sta tus));
311 // Latin-script names should go into the underflow label (0) 313 // Latin-script names should go into the underflow label (0)
312 // if the Russian collation does not use script reordering, 314 // if the Russian collation does not use script reordering,
313 // but into the overflow label (getBucketCount()-1) 315 // but into the overflow label (getBucketCount()-1)
314 // if Russian sorts Cyrillic first. 316 // if Russian sorts Cyrillic first.
315 int32_t reorderCodes[20]; 317 int32_t reorderCodes[20];
316 int32_t expectedLatinIndex = 0; 318 int32_t expectedLatinIndex = 0;
317 if (index->getCollator().getReorderCodes(reorderCodes, LENGTHOF(reorderCodes ), status) > 0) { 319 if (index->getCollator().getReorderCodes(reorderCodes, UPRV_LENGTHOF(reorder Codes), status) > 0) {
318 expectedLatinIndex = index->getBucketCount(status) - 1; 320 expectedLatinIndex = index->getBucketCount(status) - 1;
319 } 321 }
320 n = index->getBucketIndex(adam, status); 322 n = index->getBucketIndex(adam, status);
321 TEST_CHECK_STATUS; 323 TEST_CHECK_STATUS;
322 assertEquals("Russian index.getBucketIndex(adam)", expectedLatinIndex, n); 324 assertEquals("Russian index.getBucketIndex(adam)", expectedLatinIndex, n);
323 n = index->getBucketIndex(baker, status); 325 n = index->getBucketIndex(baker, status);
324 assertEquals("Russian index.getBucketIndex(baker)", expectedLatinIndex, n); 326 assertEquals("Russian index.getBucketIndex(baker)", expectedLatinIndex, n);
325 n = index->getBucketIndex(Cyrillic, status); 327 n = index->getBucketIndex(Cyrillic, status);
326 assertEquals("Russian index.getBucketIndex(Cyrillic)", 1, n); 328 assertEquals("Russian index.getBucketIndex(Cyrillic)", 1, n);
327 n = index->getBucketIndex(zed, status); 329 n = index->getBucketIndex(zed, status);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // ends up with a collator for the default locale 525 // ends up with a collator for the default locale
524 // which makes the test unreliable. (see ticket #10277) 526 // which makes the test unreliable. (see ticket #10277)
525 // It exposes a bigger problem in that it may not be desirable for collation 527 // It exposes a bigger problem in that it may not be desirable for collation
526 // to fall back to the default locale. 528 // to fall back to the default locale.
527 529
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"} , 530 // /* 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 }; 531 };
530 532
531 void AlphabeticIndexTest::TestIndexCharactersList() { 533 void AlphabeticIndexTest::TestIndexCharactersList() {
532 UErrorCode status = U_ZERO_ERROR; 534 UErrorCode status = U_ZERO_ERROR;
533 for (int32_t i = 0; i < LENGTHOF(localeAndIndexCharactersLists); ++i) { 535 for (int32_t i = 0; i < UPRV_LENGTHOF(localeAndIndexCharactersLists); ++i) {
534 const char *(&localeAndIndexCharacters)[2] = localeAndIndexCharactersLis ts[i]; 536 const char *(&localeAndIndexCharacters)[2] = localeAndIndexCharactersLis ts[i];
535 const char *locale = localeAndIndexCharacters[0]; 537 const char *locale = localeAndIndexCharacters[0];
536 UnicodeString expectedIndexCharacters 538 UnicodeString expectedIndexCharacters
537 = (UnicodeString("\\u2026:") + localeAndIndexCharacters[1] + ":\\u20 26").unescape(); 539 = (UnicodeString("\\u2026:") + localeAndIndexCharacters[1] + ":\\u20 26").unescape();
538 AlphabeticIndex index(locale, status); 540 AlphabeticIndex index(locale, status);
539 TEST_CHECK_STATUS; 541 TEST_CHECK_STATUS;
540 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmuta bleIndex(status)); 542 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmuta bleIndex(status));
541 TEST_CHECK_STATUS; 543 TEST_CHECK_STATUS;
542 544
543 // Join the elements of the list to a string with delimiter ":" 545 // Join the elements of the list to a string with delimiter ":"
544 UnicodeString actualIndexCharacters; 546 UnicodeString actualIndexCharacters;
545 assertEquals(locale, 547 assertEquals(locale,
546 expectedIndexCharacters, 548 expectedIndexCharacters,
547 joinLabelsAndAppend(*immIndex, actualIndexCharacters)); 549 joinLabelsAndAppend(*immIndex, actualIndexCharacters));
548 logln(locale + UnicodeString(": ") + actualIndexCharacters); 550 logln(locale + UnicodeString(": ") + actualIndexCharacters);
549 } 551 }
550 } 552 }
551 553
552 void AlphabeticIndexTest::TestHaniFirst() { 554 void AlphabeticIndexTest::TestHaniFirst() {
553 UErrorCode status = U_ZERO_ERROR; 555 UErrorCode status = U_ZERO_ERROR;
554 LocalPointer<RuleBasedCollator> coll( 556 LocalPointer<RuleBasedCollator> coll(
555 static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoo t(), status))); 557 static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getRoo t(), status)));
556 558
557 if (U_FAILURE(status)) { 559 if (U_FAILURE(status)) {
558 dataerrln("Failed Collator::createInstance call - %s", u_errorName(statu s)); 560 dataerrln("Failed Collator::createInstance call - %s", u_errorName(statu s));
559 return; 561 return;
560 } 562 }
561 int32_t reorderCodes[] = { USCRIPT_HAN }; 563 int32_t reorderCodes[] = { USCRIPT_HAN };
562 coll->setReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status); 564 coll->setReorderCodes(reorderCodes, UPRV_LENGTHOF(reorderCodes), status);
563 TEST_CHECK_STATUS; 565 TEST_CHECK_STATUS;
564 AlphabeticIndex index(coll.orphan(), status); 566 AlphabeticIndex index(coll.orphan(), status);
565 TEST_CHECK_STATUS; 567 TEST_CHECK_STATUS;
566 assertEquals("getBucketCount()", 1, index.getBucketCount(status)); // ... (underflow only) 568 assertEquals("getBucketCount()", 1, index.getBucketCount(status)); // ... (underflow only)
567 index.addLabels(Locale::getEnglish(), status); 569 index.addLabels(Locale::getEnglish(), status);
568 assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ... 570 assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ...
569 int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), sta tus); 571 int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), sta tus);
570 assertEquals("getBucketIndex(U+897F)", 0, bucketIndex); // underflow bucket 572 assertEquals("getBucketIndex(U+897F)", 0, bucketIndex); // underflow bucket
571 bucketIndex = index.getBucketIndex("i", status); 573 bucketIndex = index.getBucketIndex("i", status);
572 assertEquals("getBucketIndex(i)", 9, bucketIndex); 574 assertEquals("getBucketIndex(i)", 9, bucketIndex);
573 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status); 575 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status);
574 assertEquals("getBucketIndex(Greek alpha)", 27, bucketIndex); 576 assertEquals("getBucketIndex(Greek alpha)", 27, bucketIndex);
575 // TODO: Test with an unassigned code point (not just U+FFFF) 577 // U+50005 is an unassigned code point which sorts at the end, independent o f the Hani group.
576 // when unassigned code points are not in the Hani reordering group any more . 578 bucketIndex = index.getBucketIndex(UnicodeString(0x50005), status);
577 // String unassigned = UTF16.valueOf(0x50005); 579 assertEquals("getBucketIndex(U+50005)", 27, bucketIndex);
578 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status); 580 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status);
579 assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex); 581 assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex);
580 } 582 }
581 583
582 void AlphabeticIndexTest::TestPinyinFirst() { 584 void AlphabeticIndexTest::TestPinyinFirst() {
583 UErrorCode status = U_ZERO_ERROR; 585 UErrorCode status = U_ZERO_ERROR;
584 LocalPointer<RuleBasedCollator> coll( 586 LocalPointer<RuleBasedCollator> coll(
585 static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChi nese(), status))); 587 static_cast<RuleBasedCollator *>(Collator::createInstance(Locale::getChi nese(), status)));
586 if (U_FAILURE(status)) { 588 if (U_FAILURE(status)) {
587 dataerrln("Failed Collator::createInstance call - %s", u_errorName(statu s)); 589 dataerrln("Failed Collator::createInstance call - %s", u_errorName(statu s));
588 return; 590 return;
589 } 591 }
590 int32_t reorderCodes[] = { USCRIPT_HAN }; 592 int32_t reorderCodes[] = { USCRIPT_HAN };
591 coll->setReorderCodes(reorderCodes, LENGTHOF(reorderCodes), status); 593 coll->setReorderCodes(reorderCodes, UPRV_LENGTHOF(reorderCodes), status);
592 TEST_CHECK_STATUS; 594 TEST_CHECK_STATUS;
593 AlphabeticIndex index(coll.orphan(), status); 595 AlphabeticIndex index(coll.orphan(), status);
594 TEST_CHECK_STATUS; 596 TEST_CHECK_STATUS;
595 assertEquals("getBucketCount()", 1, index.getBucketCount(status)); // ... (underflow only) 597 assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ...
596 index.addLabels(Locale::getChinese(), status); 598 index.addLabels(Locale::getChinese(), status);
597 assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ... 599 assertEquals("getBucketCount()", 28, index.getBucketCount(status)); // ... A-Z ...
598 int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), sta tus); 600 int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x897f), sta tus);
599 assertEquals("getBucketIndex(U+897F)", (int32_t)((UChar)0x0058/*X*/ - (UChar )0x0041/*A*/ + 1), (int32_t)bucketIndex); 601 assertEquals("getBucketIndex(U+897F)", (int32_t)((UChar)0x0058/*X*/ - (UChar )0x0041/*A*/ + 1), bucketIndex);
600 bucketIndex = index.getBucketIndex("i", status); 602 bucketIndex = index.getBucketIndex("i", status);
601 assertEquals("getBucketIndex(i)", 9, bucketIndex); 603 assertEquals("getBucketIndex(i)", 9, bucketIndex);
602 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status); 604 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x03B1), status);
603 assertEquals("getBucketIndex(Greek alpha)", (int32_t)27, bucketIndex); 605 assertEquals("getBucketIndex(Greek alpha)", (int32_t)27, bucketIndex);
604 // TODO: Test with an unassigned code point (not just U+FFFF) 606 // U+50005 is an unassigned code point which sorts at the end, independent o f the Hani group.
605 // when unassigned code points are not in the Hani reordering group any more . 607 bucketIndex = index.getBucketIndex(UnicodeString(0x50005), status);
606 // String unassigned = UTF16.valueOf(0x50005); 608 assertEquals("getBucketIndex(U+50005)", 27, bucketIndex);
607 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status); 609 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0xFFFF), status);
608 assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex); 610 assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex);
609 } 611 }
610 612
611 void AlphabeticIndexTest::TestSchSt() { 613 void AlphabeticIndexTest::TestSchSt() {
612 UErrorCode status = U_ZERO_ERROR; 614 UErrorCode status = U_ZERO_ERROR;
613 AlphabeticIndex index(Locale::getGerman(), status); 615 AlphabeticIndex index(Locale::getGerman(), status);
614 index.addLabels(UnicodeSet("[\\u00C6{Sch*}{St*}]", status), status); 616 index.addLabels(UnicodeSet("[\\u00C6{Sch*}{St*}]", status), status);
615 TEST_CHECK_STATUS; 617 TEST_CHECK_STATUS;
616 // ... A AE-ligature B-R S Sch St T-Z ... 618 // ... A AE-ligature B-R S Sch St T-Z ...
(...skipping 13 matching lines...) Expand all
630 { "Aesthet", 2, "\\u00C6" }, 632 { "Aesthet", 2, "\\u00C6" },
631 { "Berlin", 3, "B" }, 633 { "Berlin", 3, "B" },
632 { "Rilke", 19, "R" }, 634 { "Rilke", 19, "R" },
633 { "Sacher", 20, "S" }, 635 { "Sacher", 20, "S" },
634 { "Seiler", 20, "S" }, 636 { "Seiler", 20, "S" },
635 { "Sultan", 20, "S" }, 637 { "Sultan", 20, "S" },
636 { "Schiller", 21, "Sch" }, 638 { "Schiller", 21, "Sch" },
637 { "Steiff", 22, "St" }, 639 { "Steiff", 22, "St" },
638 { "Thomas", 23, "T" } 640 { "Thomas", 23, "T" }
639 }; 641 };
640 for (int32_t i = 0; i < LENGTHOF(testCases); ++i) { 642 for (int32_t i = 0; i < UPRV_LENGTHOF(testCases); ++i) {
641 const TestCase &testCase = testCases[i]; 643 const TestCase &testCase = testCases[i];
642 UnicodeString name = UnicodeString(testCase.name).unescape(); 644 UnicodeString name = UnicodeString(testCase.name).unescape();
643 UnicodeString label = UnicodeString(testCase.bucketLabel).unescape(); 645 UnicodeString label = UnicodeString(testCase.bucketLabel).unescape();
644 char msg[100]; 646 char msg[100];
645 sprintf(msg, "getBucketIndex(%s)", testCase.name); 647 sprintf(msg, "getBucketIndex(%s)", testCase.name);
646 assertEquals(msg, testCase.bucketIndex, index.getBucketIndex(name, statu s)); 648 assertEquals(msg, testCase.bucketIndex, index.getBucketIndex(name, statu s));
647 sprintf(msg, "immutable getBucketIndex(%s)", testCase.name); 649 sprintf(msg, "immutable getBucketIndex(%s)", testCase.name);
648 assertEquals(msg, testCase.bucketIndex, immIndex->getBucketIndex(name, s tatus)); 650 assertEquals(msg, testCase.bucketIndex, immIndex->getBucketIndex(name, s tatus));
649 sprintf(msg, "immutable bucket label (%s)", testCase.name); 651 sprintf(msg, "immutable bucket label (%s)", testCase.name);
650 assertEquals(msg, label, immIndex->getBucket(testCase.bucketIndex)->getL abel()); 652 assertEquals(msg, label, immIndex->getBucket(testCase.bucketIndex)->getL abel());
(...skipping 12 matching lines...) Expand all
663 index.addRecord(UnicodeString((UChar)0x03B1), NULL, status); 665 index.addRecord(UnicodeString((UChar)0x03B1), NULL, status);
664 assertEquals("getBucketCount()", 1, index.getBucketCount(status)); // ... 666 assertEquals("getBucketCount()", 1, index.getBucketCount(status)); // ...
665 TEST_ASSERT(index.nextBucket(status)); 667 TEST_ASSERT(index.nextBucket(status));
666 assertEquals("underflow label type", (int32_t)U_ALPHAINDEX_UNDERFLOW, index. getBucketLabelType()); 668 assertEquals("underflow label type", (int32_t)U_ALPHAINDEX_UNDERFLOW, index. getBucketLabelType());
667 assertEquals("all records in the underflow bucket", (int32_t)3, index.getBuc ketRecordCount()); 669 assertEquals("all records in the underflow bucket", (int32_t)3, index.getBuc ketRecordCount());
668 } 670 }
669 671
670 void AlphabeticIndexTest::TestChineseZhuyin() { 672 void AlphabeticIndexTest::TestChineseZhuyin() {
671 UErrorCode status = U_ZERO_ERROR; 673 UErrorCode status = U_ZERO_ERROR;
672 char loc[100]; 674 char loc[100];
673 uloc_forLanguageTag("zh-u-co-zhuyin", loc, LENGTHOF(loc), NULL, &status); 675 uloc_forLanguageTag("zh-u-co-zhuyin", loc, UPRV_LENGTHOF(loc), NULL, &status );
674 AlphabeticIndex index(loc, status); 676 AlphabeticIndex index(loc, status);
675 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableI ndex(status)); 677 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableI ndex(status));
676 TEST_CHECK_STATUS; 678 TEST_CHECK_STATUS;
677 assertEquals("getBucketCount()", 38, immIndex->getBucketCount()); 679 assertEquals("getBucketCount()", 38, immIndex->getBucketCount());
678 assertEquals("label 1", UnicodeString((UChar)0x3105), immIndex->getBucket(1) ->getLabel()); 680 assertEquals("label 1", UnicodeString((UChar)0x3105), immIndex->getBucket(1) ->getLabel());
679 assertEquals("label 2", UnicodeString((UChar)0x3106), immIndex->getBucket(2) ->getLabel()); 681 assertEquals("label 2", UnicodeString((UChar)0x3106), immIndex->getBucket(2) ->getLabel());
680 assertEquals("label 3", UnicodeString((UChar)0x3107), immIndex->getBucket(3) ->getLabel()); 682 assertEquals("label 3", UnicodeString((UChar)0x3107), immIndex->getBucket(3) ->getLabel());
681 assertEquals("label 4", UnicodeString((UChar)0x3108), immIndex->getBucket(4) ->getLabel()); 683 assertEquals("label 4", UnicodeString((UChar)0x3108), immIndex->getBucket(4) ->getLabel());
682 assertEquals("label 5", UnicodeString((UChar)0x3109), immIndex->getBucket(5) ->getLabel()); 684 assertEquals("label 5", UnicodeString((UChar)0x3109), immIndex->getBucket(5) ->getLabel());
683 } 685 }
684 686
687 void AlphabeticIndexTest::TestJapaneseKanji() {
688 UErrorCode status = U_ZERO_ERROR;
689 AlphabeticIndex index(Locale::getJapanese(), status);
690 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableI ndex(status));
691 TEST_CHECK_STATUS;
692 // There are no index characters for Kanji in the Japanese standard collator .
693 // They should all go into the overflow bucket.
694 static const UChar32 kanji[] = { 0x4E9C, 0x95C7, 0x4E00, 0x58F1 };
695 int32_t overflowIndex = immIndex->getBucketCount() - 1;
696 for(int32_t i = 0; i < UPRV_LENGTHOF(kanji); ++i) {
697 char msg[40];
698 sprintf(msg, "kanji[%d]=U+%04lX in overflow bucket", (int)i, (long)kanji [i]);
699 assertEquals(msg, overflowIndex, immIndex->getBucketIndex(UnicodeString( kanji[i]), status));
700 TEST_CHECK_STATUS;
701 }
702 }
703
704 void AlphabeticIndexTest::TestChineseUnihan() {
705 UErrorCode status = U_ZERO_ERROR;
706 AlphabeticIndex index("zh-u-co-unihan", status);
707 if(U_FAILURE(status)) {
708 dataerrln("unable create an AlphabeticIndex for Chinese/unihan: %s", u_e rrorName(status));
709 return;
710 }
711 index.setMaxLabelCount(500, status); // ICU 54 default is 99.
712 LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableI ndex(status));
713 TEST_CHECK_STATUS;
714 int32_t bucketCount = immIndex->getBucketCount();
715 if(bucketCount < 216) {
716 // There should be at least an underflow and overflow label,
717 // and one for each of 214 radicals,
718 // and maybe additional labels for simplified radicals.
719 dataerrln("too few buckets/labels for Chinese/unihan: %d (is zh/unihan d ata available?)",
720 bucketCount);
721 return;
722 } else {
723 logln("Chinese/unihan has %d buckets/labels", bucketCount);
724 }
725 // bucketIndex = radical number, adjusted for simplified radicals in lower b uckets.
726 int32_t bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x4e5d), sta tus);
727 assertEquals("getBucketIndex(U+4E5D)", 5, bucketIndex);
728 bucketIndex = index.getBucketIndex(UnicodeString((UChar)0x7527), status);
729 assertEquals("getBucketIndex(U+7527)", 100, bucketIndex);
730 }
731
685 #endif 732 #endif
OLDNEW
« no previous file with comments | « source/test/intltest/alphaindextst.h ('k') | source/test/intltest/apicoll.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698