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/unistr.h" 10 11 #if !UCONFIG_NO_COLLATION 12 13 #include "unicode/tstdtmod.h" 14 #include "unicode/coll.h" 15 #include "unicode/tblcoll.h" 16 #include "unicode/sortkey.h" 17 #include "trcoll.h" 18 #include "sfwdchit.h" 19 20 CollationTurkishTest::CollationTurkishTest() 21 : myCollation(0) 22 { 23 UErrorCode status = U_ZERO_ERROR; 24 myCollation = Collator::createInstance(Locale("tr", "", ""),status); 25 } 26 27 CollationTurkishTest::~CollationTurkishTest() 28 { 29 delete myCollation; 30 } 31 32 const UChar CollationTurkishTest::testSourceCases[][CollationTurkishTest::MAX_TOKEN_LEN] = { 33 {0x73, 0x0327, 0}, 34 {0x76, 0x00E4, 0x74, 0}, 35 {0x6f, 0x6c, 0x64, 0}, 36 {0x00FC, 0x6f, 0x69, 0x64, 0}, 37 {0x68, 0x011E, 0x61, 0x6c, 0x74, 0}, 38 {0x73, 0x74, 0x72, 0x65, 0x73, 0x015E, 0}, 39 {0x76, 0x6f, 0x0131, 0x64, 0}, 40 {0x69, 0x64, 0x65, 0x61, 0}, 41 {0x00FC, 0x6f, 0x69, 0x64, 0}, 42 {0x76, 0x6f, 0x0131, 0x64, 0}, 43 {0x69, 0x64, 0x65, 0x61, 0} 44 }; 45 46 const UChar CollationTurkishTest::testTargetCases[][CollationTurkishTest::MAX_TOKEN_LEN] = { 47 {0x75, 0x0308, 0}, 48 {0x76, 0x62, 0x74, 0}, 49 {0x00D6, 0x61, 0x79, 0}, 50 {0x76, 0x6f, 0x69, 0x64, 0}, 51 {0x68, 0x61, 0x6c, 0x74, 0}, 52 {0x015E, 0x74, 0x72, 0x65, 0x015E, 0x73, 0}, 53 {0x76, 0x6f, 0x69, 0x64, 0}, 54 {0x49, 0x64, 0x65, 0x61, 0}, 55 {0x76, 0x6f, 0x69, 0x64, 0}, 56 {0x76, 0x6f, 0x69, 0x64, 0}, 57 {0x49, 0x64, 0x65, 0x61, 0} 58 }; 59 60 const Collator::EComparisonResult CollationTurkishTest::results[] = { 61 Collator::LESS, 62 Collator::LESS, 63 Collator::LESS, 64 Collator::LESS, 65 Collator::GREATER, 66 Collator::LESS, 67 Collator::LESS, 68 Collator::GREATER, 69 // test priamry > 8 70 Collator::LESS, 71 Collator::LESS, 72 Collator::GREATER 73 }; 74 75 void CollationTurkishTest::TestTertiary(/* char* par */) 76 { 77 int32_t i = 0; 78 myCollation->setStrength(Collator::TERTIARY); 79 for (i = 0; i < 8 ; i++) { 80 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 81 } 82 } 83 void CollationTurkishTest::TestPrimary(/* char* par */) 84 { 85 int32_t i; 86 myCollation->setStrength(Collator::PRIMARY); 87 for (i = 8; i < 11; i++) { 88 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 89 } 90 } 91 92 void CollationTurkishTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 93 { 94 if (exec) logln("TestSuite CollationTurkishTest: "); 95 96 if((!myCollation) && exec) { 97 dataerrln(__FILE__ " cannot test - failed to create collator."); 98 name = "some test"; 99 return; 100 } 101 switch (index) { 102 case 0: name = "TestPrimary"; if (exec) TestPrimary(/* par */); break; 103 case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break; 104 default: name = ""; break; 105 } 106 } 107 108 #endif /* #if !UCONFIG_NO_COLLATION */ 109