• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <map>
18 #include <vector>
19 
20 #include "collator.h"
21 #include "character.h"
22 #include "date_time_format.h"
23 #include "locale_compare.h"
24 #include "locale_config.h"
25 #include "locale_info.h"
26 #include "measure_data.h"
27 #include "number_format.h"
28 #include "phone_number_format.h"
29 #include "plural_rules.h"
30 #include "preferred_language.h"
31 #include "relative_time_format.h"
32 #include "utils.h"
33 #include "i18n_break_iterator.h"
34 #include "i18n_calendar.h"
35 #include "i18n_timezone.h"
36 #include "i18n_types.h"
37 #include "index_util.h"
38 #include "intl_test.h"
39 #include "system_locale_manager.h"
40 #include "taboo_utils.h"
41 #include "utils.h"
42 
43 using namespace OHOS::Global::I18n;
44 using testing::ext::TestSize;
45 using namespace std;
46 
47 namespace OHOS {
48 namespace Global {
49 namespace I18n {
50 class IntlTest : public testing::Test {
51 public:
52     static void SetUpTestCase(void);
53     static void TearDownTestCase(void);
54     void SetUp();
55     void TearDown();
56 };
57 
SetUpTestCase(void)58 void IntlTest::SetUpTestCase(void)
59 {}
60 
TearDownTestCase(void)61 void IntlTest::TearDownTestCase(void)
62 {}
63 
SetUp(void)64 void IntlTest::SetUp(void)
65 {}
66 
TearDown(void)67 void IntlTest::TearDown(void)
68 {}
69 
70 /**
71  * @tc.name: IntlFuncTest001
72  * @tc.desc: Test Intl DateTimeFormat.format
73  * @tc.type: FUNC
74  */
75 HWTEST_F(IntlTest, IntlFuncTest001, TestSize.Level1)
76 {
77     string locale = "zh-CN-u-hc-h12";
78     string expects = "公元1970年1月1日星期四 上午8:20:34";
79     vector<string> locales;
80     locales.push_back("jessie");
81     locales.push_back(locale);
82     map<string, string> options = { { "year", "numeric" },
83                                     { "month", "long" },
84                                     { "day", "numeric" },
85                                     { "hour", "numeric" },
86                                     { "minute", "2-digit" },
87                                     { "second", "numeric" },
88                                     { "weekday", "long" },
89                                     { "era", "short"} };
90     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
91     if (!dateFormat) {
92         EXPECT_TRUE(false);
93         return;
94     }
95     int64_t milliseconds = 1234567;
96     string out = dateFormat->Format(milliseconds);
97     EXPECT_EQ(out, expects);
98     EXPECT_EQ(dateFormat->GetYear(), "numeric");
99     EXPECT_EQ(dateFormat->GetMonth(), "long");
100     EXPECT_EQ(dateFormat->GetDay(), "numeric");
101     EXPECT_EQ(dateFormat->GetHour(), "numeric");
102     EXPECT_EQ(dateFormat->GetMinute(), "2-digit");
103     EXPECT_EQ(dateFormat->GetSecond(), "numeric");
104     EXPECT_EQ(dateFormat->GetWeekday(), "long");
105     EXPECT_EQ(dateFormat->GetEra(), "short");
106     EXPECT_EQ(dateFormat->GetHourCycle(), "h12");
107     delete dateFormat;
108 }
109 
110 /**
111  * @tc.name: IntlFuncTest002
112  * @tc.desc: Test Intl LocaleInfo
113  * @tc.type: FUNC
114  */
115 HWTEST_F(IntlTest, IntlFuncTest002, TestSize.Level0)
116 {
117     string locale = "ja-Jpan-JP-u-ca-japanese-hc-h12-co-emoji";
118     map<string, string> options = { { "hourCycle", "h11" },
119                                     { "numeric", "true" },
120                                     { "numberingSystem", "jpan" } };
121     LocaleInfo *loc = new (std::nothrow) LocaleInfo(locale, options);
122     if (!loc) {
123         EXPECT_TRUE(false);
124         return;
125     }
126     EXPECT_EQ(loc->GetLanguage(), "ja");
127     EXPECT_EQ(loc->GetScript(), "Jpan");
128     EXPECT_EQ(loc->GetRegion(), "JP");
129     EXPECT_EQ(loc->GetBaseName(), "ja-Jpan-JP");
130     EXPECT_EQ(loc->GetCalendar(), "japanese");
131     EXPECT_EQ(loc->GetHourCycle(), "h11");
132     EXPECT_EQ(loc->GetNumberingSystem(), "jpan");
133     EXPECT_EQ(loc->Minimize(), "ja-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true");
134     EXPECT_EQ(loc->Maximize(), "ja-Jpan-JP-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true");
135     EXPECT_EQ(loc->GetNumeric(), "true");
136     EXPECT_EQ(loc->GetCaseFirst(), "");
137     delete loc;
138 }
139 
140 /**
141  * @tc.name: IntlFuncTest003
142  * @tc.desc: Test Intl LocaleInfo
143  * @tc.type: FUNC
144  */
145 HWTEST_F(IntlTest, IntlFuncTest003, TestSize.Level1)
146 {
147     string locale = "en-GB";
148     LocaleInfo *loc = new (std::nothrow) LocaleInfo(locale);
149     if (!loc) {
150         EXPECT_TRUE(false);
151         return;
152     }
153     string language = "en";
154     string script = "";
155     string region = "GB";
156     string baseName = "en-GB";
157     EXPECT_EQ(loc->GetLanguage(), language);
158     EXPECT_EQ(loc->GetScript(), script);
159     EXPECT_EQ(loc->GetRegion(), region);
160     EXPECT_EQ(loc->GetBaseName(), baseName);
161     locale = "ja-u-hc-h12-nu-Jpan-JP-kf-japanese-co-emoji-kn-true";
162     LocaleInfo *localeInfo = new (std::nothrow) LocaleInfo(locale);
163     EXPECT_EQ(localeInfo->GetBaseName(), "ja");
164     delete localeInfo;
165     delete loc;
166 }
167 
168 /**
169  * @tc.name: IntlFuncTest004
170  * @tc.desc: Test Intl DateTimeFormat.format
171  * @tc.type: FUNC
172  */
173 HWTEST_F(IntlTest, IntlFuncTest004, TestSize.Level1)
174 {
175     string locale = "en-GB";
176     string expects = "2 January 1970, 18:17 – 12 January 1970, 18:20";
177     vector<string> locales;
178     locales.push_back(locale);
179     string dateStyle = "long";
180     string timeStyle = "short";
181     map<string, string> options = { { "dateStyle", dateStyle },
182                                     { "timeStyle", timeStyle } };
183     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
184     if (!dateFormat) {
185         EXPECT_TRUE(false);
186         return;
187     }
188     int64_t fromMilliseconds = 123456789;
189     int64_t toMilliseconds = 987654321;
190     string out = dateFormat->FormatRange(fromMilliseconds, toMilliseconds);
191     EXPECT_EQ(out, expects);
192     EXPECT_EQ(dateFormat->GetDateStyle(), dateStyle);
193     EXPECT_EQ(dateFormat->GetTimeStyle(), timeStyle);
194     delete dateFormat;
195 }
196 
197 /**
198  * @tc.name: IntlFuncTest005
199  * @tc.desc: Test Intl DateTimeFormat.format
200  * @tc.type: FUNC
201  */
202 HWTEST_F(IntlTest, IntlFuncTest005, TestSize.Level1)
203 {
204     string locale = "ja";
205     string expects = "1970年1月2日金曜日";
206     vector<string> locales;
207     locales.push_back(locale);
208     map<string, string> options = { { "year", "numeric" },
209                                     { "month", "long" },
210                                     { "day", "numeric" },
211                                     { "weekday", "long"} };
212     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
213     if (!dateFormat) {
214         EXPECT_TRUE(false);
215         return;
216     }
217     int64_t milliseconds = 123456789;
218     string out = dateFormat->Format(milliseconds);
219     EXPECT_EQ(out, expects);
220     int64_t fromMilliseconds = 123456789;
221     int64_t toMilliseconds = 987654321;
222     expects = "1970/01/02(金曜日)~1970/01/12(月曜日)";
223     out = dateFormat->FormatRange(fromMilliseconds, toMilliseconds);
224     EXPECT_EQ(out, expects);
225     delete dateFormat;
226 }
227 
228 /**
229  * @tc.name: IntlFuncTest006
230  * @tc.desc: Test Intl NumberFormat.format
231  * @tc.type: FUNC
232  */
233 HWTEST_F(IntlTest, IntlFuncTest006, TestSize.Level1)
234 {
235     string locale = "en-IN";
236     string expects = "+1,23,456.79 euros";
237     vector<string> locales;
238     locales.push_back(locale);
239     string useGrouping = "true";
240     string minimumIntegerDigits = "7";
241     string maximumFractionDigits = "2";
242     string style = "currency";
243     string currency = "EUR";
244     map<string, string> options = { { "useGrouping", useGrouping },
245                                     { "style", style },
246                                     { "currency", currency },
247                                     { "currencyDisplay", "name" },
248                                     { "currencySign", "accounting" },
249                                     { "signDisplay", "always" } };
250     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
251     if (!numFmt) {
252         EXPECT_TRUE(false);
253         return;
254     }
255     string out = numFmt->Format(123456.789);
256     EXPECT_EQ(out, expects);
257     EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
258     EXPECT_EQ(numFmt->GetStyle(), style);
259     EXPECT_EQ(numFmt->GetCurrency(), currency);
260     delete numFmt;
261 }
262 
263 /**
264  * @tc.name: IntlFuncTest007
265  * @tc.desc: Test Intl NumberFormat.format
266  * @tc.type: FUNC
267  */
268 HWTEST_F(IntlTest, IntlFuncTest007, TestSize.Level1)
269 {
270     string locale = "zh-CN";
271     string expects = "0,123,456.79米";
272     vector<string> locales;
273     locales.push_back("ban");
274     locales.push_back(locale);
275     string minimumIntegerDigits = "7";
276     string maximumFractionDigits = "2";
277     string style = "unit";
278     map<string, string> options = { { "style", style },
279                                     { "minimumIntegerDigits", minimumIntegerDigits },
280                                     { "maximumFractionDigits", maximumFractionDigits },
281                                     { "unit", "meter" },
282                                     { "unitDisplay", "long"} };
283     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
284     if (!numFmt) {
285         EXPECT_TRUE(false);
286         return;
287     }
288     string out = numFmt->Format(123456.789);
289     EXPECT_EQ(out, expects);
290     EXPECT_EQ(numFmt->GetStyle(), style);
291     delete numFmt;
292 }
293 
294 /**
295  * @tc.name: IntlFuncTest008
296  * @tc.desc: Test Intl NumberFormat.format
297  * @tc.type: FUNC
298  */
299 HWTEST_F(IntlTest, IntlFuncTest008, TestSize.Level1)
300 {
301     string locale = "en-CN";
302     string expects = "12,345,678.9%";
303     vector<string> locales;
304     locales.push_back(locale);
305     string minimumIntegerDigits = "7";
306     string maximumFractionDigits = "2";
307     string style = "percent";
308     map<string, string> options = { { "style", style },
309                                     { "minimumIntegerDigits", minimumIntegerDigits },
310                                     { "maximumFractionDigits", maximumFractionDigits } };
311     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
312     if (!numFmt) {
313         EXPECT_TRUE(false);
314         return;
315     }
316     string out = numFmt->Format(123456.789);
317     EXPECT_EQ(out, expects);
318     EXPECT_EQ(numFmt->GetStyle(), style);
319     delete numFmt;
320 }
321 
322 /**
323  * @tc.name: IntlFuncTest009
324  * @tc.desc: Test Intl NumberFormat.format
325  * @tc.type: FUNC
326  */
327 HWTEST_F(IntlTest, IntlFuncTest009, TestSize.Level1)
328 {
329     string locale = "en-CN";
330     string expects = "0,123,456.79";
331     vector<string> locales;
332     locales.push_back(locale);
333     string minimumIntegerDigits = "7";
334     string maximumFractionDigits = "2";
335     string style = "decimal";
336     map<string, string> options = { { "style", style },
337                                     { "minimumIntegerDigits", minimumIntegerDigits },
338                                     { "maximumFractionDigits", maximumFractionDigits } };
339     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
340     if (!numFmt) {
341         EXPECT_TRUE(false);
342         return;
343     }
344     string out = numFmt->Format(123456.789);
345     EXPECT_EQ(out, expects);
346     EXPECT_EQ(numFmt->GetStyle(), style);
347     options = { { "style", "unit" },
348                 { "unit", "meter" },
349                 { "currency", "USD" },
350                 { "currencyDisplay", "symbol" },
351                 { "compactDisplay", "long" },
352                 { "useGrouping", "true" },
353                 { "unitUsage", "length-person" },
354                 { "unitDisplay", "long" } };
355     NumberFormat *numFormat = new (std::nothrow) NumberFormat(locales, options);
356     map<string, string> res;
357     numFormat->GetResolvedOptions(res);
358     delete numFormat;
359     delete numFmt;
360 }
361 
362 /**
363  * @tc.name: IntlFuncTest0010
364  * @tc.desc: Test Intl NumberFormat.format
365  * @tc.type: FUNC
366  */
367 HWTEST_F(IntlTest, IntlFuncTest010, TestSize.Level1)
368 {
369     string locale = "en-CN";
370     string expects = "1.234568E5";
371     vector<string> locales;
372     locales.push_back(locale);
373     string style = "decimal";
374     map<string, string> options = { { "style", style },
375                                     { "notation", "scientific" } };
376     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
377     if (!numFmt) {
378         EXPECT_TRUE(false);
379         return;
380     }
381     string out = numFmt->Format(123456.789);
382     EXPECT_EQ(out, expects);
383     EXPECT_EQ(numFmt->GetStyle(), style);
384     delete numFmt;
385 }
386 
387 /**
388  * @tc.name: IntlFuncTest0011
389  * @tc.desc: Test Intl NumberFormat.format
390  * @tc.type: FUNC
391  */
392 HWTEST_F(IntlTest, IntlFuncTest011, TestSize.Level1)
393 {
394     string locale = "en-CN";
395     string expects = "123 thousand";
396     vector<string> locales;
397     locales.push_back(locale);
398     string style = "decimal";
399     map<string, string> options = { { "style", style },
400                                     { "notation", "compact" },
401                                     { "compactDisplay", "long" } };
402     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
403     if (!numFmt) {
404         EXPECT_TRUE(false);
405         return;
406     }
407     string out = numFmt->Format(123456.789);
408     EXPECT_EQ(out, expects);
409     EXPECT_EQ(numFmt->GetStyle(), style);
410     delete numFmt;
411 }
412 
413 /**
414  * @tc.name: IntlFuncTest0012
415  * @tc.desc: Test Intl DateTimeFormat
416  * @tc.type: FUNC
417  */
418 HWTEST_F(IntlTest, IntlFuncTest0012, TestSize.Level1)
419 {
420     string locale = "en";
421     map<string, string> options = {};
422     vector<string> locales;
423     locales.push_back(locale);
424     std::string expects = "3/11/82";
425     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
426     if (!dateFormat) {
427         EXPECT_TRUE(false);
428         return;
429     }
430     int64_t milliseconds = 123456789123456;
431     string out = dateFormat->Format(milliseconds);
432     EXPECT_EQ(out, expects);
433     options = {
434         { "dateStyle", "long" },
435         { "hourCycle", "h11" }
436     };
437     DateTimeFormat *dateFormatH11 = new (std::nothrow) DateTimeFormat(locales, options);
438     options.insert({ "hourCycle", "h12" });
439     DateTimeFormat *dateFormatH12 = new (std::nothrow) DateTimeFormat(locales, options);
440     options.insert({ "hourCycle", "h23" });
441     DateTimeFormat *dateFormatH23 = new (std::nothrow) DateTimeFormat(locales, options);
442     options.insert({ "hourCycle", "h24" });
443     DateTimeFormat *dateFormatH24 = new (std::nothrow) DateTimeFormat(locales, options);
444     delete dateFormatH11;
445     delete dateFormatH12;
446     delete dateFormatH23;
447     delete dateFormatH24;
448     locales.clear();
449     DateTimeFormat *dateFormatEmpty = new (std::nothrow) DateTimeFormat(locales, options);
450     locales.push_back("fake locale");
451     options = {};
452     DateTimeFormat *dateFormatFake = new (std::nothrow) DateTimeFormat(locales, options);
453     options.insert({ "dateStyle", "long" });
454     DateTimeFormat *dateFormatFake2 = new (std::nothrow) DateTimeFormat(locales, options);
455     delete dateFormatEmpty;
456     delete dateFormatFake;
457     delete dateFormatFake2;
458     delete dateFormat;
459 }
460 
461 /**
462  * @tc.name: IntlFuncTest0013
463  * @tc.desc: Test Intl LocaleInfo
464  * @tc.type: FUNC
465  */
466 HWTEST_F(IntlTest, IntlFuncTest0013, TestSize.Level1)
467 {
468     string locale = "en-CN";
469     vector<string> locales;
470     locales.push_back(locale);
471     map<string, string> options = {};
472     std::string expects = "123,456.789";
473     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
474     if (!numFmt) {
475         EXPECT_TRUE(false);
476         return;
477     }
478     string out = numFmt->Format(123456.789);
479     EXPECT_EQ(out, expects);
480     delete numFmt;
481 }
482 
483 /**
484  * @tc.name: IntlFuncTest0014
485  * @tc.desc: Test Intl LocaleInfo
486  * @tc.type: FUNC
487  */
488 HWTEST_F(IntlTest, IntlFuncTest0014, TestSize.Level1)
489 {
490     string locale = "zh-CN-u-hc-h12";
491     string expects = "北美太平洋标准时间";
492     vector<string> locales;
493     locales.push_back("jessie");
494     locales.push_back(locale);
495     map<string, string> options = { { "timeZone", "America/Los_Angeles"  }, { "timeZoneName", "long" } };
496     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
497     if (!dateFormat) {
498         EXPECT_TRUE(false);
499         return;
500     }
501     int64_t milliseconds = 123456789;
502     string out = dateFormat->Format(milliseconds);
503     EXPECT_TRUE(out.find(expects) != out.npos);
504     delete dateFormat;
505 }
506 
507 /**
508  * @tc.name: IntlFuncTest0015
509  * @tc.desc: Test Intl LocaleInfo
510  * @tc.type: FUNC
511  */
512 HWTEST_F(IntlTest, IntlFuncTest0015, TestSize.Level1)
513 {
514     string locale = "zh-CN-u-hc-h12";
515     vector<string> locales;
516     locales.push_back("jessie");
517     locales.push_back(locale);
518     map<string, string> options = { { "timeZone", "America/Los_Angeles"  }, { "timeZoneName", "long" } };
519     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
520     if (!dateFormat) {
521         EXPECT_TRUE(false);
522         return;
523     }
524     EXPECT_EQ(dateFormat->GetTimeZone(), "America/Los_Angeles");
525     EXPECT_EQ(dateFormat->GetTimeZoneName(), "long");
526     delete dateFormat;
527 }
528 
529 /**
530  * @tc.name: IntlFuncTest0016
531  * @tc.desc: Test Intl Collator
532  * @tc.type: FUNC
533  */
534 HWTEST_F(IntlTest, IntlFuncTest0016, TestSize.Level1)
535 {
536     // normal test case
537     vector<string> locales;
538     locales.push_back("en-US");
539     map<string, string> inputOptions;
540     Collator *collator = new Collator(locales, inputOptions);
541     const string param1 = "abc";
542     const string param2 = "cba";
543     CompareResult result = collator->Compare(param1, param2);
544     EXPECT_EQ(result, CompareResult::SMALLER);
545 
546     map<string, string> options;
547     collator->ResolvedOptions(options);
548     EXPECT_EQ(options.size(), 8);
549     map<string, string>::iterator it = options.find("localeMatcher");
550     if (it != options.end()) {
551         EXPECT_EQ(it->second, "best fit");
552     }
553     it = options.find("locale");
554     if (it != options.end()) {
555         EXPECT_EQ(it->second, "en-US");
556     }
557     it = options.find("usage");
558     if (it != options.end()) {
559         EXPECT_EQ(it->second, "sort");
560     }
561     it = options.find("sensitivity");
562     if (it != options.end()) {
563         EXPECT_EQ(it->second, "variant");
564     }
565     it = options.find("ignorePunctuation");
566     if (it != options.end()) {
567         EXPECT_EQ(it->second, "false");
568     }
569     it = options.find("numeric");
570     if (it != options.end()) {
571         EXPECT_EQ(it->second, "false");
572     }
573     it = options.find("caseFirst");
574     if (it != options.end()) {
575         EXPECT_EQ(it->second, "false");
576     }
577     it = options.find("collation");
578     if (it != options.end()) {
579         EXPECT_EQ(it->second, "default");
580     }
581     delete collator;
582 }
583 
584 /**
585  * @tc.name: IntlFuncTest0017
586  * @tc.desc: Test Intl Collator
587  * @tc.type: FUNC
588  */
589 HWTEST_F(IntlTest, IntlFuncTest0017, TestSize.Level1)
590 {
591     // normal test case
592     vector<string> locales;
593     locales.push_back("zh-Hans");
594     locales.push_back("en-US");
595     map<string, string> inputOptions = {
596         { "localeMatcher", "lookup" },
597         { "usage", "search"},
598         { "sensitivity", "case"},
599         { "ignorePunctuation", "true" },
600         { "collation", "pinyin"},
601         { "numeric", "true"},
602         { "caseFirst", "upper"}
603     };
604     Collator *collator = new Collator(locales, inputOptions);
605     const string param1 = "啊";
606     const string param2 = "播";
607     CompareResult result = collator->Compare(param1, param2);
608     EXPECT_EQ(result, CompareResult::SMALLER);
609 
610     map<string, string> options;
611     collator->ResolvedOptions(options);
612     EXPECT_EQ(options.size(), 8);
613     map<string, string>::iterator it = options.find("localeMatcher");
614     if (it != options.end()) {
615         EXPECT_EQ(it->second, "lookup");
616     }
617     it = options.find("locale");
618     if (it != options.end()) {
619         EXPECT_EQ(it->second, "zh-Hans");
620     }
621     it = options.find("usage");
622     if (it != options.end()) {
623         EXPECT_EQ(it->second, "search");
624     }
625     it = options.find("sensitivity");
626     if (it != options.end()) {
627         EXPECT_EQ(it->second, "case");
628     }
629     delete collator;
630 }
631 
632 /**
633  * @tc.name: IntlFuncTest0018
634  * @tc.desc: Test Intl Collator
635  * @tc.type: FUNC
636  */
637 HWTEST_F(IntlTest, IntlFuncTest0018, TestSize.Level1)
638 {
639     // normal test case
640     vector<string> locales;
641     locales.push_back("zh-Hans");
642     locales.push_back("en-US");
643     map<string, string> inputOptions = {
644         { "ignorePunctuation", "true" },
645         { "collation", "pinyin"},
646         { "numeric", "true"},
647         { "caseFirst", "upper"}
648     };
649     Collator *collator = new Collator(locales, inputOptions);
650     map<string, string> options;
651     collator->ResolvedOptions(options);
652     map<string, string>::iterator it = options.find("ignorePunctuation");
653     if (it != options.end()) {
654         EXPECT_EQ(it->second, "true");
655     }
656     it = options.find("numeric");
657     if (it != options.end()) {
658         EXPECT_EQ(it->second, "true");
659     }
660     it = options.find("caseFirst");
661     if (it != options.end()) {
662         EXPECT_EQ(it->second, "upper");
663     }
664     it = options.find("collation");
665     if (it != options.end()) {
666         EXPECT_EQ(it->second, "pinyin");
667     }
668     inputOptions = {
669         { "sensitivity", "base"},
670         { "caseFirst", "lower"}
671     };
672     Collator *collator2 = new Collator(locales, inputOptions);
673     inputOptions = {
674         { "sensitivity", "accent"},
675         { "caseFirst", "lower"}
676     };
677     Collator *collator3 = new Collator(locales, inputOptions);
678     delete collator;
679     delete collator2;
680     delete collator3;
681 }
682 
683 /**
684  * @tc.name: IntlFuncTest0019
685  * @tc.desc: Test Intl Collator
686  * @tc.type: FUNC
687  */
688 HWTEST_F(IntlTest, IntlFuncTest0019, TestSize.Level1)
689 {
690     // abnormal test case
691     vector<string> locales;
692     locales.push_back("fake locale");
693     map<string, string> inputOptions = {
694         { "localeMatcher", "fake value" },
695         { "usage", "fake value"},
696         { "sensitivity", "fake value"},
697         { "ignorePunctuation", "fake value" },
698         { "collation", "fake value"},
699         { "numeric", "fake value"},
700         { "caseFirst", "fake value"},
701         { "fake key", "fake value"}
702     };
703     Collator *collator = new Collator(locales, inputOptions);
704     const string param1 = "abc";
705     const string param2 = "cba";
706     CompareResult result = collator->Compare(param1, param2);
707     EXPECT_EQ(result, CompareResult::SMALLER);
708 
709     map<string, string> options;
710     collator->ResolvedOptions(options);
711     EXPECT_EQ(options.size(), 8);
712     map<string, string>::iterator it = options.find("localeMatcher");
713     if (it != options.end()) {
714         EXPECT_EQ(it->second, "fake value");
715     }
716     std::string systemLocale = LocaleConfig::GetSystemLocale();
717     it = options.find("locale");
718     if (it != options.end()) {
719         EXPECT_EQ(it->second, systemLocale);
720     }
721     it = options.find("usage");
722     if (it != options.end()) {
723         EXPECT_EQ(it->second, "fake value");
724     }
725     it = options.find("sensitivity");
726     if (it != options.end()) {
727         EXPECT_EQ(it->second, "fake value");
728     }
729     delete collator;
730 }
731 
732 /**
733  * @tc.name: IntlFuncTest0020
734  * @tc.desc: Test Intl Collator
735  * @tc.type: FUNC
736  */
737 HWTEST_F(IntlTest, IntlFuncTest0020, TestSize.Level1)
738 {
739     // abnormal test case
740     vector<string> locales;
741     locales.push_back("fake locale");
742     map<string, string> inputOptions = {
743         { "ignorePunctuation", "fake value" },
744         { "collation", "fake value"},
745         { "numeric", "fake value"},
746         { "caseFirst", "fake value"},
747         { "fake key", "fake value"}
748     };
749     Collator *collator = new Collator(locales, inputOptions);
750     map<string, string> options;
751     collator->ResolvedOptions(options);
752     map<string, string>::iterator it = options.find("ignorePunctuation");
753     if (it != options.end()) {
754         EXPECT_EQ(it->second, "fake value");
755     }
756     it = options.find("numeric");
757     if (it != options.end()) {
758         EXPECT_EQ(it->second, "fake value");
759     }
760     it = options.find("caseFirst");
761     if (it != options.end()) {
762         EXPECT_EQ(it->second, "fake value");
763     }
764     it = options.find("collation");
765     if (it != options.end()) {
766         EXPECT_EQ(it->second, "default");
767     }
768     delete collator;
769 }
770 
771 /**
772  * @tc.name: IntlFuncTest0021
773  * @tc.desc: Test Intl PluralRules
774  * @tc.type: FUNC
775  */
776 HWTEST_F(IntlTest, IntlFuncTest0021, TestSize.Level1)
777 {
778     // normal test case
779     vector<string> locales;
780     locales.push_back("en-US");
781     map<string, string> options;
782     PluralRules *plurals = new PluralRules(locales, options);
783     string res = plurals->Select(0);
784     EXPECT_EQ(res, "other");
785     res = plurals->Select(1);
786     EXPECT_EQ(res, "one");
787     res = plurals->Select(2);
788     EXPECT_EQ(res, "other");
789     res = plurals->Select(5);
790     EXPECT_EQ(res, "other");
791     res = plurals->Select(20);
792     EXPECT_EQ(res, "other");
793     res = plurals->Select(200);
794     EXPECT_EQ(res, "other");
795     res = plurals->Select(12.34);
796     EXPECT_EQ(res, "other");
797     delete plurals;
798 }
799 
800 /**
801  * @tc.name: IntlFuncTest0022
802  * @tc.desc: Test Intl PluralRules
803  * @tc.type: FUNC
804  */
805 HWTEST_F(IntlTest, IntlFuncTest0022, TestSize.Level1)
806 {
807     // normal test case
808     vector<string> locales;
809     locales.push_back("ar");
810     map<string, string> options;
811     PluralRules *plurals = new PluralRules(locales, options);
812     string res = plurals->Select(0);
813     EXPECT_EQ(res, "zero");
814     res = plurals->Select(1);
815     EXPECT_EQ(res, "one");
816     res = plurals->Select(2);
817     EXPECT_EQ(res, "two");
818     res = plurals->Select(5);
819     EXPECT_EQ(res, "few");
820     res = plurals->Select(20);
821     EXPECT_EQ(res, "many");
822     res = plurals->Select(200);
823     EXPECT_EQ(res, "other");
824     res = plurals->Select(12.34);
825     EXPECT_EQ(res, "other");
826     options = {
827         { "localeMatcher", "best fit" },
828         { "type", "cardinal" },
829         { "minimumIntegerDigits", "1" },
830         { "minimumFractionDigits", "0" },
831         { "maximumFractionDigits", "21" },
832     };
833     PluralRules *pluralRules = new PluralRules(locales, options);
834     delete pluralRules;
835     delete plurals;
836 }
837 
838 /**
839  * @tc.name: IntlFuncTest0023
840  * @tc.desc: Test Intl PluralRules
841  * @tc.type: FUNC
842  */
843 HWTEST_F(IntlTest, IntlFuncTest0023, TestSize.Level1)
844 {
845     // normal test case
846     vector<string> locales;
847     locales.push_back("ar");
848     map<string, string> options = {
849         { "localeMatcher", "best fit" },
850         { "type", "cardinal" },
851         { "minimumIntegerDigits", "1" },
852         { "minimumFractionDigits", "0" },
853         { "maximumFractionDigits", "21" },
854         { "minimumSignificantDigits", "21" },
855         { "maximumSignificantDigits", "21" },
856     };
857     PluralRules *plurals = new PluralRules(locales, options);
858     string res = plurals->Select(0);
859     EXPECT_EQ(res, "zero");
860     res = plurals->Select(1);
861     EXPECT_EQ(res, "one");
862     res = plurals->Select(2);
863     EXPECT_EQ(res, "two");
864     res = plurals->Select(5);
865     EXPECT_EQ(res, "few");
866     res = plurals->Select(20);
867     EXPECT_EQ(res, "many");
868     res = plurals->Select(200);
869     EXPECT_EQ(res, "other");
870     res = plurals->Select(12.34);
871     EXPECT_EQ(res, "other");
872     delete plurals;
873 }
874 
875 /**
876  * @tc.name: IntlFuncTest0024
877  * @tc.desc: Test Intl PluralRules
878  * @tc.type: FUNC
879  */
880 HWTEST_F(IntlTest, IntlFuncTest0024, TestSize.Level1)
881 {
882     // abnormal test cast
883     // normal test case
884     vector<string> locales;
885     locales.push_back("fake_locale");
886     map<string, string> options = {
887         { "fake_localeMatcher", "best fit" },
888         { "type", "fake_cardinal" },
889         { "minimumIntegerDigits", "11111" },
890         { "minimumFractionDigits", "-111" },
891         { "maximumFractionDigits", "-111" },
892         { "minimumSignificantDigits", "11111" },
893         { "maximumSignificantDigits", "11111" },
894     };
895     PluralRules *plurals = new PluralRules(locales, options);
896     string res = plurals->Select(0);
897     EXPECT_EQ(res, "other");
898     res = plurals->Select(1);
899     EXPECT_EQ(res, "other");
900     res = plurals->Select(2);
901     EXPECT_EQ(res, "other");
902     res = plurals->Select(5);
903     EXPECT_EQ(res, "other");
904     res = plurals->Select(20);
905     EXPECT_EQ(res, "other");
906     res = plurals->Select(200);
907     EXPECT_EQ(res, "other");
908     res = plurals->Select(12.34);
909     EXPECT_EQ(res, "other");
910     delete plurals;
911 }
912 
913 /**
914  * @tc.name: IntlFuncTest0025
915  * @tc.desc: Test Intl RelativeTimeFormat
916  * @tc.type: FUNC
917  */
918 HWTEST_F(IntlTest, IntlFuncTest0025, TestSize.Level1)
919 {
920     vector<string> locales;
921     locales.push_back("en-US");
922     map<string, string> options;
923     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
924 
925     double number = 2022;
926     string unit = "year";
927     string res = formatter->Format(number, unit);
928     EXPECT_EQ(res, "in 2,022 years");
929     vector<vector<string>> timeVector;
930     formatter->FormatToParts(number, unit, timeVector);
931     EXPECT_EQ(timeVector.size(), 5);
932 
933     number = 3;
934     unit = "quarter";
935     res = formatter->Format(number, unit);
936     EXPECT_EQ(res, "in 3 quarters");
937     formatter->FormatToParts(number, unit, timeVector);
938     EXPECT_EQ(timeVector.size(), 8);
939 
940     number = 11;
941     unit = "month";
942     res = formatter->Format(number, unit);
943     EXPECT_EQ(res, "in 11 months");
944     formatter->FormatToParts(number, unit, timeVector);
945     EXPECT_EQ(timeVector.size(), 11);
946 
947     number = 2;
948     unit = "week";
949     res = formatter->Format(number, unit);
950     EXPECT_EQ(res, "in 2 weeks");
951     formatter->FormatToParts(number, unit, timeVector);
952     EXPECT_EQ(timeVector.size(), 14);
953 
954     number = 18;
955     unit = "day";
956     res = formatter->Format(number, unit);
957     EXPECT_EQ(res, "in 18 days");
958     formatter->FormatToParts(number, unit, timeVector);
959     EXPECT_EQ(timeVector.size(), 17);
960     delete formatter;
961 }
962 
963 /**
964  * @tc.name: IntlFuncTest0026
965  * @tc.desc: Test Intl RelativeTimeFormat
966  * @tc.type: FUNC
967  */
968 HWTEST_F(IntlTest, IntlFuncTest0026, TestSize.Level1)
969 {
970     vector<string> locales;
971     locales.push_back("en-US");
972     map<string, string> options;
973     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
974 
975     double number = 23;
976     string unit = "hour";
977     string res = formatter->Format(number, unit);
978     EXPECT_EQ(res, "in 23 hours");
979     vector<vector<string>> timeVector;
980     formatter->FormatToParts(number, unit, timeVector);
981     EXPECT_EQ(timeVector.size(), 3);
982 
983     number = 59;
984     unit = "minute";
985     res = formatter->Format(number, unit);
986     EXPECT_EQ(res, "in 59 minutes");
987     formatter->FormatToParts(number, unit, timeVector);
988     EXPECT_EQ(timeVector.size(), 6);
989 
990     number = 1;
991     unit = "second";
992     res = formatter->Format(number, unit);
993     EXPECT_EQ(res, "in 1 second");
994     formatter->FormatToParts(number, unit, timeVector);
995     EXPECT_EQ(timeVector.size(), 9);
996 
997     delete formatter;
998 }
999 
1000 /**
1001  * @tc.name: IntlFuncTest0027
1002  * @tc.desc: Test Intl RelativeTimeFormat
1003  * @tc.type: FUNC
1004  */
1005 HWTEST_F(IntlTest, IntlFuncTest0027, TestSize.Level1)
1006 {
1007     vector<string> locales;
1008     locales.push_back("zh-Hans");
1009     map<string, string> options = {
1010         { "localeMatcher", "best fit" },
1011         { "numeric", "auto" },
1012         { "style", "long" }
1013     };
1014     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
1015 
1016     double number = 2022;
1017     string unit = "year";
1018     string res = formatter->Format(number, unit);
1019     EXPECT_EQ(res, "2,022年后");
1020     vector<vector<string>> timeVector;
1021     formatter->FormatToParts(number, unit, timeVector);
1022     EXPECT_EQ(timeVector.size(), 4);
1023 
1024     number = 3;
1025     unit = "quarter";
1026     res = formatter->Format(number, unit);
1027     EXPECT_EQ(res, "3个季度后");
1028     formatter->FormatToParts(number, unit, timeVector);
1029     EXPECT_EQ(timeVector.size(), 6);
1030 
1031     number = 11;
1032     unit = "month";
1033     res = formatter->Format(number, unit);
1034     EXPECT_EQ(res, "11个月后");
1035     formatter->FormatToParts(number, unit, timeVector);
1036     EXPECT_EQ(timeVector.size(), 8);
1037 
1038     number = 2;
1039     unit = "week";
1040     res = formatter->Format(number, unit);
1041     EXPECT_EQ(res, "2周后");
1042     formatter->FormatToParts(number, unit, timeVector);
1043     EXPECT_EQ(timeVector.size(), 10);
1044     delete formatter;
1045 }
1046 
1047 /**
1048  * @tc.name: IntlFuncTest0028
1049  * @tc.desc: Test Intl RelativeTimeFormat
1050  * @tc.type: FUNC
1051  */
1052 HWTEST_F(IntlTest, IntlFuncTest0028, TestSize.Level1)
1053 {
1054     vector<string> locales;
1055     locales.push_back("zh-Hans");
1056     map<string, string> options = {
1057         { "localeMatcher", "lookup" },
1058         { "numeric", "auto" },
1059         { "style", "long" }
1060     };
1061     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
1062 
1063     double number = 18;
1064     string unit = "day";
1065     string res = formatter->Format(number, unit);
1066     EXPECT_EQ(res, "18天后");
1067     vector<vector<string>> timeVector;
1068     formatter->FormatToParts(number, unit, timeVector);
1069     EXPECT_EQ(timeVector.size(), 2);
1070 
1071     number = 23;
1072     unit = "hour";
1073     res = formatter->Format(number, unit);
1074     EXPECT_EQ(res, "23小时后");
1075     formatter->FormatToParts(number, unit, timeVector);
1076     EXPECT_EQ(timeVector.size(), 4);
1077 
1078     number = 59;
1079     unit = "minute";
1080     res = formatter->Format(number, unit);
1081     EXPECT_EQ(res, "59分钟后");
1082     formatter->FormatToParts(number, unit, timeVector);
1083     EXPECT_EQ(timeVector.size(), 6);
1084 
1085     number = 1;
1086     unit = "second";
1087     res = formatter->Format(number, unit);
1088     EXPECT_EQ(res, "1秒钟后");
1089     formatter->FormatToParts(number, unit, timeVector);
1090     EXPECT_EQ(timeVector.size(), 8);
1091 
1092     delete formatter;
1093 }
1094 
1095 /**
1096  * @tc.name: IntlFuncTest0029
1097  * @tc.desc: Test Intl RelativeTimeFormatter
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(IntlTest, IntlFuncTest0029, TestSize.Level1)
1101 {
1102     vector<string> locales;
1103     locales.push_back("xxxx");
1104     locales.push_back("zh-Hans");
1105     map<string, string> options = {
1106         { "localeMatcher", "best fit" },
1107         { "numeric", "auto" },
1108         { "style", "long" }
1109     };
1110     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
1111     map<string, string> res;
1112     formatter->GetResolvedOptions(res);
1113     EXPECT_EQ(res.size(), 4);
1114 
1115     map<string, string>::iterator it = res.find("locale");
1116     if (it != res.end()) {
1117         EXPECT_EQ(it->second, "zh-Hans");
1118     }
1119     it = res.find("style");
1120     if (it != res.end()) {
1121         EXPECT_EQ(it->second, "long");
1122     }
1123     it = res.find("numeric");
1124     if (it != res.end()) {
1125         EXPECT_EQ(it->second, "auto");
1126     }
1127     it = res.find("numberingSystem");
1128     if (it != res.end()) {
1129         EXPECT_EQ(it->second, "latn");
1130     }
1131     delete formatter;
1132 }
1133 
1134 /**
1135  * @tc.name: IntlFuncTest0030
1136  * @tc.desc: Test Intl NumberFormat
1137  * @tc.type: FUNC
1138  */
1139 HWTEST_F(IntlTest, IntlFuncTest0030, TestSize.Level1)
1140 {
1141     vector<string> locales;
1142     locales.push_back("en-US");
1143     map<string, string> options;
1144     NumberFormat *formatter = new NumberFormat(locales, options);
1145 
1146     string res = formatter->Format(123);
1147     EXPECT_EQ(res, "123");
1148     res = formatter->Format(123.456);
1149     EXPECT_EQ(res, "123.456");
1150 
1151     delete formatter;
1152 }
1153 
1154 /**
1155  * @tc.name: IntlFuncTest0031
1156  * @tc.desc: Test Intl NumberFormat
1157  * @tc.type: FUNC
1158  */
1159 HWTEST_F(IntlTest, IntlFuncTest0031, TestSize.Level1)
1160 {
1161     vector<string> locales;
1162     locales.push_back("zh-Hans");
1163     map<string, string> options = {
1164         { "locale", "zh-Hans" },
1165         { "currency", "EUR" },
1166         { "currencySign", "narrowSymbol" },
1167         { "currencyDisplay", "symbol" },
1168         { "unit", "meter" },
1169         { "unitDisplay", "long" },
1170         { "unitUsage", "length-person" },
1171         { "signDisplay", "always" },
1172         { "compactDisplay", "long" },
1173         { "notation", "standard" },
1174         { "localeMatcher", "lookup" },
1175         { "style", "decimal" },
1176         { "numberingSystem", "latn" },
1177         { "useGroup", "true" },
1178         { "minimumIntegerDigits", "1" },
1179         { "minimumFractionDigits", "0" },
1180         { "maximumFractionDigits", "20" },
1181         { "minimumSignificantDigits", "1" },
1182         { "maximumSignificantDigits", "20" }
1183     };
1184     NumberFormat *formatter = new NumberFormat(locales, options);
1185 
1186     string formatRes = formatter->Format(123);
1187     EXPECT_EQ(formatRes, "+123");
1188     formatRes = formatter->Format(123.456);
1189     EXPECT_EQ(formatRes, "+123.456");
1190 
1191     map<string, string> res;
1192     formatter->GetResolvedOptions(res);
1193     EXPECT_EQ(res.size(), 12);
1194     map<string, string>::iterator it = res.find("locale");
1195     if (it != res.end()) {
1196         EXPECT_EQ(it->second, "zh-Hans");
1197     }
1198     it = res.find("signDisplay");
1199     if (it != res.end()) {
1200         EXPECT_EQ(it->second, "always");
1201     }
1202     it = res.find("notation");
1203     if (it != res.end()) {
1204         EXPECT_EQ(it->second, "standard");
1205     }
1206     delete formatter;
1207 }
1208 
1209 /**
1210  * @tc.name: IntlFuncTest0032
1211  * @tc.desc: Test Intl NumberFormat
1212  * @tc.type: FUNC
1213  */
1214 HWTEST_F(IntlTest, IntlFuncTest0032, TestSize.Level1)
1215 {
1216     vector<string> locales;
1217     locales.push_back("zh-Hans");
1218     map<string, string> options = {
1219         { "locale", "zh-Hans" },
1220         { "currency", "CNY" },
1221         { "currencySign", "symbol" },
1222         { "currencyDisplay", "symbol" },
1223         { "unit", "meter" },
1224         { "unitDisplay", "long" },
1225         { "unitUsage", "length-person" },
1226         { "signDisplay", "always" },
1227         { "compactDisplay", "long" },
1228         { "notation", "standard" },
1229         { "localeMatcher", "best fit" },
1230         { "style", "decimal" },
1231         { "numberingSystem", "latn" },
1232         { "useGroup", "true" },
1233         { "minimumIntegerDigits", "1" },
1234         { "minimumFractionDigits", "0" },
1235         { "maximumFractionDigits", "21" },
1236         { "minimumSignificantDigits", "1" },
1237         { "maximumSignificantDigits", "21" }
1238     };
1239     NumberFormat *formatter = new NumberFormat(locales, options);
1240     map<string, string> res;
1241     formatter->GetResolvedOptions(res);
1242     map<string, string>::iterator it = res.find("style");
1243     if (it != res.end()) {
1244         EXPECT_EQ(it->second, "decimal");
1245     }
1246     it = res.find("numberingSystem");
1247     if (it != res.end()) {
1248         EXPECT_EQ(it->second, "latn");
1249     }
1250     it = res.find("useGrouping");
1251     if (it != res.end()) {
1252         EXPECT_EQ(it->second, "true");
1253     }
1254     it = res.find("minimumIntegerDigits");
1255     if (it != res.end()) {
1256         EXPECT_EQ(it->second, "1");
1257     }
1258     it = res.find("minimumFractionDigits");
1259     if (it != res.end()) {
1260         EXPECT_EQ(it->second, "0");
1261     }
1262     delete formatter;
1263 }
1264 
1265 /**
1266  * @tc.name: IntlFuncTest0033
1267  * @tc.desc: Test Intl NumberFormat
1268  * @tc.type: FUNC
1269  */
1270 HWTEST_F(IntlTest, IntlFuncTest0033, TestSize.Level1)
1271 {
1272     vector<string> locales;
1273     locales.push_back("zh-Hans");
1274     map<string, string> options = {
1275         { "locale", "fake locale" },
1276         { "currency", "fake currency" },
1277         { "currencySign", "fake sign" },
1278         { "currencyDisplay", "symbol" },
1279         { "unit", "meter" },
1280         { "unitDisplay", "fake value" },
1281         { "unitUsage", "length-person" },
1282         { "signDisplay", "always" },
1283         { "compactDisplay", "long" },
1284         { "notation", "fake value" },
1285         { "localeMatcher", "best fit" },
1286         { "style", "decimal" },
1287         { "numberingSystem", "latn" },
1288         { "useGroup", "fake value" },
1289         { "minimumIntegerDigits", "1" },
1290         { "minimumFractionDigits", "0" },
1291         { "maximumFractionDigits", "21" },
1292         { "minimumSignificantDigits", "1" },
1293         { "maximumSignificantDigits", "21" }
1294     };
1295     NumberFormat *formatter = new NumberFormat(locales, options);
1296     map<string, string> res;
1297     formatter->GetResolvedOptions(res);
1298     map<string, string>::iterator it = res.find("maximumFractionDigits");
1299     if (it != res.end()) {
1300         EXPECT_EQ(it->second, "21");
1301     }
1302     it = res.find("minimumSignificantDigits");
1303     if (it != res.end()) {
1304         EXPECT_EQ(it->second, "1");
1305     }
1306     it = res.find("maximumSignificantDigits");
1307     if (it != res.end()) {
1308         EXPECT_EQ(it->second, "21");
1309     }
1310     delete formatter;
1311 }
1312 
1313 /**
1314  * @tc.name: IntlFuncTest0034
1315  * @tc.desc: Test Intl NumberFormat
1316  * @tc.type: FUNC
1317  */
1318 HWTEST_F(IntlTest, IntlFuncTest0034, TestSize.Level1)
1319 {
1320     vector<string> locales;
1321     locales.push_back("en-US");
1322     map<string, string> options = {
1323         { "locale", "fake locale" },
1324         { "currency", "USD" },
1325         { "currencySign", "symbol" },
1326         { "currencyDisplay", "symbol" },
1327         { "unit", "fake unit" },
1328         { "unitDisplay", "long" },
1329         { "unitUsage", "fake usage" },
1330         { "signDisplay", "always" },
1331         { "compactDisplay", "long" },
1332         { "notation", "standard" },
1333         { "localeMatcher", "lookup" },
1334         { "style", "currency" },
1335         { "numberingSystem", "latn" },
1336         { "useGrouping", "true" },
1337         { "minimumIntegerDigits", "1" },
1338         { "minimumFractionDigits", "0" },
1339         { "maximumFractionDigits", "20" },
1340         { "minimumSignificantDigits", "1" },
1341         { "maximumSignificantDigits", "20" }
1342     };
1343     NumberFormat *formatter = new NumberFormat(locales, options);
1344     string res = formatter->Format(123);
1345     EXPECT_EQ(res, "+$123");
1346     res = formatter->Format(123.456);
1347     EXPECT_EQ(res, "+$123.456");
1348     res = formatter->GetCurrency();
1349     EXPECT_EQ(res, "USD");
1350     res = formatter->GetCurrencySign();
1351     EXPECT_EQ(res, "symbol");
1352     res = formatter->GetStyle();
1353     EXPECT_EQ(res, "currency");
1354     res = formatter->GetNumberingSystem();
1355     EXPECT_EQ(res, "latn");
1356     delete formatter;
1357 }
1358 
1359 /**
1360  * @tc.name: IntlFuncTest0035
1361  * @tc.desc: Test Intl NumberFormat
1362  * @tc.type: FUNC
1363  */
1364 HWTEST_F(IntlTest, IntlFuncTest0035, TestSize.Level1)
1365 {
1366     vector<string> locales;
1367     locales.push_back("en-US");
1368     map<string, string> options = {
1369         { "locale", "fake locale" },
1370         { "currency", "USD" },
1371         { "currencySign", "fake sign" },
1372         { "currencyDisplay", "symbol" },
1373         { "unit", "fake unit" },
1374         { "unitDisplay", "long" },
1375         { "unitUsage", "length-person" },
1376         { "signDisplay", "fake display" },
1377         { "compactDisplay", "long" },
1378         { "notation", "standard" },
1379         { "localeMatcher", "lookup" },
1380         { "style", "currency" },
1381         { "numberingSystem", "latn" },
1382         { "useGrouping", "false" },
1383         { "minimumIntegerDigits", "1" },
1384         { "minimumFractionDigits", "0" },
1385         { "maximumFractionDigits", "17" },
1386         { "minimumSignificantDigits", "1" },
1387         { "maximumSignificantDigits", "17" }
1388     };
1389     NumberFormat *formatter = new NumberFormat(locales, options);
1390     string res = formatter->GetUseGrouping();
1391     EXPECT_EQ(res, "false");
1392     res = formatter->GetMinimumIntegerDigits();
1393     EXPECT_EQ(res, "1");
1394     res = formatter->GetMinimumFractionDigits();
1395     EXPECT_EQ(res, "0");
1396     res = formatter->GetMaximumFractionDigits();
1397     EXPECT_EQ(res, "17");
1398     res = formatter->GetMinimumSignificantDigits();
1399     EXPECT_EQ(res, "1");
1400     res = formatter->GetMaximumSignificantDigits();
1401     EXPECT_EQ(res, "17");
1402     delete formatter;
1403 }
1404 
1405 /**
1406  * @tc.name: IntlFuncTest0036
1407  * @tc.desc: Test Intl DateTimeFormat
1408  * @tc.type: FUNC
1409  */
1410 HWTEST_F(IntlTest, IntlFuncTest0036, TestSize.Level1)
1411 {
1412     vector<string> locales;
1413     locales.push_back("en-US");
1414     map<string, string> options;
1415     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1416 
1417     int64_t milliseconds = 123456789;
1418     string res = formatter->Format(milliseconds);
1419     EXPECT_EQ(res, "1/2/70");
1420 
1421     int64_t milliseconds2 = 987654321;
1422     res = formatter->FormatRange(milliseconds, milliseconds2);
1423     EXPECT_EQ(res, "1/2/70 \xE2\x80\x93 1/12/70");
1424     delete formatter;
1425 }
1426 
1427 /**
1428  * @tc.name: IntlFuncTest0037
1429  * @tc.desc: Test Intl DateTimeFormat
1430  * @tc.type: FUNC
1431  */
1432 HWTEST_F(IntlTest, IntlFuncTest0037, TestSize.Level1)
1433 {
1434     vector<string> locales;
1435     locales.push_back("zh-CN");
1436     map<string, string> options = {
1437         { "locale", "zh-CN" },
1438         { "dateStyle", "medium" },
1439         { "timeStyle", "long" },
1440         { "hourCycle", "h24" },
1441         { "timeZone", "Asia/Shanghai" },
1442         { "numberingSystem", "latn" },
1443         { "hour12", "false" },
1444         { "weekday", "long" },
1445         { "era", "long" },
1446         { "year", "2-digit" },
1447         { "month", "2-digit" },
1448         { "day", "2-digit" },
1449         { "hour", "2-digit" },
1450         { "minute", "2-digit" },
1451         { "second", "2-digit" },
1452         { "timeZoneName", "long" },
1453         { "dayPeriod", "long" },
1454         { "localeMatcher", "lookup" },
1455         { "formatMatcher", "basic" }
1456     };
1457     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1458 
1459     int64_t milliseconds = 123456789;
1460     string res = formatter->Format(milliseconds);
1461     // 2022年12月19日 GMT+8 15:18:24
1462     EXPECT_TRUE(res.length() > 0);
1463 
1464     int64_t milliseconds2 = 987654321;
1465     res = formatter->FormatRange(milliseconds, milliseconds2);
1466     // 2022/12/19 GMT+8 15:18:24 \xE2\x80\x93 2023/11/18 GMT+8 14:17:23
1467     EXPECT_TRUE(res.length() > 0);
1468 
1469     res = formatter->GetDateStyle();
1470     EXPECT_EQ(res, "medium");
1471     res = formatter->GetTimeStyle();
1472     EXPECT_EQ(res, "long");
1473     res = formatter->GetHourCycle();
1474     EXPECT_EQ(res, "h24");
1475     res = formatter->GetTimeZone();
1476     EXPECT_EQ(res, "Asia/Shanghai");
1477     res = formatter->GetTimeZoneName();
1478     EXPECT_EQ(res, "long");
1479     delete formatter;
1480 }
1481 
1482 /**
1483  * @tc.name: IntlFuncTest0038
1484  * @tc.desc: Test Intl DateTimeFormat
1485  * @tc.type: FUNC
1486  */
1487 HWTEST_F(IntlTest, IntlFuncTest0038, TestSize.Level1)
1488 {
1489     vector<string> locales;
1490     locales.push_back("zh-CN");
1491     map<string, string> options = {
1492         { "locale", "zh-CN" },
1493         { "dateStyle", "full" },
1494         { "timeStyle", "full" },
1495         { "hourCycle", "h24" },
1496         { "timeZone", "Asia/Shanghai" },
1497         { "numberingSystem", "latn" },
1498         { "hour12", "false" },
1499         { "weekday", "long" },
1500         { "era", "long" },
1501         { "year", "numeric" },
1502         { "month", "numeric" },
1503         { "day", "numeric" },
1504         { "hour", "numeric" },
1505         { "minute", "numeric" },
1506         { "second", "numeric" },
1507         { "timeZoneName", "long" },
1508         { "dayPeriod", "long" },
1509         { "localeMatcher", "lookup" },
1510         { "formatMatcher", "basic" }
1511     };
1512     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1513     string res = formatter->GetNumberingSystem();
1514     EXPECT_EQ(res, "latn");
1515     res = formatter->GetHour12();
1516     EXPECT_EQ(res, "false");
1517     res = formatter->GetWeekday();
1518     EXPECT_EQ(res, "long");
1519     res = formatter->GetEra();
1520     EXPECT_EQ(res, "long");
1521     res = formatter->GetYear();
1522     EXPECT_EQ(res, "numeric");
1523     res = formatter->GetMonth();
1524     EXPECT_EQ(res, "numeric");
1525     res = formatter->GetDay();
1526     EXPECT_EQ(res, "numeric");
1527     res = formatter->GetHour();
1528     EXPECT_EQ(res, "numeric");
1529     res = formatter->GetMinute();
1530     EXPECT_EQ(res, "numeric");
1531     res = formatter->GetSecond();
1532     EXPECT_EQ(res, "numeric");
1533     delete formatter;
1534 }
1535 
1536 /**
1537  * @tc.name: IntlFuncTest0039
1538  * @tc.desc: Test Intl DateTimeFormat
1539  * @tc.type: FUNC
1540  */
1541 HWTEST_F(IntlTest, IntlFuncTest0039, TestSize.Level1)
1542 {
1543     vector<string> locales;
1544     locales.push_back("en-US");
1545     map<string, string> inputOptions = {
1546         { "locale", "en-US" },
1547         { "dateStyle", "medium" },
1548         { "timeStyle", "long" },
1549         { "hourCycle", "h12" },
1550         { "timeZone", "Asia/Shanghai" },
1551         { "numberingSystem", "latn" },
1552         { "hour12", "true" },
1553         { "weekday", "long" },
1554         { "era", "long" },
1555         { "year", "2-digit" },
1556         { "month", "2-digit" },
1557         { "day", "2-digit" },
1558         { "hour", "2-digit" },
1559         { "minute", "2-digit" },
1560         { "second", "2-digit" },
1561         { "timeZoneName", "long" },
1562         { "dayPeriod", "long" },
1563         { "localeMatcher", "lookup" },
1564         { "formatMatcher", "basic" }
1565     };
1566     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1567     int64_t milliseconds = 123456789;
1568     string res = formatter->Format(milliseconds);
1569     // Dec 19, 2022, 3:18:24 PM GMT+8
1570     EXPECT_TRUE(res.length() > 0);
1571     int64_t milliseconds2 = 987654321;
1572     res = formatter->FormatRange(milliseconds, milliseconds2);
1573     // Dec 19, 2022, 3:18:24 PM GMT+8 \xE2\x80\x93 Nov 18, 2023, 2:17:23 PM GMT+8
1574     EXPECT_TRUE(res.length() > 0);
1575     map<string, string> options;
1576     formatter->GetResolvedOptions(options);
1577     EXPECT_EQ(options.size(), 20);
1578     map<string, string>::iterator it = options.find("locale");
1579     if (it != options.end()) {
1580         EXPECT_EQ(it->second, "en-US");
1581     }
1582     it = options.find("dateStyle");
1583     if (it != options.end()) {
1584         EXPECT_EQ(it->second, "medium");
1585     }
1586     it = options.find("timeStyle");
1587     if (it != options.end()) {
1588         EXPECT_EQ(it->second, "long");
1589     }
1590 }
1591 
1592 /**
1593  * @tc.name: IntlFuncTest0040
1594  * @tc.desc: Test Intl DateTimeFormat
1595  * @tc.type: FUNC
1596  */
1597 HWTEST_F(IntlTest, IntlFuncTest0040, TestSize.Level1)
1598 {
1599     vector<string> locales;
1600     locales.push_back("en-GB");
1601     map<string, string> inputOptions = {
1602         { "locale", "en-GB" },
1603         { "dateStyle", "medium" },
1604         { "timeStyle", "long" },
1605         { "hourCycle", "h12" },
1606         { "timeZone", "Asia/Shanghai" },
1607         { "numberingSystem", "latn" },
1608         { "hour12", "true" },
1609         { "weekday", "long" },
1610         { "era", "long" },
1611         { "year", "numeric" },
1612         { "month", "numeric" },
1613         { "day", "numeric" },
1614         { "hour", "numeric" },
1615         { "minute", "numeric" },
1616         { "second", "numeric" },
1617         { "timeZoneName", "long" },
1618         { "dayPeriod", "long" },
1619         { "localeMatcher", "lookup" },
1620         { "formatMatcher", "basic" }
1621     };
1622     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1623     map<string, string> options;
1624     formatter->GetResolvedOptions(options);
1625     map<string, string>::iterator it = options.find("hourCycle");
1626     if (it != options.end()) {
1627         EXPECT_EQ(it->second, "h12");
1628     }
1629     it = options.find("timeZone");
1630     if (it != options.end()) {
1631         EXPECT_EQ(it->second, "Asia/Shanghai");
1632     }
1633     it = options.find("numberingSystem");
1634     if (it != options.end()) {
1635         EXPECT_EQ(it->second, "latn");
1636     }
1637     it = options.find("hour12");
1638     if (it != options.end()) {
1639         EXPECT_EQ(it->second, "true");
1640     }
1641     it = options.find("weekday");
1642     if (it != options.end()) {
1643         EXPECT_EQ(it->second, "long");
1644     }
1645 }
1646 
1647 /**
1648  * @tc.name: IntlFuncTest0041
1649  * @tc.desc: Test Intl DateTimeFormat
1650  * @tc.type: FUNC
1651  */
1652 HWTEST_F(IntlTest, IntlFuncTest0041, TestSize.Level1)
1653 {
1654     vector<string> locales;
1655     locales.push_back("en-US");
1656     map<string, string> inputOptions = {
1657         { "locale", "en-US" },
1658         { "dateStyle", "medium" },
1659         { "timeStyle", "medium" },
1660         { "hourCycle", "h24" },
1661         { "timeZone", "Asia/Shanghai" },
1662         { "numberingSystem", "latn" },
1663         { "hour12", "false" },
1664         { "weekday", "long" },
1665         { "era", "long" },
1666         { "year", "2-digit" },
1667         { "month", "2-digit" },
1668         { "day", "2-digit" },
1669         { "hour", "2-digit" },
1670         { "minute", "2-digit" },
1671         { "second", "2-digit" },
1672         { "timeZoneName", "long" },
1673         { "dayPeriod", "long" },
1674         { "localeMatcher", "best fit" },
1675         { "formatMatcher", "best fit" }
1676     };
1677     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1678     map<string, string> options;
1679     formatter->GetResolvedOptions(options);
1680     map<string, string>::iterator it = options.find("era");
1681     if (it != options.end()) {
1682         EXPECT_EQ(it->second, "long");
1683     }
1684     it = options.find("year");
1685     if (it != options.end()) {
1686         EXPECT_EQ(it->second, "2-digit");
1687     }
1688     it = options.find("month");
1689     if (it != options.end()) {
1690         EXPECT_EQ(it->second, "2-digit");
1691     }
1692     it = options.find("day");
1693     if (it != options.end()) {
1694         EXPECT_EQ(it->second, "2-digit");
1695     }
1696     it = options.find("hour");
1697     if (it != options.end()) {
1698         EXPECT_EQ(it->second, "2-digit");
1699     }
1700 }
1701 
1702 /**
1703  * @tc.name: IntlFuncTest0042
1704  * @tc.desc: Test Intl DateTimeFormat
1705  * @tc.type: FUNC
1706  */
1707 HWTEST_F(IntlTest, IntlFuncTest0042, TestSize.Level1)
1708 {
1709     vector<string> locales;
1710     locales.push_back("en-US");
1711     map<string, string> inputOptions = {
1712         { "locale", "en-US" },
1713         { "dateStyle", "full" },
1714         { "timeStyle", "long" },
1715         { "hourCycle", "h12" },
1716         { "timeZone", "Asia/Singapore" },
1717         { "numberingSystem", "latn" },
1718         { "hour12", "true" },
1719         { "weekday", "long" },
1720         { "era", "long" },
1721         { "year", "2-digit" },
1722         { "month", "2-digit" },
1723         { "day", "2-digit" },
1724         { "hour", "numeric" },
1725         { "minute", "numeric" },
1726         { "second", "numeric" },
1727         { "timeZoneName", "long" },
1728         { "dayPeriod", "long" },
1729         { "localeMatcher", "lookup" },
1730         { "formatMatcher", "basic" }
1731     };
1732     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1733     map<string, string> options;
1734     formatter->GetResolvedOptions(options);
1735     map<string, string>::iterator it = options.find("minute");
1736     if (it != options.end()) {
1737         EXPECT_EQ(it->second, "numeric");
1738     }
1739     it = options.find("second");
1740     if (it != options.end()) {
1741         EXPECT_EQ(it->second, "numeric");
1742     }
1743     it = options.find("timeZoneName");
1744     if (it != options.end()) {
1745         EXPECT_EQ(it->second, "long");
1746     }
1747     it = options.find("dayPeriod");
1748     if (it != options.end()) {
1749         EXPECT_EQ(it->second, "long");
1750     }
1751 }
1752 
1753 /**
1754  * @tc.name: IntlFuncTest0043
1755  * @tc.desc: Test Intl DateTimeFormat
1756  * @tc.type: FUNC
1757  */
1758 HWTEST_F(IntlTest, IntlFuncTest0043, TestSize.Level1)
1759 {
1760     vector<string> locales;
1761     locales.push_back("en-US");
1762     map<string, string> inputOptions = {
1763         { "locale", "en-US" },
1764         { "dateStyle", "long" },
1765         { "timeStyle", "long" },
1766         { "hourCycle", "h12" },
1767         { "timeZone", "America/Los_Angeles" },
1768         { "numberingSystem", "latn" },
1769         { "hour12", "true" },
1770         { "weekday", "long" },
1771         { "era", "long" },
1772         { "year", "numeric" },
1773         { "month", "numeric" },
1774         { "day", "numeric" },
1775         { "hour", "2-digit" },
1776         { "minute", "2-digit" },
1777         { "second", "2-digit" },
1778         { "timeZoneName", "long" },
1779         { "dayPeriod", "long" },
1780         { "localeMatcher", "lookup" },
1781         { "formatMatcher", "basic" }
1782     };
1783     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1784     map<string, string> options;
1785     formatter->GetResolvedOptions(options);
1786     map<string, string>::iterator it = options.find("localeMatcher");
1787     if (it != options.end()) {
1788         EXPECT_EQ(it->second, "lookup");
1789     }
1790     it = options.find("formatMatcher");
1791     if (it != options.end()) {
1792         EXPECT_EQ(it->second, "basic");
1793     }
1794 }
1795 
1796 /**
1797  * @tc.name: IntlFuncTest0044
1798  * @tc.desc: Test Intl LocaleInfo
1799  * @tc.type: FUNC
1800  */
1801 HWTEST_F(IntlTest, IntlFuncTest0044, TestSize.Level1)
1802 {
1803     string localeTag = "zh-Hans-CN";
1804     map<string, string> configs = {
1805         { "calendar", "chinese" },
1806         { "collation", "pinyin" },
1807         { "hourCycle", "h12" },
1808         { "numberingSystem", "latn" },
1809         { "numeric", "true" },
1810         { "caseFirst", "upper" }
1811     };
1812     LocaleInfo *locale = new LocaleInfo(localeTag, configs);
1813     string res = locale->GetLanguage();
1814     EXPECT_EQ(res, "zh");
1815     res = locale->GetScript();
1816     EXPECT_EQ(res, "Hans");
1817     res = locale->GetRegion();
1818     EXPECT_EQ(res, "CN");
1819     res = locale->GetBaseName();
1820     EXPECT_EQ(res, "zh-Hans-CN");
1821     res = locale->GetCalendar();
1822     EXPECT_EQ(res, "chinese");
1823     res = locale->GetCollation();
1824     EXPECT_EQ(res, "pinyin");
1825     res = locale->GetHourCycle();
1826     EXPECT_EQ(res, "h12");
1827     res = locale->GetNumberingSystem();
1828     EXPECT_EQ(res, "latn");
1829     res = locale->GetNumeric();
1830     EXPECT_EQ(res, "true");
1831     res = locale->GetCaseFirst();
1832     EXPECT_EQ(res, "upper");
1833     icu::Locale icuLocale = locale->GetLocale();
1834     res = locale->ToString();
1835     EXPECT_EQ(res, "zh-Hans-CN-u-hc-h12-nu-latn-ca-chinese-co-pinyin-kf-upper-kn-true");
1836     delete locale;
1837 }
1838 
1839 /**
1840  * @tc.name: IntlFuncTest0045
1841  * @tc.desc: Test Intl ReadSystemParameter
1842  * @tc.type: FUNC
1843  */
1844 HWTEST_F(IntlTest, IntlFuncTest0045, TestSize.Level1)
1845 {
1846     string paramKey = "const.global.language";
1847     int paramLength = 128;
1848     string res = ReadSystemParameter(paramKey.c_str(), paramLength);
1849     EXPECT_TRUE(res.length() > 0);
1850 
1851     paramKey = "fake system param";
1852     res = ReadSystemParameter(paramKey.c_str(), paramLength);
1853     EXPECT_TRUE(res.length() == 0);
1854 }
1855 
1856 /**
1857  * @tc.name: IntlFuncTest0046
1858  * @tc.desc: Test Intl GetTimezoneIdByLocation
1859  * @tc.type: FUNC
1860  */
1861 HWTEST_F(IntlTest, IntlFuncTest0046, TestSize.Level1)
1862 {
1863     //北京
1864     vector<std::string> Beijing = I18nTimeZone::GetTimezoneIdByLocation(116.3, 39.5);
1865     EXPECT_TRUE(Beijing.size() == 1 && Beijing[0] == "Asia/Shanghai");
1866     //洛杉矶
1867     vector<std::string> LosAngeles = I18nTimeZone::GetTimezoneIdByLocation(-118.1, 34.0);
1868     EXPECT_TRUE(LosAngeles.size() == 1 && LosAngeles[0] == "America/Los_Angeles");
1869     //里约热内卢
1870     vector<std::string> RIO = I18nTimeZone::GetTimezoneIdByLocation(-43.1, -22.5);
1871     EXPECT_TRUE(RIO.size() == 1 && RIO[0] == "America/Sao_Paulo");
1872     //悉尼
1873     vector<std::string> Sydney = I18nTimeZone::GetTimezoneIdByLocation(150.5, -33.55);
1874     EXPECT_TRUE(Sydney.size() == 1 && Sydney[0] == "Australia/Sydney");
1875     //乌鲁木齐
1876     vector<std::string> Urumqi = I18nTimeZone::GetTimezoneIdByLocation(87.7, 43.8);
1877     EXPECT_TRUE(Urumqi.size() == 2);
1878     bool containsShanghai = false;
1879     bool containsUrumqi = false;
1880     for (unsigned int i = 0; i < Urumqi.size(); i++) {
1881         if (Urumqi[i] == "Asia/Shanghai") {
1882             containsShanghai = true;
1883         }
1884         if (Urumqi[i] == "Asia/Urumqi") {
1885             containsUrumqi = true;
1886         }
1887     }
1888     EXPECT_TRUE(containsShanghai);
1889     EXPECT_TRUE(containsUrumqi);
1890 }
1891 
1892 /**
1893  * @tc.name: IntlFuncTest0047
1894  * @tc.desc: Test Intl LocaleConfig GetBlockedLanguages
1895  * @tc.type: FUNC
1896  */
1897 HWTEST_F(IntlTest, IntlFuncTest0047, TestSize.Level1)
1898 {
1899     std::unordered_set<std::string> languageSet = LocaleConfig::GetBlockedLanguages();
1900     EXPECT_TRUE(languageSet.size() == 1);
1901 }
1902 
1903 /**
1904  * @tc.name: IntlFuncTest0048
1905  * @tc.desc: Test Intl LocaleConfig GetBlockedRegions
1906  * @tc.type: FUNC
1907  */
1908 HWTEST_F(IntlTest, IntlFuncTest0048, TestSize.Level1)
1909 {
1910     std::unordered_set<std::string> regionSet = LocaleConfig::GetBlockedRegions();
1911     EXPECT_TRUE(regionSet.size() == 0);
1912 }
1913 
1914 /**
1915  * @tc.name: IntlFuncTest0049
1916  * @tc.desc: Test Intl LocaleConfig GetLanguageBlockedRegions
1917  * @tc.type: FUNC
1918  */
1919 HWTEST_F(IntlTest, IntlFuncTest0049, TestSize.Level1)
1920 {
1921     std::unordered_set<std::string> blockedRegionSet = LocaleConfig::GetLanguageBlockedRegions();
1922     EXPECT_EQ(blockedRegionSet.size(), 0);
1923     std::string systemLanguage = LocaleConfig::GetSystemLanguage();
1924     EXPECT_EQ(systemLanguage, "zh-Hans");
1925     std::string systemRegion = LocaleConfig::GetSystemRegion();
1926     EXPECT_EQ(systemRegion, "CN");
1927     std::string systemLocale = LocaleConfig::GetSystemLocale();
1928     EXPECT_EQ(systemLocale, "zh-Hans-CN");
1929     const std::string locale = "zh-CN";
1930     bool isRTL = LocaleConfig::IsRTL(locale);
1931     EXPECT_TRUE(!isRTL);
1932     std::string validLocale = LocaleConfig::GetValidLocale(locale);
1933     EXPECT_EQ(validLocale, "zh-CN");
1934     bool is24HourClock = LocaleConfig::Is24HourClock();
1935     EXPECT_TRUE(!is24HourClock);
1936     bool set24HourClock = LocaleConfig::Set24HourClock(true);
1937     EXPECT_TRUE(!set24HourClock);
1938     bool permission = LocaleConfig::CheckPermission();
1939     EXPECT_TRUE(!permission);
1940     bool usingLocalDigit = LocaleConfig::SetUsingLocalDigit(true);
1941     EXPECT_TRUE(!usingLocalDigit);
1942     usingLocalDigit = LocaleConfig::GetUsingLocalDigit();
1943     EXPECT_TRUE(!usingLocalDigit);
1944 }
1945 
1946 /**
1947  * @tc.name: IntlFuncTest0050
1948  * @tc.desc: Test Intl PreferredLanguage AddPreferredLanguageExist
1949  * @tc.type: FUNC
1950  */
1951 HWTEST_F(IntlTest, IntlFuncTest0050, TestSize.Level1)
1952 {
1953     const std::string langugae = "zh-CN";
1954     const std::string langugaeDe = "de-DE";
1955     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
1956     PreferredLanguage::AddPreferredLanguage(langugae, 0, errorCode);
1957     EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
1958     PreferredLanguage::AddPreferredLanguage(langugaeDe, 1, errorCode);
1959     EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
1960     PreferredLanguage::AddPreferredLanguage(langugae, 3, errorCode);
1961     EXPECT_TRUE(errorCode != I18nErrorCode::SUCCESS);
1962     std::vector<std::string> list = PreferredLanguage::GetPreferredLanguageList();
1963     EXPECT_EQ(list.size(), 1);
1964     std::string firstPreferredLanguage = PreferredLanguage::GetFirstPreferredLanguage();
1965     EXPECT_EQ(firstPreferredLanguage, "zh-Hans");
1966     std::string preferredLocale = PreferredLanguage::GetPreferredLocale();
1967     EXPECT_EQ(preferredLocale, "zh-CN");
1968     bool flag = PreferredLanguage::RemovePreferredLanguage(0);
1969     EXPECT_TRUE(!flag);
1970 }
1971 
1972 /**
1973  * @tc.name: IntlFuncTest0051
1974  * @tc.desc: Test Intl I18nCalendar
1975  * @tc.type: FUNC
1976  */
1977 HWTEST_F(IntlTest, IntlFuncTest0051, TestSize.Level1)
1978 {
1979     I18nCalendar *calendar = new I18nCalendar("zh-Hans-CN");
1980     I18nCalendar *calendar2 = new I18nCalendar("zh-Hans-CN", CalendarType::CHINESE);
1981     calendar->SetTime(1684742124645);
1982     calendar->Set(1989, 5, 23);
1983     calendar->SetTimeZone("Asia/Shanghai");
1984     std::string tzId = calendar->GetTimeZone();
1985     EXPECT_EQ(tzId, "Asia/Shanghai");
1986     int32_t minimalDaysInFirstWeek = calendar->GetMinimalDaysInFirstWeek();
1987     EXPECT_EQ(minimalDaysInFirstWeek, 1);
1988     int32_t firstDayOfWeek = calendar->GetFirstDayOfWeek();
1989     EXPECT_EQ(firstDayOfWeek, 1);
1990     calendar2->Set(2023, 5, 28);
1991     bool isWeekend = calendar2->IsWeekend();
1992     EXPECT_TRUE(isWeekend);
1993     I18nCalendar *calendarFake = new I18nCalendar("123");
1994     I18nCalendar *calendarInvalid = new I18nCalendar("123", CalendarType::CHINESE);
1995     delete calendarFake;
1996     delete calendarInvalid;
1997     delete calendar;
1998     delete calendar2;
1999 }
2000 
2001 /**
2002  * @tc.name: IntlFuncTest0052
2003  * @tc.desc: Test Intl IndexUtil
2004  * @tc.type: FUNC
2005  */
2006 HWTEST_F(IntlTest, IntlFuncTest0052, TestSize.Level1)
2007 {
2008     IndexUtil *indexUtil = new IndexUtil("zh-CN");
2009     std::vector<std::string> indexList = indexUtil->GetIndexList();
2010     EXPECT_EQ(indexList.size(), 28);
2011     indexUtil->AddLocale("en-US");
2012     std::string indexStr = indexUtil->GetIndex("A");
2013     EXPECT_EQ(indexStr, "A");
2014     IndexUtil *indexUtil2 = new IndexUtil("");
2015     delete indexUtil;
2016     delete indexUtil2;
2017 
2018     IndexUtil indexUtil3("");
2019     indexUtil3.AddLocale("en-US");
2020     indexStr = indexUtil3.GetIndex("A");
2021     EXPECT_EQ(indexStr, "A");
2022 }
2023 
2024 /**
2025  * @tc.name: IntlFuncTest0053
2026  * @tc.desc: Test Intl PhoneNumberFormat
2027  * @tc.type: FUNC
2028  */
2029 HWTEST_F(IntlTest, IntlFuncTest0053, TestSize.Level1)
2030 {
2031     map<string, string> options = {
2032         { "type", "national" }
2033     };
2034     PhoneNumberFormat *phoneNumberFormat = new PhoneNumberFormat("zh-CN", options);
2035     std::string location = phoneNumberFormat->getLocationName("18622350085", "zh-CN");
2036     EXPECT_EQ(location, "天津市");
2037     bool flag = phoneNumberFormat->isValidPhoneNumber("+8618622350085");
2038     EXPECT_TRUE(flag);
2039     std::string number = "+8618622350085";
2040     std::string formated = phoneNumberFormat->format(number);
2041     EXPECT_EQ(formated, "186 2235 0085");
2042     delete phoneNumberFormat;
2043 }
2044 
2045 /**
2046  * @tc.name: IntlFuncTest0054
2047  * @tc.desc: Test Intl TabooUtils
2048  * @tc.type: FUNC
2049  */
2050 HWTEST_F(IntlTest, IntlFuncTest0054, TestSize.Level1)
2051 {
2052     TabooUtils *tabooUtils = new TabooUtils();
2053     std::string res1 = tabooUtils->ReplaceCountryName("CN", "en", "China");
2054     EXPECT_EQ(res1, "China");
2055     std::string res2 = tabooUtils->ReplaceLanguageName("zh", "en", "chinese");
2056     EXPECT_EQ(res2, "chinese");
2057     delete tabooUtils;
2058 }
2059 
2060 /**
2061  * @tc.name: IntlFuncTest0055
2062  * @tc.desc: Test Intl LocaleCompare
2063  * @tc.type: FUNC
2064  */
2065 HWTEST_F(IntlTest, IntlFuncTest0055, TestSize.Level1)
2066 {
2067     int32_t result = LocaleCompare::Compare("zh-CN", "zh-Hans-CN");
2068     EXPECT_EQ(result, 9);
2069     I18nBreakIterator *i18nBreakIterator = new I18nBreakIterator("zh-Hans-CN");
2070     bool isBoundary = i18nBreakIterator->IsBoundary(6);
2071     EXPECT_TRUE(!isBoundary);
2072     int32_t current = i18nBreakIterator->Current();
2073     EXPECT_EQ(current, 0);
2074     int32_t first = i18nBreakIterator->First();
2075     EXPECT_EQ(first, 0);
2076     int32_t last = i18nBreakIterator->Last();
2077     EXPECT_EQ(last, 0);
2078     int32_t previous = i18nBreakIterator->Previous();
2079     EXPECT_EQ(previous, -1);
2080     int32_t next6 = i18nBreakIterator->Next(6);
2081     EXPECT_EQ(next6, -1);
2082     int32_t resultLatn = LocaleCompare::Compare("en-Latn-US", "en-Qaag-US");
2083     EXPECT_EQ(resultLatn, 9);
2084     int32_t resultTl = LocaleCompare::Compare("tl-PH", "fil-PH");
2085     EXPECT_EQ(resultTl, 9);
2086     int32_t resultFil = LocaleCompare::Compare("fil-PH", "tl-PH");
2087     EXPECT_EQ(resultFil, 9);
2088     int32_t resultQaag = LocaleCompare::Compare("en-Qaag-US", "en-Latn-US");
2089     EXPECT_EQ(resultQaag, 9);
2090     int32_t resultHashMapZh = LocaleCompare::Compare("zh-MO", "zh-Hant-HK");
2091     EXPECT_EQ(resultHashMapZh, 8);
2092     int32_t resultZh = LocaleCompare::Compare("zh-Hant-MO", "zh-Hant-HK");
2093     EXPECT_EQ(resultZh, 8);
2094     int32_t resultHashMapEn = LocaleCompare::Compare("en-WS", "en-001");
2095     EXPECT_EQ(resultHashMapEn, 8);
2096     int32_t resultHashEn = LocaleCompare::Compare("en-Latn-WS", "en-001");
2097     EXPECT_EQ(resultHashEn, 8);
2098     int32_t resultHashQaagEn = LocaleCompare::Compare("en-Qaag-WS", "en-001");
2099     EXPECT_EQ(resultHashQaagEn, 8);
2100     I18nBreakIterator *breakIterator = new I18nBreakIterator("fake locale");
2101     breakIterator->Current();
2102     breakIterator->First();
2103     breakIterator->Last();
2104     breakIterator->Previous();
2105     breakIterator->Next(6);
2106     breakIterator->Next();
2107     breakIterator->Following(0);
2108     breakIterator->IsBoundary(6);
2109     delete breakIterator;
2110     delete i18nBreakIterator;
2111 }
2112 
2113 /**
2114  * @tc.name: IntlFuncTest0056
2115  * @tc.desc: Test Intl SystemLocaleManager
2116  * @tc.type: FUNC
2117  */
2118 HWTEST_F(IntlTest, IntlFuncTest0056, TestSize.Level1)
2119 {
2120     SystemLocaleManager *systemLocaleManager = new SystemLocaleManager();
2121     std::vector<std::string> languages = {"en", "de", "es", "fr"};
2122     SortOptions sortOptions = {"en-US", true, true};
2123     std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions);
2124     EXPECT_EQ(languageInfos.size(), 4);
2125     const std::vector<std::string> countries = {"US", "GB", "DE", "CA"};
2126     std::vector<LocaleItem> countryInfos = systemLocaleManager->GetCountryInfoArray(countries, sortOptions);
2127     EXPECT_EQ(countryInfos.size(), 4);
2128     std::vector<TimeZoneCityItem> timezoneCityItemList = SystemLocaleManager::GetTimezoneCityInfoArray();
2129     EXPECT_TRUE(timezoneCityItemList.size() > 0);
2130     delete systemLocaleManager;
2131 }
2132 
2133 /**
2134  * @tc.name: IntlFuncTest0057
2135  * @tc.desc: Test Intl Utils
2136  * @tc.type: FUNC
2137  */
2138 HWTEST_F(IntlTest, IntlFuncTest0057, TestSize.Level1)
2139 {
2140     bool isDigit = IsDigit("55");
2141     EXPECT_TRUE(isDigit);
2142     bool isSpaceChar = IsSpaceChar(" ");
2143     EXPECT_TRUE(isSpaceChar);
2144     bool isWhiteSpace = IsWhiteSpace("  ");
2145     EXPECT_TRUE(isWhiteSpace);
2146     bool isRTLCharacter = IsRTLCharacter("^");
2147     EXPECT_TRUE(!isRTLCharacter);
2148     isRTLCharacter = IsRTLCharacter("\u0645");
2149     EXPECT_TRUE(isRTLCharacter);
2150     bool isIdeoGraphic = IsIdeoGraphic("&&*");
2151     EXPECT_TRUE(!isIdeoGraphic);
2152     bool isLetter = IsLetter("cccUt");
2153     EXPECT_TRUE(isLetter);
2154     bool isLowerCase = IsLowerCase("abc");
2155     EXPECT_TRUE(isLowerCase);
2156     bool isUpperCase = IsUpperCase("AbC");
2157     EXPECT_TRUE(isUpperCase);
2158     std::string getType = GetType("$$%");
2159     EXPECT_EQ(getType, "U_CURRENCY_SYMBOL");
2160 }
2161 
2162 /**
2163  * @tc.name: IntlFuncTest0058
2164  * @tc.desc: Test Intl MeasureData
2165  * @tc.type: FUNC
2166  */
2167 HWTEST_F(IntlTest, IntlFuncTest0058, TestSize.Level1)
2168 {
2169     std::string timezoneId = "Asia/Shanghai";
2170     I18nTimeZone *i18nTimeZone = new I18nTimeZone(timezoneId, true);
2171     int32_t offset = i18nTimeZone->GetOffset(1684742124645);
2172     EXPECT_EQ(offset, 28800000);
2173     int32_t rawOffset = i18nTimeZone->GetRawOffset();
2174     EXPECT_EQ(rawOffset, 28800000);
2175     std::string tzId = i18nTimeZone->GetID();
2176     EXPECT_EQ(tzId, "Asia/Shanghai");
2177     std::string displayName = i18nTimeZone->GetDisplayName();
2178     EXPECT_EQ(displayName, "中国标准时间");
2179     std::string displayName2 = i18nTimeZone->GetDisplayName(true);
2180     EXPECT_EQ(displayName2, "中国标准时间");
2181     std::string zhCn = "zh-CN";
2182     std::string displayNameCn = i18nTimeZone->GetDisplayName(zhCn);
2183     EXPECT_EQ(displayNameCn, "中国标准时间");
2184     std::string displayName4 = i18nTimeZone->GetDisplayName("zh-CN", true);
2185     EXPECT_EQ(displayName4, "中国标准时间");
2186     std::string cityId = "Shanghai";
2187     std::string localeId = "en-US";
2188     std::string cityDisplayName = i18nTimeZone->GetCityDisplayName(cityId, localeId);
2189     EXPECT_EQ(cityDisplayName, "Shanghai (China)");
2190     std::unique_ptr<I18nTimeZone> timezone = I18nTimeZone::CreateInstance(timezoneId, true);
2191     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
2192     std::set<std::string> set0 = I18nTimeZone::GetAvailableIDs(errorCode);
2193     EXPECT_EQ(set0.size(), 437);
2194     std::set<std::string> set1 = I18nTimeZone::GetAvailableZoneCityIDs();
2195     EXPECT_TRUE(set1.size() > 0);
2196     std::string empty = "";
2197     std::string fakeCityId = "fake cityId";
2198     I18nTimeZone *i18nTimeZoneEmpty = new I18nTimeZone(empty, true);
2199     I18nTimeZone *i18nTimeZoneFake = new I18nTimeZone(fakeCityId, false);
2200     I18nTimeZone *i18nTimeZoneCityId = new I18nTimeZone(cityId, false);
2201     delete i18nTimeZoneEmpty;
2202     delete i18nTimeZoneFake;
2203     delete i18nTimeZoneCityId;
2204     delete i18nTimeZone;
2205     uint32_t mask = GetMask("CN");
2206     EXPECT_EQ(mask, 2462);
2207 }
2208 
2209 /**
2210  * @tc.name: IntlFuncTest0059
2211  * @tc.desc: Test Intl NumberFormat
2212  * @tc.type: FUNC
2213  */
2214 HWTEST_F(IntlTest, IntlFuncTest0059, TestSize.Level1)
2215 {
2216     std::vector<std::string> localeTags = { "fake locale tag"};
2217     std::map<std::string, std::string> configs = {
2218         {"style", "unit"}, {"unit", "fake unit"}
2219     };
2220     NumberFormat formatter(localeTags, configs);
2221     std::string res = formatter.Format(12);
2222     EXPECT_EQ(res, "");
2223 }
2224 } // namespace I18n
2225 } // namespace Global
2226 } // namespace OHOS