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