1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************************** 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CESTST.C 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History: 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Name Description 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Madhu Katragadda Ported for C API 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*********************************************************************************/ 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * CollationSpanishTest is a third level test class. This tests the locale 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * specific primary, secondary and tertiary rules. For example, the ignorable 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * character '-' in string "black-bird". The en_US locale uses the default 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * collation rules as its sorting sequence. 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucol.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cestst.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ccolltst.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "callcoll.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "string.h" 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UCollator *myCollation; 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testSourceCases[][MAX_TOKEN_LEN] = { 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000}, 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000}, 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000}, 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000}, 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000}, 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000}, 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000}, 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testTargetCases[][MAX_TOKEN_LEN] = { 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000}, 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000}, 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000}, 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000}, 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000}, 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000}, 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UCollationResult results[] = { 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_GREATER, 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test primary > 5*/ 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_EQUAL, 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_EQUAL 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addSpanishCollTest(TestNode** root) 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestPrimary, "tscoll/cestst/TestPrimary"); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestTertiary, "tscoll/cestst/TestTertiary"); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestTertiary( ) 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation = ucol_open("es_ES", &status); 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 9285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status)); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing Spanish Collation with Tertiary strength\n"); 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(myCollation, UCOL_TERTIARY); 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < 5 ; i++) 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(myCollation); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestPrimary() 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation = ucol_open("es_ES", &status); 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 11185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status)); 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing Spanish Collation with Primary strength\n"); 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(myCollation, UCOL_PRIMARY); 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 5; i < 9; i++) 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(myCollation); 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 124