static void TestGetContainedRegions() { 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_GROUPING) { continue; } containedRegions = uregion_getContainedRegions(r, &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_getContainingRegion(cr) : NULL; if ( !containingRegion || !uregion_areEqual(containingRegion, r) ) { log_err("ERROR: Region: %s contains region %s. Expected containing region 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 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 TestGetContainingRegion() { 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); if (rd->parent == NULL) { if ( c ) { log_err("ERROR: Containing region for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) ); } } else { const URegion *p = uregion_getRegionFromCode(rd->parent, &status); if ( c == NULL || !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); } } }