1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /******************************************************************** 4 * COPYRIGHT: 5 * Copyright (c) 1997-2015, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ********************************************************************/ 8 9 #include "intltest.h" 10 #include "unicode/locid.h" 11 12 /** 13 * Tests for the Locale class 14 **/ 15 class LocaleTest: public IntlTest { 16 public: 17 LocaleTest(); 18 virtual ~LocaleTest(); 19 20 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ) override; 21 22 /** 23 * Test methods to set and get data fields 24 **/ 25 void TestBasicGetters(void); 26 /** 27 * Test methods to set and get data fields 28 **/ 29 void TestParallelAPIValues(void); 30 /** 31 * Use Locale to access Resource file data and compare against expected values 32 **/ 33 void TestSimpleResourceInfo(void); 34 /** 35 * Use Locale to access Resource file display names and compare against expected values 36 **/ 37 void TestDisplayNames(void); 38 /** 39 * Test methods for basic object behaviour 40 **/ 41 void TestSimpleObjectStuff(void); 42 /** 43 * Test methods for POSIX parsing behavior 44 **/ 45 void TestPOSIXParsing(void); 46 /** 47 * Test Locale::getAvailableLocales 48 **/ 49 void TestGetAvailableLocales(void); 50 /** 51 * Test methods to set and access a custom data directory 52 **/ 53 void TestDataDirectory(void); 54 55 void TestISO3Fallback(void); 56 void TestGetLangsAndCountries(void); 57 void TestSimpleDisplayNames(void); 58 void TestUninstalledISO3Names(void); 59 void TestAtypicalLocales(void); 60 #if !UCONFIG_NO_FORMATTING 61 void TestThaiCurrencyFormat(void); 62 void TestEuroSupport(void); 63 #endif 64 void TestToString(void); 65 #if !UCONFIG_NO_FORMATTING 66 void Test4139940(void); 67 void Test4143951(void); 68 #endif 69 void Test4147315(void); 70 void Test4147317(void); 71 void Test4147552(void); 72 73 void Test20639_DeprecatesISO3Language(); 74 75 void TestVariantParsing(void); 76 77 /* Test getting keyword enumeration */ 78 void TestKeywordVariants(void); 79 void TestCreateUnicodeKeywords(void); 80 81 /* Test getting keyword values */ 82 void TestKeywordVariantParsing(void); 83 void TestCreateKeywordSet(void); 84 void TestCreateKeywordSetEmpty(void); 85 void TestCreateKeywordSetWithPrivateUse(void); 86 void TestCreateUnicodeKeywordSet(void); 87 void TestCreateUnicodeKeywordSetEmpty(void); 88 void TestCreateUnicodeKeywordSetWithPrivateUse(void); 89 void TestGetKeywordValueStdString(void); 90 void TestGetUnicodeKeywordValueStdString(void); 91 92 /* Test setting keyword values */ 93 void TestSetKeywordValue(void); 94 void TestSetKeywordValueStringPiece(void); 95 void TestSetUnicodeKeywordValueStringPiece(void); 96 97 /* Test getting the locale base name */ 98 void TestGetBaseName(void); 99 100 #if !UCONFIG_NO_FORMATTING 101 void Test4105828(void) ; 102 #endif 103 104 void TestSetIsBogus(void); 105 106 void TestGetLocale(void); 107 108 void TestVariantWithOutCountry(void); 109 110 void TestCanonicalization(void); 111 112 void TestCanonicalize(void); 113 114 #if !UCONFIG_NO_FORMATTING 115 static UDate date(int32_t y, int32_t m, int32_t d, int32_t hr = 0, int32_t min = 0, int32_t sec = 0); 116 #endif 117 118 void TestCurrencyByDate(void); 119 120 void TestGetVariantWithKeywords(void); 121 void TestIsRightToLeft(); 122 void TestBug11421(); 123 void TestBug13277(); 124 void TestBug13554(); 125 void TestBug20410(); 126 void TestBug20900(); 127 void TestLocaleCanonicalizationFromFile(); 128 void TestKnownCanonicalizedListCorrect(); 129 void TestConstructorAcceptsBCP47(); 130 131 void TestAddLikelySubtags(); 132 void TestMinimizeSubtags(); 133 void TestAddLikelyAndMinimizeSubtags(); 134 135 void TestForLanguageTag(); 136 void TestForLanguageTagLegacyTagBug21676(); 137 void TestToLanguageTag(); 138 void TestToLanguageTagOmitTrue(); 139 140 void TestMoveAssign(); 141 void TestMoveCtor(); 142 143 void TestBug20407iVariantPreferredValue(); 144 145 void TestBug13417VeryLongLanguageTag(); 146 147 void TestBug11053UnderlineTimeZone(); 148 149 void TestUnd(); 150 void TestUndScript(); 151 void TestUndRegion(); 152 void TestUndCAPI(); 153 void TestRangeIterator(); 154 void TestPointerConvertingIterator(); 155 void TestTagConvertingIterator(); 156 void TestCapturingTagConvertingIterator(); 157 void TestSetUnicodeKeywordValueInLongLocale(); 158 void TestSetUnicodeKeywordValueNullInLongLocale(); 159 void TestLeak21419(); 160 void TestNullDereferenceWrite21597(); 161 void TestLongLocaleSetKeywordAssign(); 162 void TestLongLocaleSetKeywordMoveAssign(); 163 void TestSierraLeoneCurrency21997(); 164 165 private: 166 void _checklocs(const char* label, 167 const char* req, 168 const Locale& validLoc, 169 const Locale& actualLoc, 170 const char* expReqValid="gt", 171 const char* expValidActual="ge"); 172 173 /** 174 * routine to perform subtests, used by TestDisplayNames 175 **/ 176 void doTestDisplayNames(Locale& inLocale, int32_t compareIndex); 177 /** 178 * additional initialization for datatables storing expected values 179 **/ 180 void setUpDataTable(void); 181 182 UnicodeString** dataTable; 183 184 enum { 185 ENGLISH = 0, 186 FRENCH = 1, 187 CROATIAN = 2, 188 GREEK = 3, 189 NORWEGIAN = 4, 190 ITALIAN = 5, 191 XX = 6, 192 CHINESE = 7, 193 MAX_LOCALES = 7 194 }; 195 196 enum { 197 LANG = 0, 198 SCRIPT, 199 CTRY, 200 VAR, 201 NAME, 202 LANG3, 203 CTRY3, 204 LCID, 205 DLANG_EN, 206 DSCRIPT_EN, 207 DCTRY_EN, 208 DVAR_EN, 209 DNAME_EN, 210 DLANG_FR, 211 DSCRIPT_FR, 212 DCTRY_FR, 213 DVAR_FR, 214 DNAME_FR, 215 DLANG_CA, 216 DSCRIPT_CA, 217 DCTRY_CA, 218 DVAR_CA, 219 DNAME_CA, 220 DLANG_EL, 221 DSCRIPT_EL, 222 DCTRY_EL, 223 DVAR_EL, 224 DNAME_EL, 225 DLANG_NO, 226 DSCRIPT_NO, 227 DCTRY_NO, 228 DVAR_NO, 229 DNAME_NO 230 }; 231 232 #if !UCONFIG_NO_COLLATION 233 /** 234 * Check on registered collators. 235 * @param expectExtra if non-null, the locale ID of an 'extra' locale that is registered. 236 */ 237 void checkRegisteredCollators(const char *expectExtra = NULL); 238 #endif 239 }; 240