scuffed-code/icu4c/source/test/intltest/decoll.cpp

147 lines
4.1 KiB
C++
Raw Normal View History

/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
1999-08-16 21:50:52 +00:00
#include "decoll.h"
#ifndef _COLL
#include "unicode/coll.h"
1999-08-16 21:50:52 +00:00
#endif
#ifndef _TBLCOLL
#include "unicode/tblcoll.h"
1999-08-16 21:50:52 +00:00
#endif
#ifndef _UNISTR
#include "unicode/unistr.h"
1999-08-16 21:50:52 +00:00
#endif
#ifndef _SORTKEY
#include "unicode/sortkey.h"
1999-08-16 21:50:52 +00:00
#endif
#ifndef _DECOLL
#include "decoll.h"
#endif
#include "sfwdchit.h"
1999-08-16 21:50:52 +00:00
CollationGermanTest::CollationGermanTest()
: myCollation(0)
{
UErrorCode status = U_ZERO_ERROR;
myCollation = Collator::createInstance(Locale::getGermany(), status);
if(!myCollation || U_FAILURE(status)) {
errln(__FILE__ "failed to create! err " + UnicodeString(u_errorName(status)));
/* if it wasn't already: */
delete myCollation;
myCollation = NULL;
}
1999-08-16 21:50:52 +00:00
}
CollationGermanTest::~CollationGermanTest()
{
delete myCollation;
}
const UChar CollationGermanTest::testSourceCases[][CollationGermanTest::MAX_TOKEN_LEN] =
{
{0x47, 0x72, 0x00F6, 0x00DF, 0x65, 0},
{0x61, 0x62, 0x63, 0},
{0x54, 0x00F6, 0x6e, 0x65, 0},
{0x54, 0x00F6, 0x6e, 0x65, 0},
{0x54, 0x00F6, 0x6e, 0x65, 0},
{0x61, 0x0308, 0x62, 0x63, 0},
{0x00E4, 0x62, 0x63, 0},
{0x00E4, 0x62, 0x63, 0},
{0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65, 0},
{0x65, 0x66, 0x67, 0},
{0x00E4, 0x62, 0x63, 0},
{0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65, 0}
1999-08-16 21:50:52 +00:00
};
const UChar CollationGermanTest::testTargetCases[][CollationGermanTest::MAX_TOKEN_LEN] =
{
{0x47, 0x72, 0x6f, 0x73, 0x73, 0x69, 0x73, 0x74, 0},
{0x61, 0x0308, 0x62, 0x63, 0},
{0x54, 0x6f, 0x6e, 0},
{0x54, 0x6f, 0x64, 0},
{0x54, 0x6f, 0x66, 0x75, 0},
{0x41, 0x0308, 0x62, 0x63, 0},
{0x61, 0x0308, 0x62, 0x63, 0},
{0x61, 0x65, 0x62, 0x63, 0},
{0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65, 0},
{0x65, 0x66, 0x67, 0},
{0x61, 0x65, 0x62, 0x63, 0},
{0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65, 0}
1999-08-16 21:50:52 +00:00
};
const UCollationResult CollationGermanTest::results[][2] =
1999-08-16 21:50:52 +00:00
{
// Primary Tertiary
{ UCOL_LESS, UCOL_LESS },
{ UCOL_EQUAL, UCOL_LESS },
{ UCOL_GREATER, UCOL_GREATER },
{ UCOL_GREATER, UCOL_GREATER },
{ UCOL_GREATER, UCOL_GREATER },
{ UCOL_EQUAL, UCOL_LESS },
{ UCOL_EQUAL, UCOL_EQUAL },
{ UCOL_LESS, UCOL_LESS },
{ UCOL_EQUAL, UCOL_GREATER },
{ UCOL_EQUAL, UCOL_EQUAL },
{ UCOL_LESS, UCOL_LESS },
{ UCOL_EQUAL, UCOL_GREATER }
1999-08-16 21:50:52 +00:00
};
void CollationGermanTest::TestTertiary(/* char* par */)
1999-08-16 21:50:52 +00:00
{
if(myCollation == NULL ) {
errln("decoll: cannot start test, collator is null\n");
return;
}
1999-08-16 21:50:52 +00:00
int32_t i = 0;
UErrorCode status = U_ZERO_ERROR;
1999-08-16 21:50:52 +00:00
myCollation->setStrength(Collator::TERTIARY);
myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
1999-08-16 21:50:52 +00:00
for (i = 0; i < 12 ; i++)
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][1]);
1999-08-16 21:50:52 +00:00
}
}
void CollationGermanTest::TestPrimary(/* char* par */)
1999-08-16 21:50:52 +00:00
{
if(myCollation == NULL ) {
errln("decoll: cannot start test, collator is null\n");
return;
}
1999-08-16 21:50:52 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
1999-08-16 21:50:52 +00:00
myCollation->setStrength(Collator::PRIMARY);
myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
1999-08-16 21:50:52 +00:00
for (i = 0; i < 12 ; i++)
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][0]);
1999-08-16 21:50:52 +00:00
}
}
void CollationGermanTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
1999-08-16 21:50:52 +00:00
{
if (exec) logln("TestSuite CollationGermanTest: ");
switch (index)
{
case 0: name = "TestPrimary"; if (exec) TestPrimary(/* par */); break;
case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
1999-08-16 21:50:52 +00:00
default: name = ""; break;
}
}
#endif /* #if !UCONFIG_NO_COLLATION */