ICU-1880 moved doTest to collation test base class. All the tests should use this common function

X-SVN-Rev: 8550
This commit is contained in:
Vladimir Weinstein 2002-04-30 23:02:45 +00:00
parent d9a4b4ce88
commit 1bc2cacb8e
2 changed files with 58 additions and 2 deletions

View File

@ -16,7 +16,10 @@
***********************************************************************/
#include "unicode/utypes.h"
#include "tscoll.h"
#include "unicode/uchar.h"
#include "dadrcoll.h"
#include "encoll.h"
#include "frcoll.h"
@ -41,6 +44,7 @@
#include "cntabcol.h"
#include "lcukocol.h"
void IntlTestCollator::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par )
{
if (exec)
@ -287,10 +291,57 @@ void IntlTestCollator::runIndexedTest( int32_t index, UBool exec, const char* &n
}
break;
case 19:
name = "DataDrivenTest";
if (exec) {
logln("DataDrivenTest---"); logln("");
DataDrivenCollatorTest test;
callTest( test, par );
}
break;
default: name = ""; break;
}
}
void
IntlTestCollator::doTestVariant(Collator* col, UnicodeString &source, UnicodeString &target, Collator::EComparisonResult result)
{
UErrorCode status = U_ZERO_ERROR;
Collator::EComparisonResult compareResult = col->compare(source, target);
CollationKey srckey, tgtkey;
col->getCollationKey(source, srckey, status);
col->getCollationKey(target, tgtkey, status);
if (U_FAILURE(status)){
errln("Creation of collation keys failed\n");
}
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");
}
if (keyResult != result) {
errln("Collation key comparison failed in variant test\n");
}
*/
}
void
IntlTestCollator::doTest(Collator* col, UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
{
doTestVariant(col, source, target, result);
if(result == Collator::LESS) {
doTestVariant(col, target, source, Collator::GREATER);
} else if (result == Collator::GREATER) {
doTestVariant(col, target, source, Collator::LESS);
}
}
// used for collation result reporting, defined here for convenience
// (maybe moved later)
void

View File

@ -15,11 +15,16 @@
#include "intltest.h"
#include "unicode/coll.h"
#include "unicode/sortkey.h"
#include "unicode/schriter.h"
#include "unicode/ures.h"
class IntlTestCollator: public IntlTest {
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par = NULL );
protected:
// These two should probably go down in IntlTest
void doTest(Collator* col, UnicodeString source, UnicodeString target, Collator::EComparisonResult result);
void doTestVariant(Collator* col, UnicodeString &source, UnicodeString &target, Collator::EComparisonResult result);
virtual void reportCResult( UnicodeString &source, UnicodeString &target,
CollationKey &sourceKey, CollationKey &targetKey,
Collator::EComparisonResult compareResult,