Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: source/test/intltest/itercoll.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/intltest/intltest.vcxproj.filters ('k') | source/test/intltest/itformat.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2009, 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"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 /** 170 /**
171 * Test for getOffset() and setOffset() 171 * Test for getOffset() and setOffset()
172 */ 172 */
173 void CollationIteratorTest::TestOffset(/* char* par */) 173 void CollationIteratorTest::TestOffset(/* char* par */)
174 { 174 {
175 CollationElementIterator *iter = en_us->createCollationElementIterator(test1 ); 175 CollationElementIterator *iter = en_us->createCollationElementIterator(test1 );
176 UErrorCode status = U_ZERO_ERROR; 176 UErrorCode status = U_ZERO_ERROR;
177 // testing boundaries 177 // testing boundaries
178 iter->setOffset(0, status); 178 iter->setOffset(0, status);
179 if (U_FAILURE(status) || iter->previous(status) != UCOL_NULLORDER) { 179 if (U_FAILURE(status) || iter->previous(status) != CollationElementIterator: :NULLORDER) {
180 errln("Error: After setting offset to 0, we should be at the end " 180 errln("Error: After setting offset to 0, we should be at the end "
181 "of the backwards iteration"); 181 "of the backwards iteration");
182 } 182 }
183 iter->setOffset(test1.length(), status); 183 iter->setOffset(test1.length(), status);
184 if (U_FAILURE(status) || iter->next(status) != UCOL_NULLORDER) { 184 if (U_FAILURE(status) || iter->next(status) != CollationElementIterator::NUL LORDER) {
185 errln("Error: After setting offset to end of the string, we should " 185 errln("Error: After setting offset to end of the string, we should "
186 "be at the end of the backwards iteration"); 186 "be at the end of the backwards iteration");
187 } 187 }
188 188
189 // Run all the way through the iterator, then get the offset 189 // Run all the way through the iterator, then get the offset
190 int32_t orderLength = 0; 190 int32_t orderLength = 0;
191 Order *orders = getOrders(*iter, orderLength); 191 Order *orders = getOrders(*iter, orderLength);
192 192
193 int32_t offset = iter->getOffset(); 193 int32_t offset = iter->getOffset();
194 194
(...skipping 12 matching lines...) Expand all
207 207
208 if (U_FAILURE(status)) 208 if (U_FAILURE(status))
209 { 209 {
210 errln("setOffset failed."); 210 errln("setOffset failed.");
211 } 211 }
212 else 212 else
213 { 213 {
214 assertEqual(*iter, *pristine); 214 assertEqual(*iter, *pristine);
215 } 215 }
216 216
217 // TODO: try iterating halfway through a messy string.
218
219 delete pristine; 217 delete pristine;
220 delete[] orders; 218 delete[] orders;
221 delete iter; 219 delete iter;
220
221 // setting offset in the middle of a contraction
222 UnicodeString contraction = "change";
223 status = U_ZERO_ERROR;
224 RuleBasedCollator tailored("& a < ch", status);
225 if (U_FAILURE(status)) {
226 errln("Error: in creation of Spanish collator - %s", u_errorName(status) );
227 return;
228 }
229 iter = tailored.createCollationElementIterator(contraction);
230 Order *order = getOrders(*iter, orderLength);
231 iter->setOffset(1, status); // sets offset in the middle of ch
232 int32_t order2Length = 0;
233 Order *order2 = getOrders(*iter, order2Length);
234 if (orderLength != order2Length || uprv_memcmp(order, order2, orderLength * sizeof(Order)) != 0) {
235 errln("Error: setting offset in the middle of a contraction should be th e same as setting it to the start of the contraction");
236 }
237 delete[] order;
238 delete[] order2;
239 delete iter;
240 contraction = "peache";
241 iter = tailored.createCollationElementIterator(contraction);
242 iter->setOffset(3, status);
243 order = getOrders(*iter, orderLength);
244 iter->setOffset(4, status); // sets offset in the middle of ch
245 order2 = getOrders(*iter, order2Length);
246 if (orderLength != order2Length || uprv_memcmp(order, order2, orderLength * sizeof(Order)) != 0) {
247 errln("Error: setting offset in the middle of a contraction should be th e same as setting it to the start of the contraction");
248 }
249 delete[] order;
250 delete[] order2;
251 delete iter;
252 // setting offset in the middle of a surrogate pair
253 UnicodeString surrogate = UNICODE_STRING_SIMPLE("\\ud800\\udc00str").unescap e();
254 iter = tailored.createCollationElementIterator(surrogate);
255 order = getOrders(*iter, orderLength);
256 iter->setOffset(1, status); // sets offset in the middle of surrogate
257 order2 = getOrders(*iter, order2Length);
258 if (orderLength != order2Length || uprv_memcmp(order, order2, orderLength * sizeof(Order)) != 0) {
259 errln("Error: setting offset in the middle of a surrogate pair should be the same as setting it to the start of the surrogate pair");
260 }
261 delete[] order;
262 delete[] order2;
263 delete iter;
264 surrogate = UNICODE_STRING_SIMPLE("simple\\ud800\\udc00str").unescape();
265 iter = tailored.createCollationElementIterator(surrogate);
266 iter->setOffset(6, status);
267 order = getOrders(*iter, orderLength);
268 iter->setOffset(7, status); // sets offset in the middle of surrogate
269 order2 = getOrders(*iter, order2Length);
270 if (orderLength != order2Length || uprv_memcmp(order, order2, orderLength * sizeof(Order)) != 0) {
271 errln("Error: setting offset in the middle of a surrogate pair should be the same as setting it to the start of the surrogate pair");
272 }
273 delete[] order;
274 delete[] order2;
275 delete iter;
276 // TODO: try iterating halfway through a messy string.
222 } 277 }
223 278
224 /** 279 /**
225 * Test for setText() 280 * Test for setText()
226 */ 281 */
227 void CollationIteratorTest::TestSetText(/* char* par */) 282 void CollationIteratorTest::TestSetText(/* char* par */)
228 { 283 {
229 CollationElementIterator *iter1 = en_us->createCollationElementIterator(test 1); 284 CollationElementIterator *iter1 = en_us->createCollationElementIterator(test 1);
230 CollationElementIterator *iter2 = en_us->createCollationElementIterator(test 2); 285 CollationElementIterator *iter2 = en_us->createCollationElementIterator(test 2);
231 UErrorCode status = U_ZERO_ERROR; 286 UErrorCode status = U_ZERO_ERROR;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 322 }
268 else 323 else
269 { 324 {
270 assertEqual(*iter1, *iter2); 325 assertEqual(*iter1, *iter2);
271 } 326 }
272 327
273 // test for an empty string 328 // test for an empty string
274 UnicodeString empty(""); 329 UnicodeString empty("");
275 iter1->setText(empty, status); 330 iter1->setText(empty, status);
276 if (U_FAILURE(status) 331 if (U_FAILURE(status)
277 || iter1->next(status) != (int32_t)UCOL_NULLORDER) { 332 || iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
278 errln("Empty string should have no CEs."); 333 errln("Empty string should have no CEs.");
279 } 334 }
280 ((StringCharacterIterator *)chariter)->setText(empty); 335 ((StringCharacterIterator *)chariter)->setText(empty);
281 iter1->setText(*chariter, status); 336 iter1->setText(*chariter, status);
282 if (U_FAILURE(status) 337 if (U_FAILURE(status)
283 || iter1->next(status) != (int32_t)UCOL_NULLORDER) { 338 || iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
284 errln("Empty string should have no CEs."); 339 errln("Empty string should have no CEs.");
285 } 340 }
286 delete chariter; 341 delete chariter;
287 delete iter2; 342 delete iter2;
288 delete iter1; 343 delete iter1;
289 } 344 }
290 345
291 /** @bug 4108762 346 /** @bug 4108762
292 * Test for getMaxExpansion() 347 * Test for getMaxExpansion()
293 */ 348 */
(...skipping 13 matching lines...) Expand all
307 ch ++; 362 ch ++;
308 UnicodeString str(ch); 363 UnicodeString str(ch);
309 iter->setText(str, status); 364 iter->setText(str, status);
310 order = iter->previous(status); 365 order = iter->previous(status);
311 366
312 /* thai management */ 367 /* thai management */
313 if (CollationElementIterator::isIgnorable(order)) 368 if (CollationElementIterator::isIgnorable(order))
314 order = iter->previous(status); 369 order = iter->previous(status);
315 370
316 while (U_SUCCESS(status) 371 while (U_SUCCESS(status)
317 && iter->previous(status) != (int32_t)UCOL_NULLORDER) 372 && iter->previous(status) != (int32_t)CollationElementIterator::NULL ORDER)
318 { 373 {
319 count ++; 374 count ++;
320 } 375 }
321 376
322 if (U_FAILURE(status) && iter->getMaxExpansion(order) < count) { 377 if (U_FAILURE(status) && iter->getMaxExpansion(order) < count) {
323 errln("Failure at codepoint %d, maximum expansion count < %d\n", 378 errln("Failure at codepoint %d, maximum expansion count < %d\n",
324 ch, count); 379 ch, count);
325 } 380 }
326 } 381 }
327 382
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 569
515 // tests empty strings 570 // tests empty strings
516 UnicodeString empty(""); 571 UnicodeString empty("");
517 iter1 = coll->createCollationElementIterator(empty); 572 iter1 = coll->createCollationElementIterator(empty);
518 chariter.setText(empty); 573 chariter.setText(empty);
519 iter2 = coll->createCollationElementIterator(chariter); 574 iter2 = coll->createCollationElementIterator(chariter);
520 if (*iter1 != *iter1 || *iter2 != *iter2 || *iter1 != *iter2 575 if (*iter1 != *iter1 || *iter2 != *iter2 || *iter1 != *iter2
521 || *iter2 != *iter1) { 576 || *iter2 != *iter1) {
522 errln("CollationElementIterators constructed with the same string data s hould be the same at the start"); 577 errln("CollationElementIterators constructed with the same string data s hould be the same at the start");
523 } 578 }
524 if (iter1->next(status) != (int32_t)UCOL_NULLORDER) { 579 if (iter1->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
525 errln("Empty string should have no CEs."); 580 errln("Empty string should have no CEs.");
526 } 581 }
527 if (iter2->next(status) != (int32_t)UCOL_NULLORDER) { 582 if (iter2->next(status) != (int32_t)CollationElementIterator::NULLORDER) {
528 errln("Empty string should have no CEs."); 583 errln("Empty string should have no CEs.");
529 } 584 }
530 delete iter1; 585 delete iter1;
531 delete iter2; 586 delete iter2;
532 delete coll; 587 delete coll;
533 } 588 }
534 589
535 /** 590 /**
536 * Testing the strength order 591 * Testing the strength order
537 */ 592 */
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 case 8: name = "TestStrengthOrder"; if (exec) TestStrengthOrder(/* pa r */); break; 693 case 8: name = "TestStrengthOrder"; if (exec) TestStrengthOrder(/* pa r */); break;
639 default: name = ""; break; 694 default: name = ""; break;
640 } 695 }
641 } else { 696 } else {
642 dataerrln("Class iterator not instantiated"); 697 dataerrln("Class iterator not instantiated");
643 name = ""; 698 name = "";
644 } 699 }
645 } 700 }
646 701
647 #endif /* #if !UCONFIG_NO_COLLATION */ 702 #endif /* #if !UCONFIG_NO_COLLATION */
OLDNEW
« no previous file with comments | « source/test/intltest/intltest.vcxproj.filters ('k') | source/test/intltest/itformat.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698