• 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 = 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 
164 private:
165     void _checklocs(const char* label,
166                     const char* req,
167                     const Locale& validLoc,
168                     const Locale& actualLoc,
169                     const char* expReqValid="gt",
170                     const char* expValidActual="ge");
171 
172     /**
173      * routine to perform subtests, used by TestDisplayNames
174      **/
175     void doTestDisplayNames(Locale& inLocale, int32_t compareIndex);
176     /**
177      * additional initialization for datatables storing expected values
178      **/
179     void setUpDataTable(void);
180 
181     UnicodeString** dataTable;
182 
183     enum {
184         ENGLISH = 0,
185         FRENCH = 1,
186         CROATIAN = 2,
187         GREEK = 3,
188         NORWEGIAN = 4,
189         ITALIAN = 5,
190         XX = 6,
191         CHINESE = 7,
192         MAX_LOCALES = 7
193     };
194 
195     enum {
196         LANG = 0,
197         SCRIPT,
198         CTRY,
199         VAR,
200         NAME,
201         LANG3,
202         CTRY3,
203         LCID,
204         DLANG_EN,
205         DSCRIPT_EN,
206         DCTRY_EN,
207         DVAR_EN,
208         DNAME_EN,
209         DLANG_FR,
210         DSCRIPT_FR,
211         DCTRY_FR,
212         DVAR_FR,
213         DNAME_FR,
214         DLANG_CA,
215         DSCRIPT_CA,
216         DCTRY_CA,
217         DVAR_CA,
218         DNAME_CA,
219         DLANG_EL,
220         DSCRIPT_EL,
221         DCTRY_EL,
222         DVAR_EL,
223         DNAME_EL,
224         DLANG_NO,
225         DSCRIPT_NO,
226         DCTRY_NO,
227         DVAR_NO,
228         DNAME_NO
229     };
230 
231 #if !UCONFIG_NO_COLLATION
232     /**
233      * Check on registered collators.
234      * @param expectExtra if non-null, the locale ID of an 'extra' locale that is registered.
235      */
236     void checkRegisteredCollators(const char *expectExtra = NULL);
237 #endif
238 };
239