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