• 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 "date_time_format.h"
22 #include "locale_config.h"
23 #include "locale_info.h"
24 #include "number_format.h"
25 #include "plural_rules.h"
26 #include "relative_time_format.h"
27 #include "utils.h"
28 #include "intl_test.h"
29 
30 using namespace OHOS::Global::I18n;
31 using testing::ext::TestSize;
32 using namespace std;
33 
34 namespace OHOS {
35 namespace Global {
36 namespace I18n {
37 class IntlTest : public testing::Test {
38 public:
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase(void)45 void IntlTest::SetUpTestCase(void)
46 {}
47 
TearDownTestCase(void)48 void IntlTest::TearDownTestCase(void)
49 {}
50 
SetUp(void)51 void IntlTest::SetUp(void)
52 {}
53 
TearDown(void)54 void IntlTest::TearDown(void)
55 {}
56 
57 /**
58  * @tc.name: IntlFuncTest001
59  * @tc.desc: Test Intl DateTimeFormat.format
60  * @tc.type: FUNC
61  */
62 HWTEST_F(IntlTest, IntlFuncTest001, TestSize.Level1)
63 {
64     string locale = "zh-CN-u-hc-h12";
65     string expects = "公元1970年1月1日星期四 上午8:20:34";
66     vector<string> locales;
67     locales.push_back("jessie");
68     locales.push_back(locale);
69     map<string, string> options = { { "year", "numeric" },
70                                     { "month", "long" },
71                                     { "day", "numeric" },
72                                     { "hour", "numeric" },
73                                     { "minute", "2-digit" },
74                                     { "second", "numeric" },
75                                     { "weekday", "long" },
76                                     { "era", "short"} };
77     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
78     if (!dateFormat) {
79         EXPECT_TRUE(false);
80         return;
81     }
82     int64_t milliseconds = 1234567;
83     string out = dateFormat->Format(milliseconds);
84     EXPECT_EQ(out, expects);
85     EXPECT_EQ(dateFormat->GetYear(), "numeric");
86     EXPECT_EQ(dateFormat->GetMonth(), "long");
87     EXPECT_EQ(dateFormat->GetDay(), "numeric");
88     EXPECT_EQ(dateFormat->GetHour(), "numeric");
89     EXPECT_EQ(dateFormat->GetMinute(), "2-digit");
90     EXPECT_EQ(dateFormat->GetSecond(), "numeric");
91     EXPECT_EQ(dateFormat->GetWeekday(), "long");
92     EXPECT_EQ(dateFormat->GetEra(), "short");
93     EXPECT_EQ(dateFormat->GetHourCycle(), "h12");
94     delete dateFormat;
95 }
96 
97 /**
98  * @tc.name: IntlFuncTest002
99  * @tc.desc: Test Intl LocaleInfo
100  * @tc.type: FUNC
101  */
102 HWTEST_F(IntlTest, IntlFuncTest002, TestSize.Level0)
103 {
104     string locale = "ja-Jpan-JP-u-ca-japanese-hc-h12-co-emoji";
105     map<string, string> options = { { "hourCycle", "h11" },
106                                     { "numeric", "true" },
107                                     { "numberingSystem", "jpan" } };
108     LocaleInfo *loc = new (std::nothrow) LocaleInfo(locale, options);
109     if (!loc) {
110         EXPECT_TRUE(false);
111         return;
112     }
113     EXPECT_EQ(loc->GetLanguage(), "ja");
114     EXPECT_EQ(loc->GetScript(), "Jpan");
115     EXPECT_EQ(loc->GetRegion(), "JP");
116     EXPECT_EQ(loc->GetBaseName(), "ja-Jpan-JP");
117     EXPECT_EQ(loc->GetCalendar(), "japanese");
118     EXPECT_EQ(loc->GetHourCycle(), "h11");
119     EXPECT_EQ(loc->GetNumberingSystem(), "jpan");
120     EXPECT_EQ(loc->Minimize(), "ja-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true");
121     EXPECT_EQ(loc->Maximize(), "ja-Jpan-JP-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true");
122     EXPECT_EQ(loc->GetNumeric(), "true");
123     EXPECT_EQ(loc->GetCaseFirst(), "");
124     delete loc;
125 }
126 
127 /**
128  * @tc.name: IntlFuncTest003
129  * @tc.desc: Test Intl LocaleInfo
130  * @tc.type: FUNC
131  */
132 HWTEST_F(IntlTest, IntlFuncTest003, TestSize.Level1)
133 {
134     string locale = "en-GB";
135     LocaleInfo *loc = new (std::nothrow) LocaleInfo(locale);
136     if (!loc) {
137         EXPECT_TRUE(false);
138         return;
139     }
140     string language = "en";
141     string script = "";
142     string region = "GB";
143     string baseName = "en-GB";
144     EXPECT_EQ(loc->GetLanguage(), language);
145     EXPECT_EQ(loc->GetScript(), script);
146     EXPECT_EQ(loc->GetRegion(), region);
147     EXPECT_EQ(loc->GetBaseName(), baseName);
148     delete loc;
149 }
150 
151 /**
152  * @tc.name: IntlFuncTest004
153  * @tc.desc: Test Intl DateTimeFormat.format
154  * @tc.type: FUNC
155  */
156 HWTEST_F(IntlTest, IntlFuncTest004, TestSize.Level1)
157 {
158     string locale = "en-GB";
159     string expects = "2 January 1970, 18:17 – 12 January 1970, 18:20";
160     vector<string> locales;
161     locales.push_back(locale);
162     string dateStyle = "long";
163     string timeStyle = "short";
164     map<string, string> options = { { "dateStyle", dateStyle },
165                                     { "timeStyle", timeStyle } };
166     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
167     if (!dateFormat) {
168         EXPECT_TRUE(false);
169         return;
170     }
171     int64_t fromMilliseconds = 123456789;
172     int64_t toMilliseconds = 987654321;
173     string out = dateFormat->FormatRange(fromMilliseconds, toMilliseconds);
174     EXPECT_EQ(out, expects);
175     EXPECT_EQ(dateFormat->GetDateStyle(), dateStyle);
176     EXPECT_EQ(dateFormat->GetTimeStyle(), timeStyle);
177     delete dateFormat;
178 }
179 
180 /**
181  * @tc.name: IntlFuncTest005
182  * @tc.desc: Test Intl DateTimeFormat.format
183  * @tc.type: FUNC
184  */
185 HWTEST_F(IntlTest, IntlFuncTest005, TestSize.Level1)
186 {
187     string locale = "ja";
188     string expects = "1970年1月2日金曜日";
189     vector<string> locales;
190     locales.push_back(locale);
191     map<string, string> options = { { "year", "numeric" },
192                                     { "month", "long" },
193                                     { "day", "numeric" },
194                                     { "weekday", "long"} };
195     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
196     if (!dateFormat) {
197         EXPECT_TRUE(false);
198         return;
199     }
200     int64_t milliseconds = 123456789;
201     string out = dateFormat->Format(milliseconds);
202     EXPECT_EQ(out, expects);
203     int64_t fromMilliseconds = 123456789;
204     int64_t toMilliseconds = 987654321;
205     expects = "1970/1/2金曜日~1970/1/12月曜日";
206     out = dateFormat->FormatRange(fromMilliseconds, toMilliseconds);
207     EXPECT_EQ(out, expects);
208     delete dateFormat;
209 }
210 
211 /**
212  * @tc.name: IntlFuncTest006
213  * @tc.desc: Test Intl DateTimeFormat.format
214  * @tc.type: FUNC
215  */
216 HWTEST_F(IntlTest, IntlFuncTest006, TestSize.Level1)
217 {
218     string locale = "en-IN";
219     string expects = "+1,23,456.79 euros";
220     vector<string> locales;
221     locales.push_back(locale);
222     string useGrouping = "true";
223     string minimumIntegerDigits = "7";
224     string maximumFractionDigits = "2";
225     string style = "currency";
226     string currency = "EUR";
227     map<string, string> options = { { "useGrouping", useGrouping },
228                                     { "style", style },
229                                     { "currency", currency },
230                                     { "currencyDisplay", "name" },
231                                     { "currencySign", "accounting" },
232                                     { "signDisplay", "always" } };
233     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
234     if (!numFmt) {
235         EXPECT_TRUE(false);
236         return;
237     }
238     string out = numFmt->Format(123456.789);
239     EXPECT_EQ(out, expects);
240     EXPECT_EQ(numFmt->GetUseGrouping(), useGrouping);
241     EXPECT_EQ(numFmt->GetStyle(), style);
242     EXPECT_EQ(numFmt->GetCurrency(), currency);
243     delete numFmt;
244 }
245 
246 /**
247  * @tc.name: IntlFuncTest007
248  * @tc.desc: Test Intl DateTimeFormat.format
249  * @tc.type: FUNC
250  */
251 HWTEST_F(IntlTest, IntlFuncTest007, TestSize.Level1)
252 {
253     string locale = "zh-CN";
254     string expects = "0,123,456.79米";
255     vector<string> locales;
256     locales.push_back("ban");
257     locales.push_back(locale);
258     string minimumIntegerDigits = "7";
259     string maximumFractionDigits = "2";
260     string style = "unit";
261     map<string, string> options = { { "style", style },
262                                     { "minimumIntegerDigits", minimumIntegerDigits },
263                                     { "maximumFractionDigits", maximumFractionDigits },
264                                     { "unit", "meter" },
265                                     { "unitDisplay", "long"} };
266     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
267     if (!numFmt) {
268         EXPECT_TRUE(false);
269         return;
270     }
271     string out = numFmt->Format(123456.789);
272     EXPECT_EQ(out, expects);
273     EXPECT_EQ(numFmt->GetStyle(), style);
274     delete numFmt;
275 }
276 
277 /**
278  * @tc.name: IntlFuncTest008
279  * @tc.desc: Test Intl DateTimeFormat.format
280  * @tc.type: FUNC
281  */
282 HWTEST_F(IntlTest, IntlFuncTest008, TestSize.Level1)
283 {
284     string locale = "en-CN";
285     string expects = "0,123,456.79%";
286     vector<string> locales;
287     locales.push_back(locale);
288     string minimumIntegerDigits = "7";
289     string maximumFractionDigits = "2";
290     string style = "percent";
291     map<string, string> options = { { "style", style },
292                                     { "minimumIntegerDigits", minimumIntegerDigits },
293                                     { "maximumFractionDigits", maximumFractionDigits } };
294     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
295     if (!numFmt) {
296         EXPECT_TRUE(false);
297         return;
298     }
299     string out = numFmt->Format(123456.789);
300     EXPECT_EQ(out, expects);
301     EXPECT_EQ(numFmt->GetStyle(), style);
302     delete numFmt;
303 }
304 
305 /**
306  * @tc.name: IntlFuncTest009
307  * @tc.desc: Test Intl DateTimeFormat.format
308  * @tc.type: FUNC
309  */
310 HWTEST_F(IntlTest, IntlFuncTest009, TestSize.Level1)
311 {
312     string locale = "en-CN";
313     string expects = "0,123,456.79";
314     vector<string> locales;
315     locales.push_back(locale);
316     string minimumIntegerDigits = "7";
317     string maximumFractionDigits = "2";
318     string style = "decimal";
319     map<string, string> options = { { "style", style },
320                                     { "minimumIntegerDigits", minimumIntegerDigits },
321                                     { "maximumFractionDigits", maximumFractionDigits } };
322     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
323     if (!numFmt) {
324         EXPECT_TRUE(false);
325         return;
326     }
327     string out = numFmt->Format(123456.789);
328     EXPECT_EQ(out, expects);
329     EXPECT_EQ(numFmt->GetStyle(), style);
330     delete numFmt;
331 }
332 
333 /**
334  * @tc.name: IntlFuncTest0010
335  * @tc.desc: Test Intl DateTimeFormat.format
336  * @tc.type: FUNC
337  */
338 HWTEST_F(IntlTest, IntlFuncTest010, TestSize.Level1)
339 {
340     string locale = "en-CN";
341     string expects = "1.234568E5";
342     vector<string> locales;
343     locales.push_back(locale);
344     string style = "decimal";
345     map<string, string> options = { { "style", style },
346                                     { "notation", "scientific" } };
347     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
348     if (!numFmt) {
349         EXPECT_TRUE(false);
350         return;
351     }
352     string out = numFmt->Format(123456.789);
353     EXPECT_EQ(out, expects);
354     EXPECT_EQ(numFmt->GetStyle(), style);
355     delete numFmt;
356 }
357 
358 /**
359  * @tc.name: IntlFuncTest0011
360  * @tc.desc: Test Intl DateTimeFormat.format
361  * @tc.type: FUNC
362  */
363 HWTEST_F(IntlTest, IntlFuncTest011, TestSize.Level1)
364 {
365     string locale = "en-CN";
366     string expects = "123 thousand";
367     vector<string> locales;
368     locales.push_back(locale);
369     string style = "decimal";
370     map<string, string> options = { { "style", style },
371                                     { "notation", "compact" },
372                                     { "compactDisplay", "long" } };
373     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
374     if (!numFmt) {
375         EXPECT_TRUE(false);
376         return;
377     }
378     string out = numFmt->Format(123456.789);
379     EXPECT_EQ(out, expects);
380     EXPECT_EQ(numFmt->GetStyle(), style);
381     delete numFmt;
382 }
383 
384 /**
385  * @tc.name: IntlFuncTest0012
386  * @tc.desc: Test Intl LocaleInfo
387  * @tc.type: FUNC
388  */
389 HWTEST_F(IntlTest, IntlFuncTest0012, TestSize.Level1)
390 {
391     string locale = "en";
392     map<string, string> options = {};
393     vector<string> locales;
394     locales.push_back(locale);
395     std::string expects = "3/11/82";
396     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
397     if (!dateFormat) {
398         EXPECT_TRUE(false);
399         return;
400     }
401     int64_t milliseconds = 123456789123456;
402     string out = dateFormat->Format(milliseconds);
403     EXPECT_EQ(out, expects);
404     delete dateFormat;
405 }
406 
407 /**
408  * @tc.name: IntlFuncTest0013
409  * @tc.desc: Test Intl LocaleInfo
410  * @tc.type: FUNC
411  */
412 HWTEST_F(IntlTest, IntlFuncTest0013, TestSize.Level1)
413 {
414     string locale = "en-CN";
415     vector<string> locales;
416     locales.push_back(locale);
417     map<string, string> options = {};
418     std::string expects = "123,456.789";
419     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
420     if (!numFmt) {
421         EXPECT_TRUE(false);
422         return;
423     }
424     string out = numFmt->Format(123456.789);
425     EXPECT_EQ(out, expects);
426     delete numFmt;
427 }
428 
429 /**
430  * @tc.name: IntlFuncTest0014
431  * @tc.desc: Test Intl LocaleInfo
432  * @tc.type: FUNC
433  */
434 HWTEST_F(IntlTest, IntlFuncTest0014, TestSize.Level1)
435 {
436     string locale = "zh-CN-u-hc-h12";
437     string expects = "北美太平洋标准时间";
438     vector<string> locales;
439     locales.push_back("jessie");
440     locales.push_back(locale);
441     map<string, string> options = { { "timeZone", "America/Los_Angeles"  }, { "timeZoneName", "long" } };
442     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
443     if (!dateFormat) {
444         EXPECT_TRUE(false);
445         return;
446     }
447     int64_t milliseconds = 123456789;
448     string out = dateFormat->Format(milliseconds);
449     EXPECT_TRUE(out.find(expects) != out.npos);
450     delete dateFormat;
451 }
452 
453 /**
454  * @tc.name: IntlFuncTest0015
455  * @tc.desc: Test Intl LocaleInfo
456  * @tc.type: FUNC
457  */
458 HWTEST_F(IntlTest, IntlFuncTest0015, TestSize.Level1)
459 {
460     string locale = "zh-CN-u-hc-h12";
461     vector<string> locales;
462     locales.push_back("jessie");
463     locales.push_back(locale);
464     map<string, string> options = { { "timeZone", "America/Los_Angeles"  }, { "timeZoneName", "long" } };
465     DateTimeFormat *dateFormat = new (std::nothrow) DateTimeFormat(locales, options);
466     if (!dateFormat) {
467         EXPECT_TRUE(false);
468         return;
469     }
470     EXPECT_EQ(dateFormat->GetTimeZone(), "America/Los_Angeles");
471     EXPECT_EQ(dateFormat->GetTimeZoneName(), "long");
472     delete dateFormat;
473 }
474 
475 /**
476  * @tc.name: IntlFuncTest0016
477  * @tc.desc: Test Intl Collator
478  * @tc.type: FUNC
479  */
480 HWTEST_F(IntlTest, IntlFuncTest0016, TestSize.Level1)
481 {
482     // normal test case
483     vector<string> locales;
484     locales.push_back("en-US");
485     map<string, string> inputOptions;
486     Collator *collator = new Collator(locales, inputOptions);
487     const string param1 = "abc";
488     const string param2 = "cba";
489     CompareResult result = collator->Compare(param1, param2);
490     EXPECT_EQ(result, CompareResult::SMALLER);
491 
492     map<string, string> options;
493     collator->ResolvedOptions(options);
494     EXPECT_EQ(options.size(), 8);
495     map<string, string>::iterator it = options.find("localeMatcher");
496     if (it != options.end()) {
497         EXPECT_EQ(it->second, "best fit");
498     }
499     it = options.find("locale");
500     if (it != options.end()) {
501         EXPECT_EQ(it->second, "en-US");
502     }
503     it = options.find("usage");
504     if (it != options.end()) {
505         EXPECT_EQ(it->second, "sort");
506     }
507     it = options.find("sensitivity");
508     if (it != options.end()) {
509         EXPECT_EQ(it->second, "variant");
510     }
511     it = options.find("ignorePunctuation");
512     if (it != options.end()) {
513         EXPECT_EQ(it->second, "false");
514     }
515     it = options.find("numeric");
516     if (it != options.end()) {
517         EXPECT_EQ(it->second, "false");
518     }
519     it = options.find("caseFirst");
520     if (it != options.end()) {
521         EXPECT_EQ(it->second, "false");
522     }
523     it = options.find("collation");
524     if (it != options.end()) {
525         EXPECT_EQ(it->second, "default");
526     }
527     delete collator;
528 }
529 
530 /**
531  * @tc.name: IntlFuncTest0017
532  * @tc.desc: Test Intl Collator
533  * @tc.type: FUNC
534  */
535 HWTEST_F(IntlTest, IntlFuncTest0017, TestSize.Level1)
536 {
537     // normal test case
538     vector<string> locales;
539     locales.push_back("zh-Hans");
540     locales.push_back("en-US");
541     map<string, string> inputOptions = {
542         { "localeMatcher", "lookup" },
543         { "usage", "search"},
544         { "sensitivity", "case"},
545         { "ignorePunctuation", "true" },
546         { "collation", "pinyin"},
547         { "numeric", "true"},
548         { "caseFirst", "upper"}
549     };
550     Collator *collator = new Collator(locales, inputOptions);
551     const string param1 = "啊";
552     const string param2 = "播";
553     CompareResult result = collator->Compare(param1, param2);
554     EXPECT_EQ(result, CompareResult::SMALLER);
555 
556     map<string, string> options;
557     collator->ResolvedOptions(options);
558     EXPECT_EQ(options.size(), 8);
559     map<string, string>::iterator it = options.find("localeMatcher");
560     if (it != options.end()) {
561         EXPECT_EQ(it->second, "lookup");
562     }
563     it = options.find("locale");
564     if (it != options.end()) {
565         EXPECT_EQ(it->second, "zh-Hans");
566     }
567     it = options.find("usage");
568     if (it != options.end()) {
569         EXPECT_EQ(it->second, "search");
570     }
571     it = options.find("sensitivity");
572     if (it != options.end()) {
573         EXPECT_EQ(it->second, "case");
574     }
575     delete collator;
576 }
577 
578 /**
579  * @tc.name: IntlFuncTest0018
580  * @tc.desc: Test Intl Collator
581  * @tc.type: FUNC
582  */
583 HWTEST_F(IntlTest, IntlFuncTest0018, TestSize.Level1)
584 {
585     // normal test case
586     vector<string> locales;
587     locales.push_back("zh-Hans");
588     locales.push_back("en-US");
589     map<string, string> inputOptions = {
590         { "ignorePunctuation", "true" },
591         { "collation", "pinyin"},
592         { "numeric", "true"},
593         { "caseFirst", "upper"}
594     };
595     Collator *collator = new Collator(locales, inputOptions);
596     map<string, string> options;
597     collator->ResolvedOptions(options);
598     map<string, string>::iterator it = options.find("ignorePunctuation");
599     if (it != options.end()) {
600         EXPECT_EQ(it->second, "true");
601     }
602     it = options.find("numeric");
603     if (it != options.end()) {
604         EXPECT_EQ(it->second, "true");
605     }
606     it = options.find("caseFirst");
607     if (it != options.end()) {
608         EXPECT_EQ(it->second, "upper");
609     }
610     it = options.find("collation");
611     if (it != options.end()) {
612         EXPECT_EQ(it->second, "pinyin");
613     }
614     delete collator;
615 }
616 
617 /**
618  * @tc.name: IntlFuncTest0019
619  * @tc.desc: Test Intl Collator
620  * @tc.type: FUNC
621  */
622 HWTEST_F(IntlTest, IntlFuncTest0019, TestSize.Level1)
623 {
624     // abnormal test case
625     vector<string> locales;
626     locales.push_back("fake locale");
627     map<string, string> inputOptions = {
628         { "localeMatcher", "fake value" },
629         { "usage", "fake value"},
630         { "sensitivity", "fake value"},
631         { "ignorePunctuation", "fake value" },
632         { "collation", "fake value"},
633         { "numeric", "fake value"},
634         { "caseFirst", "fake value"},
635         { "fake key", "fake value"}
636     };
637     Collator *collator = new Collator(locales, inputOptions);
638     const string param1 = "abc";
639     const string param2 = "cba";
640     CompareResult result = collator->Compare(param1, param2);
641     EXPECT_EQ(result, CompareResult::SMALLER);
642 
643     map<string, string> options;
644     collator->ResolvedOptions(options);
645     EXPECT_EQ(options.size(), 8);
646     map<string, string>::iterator it = options.find("localeMatcher");
647     if (it != options.end()) {
648         EXPECT_EQ(it->second, "fake value");
649     }
650     std::string systemLocale = LocaleConfig::GetSystemLocale();
651     it = options.find("locale");
652     if (it != options.end()) {
653         EXPECT_EQ(it->second, systemLocale);
654     }
655     it = options.find("usage");
656     if (it != options.end()) {
657         EXPECT_EQ(it->second, "fake value");
658     }
659     it = options.find("sensitivity");
660     if (it != options.end()) {
661         EXPECT_EQ(it->second, "fake value");
662     }
663     delete collator;
664 }
665 
666 /**
667  * @tc.name: IntlFuncTest0020
668  * @tc.desc: Test Intl Collator
669  * @tc.type: FUNC
670  */
671 HWTEST_F(IntlTest, IntlFuncTest0020, TestSize.Level1)
672 {
673     // abnormal test case
674     vector<string> locales;
675     locales.push_back("fake locale");
676     map<string, string> inputOptions = {
677         { "ignorePunctuation", "fake value" },
678         { "collation", "fake value"},
679         { "numeric", "fake value"},
680         { "caseFirst", "fake value"},
681         { "fake key", "fake value"}
682     };
683     Collator *collator = new Collator(locales, inputOptions);
684     map<string, string> options;
685     collator->ResolvedOptions(options);
686     map<string, string>::iterator it = options.find("ignorePunctuation");
687     if (it != options.end()) {
688         EXPECT_EQ(it->second, "fake value");
689     }
690     it = options.find("numeric");
691     if (it != options.end()) {
692         EXPECT_EQ(it->second, "fake value");
693     }
694     it = options.find("caseFirst");
695     if (it != options.end()) {
696         EXPECT_EQ(it->second, "fake value");
697     }
698     it = options.find("collation");
699     if (it != options.end()) {
700         EXPECT_EQ(it->second, "default");
701     }
702     delete collator;
703 }
704 
705 /**
706  * @tc.name: IntlFuncTest0021
707  * @tc.desc: Test Intl PluralRules
708  * @tc.type: FUNC
709  */
710 HWTEST_F(IntlTest, IntlFuncTest0021, TestSize.Level1)
711 {
712     // normal test case
713     vector<string> locales;
714     locales.push_back("en-US");
715     map<string, string> options;
716     PluralRules *plurals = new PluralRules(locales, options);
717     string res = plurals->Select(0);
718     EXPECT_EQ(res, "other");
719     res = plurals->Select(1);
720     EXPECT_EQ(res, "one");
721     res = plurals->Select(2);
722     EXPECT_EQ(res, "other");
723     res = plurals->Select(5);
724     EXPECT_EQ(res, "other");
725     res = plurals->Select(20);
726     EXPECT_EQ(res, "other");
727     res = plurals->Select(200);
728     EXPECT_EQ(res, "other");
729     res = plurals->Select(12.34);
730     EXPECT_EQ(res, "other");
731     delete plurals;
732 }
733 
734 /**
735  * @tc.name: IntlFuncTest0022
736  * @tc.desc: Test Intl PluralRules
737  * @tc.type: FUNC
738  */
739 HWTEST_F(IntlTest, IntlFuncTest0022, TestSize.Level1)
740 {
741     // normal test case
742     vector<string> locales;
743     locales.push_back("ar");
744     map<string, string> options;
745     PluralRules *plurals = new PluralRules(locales, options);
746     string res = plurals->Select(0);
747     EXPECT_EQ(res, "zero");
748     res = plurals->Select(1);
749     EXPECT_EQ(res, "one");
750     res = plurals->Select(2);
751     EXPECT_EQ(res, "two");
752     res = plurals->Select(5);
753     EXPECT_EQ(res, "few");
754     res = plurals->Select(20);
755     EXPECT_EQ(res, "many");
756     res = plurals->Select(200);
757     EXPECT_EQ(res, "other");
758     res = plurals->Select(12.34);
759     EXPECT_EQ(res, "other");
760     delete plurals;
761 }
762 
763 /**
764  * @tc.name: IntlFuncTest0023
765  * @tc.desc: Test Intl PluralRules
766  * @tc.type: FUNC
767  */
768 HWTEST_F(IntlTest, IntlFuncTest0023, TestSize.Level1)
769 {
770     // normal test case
771     vector<string> locales;
772     locales.push_back("ar");
773     map<string, string> options = {
774         { "localeMatcher", "best fit" },
775         { "type", "cardinal" },
776         { "minimumIntegerDigits", "1" },
777         { "minimumFractionDigits", "0" },
778         { "maximumFractionDigits", "21" },
779         { "minimumSignificantDigits", "21" },
780         { "maximumSignificantDigits", "21" },
781     };
782     PluralRules *plurals = new PluralRules(locales, options);
783     string res = plurals->Select(0);
784     EXPECT_EQ(res, "zero");
785     res = plurals->Select(1);
786     EXPECT_EQ(res, "one");
787     res = plurals->Select(2);
788     EXPECT_EQ(res, "two");
789     res = plurals->Select(5);
790     EXPECT_EQ(res, "few");
791     res = plurals->Select(20);
792     EXPECT_EQ(res, "many");
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: IntlFuncTest0024
802  * @tc.desc: Test Intl PluralRules
803  * @tc.type: FUNC
804  */
805 HWTEST_F(IntlTest, IntlFuncTest0024, TestSize.Level1)
806 {
807     // abnormal test cast
808     // normal test case
809     vector<string> locales;
810     locales.push_back("fake_locale");
811     map<string, string> options = {
812         { "fake_localeMatcher", "best fit" },
813         { "type", "fake_cardinal" },
814         { "minimumIntegerDigits", "11111" },
815         { "minimumFractionDigits", "-111" },
816         { "maximumFractionDigits", "-111" },
817         { "minimumSignificantDigits", "11111" },
818         { "maximumSignificantDigits", "11111" },
819     };
820     PluralRules *plurals = new PluralRules(locales, options);
821     string res = plurals->Select(0);
822     EXPECT_EQ(res, "other");
823     res = plurals->Select(1);
824     EXPECT_EQ(res, "other");
825     res = plurals->Select(2);
826     EXPECT_EQ(res, "other");
827     res = plurals->Select(5);
828     EXPECT_EQ(res, "other");
829     res = plurals->Select(20);
830     EXPECT_EQ(res, "other");
831     res = plurals->Select(200);
832     EXPECT_EQ(res, "other");
833     res = plurals->Select(12.34);
834     EXPECT_EQ(res, "other");
835     delete plurals;
836 }
837 
838 /**
839  * @tc.name: IntlFuncTest0025
840  * @tc.desc: Test Intl RelativeTimeFormat
841  * @tc.type: FUNC
842  */
843 HWTEST_F(IntlTest, IntlFuncTest0025, TestSize.Level1)
844 {
845     vector<string> locales;
846     locales.push_back("en-US");
847     map<string, string> options;
848     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
849 
850     double number = 2022;
851     string unit = "year";
852     string res = formatter->Format(number, unit);
853     EXPECT_EQ(res, "in 2,022 years");
854     vector<vector<string>> timeVector;
855     formatter->FormatToParts(number, unit, timeVector);
856     EXPECT_EQ(timeVector.size(), 5);
857 
858     number = 3;
859     unit = "quarter";
860     res = formatter->Format(number, unit);
861     EXPECT_EQ(res, "in 3 quarters");
862     formatter->FormatToParts(number, unit, timeVector);
863     EXPECT_EQ(timeVector.size(), 8);
864 
865     number = 11;
866     unit = "month";
867     res = formatter->Format(number, unit);
868     EXPECT_EQ(res, "in 11 months");
869     formatter->FormatToParts(number, unit, timeVector);
870     EXPECT_EQ(timeVector.size(), 11);
871 
872     number = 2;
873     unit = "week";
874     res = formatter->Format(number, unit);
875     EXPECT_EQ(res, "in 2 weeks");
876     formatter->FormatToParts(number, unit, timeVector);
877     EXPECT_EQ(timeVector.size(), 14);
878 
879     number = 18;
880     unit = "day";
881     res = formatter->Format(number, unit);
882     EXPECT_EQ(res, "in 18 days");
883     formatter->FormatToParts(number, unit, timeVector);
884     EXPECT_EQ(timeVector.size(), 17);
885     delete formatter;
886 }
887 
888 /**
889  * @tc.name: IntlFuncTest0026
890  * @tc.desc: Test Intl RelativeTimeFormat
891  * @tc.type: FUNC
892  */
893 HWTEST_F(IntlTest, IntlFuncTest0026, TestSize.Level1)
894 {
895     vector<string> locales;
896     locales.push_back("en-US");
897     map<string, string> options;
898     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
899 
900     double number = 23;
901     string unit = "hour";
902     string res = formatter->Format(number, unit);
903     EXPECT_EQ(res, "in 23 hours");
904     vector<vector<string>> timeVector;
905     formatter->FormatToParts(number, unit, timeVector);
906     EXPECT_EQ(timeVector.size(), 3);
907 
908     number = 59;
909     unit = "minute";
910     res = formatter->Format(number, unit);
911     EXPECT_EQ(res, "in 59 minutes");
912     formatter->FormatToParts(number, unit, timeVector);
913     EXPECT_EQ(timeVector.size(), 6);
914 
915     number = 1;
916     unit = "second";
917     res = formatter->Format(number, unit);
918     EXPECT_EQ(res, "in 1 second");
919     formatter->FormatToParts(number, unit, timeVector);
920     EXPECT_EQ(timeVector.size(), 9);
921 
922     delete formatter;
923 }
924 
925 /**
926  * @tc.name: IntlFuncTest0027
927  * @tc.desc: Test Intl RelativeTimeFormat
928  * @tc.type: FUNC
929  */
930 HWTEST_F(IntlTest, IntlFuncTest0027, TestSize.Level1)
931 {
932     vector<string> locales;
933     locales.push_back("zh-Hans");
934     map<string, string> options = {
935         { "localeMatcher", "best fit" },
936         { "numeric", "auto" },
937         { "style", "long" }
938     };
939     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
940 
941     double number = 2022;
942     string unit = "year";
943     string res = formatter->Format(number, unit);
944     EXPECT_EQ(res, "2,022年后");
945     vector<vector<string>> timeVector;
946     formatter->FormatToParts(number, unit, timeVector);
947     EXPECT_EQ(timeVector.size(), 4);
948 
949     number = 3;
950     unit = "quarter";
951     res = formatter->Format(number, unit);
952     EXPECT_EQ(res, "3个季度后");
953     formatter->FormatToParts(number, unit, timeVector);
954     EXPECT_EQ(timeVector.size(), 6);
955 
956     number = 11;
957     unit = "month";
958     res = formatter->Format(number, unit);
959     EXPECT_EQ(res, "11个月后");
960     formatter->FormatToParts(number, unit, timeVector);
961     EXPECT_EQ(timeVector.size(), 8);
962 
963     number = 2;
964     unit = "week";
965     res = formatter->Format(number, unit);
966     EXPECT_EQ(res, "2周后");
967     formatter->FormatToParts(number, unit, timeVector);
968     EXPECT_EQ(timeVector.size(), 10);
969     delete formatter;
970 }
971 
972 /**
973  * @tc.name: IntlFuncTest0028
974  * @tc.desc: Test Intl RelativeTimeFormat
975  * @tc.type: FUNC
976  */
977 HWTEST_F(IntlTest, IntlFuncTest0028, TestSize.Level1)
978 {
979     vector<string> locales;
980     locales.push_back("zh-Hans");
981     map<string, string> options = {
982         { "localeMatcher", "lookup" },
983         { "numeric", "auto" },
984         { "style", "long" }
985     };
986     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
987 
988     double number = 18;
989     string unit = "day";
990     string res = formatter->Format(number, unit);
991     EXPECT_EQ(res, "18天后");
992     vector<vector<string>> timeVector;
993     formatter->FormatToParts(number, unit, timeVector);
994     EXPECT_EQ(timeVector.size(), 2);
995 
996     number = 23;
997     unit = "hour";
998     res = formatter->Format(number, unit);
999     EXPECT_EQ(res, "23小时后");
1000     formatter->FormatToParts(number, unit, timeVector);
1001     EXPECT_EQ(timeVector.size(), 4);
1002 
1003     number = 59;
1004     unit = "minute";
1005     res = formatter->Format(number, unit);
1006     EXPECT_EQ(res, "59分钟后");
1007     formatter->FormatToParts(number, unit, timeVector);
1008     EXPECT_EQ(timeVector.size(), 6);
1009 
1010     number = 1;
1011     unit = "second";
1012     res = formatter->Format(number, unit);
1013     EXPECT_EQ(res, "1秒钟后");
1014     formatter->FormatToParts(number, unit, timeVector);
1015     EXPECT_EQ(timeVector.size(), 8);
1016 
1017     delete formatter;
1018 }
1019 
1020 /**
1021  * @tc.name: IntlFuncTest0029
1022  * @tc.desc: Test Intl RelativeTimeFormatter
1023  * @tc.type: FUNC
1024  */
1025 HWTEST_F(IntlTest, IntlFuncTest0029, TestSize.Level1)
1026 {
1027     vector<string> locales;
1028     locales.push_back("xxxx");
1029     locales.push_back("zh-Hans");
1030     map<string, string> options = {
1031         { "localeMatcher", "best fit" },
1032         { "numeric", "auto" },
1033         { "style", "long" }
1034     };
1035     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
1036     map<string, string> res;
1037     formatter->GetResolvedOptions(res);
1038     EXPECT_EQ(res.size(), 4);
1039 
1040     map<string, string>::iterator it = res.find("locale");
1041     if (it != res.end()) {
1042         EXPECT_EQ(it->second, "zh-Hans");
1043     }
1044     it = res.find("style");
1045     if (it != res.end()) {
1046         EXPECT_EQ(it->second, "long");
1047     }
1048     it = res.find("numeric");
1049     if (it != res.end()) {
1050         EXPECT_EQ(it->second, "auto");
1051     }
1052     it = res.find("numberingSystem");
1053     if (it != res.end()) {
1054         EXPECT_EQ(it->second, "latn");
1055     }
1056     delete formatter;
1057 }
1058 
1059 /**
1060  * @tc.name: IntlFuncTest0030
1061  * @tc.desc: Test Intl NumberFormat
1062  * @tc.type: FUNC
1063  */
1064 HWTEST_F(IntlTest, IntlFuncTest0030, TestSize.Level1)
1065 {
1066     vector<string> locales;
1067     locales.push_back("en-US");
1068     map<string, string> options;
1069     NumberFormat *formatter = new NumberFormat(locales, options);
1070 
1071     string res = formatter->Format(123);
1072     EXPECT_EQ(res, "123");
1073     res = formatter->Format(123.456);
1074     EXPECT_EQ(res, "123.456");
1075 
1076     delete formatter;
1077 }
1078 
1079 /**
1080  * @tc.name: IntlFuncTest0031
1081  * @tc.desc: Test Intl NumberFormat
1082  * @tc.type: FUNC
1083  */
1084 HWTEST_F(IntlTest, IntlFuncTest0031, TestSize.Level1)
1085 {
1086     vector<string> locales;
1087     locales.push_back("zh-Hans");
1088     map<string, string> options = {
1089         { "locale", "zh-Hans" },
1090         { "currency", "EUR" },
1091         { "currencySign", "narrowSymbol" },
1092         { "currencyDisplay", "symbol" },
1093         { "unit", "meter" },
1094         { "unitDisplay", "long" },
1095         { "unitUsage", "length-person" },
1096         { "signDisplay", "always" },
1097         { "compactDisplay", "long" },
1098         { "notation", "standard" },
1099         { "localeMatcher", "lookup" },
1100         { "style", "decimal" },
1101         { "numberingSystem", "latn" },
1102         { "useGroup", "true" },
1103         { "minimumIntegerDigits", "1" },
1104         { "minimumFractionDigits", "0" },
1105         { "maximumFractionDigits", "20" },
1106         { "minimumSignificantDigits", "1" },
1107         { "maximumSignificantDigits", "20" }
1108     };
1109     NumberFormat *formatter = new NumberFormat(locales, options);
1110 
1111     string formatRes = formatter->Format(123);
1112     EXPECT_EQ(formatRes, "+123");
1113     formatRes = formatter->Format(123.456);
1114     EXPECT_EQ(formatRes, "+123.456");
1115 
1116     map<string, string> res;
1117     formatter->GetResolvedOptions(res);
1118     EXPECT_EQ(res.size(), 11);
1119     map<string, string>::iterator it = res.find("locale");
1120     if (it != res.end()) {
1121         EXPECT_EQ(it->second, "zh-Hans");
1122     }
1123     it = res.find("signDisplay");
1124     if (it != res.end()) {
1125         EXPECT_EQ(it->second, "always");
1126     }
1127     it = res.find("notation");
1128     if (it != res.end()) {
1129         EXPECT_EQ(it->second, "standard");
1130     }
1131     delete formatter;
1132 }
1133 
1134 /**
1135  * @tc.name: IntlFuncTest0032
1136  * @tc.desc: Test Intl NumberFormat
1137  * @tc.type: FUNC
1138  */
1139 HWTEST_F(IntlTest, IntlFuncTest0032, TestSize.Level1)
1140 {
1141     vector<string> locales;
1142     locales.push_back("zh-Hans");
1143     map<string, string> options = {
1144         { "locale", "zh-Hans" },
1145         { "currency", "CNY" },
1146         { "currencySign", "symbol" },
1147         { "currencyDisplay", "symbol" },
1148         { "unit", "meter" },
1149         { "unitDisplay", "long" },
1150         { "unitUsage", "length-person" },
1151         { "signDisplay", "always" },
1152         { "compactDisplay", "long" },
1153         { "notation", "standard" },
1154         { "localeMatcher", "best fit" },
1155         { "style", "decimal" },
1156         { "numberingSystem", "latn" },
1157         { "useGroup", "true" },
1158         { "minimumIntegerDigits", "1" },
1159         { "minimumFractionDigits", "0" },
1160         { "maximumFractionDigits", "21" },
1161         { "minimumSignificantDigits", "1" },
1162         { "maximumSignificantDigits", "21" }
1163     };
1164     NumberFormat *formatter = new NumberFormat(locales, options);
1165     map<string, string> res;
1166     formatter->GetResolvedOptions(res);
1167     map<string, string>::iterator it = res.find("style");
1168     if (it != res.end()) {
1169         EXPECT_EQ(it->second, "decimal");
1170     }
1171     it = res.find("numberingSystem");
1172     if (it != res.end()) {
1173         EXPECT_EQ(it->second, "latn");
1174     }
1175     it = res.find("useGrouping");
1176     if (it != res.end()) {
1177         EXPECT_EQ(it->second, "true");
1178     }
1179     it = res.find("minimumIntegerDigits");
1180     if (it != res.end()) {
1181         EXPECT_EQ(it->second, "1");
1182     }
1183     it = res.find("minimumFractionDigits");
1184     if (it != res.end()) {
1185         EXPECT_EQ(it->second, "0");
1186     }
1187     delete formatter;
1188 }
1189 
1190 /**
1191  * @tc.name: IntlFuncTest0033
1192  * @tc.desc: Test Intl NumberFormat
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(IntlTest, IntlFuncTest0033, TestSize.Level1)
1196 {
1197     vector<string> locales;
1198     locales.push_back("zh-Hans");
1199     map<string, string> options = {
1200         { "locale", "fake locale" },
1201         { "currency", "fake currency" },
1202         { "currencySign", "fake sign" },
1203         { "currencyDisplay", "symbol" },
1204         { "unit", "meter" },
1205         { "unitDisplay", "fake value" },
1206         { "unitUsage", "length-person" },
1207         { "signDisplay", "always" },
1208         { "compactDisplay", "long" },
1209         { "notation", "fake value" },
1210         { "localeMatcher", "best fit" },
1211         { "style", "decimal" },
1212         { "numberingSystem", "latn" },
1213         { "useGroup", "fake value" },
1214         { "minimumIntegerDigits", "1" },
1215         { "minimumFractionDigits", "0" },
1216         { "maximumFractionDigits", "21" },
1217         { "minimumSignificantDigits", "1" },
1218         { "maximumSignificantDigits", "21" }
1219     };
1220     NumberFormat *formatter = new NumberFormat(locales, options);
1221     map<string, string> res;
1222     formatter->GetResolvedOptions(res);
1223     map<string, string>::iterator it = res.find("maximumFractionDigits");
1224     if (it != res.end()) {
1225         EXPECT_EQ(it->second, "21");
1226     }
1227     it = res.find("minimumSignificantDigits");
1228     if (it != res.end()) {
1229         EXPECT_EQ(it->second, "1");
1230     }
1231     it = res.find("maximumSignificantDigits");
1232     if (it != res.end()) {
1233         EXPECT_EQ(it->second, "21");
1234     }
1235     delete formatter;
1236 }
1237 
1238 /**
1239  * @tc.name: IntlFuncTest0034
1240  * @tc.desc: Test Intl NumberFormat
1241  * @tc.type: FUNC
1242  */
1243 HWTEST_F(IntlTest, IntlFuncTest0034, TestSize.Level1)
1244 {
1245     vector<string> locales;
1246     locales.push_back("en-US");
1247     map<string, string> options = {
1248         { "locale", "fake locale" },
1249         { "currency", "USD" },
1250         { "currencySign", "symbol" },
1251         { "currencyDisplay", "symbol" },
1252         { "unit", "fake unit" },
1253         { "unitDisplay", "long" },
1254         { "unitUsage", "fake usage" },
1255         { "signDisplay", "always" },
1256         { "compactDisplay", "long" },
1257         { "notation", "standard" },
1258         { "localeMatcher", "lookup" },
1259         { "style", "currency" },
1260         { "numberingSystem", "latn" },
1261         { "useGrouping", "true" },
1262         { "minimumIntegerDigits", "1" },
1263         { "minimumFractionDigits", "0" },
1264         { "maximumFractionDigits", "20" },
1265         { "minimumSignificantDigits", "1" },
1266         { "maximumSignificantDigits", "20" }
1267     };
1268     NumberFormat *formatter = new NumberFormat(locales, options);
1269     string res = formatter->Format(123);
1270     EXPECT_EQ(res, "+$123");
1271     res = formatter->Format(123.456);
1272     EXPECT_EQ(res, "+$123.456");
1273     res = formatter->GetCurrency();
1274     EXPECT_EQ(res, "USD");
1275     res = formatter->GetCurrencySign();
1276     EXPECT_EQ(res, "symbol");
1277     res = formatter->GetStyle();
1278     EXPECT_EQ(res, "currency");
1279     res = formatter->GetNumberingSystem();
1280     EXPECT_EQ(res, "latn");
1281     delete formatter;
1282 }
1283 
1284 /**
1285  * @tc.name: IntlFuncTest0035
1286  * @tc.desc: Test Intl NumberFormat
1287  * @tc.type: FUNC
1288  */
1289 HWTEST_F(IntlTest, IntlFuncTest0035, TestSize.Level1)
1290 {
1291     vector<string> locales;
1292     locales.push_back("en-US");
1293     map<string, string> options = {
1294         { "locale", "fake locale" },
1295         { "currency", "USD" },
1296         { "currencySign", "fake sign" },
1297         { "currencyDisplay", "symbol" },
1298         { "unit", "fake unit" },
1299         { "unitDisplay", "long" },
1300         { "unitUsage", "length-person" },
1301         { "signDisplay", "fake display" },
1302         { "compactDisplay", "long" },
1303         { "notation", "standard" },
1304         { "localeMatcher", "lookup" },
1305         { "style", "currency" },
1306         { "numberingSystem", "latn" },
1307         { "useGrouping", "false" },
1308         { "minimumIntegerDigits", "1" },
1309         { "minimumFractionDigits", "0" },
1310         { "maximumFractionDigits", "17" },
1311         { "minimumSignificantDigits", "1" },
1312         { "maximumSignificantDigits", "17" }
1313     };
1314     NumberFormat *formatter = new NumberFormat(locales, options);
1315     string res = formatter->GetUseGrouping();
1316     EXPECT_EQ(res, "false");
1317     res = formatter->GetMinimumIntegerDigits();
1318     EXPECT_EQ(res, "1");
1319     res = formatter->GetMinimumFractionDigits();
1320     EXPECT_EQ(res, "0");
1321     res = formatter->GetMaximumFractionDigits();
1322     EXPECT_EQ(res, "17");
1323     res = formatter->GetMinimumSignificantDigits();
1324     EXPECT_EQ(res, "1");
1325     res = formatter->GetMaximumSignificantDigits();
1326     EXPECT_EQ(res, "17");
1327     delete formatter;
1328 }
1329 
1330 /**
1331  * @tc.name: IntlFuncTest0036
1332  * @tc.desc: Test Intl DateTimeFormat
1333  * @tc.type: FUNC
1334  */
1335 HWTEST_F(IntlTest, IntlFuncTest0036, TestSize.Level1)
1336 {
1337     vector<string> locales;
1338     locales.push_back("en-US");
1339     map<string, string> options;
1340     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1341 
1342     int64_t milliseconds = 123456789;
1343     string res = formatter->Format(milliseconds);
1344     EXPECT_EQ(res, "1/2/70");
1345 
1346     int64_t milliseconds2 = 987654321;
1347     res = formatter->FormatRange(milliseconds, milliseconds2);
1348     EXPECT_EQ(res, "1/2/70 \xE2\x80\x93 1/12/70");
1349     delete formatter;
1350 }
1351 
1352 /**
1353  * @tc.name: IntlFuncTest0037
1354  * @tc.desc: Test Intl DateTimeFormat
1355  * @tc.type: FUNC
1356  */
1357 HWTEST_F(IntlTest, IntlFuncTest0037, TestSize.Level1)
1358 {
1359     vector<string> locales;
1360     locales.push_back("zh-CN");
1361     map<string, string> options = {
1362         { "locale", "zh-CN" },
1363         { "dateStyle", "medium" },
1364         { "timeStyle", "long" },
1365         { "hourCycle", "h24" },
1366         { "timeZone", "Asia/Shanghai" },
1367         { "numberingSystem", "latn" },
1368         { "hour12", "false" },
1369         { "weekday", "long" },
1370         { "era", "long" },
1371         { "year", "2-digit" },
1372         { "month", "2-digit" },
1373         { "day", "2-digit" },
1374         { "hour", "2-digit" },
1375         { "minute", "2-digit" },
1376         { "second", "2-digit" },
1377         { "timeZoneName", "long" },
1378         { "dayPeriod", "long" },
1379         { "localeMatcher", "lookup" },
1380         { "formatMatcher", "basic" }
1381     };
1382     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1383 
1384     int64_t milliseconds = 123456789;
1385     string res = formatter->Format(milliseconds);
1386     // 2022年12月19日 GMT+8 15:18:24
1387     EXPECT_TRUE(res.length() > 0);
1388 
1389     int64_t milliseconds2 = 987654321;
1390     res = formatter->FormatRange(milliseconds, milliseconds2);
1391     // 2022/12/19 GMT+8 15:18:24 \xE2\x80\x93 2023/11/18 GMT+8 14:17:23
1392     EXPECT_TRUE(res.length() > 0);
1393 
1394     res = formatter->GetDateStyle();
1395     EXPECT_EQ(res, "medium");
1396     res = formatter->GetTimeStyle();
1397     EXPECT_EQ(res, "long");
1398     res = formatter->GetHourCycle();
1399     EXPECT_EQ(res, "h24");
1400     res = formatter->GetTimeZone();
1401     EXPECT_EQ(res, "Asia/Shanghai");
1402     res = formatter->GetTimeZoneName();
1403     EXPECT_EQ(res, "long");
1404     delete formatter;
1405 }
1406 
1407 /**
1408  * @tc.name: IntlFuncTest0038
1409  * @tc.desc: Test Intl DateTimeFormat
1410  * @tc.type: FUNC
1411  */
1412 HWTEST_F(IntlTest, IntlFuncTest0038, TestSize.Level1)
1413 {
1414     vector<string> locales;
1415     locales.push_back("zh-CN");
1416     map<string, string> options = {
1417         { "locale", "zh-CN" },
1418         { "dateStyle", "full" },
1419         { "timeStyle", "full" },
1420         { "hourCycle", "h24" },
1421         { "timeZone", "Asia/Shanghai" },
1422         { "numberingSystem", "latn" },
1423         { "hour12", "false" },
1424         { "weekday", "long" },
1425         { "era", "long" },
1426         { "year", "numeric" },
1427         { "month", "numeric" },
1428         { "day", "numeric" },
1429         { "hour", "numeric" },
1430         { "minute", "numeric" },
1431         { "second", "numeric" },
1432         { "timeZoneName", "long" },
1433         { "dayPeriod", "long" },
1434         { "localeMatcher", "lookup" },
1435         { "formatMatcher", "basic" }
1436     };
1437     DateTimeFormat *formatter = new DateTimeFormat(locales, options);
1438     string res = formatter->GetNumberingSystem();
1439     EXPECT_EQ(res, "latn");
1440     res = formatter->GetHour12();
1441     EXPECT_EQ(res, "false");
1442     res = formatter->GetWeekday();
1443     EXPECT_EQ(res, "long");
1444     res = formatter->GetEra();
1445     EXPECT_EQ(res, "long");
1446     res = formatter->GetYear();
1447     EXPECT_EQ(res, "numeric");
1448     res = formatter->GetMonth();
1449     EXPECT_EQ(res, "numeric");
1450     res = formatter->GetDay();
1451     EXPECT_EQ(res, "numeric");
1452     res = formatter->GetHour();
1453     EXPECT_EQ(res, "numeric");
1454     res = formatter->GetMinute();
1455     EXPECT_EQ(res, "numeric");
1456     res = formatter->GetSecond();
1457     EXPECT_EQ(res, "numeric");
1458     delete formatter;
1459 }
1460 
1461 /**
1462  * @tc.name: IntlFuncTest0039
1463  * @tc.desc: Test Intl DateTimeFormat
1464  * @tc.type: FUNC
1465  */
1466 HWTEST_F(IntlTest, IntlFuncTest0039, TestSize.Level1)
1467 {
1468     vector<string> locales;
1469     locales.push_back("en-US");
1470     map<string, string> inputOptions = {
1471         { "locale", "en-US" },
1472         { "dateStyle", "medium" },
1473         { "timeStyle", "long" },
1474         { "hourCycle", "h12" },
1475         { "timeZone", "Asia/Shanghai" },
1476         { "numberingSystem", "latn" },
1477         { "hour12", "true" },
1478         { "weekday", "long" },
1479         { "era", "long" },
1480         { "year", "2-digit" },
1481         { "month", "2-digit" },
1482         { "day", "2-digit" },
1483         { "hour", "2-digit" },
1484         { "minute", "2-digit" },
1485         { "second", "2-digit" },
1486         { "timeZoneName", "long" },
1487         { "dayPeriod", "long" },
1488         { "localeMatcher", "lookup" },
1489         { "formatMatcher", "basic" }
1490     };
1491     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1492     int64_t milliseconds = 123456789;
1493     string res = formatter->Format(milliseconds);
1494     // Dec 19, 2022, 3:18:24 PM GMT+8
1495     EXPECT_TRUE(res.length() > 0);
1496     int64_t milliseconds2 = 987654321;
1497     res = formatter->FormatRange(milliseconds, milliseconds2);
1498     // Dec 19, 2022, 3:18:24 PM GMT+8 \xE2\x80\x93 Nov 18, 2023, 2:17:23 PM GMT+8
1499     EXPECT_TRUE(res.length() > 0);
1500     map<string, string> options;
1501     formatter->GetResolvedOptions(options);
1502     EXPECT_EQ(options.size(), 20);
1503     map<string, string>::iterator it = options.find("locale");
1504     if (it != options.end()) {
1505         EXPECT_EQ(it->second, "en-US");
1506     }
1507     it = options.find("dateStyle");
1508     if (it != options.end()) {
1509         EXPECT_EQ(it->second, "medium");
1510     }
1511     it = options.find("timeStyle");
1512     if (it != options.end()) {
1513         EXPECT_EQ(it->second, "long");
1514     }
1515 }
1516 
1517 /**
1518  * @tc.name: IntlFuncTest0040
1519  * @tc.desc: Test Intl DateTimeFormat
1520  * @tc.type: FUNC
1521  */
1522 HWTEST_F(IntlTest, IntlFuncTest0040, TestSize.Level1)
1523 {
1524     vector<string> locales;
1525     locales.push_back("en-GB");
1526     map<string, string> inputOptions = {
1527         { "locale", "en-GB" },
1528         { "dateStyle", "medium" },
1529         { "timeStyle", "long" },
1530         { "hourCycle", "h12" },
1531         { "timeZone", "Asia/Shanghai" },
1532         { "numberingSystem", "latn" },
1533         { "hour12", "true" },
1534         { "weekday", "long" },
1535         { "era", "long" },
1536         { "year", "numeric" },
1537         { "month", "numeric" },
1538         { "day", "numeric" },
1539         { "hour", "numeric" },
1540         { "minute", "numeric" },
1541         { "second", "numeric" },
1542         { "timeZoneName", "long" },
1543         { "dayPeriod", "long" },
1544         { "localeMatcher", "lookup" },
1545         { "formatMatcher", "basic" }
1546     };
1547     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1548     map<string, string> options;
1549     formatter->GetResolvedOptions(options);
1550     map<string, string>::iterator it = options.find("hourCycle");
1551     if (it != options.end()) {
1552         EXPECT_EQ(it->second, "h12");
1553     }
1554     it = options.find("timeZone");
1555     if (it != options.end()) {
1556         EXPECT_EQ(it->second, "Asia/Shanghai");
1557     }
1558     it = options.find("numberingSystem");
1559     if (it != options.end()) {
1560         EXPECT_EQ(it->second, "latn");
1561     }
1562     it = options.find("hour12");
1563     if (it != options.end()) {
1564         EXPECT_EQ(it->second, "true");
1565     }
1566     it = options.find("weekday");
1567     if (it != options.end()) {
1568         EXPECT_EQ(it->second, "long");
1569     }
1570 }
1571 
1572 /**
1573  * @tc.name: IntlFuncTest0041
1574  * @tc.desc: Test Intl DateTimeFormat
1575  * @tc.type: FUNC
1576  */
1577 HWTEST_F(IntlTest, IntlFuncTest0041, TestSize.Level1)
1578 {
1579     vector<string> locales;
1580     locales.push_back("en-US");
1581     map<string, string> inputOptions = {
1582         { "locale", "en-US" },
1583         { "dateStyle", "medium" },
1584         { "timeStyle", "medium" },
1585         { "hourCycle", "h24" },
1586         { "timeZone", "Asia/Shanghai" },
1587         { "numberingSystem", "latn" },
1588         { "hour12", "false" },
1589         { "weekday", "long" },
1590         { "era", "long" },
1591         { "year", "2-digit" },
1592         { "month", "2-digit" },
1593         { "day", "2-digit" },
1594         { "hour", "2-digit" },
1595         { "minute", "2-digit" },
1596         { "second", "2-digit" },
1597         { "timeZoneName", "long" },
1598         { "dayPeriod", "long" },
1599         { "localeMatcher", "best fit" },
1600         { "formatMatcher", "best fit" }
1601     };
1602     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1603     map<string, string> options;
1604     formatter->GetResolvedOptions(options);
1605     map<string, string>::iterator it = options.find("era");
1606     if (it != options.end()) {
1607         EXPECT_EQ(it->second, "long");
1608     }
1609     it = options.find("year");
1610     if (it != options.end()) {
1611         EXPECT_EQ(it->second, "2-digit");
1612     }
1613     it = options.find("month");
1614     if (it != options.end()) {
1615         EXPECT_EQ(it->second, "2-digit");
1616     }
1617     it = options.find("day");
1618     if (it != options.end()) {
1619         EXPECT_EQ(it->second, "2-digit");
1620     }
1621     it = options.find("hour");
1622     if (it != options.end()) {
1623         EXPECT_EQ(it->second, "2-digit");
1624     }
1625 }
1626 
1627 /**
1628  * @tc.name: IntlFuncTest0042
1629  * @tc.desc: Test Intl DateTimeFormat
1630  * @tc.type: FUNC
1631  */
1632 HWTEST_F(IntlTest, IntlFuncTest0042, TestSize.Level1)
1633 {
1634     vector<string> locales;
1635     locales.push_back("en-US");
1636     map<string, string> inputOptions = {
1637         { "locale", "en-US" },
1638         { "dateStyle", "full" },
1639         { "timeStyle", "long" },
1640         { "hourCycle", "h12" },
1641         { "timeZone", "Asia/Singapore" },
1642         { "numberingSystem", "latn" },
1643         { "hour12", "true" },
1644         { "weekday", "long" },
1645         { "era", "long" },
1646         { "year", "2-digit" },
1647         { "month", "2-digit" },
1648         { "day", "2-digit" },
1649         { "hour", "numeric" },
1650         { "minute", "numeric" },
1651         { "second", "numeric" },
1652         { "timeZoneName", "long" },
1653         { "dayPeriod", "long" },
1654         { "localeMatcher", "lookup" },
1655         { "formatMatcher", "basic" }
1656     };
1657     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1658     map<string, string> options;
1659     formatter->GetResolvedOptions(options);
1660     map<string, string>::iterator it = options.find("minute");
1661     if (it != options.end()) {
1662         EXPECT_EQ(it->second, "numeric");
1663     }
1664     it = options.find("second");
1665     if (it != options.end()) {
1666         EXPECT_EQ(it->second, "numeric");
1667     }
1668     it = options.find("timeZoneName");
1669     if (it != options.end()) {
1670         EXPECT_EQ(it->second, "long");
1671     }
1672     it = options.find("dayPeriod");
1673     if (it != options.end()) {
1674         EXPECT_EQ(it->second, "long");
1675     }
1676 }
1677 
1678 /**
1679  * @tc.name: IntlFuncTest0043
1680  * @tc.desc: Test Intl DateTimeFormat
1681  * @tc.type: FUNC
1682  */
1683 HWTEST_F(IntlTest, IntlFuncTest0043, TestSize.Level1)
1684 {
1685     vector<string> locales;
1686     locales.push_back("en-US");
1687     map<string, string> inputOptions = {
1688         { "locale", "en-US" },
1689         { "dateStyle", "long" },
1690         { "timeStyle", "long" },
1691         { "hourCycle", "h12" },
1692         { "timeZone", "America/Los_Angeles" },
1693         { "numberingSystem", "latn" },
1694         { "hour12", "true" },
1695         { "weekday", "long" },
1696         { "era", "long" },
1697         { "year", "numeric" },
1698         { "month", "numeric" },
1699         { "day", "numeric" },
1700         { "hour", "2-digit" },
1701         { "minute", "2-digit" },
1702         { "second", "2-digit" },
1703         { "timeZoneName", "long" },
1704         { "dayPeriod", "long" },
1705         { "localeMatcher", "lookup" },
1706         { "formatMatcher", "basic" }
1707     };
1708     std::unique_ptr<DateTimeFormat> formatter = DateTimeFormat::CreateInstance(locales, inputOptions);
1709     map<string, string> options;
1710     formatter->GetResolvedOptions(options);
1711     map<string, string>::iterator it = options.find("localeMatcher");
1712     if (it != options.end()) {
1713         EXPECT_EQ(it->second, "lookup");
1714     }
1715     it = options.find("formatMatcher");
1716     if (it != options.end()) {
1717         EXPECT_EQ(it->second, "basic");
1718     }
1719 }
1720 
1721 /**
1722  * @tc.name: IntlFuncTest0044
1723  * @tc.desc: Test Intl LocaleInfo
1724  * @tc.type: FUNC
1725  */
1726 HWTEST_F(IntlTest, IntlFuncTest0044, TestSize.Level1)
1727 {
1728     string localeTag = "zh-Hans-CN";
1729     map<string, string> configs = {
1730         { "calendar", "chinese" },
1731         { "collation", "pinyin" },
1732         { "hourCycle", "h12" },
1733         { "numberingSystem", "latn" },
1734         { "numeric", "true" },
1735         { "caseFirst", "upper" }
1736     };
1737     LocaleInfo *locale = new LocaleInfo(localeTag, configs);
1738     string res = locale->GetLanguage();
1739     EXPECT_EQ(res, "zh");
1740     res = locale->GetScript();
1741     EXPECT_EQ(res, "Hans");
1742     res = locale->GetRegion();
1743     EXPECT_EQ(res, "CN");
1744     res = locale->GetBaseName();
1745     EXPECT_EQ(res, "zh-Hans-CN");
1746     res = locale->GetCalendar();
1747     EXPECT_EQ(res, "chinese");
1748     res = locale->GetCollation();
1749     EXPECT_EQ(res, "pinyin");
1750     res = locale->GetHourCycle();
1751     EXPECT_EQ(res, "h12");
1752     res = locale->GetNumberingSystem();
1753     EXPECT_EQ(res, "latn");
1754     res = locale->GetNumeric();
1755     EXPECT_EQ(res, "true");
1756     res = locale->GetCaseFirst();
1757     EXPECT_EQ(res, "upper");
1758     icu::Locale icuLocale = locale->GetLocale();
1759     res = locale->ToString();
1760     EXPECT_EQ(res, "zh-Hans-CN-u-hc-h12-nu-latn-ca-chinese-co-pinyin-kf-upper-kn-true");
1761     delete locale;
1762 }
1763 
1764 /**
1765  * @tc.name: IntlFuncTest0045
1766  * @tc.desc: Test Intl ReadSystemParameter
1767  * @tc.type: FUNC
1768  */
1769 HWTEST_F(IntlTest, IntlFuncTest0045, TestSize.Level1)
1770 {
1771     string paramKey = "const.global.language";
1772     int paramLength = 128;
1773     string res = ReadSystemParameter(paramKey.c_str(), paramLength);
1774     EXPECT_TRUE(res.length() > 0);
1775 
1776     paramKey = "fake system param";
1777     res = ReadSystemParameter(paramKey.c_str(), paramLength);
1778     EXPECT_TRUE(res.length() == 0);
1779 }
1780 } // namespace I18n
1781 } // namespace Global
1782 } // namespace OHOS