static void TestGetContainedRegionsWithType() {
    const KnownRegion * rd;
    for (rd = knownRegions; rd->code != NULL ; rd++ ) {
        UErrorCode status = U_ZERO_ERROR;
        const URegion *r = uregion_getRegionFromCode(rd->code, &status);
        if ( U_SUCCESS(status) ) {
            UEnumeration *containedRegions;
            const char *crID;
            if (uregion_getType(r) != URGN_CONTINENT) {
                continue;
            }
            containedRegions = uregion_getContainedRegionsOfType(r, URGN_TERRITORY, &status);
            if (containedRegions) {
                while ((crID = uenum_next(containedRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) {
                    const URegion *cr = uregion_getRegionFromCode(crID, &status);
                    const URegion *containingRegion = (cr)? uregion_getContainingRegionOfType(cr, URGN_CONTINENT) : NULL;
                    if ( !containingRegion || !uregion_areEqual(containingRegion, r) ) {
                        log_err("ERROR: Continent: %s contains territory %s. Expected containing continent of this region to be the original region, but got %s\n",
                            uregion_getRegionCode(r), uregion_getRegionCode(cr), (containingRegion)?uregion_getRegionCode(containingRegion):"NULL" ); 
                    }
                }
                uenum_close(containedRegions);
            }
        } else {
            log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
        }
    }
}
static void TestKnownRegions() {
    const KnownRegion * rd;
    for (rd = knownRegions; rd->code != NULL ; rd++ ) {
        UErrorCode status = U_ZERO_ERROR;
        const URegion *r = uregion_getRegionFromCode(rd->code, &status);
        if ( U_SUCCESS(status) ) {
            int32_t n = uregion_getNumericCode(r);
            int32_t e = rd->numeric;
            if ( n != e ) {
                log_err("ERROR: Numeric code mismatch for region %s.  Expected:%d Got:%d\n", uregion_getRegionCode(r), e, n );
            }
            if (uregion_getType(r) != rd->type) {
                log_err("ERROR: Expected region %s to be of type %d. Got: %d\n", uregion_getRegionCode(r), rd->type, uregion_getType(r) );
            }
            if ( e > 0 ) {
                const URegion *ncRegion = uregion_getRegionFromNumericCode(e, &status);
                if ( !uregion_areEqual(ncRegion, r) && e != 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891
                    log_err("ERROR: Creating region %s by its numeric code returned a different region. Got: %s instead.\n",
                        uregion_getRegionCode(r), uregion_getRegionCode(ncRegion) );
                }
             }
        } else {
            log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
        }
    }
}
static void TestGetContainingRegionWithType() {        
    const KnownRegion * rd;
    for (rd = knownRegions; rd->code != NULL ; rd++ ) {
        UErrorCode status = U_ZERO_ERROR;
        const URegion *r = uregion_getRegionFromCode(rd->code, &status);
        if ( U_SUCCESS(status) ) {
            const URegion *c = uregion_getContainingRegionOfType(r, URGN_CONTINENT);
            if (rd->containingContinent == NULL) {
                 if ( c != NULL) {
                     log_err("ERROR: Containing continent for %s should have been NULL.  Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) );
                 }
            } else {
                const URegion *p = uregion_getRegionFromCode(rd->containingContinent, &status);                   
                if ( !uregion_areEqual(p, c) ) {
                    log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n",
                        uregion_getRegionCode(r), (p)?uregion_getRegionCode(p):"NULL", (c)?uregion_getRegionCode(c):"NULL" );
                }
            }
        } else {
            log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
        }
    }
}
static void TestContains() {
    const KnownRegion * rd;
    for (rd = knownRegions; rd->code != NULL ; rd++ ) {
        UErrorCode status = U_ZERO_ERROR;
        const URegion *r = uregion_getRegionFromCode(rd->code, &status);
        if ( U_SUCCESS(status) ) {
            const URegion *c = uregion_getContainingRegion(r);
            while (c != NULL) {
                if ( !uregion_contains(c, r) ) {
                    log_err("ERROR: Region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(c), uregion_getRegionCode(r) );
                }
                c = uregion_getContainingRegion(c);
            }
        } else {
            log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
        }
    }
}
static void TestGetPreferredValues() {
    const char *** testDataPtr = expectPrefRegionsTestData;
    const char ** regionListPtr;
    while ( (regionListPtr = *testDataPtr++) != NULL ) {
        UErrorCode status = U_ZERO_ERROR;
        const char * deprecatedCode = *regionListPtr++;
        const URegion *r = uregion_getRegionFromCode(deprecatedCode, &status);
        if ( U_SUCCESS(status) ) {
            UEnumeration *preferredRegions = uregion_getPreferredValues(r, &status);
            if ( U_SUCCESS(status) ) {
                if (preferredRegions != NULL) {
                    const char * preferredCode;
                    while ( (preferredCode = *regionListPtr++) != NULL ) {
                        const char *check;
                        UBool found = FALSE;
                        uenum_reset(preferredRegions, &status);
                        while ((check = uenum_next(preferredRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) {
                            if ( !uprv_strcmp(check,preferredCode) ) {
                                found = TRUE;
                                break;
                            }
                        }
                        if ( !found ) {
                            log_err("ERROR: uregion_getPreferredValues for region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(r), preferredCode);
                        }
                    }
                    uenum_close(preferredRegions);
                }
            } else {
                log_err("ERROR: uregion_getPreferredValues failed for region %s.\n", uregion_getRegionCode(r));
            }
        } else {
            log_data_err("ERROR: Known region %s was not recognized.\n", deprecatedCode);
        }
    }
}