1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************** 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * File CFINTST.C 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Modification History: 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Name Description 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Madhu Katragadda Ported for C API 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************** 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * CollationFinnishTest 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 "ccolltst.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "callcoll.h" 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cfintst.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 {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x00FC, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000}, 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x004c/*'L'*/, 0x00E5, 0x0076/*'v'*/, 0x0069/*'i'*/, 0x0000}, 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000} 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UChar testTargetCases[][MAX_TOKEN_LEN] = { 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}, 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0079/*'y'*/, 0x0000}, 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0061/*'a'*/, 0x0078/*'x'*/, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000}, 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x004c/*'L'*/, 0x00E4, 0x0077/*'w'*/, 0x0065/*'e'*/, 0x0000}, 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000} 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst static UCollationResult results[] = { 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_GREATER, 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_GREATER, 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_LESS, 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test primary > 4*/ 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCOL_EQUAL 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addFinnishCollTest(TestNode** root) 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestPrimary, "tscoll/cficoll/TestPrimary"); 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestTertiary, "tscoll/cficoll/TestTertiary"); 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestTertiary( ) 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation = ucol_open("fi_FI@collation=standard", &status); 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 8385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing Finnish Collation with Tertiary strength\n"); 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(myCollation, UCOL_TERTIARY); 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < 4 ; i++) 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(myCollation); 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestPrimary() 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru myCollation = ucol_open("fi_FI@collation=standard", &status); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 10185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing Finnish Collation with Tertiary strength\n"); 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(myCollation, UCOL_PRIMARY); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 4; i < 5; i++) 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(myCollation); 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 113