+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 2013, International Business Machines Corporation
+ * Copyright (c) 2013-2016, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
const char *containingContinent;
} KnownRegion;
-#define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0]))
-
static KnownRegion knownRegions[] = {
// Code, Num, Parent, Type, Containing Continent
{ "TP" , 626, "035", URGN_TERRITORY, "142" },
{ "BS" , 44, "029", URGN_TERRITORY, "019" },
{ "BT" , 64, "034", URGN_TERRITORY, "142" },
{ "BU" , 104, "035", URGN_TERRITORY, "142" },
- { "BV" , 74, "QO" , URGN_TERRITORY, "009" },
+ { "BV" , 74, "005", URGN_TERRITORY, "019" },
{ "BW" , 72, "018", URGN_TERRITORY, "002" },
{ "BY" , 112, "151", URGN_TERRITORY, "150" },
{ "BZ" , 84, "013", URGN_TERRITORY, "019" },
{ "CA" , 124, "021", URGN_TERRITORY, "019" },
- { "CC" , 166, "QO" , URGN_TERRITORY, "009" },
+ { "CC" , 166, "053", URGN_TERRITORY, "009" },
{ "CD" , 180, "017", URGN_TERRITORY, "002" },
{ "CF" , 140, "017", URGN_TERRITORY, "002" },
{ "CG" , 178, "017", URGN_TERRITORY, "002" },
{ "CU" , 192, "029", URGN_TERRITORY, "019" },
{ "CV" , 132, "011", URGN_TERRITORY, "002" },
{ "CW" , 531, "029", URGN_TERRITORY, "019" },
- { "CX" , 162, "QO" , URGN_TERRITORY, "009" },
+ { "CX" , 162, "053", URGN_TERRITORY, "009" },
{ "CY" , 196, "145", URGN_TERRITORY, "142" },
{ "CZ" , 203, "151", URGN_TERRITORY, "150" },
{ "DD" , 276, "155", URGN_TERRITORY, "150" },
{ "GP" , 312, "029", URGN_TERRITORY, "019" },
{ "GQ" , 226, "017", URGN_TERRITORY, "002" },
{ "GR" , 300, "039", URGN_TERRITORY, "150" },
- { "GS" , 239, "QO" , URGN_TERRITORY, "009" },
+ { "GS" , 239, "005", URGN_TERRITORY, "019" },
{ "GT" , 320, "013", URGN_TERRITORY, "019" },
{ "GU" , 316, "057", URGN_TERRITORY, "009" },
{ "GW" , 624, "011", URGN_TERRITORY, "002" },
{ "GY" , 328, "005", URGN_TERRITORY, "019" },
{ "HK" , 344, "030", URGN_TERRITORY, "142" },
- { "HM" , 334, "QO" , URGN_TERRITORY, "009" },
+ { "HM" , 334, "053", URGN_TERRITORY, "009" },
{ "HN" , 340, "013", URGN_TERRITORY, "019" },
{ "HR" , 191, "039", URGN_TERRITORY, "150" },
{ "HT" , 332, "029", URGN_TERRITORY, "019" },
{ "IL" , 376, "145", URGN_TERRITORY, "142" },
{ "IM" , 833, "154", URGN_TERRITORY, "150" },
{ "IN" , 356, "034", URGN_TERRITORY, "142" },
- { "IO" , 86, "QO" , URGN_TERRITORY, "009" },
+ { "IO" , 86, "014", URGN_TERRITORY, "002" },
{ "IQ" , 368, "145", URGN_TERRITORY, "142" },
{ "IR" , 364, "034", URGN_TERRITORY, "142" },
{ "IS" , 352, "154", URGN_TERRITORY, "150" },
{ "SN" , 686, "011", URGN_TERRITORY, "002" },
{ "SO" , 706, "014", URGN_TERRITORY, "002" },
{ "SR" , 740, "005", URGN_TERRITORY, "019" },
- { "SS" , 728, "015", URGN_TERRITORY, "002" },
+ { "SS" , 728, "014", URGN_TERRITORY, "002" },
{ "ST" , 678, "017", URGN_TERRITORY, "002" },
{ "SU" , 810, NULL , URGN_DEPRECATED , NULL},
{ "SV" , 222, "013", URGN_TERRITORY, "019" },
{ "TA" , -1, "QO", URGN_TERRITORY, "009" },
{ "TC" , 796, "029", URGN_TERRITORY, "019" },
{ "TD" , 148, "017", URGN_TERRITORY, "002" },
- { "TF" , 260, "QO" , URGN_TERRITORY, "009" },
+ { "TF" , 260, "145", URGN_TERRITORY, "142" },
{ "TG" , 768, "011", URGN_TERRITORY, "002" },
{ "TH" , 764, "035", URGN_TERRITORY, "142" },
{ "TJ" , 762, "143", URGN_TERRITORY, "142" },
{ "TZ" , 834, "014", URGN_TERRITORY, "002" },
{ "UA" , 804, "151", URGN_TERRITORY, "150" },
{ "UG" , 800, "014", URGN_TERRITORY, "002" },
- { "UM" , 581, "QO" , URGN_TERRITORY, "009" },
+ { "UM" , 581, "057", URGN_TERRITORY, "009" },
{ "US" , 840, "021", URGN_TERRITORY, "019" },
{ "UY" , 858, "005", URGN_TERRITORY, "019" },
{ "UZ" , 860, "143", URGN_TERRITORY, "142" },
void RegionTest::TestKnownRegions() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
const Region *r = Region::getInstance(rd.code,status);
UErrorCode status = U_ZERO_ERROR;
const Region *r = Region::getInstance((const char *)NULL,status);
if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
- errln("Calling Region::getInstance(NULL) should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't.");
+ errcheckln(status, "Calling Region::getInstance(NULL) should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
}
status = U_ZERO_ERROR;
r = Region::getInstance("BOGUS",status);
if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
- errln("Calling Region::getInstance(\"BOGUS\") should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't.");
+ errcheckln(status, "Calling Region::getInstance(\"BOGUS\") should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
}
- for (int32_t i = 0 ; i < LENGTHOF(testData) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(testData) ; i++ ) {
TestData data = testData[i];
status = U_ZERO_ERROR;
r = Region::getInstance(data.inputID,status);
UErrorCode status = U_ZERO_ERROR;
Region::getInstance(-123,status);
if ( status != U_ILLEGAL_ARGUMENT_ERROR ) {
- errln("Calling Region::getInstance(-123) should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't.");
+ errcheckln(status, "Calling Region::getInstance(-123) should have triggered an U_ILLEGAL_ARGUMENT_ERROR, but didn't. - %s", u_errorName(status));
}
- for (int32_t i = 0 ; i < LENGTHOF(testData) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(testData) ; i++ ) {
TestData data = testData[i];
status = U_ZERO_ERROR;
const Region *r = Region::getInstance(data.inputID,status);
}
void RegionTest::TestGetContainedRegions() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
if (r->getType() == URGN_GROUPING) {
continue;
}
- StringEnumeration *containedRegions = r->getContainedRegions();
+ StringEnumeration *containedRegions = r->getContainedRegions(status);
+ if (U_FAILURE(status)) {
+ errln("%s->getContainedRegions(status) failed: %s", r->getRegionCode(), u_errorName(status));
+ continue;
+ }
for ( int32_t i = 0 ; i < containedRegions->count(status); i++ ) {
const char *crID = containedRegions->next(NULL,status);
const Region *cr = Region::getInstance(crID,status);
}
void RegionTest::TestGetContainedRegionsWithType() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
if (r->getType() != URGN_CONTINENT) {
continue;
}
- StringEnumeration *containedRegions = r->getContainedRegions(URGN_TERRITORY);
+ StringEnumeration *containedRegions = r->getContainedRegions(URGN_TERRITORY, status);
+ if (U_FAILURE(status)) {
+ errln("%s->getContainedRegions(URGN_TERRITORY, status) failed: %s", r->getRegionCode(), u_errorName(status));
+ continue;
+ }
for ( int32_t j = 0 ; j < containedRegions->count(status); j++ ) {
const char *crID = containedRegions->next(NULL,status);
const Region *cr = Region::getInstance(crID,status);
}
void RegionTest::TestGetContainingRegion() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
const Region *r = Region::getInstance(rd.code,status);
}
void RegionTest::TestGetContainingRegionWithType() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
UErrorCode status = U_ZERO_ERROR;
const Region *r = Region::getInstance(data[0],status);
if (r) {
- StringEnumeration *preferredValues = r->getPreferredValues();
+ StringEnumeration *preferredValues = r->getPreferredValues(status);
+ if (U_FAILURE(status)) {
+ errln("%s->getPreferredValues(status) failed: %s", r->getRegionCode(), u_errorName(status));
+ continue;
+ }
for ( int i = 1 ; data[i] ; i++ ) {
UBool found = FALSE;
preferredValues->reset(status);
}
void RegionTest::TestContains() {
- for (int32_t i = 0 ; i < LENGTHOF(knownRegions) ; i++ ) {
+ for (int32_t i = 0 ; i < UPRV_LENGTHOF(knownRegions) ; i++ ) {
KnownRegion rd = knownRegions[i];
UErrorCode status = U_ZERO_ERROR;
// Test to make sure that the set of territories contained in World and the set of all available
// territories are one and the same.
UErrorCode status = U_ZERO_ERROR;
- StringEnumeration *availableTerritories = Region::getAvailable(URGN_TERRITORY);
+ StringEnumeration *availableTerritories = Region::getAvailable(URGN_TERRITORY, status);
+ if (U_FAILURE(status)) {
+ dataerrln("Region::getAvailable(URGN_TERRITORY,status) failed: %s", u_errorName(status));
+ return;
+ }
const Region *world = Region::getInstance("001",status);
if (U_FAILURE(status)) {
dataerrln("Region::getInstance(\"001\",status) failed: %s", u_errorName(status));
return;
}
- StringEnumeration *containedInWorld = world->getContainedRegions(URGN_TERRITORY);
+ StringEnumeration *containedInWorld = world->getContainedRegions(URGN_TERRITORY, status);
+ if (U_FAILURE(status)) {
+ errln("world->getContainedRegions(URGN_TERRITORY, status) failed: %s", u_errorName(status));
+ return;
+ }
if ( !availableTerritories || !containedInWorld || *availableTerritories != *containedInWorld ) {
char availableTerritoriesString[1024] = "";
char containedInWorldString[1024] = "";
dataerrln("Fail called to Region::getInstance(\"BM\", status) - %s", u_errorName(status));
return;
}
- StringEnumeration *containedRegions = region->getContainedRegions();
+ StringEnumeration *containedRegions = region->getContainedRegions(status);
+ if (U_FAILURE(status)) {
+ errln("%s->getContainedRegions(status) failed: %s", region->getRegionCode(), u_errorName(status));
+ return;
+ }
const char *emptyStr = containedRegions->next(NULL, status);
if (U_FAILURE(status)||(emptyStr!=NULL)) {
errln("Error, 'BM' should have no subregions, but returned str=%p, err=%s\n", emptyStr, u_errorName(status));