• 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 
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();
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 = nullptr);
238 #endif
239 };
240