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

« back to all changes in this revision

Viewing changes to source/test/intltest/trcoll.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
 
#ifndef _COLL
7
 
#include "unicode/coll.h"
8
 
#endif
9
 
 
10
 
#ifndef _TBLCOLL
11
 
#include "unicode/tblcoll.h"
12
 
#endif
13
 
 
14
 
#ifndef _UNISTR
15
 
#include "unicode/unistr.h"
16
 
#endif
17
 
 
18
 
#ifndef _SORTKEY
19
 
#include "unicode/sortkey.h"
20
 
#endif
21
 
 
22
 
#ifndef _TRCOLL
23
 
#include "trcoll.h"
24
 
#endif
25
 
 
26
 
#include "sfwdchit.h"
27
 
 
28
 
CollationTurkishTest::CollationTurkishTest()
29
 
: myCollation(0)
30
 
{
31
 
    UErrorCode status = U_ZERO_ERROR;
32
 
    myCollation = Collator::createInstance(Locale("tr", "", ""),status);
33
 
}
34
 
 
35
 
CollationTurkishTest::~CollationTurkishTest()
36
 
{
37
 
    delete myCollation;
38
 
}
39
 
 
40
 
const UChar CollationTurkishTest::testSourceCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
41
 
    {0x73, 0x0327, 0},
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}
52
 
};
53
 
 
54
 
const UChar CollationTurkishTest::testTargetCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
55
 
    {0x75, 0x0308, 0},
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}
66
 
};
67
 
 
68
 
const Collator::EComparisonResult CollationTurkishTest::results[] = {
69
 
    Collator::LESS,
70
 
    Collator::LESS,
71
 
    Collator::LESS,
72
 
    Collator::LESS,
73
 
    Collator::GREATER,
74
 
    Collator::LESS,
75
 
    Collator::LESS,
76
 
    Collator::GREATER,
77
 
    // test priamry > 8
78
 
    Collator::LESS,
79
 
    Collator::LESS,
80
 
    Collator::GREATER
81
 
};
82
 
 
83
 
void CollationTurkishTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
84
 
{
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");
92
 
        return;
93
 
    }
94
 
    Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
95
 
    reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, compareResult, result );
96
 
}
97
 
 
98
 
void CollationTurkishTest::TestTertiary(/* char* par */)
99
 
{
100
 
    int32_t i = 0;
101
 
    myCollation->setStrength(Collator::TERTIARY);
102
 
    for (i = 0; i < 8 ; i++) {
103
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
104
 
    }
105
 
}
106
 
void CollationTurkishTest::TestPrimary(/* char* par */)
107
 
{
108
 
    int32_t i;
109
 
    myCollation->setStrength(Collator::PRIMARY);
110
 
    for (i = 8; i < 11; i++) {
111
 
        doTest(testSourceCases[i], testTargetCases[i], results[i]);
112
 
    }
113
 
}
114
 
 
115
 
void CollationTurkishTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
116
 
{
117
 
    if (exec) logln("TestSuite CollationTurkishTest: ");
118
 
 
119
 
    if((!myCollation) && exec) {
120
 
      errln(__FILE__ " cannot test - failed to create collator.");
121
 
      name = "";
122
 
      return;
123
 
    }
124
 
    switch (index) {
125
 
        case 0: name = "TestPrimary";   if (exec)   TestPrimary(/* par */); break;
126
 
        case 1: name = "TestTertiary";  if (exec)   TestTertiary(/* par */); break;
127
 
        default: name = ""; break;
128
 
    }
129
 
}
130
 
 
131