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