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