1 /*
2  * Copyright (c) 2024 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 #include <map>
19 #include <vector>
20 #include "border_rule.h"
21 #include "character.h"
22 #include "code_rule.h"
23 #include "collator.h"
24 #include "date_time_sequence.h"
25 #include "date_time_filter.h"
26 #include "date_time_format.h"
27 #include "date_time_rule.h"
28 #include "find_rule.h"
29 #include "holiday_manager.h"
30 #include "i18n_break_iterator.h"
31 #include "i18n_break_iterator_mock.h"
32 #include "i18n_calendar.h"
33 #include "i18n_calendar_mock.h"
34 #include "i18n_timezone.h"
35 #include "i18n_types.h"
36 #include "index_util.h"
37 #include "locale_compare.h"
38 #include "locale_config.h"
39 #include "locale_info.h"
40 #include "locale_matcher.h"
41 #include "measure_data.h"
42 #include "number_format.h"
43 #include "parameter.h"
44 #include "phone_number_format.h"
45 #include "phone_number_rule.h"
46 #include "plural_rules.h"
47 #include "positive_rule.h"
48 #include "preferred_language.h"
49 #include "regex_rule.h"
50 #include "relative_time_format.h"
51 #include "rules_engine.h"
52 #include "system_locale_manager.h"
53 #include "taboo_utils.h"
54 #include "taboo.h"
55 #include "token_setproc.h"
56 #include "utils.h"
57 #include "intl_test.h"
58 #include "generate_ics_file.h"
59 #include "signature_verifier.h"
60 #include <unistd.h>
61 #include "unicode/utypes.h"
62 
63 using namespace OHOS::Global::I18n;
64 using testing::ext::TestSize;
65 using namespace std;
66 using namespace testing;
67 
68 namespace OHOS {
69 namespace Global {
70 namespace I18n {
71 /**
72  * @tc.name: IntlFuncTest0047
73  * @tc.desc: Test Intl LocaleConfig GetBlockedLanguages
74  * @tc.type: FUNC
75  */
76 HWTEST_F(IntlTest, IntlFuncTest0047, TestSize.Level1)
77 {
78     std::unordered_set<std::string> languageSet = LocaleConfig::GetBlockedLanguages();
79     EXPECT_TRUE(languageSet.size() == 0);
80 }
81 
82 /**
83  * @tc.name: IntlFuncTest0048
84  * @tc.desc: Test Intl LocaleConfig GetBlockedRegions
85  * @tc.type: FUNC
86  */
87 HWTEST_F(IntlTest, IntlFuncTest0048, TestSize.Level1)
88 {
89     std::unordered_set<std::string> regionSet = LocaleConfig::GetBlockedRegions();
90     EXPECT_TRUE(regionSet.size() == 0);
91 }
92 
93 /**
94  * @tc.name: IntlFuncTest0049
95  * @tc.desc: Test Intl LocaleConfig GetLanguageBlockedRegions
96  * @tc.type: FUNC
97  */
98 HWTEST_F(IntlTest, IntlFuncTest0049, TestSize.Level1)
99 {
100     std::unordered_set<std::string> blockedRegionSet = LocaleConfig::GetLanguageBlockedRegions();
101     EXPECT_EQ(blockedRegionSet.size(), 0);
102     I18nErrorCode status = LocaleConfig::SetSystemLanguage("zh-Hans");
103     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
104     std::string systemLanguage = LocaleConfig::GetSystemLanguage();
105     EXPECT_EQ(systemLanguage, "zh-Hans");
106 
107     status = LocaleConfig::SetSystemRegion("CN");
108     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
109     std::string systemRegion = LocaleConfig::GetSystemRegion();
110     EXPECT_EQ(systemRegion, "CN");
111     std::string systemLocale = LocaleConfig::GetSystemLocale();
112     EXPECT_EQ(systemLocale, "zh-Hans-CN");
113 
114     const std::string locale = "zh-CN";
115     bool isRTL = LocaleConfig::IsRTL(locale);
116     EXPECT_TRUE(!isRTL);
117     std::string validLocale = LocaleConfig::GetValidLocale(locale);
118     EXPECT_EQ(validLocale, "zh-CN");
119 
120     status = LocaleConfig::Set24HourClock("false");
121     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
122     bool is24HourClock = LocaleConfig::Is24HourClock();
123     EXPECT_TRUE(!is24HourClock);
124 
125     status = LocaleConfig::SetUsingLocalDigit(true);
126     EXPECT_EQ(status, I18nErrorCode::UPDATE_LOCAL_DIGIT_FAILED);
127     bool usingLocalDigit = LocaleConfig::GetUsingLocalDigit();
128     EXPECT_FALSE(usingLocalDigit);
129 }
130 
131 /**
132  * @tc.name: IntlFuncTest0050
133  * @tc.desc: Test Intl PreferredLanguage AddPreferredLanguageExist
134  * @tc.type: FUNC
135  */
136 HWTEST_F(IntlTest, IntlFuncTest0050, TestSize.Level1)
137 {
138     // init test environment
139     I18nErrorCode status = LocaleConfig::SetSystemLanguage("zh-Hans");
140     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
141     std::vector<std::string> preferredLanguageList = PreferredLanguage::GetPreferredLanguageList();
142     for (auto i = preferredLanguageList.size() - 1; i > 0; --i) {
143         status = PreferredLanguage::RemovePreferredLanguage(i);
144         EXPECT_EQ(status, I18nErrorCode::SUCCESS);
145     }
146     // execute test
147     const std::string language = "zh-CN";
148     const std::string languageDe = "de-DE";
149     const std::string fakeLanguage = "1**1";
150     status = PreferredLanguage::AddPreferredLanguage(language, 0);
151     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
152     status = PreferredLanguage::AddPreferredLanguage(languageDe, 1);
153     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
154     status = PreferredLanguage::AddPreferredLanguage(language, 3);
155     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
156     PreferredLanguage::AddPreferredLanguage(fakeLanguage, -1);
157     PreferredLanguage::AddPreferredLanguage(language, -1);
158     std::vector<std::string> list = PreferredLanguage::GetPreferredLanguageList();
159     EXPECT_EQ(list.size(), 2);
160     std::string firstPreferredLanguage = PreferredLanguage::GetFirstPreferredLanguage();
161     EXPECT_EQ(firstPreferredLanguage, "zh-Hans");
162     std::string preferredLocale = PreferredLanguage::GetPreferredLocale();
163     EXPECT_EQ(preferredLocale, "zh-CN");
164     status = PreferredLanguage::RemovePreferredLanguage(0);
165     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
166     // restore environment
167     status = LocaleConfig::SetSystemLanguage("zh-Hans");
168     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
169     preferredLanguageList = PreferredLanguage::GetPreferredLanguageList();
170     for (auto i = preferredLanguageList.size() - 1; i > 0; --i) {
171         status = PreferredLanguage::RemovePreferredLanguage(i);
172         EXPECT_EQ(status, I18nErrorCode::SUCCESS);
173     }
174 }
175 
176 /**
177  * @tc.name: IntlFuncTest0051
178  * @tc.desc: Test Intl I18nCalendar
179  * @tc.type: FUNC
180  */
181 HWTEST_F(IntlTest, IntlFuncTest0051, TestSize.Level1)
182 {
183     I18nCalendar *calendar = new I18nCalendar("zh-Hans-CN");
184     I18nCalendar *calendar2 = new I18nCalendar("zh-Hans-CN", CalendarType::CHINESE);
185     calendar->SetTime(1684742124645);
186     calendar->Set(1989, 5, 23);
187     calendar->SetTimeZone("Asia/Shanghai");
188     std::string tzId = calendar->GetTimeZone();
189     EXPECT_EQ(tzId, "Asia/Shanghai");
190     int32_t minimalDaysInFirstWeek = calendar->GetMinimalDaysInFirstWeek();
191     EXPECT_EQ(minimalDaysInFirstWeek, 1);
192     int32_t firstDayOfWeek = calendar->GetFirstDayOfWeek();
193     EXPECT_EQ(firstDayOfWeek, 1);
194     calendar2->Set(2023, 5, 28);
195     bool isWeekend = calendar2->IsWeekend();
196     EXPECT_TRUE(isWeekend);
197     I18nCalendar *calendarFake = new I18nCalendar("123");
198     I18nCalendar *calendarInvalid = new I18nCalendar("123", CalendarType::CHINESE);
199     delete calendarFake;
200     delete calendarInvalid;
201     delete calendar;
202     delete calendar2;
203 }
204 
205 /**
206  * @tc.name: IntlFuncTest0052
207  * @tc.desc: Test Intl IndexUtil
208  * @tc.type: FUNC
209  */
210 HWTEST_F(IntlTest, IntlFuncTest0052, TestSize.Level1)
211 {
212     IndexUtil *indexUtil = new IndexUtil("zh-CN");
213     std::vector<std::string> indexList = indexUtil->GetIndexList();
214     EXPECT_EQ(indexList.size(), 28);
215     indexUtil->AddLocale("en-US");
216     std::string indexStr = indexUtil->GetIndex("A");
217     EXPECT_EQ(indexStr, "A");
218     IndexUtil *indexUtil2 = new IndexUtil("");
219     IndexUtil *idxUtil = new IndexUtil("@@#");
220     idxUtil->GetIndexList();
221     idxUtil->GetIndex("**");
222     delete indexUtil;
223     delete indexUtil2;
224     delete idxUtil;
225 
226     IndexUtil indexUtil3("");
227     indexUtil3.AddLocale("en-US");
228     indexStr = indexUtil3.GetIndex("A");
229     EXPECT_EQ(indexStr, "A");
230 }
231 
232 /**
233  * @tc.name: IntlFuncTest0053
234  * @tc.desc: Test Intl PhoneNumberFormat
235  * @tc.type: FUNC
236  */
237 HWTEST_F(IntlTest, IntlFuncTest0053, TestSize.Level1)
238 {
239     map<string, string> options = {
240         { "type", "NATIONAL" }
241     };
242     std::unique_ptr<PhoneNumberFormat> phoneNumberFormat =
243         std::make_unique<PhoneNumberFormat>("zh-CN", options);
244     std::string location = phoneNumberFormat->getLocationName("13228901234", "en-US");
245     EXPECT_EQ(location, "Lhasa, Xizang");
246     std::string location2 = phoneNumberFormat->getLocationName("15156712345", "zh-CN");
247     EXPECT_EQ(location2, "安徽省亳州市");
248     std::string location3 = phoneNumberFormat->getLocationName("17673241234", "zh-CN");
249     EXPECT_EQ(location3, "湖南省株洲市");
250     bool flag = phoneNumberFormat->isValidPhoneNumber("+8618622350085");
251     EXPECT_TRUE(flag);
252     std::string number2 = "+8618622350085";
253     std::string formatResult = phoneNumberFormat->format(number2);
254     EXPECT_EQ(formatResult, "186 2235 0085");
255     std::string location4 = phoneNumberFormat->getLocationName("fake-number", "zh-CN");
256     EXPECT_EQ(location4, "");
257     std::string number3 = "1068195561";
258     std::string formatedStr = phoneNumberFormat->format(number3);
259     EXPECT_EQ(formatedStr, "10 6819 5561");
260 }
261 
262 /**
263  * @tc.name: IntlFuncTest0054
264  * @tc.desc: Test Intl TabooUtils
265  * @tc.type: FUNC
266  */
267 HWTEST_F(IntlTest, IntlFuncTest0054, TestSize.Level1)
268 {
269     TabooUtils *tabooUtils = new TabooUtils();
270     std::string res1 = tabooUtils->ReplaceCountryName("CN", "en", "China");
271     EXPECT_EQ(res1, "China");
272     std::string res2 = tabooUtils->ReplaceLanguageName("zh", "en", "chinese");
273     EXPECT_EQ(res2, "chinese");
274     std::string res3 = tabooUtils->ReplaceCountryName("TW", "zh-Hans", "中国台湾");
275     EXPECT_EQ(res3, "中国台湾");
276     delete tabooUtils;
277     Taboo* taboo = new Taboo();
278     delete taboo;
279 }
280 
281 /**
282  * @tc.name: IntlFuncTest0055
283  * @tc.desc: Test Intl LocaleCompare
284  * @tc.type: FUNC
285  */
286 HWTEST_F(IntlTest, IntlFuncTest0055, TestSize.Level1)
287 {
288     int32_t result = LocaleCompare::Compare("zh-CN", "zh-Hans-CN");
289     EXPECT_EQ(result, 9);
290     I18nBreakIterator *i18nBreakIterator = new I18nBreakIterator("zh-Hans-CN");
291     bool isBoundary = i18nBreakIterator->IsBoundary(6);
292     EXPECT_TRUE(!isBoundary);
293     int32_t current = i18nBreakIterator->Current();
294     EXPECT_EQ(current, 0);
295     int32_t first = i18nBreakIterator->First();
296     EXPECT_EQ(first, 0);
297     int32_t last = i18nBreakIterator->Last();
298     EXPECT_EQ(last, 0);
299     int32_t previous = i18nBreakIterator->Previous();
300     EXPECT_EQ(previous, -1);
301     int32_t next6 = i18nBreakIterator->Next(6);
302     EXPECT_EQ(next6, -1);
303     int32_t resultLatn = LocaleCompare::Compare("en-Latn-US", "en-Qaag-US");
304     EXPECT_EQ(resultLatn, 9);
305     int32_t resultTl = LocaleCompare::Compare("tl-PH", "fil-PH");
306     EXPECT_EQ(resultTl, 9);
307     int32_t resultFil = LocaleCompare::Compare("fil-PH", "tl-PH");
308     EXPECT_EQ(resultFil, 9);
309     int32_t resultQaag = LocaleCompare::Compare("en-Qaag-US", "en-Latn-US");
310     EXPECT_EQ(resultQaag, 9);
311     int32_t resultHashMapZh = LocaleCompare::Compare("zh-MO", "zh-Hant-HK");
312     EXPECT_EQ(resultHashMapZh, 8);
313     int32_t resultZh = LocaleCompare::Compare("zh-Hant-MO", "zh-Hant-HK");
314     EXPECT_EQ(resultZh, 8);
315     int32_t resultHashMapEn = LocaleCompare::Compare("en-WS", "en-001");
316     EXPECT_EQ(resultHashMapEn, 8);
317     int32_t resultHashEn = LocaleCompare::Compare("en-Latn-WS", "en-001");
318     EXPECT_EQ(resultHashEn, 8);
319     int32_t resultHashQaagEn = LocaleCompare::Compare("en-Qaag-WS", "en-001");
320     EXPECT_EQ(resultHashQaagEn, 8);
321     I18nBreakIterator *breakIterator = new I18nBreakIterator("2--**");
322     breakIterator->Current();
323     breakIterator->First();
324     breakIterator->Last();
325     breakIterator->Previous();
326     breakIterator->Next(6);
327     breakIterator->Next();
328     breakIterator->Following(0);
329     breakIterator->IsBoundary(6);
330     delete breakIterator;
331     delete i18nBreakIterator;
332 }
333 
334 /**
335  * @tc.name: IntlFuncTest0056
336  * @tc.desc: Test Intl SystemLocaleManager
337  * @tc.type: FUNC
338  */
339 HWTEST_F(IntlTest, IntlFuncTest0056, TestSize.Level1)
340 {
341     SystemLocaleManager *systemLocaleManager = new SystemLocaleManager();
342     std::vector<std::string> languages = {"en", "de", "es", "fr"};
343     SortOptions sortOptions = {"en-US", true, true};
344     I18nErrorCode status;
345     std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions, status);
346     EXPECT_EQ(languageInfos.size(), 4);
347     const std::vector<std::string> countries = {"US", "GB", "DE", "CN"};
348     std::vector<LocaleItem> countryInfos = systemLocaleManager->GetCountryInfoArray(countries, sortOptions, status);
349     EXPECT_EQ(countryInfos.size(), 4);
350     std::vector<TimeZoneCityItem> timezoneCityItemList = SystemLocaleManager::GetTimezoneCityInfoArray(status);
351     EXPECT_TRUE(timezoneCityItemList.size() > 0);
352     delete systemLocaleManager;
353 }
354 
355 /**
356  * @tc.name: IntlFuncTest0057
357  * @tc.desc: Test Intl Utils
358  * @tc.type: FUNC
359  */
360 HWTEST_F(IntlTest, IntlFuncTest0057, TestSize.Level1)
361 {
362     bool isDigit = IsDigit("55");
363     EXPECT_TRUE(isDigit);
364     bool isSpaceChar = IsSpaceChar(" ");
365     EXPECT_TRUE(isSpaceChar);
366     bool isWhiteSpace = IsWhiteSpace("  ");
367     EXPECT_TRUE(isWhiteSpace);
368     bool isRTLCharacter = IsRTLCharacter("^");
369     EXPECT_TRUE(!isRTLCharacter);
370     isRTLCharacter = IsRTLCharacter("\u0645");
371     EXPECT_TRUE(isRTLCharacter);
372     bool isIdeoGraphic = IsIdeoGraphic("&&*");
373     EXPECT_TRUE(!isIdeoGraphic);
374     bool isLetter = IsLetter("cccUt");
375     EXPECT_TRUE(isLetter);
376     bool isLowerCase = IsLowerCase("abc");
377     EXPECT_TRUE(isLowerCase);
378     bool isUpperCase = IsUpperCase("AbC");
379     EXPECT_TRUE(isUpperCase);
380     std::string getType = GetType("$$%");
381     EXPECT_EQ(getType, "U_CURRENCY_SYMBOL");
382 }
383 
384 /**
385  * @tc.name: IntlFuncTest0058
386  * @tc.desc: Test Intl MeasureData
387  * @tc.type: FUNC
388  */
389 HWTEST_F(IntlTest, IntlFuncTest0058, TestSize.Level1)
390 {
391     std::string timezoneId = "Asia/Shanghai";
392     I18nTimeZone *i18nTimeZone = new I18nTimeZone(timezoneId, true);
393     int32_t offset = i18nTimeZone->GetOffset(1684742124645);
394     EXPECT_EQ(offset, 28800000);
395     int32_t rawOffset = i18nTimeZone->GetRawOffset();
396     EXPECT_EQ(rawOffset, 28800000);
397     std::string tzId = i18nTimeZone->GetID();
398     EXPECT_EQ(tzId, "Asia/Shanghai");
399     std::string displayName = i18nTimeZone->GetDisplayName();
400     EXPECT_EQ(displayName, "中国标准时间");
401     std::string displayName2 = i18nTimeZone->GetDisplayName(true);
402     EXPECT_EQ(displayName2, "中国标准时间");
403     std::string zhCn = "zh-CN";
404     std::string displayNameCn = i18nTimeZone->GetDisplayName(zhCn);
405     EXPECT_EQ(displayNameCn, "中国标准时间");
406     std::string displayName4 = i18nTimeZone->GetDisplayName("zh-CN", true);
407     EXPECT_EQ(displayName4, "中国标准时间");
408     std::string cityId = "Shanghai";
409     std::string localeId = "en-US";
410     std::string cityDisplayName = I18nTimeZone::GetCityDisplayName(cityId, localeId);
411     EXPECT_EQ(cityDisplayName, "Shanghai (China)");
412     std::unique_ptr<I18nTimeZone> timezone = I18nTimeZone::CreateInstance(timezoneId, true);
413     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
414     std::set<std::string> set0 = I18nTimeZone::GetAvailableIDs(errorCode);
415     EXPECT_EQ(set0.size(), 442);
416     std::set<std::string> set1 = I18nTimeZone::GetAvailableZoneCityIDs();
417     EXPECT_TRUE(set1.size() > 0);
418     std::string empty = "";
419     std::string fakeCityId = "fake cityId";
420     I18nTimeZone *i18nTimeZoneEmpty = new I18nTimeZone(empty, true);
421     I18nTimeZone *i18nTimeZoneFake = new I18nTimeZone(fakeCityId, false);
422     I18nTimeZone *i18nTimeZoneCityId = new I18nTimeZone(cityId, false);
423     delete i18nTimeZoneEmpty;
424     delete i18nTimeZoneFake;
425     delete i18nTimeZoneCityId;
426     delete i18nTimeZone;
427     uint32_t mask = GetMask("CN");
428     EXPECT_EQ(mask, 2462);
429 }
430 
431 /**
432  * @tc.name: IntlFuncTest0059
433  * @tc.desc: Test Intl NumberFormat
434  * @tc.type: FUNC
435  */
436 HWTEST_F(IntlTest, IntlFuncTest0059, TestSize.Level1)
437 {
438     std::vector<std::string> localeTags = { "$$@@#" };
439     std::map<std::string, std::string> configs = {
440         {"style", "unit"}, {"unit", "fake unit"}
441     };
442     NumberFormat formatter(localeTags, configs);
443     std::string res = formatter.Format(12);
444     EXPECT_EQ(res, "12");
445     localeTags = { "zh-Hans-u-nu-latn" };
446     NumberFormat* format = new (std::nothrow) NumberFormat(localeTags, configs);
447     EXPECT_EQ(res, format->Format(12));
448     delete format;
449 }
450 
451 /**
452  * @tc.name: IntlFuncTest0060
453  * @tc.desc: Test Intl HolidayManager
454  * @tc.type: FUNC
455  */
456 HWTEST_F(IntlTest, IntlFuncTest0060, TestSize.Level1)
457 {
458     IcsFileWriter icsFileWriter;
459     std::string path = icsFileWriter.GenerateFile();
460     HolidayManager *holiday_manager = new HolidayManager(path.c_str());
461     std::map<std::string, std::vector<HolidayInfoItem>> holidayDataMap;
462     std::vector<HolidayInfoItem> infoList;
463     std::vector<HolidayLocalName> localNameList1;
464     localNameList1.push_back({"tr", "Kurban Bayrami Tatili"});
465     std::vector<HolidayLocalName> localNameList2;
466     localNameList2.push_back({"tr", "Kurban Bayrami 2. Günü"});
467     HolidayInfoItem item1 = {"Sacrifice Feast Holiday", 2022, 6, 25, localNameList1};
468     HolidayInfoItem item2 = {"The Second Day of Sacrifice Feast", 2022, 6, 25, localNameList2};
469     infoList.push_back(item1);
470     infoList.push_back(item2);
471     holidayDataMap.insert({"20220625", infoList});
472     holiday_manager->SetHolidayData(holidayDataMap);
473     std::vector<HolidayInfoItem> list = holiday_manager->GetHolidayInfoItemArray(2022);
474     EXPECT_EQ(2, list.size());
475     list = holiday_manager->GetHolidayInfoItemArray();
476     EXPECT_EQ(0, list.size());
477     bool flag = holiday_manager->IsHoliday(2022, 6, 25);
478     EXPECT_TRUE(flag);
479     flag = holiday_manager->IsHoliday();
480     EXPECT_TRUE(!flag);
481     std::unique_ptr<HolidayManager> holidayManager = std::make_unique<HolidayManager>(nullptr);
482     std::string fakePath = "/data/log/fake.ics";
483     std::unique_ptr<HolidayManager> fakeManager = std::make_unique<HolidayManager>(fakePath.c_str());
484     delete holiday_manager;
485 }
486 
487 /**
488  * @tc.name: IntlFuncTest0061
489  * @tc.desc: Test Intl NumberFormat.format
490  * @tc.type: FUNC
491  */
492 HWTEST_F(IntlTest, IntlFuncTest0061, TestSize.Level1)
493 {
494     string locale = "en-CN";
495     string expects = "123K";
496     vector<string> locales;
497     locales.push_back(locale);
498     string style = "decimal";
499     map<string, string> options = { { "style", style },
500                                     { "notation", "compact" } };
501     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
502     if (!numFmt) {
503         EXPECT_TRUE(false);
504         return;
505     }
506     string out = numFmt->Format(123456.789);
507     EXPECT_EQ(out, expects);
508     EXPECT_EQ(numFmt->GetStyle(), style);
509     delete numFmt;
510 }
511 
512 /**
513  * @tc.name: IntlFuncTest0062
514  * @tc.desc: Test Intl utils.cpp
515  * @tc.type: FUNC
516  */
517 HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1)
518 {
519     string emptyStr = "";
520     string sep = ";";
521     vector<string> dest;
522     std::unordered_set<std::string> allValidLocalesLanguageTag;
523     Split(emptyStr, sep, dest);
524     int32_t status = 0;
525     string numberStr = "12345678901234567890123456789012345678901234567890987654321";
526     ConvertString2Int(numberStr, status);
527     numberStr = "@#";
528     ConvertString2Int(numberStr, status);
529     icu::Locale locale("$$$$5%%%");
530     bool isValid = IsValidLocaleTag(locale);
531     EXPECT_TRUE(!isValid);
532     GetAllValidLocalesTag(allValidLocalesLanguageTag);
533     EXPECT_TRUE(allValidLocalesLanguageTag.size() == 0);
534     const std::string str = "zh_Hans_CN";
535     const std::string target = "-";
536     const std::string replace = "";
537     StrReplaceAll(str, target, replace);
538 
539     std::string localeRule = "zh-Hans";
540     DateTimeRule* dateTimeRule = new DateTimeRule(localeRule);
541     DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule);
542     delete dateTimeFilter;
543     delete dateTimeRule;
544 }
545 
546 /**
547  * @tc.name: IntlFuncTest0063
548  * @tc.desc: Test Intl RegexRule
549  * @tc.type: FUNC
550  */
551 HWTEST_F(IntlTest, IntlFuncTest0063, TestSize.Level1)
552 {
553     using namespace i18n::phonenumbers;
554     std::string regexStr = "[a-z]1?";
555     icu::UnicodeString regex(regexStr.c_str());
556     std::string isValidType = "PrexxxxSuf";
557     std::string handleType = "EndWithMobile";
558     std::string insensitive = "False";
559     std::string type = "xxx";
560     std::unique_ptr<RegexRule> regexRule = std::make_unique<RegexRule>(regex,
561         isValidType, handleType, insensitive, type);
562     handleType = "fake";
563     isValidType = "Code";
564     std::unique_ptr<RegexRule> regexRule2 = std::make_unique<RegexRule>(regex, isValidType,
565         handleType, insensitive, type);
566     icu::UnicodeString message(type.c_str());
567 
568     i18n::phonenumbers::PhoneNumber phoneNumber;
569     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
570     std::string input = "[010111111111111;ext=0782";
571     std::string country = "CN";
572     size_t size = input.length();
573     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
574     std::unique_ptr<PhoneNumberMatch> possibleNumber =
575         std::make_unique<PhoneNumberMatch>(size, input, phoneNumber);
576     PhoneNumberMatch* phoneNumberMatch =
577         regexRule2->IsValid(possibleNumber.get(), message);
578     EXPECT_TRUE(phoneNumberMatch != nullptr);
579     regexRule2->GetType();
580     std::unique_ptr<icu::RegexPattern> regexPattern =
581         std::unique_ptr<icu::RegexPattern>(regexRule2->GetPattern());
582     isValidType = "Rawstr";
583     std::unique_ptr<RegexRule> regexRule3 = std::make_unique<RegexRule>(regex, isValidType,
584         handleType, insensitive, type);
585     PhoneNumberMatch* phoneNumMatch =
586         regexRule3->IsValid(possibleNumber.get(), message);
587     EXPECT_TRUE(phoneNumMatch != nullptr);
588     type = "CONTAIN";
589     string newRegexStr;
590     icu::UnicodeString unicRegex(newRegexStr.c_str());
591     std::unique_ptr<RegexRule> regexRule4 = std::make_unique<RegexRule>(unicRegex, isValidType,
592         handleType, insensitive, type);
593     type = "CONTAIN_OR_INTERSECT";
594     std::unique_ptr<RegexRule> regexRule5 = std::make_unique<RegexRule>(unicRegex, isValidType,
595         handleType, insensitive, type);
596     EXPECT_TRUE(regexRule5 != nullptr);
597 }
598 
599 /**
600  * @tc.name: IntlFuncTest0064
601  * @tc.desc: Test number format default parameter
602  * @tc.type: FUNC
603  */
604 HWTEST_F(IntlTest, IntlFuncTest0064, TestSize.Level1)
605 {
606     int bufferLen = 10;
607     char value[bufferLen];
608     vector<string> locales;
609     locales.push_back("en-GB");
610     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
611     std::string deviceType;
612     if (code > 0) {
613         deviceType = value;
614     }
615     map<string, string> unitOptions = {
616         { "style", "unit" },
617         { "unit", "hectare" }
618     };
619     NumberFormat *unitFormatter = new NumberFormat(locales, unitOptions);
620     string unitRes = unitFormatter->Format(123);
621     map<string, string> currencyOptions = {
622         { "style", "currency" },
623         { "currency", "USD" }
624     };
625     NumberFormat *currencyFormatter = new NumberFormat(locales, currencyOptions);
626     string currencyRes = currencyFormatter->Format(123);
627     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
628         EXPECT_EQ(currencyRes, "$123.00");
629         EXPECT_EQ(unitRes, "123ha");
630     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
631         EXPECT_EQ(currencyRes, "US$123.00");
632         EXPECT_EQ(unitRes, "123 hectares");
633     } else {
634         EXPECT_EQ(currencyRes, "US$123.00");
635         EXPECT_EQ(unitRes, "123 ha");
636     }
637     delete unitFormatter;
638     delete currencyFormatter;
639 }
640 
641 /**
642  * @tc.name: IntlFuncTest0065
643  * @tc.desc: Test relative time format default parameter
644  * @tc.type: FUNC
645  */
646 HWTEST_F(IntlTest, IntlFuncTest0065, TestSize.Level1)
647 {
648     int bufferLen = 10;
649     char value[bufferLen];
650     vector<string> locales;
651     locales.push_back("fr-FR");
652     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
653     std::string deviceType;
654     if (code > 0) {
655         deviceType = value;
656     }
657     map<string, string> options;
658     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
659 
660     double number = -1;
661     string unit = "day";
662     string res = formatter->Format(number, unit);
663     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
664         EXPECT_EQ(res, "-1 j");
665     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
666         EXPECT_EQ(res, "il y a 1 jour");
667     } else {
668         EXPECT_EQ(res, "il y a 1 jour");
669     }
670     delete formatter;
671 }
672 
673 /**
674  * @tc.name: IntlFuncTest0066
675  * @tc.desc: Test datetime format default parameter
676  * @tc.type: FUNC
677  */
678 HWTEST_F(IntlTest, IntlFuncTest0066, TestSize.Level1)
679 {
680     int bufferLen = 10;
681     char value[bufferLen];
682     vector<string> locales;
683     locales.push_back("en-GB");
684     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
685     std::string deviceType;
686     if (code > 0) {
687         deviceType = value;
688     }
689     int64_t milliseconds = 987654321;
690 
691     map<string, string> defaultOptions;
692     std::unique_ptr<DateTimeFormat> defaultFormatter = DateTimeFormat::CreateInstance(locales, defaultOptions);
693     string defaultRes = defaultFormatter->Format(milliseconds);
694 
695     map<string, string> dateOptions = {
696         { "dateStyle", "auto" }
697     };
698     std::unique_ptr<DateTimeFormat> dateFormatter = DateTimeFormat::CreateInstance(locales, dateOptions);
699     string dateRes = dateFormatter->Format(milliseconds);
700 
701     map<string, string> timeOptions = {
702         { "timeStyle", "auto" }
703     };
704     std::unique_ptr<DateTimeFormat> timeFormatter = DateTimeFormat::CreateInstance(locales, timeOptions);
705     string timeRes = timeFormatter->Format(milliseconds);
706 
707     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
708         EXPECT_EQ(defaultRes, "12/01/1970");
709         EXPECT_EQ(dateRes, "12/01/1970");
710         EXPECT_EQ(timeRes, "06:20");
711     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
712         EXPECT_EQ(defaultRes, "12 Jan 1970");
713         EXPECT_EQ(dateRes, "12 Jan 1970");
714         EXPECT_EQ(timeRes, "06:20:54");
715     } else {
716         EXPECT_EQ(defaultRes, "12/01/1970");
717         EXPECT_EQ(dateRes, "12/01/1970");
718         EXPECT_EQ(timeRes, "06:20");
719     }
720 }
721 
722 /**
723  * @tc.name: IntlFuncTest0067
724  * @tc.desc: Test datetime format default parameter
725  * @tc.type: FUNC
726  */
727 HWTEST_F(IntlTest, IntlFuncTest0067, TestSize.Level1)
728 {
729     int bufferLen = 10;
730     char value[bufferLen];
731     vector<string> locales;
732     locales.push_back("en-GB");
733     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
734     std::string deviceType;
735     if (code > 0) {
736         deviceType = value;
737     }
738     int64_t milliseconds = 987654321;
739 
740     map<string, string> monthOptions = {
741         { "month", "auto" }
742     };
743     std::unique_ptr<DateTimeFormat> monthFormatter = DateTimeFormat::CreateInstance(locales, monthOptions);
744     string monthRes = monthFormatter->Format(milliseconds);
745 
746     map<string, string> weekdayOptions = {
747         { "weekday", "auto" }
748     };
749     std::unique_ptr<DateTimeFormat> weekdayFormatter = DateTimeFormat::CreateInstance(locales, weekdayOptions);
750     string weekdayRes = weekdayFormatter->Format(milliseconds);
751 
752     map<string, string> eraOptions = {
753         { "year", "2-digit" },
754         { "era", "auto" }
755     };
756     std::unique_ptr<DateTimeFormat> eraFormatter = DateTimeFormat::CreateInstance(locales, eraOptions);
757     string eraRes = eraFormatter->Format(milliseconds);
758 
759     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
760         EXPECT_EQ(monthRes, "Jan");
761         EXPECT_EQ(weekdayRes, "Mon");
762         EXPECT_EQ(eraRes, "70 A");
763     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
764         EXPECT_EQ(monthRes, "January");
765         EXPECT_EQ(weekdayRes, "Monday");
766         EXPECT_EQ(eraRes, "70 Anno Domini");
767     } else {
768         EXPECT_EQ(monthRes, "Jan");
769         EXPECT_EQ(weekdayRes, "Mon");
770         EXPECT_EQ(eraRes, "70 AD");
771     }
772 }
773 
774 /**
775  * @tc.name: IntlFuncTest0068
776  * @tc.desc: Test datetime format default parameter
777  * @tc.type: FUNC
778  */
779 HWTEST_F(IntlTest, IntlFuncTest0068, TestSize.Level1)
780 {
781     int bufferLen = 10;
782     char value[bufferLen];
783     vector<string> locales;
784     locales.push_back("fr-FR");
785     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
786     std::string deviceType;
787     if (code > 0) {
788         deviceType = value;
789     }
790     int64_t milliseconds = 987654321;
791 
792     map<string, string> dayPeriodOptions = {
793         { "hour", "numeric" },
794         { "hourCycle", "h12" },
795         { "dayPeriod", "auto" },
796         { "timeZone", "UTC" }
797     };
798     std::unique_ptr<DateTimeFormat> dayPeriodFormatter = DateTimeFormat::CreateInstance(locales, dayPeriodOptions);
799     string dayPeriodRes = dayPeriodFormatter->Format(milliseconds);
800 
801     map<string, string> timeZoneNameOptions = {
802         { "hour", "2-digit" },
803         { "timeZoneName", "auto" }
804     };
805     std::unique_ptr<DateTimeFormat> timeZoneNameFormatter
806         = DateTimeFormat::CreateInstance(locales, timeZoneNameOptions);
807     string timeZoneNameRes = timeZoneNameFormatter->Format(milliseconds);
808 
809     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
810         EXPECT_EQ(dayPeriodRes, "10 mat.");
811         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
812     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
813         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAF" "du matin");
814         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM heure normale de la Chine");
815     } else {
816         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAFmatin");
817         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
818     }
819 }
820 
821 /**
822  * @tc.name: IntlFuncTest0069
823  * @tc.desc: Test number format unitUsage
824  * @tc.type: FUNC
825  */
826 HWTEST_F(IntlTest, IntlFuncTest0069, TestSize.Level1)
827 {
828     std::string locale = "en-GB";
829     std::vector<std::string> locales;
830     locales.push_back(locale);
831     map<string, string> options = { { "style", "unit" },
832                                     { "unit", "day" },
833                                     { "unitUsage", "elapsed-time-second"} };
834     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
835     if (!numFmt) {
836         EXPECT_TRUE(false);
837         return;
838     }
839     std::string nowRes = numFmt->Format(0.00001);
840     std::string secondRes = numFmt->Format(0.00004);
841     std::string dayRes = numFmt->Format(1.5);
842     std::string monthRes = numFmt->Format(-62.5);
843 
844     EXPECT_EQ(nowRes, "now");
845     EXPECT_EQ(secondRes, "3 seconds ago");
846     EXPECT_EQ(dayRes, "yesterday");
847     EXPECT_EQ(monthRes, "2 months ago");
848     delete numFmt;
849 }
850 
851 /**
852  * @tc.name: IntlFuncTest0070
853  * @tc.desc: Test number format unitUsage
854  * @tc.type: FUNC
855  */
856 HWTEST_F(IntlTest, IntlFuncTest0070, TestSize.Level1)
857 {
858     std::string locale = "en-GB";
859     std::vector<std::string> locales;
860     locales.push_back(locale);
861     map<string, string> options = { { "style", "unit" },
862                                     { "unit", "megabyte" },
863                                     { "unitUsage", "size-file-byte"} };
864     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
865     if (!numFmt) {
866         EXPECT_TRUE(false);
867         return;
868     }
869     std::string byteRes = numFmt->Format(0.00000812);
870     std::string kbRes = numFmt->Format(0.125);
871     std::string mbRes = numFmt->Format(3.5);
872     std::string gbRes = numFmt->Format(23122);
873 
874     EXPECT_EQ(byteRes, "8 byte");
875     EXPECT_EQ(kbRes, "125 kB");
876     EXPECT_EQ(mbRes, "3.50 MB");
877     EXPECT_EQ(gbRes, "23.12 GB");
878     delete numFmt;
879 }
880 
881 /**
882  * @tc.name: IntlFuncTest0071
883  * @tc.desc: Test number format unitUsage
884  * @tc.type: FUNC
885  */
886 HWTEST_F(IntlTest, IntlFuncTest0071, TestSize.Level1)
887 {
888     std::string locale = "en-GB";
889     std::vector<std::string> locales;
890     locales.push_back(locale);
891     map<string, string> options = { { "style", "unit" },
892                                     { "unit", "megabyte" },
893                                     { "unitUsage", "size-shortfile-byte"} };
894     NumberFormat *numFmt = new (std::nothrow) NumberFormat(locales, options);
895     if (!numFmt) {
896         EXPECT_TRUE(false);
897         return;
898     }
899     std::string byteRes = numFmt->Format(0.00000812);
900     std::string kbRes = numFmt->Format(0.125);
901     std::string mbRes = numFmt->Format(3.5);
902     std::string gbRes = numFmt->Format(23122);
903 
904     EXPECT_EQ(byteRes, "8 byte");
905     EXPECT_EQ(kbRes, "125 kB");
906     EXPECT_EQ(mbRes, "3.5 MB");
907     EXPECT_EQ(gbRes, "23 GB");
908     delete numFmt;
909 }
910 
911 /**
912  * @tc.name: IntlFuncTest0072
913  * @tc.desc: Test date order
914  * @tc.type: FUNC
915  */
916 HWTEST_F(IntlTest, IntlFuncTest0072, TestSize.Level1)
917 {
918     std::string locale = "en-GB";
919     std::string result = DateTimeSequence::GetDateOrder(locale);
920     EXPECT_EQ(result, "d-LLL-y");
921     locale = "zh-Hans";
922     result = DateTimeSequence::GetDateOrder(locale);
923     EXPECT_EQ(result, "y-L-d");
924     locale = "bo-CN";
925     result = DateTimeSequence::GetDateOrder(locale);
926     EXPECT_EQ(result, "y-LLL-d");
927     locale = "zh-Hant";
928     result = DateTimeSequence::GetDateOrder(locale);
929     EXPECT_EQ(result, "y-L-d");
930     locale = "ug";
931     result = DateTimeSequence::GetDateOrder(locale);
932     EXPECT_EQ(result, "L-d-y");
933     std::string localeBg = "bg-BG";
934     DateTimeSequence::GetDateOrder(localeBg);
935 }
936 
937 /**
938  * @tc.name: IntlFuncTest0073
939  * @tc.desc: Test PhoneNumberFormat.format()
940  * @tc.type: FUNC
941  */
942 HWTEST_F(IntlTest, IntlFuncTest0073, TestSize.Level1)
943 {
944     map<string, string> options = {
945         { "type", "TYPING" }
946     };
947     std::unique_ptr<PhoneNumberFormat> phoneNumFmt =
948         std::make_unique<PhoneNumberFormat>("zh-CN", options);
949     std::string number = "186223500";
950     std::string formated = "";
951     for (char c : number) {
952         formated = formated + c;
953         formated = phoneNumFmt->format(formated);
954     }
955     EXPECT_EQ(formated, "186 2235 00");
956     number = "186223500102933884747757758585885858854774";
957     phoneNumFmt->format(number);
958     number = "(020) 6355";
959     phoneNumFmt->format(number);
960     number = "123";
961     phoneNumFmt->format(number);
962     number = "2134";
963     phoneNumFmt->format(number);
964 
965     formated = "";
966     number = "075576453";
967     for (char c : number) {
968         formated = formated + c;
969         formated = phoneNumFmt->format(formated);
970     }
971     EXPECT_EQ(formated, "0755 7645 3");
972 
973     std::unique_ptr<PhoneNumberFormat> phoneNumFmt2 =
974         std::make_unique<PhoneNumberFormat>("AD", options);
975     formated = "";
976     number = "7123945";
977     for (char c : number) {
978         if (c == '4') {
979             formated = formated.substr(0, formated.length() - 1);
980             formated = phoneNumFmt->format(formated);
981         }
982         formated = formated + c;
983         formated = phoneNumFmt->format(formated);
984     }
985     EXPECT_EQ(formated, "712 345");
986     PhoneNumberFormat::CloseDynamicHandler();
987 }
988 
989 /**
990  * @tc.name: IntlFuncTest0074
991  * @tc.desc: Test LocaleMatcher
992  * @tc.type: FUNC
993  */
994 HWTEST_F(IntlTest, IntlFuncTest0074, TestSize.Level1)
995 {
996     const LocaleInfo* other = new LocaleInfo("fil");
997     LocaleMatcher::IsMoreSuitable(nullptr, other, nullptr);
998     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, nullptr);
999     const LocaleInfo* request = new LocaleInfo("en-Qaag-GB");
1000     std::unique_ptr<LocaleInfo> currentHE = std::make_unique<LocaleInfo>("he");
1001     std::unique_ptr<LocaleInfo> otherIW = std::make_unique<LocaleInfo>("iw");
1002     LocaleMatcher::IsMoreSuitable(currentHE.get(), otherIW.get(), request);
1003     const LocaleInfo* currentTL = new LocaleInfo("tl");
1004     LocaleMatcher::IsMoreSuitable(currentTL, other, request);
1005     LocaleMatcher::IsMoreSuitable(other, currentTL, request);
1006     const LocaleInfo* currentJI = new LocaleInfo("ji");
1007     const LocaleInfo* otherYI = new LocaleInfo("yi");
1008     LocaleMatcher::IsMoreSuitable(currentJI, otherYI, request);
1009     LocaleMatcher::IsMoreSuitable(otherYI, currentJI, request);
1010     std::unique_ptr<LocaleInfo> currentJW = std::make_unique<LocaleInfo>("jw");
1011     std::unique_ptr<LocaleInfo> otherJV = std::make_unique<LocaleInfo>("jv");
1012     LocaleMatcher::IsMoreSuitable(currentJW.get(), otherJV.get(), request);
1013     LocaleMatcher::IsMoreSuitable(otherJV.get(), currentJW.get(), request);
1014     const LocaleInfo* currentIN = new LocaleInfo("in-PH");
1015     const LocaleInfo* otherID = new LocaleInfo("id-MY");
1016     LocaleMatcher::IsMoreSuitable(currentIN, otherID, request);
1017     LocaleMatcher::IsMoreSuitable(otherID, currentIN, request);
1018     LocaleMatcher::IsMoreSuitable(nullptr, currentIN, request);
1019     LocaleMatcher::IsMoreSuitable(currentIN, nullptr, request);
1020     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, request);
1021     const LocaleInfo* enLatn = new LocaleInfo("en-Latn-US");
1022     LocaleMatcher::Match(request, enLatn);
1023     std::unique_ptr<LocaleInfo> otherIN = std::make_unique<LocaleInfo>("in-MY");
1024     LocaleMatcher::Match(currentIN, otherIN.get());
1025     LocaleMatcher::Match(currentIN, nullptr);
1026     std::unique_ptr<LocaleInfo> newRequest = std::make_unique<LocaleInfo>("en-Latn");
1027     std::unique_ptr<LocaleInfo> currentEn = std::make_unique<LocaleInfo>("en-GB");
1028     std::unique_ptr<LocaleInfo> otherEn = std::make_unique<LocaleInfo>("en-US");
1029     int8_t result = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), newRequest.get());
1030     LocaleMatcher::Match(enLatn, currentEn.get());
1031     EXPECT_EQ(result, -1);
1032     delete other;
1033     delete request;
1034     delete currentTL;
1035     delete currentJI;
1036     delete otherYI;
1037     delete currentIN;
1038     delete otherID;
1039     delete enLatn;
1040 }
1041 
1042 /**
1043  * @tc.name: IntlFuncTest0075
1044  * @tc.desc: Test RulesEngine
1045  * @tc.type: FUNC
1046  */
1047 HWTEST_F(IntlTest, IntlFuncTest0075, TestSize.Level1)
1048 {
1049     DateTimeRule* dateTimeRule = nullptr;
1050     std::unordered_map<std::string, std::string> rulesMap = {};
1051     std::unordered_map<std::string, std::string> subRules = {};
1052     std::unordered_map<std::string, std::string> param = {};
1053     std::unordered_map<std::string, std::string> paramBackup = {};
1054     RulesSet rulesSet(rulesMap, subRules, param, paramBackup);
1055     RulesEngine rulesEngine(dateTimeRule, rulesSet);
1056     std::string locale = "&&%";
1057     DateTimeSequence::GetDateOrder(locale);
1058     const std::string oldWriteVersion = "1.10.23.100";
1059     const std::string newWriteVersion = "1.10.24.100";
1060     IcsFileWriter icsFileWriter;
1061     std::string oldFilePath = icsFileWriter.WriteVersionFile(oldWriteVersion, "old");
1062     std::string newFilePath = icsFileWriter.WriteVersionFile(newWriteVersion, "new");
1063     std::string oldVersion = SignatureVerifier::LoadFileVersion(oldFilePath);
1064     std::string newVersion = SignatureVerifier::LoadFileVersion(newFilePath);
1065     int res = SignatureVerifier::CompareVersion(oldVersion, newVersion);
1066     EXPECT_EQ(res, 1);
1067     res = SignatureVerifier::CompareVersion(newVersion, oldVersion);
1068     EXPECT_EQ(res, -1);
1069     std::string fakeVersion = "1.10.4";
1070     res = SignatureVerifier::CompareVersion(fakeVersion, oldVersion);
1071     EXPECT_EQ(res, -1);
1072     res = SignatureVerifier::CompareVersion(oldVersion, oldVersion);
1073     EXPECT_EQ(res, 0);
1074     FileExist(oldFilePath);
1075     trim(locale);
1076     const std::string destPath = "/data/log/copy.txt";
1077     FileCopy(oldFilePath, destPath);
1078     IsLegalPath(destPath);
1079     const std::string relativePath = "../log/copy.txt";
1080     IsLegalPath(relativePath);
1081     const char* dirPath = "/data/log";
1082     IsDirExist(dirPath);
1083 }
1084 
1085 /**
1086  * @tc.name: IntlFuncTest0076
1087  * @tc.desc: Test RulesEngine
1088  * @tc.type: FUNC
1089  */
1090 HWTEST_F(IntlTest, IntlFuncTest0076, TestSize.Level1)
1091 {
1092     i18n::phonenumbers::PhoneNumber phoneNumber;
1093     size_t start = 10;
1094     std::string rawStr = "1 800 234 45 67";
1095     std::unique_ptr<PhoneNumberMatch> possibleNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1096     icu::UnicodeString regex;
1097     std::string handleType = "Operator";
1098     std::string insensitive = "True";
1099     std::unique_ptr<PositiveRule> pRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1100     icu::RegexPattern* regexP = pRule->GetPattern();
1101     std::string msg = "(0075 665";
1102     icu::UnicodeString message(msg.c_str());
1103     std::vector<MatchedNumberInfo> vector = pRule->HandleInner(possibleNumber.get(), message);
1104     handleType = "EndWithMobile";
1105     std::unique_ptr<PositiveRule> pRule2 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1106     vector = pRule2->HandleInner(possibleNumber.get(), message);
1107     vector = pRule2->Handle(possibleNumber.get(), message);
1108     handleType = "default";
1109     std::unique_ptr<PositiveRule> pRule3 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1110     vector = pRule3->HandleInner(possibleNumber.get(), message);
1111     vector = pRule3->Handle(possibleNumber.get(), message);
1112     delete regexP;
1113 
1114     EXPECT_FALSE(IsDirExist(nullptr));
1115     std::string strForTrim;
1116     EXPECT_EQ(trim(strForTrim), "");
1117     bool copyResult = FileCopy("/data/123/abc.txt", "/data/456/abc.txt");
1118     EXPECT_FALSE(copyResult);
1119 }
1120 
1121 /**
1122  * @tc.name: IntlFuncTest0077
1123  * @tc.desc: Test RegexRule
1124  * @tc.type: FUNC
1125  */
1126 HWTEST_F(IntlTest, IntlFuncTest0077, TestSize.Level1)
1127 {
1128     using namespace i18n::phonenumbers;
1129     std::string regexStr = "\\d{3}";
1130     icu::UnicodeString regex(regexStr.c_str());
1131     std::string isValidType = "Default";
1132     std::string handleType = "Operator";
1133     std::string insensitive = "False";
1134     std::string type = "xxx";
1135     icu::UnicodeString message(type.c_str());
1136 
1137     i18n::phonenumbers::PhoneNumber phoneNumber;
1138     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1139     std::string input = "(010)86753564";
1140     std::string country = "CN";
1141     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
1142     size_t start = 10;
1143     std::string rawString = "1 800 234 45 67";
1144     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1145         std::make_unique<PhoneNumberMatch>(start, rawString, phoneNumber);
1146     std::unique_ptr<RegexRule> regexRule =
1147         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1148     if (possibleNumber.get() != nullptr) {
1149         PhoneNumberMatch* phoneNumMatch = regexRule->IsValid(possibleNumber.get(), message);
1150         if (phoneNumMatch != nullptr) {
1151             std::vector<MatchedNumberInfo> list = regexRule->Handle(phoneNumMatch, message);
1152             EXPECT_EQ(list.size(), 1);
1153         }
1154     }
1155 }
1156 
1157 /**
1158  * @tc.name: IntlFuncTest0078
1159  * @tc.desc: Test CodeRule
1160  * @tc.type: FUNC
1161  */
1162 HWTEST_F(IntlTest, IntlFuncTest0078, TestSize.Level1)
1163 {
1164     std::string isValidType = "Default";
1165     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1166     std::string msg = "00222a-1 800 234 45 670A-";
1167     icu::UnicodeString message(msg.c_str());
1168     i18n::phonenumbers::PhoneNumber phoneNumber;
1169     size_t start = 7;
1170     std::string rawStr = "1 800 234 45 67";
1171     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1172         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1173     if (possibleNumber != nullptr) {
1174         codeRule->IsValid(possibleNumber.get(), message);
1175     }
1176     std::string country = "../supported_locales";
1177     std::unique_ptr<PhoneNumberRule> phoneNumberRule = std::make_unique<PhoneNumberRule>(country);
1178     EXPECT_TRUE(phoneNumberRule != nullptr);
1179 }
1180 
1181 /**
1182  * @tc.name: IntlFuncTest0079
1183  * @tc.desc: Test CodeRule
1184  * @tc.type: FUNC
1185  */
1186 HWTEST_F(IntlTest, IntlFuncTest0079, TestSize.Level1)
1187 {
1188     std::string isValidType = "PreSuf";
1189     std::string msg = "00222a-1 800 234 45 670A-";
1190     icu::UnicodeString message(msg.c_str());
1191     i18n::phonenumbers::PhoneNumber phoneNumber;
1192     size_t start = 7;
1193     std::string rawStr = "1 800 234 45 67";
1194     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1195         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1196     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1197     if (possibleNumber != nullptr) {
1198         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1199         EXPECT_TRUE(match != nullptr);
1200     }
1201 }
1202 
1203 /**
1204  * @tc.name: IntlFuncTest0080
1205  * @tc.desc: Test RegexRule
1206  * @tc.type: FUNC
1207  */
1208 HWTEST_F(IntlTest, IntlFuncTest0080, TestSize.Level1)
1209 {
1210     using namespace i18n::phonenumbers;
1211     std::string regexStr = "\\d{3}";
1212     icu::UnicodeString regex(regexStr.c_str());
1213     std::string isValidType = "Default";
1214     std::string handleType = "Operator";
1215     std::string insensitive = "True";
1216     std::string type = "xxx";
1217     std::string input = "(010)86753564";
1218     size_t start = 10;
1219     std::string rawStr = "1 800 234 45 67";
1220     i18n::phonenumbers::PhoneNumber phoneNumber;
1221     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1222         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1223     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1224     std::unique_ptr<icu::RegexPattern> regexPattern =
1225         std::unique_ptr<icu::RegexPattern>(regexRule->GetPattern());
1226     std::string msg = "00222a-86753564A-";
1227     icu::UnicodeString message(msg.c_str());
1228     if (possibleNumber != nullptr) {
1229         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1230         EXPECT_EQ(list.size(), 1);
1231     }
1232     delete regexRule;
1233 }
1234 
1235 /**
1236  * @tc.name: IntlFuncTest0081
1237  * @tc.desc: Test RegexRule
1238  * @tc.type: FUNC
1239  */
1240 HWTEST_F(IntlTest, IntlFuncTest0081, TestSize.Level1)
1241 {
1242     using namespace i18n::phonenumbers;
1243     std::string regexStr = "\\d{3}";
1244     icu::UnicodeString regex(regexStr.c_str());
1245     std::string isValidType = "PreSuf";
1246     std::string handleType = "Blank";
1247     std::string insensitive = "False";
1248     std::string type = "xxx";
1249     std::string input = "(010)86753564";
1250     size_t start = 0;
1251     std::string rawStr = "1 800 234 45 67";
1252     i18n::phonenumbers::PhoneNumber phoneNumber;
1253     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1254         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1255     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1256     std::string msg = "00222a-86753564A-";
1257     icu::UnicodeString message(msg.c_str());
1258     if (possibleNumber != nullptr) {
1259         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1260         EXPECT_EQ(list.size(), 1);
1261         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1262         EXPECT_TRUE(match != nullptr);
1263         PhoneNumberMatch* match2 = regexRule->IsValid(nullptr, message);
1264         EXPECT_TRUE(match2 == nullptr);
1265     }
1266     rawStr = "5201314";
1267     std::unique_ptr<PhoneNumberMatch> possibleNum =
1268         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1269     if (possibleNum != nullptr) {
1270         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNum.get(), message);
1271         EXPECT_EQ(list.size(), 0);
1272     }
1273     delete regexRule;
1274 }
1275 
1276 /**
1277  * @tc.name: IntlFuncTest0082
1278  * @tc.desc: Test RegexRule
1279  * @tc.type: FUNC
1280  */
1281 HWTEST_F(IntlTest, IntlFuncTest0082, TestSize.Level1)
1282 {
1283     using namespace i18n::phonenumbers;
1284     std::string regexStr = "\\d{3}";
1285     icu::UnicodeString regex(regexStr.c_str());
1286     std::string isValidType = "Code";
1287     std::string handleType = "Slant";
1288     std::string insensitive = "False";
1289     std::string type = "xxx";
1290     std::string input = "(010)120/110";
1291     size_t start = 10;
1292     i18n::phonenumbers::PhoneNumber phoneNumber;
1293     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1294         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1295     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1296     std::string msg = "00222a-86753564A-";
1297     icu::UnicodeString message(msg.c_str());
1298     if (possibleNumber != nullptr) {
1299         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1300         EXPECT_EQ(list.size(), 1);
1301         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1302         EXPECT_TRUE(match != nullptr);
1303     }
1304     delete regexRule;
1305 }
1306 
1307 /**
1308  * @tc.name: IntlFuncTest0083
1309  * @tc.desc: Test RegexRule
1310  * @tc.type: FUNC
1311  */
1312 HWTEST_F(IntlTest, IntlFuncTest0083, TestSize.Level1)
1313 {
1314     using namespace i18n::phonenumbers;
1315     std::string regexStr = "\\d{3}";
1316     icu::UnicodeString regex(regexStr.c_str());
1317     std::string isValidType = "PreSuf";
1318     std::string handleType = "StartWithMobile";
1319     std::string insensitive = "False";
1320     std::string type = "xxx";
1321     std::string input = "(010)86753564";
1322     size_t start = 10;
1323     i18n::phonenumbers::PhoneNumber phoneNumber;
1324     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1325         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1326     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1327     std::string msg = "00222a-86753564A-";
1328     icu::UnicodeString message(msg.c_str());
1329     if (possibleNumber != nullptr) {
1330         regexRule->IsValid(possibleNumber.get(), message);
1331         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1332         EXPECT_EQ(list.size(), 0);
1333     }
1334     delete regexRule;
1335 }
1336 
1337 /**
1338  * @tc.name: IntlFuncTest0084
1339  * @tc.desc: Test RegexRule
1340  * @tc.type: FUNC
1341  */
1342 HWTEST_F(IntlTest, IntlFuncTest0084, TestSize.Level1)
1343 {
1344     using namespace i18n::phonenumbers;
1345     std::string regexStr = "\\d{3}";
1346     icu::UnicodeString regex(regexStr.c_str());
1347     std::string isValidType = "Default";
1348     std::string handleType = "Default";
1349     std::string insensitive = "False";
1350     std::string type = "xxx";
1351     std::string input = "(010)86753564";
1352     size_t start = 10;
1353     i18n::phonenumbers::PhoneNumber phoneNumber;
1354     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1355         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1356     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1357     std::string msg = "00222a-86753564A-";
1358     icu::UnicodeString message(msg.c_str());
1359     if (possibleNumber != nullptr) {
1360         std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1361         EXPECT_EQ(list.size(), 1);
1362     }
1363     delete regexRule;
1364 }
1365 
1366 /**
1367  * @tc.name: IntlFuncTest0085
1368  * @tc.desc: Test BorderRule
1369  * @tc.type: FUNC
1370  */
1371 HWTEST_F(IntlTest, IntlFuncTest0085, TestSize.Level1)
1372 {
1373     using namespace i18n::phonenumbers;
1374     std::string str = "\\d+";
1375     icu::UnicodeString regex(str.c_str());
1376     std::string insensitive = "False";
1377     std::string type = "CONTAIN_OR_INTERSECT";
1378     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1379     icu::RegexPattern* regexPattern = borderRule->GetPattern();
1380     std::string msg = "2222U-(010)86753564a-hha";
1381     std::string input = "(010)86753564";
1382     size_t start = 6;
1383     i18n::phonenumbers::PhoneNumber phoneNumber;
1384     icu::UnicodeString message(msg.c_str());
1385     std::unique_ptr<PhoneNumberMatch> match =
1386         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1387     bool flag = borderRule->Handle(match.get(), message);
1388     EXPECT_TRUE(flag);
1389 
1390     type = "CONTAIN";
1391     std::unique_ptr<BorderRule> bRule = std::make_unique<BorderRule>(regex, insensitive, type);
1392     flag = bRule->Handle(match.get(), message);
1393     EXPECT_TRUE(flag);
1394     delete regexPattern;
1395 }
1396 
1397 /**
1398  * @tc.name: IntlFuncTest0086
1399  * @tc.desc: Test BorderRule
1400  * @tc.type: FUNC
1401  */
1402 HWTEST_F(IntlTest, IntlFuncTest0086, TestSize.Level1)
1403 {
1404     using namespace i18n::phonenumbers;
1405     std::string str = "\\d+";
1406     icu::UnicodeString regex(str.c_str());
1407     std::string insensitive = "False";
1408     std::string type = "xx@@";
1409     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1410     icu::UnicodeString newRegex;
1411     insensitive = "True";
1412     std::unique_ptr<FindRule> findRule = std::make_unique<FindRule>(newRegex, insensitive);
1413     icu::RegexPattern* regexPattern = findRule->GetPattern();
1414     EXPECT_TRUE(regexPattern != nullptr);
1415     delete regexPattern;
1416     std::string emptyStr = "";
1417     icu::UnicodeString emptyRegex(emptyStr.c_str());
1418     std::unique_ptr<BorderRule> emptyBorderRule =
1419         std::make_unique<BorderRule>(emptyRegex, insensitive, type);
1420 }
1421 
1422 /**
1423  * @tc.name: IntlFuncTest0087
1424  * @tc.desc: Test LocaleMatcher
1425  * @tc.type: FUNC
1426  */
1427 HWTEST_F(IntlTest, IntlFuncTest0087, TestSize.Level1)
1428 {
1429     const std::unique_ptr<LocaleInfo> request = std::make_unique<LocaleInfo>("en-Qaag-GB");
1430     const std::unique_ptr<LocaleInfo> enLatn = std::make_unique<LocaleInfo>("en-US");
1431     LocaleMatcher::Match(request.get(), enLatn.get());
1432     std::vector<LocaleInfo*> candidateLocales;
1433     LocaleInfo* locale0 = new LocaleInfo("en-US");
1434     LocaleInfo* locale1 = new LocaleInfo("en-Qaag-US");
1435     LocaleInfo* locale2 = new LocaleInfo("en-Latn-GB");
1436     LocaleInfo* locale3 = new LocaleInfo("en");
1437     candidateLocales.push_back(locale0);
1438     candidateLocales.push_back(locale1);
1439     candidateLocales.push_back(locale2);
1440     candidateLocales.push_back(locale3);
1441     std::string bestMatch = LocaleMatcher::GetBestMatchedLocale(request.get(), candidateLocales);
1442     EXPECT_EQ(bestMatch, "en-Latn-GB");
1443     delete locale0;
1444     delete locale1;
1445     delete locale2;
1446     delete locale3;
1447 }
1448 
1449 /**
1450  * @tc.name: IntlFuncTest0088
1451  * @tc.desc: Test SignatureVerifier
1452  * @tc.type: FUNC
1453  */
1454 HWTEST_F(IntlTest, IntlFuncTest0088, TestSize.Level1)
1455 {
1456     std::vector<std::string> list;
1457     list.push_back("Name: version.txt");
1458     list.push_back("SHA-256-Digest: ZI5bXA19r7Zc9THhWCuoSaSvg+mvdX9ztQNocDvlej4=");
1459     list.push_back("");
1460     IcsFileWriter icsFileWriter;
1461     std::string manifestName = "MANIFEST.MF";
1462     std::string manifestPath = icsFileWriter.WriteManifest(list, manifestName);
1463     const std::string filePath = "/data/log/";
1464     std::string fileName = "version.txt";
1465     std::vector<std::string> versonList;
1466     versonList.push_back("version=1.10.25.100");
1467     versonList.push_back("type=TIMEZONE");
1468     versonList.push_back("subtype=generic");
1469     versonList.push_back("compatibleVersion=1");
1470     versonList.push_back("classify=2");
1471     versonList.push_back("displayVersion=TB.GENC.1.10.25.100");
1472     icsFileWriter.WriteManifest(versonList, fileName);
1473     bool flag = SignatureVerifier::VerifyParamFile(fileName, filePath, manifestPath);
1474     EXPECT_FALSE(flag);
1475     std::string fakeManifestPath = "/data/54321.MF";
1476     flag = SignatureVerifier::VerifyParamFile(fileName, filePath, fakeManifestPath);
1477     std::string fakeFileName = "version0.txt";
1478     flag = SignatureVerifier::VerifyParamFile(fakeFileName, filePath, manifestPath);
1479     std::string fakePath = "/data/log/123.txt";
1480     std::string resultVersion = SignatureVerifier::LoadFileVersion(fakePath);
1481     EXPECT_EQ(resultVersion, "");
1482     resultVersion = SignatureVerifier::LoadFileVersion(manifestPath);
1483     EXPECT_EQ(resultVersion, "");
1484 
1485     std::vector<std::string> verifyList;
1486     list.push_back("SHA-256-Digest-Manifest: digRIFiRRqEetuyxz6QSRpPePWxaCvAqWgBSnB42Cwc=");
1487     list.push_back("Name: version.txt");
1488     list.push_back("SHA-256-Digest: UkBz6aVlhyCe1tHdxZOvwg8y2pODSmbJSgMTurmeNN0");
1489     list.push_back("");
1490     std::string verifyName = "CERT.SF";
1491     std::string verifyPath = icsFileWriter.WriteManifest(verifyList, verifyName);
1492     std::string certName = "CERT.ENC";
1493     std::string certPath = icsFileWriter.WriteBinaryFile(certName);
1494     std::string publicName = "123.pem";
1495     std::string pubkeyPath = icsFileWriter.WriteBinaryFile(publicName);
1496     bool verifyFlag = SignatureVerifier::VerifyCertFile(certPath, verifyPath, pubkeyPath, manifestPath);
1497     EXPECT_FALSE(verifyFlag);
1498 }
1499 
1500 /**
1501  * @tc.name: IntlFuncTest0089
1502  * @tc.desc: Test CodeRule
1503  * @tc.type: FUNC
1504  */
1505 HWTEST_F(IntlTest, IntlFuncTest0089, TestSize.Level1)
1506 {
1507     std::string isValidType = "PreSuf";
1508     std::string msg = "1 800 234 45 67A-";
1509     icu::UnicodeString message(msg.c_str());
1510     i18n::phonenumbers::PhoneNumber phoneNumber;
1511     size_t start = 0;
1512     std::string rawStr = "1 800 234 45 67";
1513     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1514         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1515     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1516     if (possibleNumber != nullptr) {
1517         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1518         EXPECT_TRUE(match != nullptr);
1519         msg = "1 800 234 45 67a1";
1520         icu::UnicodeString message2(msg.c_str());
1521         PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1522         EXPECT_TRUE(match2 != nullptr);
1523         msg = "1 800 234 45 67a@";
1524         icu::UnicodeString message3(msg.c_str());
1525         PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1526         EXPECT_TRUE(match3 != nullptr);
1527         msg = "1 800 234 45 67ab";
1528         icu::UnicodeString message4(msg.c_str());
1529         PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1530         EXPECT_TRUE(match4 != nullptr);
1531     }
1532     PhoneNumberMatch* match5 = codeRule->Handle(nullptr, message);
1533     EXPECT_TRUE(match5 == nullptr);
1534 }
1535 
1536 /**
1537  * @tc.name: IntlFuncTest0090
1538  * @tc.desc: Test CodeRule
1539  * @tc.type: FUNC
1540  */
1541 HWTEST_F(IntlTest, IntlFuncTest0090, TestSize.Level1)
1542 {
1543     std::string isValidType = "Code";
1544     std::string msg = "00222a-1 800 234 45 67A-";
1545     icu::UnicodeString message(msg.c_str());
1546     i18n::phonenumbers::PhoneNumber phoneNumber;
1547     size_t start = 10;
1548     std::string rawStr = "[17777]8;ext=123";
1549     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1550         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1551     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1552     if (possibleNumber != nullptr) {
1553         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1554         EXPECT_TRUE(match == nullptr);
1555     }
1556 }
1557 
1558 /**
1559  * @tc.name: IntlFuncTest0091
1560  * @tc.desc: Test CodeRule
1561  * @tc.type: FUNC
1562  */
1563 HWTEST_F(IntlTest, IntlFuncTest0091, TestSize.Level1)
1564 {
1565     size_t start = 10;
1566     i18n::phonenumbers::PhoneNumber phoneNumber;
1567     std::string msg = "00222a-(0755)36661888A-";
1568     icu::UnicodeString message(msg.c_str());
1569     std::string rawStr = "(0755)36661888";
1570     std::unique_ptr<PhoneNumberMatch> possibleNum = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1571     std::string regexStr = "\\d{4}";
1572     icu::UnicodeString regex(regexStr.c_str());
1573     std::string handleType = "Operator";
1574     std::string insensitive = "True";
1575     std::unique_ptr<PositiveRule> pRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1576     std::vector<MatchedNumberInfo> list = pRule->HandleInner(possibleNum.get(), message);
1577     EXPECT_EQ(list.size(), 1);
1578     handleType = "Blank";
1579     start = 0;
1580     rawStr = "0755 36661888";
1581     i18n::phonenumbers::PhoneNumber phoneNumber2;
1582     std::unique_ptr<PhoneNumberMatch> maybeNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1583     std::unique_ptr<PositiveRule> posiRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1584     std::vector<MatchedNumberInfo> list2 = posiRule->HandleInner(maybeNumber.get(), message);
1585     EXPECT_EQ(list2.size(), 1);
1586 }
1587 
1588 /**
1589  * @tc.name: IntlFuncTest0092
1590  * @tc.desc: Test I18nBreakIterator
1591  * @tc.type: FUNC
1592  */
1593 HWTEST_F(IntlTest, IntlFuncTest0092, TestSize.Level1)
1594 {
1595     std::unique_ptr<I18nBreakIteratorMock> breakIteratorMock = std::make_unique<I18nBreakIteratorMock>("en-GB");
1596     EXPECT_CALL(*breakIteratorMock, GetBreakIterator())
1597     .WillRepeatedly(Return(nullptr));
1598     breakIteratorMock->Current();
1599     breakIteratorMock->First();
1600     breakIteratorMock->Last();
1601     breakIteratorMock->Previous();
1602     breakIteratorMock->Next();
1603     breakIteratorMock->Next(1);
1604     breakIteratorMock->Following(3);
1605     bool flag = breakIteratorMock->IsBoundary(1);
1606     EXPECT_FALSE(flag);
1607 }
1608 
1609 /**
1610  * @tc.name: IntlFuncTest0093
1611  * @tc.desc: Test RegexRule
1612  * @tc.type: FUNC
1613  */
1614 HWTEST_F(IntlTest, IntlFuncTest0093, TestSize.Level1)
1615 {
1616     using namespace i18n::phonenumbers;
1617     std::string regexStr = "\\d{3}";
1618     icu::UnicodeString regex(regexStr.c_str());
1619     std::string isValidType = "PreSuf";
1620     std::string insensitive = "False";
1621     std::string handleType = "EndWithMobile";
1622     std::string type = "xxx";
1623     std::string msg = "00222a-1 800 234 45 67A-";
1624     icu::UnicodeString message(msg.c_str());
1625     i18n::phonenumbers::PhoneNumber phoneNumber;
1626     size_t start = 10;
1627     std::string rawStr = "1 800 234 45 67";
1628     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1629         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1630     std::unique_ptr<RegexRule> regexRule =
1631         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1632     if (possibleNumber != nullptr) {
1633         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1634         EXPECT_TRUE(match != nullptr);
1635     }
1636 
1637     isValidType = "Code";
1638     rawStr = "119";
1639     start = 0;
1640     i18n::phonenumbers::PhoneNumber phoneNumber2;
1641     std::unique_ptr<PhoneNumberMatch> possibleNum =
1642         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1643     std::unique_ptr<RegexRule> regexRule2 =
1644         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1645     if (possibleNum != nullptr) {
1646         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1647         EXPECT_TRUE(pnMatch == nullptr);
1648     }
1649 }
1650 
1651 /**
1652  * @tc.name: IntlFuncTest0094
1653  * @tc.desc: Test RegexRule
1654  * @tc.type: FUNC
1655  */
1656 HWTEST_F(IntlTest, IntlFuncTest0094, TestSize.Level1)
1657 {
1658     using namespace i18n::phonenumbers;
1659     std::string regexStr = "\\d{3}";
1660     icu::UnicodeString regex(regexStr.c_str());
1661     std::string isValidType = "PreSuf";
1662     std::string insensitive = "False";
1663     std::string handleType = "EndWithMobile";
1664     std::string type = "xxx";
1665     std::string msg = "00222a-1 800 234 45 67a1";
1666     icu::UnicodeString message(msg.c_str());
1667     i18n::phonenumbers::PhoneNumber phoneNumber;
1668     size_t start = 10;
1669     std::string rawStr = "1 800 234 45 67";
1670     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1671         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1672     std::unique_ptr<RegexRule> regexRule =
1673         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1674     if (possibleNumber != nullptr) {
1675         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1676         EXPECT_TRUE(match != nullptr);
1677     }
1678 
1679     isValidType = "Code";
1680     rawStr = "118057628100000001";
1681     start = 0;
1682     i18n::phonenumbers::PhoneNumber phoneNumber2;
1683     std::unique_ptr<PhoneNumberMatch> possibleNum =
1684         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1685     std::unique_ptr<RegexRule> regexRule2 =
1686         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1687     if (possibleNum != nullptr) {
1688         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1689         EXPECT_TRUE(pnMatch == nullptr);
1690     }
1691 
1692     isValidType = "Code";
1693     rawStr = "40082088201";
1694     start = 0;
1695     i18n::phonenumbers::PhoneNumber phoneNumber3;
1696     std::unique_ptr<PhoneNumberMatch> maybeNumber =
1697         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber3);
1698     std::unique_ptr<RegexRule> regexRule3 =
1699         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1700     if (maybeNumber != nullptr) {
1701         PhoneNumberMatch* pnMatch = regexRule3->IsValid(maybeNumber.get(), message);
1702         EXPECT_TRUE(pnMatch == nullptr);
1703     }
1704 }
1705 
1706 /**
1707  * @tc.name: IntlFuncTest0095
1708  * @tc.desc: Test RegexRule
1709  * @tc.type: FUNC
1710  */
1711 HWTEST_F(IntlTest, IntlFuncTest0095, TestSize.Level1)
1712 {
1713     using namespace i18n::phonenumbers;
1714     std::string regexStr = "\\d{3}";
1715     icu::UnicodeString regex(regexStr.c_str());
1716     std::string isValidType = "PreSuf";
1717     std::string insensitive = "False";
1718     std::string handleType = "EndWithMobile";
1719     std::string type = "xxx";
1720     std::string msg = "00222a-1 800 234 45 67a@";
1721     icu::UnicodeString message(msg.c_str());
1722     i18n::phonenumbers::PhoneNumber phoneNumber;
1723     size_t start = 10;
1724     std::string rawStr = "1 800 234 45 67";
1725     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1726         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1727     std::unique_ptr<RegexRule> regexRule =
1728         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1729     if (possibleNumber != nullptr) {
1730         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1731         EXPECT_TRUE(match != nullptr);
1732     }
1733 
1734     isValidType = "Code";
1735     rawStr = "0106857628100000001";
1736     start = 0;
1737     i18n::phonenumbers::PhoneNumber phoneNumber2;
1738     std::unique_ptr<PhoneNumberMatch> possibleNum =
1739         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1740     std::unique_ptr<RegexRule> regexRule2 =
1741         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1742     if (possibleNum != nullptr) {
1743         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1744         EXPECT_TRUE(pnMatch == nullptr);
1745     }
1746 }
1747 
1748 /**
1749  * @tc.name: IntlFuncTest0096
1750  * @tc.desc: Test RegexRule
1751  * @tc.type: FUNC
1752  */
1753 HWTEST_F(IntlTest, IntlFuncTest0096, TestSize.Level1)
1754 {
1755     using namespace i18n::phonenumbers;
1756     std::string regexStr = "\\d{3}";
1757     icu::UnicodeString regex(regexStr.c_str());
1758     std::string isValidType = "PreSuf";
1759     std::string insensitive = "False";
1760     std::string handleType = "EndWithMobile";
1761     std::string type = "xxx";
1762     std::string msg = "00222a-1 800 234 45 67ab";
1763     icu::UnicodeString message(msg.c_str());
1764     i18n::phonenumbers::PhoneNumber phoneNumber;
1765     size_t start = 7;
1766     std::string rawStr = "1 800 234 45 67";
1767     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1768         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1769     std::unique_ptr<RegexRule> regexRule =
1770         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1771     if (possibleNumber != nullptr) {
1772         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1773         EXPECT_TRUE(match != nullptr);
1774     }
1775 
1776     isValidType = "Rawstr";
1777     rawStr = "10645656";
1778     start = 0;
1779     i18n::phonenumbers::PhoneNumber phoneNumber2;
1780     std::unique_ptr<PhoneNumberMatch> possibleNum =
1781         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1782     std::unique_ptr<RegexRule> regexRule2 =
1783         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1784     if (possibleNum != nullptr) {
1785         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1786         EXPECT_TRUE(pnMatch == nullptr);
1787     }
1788 
1789     isValidType = "Rawstr";
1790     rawStr = "119";
1791     start = 0;
1792     i18n::phonenumbers::PhoneNumber phoneNumber3;
1793     std::unique_ptr<PhoneNumberMatch> posibleNumber =
1794         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber3);
1795     std::unique_ptr<RegexRule> regexRule3 =
1796         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1797     if (posibleNumber != nullptr) {
1798         PhoneNumberMatch* pMatch = regexRule3->IsValid(posibleNumber.get(), message);
1799         EXPECT_TRUE(pMatch == nullptr);
1800     }
1801 }
1802 
1803 /**
1804  * @tc.name: IntlFuncTest0097
1805  * @tc.desc: Test Intl I18nCalendarMock
1806  * @tc.type: FUNC
1807  */
1808 HWTEST_F(IntlTest, IntlFuncTest0097, TestSize.Level1)
1809 {
1810     std::unique_ptr<I18nCalendarMock> calendarMock = std::make_unique<I18nCalendarMock>("zh-Hans-CN");
1811     EXPECT_CALL(*calendarMock, GetIcuCalendar())
1812     .WillRepeatedly(Return(nullptr));
1813 
1814     calendarMock->SetTime(1684742124645);
1815     calendarMock->Get(UCalendarDateFields::UCAL_YEAR);
1816     calendarMock->SetFirstDayOfWeek(-1);
1817     calendarMock->GetTimeInMillis();
1818 
1819     calendarMock->GetMinimalDaysInFirstWeek();
1820     int32_t minimalDaysInFirstWeek = calendarMock->GetMinimalDaysInFirstWeek();
1821     EXPECT_EQ(minimalDaysInFirstWeek, 1);
1822     int32_t firstDayOfWeek = calendarMock->GetFirstDayOfWeek();
1823     EXPECT_EQ(firstDayOfWeek, 1);
1824     calendarMock->Set(2023, 5, 28);
1825     UErrorCode status = U_ZERO_ERROR;
1826     calendarMock->IsWeekend(168473854645, status);
1827     calendarMock->CompareDays(1684742124650);
1828     bool isWeekend = calendarMock->IsWeekend();
1829     EXPECT_FALSE(isWeekend);
1830     std::string localeTag = "en";
1831     std::string displayName = calendarMock->GetDisplayName(localeTag);
1832     EXPECT_EQ(displayName, "");
1833 }
1834 
1835 /**
1836  * @tc.name: IntlFuncTest00104
1837  * @tc.desc: Test CodeRule
1838  * @tc.type: FUNC
1839  */
1840 HWTEST_F(IntlTest, IntlFuncTest00104, TestSize.Level1)
1841 {
1842     std::string isValidType = "PreSuf";
1843     std::string msg = "1 800 234 45";
1844     icu::UnicodeString message(msg.c_str());
1845     i18n::phonenumbers::PhoneNumber phoneNumber;
1846     size_t start = 0;
1847     std::string rawStr = "1 800 234 45 67";
1848     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1849         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1850     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1851     if (possibleNumber != nullptr) {
1852         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1853         EXPECT_TRUE(match != nullptr);
1854     }
1855 }
1856 
1857 /**
1858  * @tc.name: IntlFuncTest00105
1859  * @tc.desc: Test CodeRule
1860  * @tc.type: FUNC
1861  */
1862 HWTEST_F(IntlTest, IntlFuncTest00105, TestSize.Level1)
1863 {
1864     std::string isValidType = "PreSuf";
1865     std::string msg = "A-1 800 234 45 67";
1866     icu::UnicodeString message(msg.c_str());
1867     i18n::phonenumbers::PhoneNumber phoneNumber;
1868     size_t start = 2;
1869     std::string rawStr = "1 800 234 45 67";
1870     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1871         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1872     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1873     if (possibleNumber != nullptr) {
1874         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1875         EXPECT_TRUE(match != nullptr);
1876         msg = "a11 800 234 45 67";
1877         icu::UnicodeString message2(msg.c_str());
1878         PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1879         EXPECT_TRUE(match2 != nullptr);
1880         msg = "a@1 800 234 45 67";
1881         icu::UnicodeString message3(msg.c_str());
1882         PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1883         EXPECT_TRUE(match3 != nullptr);
1884         msg = "ab1 800 234 45 67";
1885         icu::UnicodeString message4(msg.c_str());
1886         PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1887         EXPECT_TRUE(match4 != nullptr);
1888     }
1889 }
1890 
1891 /**
1892  * @tc.name: IntlFuncTest00106
1893  * @tc.desc: Test CodeRule
1894  * @tc.type: FUNC
1895  */
1896 HWTEST_F(IntlTest, IntlFuncTest00106, TestSize.Level1)
1897 {
1898     std::string isValidType = "Rawstr";
1899     std::string msg = "13649372A-";
1900     icu::UnicodeString message(msg.c_str());
1901     i18n::phonenumbers::PhoneNumber phoneNumber;
1902     size_t start = 0;
1903     std::string rawStr = "13649372;ext=123";
1904     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1905         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1906     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1907     if (possibleNumber != nullptr) {
1908         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1909         if (match != nullptr) {
1910             EXPECT_EQ(match->raw_string(), rawStr);
1911         }
1912     }
1913 }
1914 
1915 /**
1916  * @tc.name: IntlFuncTest00107
1917  * @tc.desc: Test CodeRule
1918  * @tc.type: FUNC
1919  */
1920 HWTEST_F(IntlTest, IntlFuncTest00107, TestSize.Level1)
1921 {
1922     std::string isValidType = "Rawstr";
1923     std::string msg = "400A-";
1924     icu::UnicodeString message(msg.c_str());
1925     i18n::phonenumbers::PhoneNumber phoneNumber;
1926     size_t start = 0;
1927     std::string rawStr = "400";
1928     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1929         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1930     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1931     if (possibleNumber != nullptr) {
1932         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1933         EXPECT_TRUE(match == nullptr);
1934     }
1935 }
1936 } // namespace I18n
1937 } // namespace Global
1938 } // namespace OHOS