mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-1007 add tests for better Normalizer test code coverage
X-SVN-Rev: 6715
This commit is contained in:
parent
b15e9a73bb
commit
1699f48fed
2 changed files with 106 additions and 1 deletions
|
@ -5,8 +5,9 @@
|
|||
********************************************************************/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "cstring.h"
|
||||
#include "unicode/normlzr.h"
|
||||
#include "unicode/schriter.h"
|
||||
#include "cstring.h"
|
||||
#include "tstnorm.h"
|
||||
|
||||
#define ARRAY_LENGTH(array) ((int32_t)(sizeof (array) / sizeof (*array)))
|
||||
|
@ -37,6 +38,7 @@ void BasicNormalizerTest::runIndexedTest(int32_t index, UBool exec,
|
|||
CASE(9,TestZeroIndex);
|
||||
CASE(10,TestVerisign);
|
||||
CASE(11,TestPreviousNext);
|
||||
CASE(12,TestNormalizerAPI);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -677,3 +679,105 @@ BasicNormalizerTest::TestPreviousNext() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test APIs that are not otherwise used - improve test coverage
|
||||
void
|
||||
BasicNormalizerTest::TestNormalizerAPI() {
|
||||
// instantiate a Normalizer from a CharacterIterator
|
||||
UnicodeString s=UnicodeString("a\\u0308\\uac00\\U0002f800", "").unescape();
|
||||
s.append(s); // make s a bit longer and more interesting
|
||||
StringCharacterIterator iter(s);
|
||||
Normalizer norm(iter, UNORM_NFC);
|
||||
if(norm.next()!=0xe4) {
|
||||
errln("error in Normalizer(CharacterIterator).next()");
|
||||
}
|
||||
|
||||
// test copy constructor
|
||||
Normalizer copy(norm);
|
||||
if(copy.next()!=0xac00) {
|
||||
errln("error in Normalizer(Normalizer(CharacterIterator)).next()");
|
||||
}
|
||||
|
||||
// test clone(), ==, and hashCode()
|
||||
Normalizer *clone=copy.clone();
|
||||
if(*clone!=copy) {
|
||||
errln("error in Normalizer(Normalizer(CharacterIterator)).clone()!=copy");
|
||||
}
|
||||
// clone must have the same hashCode()
|
||||
if(clone->hashCode()!=copy.hashCode()) {
|
||||
errln("error in Normalizer(Normalizer(CharacterIterator)).clone()->hashCode()!=copy.hashCode()");
|
||||
}
|
||||
if(clone->next()!=0x4e3d) {
|
||||
errln("error in Normalizer(Normalizer(CharacterIterator)).clone()->next()");
|
||||
}
|
||||
// position changed, must change hashCode()
|
||||
if(clone->hashCode()==copy.hashCode()) {
|
||||
errln("error in Normalizer(Normalizer(CharacterIterator)).clone()->next().hashCode()==copy.hashCode()");
|
||||
}
|
||||
delete clone;
|
||||
clone=0;
|
||||
|
||||
// test compose() and decompose()
|
||||
UnicodeString tel, nfkc, nfkd;
|
||||
tel=UnicodeString(1, (UChar32)0x2121, 10);
|
||||
tel.insert(1, (UChar)0x301);
|
||||
|
||||
UErrorCode errorCode=U_ZERO_ERROR;
|
||||
Normalizer::compose(tel, TRUE, 0, nfkc, errorCode);
|
||||
Normalizer::decompose(tel, TRUE, 0, nfkd, errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
errln("error in Normalizer::(de)compose(): %s", u_errorName(errorCode));
|
||||
} else if(
|
||||
nfkc!=UnicodeString("TE\\u0139TELTELTELTELTELTELTELTELTEL", "").unescape() ||
|
||||
nfkd!=UnicodeString("TEL\\u0301TELTELTELTELTELTELTELTELTEL", "").unescape()
|
||||
) {
|
||||
errln("error in Normalizer::(de)compose(): wrong result(s)");
|
||||
}
|
||||
|
||||
// test setIndex()
|
||||
if(norm.setIndex(3)!=0x4e3d) {
|
||||
errln("error in Normalizer(CharacterIterator).setIndex(3)");
|
||||
}
|
||||
|
||||
// test setText(CharacterIterator) and getText()
|
||||
UnicodeString out, out2;
|
||||
errorCode=U_ZERO_ERROR;
|
||||
copy.setText(iter, errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
errln("error Normalizer::setText() failed: %s", u_errorName(errorCode));
|
||||
} else {
|
||||
copy.getText(out);
|
||||
iter.getText(out2);
|
||||
if( out!=out2 ||
|
||||
copy.startIndex()!=iter.startIndex() ||
|
||||
copy.endIndex()!=iter.endIndex()
|
||||
) {
|
||||
errln("error in Normalizer::setText() or Normalizer::getText()");
|
||||
}
|
||||
}
|
||||
|
||||
// test setText(UChar *), getUMode() and setMode()
|
||||
errorCode=U_ZERO_ERROR;
|
||||
copy.setText(s.getBuffer()+1, s.length()-1, errorCode);
|
||||
copy.setMode(UNORM_NFD);
|
||||
if(copy.getUMode()!=UNORM_NFD) {
|
||||
errln("error in Normalizer::setMode() or Normalizer::getUMode()");
|
||||
}
|
||||
if(copy.next()!=0x308 || copy.next()!=0x1100) {
|
||||
errln("error in Normalizer::setText(UChar *) or Normalizer::setMode()");
|
||||
}
|
||||
|
||||
// test setOption() and getOption()
|
||||
copy.setOption(0xaa0000, TRUE);
|
||||
copy.setOption(0x20000, FALSE);
|
||||
if(!copy.getOption(0x880000) || copy.getOption(0x20000)) {
|
||||
errln("error in Normalizer::setOption() or Normalizer::getOption()");
|
||||
}
|
||||
|
||||
// test last()/previous() with an internal buffer overflow
|
||||
errorCode=U_ZERO_ERROR;
|
||||
copy.setText(UnicodeString(1000, (UChar32)0x308, 1000), errorCode);
|
||||
if(copy.last()!=0x308) {
|
||||
errln("error in Normalizer(1000*U+0308).last()");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
void TestZeroIndex(void);
|
||||
void TestVerisign(void);
|
||||
void TestPreviousNext(void);
|
||||
void TestNormalizerAPI(void);
|
||||
|
||||
private:
|
||||
UnicodeString canonTests[24][3];
|
||||
|
|
Loading…
Add table
Reference in a new issue