| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2010, International Business Machines Corporation and | 3 * Copyright (c) 1997-2014, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 | 6 |
| 7 #include "unicode/utypes.h" | 7 #include "unicode/utypes.h" |
| 8 | 8 |
| 9 #if !UCONFIG_NO_COLLATION | 9 #if !UCONFIG_NO_COLLATION |
| 10 | 10 |
| 11 #include "unicode/coll.h" | 11 #include "unicode/coll.h" |
| 12 #include "unicode/tblcoll.h" | 12 #include "unicode/tblcoll.h" |
| 13 #include "unicode/unistr.h" | 13 #include "unicode/unistr.h" |
| 14 #include "unicode/sortkey.h" | 14 #include "unicode/sortkey.h" |
| 15 #include "g7coll.h" | 15 #include "g7coll.h" |
| 16 #include "sfwdchit.h" | 16 #include "sfwdchit.h" |
| 17 | 17 #include "cmemory.h" |
| 18 | 18 |
| 19 static const UChar testCases[][G7CollationTest::MAX_TOKEN_LEN] = { | 19 static const UChar testCases[][G7CollationTest::MAX_TOKEN_LEN] = { |
| 20 { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*
'k'*/, | 20 { 0x0062 /*'b'*/, 0x006c /*'l'*/, 0x0061 /*'a'*/, 0x0062 /*'c'*/, 0x006b /*
'k'*/, |
| 21 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0073 /
*'s'*/, 0x0000}, /* 9 */ | 21 0x0062 /*'b'*/, 0x0069 /*'i'*/, 0x0072 /*'r'*/, 0x0064 /*'d'*/, 0x0073 /
*'s'*/, 0x0000}, /* 9 */ |
| 22 { 0x0050 /*'P'*/, 0x0061 /*'a'*/, 0x0074/*'t'*/, 0x0000},
/* 1 */ | 22 { 0x0050 /*'P'*/, 0x0061 /*'a'*/, 0x0074/*'t'*/, 0x0000},
/* 1 */ |
| 23 { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x00E9, 0x0000},
/* 2 */ | 23 { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x00E9, 0x0000},
/* 2 */ |
| 24 { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0000}, /* 3 */ | 24 { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0000}, /* 3 */ |
| 25 { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0072 /*'r'*/, 0x0000}, /* 4 */ | 25 { 0x0070 /*'p'*/, 0x00E9, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0072 /*'r'*/, 0x0000}, /* 4 */ |
| 26 { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0072 /*'r'*/, 0x0000}, /* 5 */ | 26 { 0x0070 /*'p'*/, 0x00EA, 0x0063 /*'c'*/, 0x0068 /*'h'*/, 0x0065 /*'e'*/, 0x
0072 /*'r'*/, 0x0000}, /* 5 */ |
| 27 { 0x0054 /*'T'*/, 0x006f /*'o'*/, 0x0064 /*'d'*/, 0x0000},
/* 6 */ | 27 { 0x0054 /*'T'*/, 0x006f /*'o'*/, 0x0064 /*'d'*/, 0x0000},
/* 6 */ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Locale("en", "US", ""), | 84 Locale("en", "US", ""), |
| 85 Locale("en", "GB", ""), | 85 Locale("en", "GB", ""), |
| 86 Locale("en", "CA", ""), | 86 Locale("en", "CA", ""), |
| 87 Locale("fr", "FR", ""), | 87 Locale("fr", "FR", ""), |
| 88 Locale("fr", "CA", ""), | 88 Locale("fr", "CA", ""), |
| 89 Locale("de", "DE", ""), | 89 Locale("de", "DE", ""), |
| 90 Locale("it", "IT", ""), | 90 Locale("it", "IT", ""), |
| 91 Locale("ja", "JP", "") | 91 Locale("ja", "JP", "") |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 | 94 for (i = 0; i < UPRV_LENGTHOF(locales); i++) |
| 95 for (i = 0; i < 8; i++) | |
| 96 { | 95 { |
| 97 Collator *myCollation= 0; | |
| 98 UnicodeString dispName; | 96 UnicodeString dispName; |
| 99 UErrorCode status = U_ZERO_ERROR; | 97 UErrorCode status = U_ZERO_ERROR; |
| 100 RuleBasedCollator* tblColl1 = 0; | |
| 101 | 98 |
| 102 myCollation = Collator::createInstance(locales[i], status); | 99 const Locale &locale = locales[i]; |
| 100 LocalPointer<Collator> myCollation(Collator::createInstance(locale, stat
us)); |
| 103 if(U_FAILURE(status)) { | 101 if(U_FAILURE(status)) { |
| 104 delete myCollation; | |
| 105 errcheckln(status, "Couldn't instantiate collator. Error: %s", u_error
Name(status)); | 102 errcheckln(status, "Couldn't instantiate collator. Error: %s", u_error
Name(status)); |
| 106 return; | 103 return; |
| 107 } | 104 } |
| 108 myCollation->setStrength(Collator::QUATERNARY); | 105 myCollation->setStrength(Collator::QUATERNARY); |
| 109 myCollation->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status)
; | 106 myCollation->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status)
; |
| 110 if (U_FAILURE(status)) | 107 if (U_FAILURE(status)) { |
| 111 { | 108 errln("Locale %s creation failed - %s", locale.getName(), u_errorNam
e(status)); |
| 112 UnicodeString msg; | |
| 113 | |
| 114 msg += "Locale "; | |
| 115 msg += locales[i].getDisplayName(dispName); | |
| 116 msg += "creation failed."; | |
| 117 | |
| 118 errln(msg); | |
| 119 continue; | 109 continue; |
| 120 } | 110 } |
| 121 | 111 |
| 122 // const UnicodeString& defRules = ((RuleBasedCollator*)myCollation)->get
Rules(); | 112 const UnicodeString &rules = ((RuleBasedCollator*)myCollation.getAlias()
)->getRules(); |
| 123 status = U_ZERO_ERROR; | 113 if (rules.isEmpty() && |
| 124 tblColl1 = new RuleBasedCollator(((RuleBasedCollator*)myCollation)->getR
ules(), status); | 114 (locale == Locale::getCanadaFrench() || locale == Locale::getJap
anese())) { |
| 125 if (U_FAILURE(status)) | 115 dataerrln("%s Collator missing rule string", locale.getName()); |
| 126 { | 116 if (logKnownIssue("10671", "TestG7Locales does not test ignore-punct
uation")) { |
| 127 UnicodeString msg, name; | 117 continue; |
| 128 | 118 } |
| 129 msg += "Recreate "; | 119 } else { |
| 130 msg += locales[i].getDisplayName(name); | 120 status = U_ZERO_ERROR; |
| 131 msg += "collation failed."; | 121 RuleBasedCollator *tblColl1 = new RuleBasedCollator(rules, status); |
| 132 | 122 if (U_FAILURE(status)) { |
| 133 errln(msg); | 123 errln("Recreate %s collation failed - %s", locale.getName(), u_e
rrorName(status)); |
| 134 continue; | 124 continue; |
| 125 } |
| 126 myCollation.adoptInstead(tblColl1); |
| 135 } | 127 } |
| 136 | 128 |
| 137 UnicodeString msg; | 129 UnicodeString msg; |
| 138 | 130 |
| 139 msg += "Locale "; | 131 msg += "Locale "; |
| 140 msg += locales[i].getDisplayName(dispName); | 132 msg += locales[i].getDisplayName(dispName); |
| 141 msg += "tests start :"; | 133 msg += "tests start :"; |
| 142 logln(msg); | 134 logln(msg); |
| 143 | 135 |
| 144 int32_t j, n; | 136 int32_t j, n; |
| 145 for (j = 0; j < FIXEDTESTSET; j++) | 137 for (j = 0; j < FIXEDTESTSET; j++) |
| 146 { | 138 { |
| 147 for (n = j+1; n < FIXEDTESTSET; n++) | 139 for (n = j+1; n < FIXEDTESTSET; n++) |
| 148 { | 140 { |
| 149 doTest(tblColl1, testCases[results[i][j]], testCases[results[i][
n]], Collator::LESS); | 141 doTest(myCollation.getAlias(), testCases[results[i][j]], testCas
es[results[i][n]], Collator::LESS); |
| 150 } | 142 } |
| 151 } | 143 } |
| 152 | |
| 153 delete myCollation; | |
| 154 delete tblColl1; | |
| 155 } | 144 } |
| 156 } | 145 } |
| 157 | 146 |
| 158 void G7CollationTest::TestDemo1(/* char* par */) | 147 void G7CollationTest::TestDemo1(/* char* par */) |
| 159 { | 148 { |
| 160 logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\""
); | 149 logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\""
); |
| 161 UErrorCode status = U_ZERO_ERROR; | 150 UErrorCode status = U_ZERO_ERROR; |
| 162 Collator *col = Collator::createInstance("en_US", status); | 151 Collator *col = Collator::createInstance("en_US", status); |
| 163 if(U_FAILURE(status)) { | 152 if(U_FAILURE(status)) { |
| 164 delete col; | 153 delete col; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 case 0: name = "TestG7Locales"; if (exec) TestG7Locales(/* par */); br
eak; | 282 case 0: name = "TestG7Locales"; if (exec) TestG7Locales(/* par */); br
eak; |
| 294 case 1: name = "TestDemo1"; if (exec) TestDemo1(/* par */); break; | 283 case 1: name = "TestDemo1"; if (exec) TestDemo1(/* par */); break; |
| 295 case 2: name = "TestDemo2"; if (exec) TestDemo2(/* par */); break; | 284 case 2: name = "TestDemo2"; if (exec) TestDemo2(/* par */); break; |
| 296 case 3: name = "TestDemo3"; if (exec) TestDemo3(/* par */); break; | 285 case 3: name = "TestDemo3"; if (exec) TestDemo3(/* par */); break; |
| 297 case 4: name = "TestDemo4"; if (exec) TestDemo4(/* par */); break; | 286 case 4: name = "TestDemo4"; if (exec) TestDemo4(/* par */); break; |
| 298 default: name = ""; break; | 287 default: name = ""; break; |
| 299 } | 288 } |
| 300 } | 289 } |
| 301 | 290 |
| 302 #endif /* #if !UCONFIG_NO_COLLATION */ | 291 #endif /* #if !UCONFIG_NO_COLLATION */ |
| OLD | NEW |