ICU-4465 Change TestExhaustive to try the character with and without u+0345.

X-SVN-Rev: 17442
This commit is contained in:
Eric Mader 2005-04-01 01:14:25 +00:00
parent 1dbed06f82
commit 976433d4a4
3 changed files with 114 additions and 91 deletions

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2004, International Business Machines Corporation and
* Copyright (c) 2002-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*
@ -72,7 +72,7 @@ void CanonicalIteratorTest::TestExhaustive() {
UErrorCode status = U_ZERO_ERROR;
CanonicalIterator it("", status);
UChar32 i = 0;
UnicodeString s, decomp, comp;
UnicodeString s;
// Test static and dynamic class IDs
if(it.getDynamicClassID() != CanonicalIterator::getStaticClassID()){
errln("CanonicalIterator::getStaticClassId ! = CanonicalIterator.getDynamicClassID");
@ -90,33 +90,10 @@ void CanonicalIteratorTest::TestExhaustive() {
|| type == U_SURROGATE) continue;
s = i;
characterTest(s, i, it);
s += (UChar32)0x0345; //"\\u0345";
Normalizer::decompose(s, FALSE, 0, decomp, status);
Normalizer::compose(s, FALSE, 0, comp, status);
// skip characters that don't have either decomp.
// need quick test for this!
if (s == decomp && s == comp) {
continue;
}
it.setSource(s, status);
UBool gotDecomp = FALSE;
UBool gotComp = FALSE;
UBool gotSource = FALSE;
while (TRUE) {
UnicodeString item = it.next();
if (item.isBogus()) break;
if (item == s) gotSource = TRUE;
if (item == decomp) gotDecomp = TRUE;
if (item == comp) gotComp = TRUE;
}
if (!gotSource || !gotDecomp || !gotComp) {
errln("FAIL CanonicalIterator: " + s + (int)i);
}
characterTest(s, i, it);
}
}
@ -191,6 +168,38 @@ void CanonicalIteratorTest::TestBasic() {
delete set;
}
void CanonicalIteratorTest::characterTest(UnicodeString &s, UChar32 ch, CanonicalIterator &it)
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString decomp, comp;
UBool gotDecomp = FALSE;
UBool gotComp = FALSE;
UBool gotSource = FALSE;
Normalizer::decompose(s, FALSE, 0, decomp, status);
Normalizer::compose(s, FALSE, 0, comp, status);
// skip characters that don't have either decomp.
// need quick test for this!
if (s == decomp && s == comp) {
return;
}
it.setSource(s, status);
while (TRUE) {
UnicodeString item = it.next();
if (item.isBogus()) break;
if (item == s) gotSource = TRUE;
if (item == decomp) gotDecomp = TRUE;
if (item == comp) gotComp = TRUE;
}
if (!gotSource || !gotDecomp || !gotComp) {
errln("FAIL CanonicalIterator: " + s + (int)ch);
}
}
void CanonicalIteratorTest::expectEqual(const UnicodeString &message, const UnicodeString &item, const UnicodeString &a, const UnicodeString &b) {
if (!(a==b)) {
errln("FAIL: " + message + getReadable(item));

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2003, International Business Machines Corporation and
* Copyright (c) 2002-2005, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*
@ -27,6 +27,7 @@ class Transliterator;
U_NAMESPACE_END
#include "unicode/translit.h"
#include "unicode/caniter.h"
#include "intltest.h"
#include "hash.h"
@ -45,6 +46,7 @@ public:
//static UnicodeString collectionToString(Collection col);
private:
void expectEqual(const UnicodeString &message, const UnicodeString &item, const UnicodeString &a, const UnicodeString &b);
void characterTest(UnicodeString &s, UChar32 ch, CanonicalIterator &it);
Transliterator *nameTrans;
Transliterator *hexTrans;

View file

@ -62,69 +62,10 @@ public class TestCanonicalIterator extends TestFmwk {
if ((++counter % 5000) == 0) logln("Testing " + Utility.hex(i,0));
String s = UTF16.valueOf(i) + "\u0345";
String decomp = Normalizer.decompose(s, false);
String comp = Normalizer.compose(s, false);
// skip characters that don't have either decomp.
// need quick test for this!
if (s.equals(decomp) && s.equals(comp)) continue;
String s = UTF16.valueOf(i);
it.setSource(s);
boolean gotDecomp = false;
boolean gotComp = false;
boolean gotSource = false;
while (true) {
String item = it.next();
if (item == null) break;
if (item.equals(s)) gotSource = true;
if (item.equals(decomp)) gotDecomp = true;
if (item.equals(comp)) gotComp = true;
if ((mixedCounter & 0x7F) == 0 && (i < 0xAD00 || i > 0xAC00 + 11172)) {
if (lastMixedCounter != mixedCounter) {
logln("");
lastMixedCounter = mixedCounter;
}
logln("\t" + mixedCounter + "\t" + hex(item)
+ (item.equals(s) ? "\t(*original*)" : "")
+ (item.equals(decomp) ? "\t(*decomp*)" : "")
+ (item.equals(comp) ? "\t(*comp*)" : "")
);
}
}
// check that zeros optimization doesn't mess up.
/*
if (true) {
it.reset();
itSet.clear();
while (true) {
String item = it.next();
if (item == null) break;
itSet.add(item);
}
slowIt.setSource(s);
slowItSet.clear();
while (true) {
String item = slowIt.next();
if (item == null) break;
slowItSet.add(item);
}
if (!itSet.equals(slowItSet)) {
errln("Zero optimization failure with " + getReadable(s));
}
}
*/
mixedCounter++;
if (!gotSource || !gotDecomp || !gotComp) {
errln("FAIL CanonicalIterator: " + s + " decomp: " +decomp+" comp: "+comp);
it.reset();
for(String item=it.next();item!=null;item=it.next()){
err(item + " ");
}
errln("");
}
characterTest(s, i, it);
characterTest(s + "\u0345", i, it);
}
}
@ -249,6 +190,77 @@ public class TestCanonicalIterator extends TestFmwk {
return "[" + (SHOW_NAMES ? hex(s) + "; " : "") + hex(s) + "]";
}
public void characterTest(String s, int ch, CanonicalIterator it)
{
int counter = 0;
int mixedCounter = 0;
int lastMixedCounter = -1;
boolean gotDecomp = false;
boolean gotComp = false;
boolean gotSource = false;
String decomp = Normalizer.decompose(s, false);
String comp = Normalizer.compose(s, false);
// skip characters that don't have either decomp.
// need quick test for this!
if (s.equals(decomp) && s.equals(comp)) return;
it.setSource(s);
while (true) {
String item = it.next();
if (item == null) break;
if (item.equals(s)) gotSource = true;
if (item.equals(decomp)) gotDecomp = true;
if (item.equals(comp)) gotComp = true;
if ((mixedCounter & 0x7F) == 0 && (ch < 0xAD00 || ch > 0xAC00 + 11172)) {
if (lastMixedCounter != mixedCounter) {
logln("");
lastMixedCounter = mixedCounter;
}
logln("\t" + mixedCounter + "\t" + hex(item)
+ (item.equals(s) ? "\t(*original*)" : "")
+ (item.equals(decomp) ? "\t(*decomp*)" : "")
+ (item.equals(comp) ? "\t(*comp*)" : "")
);
}
}
// check that zeros optimization doesn't mess up.
/*
if (true) {
it.reset();
itSet.clear();
while (true) {
String item = it.next();
if (item == null) break;
itSet.add(item);
}
slowIt.setSource(s);
slowItSet.clear();
while (true) {
String item = slowIt.next();
if (item == null) break;
slowItSet.add(item);
}
if (!itSet.equals(slowItSet)) {
errln("Zero optimization failure with " + getReadable(s));
}
}
*/
mixedCounter++;
if (!gotSource || !gotDecomp || !gotComp) {
errln("FAIL CanonicalIterator: " + s + " decomp: " +decomp+" comp: "+comp);
it.reset();
for(String item=it.next();item!=null;item=it.next()){
err(item + " ");
}
errln("");
}
}
static String collectionToString(Collection col) {
StringBuffer result = new StringBuffer();
Iterator it = col.iterator();