12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 32e5b6d6dSopenharmony_ci/******************************************************************** 42e5b6d6dSopenharmony_ci * Copyright (c) 2014-2016, International Business Machines Corporation 52e5b6d6dSopenharmony_ci * and others. All Rights Reserved. 62e5b6d6dSopenharmony_ci ********************************************************************/ 72e5b6d6dSopenharmony_ci/* C API TEST FOR UREGION */ 82e5b6d6dSopenharmony_ci/*********************************************************************** 92e5b6d6dSopenharmony_ci * Test cases ported from ICU4J ( RegionTest.java ) 102e5b6d6dSopenharmony_ci * to C++ (regiontst.cpp) to here. 112e5b6d6dSopenharmony_ci * Try to keep them in sync if at all possible...! 122e5b6d6dSopenharmony_ci ***********************************************************************/ 132e5b6d6dSopenharmony_ci 142e5b6d6dSopenharmony_ci#include "unicode/utypes.h" 152e5b6d6dSopenharmony_ci 162e5b6d6dSopenharmony_ci#if !UCONFIG_NO_FORMATTING 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci#include <stdbool.h> 192e5b6d6dSopenharmony_ci 202e5b6d6dSopenharmony_ci#include "unicode/ustring.h" 212e5b6d6dSopenharmony_ci#include "unicode/uregion.h" 222e5b6d6dSopenharmony_ci#include "unicode/uenum.h" 232e5b6d6dSopenharmony_ci#include "cintltst.h" 242e5b6d6dSopenharmony_ci#include "cmemory.h" 252e5b6d6dSopenharmony_ci#include "cstring.h" 262e5b6d6dSopenharmony_ci 272e5b6d6dSopenharmony_cistatic void TestKnownRegions(void); 282e5b6d6dSopenharmony_cistatic void TestGetContainedRegions(void); 292e5b6d6dSopenharmony_cistatic void TestGroupingChildren(void); 302e5b6d6dSopenharmony_cistatic void TestGetContainedRegionsWithType(void); 312e5b6d6dSopenharmony_cistatic void TestGetContainingRegion(void); 322e5b6d6dSopenharmony_cistatic void TestGetContainingRegionWithType(void); 332e5b6d6dSopenharmony_cistatic void TestGetPreferredValues(void); 342e5b6d6dSopenharmony_cistatic void TestContains(void); 352e5b6d6dSopenharmony_ci 362e5b6d6dSopenharmony_civoid addURegionTest(TestNode** root); 372e5b6d6dSopenharmony_ci 382e5b6d6dSopenharmony_ci#define TESTCASE(x) addTest(root, &x, "tsformat/uregiontest/" #x) 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_civoid addURegionTest(TestNode** root) 412e5b6d6dSopenharmony_ci{ 422e5b6d6dSopenharmony_ci TESTCASE(TestKnownRegions); 432e5b6d6dSopenharmony_ci TESTCASE(TestGetContainedRegions); 442e5b6d6dSopenharmony_ci TESTCASE(TestGroupingChildren); 452e5b6d6dSopenharmony_ci TESTCASE(TestGetContainedRegionsWithType); 462e5b6d6dSopenharmony_ci TESTCASE(TestGetContainingRegion); 472e5b6d6dSopenharmony_ci TESTCASE(TestGetContainingRegionWithType); 482e5b6d6dSopenharmony_ci TESTCASE(TestGetPreferredValues); 492e5b6d6dSopenharmony_ci TESTCASE(TestContains); 502e5b6d6dSopenharmony_ci} 512e5b6d6dSopenharmony_ci 522e5b6d6dSopenharmony_citypedef struct KnownRegion { 532e5b6d6dSopenharmony_ci const char *code; 542e5b6d6dSopenharmony_ci int32_t numeric; 552e5b6d6dSopenharmony_ci const char *parent; 562e5b6d6dSopenharmony_ci URegionType type; 572e5b6d6dSopenharmony_ci const char *containingContinent; 582e5b6d6dSopenharmony_ci} KnownRegion; 592e5b6d6dSopenharmony_ci 602e5b6d6dSopenharmony_cistatic KnownRegion knownRegions[] = { 612e5b6d6dSopenharmony_ci // Code, Num, Parent, Type, Containing Continent 622e5b6d6dSopenharmony_ci { "TP" , 626, "035", URGN_TERRITORY, "142" }, 632e5b6d6dSopenharmony_ci { "001", 1, NULL , URGN_WORLD, NULL }, 642e5b6d6dSopenharmony_ci { "002", 2, "001", URGN_CONTINENT, NULL }, 652e5b6d6dSopenharmony_ci { "003", 3, NULL, URGN_GROUPING, NULL }, 662e5b6d6dSopenharmony_ci { "005", 5, "019", URGN_SUBCONTINENT, "019" }, 672e5b6d6dSopenharmony_ci { "009", 9, "001", URGN_CONTINENT, NULL}, 682e5b6d6dSopenharmony_ci { "011", 11, "002", URGN_SUBCONTINENT, "002" }, 692e5b6d6dSopenharmony_ci { "013", 13, "019", URGN_SUBCONTINENT, "019" }, 702e5b6d6dSopenharmony_ci { "014", 14, "002", URGN_SUBCONTINENT, "002" }, 712e5b6d6dSopenharmony_ci { "015", 15, "002", URGN_SUBCONTINENT, "002" }, 722e5b6d6dSopenharmony_ci { "017", 17, "002", URGN_SUBCONTINENT, "002" }, 732e5b6d6dSopenharmony_ci { "018", 18, "002", URGN_SUBCONTINENT, "002" }, 742e5b6d6dSopenharmony_ci { "019", 19, "001", URGN_CONTINENT, NULL }, 752e5b6d6dSopenharmony_ci { "021", 21, "019", URGN_SUBCONTINENT, "019" }, 762e5b6d6dSopenharmony_ci { "029", 29, "019", URGN_SUBCONTINENT, "019" }, 772e5b6d6dSopenharmony_ci { "030", 30, "142", URGN_SUBCONTINENT, "142" }, 782e5b6d6dSopenharmony_ci { "034", 34, "142", URGN_SUBCONTINENT, "142" }, 792e5b6d6dSopenharmony_ci { "035", 35, "142", URGN_SUBCONTINENT, "142" }, 802e5b6d6dSopenharmony_ci { "039", 39, "150", URGN_SUBCONTINENT, "150"}, 812e5b6d6dSopenharmony_ci { "053", 53, "009", URGN_SUBCONTINENT, "009" }, 822e5b6d6dSopenharmony_ci { "054", 54, "009", URGN_SUBCONTINENT, "009" }, 832e5b6d6dSopenharmony_ci { "057", 57, "009", URGN_SUBCONTINENT, "009" }, 842e5b6d6dSopenharmony_ci { "061", 61, "009", URGN_SUBCONTINENT, "009" }, 852e5b6d6dSopenharmony_ci { "142", 142, "001", URGN_CONTINENT, NULL }, 862e5b6d6dSopenharmony_ci { "143", 143, "142", URGN_SUBCONTINENT, "142" }, 872e5b6d6dSopenharmony_ci { "145", 145, "142", URGN_SUBCONTINENT, "142" }, 882e5b6d6dSopenharmony_ci { "150", 150, "001", URGN_CONTINENT, NULL }, 892e5b6d6dSopenharmony_ci { "151", 151, "150", URGN_SUBCONTINENT, "150" }, 902e5b6d6dSopenharmony_ci { "154", 154, "150", URGN_SUBCONTINENT, "150" }, 912e5b6d6dSopenharmony_ci { "155", 155, "150", URGN_SUBCONTINENT, "150" }, 922e5b6d6dSopenharmony_ci { "419", 419, NULL, URGN_GROUPING , NULL}, 932e5b6d6dSopenharmony_ci { "AC" , -1, "QO" , URGN_TERRITORY, "009" }, 942e5b6d6dSopenharmony_ci { "AD" , 20, "039", URGN_TERRITORY, "150" }, 952e5b6d6dSopenharmony_ci { "AE" , 784, "145", URGN_TERRITORY, "142" }, 962e5b6d6dSopenharmony_ci { "AF" , 4, "034", URGN_TERRITORY, "142" }, 972e5b6d6dSopenharmony_ci { "AG" , 28, "029", URGN_TERRITORY, "019" }, 982e5b6d6dSopenharmony_ci { "AI" , 660, "029", URGN_TERRITORY, "019" }, 992e5b6d6dSopenharmony_ci { "AL" , 8, "039", URGN_TERRITORY, "150" }, 1002e5b6d6dSopenharmony_ci { "AM" , 51, "145", URGN_TERRITORY, "142" }, 1012e5b6d6dSopenharmony_ci { "AN" , 530, NULL, URGN_DEPRECATED, NULL }, 1022e5b6d6dSopenharmony_ci { "AO" , 24, "017", URGN_TERRITORY, "002" }, 1032e5b6d6dSopenharmony_ci { "AQ" , 10, "QO" , URGN_TERRITORY, "009" }, 1042e5b6d6dSopenharmony_ci { "AR" , 32, "005", URGN_TERRITORY, "019" }, 1052e5b6d6dSopenharmony_ci { "AS" , 16, "061", URGN_TERRITORY, "009" }, 1062e5b6d6dSopenharmony_ci { "AT" , 40, "155", URGN_TERRITORY, "150" }, 1072e5b6d6dSopenharmony_ci { "AU" , 36, "053", URGN_TERRITORY, "009" }, 1082e5b6d6dSopenharmony_ci { "AW" , 533, "029", URGN_TERRITORY, "019" }, 1092e5b6d6dSopenharmony_ci { "AX" , 248, "154", URGN_TERRITORY, "150" }, 1102e5b6d6dSopenharmony_ci { "AZ" , 31, "145", URGN_TERRITORY, "142" }, 1112e5b6d6dSopenharmony_ci { "BA" , 70, "039", URGN_TERRITORY, "150" }, 1122e5b6d6dSopenharmony_ci { "BB" , 52, "029", URGN_TERRITORY, "019" }, 1132e5b6d6dSopenharmony_ci { "BD" , 50, "034", URGN_TERRITORY, "142" }, 1142e5b6d6dSopenharmony_ci { "BE" , 56, "155", URGN_TERRITORY, "150" }, 1152e5b6d6dSopenharmony_ci { "BF" , 854, "011", URGN_TERRITORY, "002" }, 1162e5b6d6dSopenharmony_ci { "BG" , 100, "151", URGN_TERRITORY, "150" }, 1172e5b6d6dSopenharmony_ci { "BH" , 48, "145", URGN_TERRITORY, "142" }, 1182e5b6d6dSopenharmony_ci { "BI" , 108, "014", URGN_TERRITORY, "002" }, 1192e5b6d6dSopenharmony_ci { "BJ" , 204, "011", URGN_TERRITORY, "002" }, 1202e5b6d6dSopenharmony_ci { "BL" , 652, "029", URGN_TERRITORY, "019" }, 1212e5b6d6dSopenharmony_ci { "BM" , 60, "021", URGN_TERRITORY, "019" }, 1222e5b6d6dSopenharmony_ci { "BN" , 96, "035", URGN_TERRITORY, "142" }, 1232e5b6d6dSopenharmony_ci { "BO" , 68, "005", URGN_TERRITORY, "019" }, 1242e5b6d6dSopenharmony_ci { "BQ" , 535, "029", URGN_TERRITORY, "019" }, 1252e5b6d6dSopenharmony_ci { "BR" , 76, "005", URGN_TERRITORY, "019" }, 1262e5b6d6dSopenharmony_ci { "BS" , 44, "029", URGN_TERRITORY, "019" }, 1272e5b6d6dSopenharmony_ci { "BT" , 64, "034", URGN_TERRITORY, "142" }, 1282e5b6d6dSopenharmony_ci { "BU" , 104, "035", URGN_TERRITORY, "142" }, 1292e5b6d6dSopenharmony_ci { "BV" , 74, "005", URGN_TERRITORY, "019" }, 1302e5b6d6dSopenharmony_ci { "BW" , 72, "018", URGN_TERRITORY, "002" }, 1312e5b6d6dSopenharmony_ci { "BY" , 112, "151", URGN_TERRITORY, "150" }, 1322e5b6d6dSopenharmony_ci { "BZ" , 84, "013", URGN_TERRITORY, "019" }, 1332e5b6d6dSopenharmony_ci { "CA" , 124, "021", URGN_TERRITORY, "019" }, 1342e5b6d6dSopenharmony_ci { "CC" , 166, "053", URGN_TERRITORY, "009" }, 1352e5b6d6dSopenharmony_ci { "CD" , 180, "017", URGN_TERRITORY, "002" }, 1362e5b6d6dSopenharmony_ci { "CF" , 140, "017", URGN_TERRITORY, "002" }, 1372e5b6d6dSopenharmony_ci { "CG" , 178, "017", URGN_TERRITORY, "002" }, 1382e5b6d6dSopenharmony_ci { "CH" , 756, "155", URGN_TERRITORY, "150" }, 1392e5b6d6dSopenharmony_ci { "CI" , 384, "011", URGN_TERRITORY, "002" }, 1402e5b6d6dSopenharmony_ci { "CK" , 184, "061", URGN_TERRITORY, "009" }, 1412e5b6d6dSopenharmony_ci { "CL" , 152, "005", URGN_TERRITORY, "019" }, 1422e5b6d6dSopenharmony_ci { "CM" , 120, "017", URGN_TERRITORY, "002" }, 1432e5b6d6dSopenharmony_ci { "CN" , 156, "030", URGN_TERRITORY, "142" }, 1442e5b6d6dSopenharmony_ci { "CO" , 170, "005", URGN_TERRITORY, "019" }, 1452e5b6d6dSopenharmony_ci { "CP" , -1 , "QO" , URGN_TERRITORY, "009" }, 1462e5b6d6dSopenharmony_ci { "CR" , 188, "013", URGN_TERRITORY, "019" }, 1472e5b6d6dSopenharmony_ci { "CU" , 192, "029", URGN_TERRITORY, "019" }, 1482e5b6d6dSopenharmony_ci { "CV" , 132, "011", URGN_TERRITORY, "002" }, 1492e5b6d6dSopenharmony_ci { "CW" , 531, "029", URGN_TERRITORY, "019" }, 1502e5b6d6dSopenharmony_ci { "CX" , 162, "053", URGN_TERRITORY, "009" }, 1512e5b6d6dSopenharmony_ci { "CY" , 196, "145", URGN_TERRITORY, "142" }, 1522e5b6d6dSopenharmony_ci { "CZ" , 203, "151", URGN_TERRITORY, "150" }, 1532e5b6d6dSopenharmony_ci { "DD" , 276, "155", URGN_TERRITORY, "150" }, 1542e5b6d6dSopenharmony_ci { "DE" , 276, "155", URGN_TERRITORY, "150" }, 1552e5b6d6dSopenharmony_ci { "DG" , -1 , "QO" , URGN_TERRITORY, "009" }, 1562e5b6d6dSopenharmony_ci { "DJ" , 262, "014", URGN_TERRITORY, "002" }, 1572e5b6d6dSopenharmony_ci { "DK" , 208, "154", URGN_TERRITORY, "150" }, 1582e5b6d6dSopenharmony_ci { "DM" , 212, "029", URGN_TERRITORY, "019" }, 1592e5b6d6dSopenharmony_ci { "DO" , 214, "029", URGN_TERRITORY, "019" }, 1602e5b6d6dSopenharmony_ci { "DZ" , 12, "015", URGN_TERRITORY, "002" }, 1612e5b6d6dSopenharmony_ci { "EA" , -1, "015", URGN_TERRITORY, "002" }, 1622e5b6d6dSopenharmony_ci { "EC" , 218, "005", URGN_TERRITORY, "019" }, 1632e5b6d6dSopenharmony_ci { "EE" , 233, "154", URGN_TERRITORY, "150" }, 1642e5b6d6dSopenharmony_ci { "EG" , 818, "015", URGN_TERRITORY, "002" }, 1652e5b6d6dSopenharmony_ci { "EH" , 732, "015", URGN_TERRITORY, "002" }, 1662e5b6d6dSopenharmony_ci { "ER" , 232, "014", URGN_TERRITORY, "002" }, 1672e5b6d6dSopenharmony_ci { "ES" , 724, "039", URGN_TERRITORY, "150" }, 1682e5b6d6dSopenharmony_ci { "ET" , 231, "014", URGN_TERRITORY, "002" }, 1692e5b6d6dSopenharmony_ci { "EU" , 967, NULL, URGN_GROUPING, NULL }, 1702e5b6d6dSopenharmony_ci { "FI" , 246, "154", URGN_TERRITORY, "150" }, 1712e5b6d6dSopenharmony_ci { "FJ" , 242, "054", URGN_TERRITORY, "009" }, 1722e5b6d6dSopenharmony_ci { "FK" , 238, "005", URGN_TERRITORY, "019" }, 1732e5b6d6dSopenharmony_ci { "FM" , 583, "057", URGN_TERRITORY, "009" }, 1742e5b6d6dSopenharmony_ci { "FO" , 234, "154", URGN_TERRITORY, "150" }, 1752e5b6d6dSopenharmony_ci { "FR" , 250, "155", URGN_TERRITORY, "150" }, 1762e5b6d6dSopenharmony_ci { "FX" , 250, "155", URGN_TERRITORY, "150" }, 1772e5b6d6dSopenharmony_ci { "GA" , 266, "017", URGN_TERRITORY, "002" }, 1782e5b6d6dSopenharmony_ci { "GB" , 826, "154", URGN_TERRITORY, "150" }, 1792e5b6d6dSopenharmony_ci { "GD" , 308, "029", URGN_TERRITORY, "019" }, 1802e5b6d6dSopenharmony_ci { "GE" , 268, "145", URGN_TERRITORY, "142" }, 1812e5b6d6dSopenharmony_ci { "GF" , 254, "005", URGN_TERRITORY, "019" }, 1822e5b6d6dSopenharmony_ci { "GG" , 831, "154", URGN_TERRITORY, "150" }, 1832e5b6d6dSopenharmony_ci { "GH" , 288, "011", URGN_TERRITORY, "002" }, 1842e5b6d6dSopenharmony_ci { "GI" , 292, "039", URGN_TERRITORY, "150" }, 1852e5b6d6dSopenharmony_ci { "GL" , 304, "021", URGN_TERRITORY, "019" }, 1862e5b6d6dSopenharmony_ci { "GM" , 270, "011", URGN_TERRITORY, "002" }, 1872e5b6d6dSopenharmony_ci { "GN" , 324, "011", URGN_TERRITORY, "002" }, 1882e5b6d6dSopenharmony_ci { "GP" , 312, "029", URGN_TERRITORY, "019" }, 1892e5b6d6dSopenharmony_ci { "GQ" , 226, "017", URGN_TERRITORY, "002" }, 1902e5b6d6dSopenharmony_ci { "GR" , 300, "039", URGN_TERRITORY, "150" }, 1912e5b6d6dSopenharmony_ci { "GS" , 239, "005", URGN_TERRITORY, "019" }, 1922e5b6d6dSopenharmony_ci { "GT" , 320, "013", URGN_TERRITORY, "019" }, 1932e5b6d6dSopenharmony_ci { "GU" , 316, "057", URGN_TERRITORY, "009" }, 1942e5b6d6dSopenharmony_ci { "GW" , 624, "011", URGN_TERRITORY, "002" }, 1952e5b6d6dSopenharmony_ci { "GY" , 328, "005", URGN_TERRITORY, "019" }, 1962e5b6d6dSopenharmony_ci { "HK" , 344, "030", URGN_TERRITORY, "142" }, 1972e5b6d6dSopenharmony_ci { "HM" , 334, "053", URGN_TERRITORY, "009" }, 1982e5b6d6dSopenharmony_ci { "HN" , 340, "013", URGN_TERRITORY, "019" }, 1992e5b6d6dSopenharmony_ci { "HR" , 191, "039", URGN_TERRITORY, "150" }, 2002e5b6d6dSopenharmony_ci { "HT" , 332, "029", URGN_TERRITORY, "019" }, 2012e5b6d6dSopenharmony_ci { "HU" , 348, "151", URGN_TERRITORY, "150" }, 2022e5b6d6dSopenharmony_ci { "IC" , -1, "015", URGN_TERRITORY, "002" }, 2032e5b6d6dSopenharmony_ci { "ID" , 360, "035", URGN_TERRITORY, "142" }, 2042e5b6d6dSopenharmony_ci { "IE" , 372, "154", URGN_TERRITORY, "150" }, 2052e5b6d6dSopenharmony_ci { "IL" , 376, "145", URGN_TERRITORY, "142" }, 2062e5b6d6dSopenharmony_ci { "IM" , 833, "154", URGN_TERRITORY, "150" }, 2072e5b6d6dSopenharmony_ci { "IN" , 356, "034", URGN_TERRITORY, "142" }, 2082e5b6d6dSopenharmony_ci { "IO" , 86, "014", URGN_TERRITORY, "002" }, 2092e5b6d6dSopenharmony_ci { "IQ" , 368, "145", URGN_TERRITORY, "142" }, 2102e5b6d6dSopenharmony_ci { "IR" , 364, "034", URGN_TERRITORY, "142" }, 2112e5b6d6dSopenharmony_ci { "IS" , 352, "154", URGN_TERRITORY, "150" }, 2122e5b6d6dSopenharmony_ci { "IT" , 380, "039", URGN_TERRITORY, "150" }, 2132e5b6d6dSopenharmony_ci { "JE" , 832, "154", URGN_TERRITORY, "150" }, 2142e5b6d6dSopenharmony_ci { "JM" , 388, "029", URGN_TERRITORY, "019" }, 2152e5b6d6dSopenharmony_ci { "JO" , 400, "145", URGN_TERRITORY, "142" }, 2162e5b6d6dSopenharmony_ci { "JP" , 392, "030", URGN_TERRITORY, "142" }, 2172e5b6d6dSopenharmony_ci { "KE" , 404, "014", URGN_TERRITORY, "002" }, 2182e5b6d6dSopenharmony_ci { "KG" , 417, "143", URGN_TERRITORY, "142" }, 2192e5b6d6dSopenharmony_ci { "KH" , 116, "035", URGN_TERRITORY, "142" }, 2202e5b6d6dSopenharmony_ci { "KI" , 296, "057", URGN_TERRITORY, "009" }, 2212e5b6d6dSopenharmony_ci { "KM" , 174, "014", URGN_TERRITORY, "002" }, 2222e5b6d6dSopenharmony_ci { "KN" , 659, "029", URGN_TERRITORY, "019" }, 2232e5b6d6dSopenharmony_ci { "KP" , 408, "030", URGN_TERRITORY, "142" }, 2242e5b6d6dSopenharmony_ci { "KR" , 410, "030", URGN_TERRITORY, "142" }, 2252e5b6d6dSopenharmony_ci { "KW" , 414, "145", URGN_TERRITORY, "142" }, 2262e5b6d6dSopenharmony_ci { "KY" , 136, "029", URGN_TERRITORY, "019" }, 2272e5b6d6dSopenharmony_ci { "KZ" , 398, "143", URGN_TERRITORY, "142" }, 2282e5b6d6dSopenharmony_ci { "LA" , 418, "035", URGN_TERRITORY, "142" }, 2292e5b6d6dSopenharmony_ci { "LB" , 422, "145", URGN_TERRITORY, "142" }, 2302e5b6d6dSopenharmony_ci { "LC" , 662, "029", URGN_TERRITORY, "019" }, 2312e5b6d6dSopenharmony_ci { "LI" , 438, "155", URGN_TERRITORY, "150" }, 2322e5b6d6dSopenharmony_ci { "LK" , 144, "034", URGN_TERRITORY, "142" }, 2332e5b6d6dSopenharmony_ci { "LR" , 430, "011", URGN_TERRITORY, "002" }, 2342e5b6d6dSopenharmony_ci { "LS" , 426, "018", URGN_TERRITORY, "002" }, 2352e5b6d6dSopenharmony_ci { "LT" , 440, "154", URGN_TERRITORY, "150" }, 2362e5b6d6dSopenharmony_ci { "LU" , 442, "155", URGN_TERRITORY, "150" }, 2372e5b6d6dSopenharmony_ci { "LV" , 428, "154", URGN_TERRITORY, "150" }, 2382e5b6d6dSopenharmony_ci { "LY" , 434, "015", URGN_TERRITORY, "002" }, 2392e5b6d6dSopenharmony_ci { "MA" , 504, "015", URGN_TERRITORY, "002" }, 2402e5b6d6dSopenharmony_ci { "MC" , 492, "155", URGN_TERRITORY, "150" }, 2412e5b6d6dSopenharmony_ci { "MD" , 498, "151", URGN_TERRITORY, "150" }, 2422e5b6d6dSopenharmony_ci { "ME" , 499, "039", URGN_TERRITORY, "150" }, 2432e5b6d6dSopenharmony_ci { "MF" , 663, "029", URGN_TERRITORY, "019" }, 2442e5b6d6dSopenharmony_ci { "MG" , 450, "014", URGN_TERRITORY, "002" }, 2452e5b6d6dSopenharmony_ci { "MH" , 584, "057", URGN_TERRITORY, "009" }, 2462e5b6d6dSopenharmony_ci { "MK" , 807, "039", URGN_TERRITORY, "150" }, 2472e5b6d6dSopenharmony_ci { "ML" , 466, "011", URGN_TERRITORY, "002" }, 2482e5b6d6dSopenharmony_ci { "MM" , 104, "035", URGN_TERRITORY, "142" }, 2492e5b6d6dSopenharmony_ci { "MN" , 496, "030", URGN_TERRITORY, "142" }, 2502e5b6d6dSopenharmony_ci { "MO" , 446, "030", URGN_TERRITORY, "142" }, 2512e5b6d6dSopenharmony_ci { "MP" , 580, "057", URGN_TERRITORY, "009" }, 2522e5b6d6dSopenharmony_ci { "MQ" , 474, "029", URGN_TERRITORY, "019" }, 2532e5b6d6dSopenharmony_ci { "MR" , 478, "011", URGN_TERRITORY, "002" }, 2542e5b6d6dSopenharmony_ci { "MS" , 500, "029", URGN_TERRITORY, "019" }, 2552e5b6d6dSopenharmony_ci { "MT" , 470, "039", URGN_TERRITORY, "150" }, 2562e5b6d6dSopenharmony_ci { "MU" , 480, "014", URGN_TERRITORY, "002" }, 2572e5b6d6dSopenharmony_ci { "MV" , 462, "034", URGN_TERRITORY, "142" }, 2582e5b6d6dSopenharmony_ci { "MW" , 454, "014", URGN_TERRITORY, "002" }, 2592e5b6d6dSopenharmony_ci { "MX" , 484, "013", URGN_TERRITORY, "019"}, 2602e5b6d6dSopenharmony_ci { "MY" , 458, "035", URGN_TERRITORY, "142" }, 2612e5b6d6dSopenharmony_ci { "MZ" , 508, "014", URGN_TERRITORY, "002" }, 2622e5b6d6dSopenharmony_ci { "NA" , 516, "018", URGN_TERRITORY, "002" }, 2632e5b6d6dSopenharmony_ci { "NC" , 540, "054", URGN_TERRITORY, "009" }, 2642e5b6d6dSopenharmony_ci { "NE" , 562, "011", URGN_TERRITORY, "002" }, 2652e5b6d6dSopenharmony_ci { "NF" , 574, "053", URGN_TERRITORY, "009" }, 2662e5b6d6dSopenharmony_ci { "NG" , 566, "011", URGN_TERRITORY, "002" }, 2672e5b6d6dSopenharmony_ci { "NI" , 558, "013", URGN_TERRITORY, "019" }, 2682e5b6d6dSopenharmony_ci { "NL" , 528, "155", URGN_TERRITORY, "150" }, 2692e5b6d6dSopenharmony_ci { "NO" , 578, "154", URGN_TERRITORY, "150" }, 2702e5b6d6dSopenharmony_ci { "NP" , 524, "034", URGN_TERRITORY, "142" }, 2712e5b6d6dSopenharmony_ci { "NR" , 520, "057", URGN_TERRITORY, "009" }, 2722e5b6d6dSopenharmony_ci { "NT" , 536, NULL , URGN_DEPRECATED, NULL }, 2732e5b6d6dSopenharmony_ci { "NU" , 570, "061", URGN_TERRITORY, "009" }, 2742e5b6d6dSopenharmony_ci { "NZ" , 554, "053", URGN_TERRITORY, "009" }, 2752e5b6d6dSopenharmony_ci { "OM" , 512, "145", URGN_TERRITORY, "142" }, 2762e5b6d6dSopenharmony_ci { "PA" , 591, "013", URGN_TERRITORY, "019" }, 2772e5b6d6dSopenharmony_ci { "PE" , 604, "005", URGN_TERRITORY, "019" }, 2782e5b6d6dSopenharmony_ci { "PF" , 258, "061", URGN_TERRITORY, "009" }, 2792e5b6d6dSopenharmony_ci { "PG" , 598, "054", URGN_TERRITORY, "009" }, 2802e5b6d6dSopenharmony_ci { "PH" , 608, "035", URGN_TERRITORY, "142" }, 2812e5b6d6dSopenharmony_ci { "PK" , 586, "034", URGN_TERRITORY, "142" }, 2822e5b6d6dSopenharmony_ci { "PL" , 616, "151", URGN_TERRITORY, "150" }, 2832e5b6d6dSopenharmony_ci { "PM" , 666, "021", URGN_TERRITORY, "019" }, 2842e5b6d6dSopenharmony_ci { "PN" , 612, "061", URGN_TERRITORY, "009" }, 2852e5b6d6dSopenharmony_ci { "PR" , 630, "029", URGN_TERRITORY, "019" }, 2862e5b6d6dSopenharmony_ci { "PS" , 275, "145", URGN_TERRITORY, "142" }, 2872e5b6d6dSopenharmony_ci { "PT" , 620, "039", URGN_TERRITORY, "150" }, 2882e5b6d6dSopenharmony_ci { "PW" , 585, "057", URGN_TERRITORY, "009" }, 2892e5b6d6dSopenharmony_ci { "PY" , 600, "005", URGN_TERRITORY, "019" }, 2902e5b6d6dSopenharmony_ci { "QA" , 634, "145", URGN_TERRITORY, "142" }, 2912e5b6d6dSopenharmony_ci { "QO" , 961, "009", URGN_SUBCONTINENT, "009" }, 2922e5b6d6dSopenharmony_ci { "QU" , 967, NULL, URGN_GROUPING, NULL }, 2932e5b6d6dSopenharmony_ci { "RE" , 638, "014", URGN_TERRITORY, "002" }, 2942e5b6d6dSopenharmony_ci { "RO" , 642, "151", URGN_TERRITORY, "150" }, 2952e5b6d6dSopenharmony_ci { "RS" , 688, "039", URGN_TERRITORY, "150" }, 2962e5b6d6dSopenharmony_ci { "RU" , 643, "151", URGN_TERRITORY, "150" }, 2972e5b6d6dSopenharmony_ci { "RW" , 646, "014", URGN_TERRITORY, "002" }, 2982e5b6d6dSopenharmony_ci { "SA" , 682, "145", URGN_TERRITORY, "142" }, 2992e5b6d6dSopenharmony_ci { "SB" , 90, "054", URGN_TERRITORY, "009" }, 3002e5b6d6dSopenharmony_ci { "SC" , 690, "014", URGN_TERRITORY, "002" }, 3012e5b6d6dSopenharmony_ci { "SD" , 729, "015", URGN_TERRITORY, "002" }, 3022e5b6d6dSopenharmony_ci { "SE" , 752, "154", URGN_TERRITORY, "150" }, 3032e5b6d6dSopenharmony_ci { "SG" , 702, "035", URGN_TERRITORY, "142" }, 3042e5b6d6dSopenharmony_ci { "SH" , 654, "011", URGN_TERRITORY, "002" }, 3052e5b6d6dSopenharmony_ci { "SI" , 705, "039", URGN_TERRITORY, "150" }, 3062e5b6d6dSopenharmony_ci { "SJ" , 744, "154", URGN_TERRITORY, "150" }, 3072e5b6d6dSopenharmony_ci { "SK" , 703, "151", URGN_TERRITORY, "150" }, 3082e5b6d6dSopenharmony_ci { "SL" , 694, "011", URGN_TERRITORY, "002" }, 3092e5b6d6dSopenharmony_ci { "SM" , 674, "039", URGN_TERRITORY, "150" }, 3102e5b6d6dSopenharmony_ci { "SN" , 686, "011", URGN_TERRITORY, "002" }, 3112e5b6d6dSopenharmony_ci { "SO" , 706, "014", URGN_TERRITORY, "002" }, 3122e5b6d6dSopenharmony_ci { "SR" , 740, "005", URGN_TERRITORY, "019" }, 3132e5b6d6dSopenharmony_ci { "SS" , 728, "014", URGN_TERRITORY, "002" }, 3142e5b6d6dSopenharmony_ci { "ST" , 678, "017", URGN_TERRITORY, "002" }, 3152e5b6d6dSopenharmony_ci { "SU" , 810, NULL , URGN_DEPRECATED , NULL}, 3162e5b6d6dSopenharmony_ci { "SV" , 222, "013", URGN_TERRITORY, "019" }, 3172e5b6d6dSopenharmony_ci { "SX" , 534, "029", URGN_TERRITORY, "019" }, 3182e5b6d6dSopenharmony_ci { "SY" , 760, "145", URGN_TERRITORY, "142" }, 3192e5b6d6dSopenharmony_ci { "SZ" , 748, "018", URGN_TERRITORY, "002" }, 3202e5b6d6dSopenharmony_ci { "TA" , -1, "QO", URGN_TERRITORY, "009" }, 3212e5b6d6dSopenharmony_ci { "TC" , 796, "029", URGN_TERRITORY, "019" }, 3222e5b6d6dSopenharmony_ci { "TD" , 148, "017", URGN_TERRITORY, "002" }, 3232e5b6d6dSopenharmony_ci { "TF" , 260, "014", URGN_TERRITORY, "002" }, 3242e5b6d6dSopenharmony_ci { "TG" , 768, "011", URGN_TERRITORY, "002" }, 3252e5b6d6dSopenharmony_ci { "TH" , 764, "035", URGN_TERRITORY, "142" }, 3262e5b6d6dSopenharmony_ci { "TJ" , 762, "143", URGN_TERRITORY, "142" }, 3272e5b6d6dSopenharmony_ci { "TK" , 772, "061", URGN_TERRITORY, "009" }, 3282e5b6d6dSopenharmony_ci { "TL" , 626, "035", URGN_TERRITORY, "142" }, 3292e5b6d6dSopenharmony_ci { "TM" , 795, "143", URGN_TERRITORY, "142" }, 3302e5b6d6dSopenharmony_ci { "TN" , 788, "015", URGN_TERRITORY, "002" }, 3312e5b6d6dSopenharmony_ci { "TO" , 776, "061", URGN_TERRITORY, "009" }, 3322e5b6d6dSopenharmony_ci { "TP" , 626, "035", URGN_TERRITORY, "142" }, 3332e5b6d6dSopenharmony_ci { "TR" , 792, "145", URGN_TERRITORY, "142" }, 3342e5b6d6dSopenharmony_ci { "TT" , 780, "029", URGN_TERRITORY, "019" }, 3352e5b6d6dSopenharmony_ci { "TV" , 798, "061", URGN_TERRITORY, "009" }, 3362e5b6d6dSopenharmony_ci { "TW" , 158, "030", URGN_TERRITORY, "142" }, 3372e5b6d6dSopenharmony_ci { "TZ" , 834, "014", URGN_TERRITORY, "002" }, 3382e5b6d6dSopenharmony_ci { "UA" , 804, "151", URGN_TERRITORY, "150" }, 3392e5b6d6dSopenharmony_ci { "UG" , 800, "014", URGN_TERRITORY, "002" }, 3402e5b6d6dSopenharmony_ci { "UM" , 581, "057", URGN_TERRITORY, "009" }, 3412e5b6d6dSopenharmony_ci { "US" , 840, "021", URGN_TERRITORY, "019" }, 3422e5b6d6dSopenharmony_ci { "UY" , 858, "005", URGN_TERRITORY, "019" }, 3432e5b6d6dSopenharmony_ci { "UZ" , 860, "143", URGN_TERRITORY, "142" }, 3442e5b6d6dSopenharmony_ci { "VA" , 336, "039", URGN_TERRITORY, "150" }, 3452e5b6d6dSopenharmony_ci { "VC" , 670, "029", URGN_TERRITORY, "019" }, 3462e5b6d6dSopenharmony_ci { "VE" , 862, "005", URGN_TERRITORY, "019" }, 3472e5b6d6dSopenharmony_ci { "VG" , 92, "029", URGN_TERRITORY, "019" }, 3482e5b6d6dSopenharmony_ci { "VI" , 850, "029", URGN_TERRITORY, "019" }, 3492e5b6d6dSopenharmony_ci { "VN" , 704, "035", URGN_TERRITORY, "142" }, 3502e5b6d6dSopenharmony_ci { "VU" , 548, "054", URGN_TERRITORY, "009" }, 3512e5b6d6dSopenharmony_ci { "WF" , 876, "061", URGN_TERRITORY, "009" }, 3522e5b6d6dSopenharmony_ci { "WS" , 882, "061", URGN_TERRITORY, "009" }, 3532e5b6d6dSopenharmony_ci { "YD" , 887, "145", URGN_TERRITORY, "142" }, 3542e5b6d6dSopenharmony_ci { "YE" , 887, "145", URGN_TERRITORY, "142" }, 3552e5b6d6dSopenharmony_ci { "YT" , 175, "014", URGN_TERRITORY, "002" }, 3562e5b6d6dSopenharmony_ci { "ZA" , 710, "018", URGN_TERRITORY, "002" }, 3572e5b6d6dSopenharmony_ci { "ZM" , 894, "014", URGN_TERRITORY, "002" }, 3582e5b6d6dSopenharmony_ci { "ZR" , 180, "017", URGN_TERRITORY, "002" }, 3592e5b6d6dSopenharmony_ci { "ZW" , 716, "014", URGN_TERRITORY, "002" }, 3602e5b6d6dSopenharmony_ci { "ZZ" , 999, NULL , URGN_UNKNOWN, NULL }, 3612e5b6d6dSopenharmony_ci { NULL , 0, NULL , URGN_UNKNOWN, NULL } /* terminator */ 3622e5b6d6dSopenharmony_ci }; 3632e5b6d6dSopenharmony_ci 3642e5b6d6dSopenharmony_ci 3652e5b6d6dSopenharmony_cistatic void TestKnownRegions() { 3662e5b6d6dSopenharmony_ci const KnownRegion * rd; 3672e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 3682e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3692e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 3702e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 3712e5b6d6dSopenharmony_ci int32_t n = uregion_getNumericCode(r); 3722e5b6d6dSopenharmony_ci int32_t e = rd->numeric; 3732e5b6d6dSopenharmony_ci if ( n != e ) { 3742e5b6d6dSopenharmony_ci log_err("ERROR: Numeric code mismatch for region %s. Expected:%d Got:%d\n", uregion_getRegionCode(r), e, n ); 3752e5b6d6dSopenharmony_ci } 3762e5b6d6dSopenharmony_ci if (uregion_getType(r) != rd->type) { 3772e5b6d6dSopenharmony_ci log_err("ERROR: Expected region %s to be of type %d. Got: %d\n", uregion_getRegionCode(r), rd->type, uregion_getType(r) ); 3782e5b6d6dSopenharmony_ci } 3792e5b6d6dSopenharmony_ci if ( e > 0 ) { 3802e5b6d6dSopenharmony_ci const URegion *ncRegion = uregion_getRegionFromNumericCode(e, &status); 3812e5b6d6dSopenharmony_ci if ( !uregion_areEqual(ncRegion, r) && e != 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891 3822e5b6d6dSopenharmony_ci log_err("ERROR: Creating region %s by its numeric code returned a different region. Got: %s instead.\n", 3832e5b6d6dSopenharmony_ci uregion_getRegionCode(r), uregion_getRegionCode(ncRegion) ); 3842e5b6d6dSopenharmony_ci } 3852e5b6d6dSopenharmony_ci } 3862e5b6d6dSopenharmony_ci } else { 3872e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 3882e5b6d6dSopenharmony_ci } 3892e5b6d6dSopenharmony_ci } 3902e5b6d6dSopenharmony_ci} 3912e5b6d6dSopenharmony_ci 3922e5b6d6dSopenharmony_cistatic void TestGetContainedRegions() { 3932e5b6d6dSopenharmony_ci const KnownRegion * rd; 3942e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 3952e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3962e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 3972e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 3982e5b6d6dSopenharmony_ci UEnumeration *containedRegions; 3992e5b6d6dSopenharmony_ci const char *crID; 4002e5b6d6dSopenharmony_ci if (uregion_getType(r) == URGN_GROUPING) { 4012e5b6d6dSopenharmony_ci continue; 4022e5b6d6dSopenharmony_ci } 4032e5b6d6dSopenharmony_ci containedRegions = uregion_getContainedRegions(r, &status); 4042e5b6d6dSopenharmony_ci if (containedRegions != NULL) { 4052e5b6d6dSopenharmony_ci while ((crID = uenum_next(containedRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) { 4062e5b6d6dSopenharmony_ci const URegion *cr = uregion_getRegionFromCode(crID, &status); 4072e5b6d6dSopenharmony_ci const URegion *containingRegion = (cr)? uregion_getContainingRegion(cr) : NULL; 4082e5b6d6dSopenharmony_ci if ( !containingRegion || !uregion_areEqual(containingRegion, r) ) { 4092e5b6d6dSopenharmony_ci log_err("ERROR: Region: %s contains region %s. Expected containing region of this region to be the original region, but got %s\n", 4102e5b6d6dSopenharmony_ci uregion_getRegionCode(r), uregion_getRegionCode(cr), (containingRegion)?uregion_getRegionCode(containingRegion):"NULL" ); 4112e5b6d6dSopenharmony_ci } 4122e5b6d6dSopenharmony_ci } 4132e5b6d6dSopenharmony_ci uenum_close(containedRegions); 4142e5b6d6dSopenharmony_ci } 4152e5b6d6dSopenharmony_ci } else { 4162e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 4172e5b6d6dSopenharmony_ci } 4182e5b6d6dSopenharmony_ci } 4192e5b6d6dSopenharmony_ci} 4202e5b6d6dSopenharmony_ci 4212e5b6d6dSopenharmony_cistatic void TestGroupingChildren() { 4222e5b6d6dSopenharmony_ci const char* testGroupings[] = { 4232e5b6d6dSopenharmony_ci "003", "021,013,029", 4242e5b6d6dSopenharmony_ci "419", "013,029,005", 4252e5b6d6dSopenharmony_ci "EU", "AT,BE,CY,CZ,DE,DK,EE,ES,FI,FR,GR,HR,HU,IE,IT,LT,LU,LV,MT,NL,PL,PT,SE,SI,SK,BG,RO" 4262e5b6d6dSopenharmony_ci }; 4272e5b6d6dSopenharmony_ci 4282e5b6d6dSopenharmony_ci for (int32_t i = 0; i < UPRV_LENGTHOF(testGroupings); i += 2) { 4292e5b6d6dSopenharmony_ci const char* groupingCode = testGroupings[i]; 4302e5b6d6dSopenharmony_ci const char* expectedChildren = testGroupings[i + 1]; 4312e5b6d6dSopenharmony_ci 4322e5b6d6dSopenharmony_ci UErrorCode err = U_ZERO_ERROR; 4332e5b6d6dSopenharmony_ci const URegion* grouping = uregion_getRegionFromCode(groupingCode, &err); 4342e5b6d6dSopenharmony_ci if (U_SUCCESS(err)) { 4352e5b6d6dSopenharmony_ci UEnumeration* actualChildren = uregion_getContainedRegions(grouping, &err); 4362e5b6d6dSopenharmony_ci if (U_SUCCESS(err)) { 4372e5b6d6dSopenharmony_ci int32_t numActualChildren = uenum_count(actualChildren, &err); 4382e5b6d6dSopenharmony_ci int32_t numExpectedChildren = 0; 4392e5b6d6dSopenharmony_ci const char* expectedChildStart = expectedChildren; 4402e5b6d6dSopenharmony_ci const char* expectedChildEnd = NULL; 4412e5b6d6dSopenharmony_ci const char* actualChild = NULL; 4422e5b6d6dSopenharmony_ci while ((actualChild = uenum_next(actualChildren, NULL, &err)) != NULL && *expectedChildStart != '\0') { 4432e5b6d6dSopenharmony_ci expectedChildEnd = uprv_strchr(expectedChildStart, ','); 4442e5b6d6dSopenharmony_ci if (expectedChildEnd == NULL) { 4452e5b6d6dSopenharmony_ci expectedChildEnd = expectedChildStart + uprv_strlen(expectedChildStart); 4462e5b6d6dSopenharmony_ci } 4472e5b6d6dSopenharmony_ci if (uprv_strlen(actualChild) != (size_t)(expectedChildEnd - expectedChildStart) || uprv_strncmp(actualChild, expectedChildStart, expectedChildEnd - expectedChildStart) != 0) { 4482e5b6d6dSopenharmony_ci log_err("Mismatch in child list for %s at position %d: expected %s, got %s\n", groupingCode, i, expectedChildStart, actualChild); 4492e5b6d6dSopenharmony_ci } 4502e5b6d6dSopenharmony_ci expectedChildStart = (*expectedChildEnd != '\0') ? expectedChildEnd + 1 : expectedChildEnd; 4512e5b6d6dSopenharmony_ci ++numExpectedChildren; 4522e5b6d6dSopenharmony_ci } 4532e5b6d6dSopenharmony_ci if (expectedChildEnd == NULL) { 4542e5b6d6dSopenharmony_ci expectedChildEnd = expectedChildren; 4552e5b6d6dSopenharmony_ci } 4562e5b6d6dSopenharmony_ci while (expectedChildEnd != NULL && *expectedChildEnd != '\0') { 4572e5b6d6dSopenharmony_ci expectedChildEnd = uprv_strchr(expectedChildEnd + 1, ','); 4582e5b6d6dSopenharmony_ci ++numExpectedChildren; 4592e5b6d6dSopenharmony_ci } 4602e5b6d6dSopenharmony_ci if (numExpectedChildren != numActualChildren) { 4612e5b6d6dSopenharmony_ci log_err("Wrong number of children for %s: expected %d, got %d\n", groupingCode, numExpectedChildren, numActualChildren); 4622e5b6d6dSopenharmony_ci } 4632e5b6d6dSopenharmony_ci uenum_close(actualChildren); 4642e5b6d6dSopenharmony_ci } else { 4652e5b6d6dSopenharmony_ci log_err("Couldn't create iterator for children of %s\n", groupingCode); 4662e5b6d6dSopenharmony_ci } 4672e5b6d6dSopenharmony_ci } else { 4682e5b6d6dSopenharmony_ci log_err("Region %s not found\n", groupingCode); 4692e5b6d6dSopenharmony_ci } 4702e5b6d6dSopenharmony_ci } 4712e5b6d6dSopenharmony_ci} 4722e5b6d6dSopenharmony_ci 4732e5b6d6dSopenharmony_cistatic void TestGetContainedRegionsWithType() { 4742e5b6d6dSopenharmony_ci const KnownRegion * rd; 4752e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 4762e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 4772e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 4782e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 4792e5b6d6dSopenharmony_ci UEnumeration *containedRegions; 4802e5b6d6dSopenharmony_ci const char *crID; 4812e5b6d6dSopenharmony_ci if (uregion_getType(r) != URGN_CONTINENT) { 4822e5b6d6dSopenharmony_ci continue; 4832e5b6d6dSopenharmony_ci } 4842e5b6d6dSopenharmony_ci containedRegions = uregion_getContainedRegionsOfType(r, URGN_TERRITORY, &status); 4852e5b6d6dSopenharmony_ci if (containedRegions != NULL) { 4862e5b6d6dSopenharmony_ci while ((crID = uenum_next(containedRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) { 4872e5b6d6dSopenharmony_ci const URegion *cr = uregion_getRegionFromCode(crID, &status); 4882e5b6d6dSopenharmony_ci const URegion *containingRegion = (cr)? uregion_getContainingRegionOfType(cr, URGN_CONTINENT) : NULL; 4892e5b6d6dSopenharmony_ci if ( !containingRegion || !uregion_areEqual(containingRegion, r) ) { 4902e5b6d6dSopenharmony_ci log_err("ERROR: Continent: %s contains territory %s. Expected containing continent of this region to be the original region, but got %s\n", 4912e5b6d6dSopenharmony_ci uregion_getRegionCode(r), uregion_getRegionCode(cr), (containingRegion)?uregion_getRegionCode(containingRegion):"NULL" ); 4922e5b6d6dSopenharmony_ci } 4932e5b6d6dSopenharmony_ci } 4942e5b6d6dSopenharmony_ci uenum_close(containedRegions); 4952e5b6d6dSopenharmony_ci } 4962e5b6d6dSopenharmony_ci } else { 4972e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 4982e5b6d6dSopenharmony_ci } 4992e5b6d6dSopenharmony_ci } 5002e5b6d6dSopenharmony_ci} 5012e5b6d6dSopenharmony_ci 5022e5b6d6dSopenharmony_cistatic void TestGetContainingRegion() { 5032e5b6d6dSopenharmony_ci const KnownRegion * rd; 5042e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 5052e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5062e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 5072e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 5082e5b6d6dSopenharmony_ci const URegion *c = uregion_getContainingRegion(r); 5092e5b6d6dSopenharmony_ci if (rd->parent == NULL) { 5102e5b6d6dSopenharmony_ci if ( c ) { 5112e5b6d6dSopenharmony_ci log_err("ERROR: Containing region for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) ); 5122e5b6d6dSopenharmony_ci } 5132e5b6d6dSopenharmony_ci } else { 5142e5b6d6dSopenharmony_ci const URegion *p = uregion_getRegionFromCode(rd->parent, &status); 5152e5b6d6dSopenharmony_ci if ( c == NULL || !uregion_areEqual(p, c) ) { 5162e5b6d6dSopenharmony_ci log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n", 5172e5b6d6dSopenharmony_ci uregion_getRegionCode(r), (p)?uregion_getRegionCode(p):"NULL", (c)?uregion_getRegionCode(c):"NULL" ); 5182e5b6d6dSopenharmony_ci } 5192e5b6d6dSopenharmony_ci } 5202e5b6d6dSopenharmony_ci } else { 5212e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 5222e5b6d6dSopenharmony_ci } 5232e5b6d6dSopenharmony_ci } 5242e5b6d6dSopenharmony_ci} 5252e5b6d6dSopenharmony_ci 5262e5b6d6dSopenharmony_cistatic void TestGetContainingRegionWithType() { 5272e5b6d6dSopenharmony_ci const KnownRegion * rd; 5282e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 5292e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5302e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 5312e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 5322e5b6d6dSopenharmony_ci const URegion *c = uregion_getContainingRegionOfType(r, URGN_CONTINENT); 5332e5b6d6dSopenharmony_ci if (rd->containingContinent == NULL) { 5342e5b6d6dSopenharmony_ci if ( c != NULL) { 5352e5b6d6dSopenharmony_ci log_err("ERROR: Containing continent for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) ); 5362e5b6d6dSopenharmony_ci } 5372e5b6d6dSopenharmony_ci } else { 5382e5b6d6dSopenharmony_ci const URegion *p = uregion_getRegionFromCode(rd->containingContinent, &status); 5392e5b6d6dSopenharmony_ci if ( !uregion_areEqual(p, c) ) { 5402e5b6d6dSopenharmony_ci log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n", 5412e5b6d6dSopenharmony_ci uregion_getRegionCode(r), (p)?uregion_getRegionCode(p):"NULL", (c)?uregion_getRegionCode(c):"NULL" ); 5422e5b6d6dSopenharmony_ci } 5432e5b6d6dSopenharmony_ci } 5442e5b6d6dSopenharmony_ci } else { 5452e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 5462e5b6d6dSopenharmony_ci } 5472e5b6d6dSopenharmony_ci } 5482e5b6d6dSopenharmony_ci} 5492e5b6d6dSopenharmony_ci 5502e5b6d6dSopenharmony_cistatic const char * expectPrefRegions0[] = { "AN","CW","SX","BQ",NULL }; /* Netherlands Antilles */ 5512e5b6d6dSopenharmony_cistatic const char * expectPrefRegions1[] = { "CS","RS","ME",NULL }; /* Serbia & Montenegro */ 5522e5b6d6dSopenharmony_cistatic const char * expectPrefRegions2[] = { "FQ","AQ","TF",NULL }; /* French Southern and Antarctic Territories */ 5532e5b6d6dSopenharmony_cistatic const char * expectPrefRegions3[] = { "NT","IQ","SA",NULL }; /* Neutral Zone */ 5542e5b6d6dSopenharmony_cistatic const char * expectPrefRegions4[] = { "PC","FM","MH","MP","PW",NULL }; /* Pacific Islands Trust Territory */ 5552e5b6d6dSopenharmony_cistatic const char * expectPrefRegions5[] = { "SU","RU","AM","AZ","BY","EE","GE","KZ","KG","LV","LT","MD","TJ","TM","UA","UZ",NULL }; /* Soviet Union */ 5562e5b6d6dSopenharmony_cistatic const char ** expectPrefRegionsTestData[] = { 5572e5b6d6dSopenharmony_ci expectPrefRegions0, 5582e5b6d6dSopenharmony_ci expectPrefRegions1, 5592e5b6d6dSopenharmony_ci expectPrefRegions2, 5602e5b6d6dSopenharmony_ci expectPrefRegions3, 5612e5b6d6dSopenharmony_ci expectPrefRegions4, 5622e5b6d6dSopenharmony_ci expectPrefRegions5, 5632e5b6d6dSopenharmony_ci NULL 5642e5b6d6dSopenharmony_ci}; 5652e5b6d6dSopenharmony_ci 5662e5b6d6dSopenharmony_cistatic void TestGetPreferredValues() { 5672e5b6d6dSopenharmony_ci const char *** testDataPtr = expectPrefRegionsTestData; 5682e5b6d6dSopenharmony_ci const char ** regionListPtr; 5692e5b6d6dSopenharmony_ci while ( (regionListPtr = *testDataPtr++) != NULL ) { 5702e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5712e5b6d6dSopenharmony_ci const char * deprecatedCode = *regionListPtr++; 5722e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(deprecatedCode, &status); 5732e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 5742e5b6d6dSopenharmony_ci UEnumeration *preferredRegions = uregion_getPreferredValues(r, &status); 5752e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 5762e5b6d6dSopenharmony_ci if (preferredRegions != NULL) { 5772e5b6d6dSopenharmony_ci const char * preferredCode; 5782e5b6d6dSopenharmony_ci while ( (preferredCode = *regionListPtr++) != NULL ) { 5792e5b6d6dSopenharmony_ci const char *check; 5802e5b6d6dSopenharmony_ci UBool found = false; 5812e5b6d6dSopenharmony_ci uenum_reset(preferredRegions, &status); 5822e5b6d6dSopenharmony_ci while ((check = uenum_next(preferredRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) { 5832e5b6d6dSopenharmony_ci if ( !uprv_strcmp(check,preferredCode) ) { 5842e5b6d6dSopenharmony_ci found = true; 5852e5b6d6dSopenharmony_ci break; 5862e5b6d6dSopenharmony_ci } 5872e5b6d6dSopenharmony_ci } 5882e5b6d6dSopenharmony_ci if ( !found ) { 5892e5b6d6dSopenharmony_ci log_err("ERROR: uregion_getPreferredValues for region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(r), preferredCode); 5902e5b6d6dSopenharmony_ci } 5912e5b6d6dSopenharmony_ci } 5922e5b6d6dSopenharmony_ci uenum_close(preferredRegions); 5932e5b6d6dSopenharmony_ci } 5942e5b6d6dSopenharmony_ci } else { 5952e5b6d6dSopenharmony_ci log_err("ERROR: uregion_getPreferredValues failed for region %s.\n", uregion_getRegionCode(r)); 5962e5b6d6dSopenharmony_ci } 5972e5b6d6dSopenharmony_ci } else { 5982e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", deprecatedCode); 5992e5b6d6dSopenharmony_ci } 6002e5b6d6dSopenharmony_ci } 6012e5b6d6dSopenharmony_ci} 6022e5b6d6dSopenharmony_ci 6032e5b6d6dSopenharmony_cistatic void TestContains() { 6042e5b6d6dSopenharmony_ci const KnownRegion * rd; 6052e5b6d6dSopenharmony_ci for (rd = knownRegions; rd->code != NULL ; rd++ ) { 6062e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 6072e5b6d6dSopenharmony_ci const URegion *r = uregion_getRegionFromCode(rd->code, &status); 6082e5b6d6dSopenharmony_ci if ( U_SUCCESS(status) ) { 6092e5b6d6dSopenharmony_ci const URegion *c = uregion_getContainingRegion(r); 6102e5b6d6dSopenharmony_ci while (c != NULL) { 6112e5b6d6dSopenharmony_ci if ( !uregion_contains(c, r) ) { 6122e5b6d6dSopenharmony_ci log_err("ERROR: Region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(c), uregion_getRegionCode(r) ); 6132e5b6d6dSopenharmony_ci } 6142e5b6d6dSopenharmony_ci c = uregion_getContainingRegion(c); 6152e5b6d6dSopenharmony_ci } 6162e5b6d6dSopenharmony_ci } else { 6172e5b6d6dSopenharmony_ci log_data_err("ERROR: Known region %s was not recognized.\n", rd->code); 6182e5b6d6dSopenharmony_ci } 6192e5b6d6dSopenharmony_ci } 6202e5b6d6dSopenharmony_ci} 6212e5b6d6dSopenharmony_ci 6222e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_FORMATTING */ 623