~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/test/intltest/allcoll.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/********************************************************************
2
 
 * COPYRIGHT: 
3
 
 * Copyright (c) 1997-2001, International Business Machines Corporation and
4
 
 * others. All Rights Reserved.
5
 
 ********************************************************************/
6
 
 
7
 
#include "unicode/coll.h"
8
 
#include "unicode/tblcoll.h"
9
 
#include "unicode/unistr.h"
10
 
#include "unicode/sortkey.h"
11
 
#include "allcoll.h"
12
 
#include "sfwdchit.h"
13
 
 
14
 
/*
15
 
 * Include callcoll.c to get the test data.
16
 
 * This helps maintain a single copy of the data.
17
 
 */
18
 
#define INCLUDE_CALLCOLL_C
19
 
#include "../cintltst/callcoll.c"
20
 
 
21
 
CollationDummyTest::CollationDummyTest()
22
 
: myCollation(0)
23
 
{
24
 
    /*UErrorCode status = U_ZERO_ERROR;
25
 
    UnicodeString rules(TRUE, DEFAULTRULEARRAY, sizeof(DEFAULTRULEARRAY)/sizeof(DEFAULTRULEARRAY[0]));
26
 
    UnicodeString newRules("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
27
 
    rules += newRules;
28
 
    myCollation = new RuleBasedCollator(rules, status);
29
 
    */
30
 
 
31
 
    UErrorCode status = U_ZERO_ERROR;
32
 
    UnicodeString ruleset("& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
33
 
    if (myCollation != NULL)
34
 
    {
35
 
      delete myCollation;
36
 
    }
37
 
    myCollation = new RuleBasedCollator(ruleset, status);
38
 
    if(U_FAILURE(status)){
39
 
        errln("ERROR: in creation of rule based collator from ruleset");
40
 
    }
41
 
}
42
 
 
43
 
CollationDummyTest::~CollationDummyTest()
44
 
{
45
 
    delete myCollation;
46
 
}
47
 
 
48
 
const Collator::EComparisonResult CollationDummyTest::results[] = {
49
 
    Collator::LESS,
50
 
    Collator::LESS, /*Collator::GREATER,*/
51
 
    Collator::LESS,
52
 
    Collator::LESS,
53
 
    Collator::LESS,
54
 
    Collator::LESS,
55
 
    Collator::LESS,
56
 
    Collator::GREATER,
57
 
    Collator::GREATER,
58
 
    Collator::LESS,                                     /*  10 */
59
 
    Collator::GREATER,
60
 
    Collator::LESS,
61
 
    Collator::GREATER,
62
 
    Collator::GREATER,
63
 
    Collator::LESS,
64
 
    Collator::LESS,
65
 
    Collator::LESS,
66
 
    /*  test primary > 17 */
67
 
    Collator::EQUAL,
68
 
    Collator::EQUAL,
69
 
    Collator::EQUAL,                                    /*  20 */
70
 
    Collator::LESS,
71
 
    Collator::LESS,
72
 
    Collator::EQUAL,
73
 
    Collator::EQUAL,
74
 
    Collator::EQUAL,
75
 
    Collator::LESS,
76
 
    /*  test secondary > 26 */
77
 
    Collator::EQUAL,
78
 
    Collator::EQUAL,
79
 
    Collator::EQUAL,
80
 
    Collator::EQUAL,
81
 
    Collator::EQUAL,                                    /*  30 */
82
 
    Collator::EQUAL,
83
 
    Collator::LESS,
84
 
    Collator::EQUAL,                                     /*  34 */
85
 
    Collator::EQUAL,
86
 
    Collator::EQUAL,
87
 
    Collator::LESS 
88
 
};
89
 
 
90
 
void 
91
 
CollationDummyTest::doTestVariant(const UnicodeString source, const UnicodeString target, Collator::EComparisonResult result)
92
 
{   
93
 
  UErrorCode status = U_ZERO_ERROR;
94
 
 
95
 
  Collator::EComparisonResult compareResult = myCollation->compare(source, target);
96
 
 
97
 
  CollationKey srckey, tgtkey;
98
 
  myCollation->getCollationKey(source, srckey, status);
99
 
  myCollation->getCollationKey(target, tgtkey, status);
100
 
  if (U_FAILURE(status)){
101
 
    errln("Creation of collation keys failed\n");
102
 
  }
103
 
  Collator::EComparisonResult keyResult = srckey.compareTo(tgtkey);
104
 
 
105
 
  if (compareResult != result) {
106
 
    errln("String comparison failed in variant test\n");
107
 
  }
108
 
  if (keyResult != result) {
109
 
    errln("Collation key comparison failed in variant test\n");
110
 
  }
111
 
}
112
 
 
113
 
void CollationDummyTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
114
 
{
115
 
    /*
116
 
    Collator::EComparisonResult compareResult = myCollation->compare(source, target);
117
 
    SimpleFwdCharIterator src(source);
118
 
    SimpleFwdCharIterator trg(target);
119
 
    Collator::EComparisonResult incResult = myCollation->compare(src, trg);
120
 
    CollationKey sortKey1, sortKey2;
121
 
    UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
122
 
    myCollation->getCollationKey(source, sortKey1, key1status );
123
 
    myCollation->getCollationKey(target, sortKey2, key2status );
124
 
    if (U_FAILURE(key1status) || U_FAILURE(key2status))
125
 
    {
126
 
        errln("SortKey generation Failed.\n");
127
 
        return;
128
 
    }
129
 
 
130
 
    Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
131
 
    reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, incResult, result );
132
 
    */
133
 
  doTestVariant(source, target, result);
134
 
  if(result == Collator::LESS) {
135
 
    doTestVariant(target, source, Collator::GREATER);
136
 
  } else if (result == Collator::GREATER) {
137
 
    doTestVariant(target, source, Collator::LESS);
138
 
  } else {
139
 
    doTestVariant(target, source, Collator::EQUAL);
140
 
  }
141
 
}
142
 
 
143
 
void CollationDummyTest::TestTertiary(/* char* par */)
144
 
{
145
 
    int32_t i = 0;
146
 
    myCollation->setStrength(Collator::TERTIARY);
147
 
    for (i = 0; i < 17 ; i++)
148
 
    {
149
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
150
 
    }
151
 
}
152
 
void CollationDummyTest::TestPrimary(/* char* par */)
153
 
{
154
 
    /* problem in strcollinc for unfinshed contractions */
155
 
    UErrorCode status = U_ZERO_ERROR;
156
 
 
157
 
    myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
158
 
    myCollation->setStrength(Collator::PRIMARY);
159
 
 
160
 
    if (U_FAILURE(status))
161
 
    {
162
 
      errln("Failure in setting attribute for normalization mode\n");
163
 
    }
164
 
    
165
 
    for (int i = 17; i < 26 ; i++)
166
 
    {
167
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
168
 
    }
169
 
}
170
 
 
171
 
void CollationDummyTest::TestSecondary(/* char* par */)
172
 
{
173
 
    int32_t i;
174
 
    myCollation->setStrength(Collator::SECONDARY);
175
 
    for (i = 26; i < 34; i++)
176
 
    {
177
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
178
 
    }
179
 
}
180
 
 
181
 
void CollationDummyTest::TestExtra(/* char* par */)
182
 
{
183
 
    int32_t i, j;
184
 
    myCollation->setStrength(Collator::TERTIARY);
185
 
    for (i = 0; i < COUNT_TEST_CASES-1; i++)
186
 
    {
187
 
        for (j = i + 1; j < COUNT_TEST_CASES; j += 1)
188
 
        {
189
 
            doTest(testCases[i], testCases[j], Collator::LESS);
190
 
        }
191
 
    }
192
 
}
193
 
 
194
 
void CollationDummyTest::TestIdentical()
195
 
{
196
 
    int32_t i;
197
 
    myCollation->setStrength(Collator::IDENTICAL);
198
 
    for (i= 34; i<37; i++)
199
 
    {
200
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
201
 
    }
202
 
}
203
 
 
204
 
void CollationDummyTest::TestJB581(void)
205
 
{
206
 
    UErrorCode status = U_ZERO_ERROR;
207
 
 
208
 
    UnicodeString source("THISISATEST.");
209
 
    UnicodeString target("Thisisatest.");
210
 
 
211
 
    Collator *coll = Collator::createInstance("en_US", status);
212
 
    if (U_FAILURE(status)){
213
 
        errln("ERROR: Failed to create the collator for : en_US\n");
214
 
        return;
215
 
    }
216
 
 
217
 
    Collator::EComparisonResult result = coll->compare(source, target);
218
 
    /* result is 1, secondary differences only for ignorable space characters*/
219
 
    if (result != 1)
220
 
    {
221
 
        errln("Comparing two strings with only secondary differences in C failed.\n");
222
 
    }
223
 
    /* To compare them with just primary differences */
224
 
    coll->setStrength(Collator::PRIMARY);
225
 
    result = coll->compare(source, target);
226
 
    /* result is 0 */
227
 
    if (result != 0)
228
 
    {
229
 
        errln("Comparing two strings with no differences in C failed.\n");
230
 
    }
231
 
    /* Now, do the same comparison with keys */
232
 
    CollationKey sourceKeyOut,
233
 
      targetKeyOut;
234
 
    coll->getCollationKey(source, sourceKeyOut, status);
235
 
    coll->getCollationKey(target, targetKeyOut, status);
236
 
    result = sourceKeyOut.compareTo(targetKeyOut);
237
 
    if (result != 0)
238
 
    {
239
 
        errln("Comparing two strings with sort keys in C failed.\n");
240
 
    }
241
 
    delete coll;
242
 
}
243
 
 
244
 
void CollationDummyTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
245
 
{
246
 
    if (exec) logln("TestSuite CollationDummyTest: ");
247
 
    switch (index) {
248
 
        case 0: name = "TestPrimary";   if (exec)   TestPrimary(/* par */); break;
249
 
        case 1: name = "TestSecondary"; if (exec)   TestSecondary(/* par */); break;
250
 
        case 2: name = "TestTertiary";  if (exec)   TestTertiary(/* par */); break;
251
 
        case 3: name = "TestExtra";     if (exec)   TestExtra(/* par */); break;
252
 
        case 4: name = "TestIdentical"; if (exec)   TestIdentical(/* par */); break;
253
 
        case 5: name = "TestJB581";     if (exec)   TestJB581(/* par */); break;
254
 
        default: name = ""; break;
255
 
    }
256
 
}
257