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