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);
checkFirst(*trie, data, dataLength);
checkNext(*trie, data, dataLength);
checkNextWithState(*trie, data, dataLength);
+ checkNextWithState64(*trie, data, dataLength);
checkNextString(*trie, data, dataLength);
checkIterator(*trie, data, dataLength);
}
}
}
+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,
+ (long)trie.getValue(), (long)trie.getValue(),
+ (long)data[i].value, (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,