1 /********************************************************************
2 * Copyright (c) 1997-2009, International Business Machines
3 * Corporation and others. All Rights Reserved.
4 ********************************************************************/
5
6 #include "unicode/utypes.h"
7
8 #if !UCONFIG_NO_COLLATION
9
10 #ifndef _COLL
11 #include "unicode/coll.h"
12 #endif
13
14 #ifndef _TBLCOLL
15 #include "unicode/tblcoll.h"
16 #endif
17
18 #ifndef _UNISTR
19 #include "unicode/unistr.h"
20 #endif
21
22 #ifndef _SORTKEY
23 #include "unicode/sortkey.h"
24 #endif
25
26 #ifndef _FICOLL
27 #include "ficoll.h"
28 #endif
29
30 #include "sfwdchit.h"
31
CollationFinnishTest()32 CollationFinnishTest::CollationFinnishTest()
33 : myCollation(0)
34 {
35 UErrorCode status = U_ZERO_ERROR;
36 myCollation = Collator::createInstance(Locale("fi", "FI", "", "collation=standard"),status);
37 }
38
~CollationFinnishTest()39 CollationFinnishTest::~CollationFinnishTest()
40 {
41 delete myCollation;
42 }
43
44 const UChar CollationFinnishTest::testSourceCases[][CollationFinnishTest::MAX_TOKEN_LEN] = {
45 {0x77, 0x61, 0x74, 0},
46 {0x76, 0x61, 0x74, 0},
47 {0x61, 0x00FC, 0x62, 0x65, 0x63, 0x6b, 0},
48 {0x4c, 0x00E5, 0x76, 0x69, 0},
49 {0x77, 0x61, 0x74, 0}
50 };
51
52 const UChar CollationFinnishTest::testTargetCases[][CollationFinnishTest::MAX_TOKEN_LEN] = {
53 {0x76, 0x61, 0x74, 0},
54 {0x77, 0x61, 0x79, 0},
55 {0x61, 0x78, 0x62, 0x65, 0x63, 0x6b, 0},
56 {0x4c, 0x00E4, 0x77, 0x65, 0},
57 {0x76, 0x61, 0x74, 0}
58 };
59
60 const Collator::EComparisonResult CollationFinnishTest::results[] = {
61 Collator::GREATER,
62 Collator::LESS,
63 Collator::GREATER,
64 Collator::LESS,
65 // test primary > 4
66 Collator::EQUAL,
67 };
68
TestTertiary()69 void CollationFinnishTest::TestTertiary(/* char* par */)
70 {
71 int32_t i = 0;
72 myCollation->setStrength(Collator::TERTIARY);
73 for (i = 0; i < 4 ; i++) {
74 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
75 }
76 }
TestPrimary()77 void CollationFinnishTest::TestPrimary(/* char* par */)
78 {
79 int32_t i;
80 myCollation->setStrength(Collator::PRIMARY);
81 for (i = 4; i < 5; i++) {
82 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
83 }
84 }
85
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)86 void CollationFinnishTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
87 {
88 if (exec) logln("TestSuite CollationFinnishTest: ");
89
90 if((!myCollation) && exec) {
91 dataerrln(__FILE__ " cannot test - failed to create collator.");
92 name = "some test";
93 return;
94 }
95 switch (index) {
96 case 0: name = "TestPrimary"; if (exec) TestPrimary(/* par */); break;
97 case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
98 default: name = ""; break;
99 }
100 }
101
102 #endif /* #if !UCONFIG_NO_COLLATION */
103