OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 2013-2014, International Business Machines Corporation | 3 * Copyright (c) 2013-2015, 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" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 void RegionTest::TestGetContainedRegions() { | 492 void RegionTest::TestGetContainedRegions() { |
493 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) { | 493 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) { |
494 KnownRegion rd = knownRegions[i]; | 494 KnownRegion rd = knownRegions[i]; |
495 UErrorCode status = U_ZERO_ERROR; | 495 UErrorCode status = U_ZERO_ERROR; |
496 | 496 |
497 const Region *r = Region::getInstance(rd.code,status); | 497 const Region *r = Region::getInstance(rd.code,status); |
498 if (r) { | 498 if (r) { |
499 if (r->getType() == URGN_GROUPING) { | 499 if (r->getType() == URGN_GROUPING) { |
500 continue; | 500 continue; |
501 } | 501 } |
502 StringEnumeration *containedRegions = r->getContainedRegions(); | 502 StringEnumeration *containedRegions = r->getContainedRegions(status)
; |
| 503 if (U_FAILURE(status)) { |
| 504 errln("%s->getContainedRegions(status) failed: %s", r->getRegionCo
de(), u_errorName(status)); |
| 505 continue; |
| 506 } |
503 for ( int32_t i = 0 ; i < containedRegions->count(status); i++ ) { | 507 for ( int32_t i = 0 ; i < containedRegions->count(status); i++ ) { |
504 const char *crID = containedRegions->next(NULL,status); | 508 const char *crID = containedRegions->next(NULL,status); |
505 const Region *cr = Region::getInstance(crID,status); | 509 const Region *cr = Region::getInstance(crID,status); |
506 const Region *containingRegion = cr ? cr->getContainingRegion()
: NULL; | 510 const Region *containingRegion = cr ? cr->getContainingRegion()
: NULL; |
507 if ( !containingRegion || *containingRegion != *r ) { | 511 if ( !containingRegion || *containingRegion != *r ) { |
508 errln("Region: %s contains region %s. Expected containing re
gion of this region to be the original region, but got %s", | 512 errln("Region: %s contains region %s. Expected containing re
gion of this region to be the original region, but got %s", |
509 r->getRegionCode(),cr->getRegionCode(),containingRegion?
containingRegion->getRegionCode():"NULL"); | 513 r->getRegionCode(),cr->getRegionCode(),containingRegion?
containingRegion->getRegionCode():"NULL"); |
510 } | 514 } |
511 } | 515 } |
512 delete containedRegions; | 516 delete containedRegions; |
513 } else { | 517 } else { |
514 dataerrln("Known region %s was not recognized.",rd.code); | 518 dataerrln("Known region %s was not recognized.",rd.code); |
515 } | 519 } |
516 } | 520 } |
517 } | 521 } |
518 | 522 |
519 void RegionTest::TestGetContainedRegionsWithType() { | 523 void RegionTest::TestGetContainedRegionsWithType() { |
520 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) { | 524 for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) { |
521 KnownRegion rd = knownRegions[i]; | 525 KnownRegion rd = knownRegions[i]; |
522 UErrorCode status = U_ZERO_ERROR; | 526 UErrorCode status = U_ZERO_ERROR; |
523 | 527 |
524 const Region *r = Region::getInstance(rd.code,status); | 528 const Region *r = Region::getInstance(rd.code,status); |
525 if (r) { | 529 if (r) { |
526 if (r->getType() != URGN_CONTINENT) { | 530 if (r->getType() != URGN_CONTINENT) { |
527 continue; | 531 continue; |
528 } | 532 } |
529 StringEnumeration *containedRegions = r->getContainedRegions(URGN_TE
RRITORY); | 533 StringEnumeration *containedRegions = r->getContainedRegions(URGN_TE
RRITORY, status); |
| 534 if (U_FAILURE(status)) { |
| 535 errln("%s->getContainedRegions(URGN_TERRITORY, status) failed: %s"
, r->getRegionCode(), u_errorName(status)); |
| 536 continue; |
| 537 } |
530 for ( int32_t j = 0 ; j < containedRegions->count(status); j++ ) { | 538 for ( int32_t j = 0 ; j < containedRegions->count(status); j++ ) { |
531 const char *crID = containedRegions->next(NULL,status); | 539 const char *crID = containedRegions->next(NULL,status); |
532 const Region *cr = Region::getInstance(crID,status); | 540 const Region *cr = Region::getInstance(crID,status); |
533 const Region *containingRegion = cr ? cr->getContainingRegion(UR
GN_CONTINENT) : NULL; | 541 const Region *containingRegion = cr ? cr->getContainingRegion(UR
GN_CONTINENT) : NULL; |
534 if ( !containingRegion || *containingRegion != *r ) { | 542 if ( !containingRegion || *containingRegion != *r ) { |
535 errln("Continent: %s contains territory %s. Expected contain
ing continent of this region to be the original region, but got %s", | 543 errln("Continent: %s contains territory %s. Expected contain
ing continent of this region to be the original region, but got %s", |
536 r->getRegionCode(),cr->getRegionCode(),containingRegion?
containingRegion->getRegionCode():"NULL"); | 544 r->getRegionCode(),cr->getRegionCode(),containingRegion?
containingRegion->getRegionCode():"NULL"); |
537 } | 545 } |
538 } | 546 } |
539 delete containedRegions; | 547 delete containedRegions; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 { "NT", "IQ", "SA", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL }, // Neutral Zone | 609 { "NT", "IQ", "SA", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL }, // Neutral Zone |
602 { "PC", "FM", "MH", "MP", "PW", NULL, NULL, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL, }, // Pacific Islands Trust Territory | 610 { "PC", "FM", "MH", "MP", "PW", NULL, NULL, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL, }, // Pacific Islands Trust Territory |
603 { "SU", "RU", "AM", "AZ", "BY", "EE", "GE", "KZ", "KG", "LV", "LT", "MD"
, "TJ", "TM", "UA", "UZ" , NULL}, // Soviet Union | 611 { "SU", "RU", "AM", "AZ", "BY", "EE", "GE", "KZ", "KG", "LV", "LT", "MD"
, "TJ", "TM", "UA", "UZ" , NULL}, // Soviet Union |
604 }; | 612 }; |
605 | 613 |
606 for ( int32_t i = 0 ; i < 6 ; i++ ) { | 614 for ( int32_t i = 0 ; i < 6 ; i++ ) { |
607 const char **data = testData[i]; | 615 const char **data = testData[i]; |
608 UErrorCode status = U_ZERO_ERROR; | 616 UErrorCode status = U_ZERO_ERROR; |
609 const Region *r = Region::getInstance(data[0],status); | 617 const Region *r = Region::getInstance(data[0],status); |
610 if (r) { | 618 if (r) { |
611 StringEnumeration *preferredValues = r->getPreferredValues(); | 619 StringEnumeration *preferredValues = r->getPreferredValues(status); |
| 620 if (U_FAILURE(status)) { |
| 621 errln("%s->getPreferredValues(status) failed: %s", r->getRegionCod
e(), u_errorName(status)); |
| 622 continue; |
| 623 } |
612 for ( int i = 1 ; data[i] ; i++ ) { | 624 for ( int i = 1 ; data[i] ; i++ ) { |
613 UBool found = FALSE; | 625 UBool found = FALSE; |
614 preferredValues->reset(status); | 626 preferredValues->reset(status); |
615 while ( const char *check = preferredValues->next(NULL,status) )
{ | 627 while ( const char *check = preferredValues->next(NULL,status) )
{ |
616 if ( !uprv_strcmp(check,data[i]) ) { | 628 if ( !uprv_strcmp(check,data[i]) ) { |
617 found = TRUE; | 629 found = TRUE; |
618 break; | 630 break; |
619 } | 631 } |
620 } | 632 } |
621 if ( !found ) { | 633 if ( !found ) { |
(...skipping 24 matching lines...) Expand all Loading... |
646 } else { | 658 } else { |
647 dataerrln("Known region %s was not recognized.",rd.code); | 659 dataerrln("Known region %s was not recognized.",rd.code); |
648 } | 660 } |
649 } | 661 } |
650 } | 662 } |
651 | 663 |
652 void RegionTest::TestAvailableTerritories() { | 664 void RegionTest::TestAvailableTerritories() { |
653 // Test to make sure that the set of territories contained in World and the
set of all available | 665 // Test to make sure that the set of territories contained in World and the
set of all available |
654 // territories are one and the same. | 666 // territories are one and the same. |
655 UErrorCode status = U_ZERO_ERROR; | 667 UErrorCode status = U_ZERO_ERROR; |
656 StringEnumeration *availableTerritories = Region::getAvailable(URGN_TERRITOR
Y); | 668 StringEnumeration *availableTerritories = Region::getAvailable(URGN_TERRITOR
Y, status); |
| 669 if (U_FAILURE(status)) { |
| 670 dataerrln("Region::getAvailable(URGN_TERRITORY,status) failed: %s", u_er
rorName(status)); |
| 671 return; |
| 672 } |
657 const Region *world = Region::getInstance("001",status); | 673 const Region *world = Region::getInstance("001",status); |
658 if (U_FAILURE(status)) { | 674 if (U_FAILURE(status)) { |
659 dataerrln("Region::getInstance(\"001\",status) failed: %s", u_errorName(
status)); | 675 dataerrln("Region::getInstance(\"001\",status) failed: %s", u_errorName(
status)); |
660 return; | 676 return; |
661 } | 677 } |
662 StringEnumeration *containedInWorld = world->getContainedRegions(URGN_TERRIT
ORY); | 678 StringEnumeration *containedInWorld = world->getContainedRegions(URGN_TERRIT
ORY, status); |
| 679 if (U_FAILURE(status)) { |
| 680 errln("world->getContainedRegions(URGN_TERRITORY, status) failed: %s", u
_errorName(status)); |
| 681 return; |
| 682 } |
663 if ( !availableTerritories || !containedInWorld || *availableTerritories !=
*containedInWorld ) { | 683 if ( !availableTerritories || !containedInWorld || *availableTerritories !=
*containedInWorld ) { |
664 char availableTerritoriesString[1024] = ""; | 684 char availableTerritoriesString[1024] = ""; |
665 char containedInWorldString[1024] = ""; | 685 char containedInWorldString[1024] = ""; |
666 if ( availableTerritories ) { | 686 if ( availableTerritories ) { |
667 for (int32_t i = 0 ; i < availableTerritories->count(status) ; i++ )
{ | 687 for (int32_t i = 0 ; i < availableTerritories->count(status) ; i++ )
{ |
668 if ( i > 0 ) { | 688 if ( i > 0 ) { |
669 uprv_strcat(availableTerritoriesString," "); | 689 uprv_strcat(availableTerritoriesString," "); |
670 } | 690 } |
671 uprv_strcat(availableTerritoriesString,availableTerritories->nex
t(NULL,status)); | 691 uprv_strcat(availableTerritoriesString,availableTerritories->nex
t(NULL,status)); |
672 } | 692 } |
(...skipping 17 matching lines...) Expand all Loading... |
690 delete containedInWorld; | 710 delete containedInWorld; |
691 } | 711 } |
692 | 712 |
693 void RegionTest::TestNoContainedRegions(void) { | 713 void RegionTest::TestNoContainedRegions(void) { |
694 UErrorCode status = U_ZERO_ERROR; | 714 UErrorCode status = U_ZERO_ERROR; |
695 const Region *region = Region::getInstance("BM",status); | 715 const Region *region = Region::getInstance("BM",status); |
696 if (U_FAILURE(status) || region == NULL) { | 716 if (U_FAILURE(status) || region == NULL) { |
697 dataerrln("Fail called to Region::getInstance(\"BM\", status) - %s", u_err
orName(status)); | 717 dataerrln("Fail called to Region::getInstance(\"BM\", status) - %s", u_err
orName(status)); |
698 return; | 718 return; |
699 } | 719 } |
700 StringEnumeration *containedRegions = region->getContainedRegions(); | 720 StringEnumeration *containedRegions = region->getContainedRegions(status); |
| 721 if (U_FAILURE(status)) { |
| 722 errln("%s->getContainedRegions(status) failed: %s", region->getRegionCode(
), u_errorName(status)); |
| 723 return; |
| 724 } |
701 const char *emptyStr = containedRegions->next(NULL, status); | 725 const char *emptyStr = containedRegions->next(NULL, status); |
702 if (U_FAILURE(status)||(emptyStr!=NULL)) { | 726 if (U_FAILURE(status)||(emptyStr!=NULL)) { |
703 errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n"
, emptyStr, u_errorName(status)); | 727 errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n"
, emptyStr, u_errorName(status)); |
704 } else { | 728 } else { |
705 logln("Success - BM has no subregions\n"); | 729 logln("Success - BM has no subregions\n"); |
706 } | 730 } |
707 delete containedRegions; | 731 delete containedRegions; |
708 } | 732 } |
709 | 733 |
710 #endif /* #if !UCONFIG_NO_FORMATTING */ | 734 #endif /* #if !UCONFIG_NO_FORMATTING */ |
711 | 735 |
712 //eof | 736 //eof |
OLD | NEW |