1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _COLL 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/coll.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _TBLCOLL 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/tblcoll.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _UNISTR 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _SORTKEY 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/sortkey.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _ESCOLL 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "escoll.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "sfwdchit.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCollationSpanishTest::CollationSpanishTest() 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: myCollation(0) 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation = Collator::createInstance(Locale("es", "ES", ""),status); 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCollationSpanishTest::~CollationSpanishTest() 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete myCollation; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UChar CollationSpanishTest::testSourceCases[][CollationSpanishTest::MAX_TOKEN_LEN] = { 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x6c, 0x69, 0x61, 0x73, 0}, 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x45, 0x6c, 0x6c, 0x69, 0x6f, 0x74, 0}, 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0}, 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x63, 0x48, 0x63, 0}, 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x63, 0x63, 0}, 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x6c, 0x69, 0x61, 0x73, 0}, 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x63, 0x48, 0x63, 0}, 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x63, 0x63, 0}, 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0}, 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UChar CollationSpanishTest::testTargetCases[][CollationSpanishTest::MAX_TOKEN_LEN] = { 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x6c, 0x6c, 0x69, 0x61, 0x73, 0}, 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x45, 0x6d, 0x69, 0x6f, 0x74, 0}, 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x68, 0x65, 0x6c, 0x6c, 0x4f, 0}, 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x43, 0x48, 0x63, 0}, 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x43, 0x48, 0x63, 0}, 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x6c, 0x6c, 0x69, 0x61, 0x73, 0}, 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x43, 0x48, 0x63, 0}, 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x61, 0x43, 0x48, 0x63, 0}, 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x68, 0x65, 0x6c, 0x6c, 0x4f, 0}, 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst Collator::EComparisonResult CollationSpanishTest::results[] = { 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::GREATER, 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // test primary > 5 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::EQUAL, 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::LESS, 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator::EQUAL 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationSpanishTest::TestTertiary(/* char* par */) 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation->setStrength(Collator::TERTIARY); 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < 5 ; i++) { 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationSpanishTest::TestPrimary(/* char* par */) 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation->setStrength(Collator::PRIMARY); 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 5; i < 9; i++) { 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CollationSpanishTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par */) 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite CollationSpanishTest: "); 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((!myCollation) && exec) { 10585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho dataerrln(__FILE__ " cannot test - failed to create collator."); 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru name = "some test"; 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 0: name = "TestPrimary"; if (exec) TestPrimary(/* par */); break; 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 1: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break; 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: name = ""; break; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 117