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