1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 3fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius * Copyright (c) 1997-2014, International Business Machines Corporation and 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/coll.h" 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/tblcoll.h" 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/sortkey.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "g7coll.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "sfwdchit.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar testCases[][G7CollationTest::MAX_TOKEN_LEN] = { 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*'k'*/, 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0073 /*'s'*/, 0x0000}, /* 9 */ 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0050 /*'P'*/, 0x0061 /*'a'*/, 0x0074/*'t'*/, 0x0000}, /* 1 */ 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x00E9, 0x0000}, /* 2 */ 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x0000}, /* 3 */ 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x0072 /*'r'*/, 0x0000}, /* 4 */ 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x0072 /*'r'*/, 0x0000}, /* 5 */ 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0054 /*'T'*/, 0x006f /*'o'*/, 0x0064 /*'d'*/, 0x0000}, /* 6 */ 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0054 /*'T'*/, 0x00F6, 0x006e /*'n'*/, 0x0065 /*'e'*/, 0x0000}, /* 7 */ 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0054 /*'T'*/, 0x006f /*'o'*/, 0x0066 /*'f'*/, 0x0075 /*'u'*/, 0x0000}, /* 8 */ 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*'k'*/, 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0000}, /* 12 */ 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0054 /*'T'*/, 0x006f /*'o'*/, 0x006e /*'n'*/, 0x0000}, /* 10 */ 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0050 /*'P'*/, 0x0041 /*'A'*/, 0x0054 /*'T'*/, 0x0000}, /* 11 */ 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*'k'*/, 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002d /*'-'*/, 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0000}, /* 13 */ 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*'k'*/, 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x002d /*'-'*/, 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0073/*'s'*/, 0x0000}, /* 0 */ 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {0x0070 /*'p'*/, 0x0061 /*'a'*/, 0x0074 /*'t'*/, 0x0000}, /* 14 */ 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Additional tests */ 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x007a /*'z'*/, 0x0061 /*'a'*/, 0x0072 /*'r'*/, 0x0000 }, /* 15 */ 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0075 /*'u'*/, 0x0072 /*'r'*/, 0x006f /*'o'*/, 0x0000 }, /* 16 */ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x0061 /*'a'*/, 0x0074 /*'t'*/, 0x000 }, /* 17 */ 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0064 /*'d'*/, 0x0061 /*'a'*/, 0x0072 /*'r'*/, 0x006e /*'n'*/, 0x0000 }, /* 18 */ 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x003f /*'?'*/, 0x0000 }, /* 19 */ 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0071 /*'q'*/, 0x0075 /*'u'*/, 0x0069 /*'i'*/, 0x0063 /*'c'*/, 0x006b /*'k'*/, 0x0000 }, /* 20 */ 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0023 /*'#'*/, 0x0000 }, /* 21 */ 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0026 /*'&'*/, 0x0000 }, /* 22 */ 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0061 /*'a'*/, 0x002d /*'-'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0076 /*'v'*/, 0x0061 /*'a'*/, 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0072/*'r'*/, 0x006b/*'k'*/, 0x0000}, /* 24 */ 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0061 /*'a'*/, 0x0061 /*'a'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0076 /*'v'*/, 0x0061 /*'a'*/, 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x0072/*'r'*/, 0x006b/*'k'*/, 0x0000}, /* 23 */ 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0061 /*'a'*/, 0x0062 /*'b'*/, 0x0062 /*'b'*/, 0x006f /*'o'*/, 0x0074 /*'t'*/, 0x0000}, /* 25 */ 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x006f /*'o'*/, 0x002d /*'-'*/, 0x0070 /*'p'*/, 0x0000}, /* 27 */ 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x006f /*'o'*/, 0x0070 /*'p'*/, 0x0000}, /* 28 */ 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x0063 /*'c'*/, 0x006f /*'o'*/, 0x006f /*'o'*/, 0x0070 /*'p'*/, 0x0000}, /* 26 */ 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 0x007a /*'z'*/, 0x0065 /*'e'*/, 0x0062 /*'b'*/, 0x0072 /*'r'*/, 0x0061 /*'a'*/, 0x0000} /* 29 */ 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const int32_t results[G7CollationTest::TESTLOCALES][G7CollationTest::TOTALTESTSET] = { 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* en_US */ 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* en_GB */ 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* en_CA */ 6427f654740f2a26ad62a5c155af9199af9e69b889claireho { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* fr_FR */ 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 3, 2, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* fr_CA */ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* de_DE */ 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* it_IT */ 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 14, 1, 11, 2, 3, 4, 5, 6, 8, 10, 7, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, /* ja_JP */ 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* new table collation with rules "& Z < p, P" loop to FIXEDTESTSET */ 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 12, 13, 9, 0, 6, 8, 10, 7, 14, 1, 11, 2, 3, 4, 5, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* new table collation with rules "& C < ch , cH, Ch, CH " loop to TOTALTESTSET */ 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 19, 22, 21, 23, 24, 25, 12, 13, 9, 0, 17, 26, 28, 27, 15, 16, 18, 14, 1, 11, 2, 3, 4, 5, 20, 6, 8, 10, 7, 29 }, 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* new table collation with rules "& Question-mark ; ? & Hash-mark ; # & Ampersand ; '&' " loop to TOTALTESTSET */ 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 23, 24, 25, 22, 12, 13, 9, 0, 17, 16, 26, 28, 27, 15, 18, 21, 14, 1, 11, 2, 3, 4, 5, 19, 20, 6, 8, 10, 7, 29 }, 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* analogous to Japanese rules " & aa ; a- & ee ; e- & ii ; i- & oo ; o- & uu ; u- " */ /* loop to TOTALTESTSET */ 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 19, 22, 21, 24, 23, 25, 12, 13, 9, 0, 17, 16, 28, 26, 27, 15, 18, 14, 1, 11, 2, 3, 4, 5, 20, 6, 8, 10, 7, 29 } 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruG7CollationTest::~G7CollationTest() {} 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::TestG7Locales(/* char* par */) 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i; 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Locale locales[8] = { 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("en", "US", ""), 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("en", "GB", ""), 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("en", "CA", ""), 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("fr", "FR", ""), 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("fr", "CA", ""), 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("de", "DE", ""), 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("it", "IT", ""), 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Locale("ja", "JP", "") 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 95fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius for (i = 0; i < LENGTHOF(locales); i++) 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString dispName; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const Locale &locale = locales[i]; 101fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius LocalPointer<Collator> myCollation(Collator::createInstance(locale, status)); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 10385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 106fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius myCollation->setStrength(Collator::QUATERNARY); 107fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius myCollation->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); 108fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (U_FAILURE(status)) { 109fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius errln("Locale %s creation failed - %s", locale.getName(), u_errorName(status)); 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 113fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const UnicodeString &rules = ((RuleBasedCollator*)myCollation.getAlias())->getRules(); 114fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (rules.isEmpty() && 115fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius (locale == Locale::getCanadaFrench() || locale == Locale::getJapanese())) { 116fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius dataerrln("%s Collator missing rule string", locale.getName()); 117fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (logKnownIssue("10671", "TestG7Locales does not test ignore-punctuation")) { 118fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius continue; 119fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 120fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } else { 121fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius status = U_ZERO_ERROR; 122fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius RuleBasedCollator *tblColl1 = new RuleBasedCollator(rules, status); 123fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius if (U_FAILURE(status)) { 124fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius errln("Recreate %s collation failed - %s", locale.getName(), u_errorName(status)); 125fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius continue; 126fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 127fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius myCollation.adoptInstead(tblColl1); 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString msg; 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru msg += "Locale "; 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru msg += locales[i].getDisplayName(dispName); 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru msg += "tests start :"; 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln(msg); 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j, n; 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < FIXEDTESTSET; j++) 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (n = j+1; n < FIXEDTESTSET; n++) 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 142fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius doTest(myCollation.getAlias(), testCases[results[i][j]], testCases[results[i][n]], Collator::LESS); 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::TestDemo1(/* char* par */) 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\""); 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator *col = Collator::createInstance("en_US", status); 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 15585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newRules(" & Z < p, P"); 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newRules.insert(0, baseRules); 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln( "Demo Test 1 Table Collation object creation failed."); 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j, n; 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < FIXEDTESTSET; j++) 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (n = j+1; n < FIXEDTESTSET; n++) 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testCases[results[8][j]], testCases[results[8][n]], Collator::LESS); 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete myCollation; 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::TestDemo2(/* char* par */) 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Demo Test 2 : Create a new table collation with rules \"& C < ch , cH, Ch, CH\""); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator *col = Collator::createInstance("en_US", status); 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 18985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newRules("& C < ch , cH, Ch, CH"); 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newRules.insert(0, baseRules); 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("Demo Test 2 Table Collation object creation failed."); 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j, n; 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < TOTALTESTSET; j++) 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (n = j+1; n < TOTALTESTSET; n++) 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testCases[results[9][j]], testCases[results[9][n]], Collator::LESS); 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete myCollation; 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::TestDemo3(/* char* par */) 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\""); 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator *col = Collator::createInstance("en_US", status); 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 22285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"; 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newRules.insert(0, baseRules); 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru errln("Demo Test 3 Table Collation object creation failed."); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j, n; 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < TOTALTESTSET; j++) 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (n = j+1; n < TOTALTESTSET; n++) 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], Collator::LESS); 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete myCollation; 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::TestDemo4(/* char* par */) 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru logln("Demo Test 4 : Create a new table collation with rules \" & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' \""); 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Collator *col = Collator::createInstance("en_US", status); 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 25785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errcheckln(status, "Couldn't instantiate collator. Error: %s", u_errorName(status)); 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UnicodeString baseRules = ((RuleBasedCollator*)col)->getRules(); 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "; 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newRules.insert(0, baseRules); 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru RuleBasedCollator *myCollation = new RuleBasedCollator(newRules, status); 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t j, n; 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (j = 0; j < TOTALTESTSET; j++) 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (n = j+1; n < TOTALTESTSET; n++) 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doTest(myCollation, testCases[results[11][j]], testCases[results[11][n]], Collator::LESS); 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete myCollation; 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete col; 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid G7CollationTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite G7CollationTest: "); 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 28359d709d503bab6e2b61931737e662dd293b40578ccornelius case 0: name = "TestG7Locales"; if (exec) TestG7Locales(/* par */); break; 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 1: name = "TestDemo1"; if (exec) TestDemo1(/* par */); break; 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 2: name = "TestDemo2"; if (exec) TestDemo2(/* par */); break; 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 3: name = "TestDemo3"; if (exec) TestDemo3(/* par */); break; 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 4: name = "TestDemo4"; if (exec) TestDemo4(/* par */); break; 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: name = ""; break; 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 293