]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/decoll.cpp
   1 /******************************************************************** 
   3  * Copyright (c) 1997-2009, International Business Machines Corporation and 
   4  * others. All Rights Reserved. 
   5  ********************************************************************/ 
   7 #include "unicode/utypes.h" 
   9 #if !UCONFIG_NO_COLLATION 
  14 #include "unicode/coll.h" 
  18 #include "unicode/tblcoll.h" 
  22 #include "unicode/unistr.h" 
  26 #include "unicode/sortkey.h" 
  35 CollationGermanTest::CollationGermanTest() 
  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: */ 
  48 CollationGermanTest::~CollationGermanTest() 
  53 const UChar 
CollationGermanTest::testSourceCases
[][CollationGermanTest::MAX_TOKEN_LEN
] = 
  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} 
  69 const UChar 
CollationGermanTest::testTargetCases
[][CollationGermanTest::MAX_TOKEN_LEN
] = 
  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} 
  85 const Collator::EComparisonResult 
CollationGermanTest::results
[][2] = 
  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 
} 
 103 void CollationGermanTest::TestTertiary(/* char* par */) 
 105     if(myCollation 
== NULL 
) { 
 106         dataerrln("decoll: cannot start test, collator is null\n"); 
 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
++) 
 116         doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][1]); 
 119 void CollationGermanTest::TestPrimary(/* char* par */) 
 121     if(myCollation 
== NULL 
) { 
 122         dataerrln("decoll: cannot start test, collator is null\n"); 
 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
++) 
 131         doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][0]); 
 135 void CollationGermanTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ ) 
 137     if (exec
) logln("TestSuite CollationGermanTest: "); 
 140         case 0: name 
= "TestPrimary";   if (exec
)   TestPrimary(/* par */); break; 
 141         case 1: name 
= "TestTertiary";  if (exec
)   TestTertiary(/* par */); break; 
 142         default: name 
= ""; break; 
 146 #endif /* #if !UCONFIG_NO_COLLATION */