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

Side by Side Diff: source/test/intltest/regiontst.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/regextst.cpp ('k') | source/test/intltest/reldatefmttest.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) 2013, International Business Machines Corporation 3 * Copyright (c) 2013-2014, International Business Machines Corporation
4 * and others. All Rights Reserved. 4 * and others. All Rights Reserved.
5 ***********************************************************************/ 5 ***********************************************************************/
6 6
7 /*********************************************************************** 7 /***********************************************************************
8 * This testcase ported from ICU4J ( RegionTest.java ) to ICU4C * 8 * This testcase ported from ICU4J ( RegionTest.java ) to ICU4C *
9 * Try to keep them in sync if at all possible...! * 9 * Try to keep them in sync if at all possible...! *
10 ***********************************************************************/ 10 ***********************************************************************/
11 11
12 #include "unicode/utypes.h" 12 #include "unicode/utypes.h"
13 #include "cstring.h" 13 #include "cstring.h"
14 14
15 #if !UCONFIG_NO_FORMATTING 15 #if !UCONFIG_NO_FORMATTING
16 16
17 #include "unicode/region.h" 17 #include "unicode/region.h"
18 #include "regiontst.h" 18 #include "regiontst.h"
19 19
20 typedef struct KnownRegion { 20 typedef struct KnownRegion {
21 const char *code; 21 const char *code;
22 int32_t numeric; 22 int32_t numeric;
23 const char *parent; 23 const char *parent;
24 URegionType type; 24 URegionType type;
25 const char *containingContinent; 25 const char *containingContinent;
26 } KnownRegion; 26 } KnownRegion;
27 27
28 #define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0]))
29
30 static KnownRegion knownRegions[] = { 28 static KnownRegion knownRegions[] = {
31 // Code, Num, Parent, Type, Containing Continent 29 // Code, Num, Parent, Type, Containing Continent
32 { "TP" , 626, "035", URGN_TERRITORY, "142" }, 30 { "TP" , 626, "035", URGN_TERRITORY, "142" },
33 { "001", 1, NULL , URGN_WORLD, NULL }, 31 { "001", 1, NULL , URGN_WORLD, NULL },
34 { "002", 2, "001", URGN_CONTINENT, NULL }, 32 { "002", 2, "001", URGN_CONTINENT, NULL },
35 { "003", 3, NULL, URGN_GROUPING, NULL }, 33 { "003", 3, NULL, URGN_GROUPING, NULL },
36 { "005", 5, "019", URGN_SUBCONTINENT, "019" }, 34 { "005", 5, "019", URGN_SUBCONTINENT, "019" },
37 { "009", 9, "001", URGN_CONTINENT, NULL}, 35 { "009", 9, "001", URGN_CONTINENT, NULL},
38 { "011", 11, "002", URGN_SUBCONTINENT, "002" }, 36 { "011", 11, "002", URGN_SUBCONTINENT, "002" },
39 { "013", 13, "019", URGN_SUBCONTINENT, "019" }, 37 { "013", 13, "019", URGN_SUBCONTINENT, "019" },
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 TESTCASE_AUTO(TestGetPreferredValues); 355 TESTCASE_AUTO(TestGetPreferredValues);
358 TESTCASE_AUTO(TestContains); 356 TESTCASE_AUTO(TestContains);
359 TESTCASE_AUTO(TestAvailableTerritories); 357 TESTCASE_AUTO(TestAvailableTerritories);
360 TESTCASE_AUTO(TestNoContainedRegions); 358 TESTCASE_AUTO(TestNoContainedRegions);
361 TESTCASE_AUTO_END; 359 TESTCASE_AUTO_END;
362 } 360 }
363 361
364 362
365 void RegionTest::TestKnownRegions() { 363 void RegionTest::TestKnownRegions() {
366 364
367 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 365 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
368 KnownRegion rd = knownRegions[i]; 366 KnownRegion rd = knownRegions[i];
369 UErrorCode status = U_ZERO_ERROR; 367 UErrorCode status = U_ZERO_ERROR;
370 const Region *r = Region::getInstance(rd.code,status); 368 const Region *r = Region::getInstance(rd.code,status);
371 if ( r ) { 369 if ( r ) {
372 int32_t n = r->getNumericCode(); 370 int32_t n = r->getNumericCode();
373 int32_t e = rd.numeric; 371 int32_t e = rd.numeric;
374 if ( n != e ) { 372 if ( n != e ) {
375 errln("Numeric code mismatch for region %s. Expected:%d Got:%d" ,r->getRegionCode(),e,n); 373 errln("Numeric code mismatch for region %s. Expected:%d Got:%d" ,r->getRegionCode(),e,n);
376 } 374 }
377 375
(...skipping 30 matching lines...) Expand all
408 { "278", "DE", URGN_TERRITORY }, // Numeric code for East Germany (Depre cated) 406 { "278", "DE", URGN_TERRITORY }, // Numeric code for East Germany (Depre cated)
409 { "SU", "SU", URGN_DEPRECATED }, // Alias to a deprecated region with mu ltiple preferred values 407 { "SU", "SU", URGN_DEPRECATED }, // Alias to a deprecated region with mu ltiple preferred values
410 { "AN", "AN", URGN_DEPRECATED }, // Deprecated region with multiple pref erred values 408 { "AN", "AN", URGN_DEPRECATED }, // Deprecated region with multiple pref erred values
411 { "SVK", "SK", URGN_TERRITORY } // 3-letter code - Slovakia 409 { "SVK", "SK", URGN_TERRITORY } // 3-letter code - Slovakia
412 }; 410 };
413 411
414 412
415 UErrorCode status = U_ZERO_ERROR; 413 UErrorCode status = U_ZERO_ERROR;
416 const Region *r = Region::getInstance((const char *)NULL,status); 414 const Region *r = Region::getInstance((const char *)NULL,status);
417 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) { 415 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
418 errln("Calling Region::getInstance(NULL) should have triggered an U_ILLE GAL_ARGUMENT_ERROR, but didn't."); 416 errcheckln(status, "Calling Region::getInstance(NULL) should have trigge red an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
419 } 417 }
420 418
421 status = U_ZERO_ERROR; 419 status = U_ZERO_ERROR;
422 r = Region::getInstance("BOGUS",status); 420 r = Region::getInstance("BOGUS",status);
423 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) { 421 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
424 errln("Calling Region::getInstance(\"BOGUS\") should have triggered an U _ILLEGAL_ARGUMENT_ERROR, but didn't."); 422 errcheckln(status, "Calling Region::getInstance(\"BOGUS\") should have t riggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
425 } 423 }
426 424
427 425
428 for (int32_t i = 0 ; i < LENGTHOF(testData) ; i++ ) { 426 for (int32_t i = 0 ; i < UPRV_LENGTHOF(testData) ; i++ ) {
429 TestData data = testData[i]; 427 TestData data = testData[i];
430 status = U_ZERO_ERROR; 428 status = U_ZERO_ERROR;
431 r = Region::getInstance(data.inputID,status); 429 r = Region::getInstance(data.inputID,status);
432 const char *id; 430 const char *id;
433 URegionType type; 431 URegionType type;
434 if ( r ) { 432 if ( r ) {
435 id = r->getRegionCode(); 433 id = r->getRegionCode();
436 type = r->getType(); 434 type = r->getType();
437 } else { 435 } else {
438 id = "NULL"; 436 id = "NULL";
(...skipping 20 matching lines...) Expand all
459 { 276, "DE", URGN_TERRITORY }, // Numeric code for Germany 457 { 276, "DE", URGN_TERRITORY }, // Numeric code for Germany
460 { 278, "DE", URGN_TERRITORY }, // Numeric code for East Germany (Deprec ated) 458 { 278, "DE", URGN_TERRITORY }, // Numeric code for East Germany (Deprec ated)
461 { 419, "419", URGN_GROUPING }, // Latin America 459 { 419, "419", URGN_GROUPING }, // Latin America
462 { 736, "SD", URGN_TERRITORY }, // Sudan (pre-2011) - changed numeric co de after South Sudan split off 460 { 736, "SD", URGN_TERRITORY }, // Sudan (pre-2011) - changed numeric co de after South Sudan split off
463 { 729, "SD", URGN_TERRITORY }, // Sudan (post-2011) - changed numeric c ode after South Sudan split off 461 { 729, "SD", URGN_TERRITORY }, // Sudan (post-2011) - changed numeric c ode after South Sudan split off
464 }; 462 };
465 463
466 UErrorCode status = U_ZERO_ERROR; 464 UErrorCode status = U_ZERO_ERROR;
467 Region::getInstance(-123,status); 465 Region::getInstance(-123,status);
468 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) { 466 if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
469 errln("Calling Region::getInstance(-123) should have triggered an U_ILLE GAL_ARGUMENT_ERROR, but didn't."); 467 errcheckln(status, "Calling Region::getInstance(-123) should have trigge red an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
470 } 468 }
471 469
472 for (int32_t i = 0 ; i < LENGTHOF(testData) ; i++ ) { 470 for (int32_t i = 0 ; i < UPRV_LENGTHOF(testData) ; i++ ) {
473 TestData data = testData[i]; 471 TestData data = testData[i];
474 status = U_ZERO_ERROR; 472 status = U_ZERO_ERROR;
475 const Region *r = Region::getInstance(data.inputID,status); 473 const Region *r = Region::getInstance(data.inputID,status);
476 const char *id; 474 const char *id;
477 URegionType type; 475 URegionType type;
478 if ( r ) { 476 if ( r ) {
479 id = r->getRegionCode(); 477 id = r->getRegionCode();
480 type = r->getType(); 478 type = r->getType();
481 } else { 479 } else {
482 id = "NULL"; 480 id = "NULL";
483 type = URGN_UNKNOWN; 481 type = URGN_UNKNOWN;
484 } 482 }
485 if ( uprv_strcmp(data.expectedID,id)) { 483 if ( uprv_strcmp(data.expectedID,id)) {
486 dataerrln("Unexpected region ID for Region.getInstance(%d)); Expecte d: %s Got: %s",data.inputID,data.expectedID,id); 484 dataerrln("Unexpected region ID for Region.getInstance(%d)); Expecte d: %s Got: %s",data.inputID,data.expectedID,id);
487 } 485 }
488 if ( data.expectedType != type) { 486 if ( data.expectedType != type) {
489 dataerrln("Unexpected region type for Region.getInstance(%d)); Expec ted: %d Got: %d",data.inputID,data.expectedType,type); 487 dataerrln("Unexpected region type for Region.getInstance(%d)); Expec ted: %d Got: %d",data.inputID,data.expectedType,type);
490 } 488 }
491 } 489 }
492 } 490 }
493 491
494 void RegionTest::TestGetContainedRegions() { 492 void RegionTest::TestGetContainedRegions() {
495 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 493 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
496 KnownRegion rd = knownRegions[i]; 494 KnownRegion rd = knownRegions[i];
497 UErrorCode status = U_ZERO_ERROR; 495 UErrorCode status = U_ZERO_ERROR;
498 496
499 const Region *r = Region::getInstance(rd.code,status); 497 const Region *r = Region::getInstance(rd.code,status);
500 if (r) { 498 if (r) {
501 if (r->getType() == URGN_GROUPING) { 499 if (r->getType() == URGN_GROUPING) {
502 continue; 500 continue;
503 } 501 }
504 StringEnumeration *containedRegions = r->getContainedRegions(); 502 StringEnumeration *containedRegions = r->getContainedRegions();
505 for ( int32_t i = 0 ; i < containedRegions->count(status); i++ ) { 503 for ( int32_t i = 0 ; i < containedRegions->count(status); i++ ) {
506 const char *crID = containedRegions->next(NULL,status); 504 const char *crID = containedRegions->next(NULL,status);
507 const Region *cr = Region::getInstance(crID,status); 505 const Region *cr = Region::getInstance(crID,status);
508 const Region *containingRegion = cr ? cr->getContainingRegion() : NULL; 506 const Region *containingRegion = cr ? cr->getContainingRegion() : NULL;
509 if ( !containingRegion || *containingRegion != *r ) { 507 if ( !containingRegion || *containingRegion != *r ) {
510 errln("Region: %s contains region %s. Expected containing re gion of this region to be the original region, but got %s", 508 errln("Region: %s contains region %s. Expected containing re gion of this region to be the original region, but got %s",
511 r->getRegionCode(),cr->getRegionCode(),containingRegion? containingRegion->getRegionCode():"NULL"); 509 r->getRegionCode(),cr->getRegionCode(),containingRegion? containingRegion->getRegionCode():"NULL");
512 } 510 }
513 } 511 }
514 delete containedRegions; 512 delete containedRegions;
515 } else { 513 } else {
516 dataerrln("Known region %s was not recognized.",rd.code); 514 dataerrln("Known region %s was not recognized.",rd.code);
517 } 515 }
518 } 516 }
519 } 517 }
520 518
521 void RegionTest::TestGetContainedRegionsWithType() { 519 void RegionTest::TestGetContainedRegionsWithType() {
522 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 520 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
523 KnownRegion rd = knownRegions[i]; 521 KnownRegion rd = knownRegions[i];
524 UErrorCode status = U_ZERO_ERROR; 522 UErrorCode status = U_ZERO_ERROR;
525 523
526 const Region *r = Region::getInstance(rd.code,status); 524 const Region *r = Region::getInstance(rd.code,status);
527 if (r) { 525 if (r) {
528 if (r->getType() != URGN_CONTINENT) { 526 if (r->getType() != URGN_CONTINENT) {
529 continue; 527 continue;
530 } 528 }
531 StringEnumeration *containedRegions = r->getContainedRegions(URGN_TE RRITORY); 529 StringEnumeration *containedRegions = r->getContainedRegions(URGN_TE RRITORY);
532 for ( int32_t j = 0 ; j < containedRegions->count(status); j++ ) { 530 for ( int32_t j = 0 ; j < containedRegions->count(status); j++ ) {
533 const char *crID = containedRegions->next(NULL,status); 531 const char *crID = containedRegions->next(NULL,status);
534 const Region *cr = Region::getInstance(crID,status); 532 const Region *cr = Region::getInstance(crID,status);
535 const Region *containingRegion = cr ? cr->getContainingRegion(UR GN_CONTINENT) : NULL; 533 const Region *containingRegion = cr ? cr->getContainingRegion(UR GN_CONTINENT) : NULL;
536 if ( !containingRegion || *containingRegion != *r ) { 534 if ( !containingRegion || *containingRegion != *r ) {
537 errln("Continent: %s contains territory %s. Expected contain ing continent of this region to be the original region, but got %s", 535 errln("Continent: %s contains territory %s. Expected contain ing continent of this region to be the original region, but got %s",
538 r->getRegionCode(),cr->getRegionCode(),containingRegion? containingRegion->getRegionCode():"NULL"); 536 r->getRegionCode(),cr->getRegionCode(),containingRegion? containingRegion->getRegionCode():"NULL");
539 } 537 }
540 } 538 }
541 delete containedRegions; 539 delete containedRegions;
542 } else { 540 } else {
543 dataerrln("Known region %s was not recognized.",rd.code); 541 dataerrln("Known region %s was not recognized.",rd.code);
544 } 542 }
545 } 543 }
546 } 544 }
547 545
548 void RegionTest::TestGetContainingRegion() { 546 void RegionTest::TestGetContainingRegion() {
549 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 547 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
550 KnownRegion rd = knownRegions[i]; 548 KnownRegion rd = knownRegions[i];
551 UErrorCode status = U_ZERO_ERROR; 549 UErrorCode status = U_ZERO_ERROR;
552 const Region *r = Region::getInstance(rd.code,status); 550 const Region *r = Region::getInstance(rd.code,status);
553 if (r) { 551 if (r) {
554 const Region *c = r->getContainingRegion(); 552 const Region *c = r->getContainingRegion();
555 if (rd.parent == NULL) { 553 if (rd.parent == NULL) {
556 if ( c ) { 554 if ( c ) {
557 errln("Containing region for %s should have been NULL. Got: %s",r->getRegionCode(),c->getRegionCode()); 555 errln("Containing region for %s should have been NULL. Got: %s",r->getRegionCode(),c->getRegionCode());
558 } 556 }
559 } else { 557 } else {
560 const Region *p = Region::getInstance(rd.parent,status); 558 const Region *p = Region::getInstance(rd.parent,status);
561 if ( !c || *p != *c ) { 559 if ( !c || *p != *c ) {
562 errln("Expected containing continent of region %s to be %s. Got: %s", 560 errln("Expected containing continent of region %s to be %s. Got: %s",
563 r->getRegionCode(),p?p->getRegionCode():"NULL",c?c->getR egionCode():"NULL" ); 561 r->getRegionCode(),p?p->getRegionCode():"NULL",c?c->getR egionCode():"NULL" );
564 } 562 }
565 } 563 }
566 } else { 564 } else {
567 dataerrln("Known region %s was not recognized.",rd.code); 565 dataerrln("Known region %s was not recognized.",rd.code);
568 } 566 }
569 } 567 }
570 } 568 }
571 569
572 void RegionTest::TestGetContainingRegionWithType() { 570 void RegionTest::TestGetContainingRegionWithType() {
573 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 571 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
574 KnownRegion rd = knownRegions[i]; 572 KnownRegion rd = knownRegions[i];
575 UErrorCode status = U_ZERO_ERROR; 573 UErrorCode status = U_ZERO_ERROR;
576 574
577 const Region *r = Region::getInstance(rd.code,status); 575 const Region *r = Region::getInstance(rd.code,status);
578 if (r) { 576 if (r) {
579 const Region *c = r->getContainingRegion(URGN_CONTINENT); 577 const Region *c = r->getContainingRegion(URGN_CONTINENT);
580 if (rd.containingContinent == NULL) { 578 if (rd.containingContinent == NULL) {
581 if ( c != NULL) { 579 if ( c != NULL) {
582 errln("Containing continent for %s should have been NULL. Got: %s",r->getRegionCode(), c->getRegionCode()); 580 errln("Containing continent for %s should have been NULL. Got: %s",r->getRegionCode(), c->getRegionCode());
583 } 581 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 623 }
626 } 624 }
627 delete preferredValues; 625 delete preferredValues;
628 } else { 626 } else {
629 dataerrln("Known region %s was not recognized.",data[0]); 627 dataerrln("Known region %s was not recognized.",data[0]);
630 } 628 }
631 } 629 }
632 } 630 }
633 631
634 void RegionTest::TestContains() { 632 void RegionTest::TestContains() {
635 for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) { 633 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
636 KnownRegion rd = knownRegions[i]; 634 KnownRegion rd = knownRegions[i];
637 UErrorCode status = U_ZERO_ERROR; 635 UErrorCode status = U_ZERO_ERROR;
638 636
639 const Region *r = Region::getInstance(rd.code,status); 637 const Region *r = Region::getInstance(rd.code,status);
640 if (r) { 638 if (r) {
641 const Region *c = r->getContainingRegion(); 639 const Region *c = r->getContainingRegion();
642 while ( c ) { 640 while ( c ) {
643 if ( !c->contains(*r)) { 641 if ( !c->contains(*r)) {
644 errln("Region \"%s\" should have contained \"%s\" but it did n't.",c->getRegionCode(),r->getRegionCode()); 642 errln("Region \"%s\" should have contained \"%s\" but it did n't.",c->getRegionCode(),r->getRegionCode());
645 } 643 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n" , emptyStr, u_errorName(status)); 703 errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n" , emptyStr, u_errorName(status));
706 } else { 704 } else {
707 logln("Success - BM has no subregions\n"); 705 logln("Success - BM has no subregions\n");
708 } 706 }
709 delete containedRegions; 707 delete containedRegions;
710 } 708 }
711 709
712 #endif /* #if !UCONFIG_NO_FORMATTING */ 710 #endif /* #if !UCONFIG_NO_FORMATTING */
713 711
714 //eof 712 //eof
OLDNEW
« no previous file with comments | « source/test/intltest/regextst.cpp ('k') | source/test/intltest/reldatefmttest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698