1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "decoll.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _COLL
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/coll.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _TBLCOLL
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/tblcoll.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _UNISTR
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h"
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _SORTKEY
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/sortkey.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _DECOLL
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "decoll.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "sfwdchit.h"
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCollationGermanTest::CollationGermanTest()
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: myCollation(0)
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation = Collator::createInstance(Locale::getGermany(), status);
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!myCollation || U_FAILURE(status)) {
4185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        errcheckln(status, __FILE__ "failed to create! err " + UnicodeString(u_errorName(status)));
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* if it wasn't already: */
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete myCollation;
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        myCollation = NULL;
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCollationGermanTest::~CollationGermanTest()
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete myCollation;
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UChar CollationGermanTest::testSourceCases[][CollationGermanTest::MAX_TOKEN_LEN] =
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x47, 0x72, 0x00F6, 0x00DF, 0x65, 0},
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x62, 0x63, 0},
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x00F6, 0x6e, 0x65, 0},
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x00F6, 0x6e, 0x65, 0},
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x00F6, 0x6e, 0x65, 0},
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x0308, 0x62, 0x63, 0},
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x62, 0x63, 0},
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x62, 0x63, 0},
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65, 0},
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x65, 0x66, 0x67, 0},
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x00E4, 0x62, 0x63, 0},
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x53, 0x74, 0x72, 0x61, 0x00DF, 0x65, 0}
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UChar CollationGermanTest::testTargetCases[][CollationGermanTest::MAX_TOKEN_LEN] =
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x47, 0x72, 0x6f, 0x73, 0x73, 0x69, 0x73, 0x74, 0},
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x0308, 0x62, 0x63, 0},
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x6f, 0x6e, 0},
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x6f, 0x64, 0},
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x54, 0x6f, 0x66, 0x75, 0},
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x41, 0x0308, 0x62, 0x63, 0},
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x0308, 0x62, 0x63, 0},
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x65, 0x62, 0x63, 0},
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65, 0},
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x65, 0x66, 0x67, 0},
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x61, 0x65, 0x62, 0x63, 0},
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {0x53, 0x74, 0x72, 0x61, 0x73, 0x73, 0x65, 0}
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst Collator::EComparisonResult CollationGermanTest::results[][2] =
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      //  Primary                Tertiary
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::LESS,        Collator::LESS },
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::LESS },
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::GREATER,    Collator::GREATER },
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::GREATER,    Collator::GREATER },
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::GREATER,    Collator::GREATER },
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::LESS },
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::EQUAL },
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::LESS,        Collator::LESS },
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::GREATER },
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::EQUAL },
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::LESS,        Collator::LESS },
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { Collator::EQUAL,        Collator::GREATER }
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationGermanTest::TestTertiary(/* char* par */)
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(myCollation == NULL ) {
10685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("decoll: cannot start test, collator is null\n");
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i = 0;
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation->setStrength(Collator::TERTIARY);
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 0; i < 12 ; i++)
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][1]);
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationGermanTest::TestPrimary(/* char* par */)
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(myCollation == NULL ) {
12285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("decoll: cannot start test, collator is null\n");
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation->setStrength(Collator::PRIMARY);
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i = 0; i < 12 ; i++)
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][0]);
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationGermanTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (exec) logln("TestSuite CollationGermanTest: ");
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch (index)
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        case 0: name = "TestPrimary";   if (exec)   TestPrimary(/* par */); break;
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        case 1: name = "TestTertiary";  if (exec)   TestTertiary(/* par */); break;
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        default: name = ""; break;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */
147