public void TestNormalizerAPI() throws Exception {
try{
// instantiate a Normalizer from a CharacterIterator
String s=Utility.unescape("a\u0308\uac00\\U0002f800");
// make s a bit longer and more interesting
UCharacterIterator iter = UCharacterIterator.getInstance(s+s);
Normalizer norm = new Normalizer(iter, Normalizer.NFC,0);
if(norm.next()!=0xe4) {
errln("error in Normalizer(CharacterIterator).next()");
}
// test clone(), ==, and hashCode()
Normalizer clone=(Normalizer)norm.clone();
if(clone.equals(norm)) {
errln("error in Normalizer(Normalizer(CharacterIterator)).clone()!=norm");
}
if(clone.getLength()!= norm.getLength()){
errln("error in Normalizer.getBeginIndex()");
}
// clone must have the same hashCode()
//if(clone.hashCode()!=norm.hashCode()) {
// errln("error in Normalizer(Normalizer(CharacterIterator)).clone().hashCode()!=copy.hashCode()");
//}
if(clone.next()!=0xac00) {
errln("error in Normalizer(Normalizer(CharacterIterator)).next()");
}
int ch = clone.next();
if(ch!=0x4e3d) {
errln("error in Normalizer(Normalizer(CharacterIterator)).clone().next()");
}
// position changed, must change hashCode()
if(clone.hashCode()==norm.hashCode()) {
errln("error in Normalizer(Normalizer(CharacterIterator)).clone().next().hashCode()==copy.hashCode()");
}
// test compose() and decompose()
StringBuffer tel;
String nfkc, nfkd;
tel=new StringBuffer("\u2121\u2121\u2121\u2121\u2121\u2121\u2121\u2121\u2121\u2121");
tel.insert(1,(char)0x0301);
nfkc=Normalizer.compose(tel.toString(), true);
nfkd=Normalizer.decompose(tel.toString(), true);
if(
!nfkc.equals(Utility.unescape("TE\u0139TELTELTELTELTELTELTELTELTEL"))||
!nfkd.equals(Utility.unescape("TEL\u0301TELTELTELTELTELTELTELTELTEL"))
) {
errln("error in Normalizer::(de)compose(): wrong result(s)");
}
// test setIndex()
// ch=norm.setIndex(3);
// if(ch!=0x4e3d) {
// errln("error in Normalizer(CharacterIterator).setIndex(3)");
// }
// test setText(CharacterIterator) and getText()
String out, out2;
clone.setText(iter);
out = clone.getText();
out2 = iter.getText();
if( !out.equals(out2) ||
clone.startIndex()!=0||
clone.endIndex()!=iter.getLength()
) {
errln("error in Normalizer::setText() or Normalizer::getText()");
}
char[] fillIn1 = new char[clone.getLength()];
char[] fillIn2 = new char[iter.getLength()];
int len = clone.getText(fillIn1);
iter.getText(fillIn2,0);
if(!Utility.arrayRegionMatches(fillIn1,0,fillIn2,0,len)){
errln("error in Normalizer.getText(). Normalizer: "+
Utility.hex(new String(fillIn1))+
" Iter: " + Utility.hex(new String(fillIn2)));
}