1
/********************************************************************
3
* Copyright (c) 1997-2001, International Business Machines Corporation and
4
* others. All Rights Reserved.
5
********************************************************************/
7
#include "unicode/coll.h"
11
#include "unicode/tblcoll.h"
15
#include "unicode/unistr.h"
19
#include "unicode/sortkey.h"
28
CollationTurkishTest::CollationTurkishTest()
31
UErrorCode status = U_ZERO_ERROR;
32
myCollation = Collator::createInstance(Locale("tr", "", ""),status);
35
CollationTurkishTest::~CollationTurkishTest()
40
const UChar CollationTurkishTest::testSourceCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
42
{0x76, 0x00E4, 0x74, 0},
43
{0x6f, 0x6c, 0x64, 0},
44
{0x00FC, 0x6f, 0x69, 0x64, 0},
45
{0x68, 0x011E, 0x61, 0x6c, 0x74, 0},
46
{0x73, 0x74, 0x72, 0x65, 0x73, 0x015E, 0},
47
{0x76, 0x6f, 0x0131, 0x64, 0},
48
{0x69, 0x64, 0x65, 0x61, 0},
49
{0x00FC, 0x6f, 0x69, 0x64, 0},
50
{0x76, 0x6f, 0x0131, 0x64, 0},
51
{0x69, 0x64, 0x65, 0x61, 0}
54
const UChar CollationTurkishTest::testTargetCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
56
{0x76, 0x62, 0x74, 0},
57
{0x00D6, 0x61, 0x79, 0},
58
{0x76, 0x6f, 0x69, 0x64, 0},
59
{0x68, 0x61, 0x6c, 0x74, 0},
60
{0x015E, 0x74, 0x72, 0x65, 0x015E, 0x73, 0},
61
{0x76, 0x6f, 0x69, 0x64, 0},
62
{0x49, 0x64, 0x65, 0x61, 0},
63
{0x76, 0x6f, 0x69, 0x64, 0},
64
{0x76, 0x6f, 0x69, 0x64, 0},
65
{0x49, 0x64, 0x65, 0x61, 0}
68
const Collator::EComparisonResult CollationTurkishTest::results[] = {
83
void CollationTurkishTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
85
Collator::EComparisonResult compareResult = myCollation->compare(source, target);
86
CollationKey sortKey1, sortKey2;
87
UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
88
myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
89
myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
90
if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
91
errln("SortKey generation Failed.\n");
94
Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
95
reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
98
void CollationTurkishTest::TestTertiary(/* char* par */)
101
myCollation->setStrength(Collator::TERTIARY);
102
for (i = 0; i < 8 ; i++) {
103
doTest(testSourceCases[i], testTargetCases[i], results[i]);
106
void CollationTurkishTest::TestPrimary(/* char* par */)
109
myCollation->setStrength(Collator::PRIMARY);
110
for (i = 8; i < 11; i++) {
111
doTest(testSourceCases[i], testTargetCases[i], results[i]);
115
void CollationTurkishTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
117
if (exec) logln("TestSuite CollationTurkishTest: ");
119
if((!myCollation) && exec) {
120
errln(__FILE__ " cannot test - failed to create collator.");
125
case 0: name = "TestPrimary"; if (exec) TestPrimary(/* par */); break;
126
case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
127
default: name = ""; break;