ICU-1930 moved backAndForth test so that it is done for all collation tests
X-SVN-Rev: 9006
This commit is contained in:
parent
57805e5cd2
commit
d6b9ee3000
@ -473,118 +473,6 @@ void CollationIteratorTest::TestStrengthOrder()
|
||||
delete coll;
|
||||
}
|
||||
|
||||
void CollationIteratorTest::backAndForth(CollationElementIterator &iter)
|
||||
{
|
||||
// Run through the iterator forwards and stick it into an array
|
||||
int32_t orderLength = 0;
|
||||
int32_t *orders = getOrders(iter, orderLength);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// Now go through it backwards and make sure we get the same values
|
||||
int32_t index = orderLength;
|
||||
int32_t o;
|
||||
|
||||
// reset the iterator
|
||||
iter.reset();
|
||||
|
||||
while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
if (o != orders[--index])
|
||||
{
|
||||
if (o == 0)
|
||||
index ++;
|
||||
else
|
||||
{
|
||||
while (index > 0 && orders[--index] == 0)
|
||||
{
|
||||
}
|
||||
if (o != orders[index])
|
||||
{
|
||||
errln("Mismatch at index %d: 0x%X vs 0x%X", index,
|
||||
orders[index], o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (index != 0 && orders[index - 1] == 0)
|
||||
{
|
||||
index --;
|
||||
}
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
UnicodeString msg("Didn't get back to beginning - index is ");
|
||||
errln(msg + index);
|
||||
|
||||
iter.reset();
|
||||
err("next: ");
|
||||
while ((o = iter.next(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
UnicodeString hexString("0x");
|
||||
|
||||
appendHex(o, 8, hexString);
|
||||
hexString += " ";
|
||||
err(hexString);
|
||||
}
|
||||
errln("");
|
||||
|
||||
err("prev: ");
|
||||
while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
UnicodeString hexString("0x");
|
||||
|
||||
appendHex(o, 8, hexString);
|
||||
hexString += " ";
|
||||
err(hexString);
|
||||
}
|
||||
errln("");
|
||||
}
|
||||
|
||||
delete[] orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an integer array containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
*/
|
||||
int32_t *CollationIteratorTest::getOrders(CollationElementIterator &iter, int32_t &orderLength)
|
||||
{
|
||||
int32_t maxSize = 100;
|
||||
int32_t size = 0;
|
||||
int32_t *orders = new int32_t[maxSize];
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
int32_t order;
|
||||
while ((order = iter.next(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
if (size == maxSize)
|
||||
{
|
||||
maxSize *= 2;
|
||||
int32_t *temp = new int32_t[maxSize];
|
||||
|
||||
uprv_memcpy(temp, orders, size * sizeof(int32_t));
|
||||
delete[] orders;
|
||||
orders = temp;
|
||||
}
|
||||
|
||||
orders[size++] = order;
|
||||
}
|
||||
|
||||
if (maxSize > size)
|
||||
{
|
||||
int32_t *temp = new int32_t[size];
|
||||
|
||||
memcpy(temp, orders, size * sizeof(int32_t));
|
||||
delete[] orders;
|
||||
orders = temp;
|
||||
}
|
||||
|
||||
orderLength = size;
|
||||
return orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
|
@ -84,7 +84,6 @@ public:
|
||||
//
|
||||
|
||||
private:
|
||||
void backAndForth(CollationElementIterator &iter);
|
||||
|
||||
struct ExpansionRecord
|
||||
{
|
||||
@ -97,12 +96,6 @@ private:
|
||||
*/
|
||||
void verifyExpansion(UnicodeString rules, ExpansionRecord tests[], int32_t testCount);
|
||||
|
||||
/**
|
||||
* Return an integer array containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
*/
|
||||
int32_t *getOrders(CollationElementIterator &iter, int32_t &orderLength);
|
||||
|
||||
/**
|
||||
* Return a string containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
|
@ -320,6 +320,7 @@ IntlTestCollator::doTestVariant(Collator* col, UnicodeString &source, UnicodeStr
|
||||
Collator::EComparisonResult keyResult = srckey.compareTo(tgtkey);
|
||||
|
||||
reportCResult(source, target, srckey, tgtkey, compareResult, keyResult, result, result);
|
||||
|
||||
/*
|
||||
if (compareResult != result) {
|
||||
errln("String comparison failed in variant test\n");
|
||||
@ -339,6 +340,14 @@ IntlTestCollator::doTest(Collator* col, UnicodeString source, UnicodeString targ
|
||||
} else if (result == Collator::GREATER) {
|
||||
doTestVariant(col, target, source, Collator::LESS);
|
||||
}
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
CollationElementIterator* c = ((RuleBasedCollator *)col)->createCollationElementIterator( source );
|
||||
logln("Testing iterating source: "+source);
|
||||
backAndForth(*c);
|
||||
c->setText(target, status);
|
||||
logln("Testing iterating target: "+target);
|
||||
backAndForth(*c);
|
||||
}
|
||||
|
||||
|
||||
@ -461,3 +470,116 @@ UnicodeString &IntlTestCollator::prettify(const CollationKey &source, UnicodeStr
|
||||
return target;
|
||||
}
|
||||
|
||||
void IntlTestCollator::backAndForth(CollationElementIterator &iter)
|
||||
{
|
||||
// Run through the iterator forwards and stick it into an array
|
||||
int32_t orderLength = 0;
|
||||
int32_t *orders = getOrders(iter, orderLength);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// Now go through it backwards and make sure we get the same values
|
||||
int32_t index = orderLength;
|
||||
int32_t o;
|
||||
|
||||
// reset the iterator
|
||||
iter.reset();
|
||||
|
||||
while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
if (o != orders[--index])
|
||||
{
|
||||
if (o == 0)
|
||||
index ++;
|
||||
else
|
||||
{
|
||||
while (index > 0 && orders[--index] == 0)
|
||||
{
|
||||
}
|
||||
if (o != orders[index])
|
||||
{
|
||||
errln("Mismatch at index %d: 0x%X vs 0x%X", index,
|
||||
orders[index], o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (index != 0 && orders[index - 1] == 0)
|
||||
{
|
||||
index --;
|
||||
}
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
UnicodeString msg("Didn't get back to beginning - index is ");
|
||||
errln(msg + index);
|
||||
|
||||
iter.reset();
|
||||
err("next: ");
|
||||
while ((o = iter.next(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
UnicodeString hexString("0x");
|
||||
|
||||
appendHex(o, 8, hexString);
|
||||
hexString += " ";
|
||||
err(hexString);
|
||||
}
|
||||
errln("");
|
||||
|
||||
err("prev: ");
|
||||
while ((o = iter.previous(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
UnicodeString hexString("0x");
|
||||
|
||||
appendHex(o, 8, hexString);
|
||||
hexString += " ";
|
||||
err(hexString);
|
||||
}
|
||||
errln("");
|
||||
}
|
||||
|
||||
delete[] orders;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an integer array containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
*/
|
||||
int32_t *IntlTestCollator::getOrders(CollationElementIterator &iter, int32_t &orderLength)
|
||||
{
|
||||
int32_t maxSize = 100;
|
||||
int32_t size = 0;
|
||||
int32_t *orders = new int32_t[maxSize];
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
int32_t order;
|
||||
while ((order = iter.next(status)) != CollationElementIterator::NULLORDER)
|
||||
{
|
||||
if (size == maxSize)
|
||||
{
|
||||
maxSize *= 2;
|
||||
int32_t *temp = new int32_t[maxSize];
|
||||
|
||||
uprv_memcpy(temp, orders, size * sizeof(int32_t));
|
||||
delete[] orders;
|
||||
orders = temp;
|
||||
}
|
||||
|
||||
orders[size++] = order;
|
||||
}
|
||||
|
||||
if (maxSize > size)
|
||||
{
|
||||
int32_t *temp = new int32_t[size];
|
||||
|
||||
uprv_memcpy(temp, orders, size * sizeof(int32_t));
|
||||
delete[] orders;
|
||||
orders = temp;
|
||||
}
|
||||
|
||||
orderLength = size;
|
||||
return orders;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "unicode/sortkey.h"
|
||||
#include "unicode/schriter.h"
|
||||
#include "unicode/ures.h"
|
||||
#include "unicode/coleitr.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
|
||||
class IntlTestCollator: public IntlTest {
|
||||
@ -34,6 +36,13 @@ protected:
|
||||
|
||||
static UnicodeString &prettify(const CollationKey &source, UnicodeString &target);
|
||||
static UnicodeString &appendCompareResult(Collator::EComparisonResult result, UnicodeString &target);
|
||||
void backAndForth(CollationElementIterator &iter);
|
||||
/**
|
||||
* Return an integer array containing all of the collation orders
|
||||
* returned by calls to next on the specified iterator
|
||||
*/
|
||||
int32_t *getOrders(CollationElementIterator &iter, int32_t &orderLength);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user