1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/***********************************************************************
* Modification history
* Date Name Description
* 02/14/2001 synwee Added attributes in TestTertiary and
* TestSecondary
***********************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
#include "unicode/coll.h"
#include "unicode/tblcoll.h"
#include "unicode/unistr.h"
#include "unicode/sortkey.h"
#include "cmemory.h"
#include "frcoll.h"
#include "sfwdchit.h"
CollationFrenchTest::CollationFrenchTest()
: myCollation(nullptr)
{
UErrorCode status = U_ZERO_ERROR;
myCollation = Collator::createInstance(Locale::getCanadaFrench(), status);
if(!myCollation || U_FAILURE(status)) {
errcheckln(status, __FILE__ "failed to create! err " + UnicodeString(u_errorName(status)));
/* if it wasn't already: */
delete myCollation;
myCollation = nullptr;
}
}
CollationFrenchTest::~CollationFrenchTest()
{
delete myCollation;
}
const char16_t CollationFrenchTest::testSourceCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
{0x0043/*'C'*/, 0x004f/*'O'*/, 0x0054/*'T'*/, 0x0045/*'E'*/, 0x0000},
{0x0063/*'c'*/, 0x006f/*'o'*/, 0x002d/*'-'*/, 0x006f/*'o'*/, 0x0070/*'p'*/, 0x0000},
{0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
{0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
{0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
{0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
{0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
{0x01f1, 0x0000},
{0xfb00, 0x0000},
{0x01fa, 0x0000},
{0x0101, 0x0000}
};
const char16_t CollationFrenchTest::testTargetCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0041/*'A'*/, 0x0042/*'B'*/, 0x0043/*'C'*/, 0x0000},
{0x0063/*'c'*/, 0x00f4, 0x0074/*'t'*/, 0x0065/*'e'*/, 0x0000},
{0x0043/*'C'*/, 0x004f/*'O'*/, 0x004f/*'O'*/, 0x0050/*'P'*/, 0x0000},
{0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
{0x0070/*'p'*/, 0x00E9, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x00E9, 0x0000},
{0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0000},
{0x0070/*'p'*/, 0x00EA, 0x0063/*'c'*/, 0x0068/*'h'*/, 0x0065/*'e'*/, 0x0072/*'r'*/, 0x0000},
{0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x004f/*'O'*/, 0x0000},
{0x01ee, 0x0000},
{0x25ca, 0x0000},
{0x00e0, 0x0000},
{0x01df, 0x0000}
};
const Collator::EComparisonResult CollationFrenchTest::results[] =
{
Collator::LESS,
Collator::LESS,
Collator::LESS, /*Collator::GREATER,*/
Collator::LESS,
Collator::GREATER,
Collator::GREATER,
Collator::LESS,
Collator::GREATER,
Collator::LESS, /*Collator::GREATER,*/
Collator::GREATER,
Collator::LESS,
Collator::LESS
};
// 0x0300 is grave, 0x0301 is acute
// the order of elements in this array must be different than the order in CollationEnglishTest
const char16_t CollationFrenchTest::testAcute[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
/*00*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0000},
/*01*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0000},
/*02*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0000},
/*03*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0000},
/*04*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0000},
/*05*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0000},
/*06*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
/*07*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0000},
/*08*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
/*09*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0000},
/*0a*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
/*0b*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
/*0c*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
/*0d*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
/*0e*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0301, 0x0000},
/*0f*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0300, 0x0000},
/*10*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
/*11*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0300, 0x0000},
/*12*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
/*13*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0300, 0x0000},
/*14*/ {0x0065/*'e'*/, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
/*15*/ {0x0065/*'e'*/, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
/*16*/ {0x0065/*'e'*/, 0x0300, 0x0301, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
/*17*/ {0x0065/*'e'*/, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000},
/*18*/ {0x0065/*'e'*/, 0x0301, 0x0300, 0x0065/*'e'*/, 0x0301, 0x0300, 0x0000}
};
const char16_t CollationFrenchTest::testBugs[][CollationFrenchTest::MAX_TOKEN_LEN] =
{
{0x0061/*'a'*/, 0x000},
{0x0041/*'A'*/, 0x000},
{0x0065/*'e'*/, 0x000},
{0x0045/*'E'*/, 0x000},
{0x00e9, 0x000},
{0x00e8, 0x000},
{0x00ea, 0x000},
{0x00eb, 0x000},
{0x0065/*'e'*/, 0x0061/*'a'*/, 0x000},
{0x0078/*'x'*/, 0x000}
};
void CollationFrenchTest::TestTertiary(/* char* par */)
{
int32_t i = 0;
UErrorCode status = U_ZERO_ERROR;
myCollation->setStrength(Collator::TERTIARY);
myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
myCollation->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status);
if (U_FAILURE(status)) {
errln("Error setting attribute in French collator");
}
else
{
for (i = 0; i < 12 ; i++)
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
}
}
}
void CollationFrenchTest::TestSecondary(/* char* par */)
{
//test acute and grave ordering
int32_t i = 0;
int32_t j;
Collator::EComparisonResult expected;
UErrorCode status = U_ZERO_ERROR;
//myCollation->setAttribute(UCOL_FRENCH_COLLATION, UCOL_ON, status);
myCollation->setStrength(Collator::SECONDARY);
if (U_FAILURE(status))
errln("Error setting attribute in French collator");
else
{
const int32_t testAcuteSize = UPRV_LENGTHOF(testAcute);
for (i = 0; i < testAcuteSize; i++)
{
for (j = 0; j < testAcuteSize; j++)
{
if (i < j)
expected = Collator::LESS;
else if (i == j)
expected = Collator::EQUAL;
else // (i > j)
expected = Collator::GREATER;
doTest(myCollation, testAcute[i], testAcute[j], expected );
}
}
}
}
void CollationFrenchTest::TestExtra(/* char* par */)
{
int32_t i, j;
myCollation->setStrength(Collator::TERTIARY);
for (i = 0; i < 9 ; i++)
{
for (j = i + 1; j < 10; j += 1)
{
doTest(myCollation, testBugs[i], testBugs[j], Collator::LESS);
}
}
}
void CollationFrenchTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
{
if (exec) logln("TestSuite CollationFrenchTest: ");
if((!myCollation) && exec) {
dataerrln(__FILE__ " cannot test - failed to create collator.");
name = "some test";
return;
}
switch (index) {
case 0: name = "TestSecondary"; if (exec) TestSecondary(/* par */); break;
case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
case 2: name = "TestExtra"; if (exec) TestExtra(/* par */); break;
default: name = ""; break;
}
}
#endif /* #if !UCONFIG_NO_COLLATION */
|