From 63f29c621c3c0f0300ae3876e02794acaeecf831 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Fri, 30 Aug 2024 19:47:22 -0700 Subject: [PATCH] ICU-22854 Add consistency test against Region API --- icu4c/source/test/intltest/regiontst.cpp | 21 ++++++++++++++++- .../com/ibm/icu/dev/test/util/RegionTest.java | 23 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/icu4c/source/test/intltest/regiontst.cpp b/icu4c/source/test/intltest/regiontst.cpp index d72903b0051..cdbeac793a7 100644 --- a/icu4c/source/test/intltest/regiontst.cpp +++ b/icu4c/source/test/intltest/regiontst.cpp @@ -837,7 +837,26 @@ void RegionTest::TestGetRegionForSupplementalDataMatch(void) { printf("0x%08x, ", data[i]); } printf("\n};\n"); - errln("ulocimp_getRegionForSupplementalData() differs from supplementalData"); + errln("ulocimp_getRegionForSupplementalData() inconsistent with supplementalData"); + } + + // Ensure consistency with Region API. + MutableRegionValidateMap prefab2; + char code[3] = "AA"; + for (code[0] ='A' ; code[0] <= 'Z'; code[0]++) { + for (code[1] ='A' ; code[1] <= 'Z'; code[1]++) { + status = U_ZERO_ERROR; + const Region *r = Region::getInstance(code, status); + // The Region code successfully created by Region::getInstance with + // type URGN_TERRITORY. Notice the r->getRegionCode() may not be the + // same as the same as the one calling getInstance. + if (U_SUCCESS(status) && (r != nullptr) && r->getType() == URGN_TERRITORY ) { + prefab2.add(r->getRegionCode()); + } + } + } + if (!prefab2.equals(builtin)) { + errln("ulocimp_getRegionForSupplementalData() inconsistent with Region::getInstance"); } } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java index 709497f2626..579b9d9fc58 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/RegionTest.java @@ -670,7 +670,28 @@ public class RegionTest extends CoreTestFmwk { System.out.printf("0x%08x, ", data[i]); } System.out.println("\n};"); - errln("Error !!!!"); + errln("ULocale.RegionValidateMap.BUILTIN inconsistent with supplementalData)"); + } + MutableRegionValidateMap prefab2 = new MutableRegionValidateMap(); + char[] code = new char[2]; + for (code[0] = 'A'; code[0] <= 'Z'; code[0]++) { + for (code[1] = 'A'; code[1] <= 'Z'; code[1]++) { + String str = new String(code); + try { + Region r = Region.getInstance(str); + // The Region code successfully created by Region.getInstance with + // type URGN_TERRITORY. Notice the r.toString() may not be the + // same as the same as the one passing into getInstance. + if (r.getType() == Region.RegionType.TERRITORY) { + prefab2.add(r.toString()); + } + } catch (Exception e) { + // noop + } + } + } + if (!ULocale.RegionValidateMap.BUILTIN.equals(prefab2)) { + errln("ULocale.RegionValidateMap.BUILTIN inconsistent with Region.getInstance()"); } } }