mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-2118
code coverage test X-SVN-Rev: 10711
This commit is contained in:
parent
2b8390a7f8
commit
f2d18275b4
2 changed files with 59 additions and 8 deletions
|
@ -127,6 +127,7 @@ void SearchIterator::setText(const UnicodeString &text, UErrorCode &status)
|
|||
else {
|
||||
m_text_ = text;
|
||||
m_search_->text = m_text_.getBuffer();
|
||||
m_search_->textLength = m_text_.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,10 +206,10 @@ int32_t SearchIterator::preceding(int32_t position,
|
|||
int32_t SearchIterator::next(UErrorCode &status)
|
||||
{
|
||||
if (U_SUCCESS(status)) {
|
||||
int32_t offset = getOffset();
|
||||
int32_t offset = getOffset();
|
||||
int32_t matchindex = m_search_->matchedIndex;
|
||||
int32_t matchlength = m_search_->matchedLength;
|
||||
m_search_->reset = FALSE;
|
||||
m_search_->reset = FALSE;
|
||||
if (m_search_->isForwardSearching == TRUE) {
|
||||
int32_t textlength = m_search_->textLength;
|
||||
if (offset == textlength || matchindex == textlength ||
|
||||
|
@ -291,7 +292,9 @@ int32_t SearchIterator::previous(UErrorCode &status)
|
|||
|
||||
void SearchIterator::reset()
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
setMatchNotFound();
|
||||
setOffset(0, status);
|
||||
m_search_->isOverlap = FALSE;
|
||||
m_search_->isCanonicalMatch = FALSE;
|
||||
m_search_->isForwardSearching = TRUE;
|
||||
|
@ -300,7 +303,7 @@ void SearchIterator::reset()
|
|||
|
||||
// protected constructors and destructors -----------------------------
|
||||
|
||||
SearchIterator::SearchIterator() : m_breakiterator_(NULL)
|
||||
SearchIterator::SearchIterator()
|
||||
{
|
||||
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
|
||||
m_search_->breakIter = NULL;
|
||||
|
@ -316,8 +319,8 @@ SearchIterator::SearchIterator() : m_breakiterator_(NULL)
|
|||
|
||||
SearchIterator::SearchIterator(const UnicodeString &text,
|
||||
BreakIterator *breakiter) :
|
||||
m_breakiterator_(breakiter),
|
||||
m_text_(text)
|
||||
m_breakiterator_(breakiter),
|
||||
m_text_(text)
|
||||
{
|
||||
m_search_ = (USearch *)uprv_malloc(sizeof(USearch));
|
||||
m_search_->breakIter = NULL;
|
||||
|
|
|
@ -2064,14 +2064,17 @@ void StringSearchTest::TestUClassID()
|
|||
class TestSearch : public SearchIterator
|
||||
{
|
||||
public:
|
||||
TestSearch(const TestSearch &obj);
|
||||
TestSearch(const UnicodeString &text,
|
||||
BreakIterator *breakiter,
|
||||
const UnicodeString &pattern);
|
||||
~TestSearch();
|
||||
|
||||
void setOffset(int32_t position, UErrorCode &status);
|
||||
int32_t getOffset() const;
|
||||
SearchIterator* safeClone() const;
|
||||
|
||||
|
||||
/**
|
||||
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
||||
*
|
||||
|
@ -2086,11 +2089,14 @@ public:
|
|||
*/
|
||||
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
||||
|
||||
UBool operator!=(const TestSearch &that) const;
|
||||
|
||||
UnicodeString m_pattern_;
|
||||
|
||||
protected:
|
||||
int32_t handleNext(int32_t position, UErrorCode &status);
|
||||
int32_t handlePrev(int32_t position, UErrorCode &status);
|
||||
int32_t handleNext(int32_t position, UErrorCode &status);
|
||||
int32_t handlePrev(int32_t position, UErrorCode &status);
|
||||
TestSearch & operator=(const TestSearch &that);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -2104,10 +2110,19 @@ private:
|
|||
|
||||
const char TestSearch::fgClassID=0;
|
||||
|
||||
TestSearch::TestSearch(const TestSearch &obj) : SearchIterator(obj)
|
||||
{
|
||||
m_offset_ = obj.m_offset_;
|
||||
m_pattern_ = obj.m_pattern_;
|
||||
}
|
||||
|
||||
TestSearch::TestSearch(const UnicodeString &text,
|
||||
BreakIterator *breakiter,
|
||||
const UnicodeString &pattern) : SearchIterator(text, breakiter)
|
||||
const UnicodeString &pattern) : SearchIterator()
|
||||
{
|
||||
m_breakiterator_ = breakiter;
|
||||
m_pattern_ = pattern;
|
||||
m_text_ = text;
|
||||
m_offset_ = 0;
|
||||
m_pattern_ = pattern;
|
||||
}
|
||||
|
@ -2116,6 +2131,7 @@ TestSearch::~TestSearch()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
void TestSearch::setOffset(int32_t position, UErrorCode &status)
|
||||
{
|
||||
if (position >= 0 && position <= m_text_.length()) {
|
||||
|
@ -2136,6 +2152,14 @@ SearchIterator * TestSearch::safeClone() const
|
|||
return new TestSearch(m_text_, m_breakiterator_, m_pattern_);
|
||||
}
|
||||
|
||||
UBool TestSearch::operator!=(const TestSearch &that) const
|
||||
{
|
||||
if (SearchIterator::operator !=(that)) {
|
||||
return false;
|
||||
}
|
||||
return m_offset_ != that.m_offset_ || m_pattern_ != that.m_pattern_;
|
||||
}
|
||||
|
||||
int32_t TestSearch::handleNext(int32_t start, UErrorCode &status)
|
||||
{
|
||||
int match = m_text_.indexOf(m_pattern_, start);
|
||||
|
@ -2166,14 +2190,38 @@ int32_t TestSearch::handlePrev(int32_t start, UErrorCode &status)
|
|||
return match;
|
||||
}
|
||||
|
||||
TestSearch & TestSearch::operator=(const TestSearch &that)
|
||||
{
|
||||
this->operator =(that);
|
||||
m_offset_ = that.m_offset_;
|
||||
m_pattern_ = that.m_pattern_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void StringSearchTest::TestSubclass()
|
||||
{
|
||||
UnicodeString text("abc abcd abc");
|
||||
UnicodeString pattern("abc");
|
||||
TestSearch search(text, NULL, pattern);
|
||||
TestSearch search2(search);
|
||||
int expected[] = {0, 4, 9};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int i;
|
||||
StringCharacterIterator chariter(text);
|
||||
|
||||
search.setText(text, status);
|
||||
if (search.getText() != search2.getText()) {
|
||||
errln("Error setting text");
|
||||
}
|
||||
|
||||
search.setText(chariter, status);
|
||||
if (search.getText() != search2.getText()) {
|
||||
errln("Error setting text");
|
||||
}
|
||||
|
||||
search.reset();
|
||||
// comparing constructors
|
||||
|
||||
for (i = 0; i < sizeof(expected) / sizeof(int); i ++) {
|
||||
if (search.next(status) != expected[i]) {
|
||||
errln("Error getting next match");
|
||||
|
|
Loading…
Add table
Reference in a new issue