1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
|
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2010-2014, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: ucharstrietest.cpp
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2010nov16
* created by: Markus W. Scherer
*/
#include <string.h>
#include "unicode/utypes.h"
#include "unicode/appendable.h"
#include "unicode/localpointer.h"
#include "unicode/ucharstrie.h"
#include "unicode/ucharstriebuilder.h"
#include "unicode/uniset.h"
#include "unicode/unistr.h"
#include "unicode/utf16.h"
#include "intltest.h"
#include "cmemory.h"
struct StringAndValue {
const char *s;
int32_t value;
};
class UCharsTrieTest : public IntlTest {
public:
UCharsTrieTest();
virtual ~UCharsTrieTest();
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=nullptr) override;
void TestBuilder();
void TestEmpty();
void Test_a();
void Test_a_ab();
void TestShortestBranch();
void TestBranches();
void TestLongSequence();
void TestLongBranch();
void TestValuesForState();
void TestCompact();
void TestFirstForCodePoint();
void TestNextForCodePoint();
UCharsTrie *buildLargeTrie(int32_t numUniqueFirst);
void TestLargeTrie();
UCharsTrie *buildMonthsTrie(UStringTrieBuildOption buildOption);
void TestHasUniqueValue();
void TestGetNextUChars();
void TestIteratorFromBranch();
void TestIteratorFromLinearMatch();
void TestTruncatingIteratorFromRoot();
void TestTruncatingIteratorFromLinearMatchShort();
void TestTruncatingIteratorFromLinearMatchLong();
void TestIteratorFromUChars();
void checkData(const StringAndValue data[], int32_t dataLength);
void checkData(const StringAndValue data[], int32_t dataLength, UStringTrieBuildOption buildOption);
UCharsTrie *buildTrie(const StringAndValue data[], int32_t dataLength,
UStringTrieBuildOption buildOption);
void checkFirst(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkNext(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkNextWithState(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkNextWithState64(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkNextString(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkIterator(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
void checkIterator(UCharsTrie::Iterator &iter, const StringAndValue data[], int32_t dataLength);
private:
UCharsTrieBuilder *builder_;
};
extern IntlTest *createUCharsTrieTest() {
return new UCharsTrieTest();
}
UCharsTrieTest::UCharsTrieTest() : builder_(nullptr) {
IcuTestErrorCode errorCode(*this, "UCharsTrieTest()");
builder_=new UCharsTrieBuilder(errorCode);
}
UCharsTrieTest::~UCharsTrieTest() {
delete builder_;
}
void UCharsTrieTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
if(exec) {
logln("TestSuite UCharsTrieTest: ");
}
TESTCASE_AUTO_BEGIN;
TESTCASE_AUTO(TestBuilder);
TESTCASE_AUTO(TestEmpty);
TESTCASE_AUTO(Test_a);
TESTCASE_AUTO(Test_a_ab);
TESTCASE_AUTO(TestShortestBranch);
TESTCASE_AUTO(TestBranches);
TESTCASE_AUTO(TestLongSequence);
TESTCASE_AUTO(TestLongBranch);
TESTCASE_AUTO(TestValuesForState);
TESTCASE_AUTO(TestCompact);
TESTCASE_AUTO(TestFirstForCodePoint);
TESTCASE_AUTO(TestNextForCodePoint);
TESTCASE_AUTO(TestLargeTrie);
TESTCASE_AUTO(TestHasUniqueValue);
TESTCASE_AUTO(TestGetNextUChars);
TESTCASE_AUTO(TestIteratorFromBranch);
TESTCASE_AUTO(TestIteratorFromLinearMatch);
TESTCASE_AUTO(TestTruncatingIteratorFromRoot);
TESTCASE_AUTO(TestTruncatingIteratorFromLinearMatchShort);
TESTCASE_AUTO(TestTruncatingIteratorFromLinearMatchLong);
TESTCASE_AUTO(TestIteratorFromUChars);
TESTCASE_AUTO_END;
}
void UCharsTrieTest::TestBuilder() {
IcuTestErrorCode errorCode(*this, "TestBuilder()");
delete builder_->build(USTRINGTRIE_BUILD_FAST, errorCode);
if(errorCode.reset()!=U_INDEX_OUTOFBOUNDS_ERROR) {
errln("UCharsTrieBuilder().build() did not set U_INDEX_OUTOFBOUNDS_ERROR");
return;
}
// TODO: remove .build(...) once add() checks for duplicates.
builder_->add("=", 0, errorCode).add("=", 1, errorCode).build(USTRINGTRIE_BUILD_FAST, errorCode);
if(errorCode.reset()!=U_ILLEGAL_ARGUMENT_ERROR) {
errln("UCharsTrieBuilder.add() did not detect duplicates");
return;
}
}
void UCharsTrieTest::TestEmpty() {
static const StringAndValue data[]={
{ "", 0 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::Test_a() {
static const StringAndValue data[]={
{ "a", 1 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::Test_a_ab() {
static const StringAndValue data[]={
{ "a", 1 },
{ "ab", 100 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestShortestBranch() {
static const StringAndValue data[]={
{ "a", 1000 },
{ "b", 2000 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestBranches() {
static const StringAndValue data[]={
{ "a", 0x10 },
{ "cc", 0x40 },
{ "e", 0x100 },
{ "ggg", 0x400 },
{ "i", 0x1000 },
{ "kkkk", 0x4000 },
{ "n", 0x10000 },
{ "ppppp", 0x40000 },
{ "r", 0x100000 },
{ "sss", 0x200000 },
{ "t", 0x400000 },
{ "uu", 0x800000 },
{ "vv", 0x7fffffff },
{ "zz", static_cast<int32_t>(0x80000000) }
};
for(int32_t length=2; length<=UPRV_LENGTHOF(data); ++length) {
logln("TestBranches length=%d", static_cast<int>(length));
checkData(data, length);
}
}
void UCharsTrieTest::TestLongSequence() {
static const StringAndValue data[]={
{ "a", -1 },
// sequence of linear-match nodes
{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -2 },
// more than 256 units
{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -3 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestLongBranch() {
// Split-branch and interesting compact-integer values.
static const StringAndValue data[]={
{ "a", -2 },
{ "b", -1 },
{ "c", 0 },
{ "d2", 1 },
{ "f", 0x3f },
{ "g", 0x40 },
{ "h", 0x41 },
{ "j23", 0x1900 },
{ "j24", 0x19ff },
{ "j25", 0x1a00 },
{ "k2", 0x1a80 },
{ "k3", 0x1aff },
{ "l234567890", 0x1b00 },
{ "l234567890123", 0x1b01 },
{ "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", 0x10ffff },
{ "oooooooooooooooooooooooooooooooooooooooooooooooooooooo", 0x110000 },
{ "pppppppppppppppppppppppppppppppppppppppppppppppppppppp", 0x120000 },
{ "r", 0x333333 },
{ "s2345", 0x4444444 },
{ "t234567890", 0x77777777 },
{ "z", static_cast<int32_t>(0x80000001) }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestValuesForState() {
// Check that saveState() and resetToState() interact properly
// with next() and current().
static const StringAndValue data[]={
{ "a", -1 },
{ "ab", -2 },
{ "abc", -3 },
{ "abcd", -4 },
{ "abcde", -5 },
{ "abcdef", -6 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestCompact() {
// Duplicate trailing strings and values provide opportunities for compacting.
static const StringAndValue data[]={
{ "+", 0 },
{ "+august", 8 },
{ "+december", 12 },
{ "+july", 7 },
{ "+june", 6 },
{ "+november", 11 },
{ "+october", 10 },
{ "+september", 9 },
{ "-", 0 },
{ "-august", 8 },
{ "-december", 12 },
{ "-july", 7 },
{ "-june", 6 },
{ "-november", 11 },
{ "-october", 10 },
{ "-september", 9 },
// The l+n branch (with its sub-nodes) is a duplicate but will be written
// both times because each time it follows a different linear-match node.
{ "xjuly", 7 },
{ "xjune", 6 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestFirstForCodePoint() {
static const StringAndValue data[]={
{ "a", 1 },
{ "a\\ud800", 2 },
{ "a\\U00010000", 3 },
{ "\\ud840", 4 },
{ "\\U00020000\\udbff", 5 },
{ "\\U00020000\\U0010ffff", 6 },
{ "\\U00020000\\U0010ffffz", 7 },
{ "\\U00050000xy", 8 },
{ "\\U00050000xyz", 9 }
};
checkData(data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestNextForCodePoint() {
static const StringAndValue data[]={
{ "\\u4dff\\U00010000\\u9999\\U00020000\\udfff\\U0010ffff", 2000000000 },
{ "\\u4dff\\U00010000\\u9999\\U00020002", 44444 },
{ "\\u4dff\\U000103ff", 99999 }
};
LocalPointer<UCharsTrie> trie(buildTrie(data, UPRV_LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
UStringTrieResult result;
if( (result=trie->nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x20000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0xdfff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x10ffff))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
trie->getValue()!=2000000000
) {
errln("UCharsTrie.nextForCodePoint() fails for %s", data[0].s);
}
if( (result=trie->firstForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x20002))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
trie->getValue()!=44444
) {
errln("UCharsTrie.nextForCodePoint() fails for %s", data[1].s);
}
if( (result=trie->reset().nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x20222))!=USTRINGTRIE_NO_MATCH || result!=trie->current() // no match for trail surrogate
) {
errln("UCharsTrie.nextForCodePoint() fails for \\u4dff\\U00010000\\u9999\\U00020222");
}
if( (result=trie->reset().nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
(result=trie->nextForCodePoint(0x103ff))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
trie->getValue()!=99999
) {
errln("UCharsTrie.nextForCodePoint() fails for %s", data[2].s);
}
}
// Definitions in the anonymous namespace are invisible outside this file.
namespace {
// Generate (string, value) pairs.
// The first string (before next()) will be empty.
class Generator {
public:
Generator() : value(4711), num(0) {}
void next() {
char16_t c;
s.truncate(0);
s.append(c = static_cast<char16_t>(value >> 16));
s.append(static_cast<char16_t>(value >> 4));
if(value&1) {
s.append(static_cast<char16_t>(value));
}
set.add(c);
value+=((value>>5)&0x7ff)*3+1;
++num;
}
const UnicodeString &getString() const { return s; }
int32_t getValue() const { return value; }
int32_t countUniqueFirstChars() const { return set.size(); }
int32_t getIndex() const { return num; }
private:
UnicodeString s;
UnicodeSet set;
int32_t value;
int32_t num;
};
} // end namespace
UCharsTrie *UCharsTrieTest::buildLargeTrie(int32_t numUniqueFirst) {
IcuTestErrorCode errorCode(*this, "buildLargeTrie()");
Generator gen;
builder_->clear();
while(gen.countUniqueFirstChars()<numUniqueFirst) {
builder_->add(gen.getString(), gen.getValue(), errorCode);
gen.next();
}
logln("buildLargeTrie(%ld) added %ld strings", static_cast<long>(numUniqueFirst), static_cast<long>(gen.getIndex()));
UnicodeString trieUChars;
builder_->buildUnicodeString(USTRINGTRIE_BUILD_FAST, trieUChars, errorCode);
logln("serialized trie size: %ld UChars\n", static_cast<long>(trieUChars.length()));
return new UCharsTrie(trieUChars.getBuffer());
}
// Exercise a large branch node.
void UCharsTrieTest::TestLargeTrie() {
LocalPointer<UCharsTrie> trie(buildLargeTrie(1111));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
Generator gen;
while(gen.countUniqueFirstChars()<1111) {
UnicodeString x(gen.getString());
int32_t value=gen.getValue();
if(!x.isEmpty()) {
if(trie->first(x[0])==USTRINGTRIE_NO_MATCH) {
errln("first(first char U+%04X)=USTRINGTRIE_NO_MATCH for string %ld\n",
x[0], static_cast<long>(gen.getIndex()));
break;
}
x.remove(0, 1);
}
UStringTrieResult result=trie->next(x.getBuffer(), x.length());
if(!USTRINGTRIE_HAS_VALUE(result) || result!=trie->current() || value!=trie->getValue()) {
errln("next(%d chars U+%04X U+%04X)!=hasValue or "
"next()!=current() or getValue() wrong "
"for string %ld\n", static_cast<int>(x.length()), x[0], x[1], static_cast<long>(gen.getIndex()));
break;
}
gen.next();
}
}
enum {
u_a=0x61,
u_b=0x62,
u_c=0x63,
u_j=0x6a,
u_n=0x6e,
u_r=0x72,
u_u=0x75,
u_y=0x79
};
UCharsTrie *UCharsTrieTest::buildMonthsTrie(UStringTrieBuildOption buildOption) {
// All types of nodes leading to the same value,
// for code coverage of recursive functions.
// In particular, we need a lot of branches on some single level
// to exercise a split-branch node.
static const StringAndValue data[]={
{ "august", 8 },
{ "jan", 1 },
{ "jan.", 1 },
{ "jana", 1 },
{ "janbb", 1 },
{ "janc", 1 },
{ "janddd", 1 },
{ "janee", 1 },
{ "janef", 1 },
{ "janf", 1 },
{ "jangg", 1 },
{ "janh", 1 },
{ "janiiii", 1 },
{ "janj", 1 },
{ "jankk", 1 },
{ "jankl", 1 },
{ "jankmm", 1 },
{ "janl", 1 },
{ "janm", 1 },
{ "jannnnnnnnnnnnnnnnnnnnnnnnnnnnn", 1 },
{ "jano", 1 },
{ "janpp", 1 },
{ "janqqq", 1 },
{ "janr", 1 },
{ "januar", 1 },
{ "january", 1 },
{ "july", 7 },
{ "jun", 6 },
{ "jun.", 6 },
{ "june", 6 }
};
return buildTrie(data, UPRV_LENGTHOF(data), buildOption);
}
void UCharsTrieTest::TestHasUniqueValue() {
LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
int32_t uniqueValue;
if(trie->hasUniqueValue(uniqueValue)) {
errln("unique value at root");
}
trie->next(u_j);
trie->next(u_a);
trie->next(u_n);
// hasUniqueValue() directly after next()
if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=1) {
errln("not unique value 1 after \"jan\"");
}
trie->first(u_j);
trie->next(u_u);
if(trie->hasUniqueValue(uniqueValue)) {
errln("unique value after \"ju\"");
}
if(trie->next(u_n)!=USTRINGTRIE_INTERMEDIATE_VALUE || 6!=trie->getValue()) {
errln("not normal value 6 after \"jun\"");
}
// hasUniqueValue() after getValue()
if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=6) {
errln("not unique value 6 after \"jun\"");
}
// hasUniqueValue() from within a linear-match node
trie->first(u_a);
trie->next(u_u);
if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=8) {
errln("not unique value 8 after \"au\"");
}
}
void UCharsTrieTest::TestGetNextUChars() {
LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_SMALL));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
UnicodeString buffer;
UnicodeStringAppendable app(buffer);
int32_t count=trie->getNextUChars(app);
if(count!=2 || buffer.length()!=2 || buffer[0]!=u_a || buffer[1]!=u_j) {
errln("months getNextUChars()!=[aj] at root");
}
trie->next(u_j);
trie->next(u_a);
trie->next(u_n);
// getNextUChars() directly after next()
buffer.remove();
count=trie->getNextUChars(app);
if(count!=20 || buffer!=UNICODE_STRING_SIMPLE(".abcdefghijklmnopqru")) {
errln("months getNextUChars()!=[.abcdefghijklmnopqru] after \"jan\"");
}
// getNextUChars() after getValue()
trie->getValue(); // next() had returned USTRINGTRIE_INTERMEDIATE_VALUE.
buffer.remove();
count=trie->getNextUChars(app);
if(count!=20 || buffer!=UNICODE_STRING_SIMPLE(".abcdefghijklmnopqru")) {
errln("months getNextUChars()!=[.abcdefghijklmnopqru] after \"jan\"+getValue()");
}
// getNextUChars() from a linear-match node
trie->next(u_u);
buffer.remove();
count=trie->getNextUChars(app);
if(count!=1 || buffer.length()!=1 || buffer[0]!=u_a) {
errln("months getNextUChars()!=[a] after \"janu\"");
}
trie->next(u_a);
buffer.remove();
count=trie->getNextUChars(app);
if(count!=1 || buffer.length()!=1 || buffer[0]!=u_r) {
errln("months getNextUChars()!=[r] after \"janua\"");
}
trie->next(u_r);
trie->next(u_y);
// getNextUChars() after a final match
buffer.remove();
count=trie->getNextUChars(app);
if(count!=0 || buffer.length()!=0) {
errln("months getNextUChars()!=[] after \"january\"");
}
}
void UCharsTrieTest::TestIteratorFromBranch() {
LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
// Go to a branch node.
trie->next(u_j);
trie->next(u_a);
trie->next(u_n);
IcuTestErrorCode errorCode(*this, "TestIteratorFromBranch()");
UCharsTrie::Iterator iter(*trie, 0, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
// following "jan".
static const StringAndValue data[]={
{ "", 1 },
{ ".", 1 },
{ "a", 1 },
{ "bb", 1 },
{ "c", 1 },
{ "ddd", 1 },
{ "ee", 1 },
{ "ef", 1 },
{ "f", 1 },
{ "gg", 1 },
{ "h", 1 },
{ "iiii", 1 },
{ "j", 1 },
{ "kk", 1 },
{ "kl", 1 },
{ "kmm", 1 },
{ "l", 1 },
{ "m", 1 },
{ "nnnnnnnnnnnnnnnnnnnnnnnnnnnn", 1 },
{ "o", 1 },
{ "pp", 1 },
{ "qqq", 1 },
{ "r", 1 },
{ "uar", 1 },
{ "uary", 1 }
};
checkIterator(iter, data, UPRV_LENGTHOF(data));
// Reset, and we should get the same result.
logln("after iter.reset()");
checkIterator(iter.reset(), data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestIteratorFromLinearMatch() {
LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_SMALL));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
// Go into a linear-match node.
trie->next(u_j);
trie->next(u_a);
trie->next(u_n);
trie->next(u_u);
trie->next(u_a);
IcuTestErrorCode errorCode(*this, "TestIteratorFromLinearMatch()");
UCharsTrie::Iterator iter(*trie, 0, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the suffixes
// following "janua".
static const StringAndValue data[]={
{ "r", 1 },
{ "ry", 1 }
};
checkIterator(iter, data, UPRV_LENGTHOF(data));
// Reset, and we should get the same result.
logln("after iter.reset()");
checkIterator(iter.reset(), data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestTruncatingIteratorFromRoot() {
LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromRoot()");
UCharsTrie::Iterator iter(*trie, 4, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
// Expected data: Same as in buildMonthsTrie(), except only the first 4 characters
// of each string, and no string duplicates from the truncation.
static const StringAndValue data[]={
{ "augu", -1 },
{ "jan", 1 },
{ "jan.", 1 },
{ "jana", 1 },
{ "janb", -1 },
{ "janc", 1 },
{ "jand", -1 },
{ "jane", -1 },
{ "janf", 1 },
{ "jang", -1 },
{ "janh", 1 },
{ "jani", -1 },
{ "janj", 1 },
{ "jank", -1 },
{ "janl", 1 },
{ "janm", 1 },
{ "jann", -1 },
{ "jano", 1 },
{ "janp", -1 },
{ "janq", -1 },
{ "janr", 1 },
{ "janu", -1 },
{ "july", 7 },
{ "jun", 6 },
{ "jun.", 6 },
{ "june", 6 }
};
checkIterator(iter, data, UPRV_LENGTHOF(data));
// Reset, and we should get the same result.
logln("after iter.reset()");
checkIterator(iter.reset(), data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::TestTruncatingIteratorFromLinearMatchShort() {
static const StringAndValue data[]={
{ "abcdef", 10 },
{ "abcdepq", 200 },
{ "abcdeyz", 3000 }
};
LocalPointer<UCharsTrie> trie(buildTrie(data, UPRV_LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
// Go into a linear-match node.
trie->next(u_a);
trie->next(u_b);
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchShort()");
// Truncate within the linear-match node.
UCharsTrie::Iterator iter(*trie, 2, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
{ "cd", -1 }
};
checkIterator(iter, expected, UPRV_LENGTHOF(expected));
// Reset, and we should get the same result.
logln("after iter.reset()");
checkIterator(iter.reset(), expected, UPRV_LENGTHOF(expected));
}
void UCharsTrieTest::TestTruncatingIteratorFromLinearMatchLong() {
static const StringAndValue data[]={
{ "abcdef", 10 },
{ "abcdepq", 200 },
{ "abcdeyz", 3000 }
};
LocalPointer<UCharsTrie> trie(buildTrie(data, UPRV_LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
// Go into a linear-match node.
trie->next(u_a);
trie->next(u_b);
trie->next(u_c);
IcuTestErrorCode errorCode(*this, "TestTruncatingIteratorFromLinearMatchLong()");
// Truncate after the linear-match node.
UCharsTrie::Iterator iter(*trie, 3, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
return;
}
static const StringAndValue expected[]={
{ "def", 10 },
{ "dep", -1 },
{ "dey", -1 }
};
checkIterator(iter, expected, UPRV_LENGTHOF(expected));
// Reset, and we should get the same result.
logln("after iter.reset()");
checkIterator(iter.reset(), expected, UPRV_LENGTHOF(expected));
}
void UCharsTrieTest::TestIteratorFromUChars() {
static const StringAndValue data[]={
{ "mm", 3 },
{ "mmm", 33 },
{ "mmnop", 333 }
};
builder_->clear();
IcuTestErrorCode errorCode(*this, "TestIteratorFromUChars()");
for(int32_t i=0; i<UPRV_LENGTHOF(data); ++i) {
builder_->add(data[i].s, data[i].value, errorCode);
}
UnicodeString trieUChars;
builder_->buildUnicodeString(USTRINGTRIE_BUILD_FAST, trieUChars, errorCode);
UCharsTrie::Iterator iter(trieUChars.getBuffer(), 0, errorCode);
checkIterator(iter, data, UPRV_LENGTHOF(data));
}
void UCharsTrieTest::checkData(const StringAndValue data[], int32_t dataLength) {
logln("checkData(dataLength=%d, fast)", static_cast<int>(dataLength));
checkData(data, dataLength, USTRINGTRIE_BUILD_FAST);
logln("checkData(dataLength=%d, small)", static_cast<int>(dataLength));
checkData(data, dataLength, USTRINGTRIE_BUILD_SMALL);
}
void UCharsTrieTest::checkData(const StringAndValue data[], int32_t dataLength, UStringTrieBuildOption buildOption) {
LocalPointer<UCharsTrie> trie(buildTrie(data, dataLength, buildOption));
if(trie.isNull()) {
return; // buildTrie() reported an error
}
checkFirst(*trie, data, dataLength);
checkNext(*trie, data, dataLength);
checkNextWithState(*trie, data, dataLength);
checkNextWithState64(*trie, data, dataLength);
checkNextString(*trie, data, dataLength);
checkIterator(*trie, data, dataLength);
}
UCharsTrie *UCharsTrieTest::buildTrie(const StringAndValue data[], int32_t dataLength,
UStringTrieBuildOption buildOption) {
IcuTestErrorCode errorCode(*this, "buildTrie()");
// Add the items to the trie builder in an interesting (not trivial, not random) order.
int32_t index, step;
if(dataLength&1) {
// Odd number of items.
index=dataLength/2;
step=2;
} else if((dataLength%3)!=0) {
// Not a multiple of 3.
index=dataLength/5;
step=3;
} else {
index=dataLength-1;
step=-1;
}
builder_->clear();
for(int32_t i=0; i<dataLength; ++i) {
builder_->add(UnicodeString(data[index].s, -1, US_INV).unescape(),
data[index].value, errorCode);
index=(index+step)%dataLength;
}
UnicodeString trieUChars;
builder_->buildUnicodeString(buildOption, trieUChars, errorCode);
LocalPointer<UCharsTrie> trie(builder_->build(buildOption, errorCode));
if(!errorCode.errIfFailureAndReset("add()/build()")) {
builder_->add("zzz", 999, errorCode);
if(errorCode.reset()!=U_NO_WRITE_PERMISSION) {
errln("builder.build().add(zzz) did not set U_NO_WRITE_PERMISSION");
}
}
logln("serialized trie size: %ld UChars\n", static_cast<long>(trieUChars.length()));
UnicodeString trieUChars2;
builder_->buildUnicodeString(buildOption, trieUChars2, errorCode);
if(trieUChars.getBuffer()==trieUChars2.getBuffer()) {
errln("builder.buildUnicodeString() before & after build() returned same array");
}
if(errorCode.isFailure()) {
return nullptr;
}
// Tries from either build() method should be identical but
// UCharsTrie does not implement equals().
// We just return either one.
if((dataLength&1)!=0) {
return trie.orphan();
} else {
return new UCharsTrie(trieUChars2.getBuffer());
}
}
void UCharsTrieTest::checkFirst(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
for(int32_t i=0; i<dataLength; ++i) {
if(*data[i].s==0) {
continue; // skip empty string
}
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
UChar32 c=expectedString[0];
UChar32 nextCp=expectedString.length()>1 ? expectedString[1] : 0;
UStringTrieResult firstResult=trie.first(c);
int32_t firstValue=USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1;
UStringTrieResult nextResult=trie.next(nextCp);
if(firstResult!=trie.reset().next(c) ||
firstResult!=trie.current() ||
firstValue!=(USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1) ||
nextResult!=trie.next(nextCp)
) {
errln("trie.first(U+%04X)!=trie.reset().next(same) for %s",
c, data[i].s);
}
c=expectedString.char32At(0);
int32_t cLength=U16_LENGTH(c);
nextCp=expectedString.length()>cLength ? expectedString.char32At(cLength) : 0;
firstResult=trie.firstForCodePoint(c);
firstValue=USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1;
nextResult=trie.nextForCodePoint(nextCp);
if(firstResult!=trie.reset().nextForCodePoint(c) ||
firstResult!=trie.current() ||
firstValue!=(USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1) ||
nextResult!=trie.nextForCodePoint(nextCp)
) {
errln("trie.firstForCodePoint(U+%04X)!=trie.reset().nextForCodePoint(same) for %s",
c, data[i].s);
}
}
trie.reset();
}
void UCharsTrieTest::checkNext(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
UCharsTrie::State state;
for(int32_t i=0; i<dataLength; ++i) {
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
int32_t stringLength= (i&1) ? -1 : expectedString.length();
UStringTrieResult result;
if( !USTRINGTRIE_HAS_VALUE(
result=trie.next(expectedString.getTerminatedBuffer(), stringLength)) ||
result!=trie.current()
) {
errln("trie does not seem to contain %s", data[i].s);
} else if(trie.getValue()!=data[i].value) {
errln("trie value for %s is %ld=0x%lx instead of expected %ld=0x%lx",
data[i].s,
static_cast<long>(trie.getValue()), static_cast<long>(trie.getValue()),
static_cast<long>(data[i].value), static_cast<long>(data[i].value));
} else if(result!=trie.current() || trie.getValue()!=data[i].value) {
errln("trie value for %s changes when repeating current()/getValue()", data[i].s);
}
trie.reset();
stringLength=expectedString.length();
result=trie.current();
for(int32_t j=0; j<stringLength; ++j) {
if(!USTRINGTRIE_HAS_NEXT(result)) {
errln("trie.current()!=hasNext before end of %s (at index %d)", data[i].s, j);
break;
}
if(result==USTRINGTRIE_INTERMEDIATE_VALUE) {
trie.getValue();
if(trie.current()!=USTRINGTRIE_INTERMEDIATE_VALUE) {
errln("trie.getValue().current()!=USTRINGTRIE_INTERMEDIATE_VALUE before end of %s (at index %d)", data[i].s, j);
break;
}
}
result=trie.next(expectedString[j]);
if(!USTRINGTRIE_MATCHES(result)) {
errln("trie.next()=USTRINGTRIE_NO_MATCH before end of %s (at index %d)", data[i].s, j);
break;
}
if(result!=trie.current()) {
errln("trie.next()!=following current() before end of %s (at index %d)", data[i].s, j);
break;
}
}
if(!USTRINGTRIE_HAS_VALUE(result)) {
errln("trie.next()!=hasValue at the end of %s", data[i].s);
continue;
}
trie.getValue();
if(result!=trie.current()) {
errln("trie.current() != current()+getValue()+current() after end of %s",
data[i].s);
}
// Compare the final current() with whether next() can actually continue.
trie.saveState(state);
UBool nextContinues=false;
for(int32_t c=0x20; c<0xe000; ++c) {
if(c==0x80) {
c=0xd800; // Check for ASCII and surrogates but not all of the BMP.
}
if(trie.resetToState(state).next(c)) {
nextContinues=true;
break;
}
}
if((result==USTRINGTRIE_INTERMEDIATE_VALUE)!=nextContinues) {
errln("(trie.current()==USTRINGTRIE_INTERMEDIATE_VALUE) contradicts "
"(trie.next(some char16_t)!=USTRINGTRIE_NO_MATCH) after end of %s", data[i].s);
}
trie.reset();
}
}
void UCharsTrieTest::checkNextWithState(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
UCharsTrie::State noState, state;
for(int32_t i=0; i<dataLength; ++i) {
if((i&1)==0) {
// This should have no effect.
trie.resetToState(noState);
}
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
int32_t stringLength=expectedString.length();
int32_t partialLength=stringLength/3;
for(int32_t j=0; j<partialLength; ++j) {
if(!USTRINGTRIE_MATCHES(trie.next(expectedString[j]))) {
errln("trie.next()=USTRINGTRIE_NO_MATCH for a prefix of %s", data[i].s);
return;
}
}
trie.saveState(state);
UStringTrieResult resultAtState=trie.current();
UStringTrieResult result;
int32_t valueAtState=-99;
if(USTRINGTRIE_HAS_VALUE(resultAtState)) {
valueAtState=trie.getValue();
}
result=trie.next(0); // mismatch
if(result!=USTRINGTRIE_NO_MATCH || result!=trie.current()) {
errln("trie.next(0) matched after part of %s", data[i].s);
}
if( resultAtState!=trie.resetToState(state).current() ||
(USTRINGTRIE_HAS_VALUE(resultAtState) && valueAtState!=trie.getValue())
) {
errln("trie.next(part of %s) changes current()/getValue() after "
"saveState/next(0)/resetToState",
data[i].s);
} else if(!USTRINGTRIE_HAS_VALUE(
result=trie.next(expectedString.getTerminatedBuffer()+partialLength,
stringLength-partialLength)) ||
result!=trie.current()) {
errln("trie.next(rest of %s) does not seem to contain %s after "
"saveState/next(0)/resetToState",
data[i].s, data[i].s);
} else if(!USTRINGTRIE_HAS_VALUE(
result=trie.resetToState(state).
next(expectedString.getTerminatedBuffer()+partialLength,
stringLength-partialLength)) ||
result!=trie.current()) {
errln("trie does not seem to contain %s after saveState/next(rest)/resetToState",
data[i].s);
} else if(trie.getValue()!=data[i].value) {
errln("trie value for %s is %ld=0x%lx instead of expected %ld=0x%lx",
data[i].s,
static_cast<long>(trie.getValue()), static_cast<long>(trie.getValue()),
static_cast<long>(data[i].value), static_cast<long>(data[i].value));
}
trie.reset();
}
}
void UCharsTrieTest::checkNextWithState64(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
assertTrue("trie(initial state).getState64()!=0", trie.getState64() != 0);
for(int32_t i=0; i<dataLength; ++i) {
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
int32_t stringLength=expectedString.length();
int32_t partialLength = stringLength / 3;
for(int32_t j=0; j<partialLength; ++j) {
if(!USTRINGTRIE_MATCHES(trie.next(expectedString[j]))) {
errln("trie.next()=USTRINGTRIE_NO_MATCH for a prefix of %s", data[i].s);
return;
}
}
uint64_t state = trie.getState64();
assertTrue("trie.getState64()!=0", state != 0);
UStringTrieResult resultAtState=trie.current();
UStringTrieResult result;
int32_t valueAtState=-99;
if(USTRINGTRIE_HAS_VALUE(resultAtState)) {
valueAtState=trie.getValue();
}
result=trie.next(0); // mismatch
if(result!=USTRINGTRIE_NO_MATCH || result!=trie.current()) {
errln("trie.next(0) matched after part of %s", data[i].s);
}
if( resultAtState!=trie.resetToState64(state).current() ||
(USTRINGTRIE_HAS_VALUE(resultAtState) && valueAtState!=trie.getValue())
) {
errln("trie.next(part of %s) changes current()/getValue() after "
"getState64/next(0)/resetToState64",
data[i].s);
} else if(!USTRINGTRIE_HAS_VALUE(
result=trie.next(expectedString.getTerminatedBuffer()+partialLength,
stringLength-partialLength)) ||
result!=trie.current()) {
errln("trie.next(rest of %s) does not seem to contain %s after "
"getState64/next(0)/resetToState64",
data[i].s, data[i].s);
} else if(!USTRINGTRIE_HAS_VALUE(
result=trie.resetToState64(state).
next(expectedString.getTerminatedBuffer()+partialLength,
stringLength-partialLength)) ||
result!=trie.current()) {
errln("trie does not seem to contain %s after getState64/next(rest)/resetToState64",
data[i].s);
} else if(trie.getValue()!=data[i].value) {
errln("trie value for %s is %ld=0x%lx instead of expected %ld=0x%lx",
data[i].s,
static_cast<long>(trie.getValue()), static_cast<long>(trie.getValue()),
static_cast<long>(data[i].value), static_cast<long>(data[i].value));
}
trie.reset();
}
}
// next(string) is also tested in other functions,
// but here we try to go partway through the string, and then beyond it.
void UCharsTrieTest::checkNextString(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
for(int32_t i=0; i<dataLength; ++i) {
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
int32_t stringLength=expectedString.length();
if(!trie.next(expectedString.getTerminatedBuffer(), stringLength/2)) {
errln("trie.next(up to middle of string)=USTRINGTRIE_NO_MATCH for %s", data[i].s);
continue;
}
// Test that we stop properly at the end of the string.
if(trie.next(expectedString.getTerminatedBuffer()+stringLength/2,
stringLength+1-stringLength/2)) {
errln("trie.next(string+NUL)!=USTRINGTRIE_NO_MATCH for %s", data[i].s);
}
trie.reset();
}
}
void UCharsTrieTest::checkIterator(UCharsTrie &trie,
const StringAndValue data[], int32_t dataLength) {
IcuTestErrorCode errorCode(*this, "checkIterator()");
UCharsTrie::Iterator iter(trie, 0, errorCode);
if(errorCode.errIfFailureAndReset("UCharsTrie::Iterator(trieUChars) constructor")) {
return;
}
checkIterator(iter, data, dataLength);
}
void UCharsTrieTest::checkIterator(UCharsTrie::Iterator &iter,
const StringAndValue data[], int32_t dataLength) {
IcuTestErrorCode errorCode(*this, "checkIterator()");
for(int32_t i=0; i<dataLength; ++i) {
if(!iter.hasNext()) {
errln("trie iterator hasNext()=false for item %d: %s", static_cast<int>(i), data[i].s);
break;
}
UBool hasNext=iter.next(errorCode);
if (errorCode.errIfFailureAndReset("trie iterator next() for item %d: %s", static_cast<int>(i), data[i].s)) {
break;
}
if(!hasNext) {
errln("trie iterator next()=false for item %d: %s", static_cast<int>(i), data[i].s);
break;
}
UnicodeString expectedString=UnicodeString(data[i].s, -1, US_INV).unescape();
if(iter.getString()!=expectedString) {
char buffer[1000];
UnicodeString invString(prettify(iter.getString()));
invString.extract(0, invString.length(), buffer, UPRV_LENGTHOF(buffer), US_INV);
errln("trie iterator next().getString()=%s but expected %s for item %d",
buffer, data[i].s, static_cast<int>(i));
}
if(iter.getValue()!=data[i].value) {
errln("trie iterator next().getValue()=%ld=0x%lx but expected %ld=0x%lx for item %d: %s",
static_cast<long>(iter.getValue()), static_cast<long>(iter.getValue()),
static_cast<long>(data[i].value), static_cast<long>(data[i].value),
static_cast<int>(i), data[i].s);
}
}
if(iter.hasNext()) {
errln("trie iterator hasNext()=true after all items");
}
UBool hasNext=iter.next(errorCode);
errorCode.errIfFailureAndReset("trie iterator next() after all items");
if(hasNext) {
errln("trie iterator next()=true after all items");
}
}
|