• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "index_util_mock.h"
35 #include "rules_engine_mock.h"
36 #include "i18n_timezone.h"
37 #include "i18n_types.h"
38 #include "index_util.h"
39 #include "locale_compare.h"
40 #include "locale_config.h"
41 #include "locale_info.h"
42 #include "locale_matcher.h"
43 #include "measure_data.h"
44 #include "multi_users.h"
45 #include "number_format.h"
46 #include "parameter.h"
47 #include "phone_number_format.h"
48 #include "phone_number_rule.h"
49 #include "plural_rules.h"
50 #include "positive_rule.h"
51 #include "preferred_language.h"
52 #include "regex_rule.h"
53 #include "relative_time_format.h"
54 #include "rules_engine.h"
55 #include "system_locale_manager.h"
56 #include "taboo_utils.h"
57 #include "taboo.h"
58 #include "token_setproc.h"
59 #include "upgrade_utils.h"
60 #include "utils.h"
61 #include "intl_test.h"
62 #include "generate_ics_file.h"
63 #include <unistd.h>
64 #include "unicode/utypes.h"
65 
66 using namespace OHOS::Global::I18n;
67 using testing::ext::TestSize;
68 using namespace std;
69 using namespace testing;
70 
71 namespace OHOS {
72 namespace Global {
73 namespace I18n {
74 /**
75  * @tc.name: IntlFuncTest0047
76  * @tc.desc: Test Intl LocaleConfig GetBlockedLanguages
77  * @tc.type: FUNC
78  */
79 HWTEST_F(IntlTest, IntlFuncTest0047, TestSize.Level1)
80 {
81     std::unordered_set<std::string> languageSet = LocaleConfig::GetBlockedLanguages();
82     EXPECT_TRUE(languageSet.size() == 0);
83 }
84 
85 /**
86  * @tc.name: IntlFuncTest0048
87  * @tc.desc: Test Intl LocaleConfig GetBlockedRegions
88  * @tc.type: FUNC
89  */
90 HWTEST_F(IntlTest, IntlFuncTest0048, TestSize.Level1)
91 {
92     std::unordered_set<std::string> regionSet = LocaleConfig::GetBlockedRegions();
93     EXPECT_TRUE(regionSet.size() == 0 || regionSet.size() == 2);
94 }
95 
96 /**
97  * @tc.name: IntlFuncTest0049
98  * @tc.desc: Test Intl LocaleConfig
99  * @tc.type: FUNC
100  */
101 HWTEST_F(IntlTest, IntlFuncTest0049, TestSize.Level1)
102 {
103     I18nErrorCode status = LocaleConfig::SetSystemLanguage("zh-Hans");
104     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
105     std::string systemLanguage = LocaleConfig::GetSystemLanguage();
106     EXPECT_EQ(systemLanguage, "zh-Hans");
107 
108     status = LocaleConfig::SetSystemRegion("CN");
109     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
110     std::string systemRegion = LocaleConfig::GetSystemRegion();
111     EXPECT_EQ(systemRegion, "CN");
112     std::string systemLocale = LocaleConfig::GetSystemLocale();
113     EXPECT_EQ(systemLocale, "zh-Hans-CN");
114 
115     const std::string locale = "zh-CN";
116     bool isRTL = LocaleConfig::IsRTL(locale);
117     EXPECT_TRUE(!isRTL);
118     std::string validLocale = LocaleConfig::GetValidLocale(locale);
119     EXPECT_EQ(validLocale, "zh-CN");
120     EXPECT_TRUE(!LocaleConfig::IsRTL(""));
121 
122     status = LocaleConfig::Set24HourClock("false");
123     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
124     bool is24HourClock = LocaleConfig::Is24HourClock();
125     EXPECT_TRUE(!is24HourClock);
126 
127     status = LocaleConfig::SetUsingLocalDigit(true);
128     EXPECT_EQ(status, I18nErrorCode::UPDATE_LOCAL_DIGIT_FAILED);
129     bool usingLocalDigit = LocaleConfig::GetUsingLocalDigit();
130     EXPECT_FALSE(usingLocalDigit);
131 
132     std::string path = "/data/log/faultlog";
133     char delimiter = '/';
134     const std::string localeStr = "ar";
135     std::shared_ptr<LocaleInfo> localeInfo = std::make_shared<LocaleInfo>(localeStr);
136     std::string errorCode;
137     std::string res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
138     EXPECT_EQ(res, "\u200f/\u200edata\u200e\u200f/\u200elog\u200e\u200f/\u200efaultlog\u200e");
139     path = "\\data\\log\\faultlog";
140     delimiter = '\\';
141     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
142     EXPECT_EQ(res, "\u200f\\\u200edata\u200e\u200f\\\u200elog\u200e\u200f\\\u200efaultlog\u200e");
143     path = "data>log>faultlog";
144     delimiter = '>';
145     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
146     EXPECT_EQ(res, "\u200f\u200edata\u200e\u200f>\u200elog\u200e\u200f>\u200efaultlog\u200e");
147 }
148 
149 /**
150  * @tc.name: IntlFuncTest0050
151  * @tc.desc: Test Intl PreferredLanguage AddPreferredLanguageExist
152  * @tc.type: FUNC
153  */
154 HWTEST_F(IntlTest, IntlFuncTest0050, TestSize.Level1)
155 {
156     // init test environment
157     I18nErrorCode status = LocaleConfig::SetSystemLanguage("zh-Hans");
158     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
159     std::vector<std::string> preferredLanguageList = PreferredLanguage::GetPreferredLanguageList();
160     for (auto i = preferredLanguageList.size() - 1; i > 0; --i) {
161         status = PreferredLanguage::RemovePreferredLanguage(i);
162         EXPECT_EQ(status, I18nErrorCode::SUCCESS);
163     }
164     // execute test
165     const std::string language = "zh-CN";
166     const std::string languageDe = "de-DE";
167     const std::string fakeLanguage = "1**1";
168     status = PreferredLanguage::AddPreferredLanguage(language, 0);
169     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
170     status = PreferredLanguage::AddPreferredLanguage(language, 0);
171     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
172     PreferredLanguage::RemovePreferredLanguage(0);
173     status = PreferredLanguage::AddPreferredLanguage(languageDe, 1);
174     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
175     status = PreferredLanguage::AddPreferredLanguage(language, 3);
176     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
177     status = PreferredLanguage::AddPreferredLanguage("", 3);
178     EXPECT_EQ(status, I18nErrorCode::INVALID_LANGUAGE_TAG);
179     PreferredLanguage::AddPreferredLanguage(fakeLanguage, -1);
180     PreferredLanguage::AddPreferredLanguage(language, -1);
181     PreferredLanguage::AddPreferredLanguage("$$", 0);
182     std::vector<std::string> list = PreferredLanguage::GetPreferredLanguageList();
183     EXPECT_EQ(list.size(), 2);
184     std::string firstPreferredLanguage = PreferredLanguage::GetFirstPreferredLanguage();
185     EXPECT_EQ(firstPreferredLanguage, "zh-Hans");
186     std::string preferredLocale = PreferredLanguage::GetPreferredLocale();
187     EXPECT_EQ(preferredLocale, "zh-CN");
188     status = PreferredLanguage::RemovePreferredLanguage(0);
189     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
190     // restore environment
191     status = LocaleConfig::SetSystemLanguage("zh-Hans");
192     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
193     preferredLanguageList = PreferredLanguage::GetPreferredLanguageList();
194     for (auto i = preferredLanguageList.size() - 1; i > 0; --i) {
195         status = PreferredLanguage::RemovePreferredLanguage(i);
196         EXPECT_EQ(status, I18nErrorCode::SUCCESS);
197     }
198 }
199 
200 /**
201  * @tc.name: IntlFuncTest0051
202  * @tc.desc: Test Intl I18nCalendar
203  * @tc.type: FUNC
204  */
205 HWTEST_F(IntlTest, IntlFuncTest0051, TestSize.Level1)
206 {
207     I18nCalendar *calendar = new I18nCalendar("zh-Hans-CN");
208     I18nCalendar *calendar2 = new I18nCalendar("zh-Hans-CN", CalendarType::CHINESE);
209     calendar->SetTime(1684742124645);
210     calendar->Set(1989, 5, 23);
211     calendar->SetTimeZone("Asia/Shanghai");
212     std::string tzId = calendar->GetTimeZone();
213     EXPECT_EQ(tzId, "Asia/Shanghai");
214     int32_t minimalDaysInFirstWeek = calendar->GetMinimalDaysInFirstWeek();
215     EXPECT_EQ(minimalDaysInFirstWeek, 1);
216     int32_t firstDayOfWeek = calendar->GetFirstDayOfWeek();
217     EXPECT_EQ(firstDayOfWeek, 1);
218     calendar2->Set(2023, 5, 28);
219     bool isWeekend = calendar2->IsWeekend();
220     EXPECT_TRUE(isWeekend);
221     I18nCalendar *calendarFake = new I18nCalendar("123");
222     I18nCalendar *calendarInvalid = new I18nCalendar("123", CalendarType::CHINESE);
223     delete calendarFake;
224     delete calendarInvalid;
225     delete calendar;
226     delete calendar2;
227 }
228 
229 /**
230  * @tc.name: IntlFuncTest0052
231  * @tc.desc: Test Intl IndexUtil
232  * @tc.type: FUNC
233  */
234 HWTEST_F(IntlTest, IntlFuncTest0052, TestSize.Level1)
235 {
236     std::unique_ptr<IndexUtil> indexUtil = std::make_unique<IndexUtil>("zh-CN");
237     std::vector<std::string> indexList = indexUtil->GetIndexList();
238     EXPECT_EQ(indexList.size(), 28);
239     indexUtil->AddLocale("en-US");
240     std::string indexStr = indexUtil->GetIndex("A");
241     EXPECT_EQ(indexStr, "A");
242     std::unique_ptr<IndexUtil> idxUtil = std::make_unique<IndexUtil>("@@#");
243     idxUtil->GetIndexList();
244     idxUtil->GetIndex("**");
245 
246     std::unique_ptr<IndexUtil> indexUtil3 = std::make_unique<IndexUtil>("");
247     indexUtil3->AddLocale("en-US");
248     indexStr = indexUtil3->GetIndex("A");
249     EXPECT_EQ(indexStr, "A");
250     std::unique_ptr<MockIndexUtil> indexUtilMock = std::make_unique<MockIndexUtil>("zh-CN");
251     ASSERT_TRUE(indexUtilMock != nullptr);
252     EXPECT_CALL(*indexUtilMock, IsCreateSuccess())
253     .WillRepeatedly(Return(false));
254     indexUtilMock->GetIndexList();
255     std::string res = indexUtilMock->GetIndex("A");
256     EXPECT_EQ(res, "");
257     UErrorCode status = U_ZERO_ERROR;
258     std::unique_ptr<MockIndexUtil> mockIndexUtil = std::make_unique<MockIndexUtil>("zh-CN");
259     ASSERT_TRUE(mockIndexUtil != nullptr);
260     EXPECT_CALL(*mockIndexUtil, IsCreateSuccess()).WillRepeatedly(Return(true));
261     EXPECT_CALL(*mockIndexUtil, IsStatusSuccess(status)).WillOnce(Return(false));
262     std::string result = mockIndexUtil->GetIndex("A");
263     EXPECT_EQ(result, "");
264 
265     std::unique_ptr<MockIndexUtil> indexUtilMock3 = std::make_unique<MockIndexUtil>("zh-CN");
266     ASSERT_TRUE(indexUtilMock3 != nullptr);
267     EXPECT_CALL(*indexUtilMock3, IsCreateSuccess()).WillRepeatedly(Return(true));
268     EXPECT_CALL(*indexUtilMock3, IsStatusSuccess(status))
269     .WillOnce(Return(true))
270     .WillRepeatedly(Return(false));
271     std::string resultIndex = indexUtilMock3->GetIndex("B");
272     EXPECT_EQ(resultIndex, "");
273 }
274 
275 /**
276  * @tc.name: IntlFuncTest0053
277  * @tc.desc: Test Intl PhoneNumberFormat
278  * @tc.type: FUNC
279  */
280 HWTEST_F(IntlTest, IntlFuncTest0053, TestSize.Level1)
281 {
282     map<string, string> options = {
283         { "type", "NATIONAL" }
284     };
285     std::unique_ptr<PhoneNumberFormat> phoneNumberFormat =
286         std::make_unique<PhoneNumberFormat>("zh-CN", options);
287     std::string location = phoneNumberFormat->getLocationName("13228901234", "en-US");
288     EXPECT_EQ(location, "Lhasa, Xizang");
289     std::string location2 = phoneNumberFormat->getLocationName("15156712345", "zh-CN");
290     EXPECT_EQ(location2, "安徽省亳州市");
291     std::string location3 = phoneNumberFormat->getLocationName("17673241234", "zh-CN");
292     EXPECT_EQ(location3, "湖南省株洲市");
293     bool flag = phoneNumberFormat->isValidPhoneNumber("+8618622350085");
294     EXPECT_TRUE(flag);
295     std::string number2 = "+8618622350085";
296     std::string formatResult = phoneNumberFormat->format(number2);
297     EXPECT_EQ(formatResult, "186 2235 0085");
298     std::string location4 = phoneNumberFormat->getLocationName("fake-number", "zh-CN");
299     EXPECT_EQ(location4, "");
300     std::string number3 = "1068195561";
301     std::string formatedStr = phoneNumberFormat->format(number3);
302     EXPECT_EQ(formatedStr, "10 6819 5561");
303 
304     map<string, string> options2 = {
305         { "type", "INTERNATIONAL" }
306     };
307     std::unique_ptr<PhoneNumberFormat> phoneNumberFmt =
308         std::make_unique<PhoneNumberFormat>("zh-CN", options2);
309     std::string loc = phoneNumberFmt->getLocationName("+12015550123", "zh-CN");
310     EXPECT_EQ(loc, "美国");
311 }
312 
313 /**
314  * @tc.name: IntlFuncTest0054
315  * @tc.desc: Test Intl TabooUtils
316  * @tc.type: FUNC
317  */
318 HWTEST_F(IntlTest, IntlFuncTest0054, TestSize.Level1)
319 {
320     TabooUtils* tabooUtils = TabooUtils::GetInstance();
321     ASSERT_TRUE(tabooUtils != nullptr);
322     std::string res1 = tabooUtils->ReplaceCountryName("CN", "en", "China");
323     EXPECT_EQ(res1, "China");
324     std::string res2 = tabooUtils->ReplaceLanguageName("zh", "en", "chinese");
325     EXPECT_EQ(res2, "chinese");
326     std::string res3 = tabooUtils->ReplaceCountryName("TW", "zh-Hans", "中国台湾");
327     EXPECT_EQ(res3, "中国台湾");
328 }
329 
330 /**
331  * @tc.name: IntlFuncTest0055
332  * @tc.desc: Test Intl LocaleCompare
333  * @tc.type: FUNC
334  */
335 HWTEST_F(IntlTest, IntlFuncTest0055, TestSize.Level1)
336 {
337     int32_t result = LocaleCompare::Compare("zh-CN", "zh-Hans-CN");
338     EXPECT_EQ(result, 9);
339     I18nBreakIterator *i18nBreakIterator = new I18nBreakIterator("zh-Hans-CN");
340     bool isBoundary = i18nBreakIterator->IsBoundary(6);
341     EXPECT_TRUE(!isBoundary);
342     int32_t current = i18nBreakIterator->Current();
343     EXPECT_EQ(current, 0);
344     int32_t first = i18nBreakIterator->First();
345     EXPECT_EQ(first, 0);
346     int32_t last = i18nBreakIterator->Last();
347     EXPECT_EQ(last, 0);
348     int32_t previous = i18nBreakIterator->Previous();
349     EXPECT_EQ(previous, -1);
350     int32_t next6 = i18nBreakIterator->Next(6);
351     EXPECT_EQ(next6, -1);
352     int32_t resultLatn = LocaleCompare::Compare("en-Latn-US", "en-Qaag-US");
353     EXPECT_EQ(resultLatn, 9);
354     int32_t resultTl = LocaleCompare::Compare("tl-PH", "fil-PH");
355     EXPECT_EQ(resultTl, 9);
356     int32_t resultFil = LocaleCompare::Compare("fil-PH", "tl-PH");
357     EXPECT_EQ(resultFil, 9);
358     int32_t resultQaag = LocaleCompare::Compare("en-Qaag-US", "en-Latn-US");
359     EXPECT_EQ(resultQaag, 9);
360     int32_t resultHashMapZh = LocaleCompare::Compare("zh-MO", "zh-Hant-HK");
361     EXPECT_EQ(resultHashMapZh, 8);
362     int32_t resultZh = LocaleCompare::Compare("zh-Hant-MO", "zh-Hant-HK");
363     EXPECT_EQ(resultZh, 8);
364     int32_t resultHashMapEn = LocaleCompare::Compare("en-WS", "en-001");
365     EXPECT_EQ(resultHashMapEn, 8);
366     int32_t resultHashEn = LocaleCompare::Compare("en-Latn-WS", "en-001");
367     EXPECT_EQ(resultHashEn, 8);
368     int32_t resultHashQaagEn = LocaleCompare::Compare("en-Qaag-WS", "en-001");
369     EXPECT_EQ(resultHashQaagEn, 8);
370     I18nBreakIterator *breakIterator = new I18nBreakIterator("2--**");
371     breakIterator->Current();
372     breakIterator->First();
373     breakIterator->Last();
374     breakIterator->Previous();
375     breakIterator->Next(6);
376     breakIterator->Next();
377     breakIterator->Following(0);
378     breakIterator->IsBoundary(6);
379     std::unique_ptr<I18nBreakIterator> brkIterator = std::make_unique<I18nBreakIterator>("");
380     delete breakIterator;
381     delete i18nBreakIterator;
382 }
383 
384 /**
385  * @tc.name: IntlFuncTest0056
386  * @tc.desc: Test Intl SystemLocaleManager
387  * @tc.type: FUNC
388  */
389 HWTEST_F(IntlTest, IntlFuncTest0056, TestSize.Level1)
390 {
391     SystemLocaleManager *systemLocaleManager = new SystemLocaleManager();
392     std::vector<std::string> languages = {"en", "de", "es", "fr"};
393     SortOptions sortOptions = {"en-US", true, true};
394     I18nErrorCode status;
395     std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions, status);
396     EXPECT_EQ(languageInfos.size(), 4);
397     const std::vector<std::string> countries = {"US", "GB", "DE", "CN"};
398     std::vector<LocaleItem> countryInfos = systemLocaleManager->GetCountryInfoArray(countries, sortOptions, status);
399     EXPECT_EQ(countryInfos.size(), 4);
400     std::vector<TimeZoneCityItem> timezoneCityItemList = SystemLocaleManager::GetTimezoneCityInfoArray(status);
401     EXPECT_TRUE(timezoneCityItemList.size() > 0);
402     delete systemLocaleManager;
403 }
404 
405 /**
406  * @tc.name: IntlFuncTest0057
407  * @tc.desc: Test Intl Utils
408  * @tc.type: FUNC
409  */
410 HWTEST_F(IntlTest, IntlFuncTest0057, TestSize.Level1)
411 {
412     bool isDigit = IsDigit("55");
413     EXPECT_TRUE(isDigit);
414     bool isSpaceChar = IsSpaceChar(" ");
415     EXPECT_TRUE(isSpaceChar);
416     bool isWhiteSpace = IsWhiteSpace("  ");
417     EXPECT_TRUE(isWhiteSpace);
418     bool isRTLCharacter = IsRTLCharacter("^");
419     EXPECT_TRUE(!isRTLCharacter);
420     isRTLCharacter = IsRTLCharacter("\u0645");
421     EXPECT_TRUE(isRTLCharacter);
422     bool isIdeoGraphic = IsIdeoGraphic("&&*");
423     EXPECT_TRUE(!isIdeoGraphic);
424     bool isLetter = IsLetter("cccUt");
425     EXPECT_TRUE(isLetter);
426     bool isLowerCase = IsLowerCase("abc");
427     EXPECT_TRUE(isLowerCase);
428     bool isUpperCase = IsUpperCase("AbC");
429     EXPECT_TRUE(isUpperCase);
430     std::string getType = GetType("$$%");
431     EXPECT_EQ(getType, "U_CURRENCY_SYMBOL");
432 }
433 
434 /**
435  * @tc.name: IntlFuncTest0058
436  * @tc.desc: Test Intl MeasureData
437  * @tc.type: FUNC
438  */
439 HWTEST_F(IntlTest, IntlFuncTest0058, TestSize.Level1)
440 {
441     std::string timezoneId = "Asia/Shanghai";
442     I18nTimeZone *i18nTimeZone = new I18nTimeZone(timezoneId, true);
443     int32_t offset = i18nTimeZone->GetOffset(1684742124645);
444     EXPECT_EQ(offset, 28800000);
445     int32_t rawOffset = i18nTimeZone->GetRawOffset();
446     EXPECT_EQ(rawOffset, 28800000);
447     std::string tzId = i18nTimeZone->GetID();
448     EXPECT_EQ(tzId, "Asia/Shanghai");
449     std::string displayName = i18nTimeZone->GetDisplayName();
450     EXPECT_EQ(displayName, "中国标准时间");
451     std::string displayName2 = i18nTimeZone->GetDisplayName(true);
452     EXPECT_EQ(displayName2, "中国标准时间");
453     std::string zhCn = "zh-CN";
454     std::string displayNameCn = i18nTimeZone->GetDisplayName(zhCn);
455     EXPECT_EQ(displayNameCn, "中国标准时间");
456     std::string displayName4 = i18nTimeZone->GetDisplayName("zh-CN", true);
457     EXPECT_EQ(displayName4, "中国标准时间");
458     std::string cityId = "Shanghai";
459     std::string localeId = "en-US";
460     std::string cityDisplayName = I18nTimeZone::GetCityDisplayName(cityId, localeId);
461     EXPECT_EQ(cityDisplayName, "Shanghai (China)");
462     std::unique_ptr<I18nTimeZone> timezone = I18nTimeZone::CreateInstance(timezoneId, true);
463     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
464     std::set<std::string> set0 = I18nTimeZone::GetAvailableIDs(errorCode);
465     EXPECT_EQ(set0.size(), 442);
466     std::unordered_set<std::string> set1 = I18nTimeZone::GetAvailableZoneCityIDs();
467     EXPECT_TRUE(set1.size() > 0);
468     std::string empty = "";
469     std::string fakeCityId = "fake cityId";
470     I18nTimeZone *i18nTimeZoneEmpty = new I18nTimeZone(empty, true);
471     I18nTimeZone *i18nTimeZoneFake = new I18nTimeZone(fakeCityId, false);
472     I18nTimeZone *i18nTimeZoneCityId = new I18nTimeZone(cityId, false);
473     delete i18nTimeZoneEmpty;
474     delete i18nTimeZoneFake;
475     delete i18nTimeZoneCityId;
476     delete i18nTimeZone;
477     uint32_t mask = GetMask("CN");
478     EXPECT_EQ(mask, 2462);
479 }
480 
481 /**
482  * @tc.name: IntlFuncTest0059
483  * @tc.desc: Test Intl LocaleMatcher
484  * @tc.type: FUNC
485  */
486 HWTEST_F(IntlTest, IntlFuncTest0059, TestSize.Level1)
487 {
488     std::unique_ptr<LocaleInfo> request = std::make_unique<LocaleInfo>("zh-Hant-HK");
489     std::unique_ptr<LocaleInfo> currentEn = std::make_unique<LocaleInfo>("en-GB");
490     std::unique_ptr<LocaleInfo> otherEn = std::make_unique<LocaleInfo>("en-US");
491     int8_t result = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), request.get());
492     EXPECT_EQ(result, 1);
493     std::unique_ptr<LocaleInfo> requestZh = std::make_unique<LocaleInfo>("zh-Hant");
494     std::unique_ptr<LocaleInfo> current = std::make_unique<LocaleInfo>("en");
495     std::unique_ptr<LocaleInfo> other = std::make_unique<LocaleInfo>("en-US");
496     result = LocaleMatcher::IsMoreSuitable(current.get(), other.get(), requestZh.get());
497     EXPECT_EQ(result, 1);
498     result = LocaleMatcher::IsMoreSuitable(currentEn.get(), current.get(), requestZh.get());
499     EXPECT_EQ(result, -1);
500     std::unique_ptr<LocaleInfo> requestQaag = std::make_unique<LocaleInfo>("en-Qaag");
501     int8_t suitable = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), requestQaag.get());
502     EXPECT_EQ(suitable, 1);
503     suitable = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), current.get());
504     EXPECT_EQ(suitable, -1);
505 }
506 
507 /**
508  * @tc.name: IntlFuncTest0060
509  * @tc.desc: Test Intl HolidayManager
510  * @tc.type: FUNC
511  */
512 HWTEST_F(IntlTest, IntlFuncTest0060, TestSize.Level1)
513 {
514     IcsFileWriter icsFileWriter;
515     std::string path = icsFileWriter.GenerateFile();
516     HolidayManager *holiday_manager = new HolidayManager(path.c_str());
517     std::map<std::string, std::vector<HolidayInfoItem>> holidayDataMap;
518     std::vector<HolidayInfoItem> infoList;
519     std::vector<HolidayLocalName> localNameList1;
520     localNameList1.push_back({"tr", "Kurban Bayrami Tatili"});
521     std::vector<HolidayLocalName> localNameList2;
522     localNameList2.push_back({"tr", "Kurban Bayrami 2. Günü"});
523     HolidayInfoItem item1 = {"Sacrifice Feast Holiday", 2022, 6, 25, localNameList1};
524     HolidayInfoItem item2 = {"The Second Day of Sacrifice Feast", 2022, 6, 25, localNameList2};
525     infoList.push_back(item1);
526     infoList.push_back(item2);
527     holidayDataMap.insert({"20220625", infoList});
528     holiday_manager->SetHolidayData(holidayDataMap);
529     std::vector<HolidayInfoItem> list = holiday_manager->GetHolidayInfoItemArray(2022);
530     EXPECT_EQ(2, list.size());
531     list = holiday_manager->GetHolidayInfoItemArray();
532     EXPECT_EQ(0, list.size());
533     bool flag = holiday_manager->IsHoliday(2022, 6, 25);
534     EXPECT_TRUE(flag);
535     flag = holiday_manager->IsHoliday();
536     EXPECT_TRUE(!flag);
537     std::unique_ptr<HolidayManager> holidayManager = std::make_unique<HolidayManager>(nullptr);
538     std::string fakePath = "/data/log/fake.ics";
539     std::unique_ptr<HolidayManager> fakeManager = std::make_unique<HolidayManager>(fakePath.c_str());
540     delete holiday_manager;
541 }
542 
543 /**
544  * @tc.name: IntlFuncTest0061
545  * @tc.desc: Test Intl LocaleConfig.IsSuggestedV15
546  * @tc.type: FUNC
547  */
548 HWTEST_F(IntlTest, IntlFuncTest0061, TestSize.Level1)
549 {
550     bool flag = LocaleConfig::IsSuggestedV15("zh-Hans");
551     EXPECT_TRUE(flag);
552     EXPECT_TRUE(LocaleConfig::IsSuggestedV15("zh-Hans", "SG"));
553 }
554 
555 /**
556  * @tc.name: IntlFuncTest0062
557  * @tc.desc: Test Intl utils.cpp
558  * @tc.type: FUNC
559  */
560 HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1)
561 {
562     string emptyStr = "";
563     string sep = ";";
564     vector<string> dest;
565     std::unordered_set<std::string> allValidLocalesLanguageTag;
566     Split(emptyStr, sep, dest);
567     int32_t status = 0;
568     string numberStr = "12345678901234567890123456789012345678901234567890987654321";
569     ConvertString2Int(numberStr, status);
570     numberStr = "@#";
571     ConvertString2Int(numberStr, status);
572     icu::Locale locale("$$$$5%%%");
573     bool isValid = IsValidLocaleTag(locale);
574     EXPECT_TRUE(!isValid);
575     GetAllValidLocalesTag(allValidLocalesLanguageTag);
576     EXPECT_TRUE(allValidLocalesLanguageTag.size() == 0);
577     const std::string str = "zh_Hans_CN";
578     const std::string target = "-";
579     const std::string replace = "";
580     StrReplaceAll(str, target, replace);
581 
582     double a = 403.21;
583     double b = 403.2;
584     EXPECT_TRUE(Geq(a, b));
585     EXPECT_TRUE(Leq(b, a));
586 
587     std::string localeTag = "zh-Hans-CN";
588     std::string localeCode = LocaleEncode(localeTag);
589     std::string targetCode = "58400008334651000314";
590     EXPECT_EQ(localeCode, targetCode);
591     std::vector<std::string> resultVec = {"zh", "en", "fr", "de", "zh-Hant", "fil"};
592     const std::string separator = ",";
593     std::string source;
594     Merge(resultVec, separator, source);
595     EXPECT_EQ(source, "zh,en,fr,de,zh-Hant,fil");
596 
597     std::string localeRule = "zh-Hans";
598     DateTimeRule* dateTimeRule = new DateTimeRule(localeRule);
599     DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule);
600     EXPECT_TRUE(dateTimeRule->GetPatternByKey("abc") == nullptr);
601     std::string key1 = "9000";
602     std::string key2 = "10000";
603     EXPECT_EQ(dateTimeRule->CompareLevel(key1, key2), 1);
604     delete dateTimeFilter;
605     delete dateTimeRule;
606 }
607 
608 /**
609  * @tc.name: IntlFuncTest0063
610  * @tc.desc: Test Intl RegexRule
611  * @tc.type: FUNC
612  */
613 HWTEST_F(IntlTest, IntlFuncTest0063, TestSize.Level1)
614 {
615     using namespace i18n::phonenumbers;
616     std::string regexStr = "[a-z]1?";
617     icu::UnicodeString regex(regexStr.c_str());
618     std::string isValidType = "PrexxxxSuf";
619     std::string handleType = "EndWithMobile";
620     std::string insensitive = "False";
621     std::string type = "xxx";
622     std::unique_ptr<RegexRule> regexRule = std::make_unique<RegexRule>(regex,
623         isValidType, handleType, insensitive, type);
624     handleType = "fake";
625     isValidType = "Code";
626     std::unique_ptr<RegexRule> regexRule2 = std::make_unique<RegexRule>(regex, isValidType,
627         handleType, insensitive, type);
628     icu::UnicodeString message(type.c_str());
629 
630     i18n::phonenumbers::PhoneNumber phoneNumber;
631     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
632     std::string input = "[010111111111111;ext=0782";
633     std::string country = "CN";
634     size_t size = input.length();
635     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
636     std::unique_ptr<PhoneNumberMatch> possibleNumber =
637         std::make_unique<PhoneNumberMatch>(size, input, phoneNumber);
638     PhoneNumberMatch* phoneNumberMatch =
639         regexRule2->IsValid(possibleNumber.get(), message);
640     EXPECT_TRUE(phoneNumberMatch != nullptr);
641     regexRule2->GetType();
642     std::unique_ptr<icu::RegexPattern> regexPattern =
643         std::unique_ptr<icu::RegexPattern>(regexRule2->GetPattern());
644     isValidType = "Rawstr";
645     std::unique_ptr<RegexRule> regexRule3 = std::make_unique<RegexRule>(regex, isValidType,
646         handleType, insensitive, type);
647     PhoneNumberMatch* phoneNumMatch =
648         regexRule3->IsValid(possibleNumber.get(), message);
649     EXPECT_TRUE(phoneNumMatch != nullptr);
650     type = "CONTAIN";
651     string newRegexStr;
652     icu::UnicodeString unicRegex(newRegexStr.c_str());
653     std::unique_ptr<RegexRule> regexRule4 = std::make_unique<RegexRule>(unicRegex, isValidType,
654         handleType, insensitive, type);
655     type = "CONTAIN_OR_INTERSECT";
656     std::unique_ptr<RegexRule> regexRule5 = std::make_unique<RegexRule>(unicRegex, isValidType,
657         handleType, insensitive, type);
658     EXPECT_TRUE(regexRule5 != nullptr);
659 }
660 
661 /**
662  * @tc.name: IntlFuncTest0064
663  * @tc.desc: Test GetLanguageInfoArray
664  * @tc.type: FUNC
665  */
666 HWTEST_F(IntlTest, IntlFuncTest0064, TestSize.Level1)
667 {
668     std::unique_ptr<SystemLocaleManager> systemLocaleManager = std::make_unique<SystemLocaleManager>();
669     std::vector<std::string> languages = {"en", "zh-Hans", "es", "fr"};
670     SortOptions sortOptions = {"en-US", true, true};
671     I18nErrorCode status;
672     std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions, status);
673     EXPECT_EQ(languageInfos.size(), 4);
674     EXPECT_EQ(languageInfos[0].id, "zh-Hans");
675     EXPECT_EQ(languageInfos[0].suggestionType, 2);
676 }
677 
678 /**
679  * @tc.name: IntlFuncTest0065
680  * @tc.desc: Test relative time format default parameter
681  * @tc.type: FUNC
682  */
683 HWTEST_F(IntlTest, IntlFuncTest0065, TestSize.Level1)
684 {
685     int bufferLen = 10;
686     char value[bufferLen];
687     vector<string> locales;
688     locales.push_back("fr-FR");
689     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
690     std::string deviceType;
691     if (code > 0) {
692         deviceType = value;
693     }
694     map<string, string> options;
695     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
696 
697     double number = -1;
698     string unit = "day";
699     string res = formatter->Format(number, unit);
700     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
701         EXPECT_EQ(res, "-1 j");
702     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
703         EXPECT_EQ(res, "il y a 1 jour");
704     } else {
705         EXPECT_EQ(res, "il y a 1 jour");
706     }
707     delete formatter;
708 }
709 
710 /**
711  * @tc.name: IntlFuncTest0066
712  * @tc.desc: Test datetime format default parameter
713  * @tc.type: FUNC
714  */
715 HWTEST_F(IntlTest, IntlFuncTest0066, TestSize.Level1)
716 {
717     int bufferLen = 10;
718     char value[bufferLen];
719     vector<string> locales;
720     locales.push_back("en-GB");
721     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
722     std::string deviceType;
723     if (code > 0) {
724         deviceType = value;
725     }
726     int64_t milliseconds = 987654321;
727 
728     map<string, string> defaultOptions;
729     std::unique_ptr<DateTimeFormat> defaultFormatter = DateTimeFormat::CreateInstance(locales, defaultOptions);
730     string defaultRes = defaultFormatter->Format(milliseconds);
731 
732     map<string, string> dateOptions = {
733         { "dateStyle", "auto" }
734     };
735     std::unique_ptr<DateTimeFormat> dateFormatter = DateTimeFormat::CreateInstance(locales, dateOptions);
736     string dateRes = dateFormatter->Format(milliseconds);
737 
738     map<string, string> timeOptions = {
739         { "timeStyle", "auto" }
740     };
741     std::unique_ptr<DateTimeFormat> timeFormatter = DateTimeFormat::CreateInstance(locales, timeOptions);
742     string timeRes = timeFormatter->Format(milliseconds);
743 
744     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
745         EXPECT_EQ(defaultRes, "12/01/1970");
746         EXPECT_EQ(dateRes, "12/01/1970");
747         EXPECT_EQ(timeRes, "06:20");
748     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
749         EXPECT_EQ(defaultRes, "12 Jan 1970");
750         EXPECT_EQ(dateRes, "12 Jan 1970");
751         EXPECT_EQ(timeRes, "06:20:54");
752     } else {
753         EXPECT_EQ(defaultRes, "12/01/1970");
754         EXPECT_EQ(dateRes, "12/01/1970");
755         EXPECT_EQ(timeRes, "06:20");
756     }
757 }
758 
759 /**
760  * @tc.name: IntlFuncTest0067
761  * @tc.desc: Test datetime format default parameter
762  * @tc.type: FUNC
763  */
764 HWTEST_F(IntlTest, IntlFuncTest0067, TestSize.Level1)
765 {
766     int bufferLen = 10;
767     char value[bufferLen];
768     vector<string> locales;
769     locales.push_back("en-GB");
770     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
771     std::string deviceType;
772     if (code > 0) {
773         deviceType = value;
774     }
775     int64_t milliseconds = 987654321;
776 
777     map<string, string> monthOptions = {
778         { "month", "auto" }
779     };
780     std::unique_ptr<DateTimeFormat> monthFormatter = DateTimeFormat::CreateInstance(locales, monthOptions);
781     string monthRes = monthFormatter->Format(milliseconds);
782 
783     map<string, string> weekdayOptions = {
784         { "weekday", "auto" }
785     };
786     std::unique_ptr<DateTimeFormat> weekdayFormatter = DateTimeFormat::CreateInstance(locales, weekdayOptions);
787     string weekdayRes = weekdayFormatter->Format(milliseconds);
788 
789     map<string, string> eraOptions = {
790         { "year", "2-digit" },
791         { "era", "auto" }
792     };
793     std::unique_ptr<DateTimeFormat> eraFormatter = DateTimeFormat::CreateInstance(locales, eraOptions);
794     string eraRes = eraFormatter->Format(milliseconds);
795 
796     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
797         EXPECT_EQ(monthRes, "Jan");
798         EXPECT_EQ(weekdayRes, "Mon");
799         EXPECT_EQ(eraRes, "70 A");
800     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
801         EXPECT_EQ(monthRes, "January");
802         EXPECT_EQ(weekdayRes, "Monday");
803         EXPECT_EQ(eraRes, "70 Anno Domini");
804     } else {
805         EXPECT_EQ(monthRes, "Jan");
806         EXPECT_EQ(weekdayRes, "Mon");
807         EXPECT_EQ(eraRes, "70 AD");
808     }
809 }
810 
811 /**
812  * @tc.name: IntlFuncTest0068
813  * @tc.desc: Test datetime format default parameter
814  * @tc.type: FUNC
815  */
816 HWTEST_F(IntlTest, IntlFuncTest0068, TestSize.Level1)
817 {
818     int bufferLen = 10;
819     char value[bufferLen];
820     vector<string> locales;
821     locales.push_back("fr-FR");
822     int code = GetParameter("const.product.devicetype", "", value, bufferLen);
823     std::string deviceType;
824     if (code > 0) {
825         deviceType = value;
826     }
827     int64_t milliseconds = 987654321;
828 
829     map<string, string> dayPeriodOptions = {
830         { "hour", "numeric" },
831         { "hourCycle", "h12" },
832         { "dayPeriod", "auto" },
833         { "timeZone", "UTC" }
834     };
835     std::unique_ptr<DateTimeFormat> dayPeriodFormatter = DateTimeFormat::CreateInstance(locales, dayPeriodOptions);
836     string dayPeriodRes = dayPeriodFormatter->Format(milliseconds);
837 
838     map<string, string> timeZoneNameOptions = {
839         { "hour", "2-digit" },
840         { "timeZoneName", "auto" }
841     };
842     std::unique_ptr<DateTimeFormat> timeZoneNameFormatter
843         = DateTimeFormat::CreateInstance(locales, timeZoneNameOptions);
844     string timeZoneNameRes = timeZoneNameFormatter->Format(milliseconds);
845 
846     if (deviceType == "wearable" || deviceType == "liteWearable" || deviceType == "watch") {
847         EXPECT_EQ(dayPeriodRes, "10 mat.");
848         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
849     } else if (deviceType == "tablet" || deviceType == "2in1" || deviceType == "tv" || deviceType == "pc") {
850         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAF" "du matin");
851         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM heure normale de la Chine");
852     } else {
853         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAFmatin");
854         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
855     }
856 }
857 
858 /**
859  * @tc.name: IntlFuncTest0069
860  * @tc.desc: Test number format unitUsage
861  * @tc.type: FUNC
862  */
863 HWTEST_F(IntlTest, IntlFuncTest0069, TestSize.Level1)
864 {
865     std::string locale = "&&%";
866     DateTimeSequence::GetDateOrder(locale);
867     trim(locale);
868     const std::string destPath = "/data/log/copy.txt";
869     EXPECT_TRUE(IsLegalPath(destPath));
870     const std::string relativePath = "../log/copy.txt";
871     EXPECT_FALSE(IsLegalPath(relativePath));
872     const char* dirPath = "/data/log";
873     EXPECT_TRUE(IsDirExist(dirPath));
874 }
875 
876 /**
877  * @tc.name: IntlFuncTest0070
878  * @tc.desc: Test Merge
879  * @tc.type: FUNC
880  */
881 HWTEST_F(IntlTest, IntlFuncTest0070, TestSize.Level1)
882 {
883     std::vector<std::string> resultVec;
884     const std::string separator = ",";
885     std::string source;
886     Merge(resultVec, separator, source);
887     EXPECT_EQ(source, "");
888 }
889 
890 /**
891  * @tc.name: IntlFuncTest0071
892  * @tc.desc: Test number format unitUsage
893  * @tc.type: FUNC
894  */
895 HWTEST_F(IntlTest, IntlFuncTest0071, TestSize.Level1)
896 {
897     std::string path = "/data/log/faultlog";
898     char delimiter = '\0';
899     const std::string localeStr = "ar";
900     std::shared_ptr<LocaleInfo> localeInfo = std::make_shared<LocaleInfo>(localeStr);
901     std::string errorCode;
902     std::string res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
903     EXPECT_EQ(res, path);
904     delimiter = '/';
905     res = LocaleConfig::GetUnicodeWrappedFilePath("", delimiter, localeInfo, errorCode);
906     EXPECT_EQ(res, "");
907     std::shared_ptr<LocaleInfo> invalidLocale = std::make_shared<LocaleInfo>("@@@");
908     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, invalidLocale, errorCode);
909     EXPECT_EQ(res, path);
910     std::shared_ptr<LocaleInfo> zhLocale = std::make_shared<LocaleInfo>("zh-Hans");
911     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, invalidLocale, errorCode);
912     EXPECT_EQ(res, path);
913     path = "data-log-faultlog";
914     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
915     EXPECT_EQ(res, path);
916 }
917 
918 /**
919  * @tc.name: IntlFuncTest0072
920  * @tc.desc: Test date order
921  * @tc.type: FUNC
922  */
923 HWTEST_F(IntlTest, IntlFuncTest0072, TestSize.Level1)
924 {
925     std::string locale = "en-GB";
926     std::string result = DateTimeSequence::GetDateOrder(locale);
927     EXPECT_EQ(result, "d-LLL-y");
928     locale = "zh-Hans";
929     result = DateTimeSequence::GetDateOrder(locale);
930     EXPECT_EQ(result, "y-L-d");
931     locale = "bo-CN";
932     result = DateTimeSequence::GetDateOrder(locale);
933     EXPECT_EQ(result, "y-LLL-d");
934     locale = "zh-Hant";
935     result = DateTimeSequence::GetDateOrder(locale);
936     EXPECT_EQ(result, "y-L-d");
937     locale = "ug";
938     result = DateTimeSequence::GetDateOrder(locale);
939     EXPECT_EQ(result, "L-d-y");
940     std::string localeBg = "bg-BG";
941     DateTimeSequence::GetDateOrder(localeBg);
942 }
943 
944 /**
945  * @tc.name: IntlFuncTest0073
946  * @tc.desc: Test PhoneNumberFormat.format()
947  * @tc.type: FUNC
948  */
949 HWTEST_F(IntlTest, IntlFuncTest0073, TestSize.Level1)
950 {
951     map<string, string> options = {
952         { "type", "TYPING" }
953     };
954     std::unique_ptr<PhoneNumberFormat> phoneNumFmt =
955         std::make_unique<PhoneNumberFormat>("zh-CN", options);
956     std::string number = "186223500";
957     std::string formated = "";
958     for (char c : number) {
959         formated = formated + c;
960         formated = phoneNumFmt->format(formated);
961     }
962     EXPECT_EQ(formated, "186 2235 00");
963     number = "186223500102933884747757758585885858854774";
964     phoneNumFmt->format(number);
965     number = "(020) 6355";
966     phoneNumFmt->format(number);
967     number = "123";
968     phoneNumFmt->format(number);
969     number = "2134";
970     phoneNumFmt->format(number);
971 
972     formated = "";
973     number = "075576453";
974     for (char c : number) {
975         formated = formated + c;
976         formated = phoneNumFmt->format(formated);
977     }
978     EXPECT_EQ(formated, "0755 7645 3");
979 
980     std::unique_ptr<PhoneNumberFormat> phoneNumFmt2 =
981         std::make_unique<PhoneNumberFormat>("AD", options);
982     formated = "";
983     number = "7123945";
984     for (char c : number) {
985         if (c == '4') {
986             formated = formated.substr(0, formated.length() - 1);
987             formated = phoneNumFmt->format(formated);
988         }
989         formated = formated + c;
990         formated = phoneNumFmt->format(formated);
991     }
992     EXPECT_EQ(formated, "712 345");
993     PhoneNumberFormat::CloseDynamicHandler();
994 }
995 
996 /**
997  * @tc.name: IntlFuncTest0074
998  * @tc.desc: Test LocaleMatcher
999  * @tc.type: FUNC
1000  */
1001 HWTEST_F(IntlTest, IntlFuncTest0074, TestSize.Level1)
1002 {
1003     const LocaleInfo* other = new LocaleInfo("fil");
1004     LocaleMatcher::IsMoreSuitable(nullptr, other, nullptr);
1005     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, nullptr);
1006     const LocaleInfo* request = new LocaleInfo("en-Qaag-GB");
1007     std::unique_ptr<LocaleInfo> currentHE = std::make_unique<LocaleInfo>("he");
1008     std::unique_ptr<LocaleInfo> otherIW = std::make_unique<LocaleInfo>("iw");
1009     LocaleMatcher::IsMoreSuitable(currentHE.get(), otherIW.get(), request);
1010     const LocaleInfo* currentTL = new LocaleInfo("tl");
1011     LocaleMatcher::IsMoreSuitable(currentTL, other, request);
1012     LocaleMatcher::IsMoreSuitable(other, currentTL, request);
1013     const LocaleInfo* currentJI = new LocaleInfo("ji");
1014     const LocaleInfo* otherYI = new LocaleInfo("yi");
1015     LocaleMatcher::IsMoreSuitable(currentJI, otherYI, request);
1016     LocaleMatcher::IsMoreSuitable(otherYI, currentJI, request);
1017     std::unique_ptr<LocaleInfo> currentJW = std::make_unique<LocaleInfo>("jw");
1018     std::unique_ptr<LocaleInfo> otherJV = std::make_unique<LocaleInfo>("jv");
1019     LocaleMatcher::IsMoreSuitable(currentJW.get(), otherJV.get(), request);
1020     LocaleMatcher::IsMoreSuitable(otherJV.get(), currentJW.get(), request);
1021     const LocaleInfo* currentIN = new LocaleInfo("in-PH");
1022     const LocaleInfo* otherID = new LocaleInfo("id-MY");
1023     LocaleMatcher::IsMoreSuitable(currentIN, otherID, request);
1024     LocaleMatcher::IsMoreSuitable(otherID, currentIN, request);
1025     LocaleMatcher::IsMoreSuitable(nullptr, currentIN, request);
1026     LocaleMatcher::IsMoreSuitable(currentIN, nullptr, request);
1027     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, request);
1028     const LocaleInfo* enLatn = new LocaleInfo("en-Latn-US");
1029     LocaleMatcher::Match(request, enLatn);
1030     std::unique_ptr<LocaleInfo> otherIN = std::make_unique<LocaleInfo>("in-MY");
1031     LocaleMatcher::Match(currentIN, otherIN.get());
1032     LocaleMatcher::Match(currentIN, nullptr);
1033     std::unique_ptr<LocaleInfo> newRequest = std::make_unique<LocaleInfo>("en-Latn");
1034     std::unique_ptr<LocaleInfo> currentEn = std::make_unique<LocaleInfo>("en-GB");
1035     std::unique_ptr<LocaleInfo> otherEn = std::make_unique<LocaleInfo>("en-US");
1036     int8_t result = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), newRequest.get());
1037     LocaleMatcher::Match(enLatn, currentEn.get());
1038     EXPECT_EQ(result, -1);
1039     delete other;
1040     delete request;
1041     delete currentTL;
1042     delete currentJI;
1043     delete otherYI;
1044     delete currentIN;
1045     delete otherID;
1046     delete enLatn;
1047 }
1048 
1049 /**
1050  * @tc.name: IntlFuncTest0075
1051  * @tc.desc: Test RulesEngine
1052  * @tc.type: FUNC
1053  */
1054 HWTEST_F(IntlTest, IntlFuncTest0075, TestSize.Level1)
1055 {
1056     using testing::_;
1057     DateTimeRule* dateTimeRule = nullptr;
1058     std::unordered_map<std::string, std::string> rulesMap = {};
1059     std::unordered_map<std::string, std::string> subRules = {};
1060     std::unordered_map<std::string, std::string> param = {};
1061     std::unordered_map<std::string, std::string> paramBackup = {};
1062     RulesSet rulesSet(rulesMap, subRules, param, paramBackup);
1063     RulesEngine rulesEngine(dateTimeRule, rulesSet);
1064 
1065     std::string str = "abc123";
1066     icu::UnicodeString message(str.c_str());
1067     std::string locale = "en";
1068     std::unique_ptr<DateTimeRule> dtRule = std::make_unique<DateTimeRule>(locale);
1069     ASSERT_TRUE(dtRule != nullptr);
1070     MockRulesEngine ruleEngineMock(dtRule.get(), rulesSet);
1071     EXPECT_CALL(ruleEngineMock, IsRegexPatternInvalid(_))
1072     .WillRepeatedly(Return(true));
1073     std::vector<MatchedDateTimeInfo> matches = ruleEngineMock.Match(message);
1074     EXPECT_EQ(matches.size(), 0);
1075 
1076     MockRulesEngine ruleEngineMock2(dtRule.get(), rulesSet);
1077     EXPECT_CALL(ruleEngineMock2, IsRegexMatcherInvalid(_))
1078     .WillRepeatedly(Return(true));
1079     matches = ruleEngineMock2.Match(message);
1080     EXPECT_EQ(matches.size(), 0);
1081 }
1082 
1083 /**
1084  * @tc.name: IntlFuncTest0076
1085  * @tc.desc: Test RulesEngine
1086  * @tc.type: FUNC
1087  */
1088 HWTEST_F(IntlTest, IntlFuncTest0076, TestSize.Level1)
1089 {
1090     i18n::phonenumbers::PhoneNumber phoneNumber;
1091     size_t start = 10;
1092     std::string rawStr = "1 800 234 45 67";
1093     std::unique_ptr<PhoneNumberMatch> possibleNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1094     icu::UnicodeString regex;
1095     std::string handleType = "Operator";
1096     std::string insensitive = "True";
1097     std::unique_ptr<PositiveRule> pRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1098     icu::RegexPattern* regexP = pRule->GetPattern();
1099     std::string msg = "(0075 665";
1100     icu::UnicodeString message(msg.c_str());
1101     std::vector<MatchedNumberInfo> vector = pRule->HandleInner(possibleNumber.get(), message);
1102     handleType = "EndWithMobile";
1103     std::unique_ptr<PositiveRule> pRule2 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1104     vector = pRule2->HandleInner(possibleNumber.get(), message);
1105     vector = pRule2->Handle(possibleNumber.get(), message);
1106     handleType = "default";
1107     std::unique_ptr<PositiveRule> pRule3 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1108     vector = pRule3->HandleInner(possibleNumber.get(), message);
1109     vector = pRule3->Handle(possibleNumber.get(), message);
1110     rawStr = "(1 800 234 45 67";
1111     std::unique_ptr<PhoneNumberMatch> posbNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1112     vector = pRule3->Handle(posbNumber.get(), message);
1113     EXPECT_EQ(vector.size(), 1);
1114     delete regexP;
1115 
1116     EXPECT_FALSE(IsDirExist(nullptr));
1117     std::string strForTrim;
1118     EXPECT_EQ(trim(strForTrim), "");
1119     bool copyResult = FileCopy("/data/123/abc.txt", "/data/456/abc.txt");
1120     EXPECT_FALSE(copyResult);
1121 }
1122 
1123 /**
1124  * @tc.name: IntlFuncTest0077
1125  * @tc.desc: Test RegexRule
1126  * @tc.type: FUNC
1127  */
1128 HWTEST_F(IntlTest, IntlFuncTest0077, TestSize.Level1)
1129 {
1130     using namespace i18n::phonenumbers;
1131     std::string regexStr = "\\d{3}";
1132     icu::UnicodeString regex(regexStr.c_str());
1133     std::string isValidType = "Default";
1134     std::string handleType = "Operator";
1135     std::string insensitive = "False";
1136     std::string type = "xxx";
1137     icu::UnicodeString message(type.c_str());
1138 
1139     i18n::phonenumbers::PhoneNumber phoneNumber;
1140     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1141     std::string input = "(010)86753564";
1142     std::string country = "CN";
1143     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
1144     size_t start = 10;
1145     std::string rawString = "1 800 234 45 67";
1146     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1147         std::make_unique<PhoneNumberMatch>(start, rawString, phoneNumber);
1148     std::unique_ptr<RegexRule> regexRule =
1149         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1150     ASSERT_TRUE(possibleNumber != nullptr);
1151     PhoneNumberMatch* phoneNumMatch = regexRule->IsValid(possibleNumber.get(), message);
1152     if (phoneNumMatch != nullptr) {
1153         std::vector<MatchedNumberInfo> list = regexRule->Handle(phoneNumMatch, message);
1154         EXPECT_EQ(list.size(), 1);
1155     }
1156 }
1157 
1158 /**
1159  * @tc.name: IntlFuncTest0078
1160  * @tc.desc: Test CodeRule
1161  * @tc.type: FUNC
1162  */
1163 HWTEST_F(IntlTest, IntlFuncTest0078, TestSize.Level1)
1164 {
1165     std::string isValidType = "Default";
1166     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1167     std::string msg = "00222a-1 800 234 45 670A-";
1168     icu::UnicodeString message(msg.c_str());
1169     i18n::phonenumbers::PhoneNumber phoneNumber;
1170     size_t start = 7;
1171     std::string rawStr = "1 800 234 45 67";
1172     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1173         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1174     ASSERT_TRUE(possibleNumber != nullptr);
1175     codeRule->IsValid(possibleNumber.get(), message);
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     ASSERT_TRUE(possibleNumber != nullptr);
1198     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1199     EXPECT_TRUE(match != nullptr);
1200 }
1201 
1202 /**
1203  * @tc.name: IntlFuncTest0080
1204  * @tc.desc: Test RegexRule
1205  * @tc.type: FUNC
1206  */
1207 HWTEST_F(IntlTest, IntlFuncTest0080, TestSize.Level1)
1208 {
1209     using namespace i18n::phonenumbers;
1210     std::string regexStr = "\\d{3}";
1211     icu::UnicodeString regex(regexStr.c_str());
1212     std::string isValidType = "Default";
1213     std::string handleType = "Operator";
1214     std::string insensitive = "True";
1215     std::string type = "xxx";
1216     std::string input = "(010)86753564";
1217     size_t start = 10;
1218     std::string rawStr = "1 800 234 45 67";
1219     i18n::phonenumbers::PhoneNumber phoneNumber;
1220     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1221         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1222     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1223     std::unique_ptr<icu::RegexPattern> regexPattern =
1224         std::unique_ptr<icu::RegexPattern>(regexRule->GetPattern());
1225     std::string msg = "00222a-86753564A-";
1226     icu::UnicodeString message(msg.c_str());
1227     ASSERT_TRUE(possibleNumber != nullptr);
1228     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1229     EXPECT_EQ(list.size(), 1);
1230     delete regexRule;
1231 }
1232 
1233 /**
1234  * @tc.name: IntlFuncTest0081
1235  * @tc.desc: Test RegexRule
1236  * @tc.type: FUNC
1237  */
1238 HWTEST_F(IntlTest, IntlFuncTest0081, TestSize.Level1)
1239 {
1240     using namespace i18n::phonenumbers;
1241     std::string regexStr = "\\d{3}";
1242     icu::UnicodeString regex(regexStr.c_str());
1243     std::string isValidType = "PreSuf";
1244     std::string handleType = "Blank";
1245     std::string insensitive = "False";
1246     std::string type = "xxx";
1247     std::string input = "(010)86753564";
1248     size_t start = 0;
1249     std::string rawStr = "1 800 234 45 67";
1250     i18n::phonenumbers::PhoneNumber phoneNumber;
1251     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1252         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1253     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1254     std::string msg = "00222a-86753564A-";
1255     icu::UnicodeString message(msg.c_str());
1256     ASSERT_TRUE(possibleNumber != nullptr);
1257     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1258     EXPECT_EQ(list.size(), 1);
1259     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1260     EXPECT_TRUE(match != nullptr);
1261     PhoneNumberMatch* match2 = regexRule->IsValid(nullptr, message);
1262     EXPECT_TRUE(match2 == nullptr);
1263     rawStr = "5201314";
1264     std::unique_ptr<PhoneNumberMatch> possibleNum =
1265         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1266     ASSERT_TRUE(possibleNum != nullptr);
1267     std::vector<MatchedNumberInfo> list2 = regexRule->Handle(possibleNum.get(), message);
1268     EXPECT_EQ(list2.size(), 0);
1269     delete regexRule;
1270 }
1271 
1272 /**
1273  * @tc.name: IntlFuncTest0082
1274  * @tc.desc: Test RegexRule
1275  * @tc.type: FUNC
1276  */
1277 HWTEST_F(IntlTest, IntlFuncTest0082, TestSize.Level1)
1278 {
1279     using namespace i18n::phonenumbers;
1280     std::string regexStr = "\\d{3}";
1281     icu::UnicodeString regex(regexStr.c_str());
1282     std::string isValidType = "Code";
1283     std::string handleType = "Slant";
1284     std::string insensitive = "False";
1285     std::string type = "xxx";
1286     std::string input = "(010)120/110";
1287     size_t start = 10;
1288     i18n::phonenumbers::PhoneNumber phoneNumber;
1289     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1290         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1291     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1292     std::string msg = "00222a-86753564A-";
1293     icu::UnicodeString message(msg.c_str());
1294     ASSERT_TRUE(possibleNumber != nullptr);
1295     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1296     EXPECT_EQ(list.size(), 1);
1297     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1298     EXPECT_TRUE(match != nullptr);
1299     delete regexRule;
1300 }
1301 
1302 /**
1303  * @tc.name: IntlFuncTest0083
1304  * @tc.desc: Test RegexRule
1305  * @tc.type: FUNC
1306  */
1307 HWTEST_F(IntlTest, IntlFuncTest0083, TestSize.Level1)
1308 {
1309     using namespace i18n::phonenumbers;
1310     std::string regexStr = "\\d{3}";
1311     icu::UnicodeString regex(regexStr.c_str());
1312     std::string isValidType = "PreSuf";
1313     std::string handleType = "StartWithMobile";
1314     std::string insensitive = "False";
1315     std::string type = "xxx";
1316     std::string input = "86753564";
1317     size_t start = 0;
1318     i18n::phonenumbers::PhoneNumber phoneNumber;
1319     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1320         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1321     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1322     std::string msg = "86753564a-";
1323     icu::UnicodeString message(msg.c_str());
1324     ASSERT_TRUE(possibleNumber != nullptr);
1325     regexRule->IsValid(possibleNumber.get(), message);
1326     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1327     EXPECT_EQ(list.size(), 0);
1328     msg = "86753564A1";
1329     icu::UnicodeString message2(msg.c_str());
1330     PhoneNumberMatch* match2 = regexRule->IsValid(possibleNumber.get(), message2);
1331     EXPECT_TRUE(match2 == nullptr);
1332     msg = "86753564Aa";
1333     icu::UnicodeString message3(msg.c_str());
1334     PhoneNumberMatch* match3 = regexRule->IsValid(possibleNumber.get(), message3);
1335     EXPECT_TRUE(match3 != nullptr);
1336     msg = "86753564AA-";
1337     icu::UnicodeString message4(msg.c_str());
1338     PhoneNumberMatch* match4 = regexRule->IsValid(possibleNumber.get(), message4);
1339     EXPECT_TRUE(match4 != nullptr);
1340     msg = "86753564AA2";
1341     icu::UnicodeString message5(msg.c_str());
1342     PhoneNumberMatch* match5 = regexRule->IsValid(possibleNumber.get(), message5);
1343     EXPECT_TRUE(match5 == nullptr);
1344     msg = "86753564AA@";
1345     icu::UnicodeString message6(msg.c_str());
1346     PhoneNumberMatch* match6 = regexRule->IsValid(possibleNumber.get(), message6);
1347     EXPECT_TRUE(match6 == nullptr);
1348     msg = "86753564AAc";
1349     icu::UnicodeString message7(msg.c_str());
1350     PhoneNumberMatch* match7 = regexRule->IsValid(possibleNumber.get(), message7);
1351     EXPECT_TRUE(match7 != nullptr);
1352     delete regexRule;
1353 }
1354 
1355 /**
1356  * @tc.name: IntlFuncTest0084
1357  * @tc.desc: Test RegexRule
1358  * @tc.type: FUNC
1359  */
1360 HWTEST_F(IntlTest, IntlFuncTest0084, TestSize.Level1)
1361 {
1362     using namespace i18n::phonenumbers;
1363     std::string regexStr = "\\d{3}";
1364     icu::UnicodeString regex(regexStr.c_str());
1365     std::string isValidType = "Default";
1366     std::string handleType = "Default";
1367     std::string insensitive = "False";
1368     std::string type = "xxx";
1369     std::string input = "(010)86753564";
1370     size_t start = 10;
1371     i18n::phonenumbers::PhoneNumber phoneNumber;
1372     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1373         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1374     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1375     std::string msg = "00222a-86753564A-";
1376     icu::UnicodeString message(msg.c_str());
1377     ASSERT_TRUE(possibleNumber != nullptr);
1378     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1379     EXPECT_EQ(list.size(), 1);
1380     delete regexRule;
1381 }
1382 
1383 /**
1384  * @tc.name: IntlFuncTest0085
1385  * @tc.desc: Test BorderRule
1386  * @tc.type: FUNC
1387  */
1388 HWTEST_F(IntlTest, IntlFuncTest0085, TestSize.Level1)
1389 {
1390     using namespace i18n::phonenumbers;
1391     std::string str = "\\d+";
1392     icu::UnicodeString regex(str.c_str());
1393     std::string insensitive = "False";
1394     std::string type = "CONTAIN_OR_INTERSECT";
1395     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1396     icu::RegexPattern* regexPattern = borderRule->GetPattern();
1397     std::string msg = "2222U-(010)86753564a-hha";
1398     std::string input = "(010)86753564";
1399     size_t start = 6;
1400     i18n::phonenumbers::PhoneNumber phoneNumber;
1401     icu::UnicodeString message(msg.c_str());
1402     std::unique_ptr<PhoneNumberMatch> match =
1403         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1404     bool flag = borderRule->Handle(match.get(), message);
1405     EXPECT_TRUE(flag);
1406 
1407     type = "CONTAIN";
1408     std::unique_ptr<BorderRule> bRule = std::make_unique<BorderRule>(regex, insensitive, type);
1409     flag = bRule->Handle(match.get(), message);
1410     EXPECT_TRUE(flag);
1411     delete regexPattern;
1412 }
1413 
1414 /**
1415  * @tc.name: IntlFuncTest0086
1416  * @tc.desc: Test BorderRule
1417  * @tc.type: FUNC
1418  */
1419 HWTEST_F(IntlTest, IntlFuncTest0086, TestSize.Level1)
1420 {
1421     using namespace i18n::phonenumbers;
1422     std::string str = "\\d+";
1423     icu::UnicodeString regex(str.c_str());
1424     std::string insensitive = "False";
1425     std::string type = "xx@@";
1426     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1427     icu::UnicodeString newRegex;
1428     insensitive = "True";
1429     std::unique_ptr<FindRule> findRule = std::make_unique<FindRule>(newRegex, insensitive);
1430     icu::RegexPattern* regexPattern = findRule->GetPattern();
1431     EXPECT_TRUE(regexPattern != nullptr);
1432     delete regexPattern;
1433     std::string emptyStr = "";
1434     icu::UnicodeString emptyRegex(emptyStr.c_str());
1435     std::unique_ptr<BorderRule> emptyBorderRule =
1436         std::make_unique<BorderRule>(emptyRegex, insensitive, type);
1437 }
1438 
1439 /**
1440  * @tc.name: IntlFuncTest0087
1441  * @tc.desc: Test LocaleMatcher
1442  * @tc.type: FUNC
1443  */
1444 HWTEST_F(IntlTest, IntlFuncTest0087, TestSize.Level1)
1445 {
1446     const std::unique_ptr<LocaleInfo> request = std::make_unique<LocaleInfo>("en-Qaag-GB");
1447     const std::unique_ptr<LocaleInfo> enLatn = std::make_unique<LocaleInfo>("en-US");
1448     LocaleMatcher::Match(request.get(), enLatn.get());
1449     std::vector<LocaleInfo*> candidateLocales;
1450     LocaleInfo* locale0 = new LocaleInfo("en-US");
1451     LocaleInfo* locale1 = new LocaleInfo("en-Qaag-US");
1452     LocaleInfo* locale2 = new LocaleInfo("en-Latn-GB");
1453     LocaleInfo* locale3 = new LocaleInfo("en");
1454     candidateLocales.push_back(locale0);
1455     candidateLocales.push_back(locale1);
1456     candidateLocales.push_back(locale2);
1457     candidateLocales.push_back(locale3);
1458     std::string bestMatch = LocaleMatcher::GetBestMatchedLocale(request.get(), candidateLocales);
1459     EXPECT_EQ(bestMatch, "en-Latn-GB");
1460     delete locale0;
1461     delete locale1;
1462     delete locale2;
1463     delete locale3;
1464 }
1465 
1466 /**
1467  * @tc.name: IntlFuncTest0088
1468  * @tc.desc: Test SignatureVerifier
1469  * @tc.type: FUNC
1470  */
1471 HWTEST_F(IntlTest, IntlFuncTest0088, TestSize.Level1)
1472 {
1473     std::string localVersionPath = "/data/log/local_version.txt";
1474     std::string updateVersionPath = "/data/log/update_version.txt";
1475     std::string localVersionContent = "version=1.0.24.100";
1476     std::string updateVersionContent = "version=1.0.24.101";
1477     IcsFileWriter icsFileWriter;
1478     bool status = icsFileWriter.WriteFile(localVersionContent, localVersionPath);
1479     ASSERT_TRUE(status);
1480     status = icsFileWriter.WriteFile(updateVersionContent, updateVersionPath);
1481     ASSERT_TRUE(status);
1482     bool isNecessary = UpgradeUtils::CheckIfUpdateNecessary(updateVersionPath, localVersionPath);
1483     ASSERT_TRUE(isNecessary);
1484 }
1485 
1486 /**
1487  * @tc.name: IntlFuncTest0089
1488  * @tc.desc: Test CodeRule
1489  * @tc.type: FUNC
1490  */
1491 HWTEST_F(IntlTest, IntlFuncTest0089, TestSize.Level1)
1492 {
1493     std::string isValidType = "PreSuf";
1494     std::string msg = "1 800 234 45 67a-";
1495     icu::UnicodeString message(msg.c_str());
1496     i18n::phonenumbers::PhoneNumber phoneNumber;
1497     size_t start = 0;
1498     std::string rawStr = "1 800 234 45 67";
1499     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1500         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1501     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1502     if (possibleNumber != nullptr) {
1503         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1504         EXPECT_TRUE(match != nullptr);
1505         msg = "1 800 234 45 67A1";
1506         icu::UnicodeString message2(msg.c_str());
1507         PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1508         EXPECT_TRUE(match2 == nullptr);
1509         msg = "1 800 234 45 67Aa";
1510         icu::UnicodeString message3(msg.c_str());
1511         PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1512         EXPECT_TRUE(match3 != nullptr);
1513         msg = "1 800 234 45 67AA-";
1514         icu::UnicodeString message4(msg.c_str());
1515         PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1516         EXPECT_TRUE(match4 != nullptr);
1517         msg = "1 800 234 45 67AA2";
1518         icu::UnicodeString message5(msg.c_str());
1519         PhoneNumberMatch* match5 = codeRule->IsValid(possibleNumber.get(), message5);
1520         EXPECT_TRUE(match5 == nullptr);
1521         msg = "1 800 234 45 67AA@";
1522         icu::UnicodeString message6(msg.c_str());
1523         PhoneNumberMatch* match6 = codeRule->IsValid(possibleNumber.get(), message6);
1524         EXPECT_TRUE(match6 == nullptr);
1525         msg = "1 800 234 45 67AAc";
1526         icu::UnicodeString message7(msg.c_str());
1527         PhoneNumberMatch* match7 = codeRule->IsValid(possibleNumber.get(), message7);
1528         EXPECT_TRUE(match7 != nullptr);
1529     }
1530     PhoneNumberMatch* match8 = codeRule->Handle(nullptr, message);
1531     EXPECT_TRUE(match8 == nullptr);
1532 }
1533 
1534 /**
1535  * @tc.name: IntlFuncTest0090
1536  * @tc.desc: Test CodeRule
1537  * @tc.type: FUNC
1538  */
1539 HWTEST_F(IntlTest, IntlFuncTest0090, TestSize.Level1)
1540 {
1541     std::string isValidType = "Code";
1542     std::string msg = "00222a-1 800 234 45 67A-";
1543     icu::UnicodeString message(msg.c_str());
1544     i18n::phonenumbers::PhoneNumber phoneNumber;
1545     size_t start = 10;
1546     std::string rawStr = "[17777]8;ext=123";
1547     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1548         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1549     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1550     if (possibleNumber != nullptr) {
1551         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1552         EXPECT_TRUE(match == nullptr);
1553         PhoneNumberMatch* match2 = codeRule->IsValid(nullptr, message);
1554         EXPECT_TRUE(match2 == 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 = "--a86753564";
1763     icu::UnicodeString message(msg.c_str());
1764     i18n::phonenumbers::PhoneNumber phoneNumber;
1765     size_t start = 3;
1766     std::string rawStr = "86753564";
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     ASSERT_TRUE(possibleNumber != nullptr);
1772     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1773     EXPECT_TRUE(match != nullptr);
1774     msg = "a1A86753564";
1775     icu::UnicodeString message1(msg.c_str());
1776     regexRule->IsValid(possibleNumber.get(), message1);
1777     msg = "0aA86753564";
1778     icu::UnicodeString message2(msg.c_str());
1779     regexRule->IsValid(possibleNumber.get(), message2);
1780     msg = "-AA86753564";
1781     icu::UnicodeString message3(msg.c_str());
1782     regexRule->IsValid(possibleNumber.get(), message3);
1783     msg = "2AA86753564";
1784     icu::UnicodeString message4(msg.c_str());
1785     regexRule->IsValid(possibleNumber.get(), message4);
1786     msg = "@AA86753564";
1787     icu::UnicodeString message5(msg.c_str());
1788     regexRule->IsValid(possibleNumber.get(), message5);
1789     msg = "cAA86753564";
1790     icu::UnicodeString message6(msg.c_str());
1791     PhoneNumberMatch* match6 = regexRule->IsValid(possibleNumber.get(), message6);
1792     EXPECT_TRUE(match6 != nullptr);
1793     regexRule->Handle(possibleNumber.get(), message);
1794 }
1795 
1796 /**
1797  * @tc.name: IntlFuncTest0097
1798  * @tc.desc: Test Intl I18nCalendarMock
1799  * @tc.type: FUNC
1800  */
1801 HWTEST_F(IntlTest, IntlFuncTest0097, TestSize.Level1)
1802 {
1803     std::unique_ptr<I18nCalendarMock> calendarMock = std::make_unique<I18nCalendarMock>("zh-Hans-CN");
1804     EXPECT_CALL(*calendarMock, GetIcuCalendar())
1805     .WillRepeatedly(Return(nullptr));
1806 
1807     calendarMock->SetTime(1684742124645);
1808     calendarMock->Get(UCalendarDateFields::UCAL_YEAR);
1809     calendarMock->SetFirstDayOfWeek(-1);
1810     calendarMock->GetTimeInMillis();
1811 
1812     calendarMock->GetMinimalDaysInFirstWeek();
1813     int32_t minimalDaysInFirstWeek = calendarMock->GetMinimalDaysInFirstWeek();
1814     EXPECT_EQ(minimalDaysInFirstWeek, 1);
1815     int32_t firstDayOfWeek = calendarMock->GetFirstDayOfWeek();
1816     EXPECT_EQ(firstDayOfWeek, 1);
1817     calendarMock->Set(2023, 5, 28);
1818     UErrorCode status = U_ZERO_ERROR;
1819     calendarMock->IsWeekend(168473854645, status);
1820     calendarMock->CompareDays(1684742124650);
1821     bool isWeekend = calendarMock->IsWeekend();
1822     EXPECT_FALSE(isWeekend);
1823     std::string localeTag = "en";
1824     std::string displayName = calendarMock->GetDisplayName(localeTag);
1825     EXPECT_EQ(displayName, "");
1826 }
1827 
1828 /**
1829  * @tc.name: IntlFuncTest0098
1830  * @tc.desc: Test Intl multi users
1831  * @tc.type: FUNC
1832  */
1833 HWTEST_F(IntlTest, IntlFuncTest0098, TestSize.Level1)
1834 {
1835 #ifdef SUPPORT_MULTI_USER
1836     std::string path = "/data/service/el1/public/i18n/global/GlobalParamData";
1837     OHOS::NativePreferences::Options opt(path);
1838     int status;
1839     std::shared_ptr<NativePreferences::Preferences> preferences =
1840         NativePreferences::PreferencesHelper::GetPreferences(opt, status);
1841     MultiUsers::AddUser("101");
1842     MultiUsers::SwitchUser("101");
1843     MultiUsers::RemoveUser("100");
1844     if (preferences != nullptr) {
1845         std::string language = preferences->GetString("languageData", "");
1846         std::string locale = preferences->GetString("localeData", "");
1847         std::string is24Hour = preferences->GetString("is24HourData", "");
1848         EXPECT_EQ(language, "101:zh-Hans");
1849         EXPECT_EQ(locale, "101:zh-Hans-CN");
1850         EXPECT_EQ(is24Hour, "101:false");
1851     }
1852     MultiUsers::RemoveUser("101");
1853     if (preferences != nullptr) {
1854         std::string language = preferences->GetString("languageData", "");
1855         std::string locale = preferences->GetString("localeData", "");
1856         std::string is24Hour = preferences->GetString("is24HourData", "");
1857         EXPECT_EQ(language, "");
1858         EXPECT_EQ(locale, "");
1859         EXPECT_EQ(is24Hour, "");
1860     }
1861 #endif
1862 }
1863 
1864 /**
1865  * @tc.name: IntlFuncTest0099
1866  * @tc.desc: Test CodeRule
1867  * @tc.type: FUNC
1868  */
1869 HWTEST_F(IntlTest, IntlFuncTest0099, TestSize.Level1)
1870 {
1871     std::string isValidType = "PreSuf";
1872     std::string msg = "1 800 234 45";
1873     icu::UnicodeString message(msg.c_str());
1874     i18n::phonenumbers::PhoneNumber phoneNumber;
1875     size_t start = 0;
1876     std::string rawStr = "1 800 234 45 67";
1877     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1878         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1879     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1880     ASSERT_TRUE(possibleNumber != nullptr);
1881     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1882     EXPECT_TRUE(match != nullptr);
1883 }
1884 
1885 /**
1886  * @tc.name: IntlFuncTest00100
1887  * @tc.desc: Test CodeRule
1888  * @tc.type: FUNC
1889  */
1890 HWTEST_F(IntlTest, IntlFuncTest00100, TestSize.Level1)
1891 {
1892     std::string isValidType = "PreSuf";
1893     std::string msg = "0ca1 800 234 45 67";
1894     icu::UnicodeString message(msg.c_str());
1895     i18n::phonenumbers::PhoneNumber phoneNumber;
1896     size_t start = 3;
1897     std::string rawStr = "1 800 234 45 67";
1898     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1899         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1900     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1901     ASSERT_TRUE(possibleNumber != nullptr);
1902     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1903     EXPECT_TRUE(match != nullptr);
1904     msg = "abA1 800 234 45 67";
1905     icu::UnicodeString message2(msg.c_str());
1906     PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1907     EXPECT_TRUE(match2 != nullptr);
1908     msg = "0aA1 800 234 45 67";
1909     icu::UnicodeString message3(msg.c_str());
1910     PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1911     EXPECT_TRUE(match3 != nullptr);
1912     msg = "-AA1 800 234 45 67";
1913     icu::UnicodeString message4(msg.c_str());
1914     PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1915     EXPECT_TRUE(match4 != nullptr);
1916     msg = "3AA1 800 234 45 67";
1917     icu::UnicodeString message5(msg.c_str());
1918     PhoneNumberMatch* match5 = codeRule->IsValid(possibleNumber.get(), message5);
1919     EXPECT_TRUE(match5 == nullptr);
1920     msg = "$AA1 800 234 45 67";
1921     icu::UnicodeString message6(msg.c_str());
1922     PhoneNumberMatch* match6 = codeRule->IsValid(possibleNumber.get(), message6);
1923     EXPECT_TRUE(match6 == nullptr);
1924     msg = "vAA1 800 234 45 67";
1925     icu::UnicodeString message7(msg.c_str());
1926     PhoneNumberMatch* match7 = codeRule->IsValid(possibleNumber.get(), message7);
1927     EXPECT_TRUE(match7 != nullptr);
1928 }
1929 
1930 /**
1931  * @tc.name: IntlFuncTest00101
1932  * @tc.desc: Test CodeRule
1933  * @tc.type: FUNC
1934  */
1935 HWTEST_F(IntlTest, IntlFuncTest00101, TestSize.Level1)
1936 {
1937     std::string isValidType = "Rawstr";
1938     std::string msg = "13649372A-";
1939     icu::UnicodeString message(msg.c_str());
1940     i18n::phonenumbers::PhoneNumber phoneNumber;
1941     size_t start = 0;
1942     std::string rawStr = "13649372;ext=123";
1943     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1944         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1945     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1946     ASSERT_TRUE(possibleNumber != nullptr);
1947     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1948     if (match != nullptr) {
1949         EXPECT_EQ(match->raw_string(), rawStr);
1950     }
1951     PhoneNumberMatch* match2 = codeRule->IsValid(nullptr, message);
1952     EXPECT_TRUE(match2 == nullptr);
1953     rawStr = "12345678";
1954     std::unique_ptr<PhoneNumberMatch> possibleNumber2 =
1955         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1956     ASSERT_TRUE(possibleNumber2 != nullptr);
1957     PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber2.get(), message);
1958     EXPECT_TRUE(match3 == nullptr);
1959 }
1960 
1961 /**
1962  * @tc.name: IntlFuncTest00102
1963  * @tc.desc: Test CodeRule
1964  * @tc.type: FUNC
1965  */
1966 HWTEST_F(IntlTest, IntlFuncTest00102, TestSize.Level1)
1967 {
1968     std::string isValidType = "Rawstr";
1969     std::string msg = "400A-";
1970     icu::UnicodeString message(msg.c_str());
1971     i18n::phonenumbers::PhoneNumber phoneNumber;
1972     size_t start = 0;
1973     std::string rawStr = "400";
1974     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1975         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1976     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1977     ASSERT_TRUE(possibleNumber != nullptr);
1978     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1979     EXPECT_TRUE(match == nullptr);
1980 }
1981 
1982 /**
1983  * @tc.name: IntlFuncTest00103
1984  * @tc.desc: Test RegexRule
1985  * @tc.type: FUNC
1986  */
1987 HWTEST_F(IntlTest, IntlFuncTest00103, TestSize.Level1)
1988 {
1989     using namespace i18n::phonenumbers;
1990     std::string regexStr = "\\d{3}";
1991     icu::UnicodeString regex(regexStr.c_str());
1992     std::string isValidType = "Rawstr";
1993     std::string insensitive = "False";
1994     std::string handleType = "EndWithMobile";
1995     std::string type = "xxx";
1996     std::string msg = "--a86753564";
1997     icu::UnicodeString message(msg.c_str());
1998     std::string rawStr = "10645656";
1999     size_t start = 0;
2000     i18n::phonenumbers::PhoneNumber phoneNumber2;
2001     std::unique_ptr<PhoneNumberMatch> possibleNum =
2002         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
2003     std::unique_ptr<RegexRule> regexRule2 =
2004         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
2005     ASSERT_TRUE(possibleNum != nullptr);
2006     PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
2007     EXPECT_TRUE(pnMatch == nullptr);
2008 
2009     isValidType = "Rawstr";
2010     rawStr = "119";
2011     start = 0;
2012     i18n::phonenumbers::PhoneNumber phoneNumber3;
2013     std::unique_ptr<PhoneNumberMatch> posibleNumber =
2014         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber3);
2015     std::unique_ptr<RegexRule> regexRule3 =
2016         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
2017     ASSERT_TRUE(posibleNumber != nullptr);
2018     PhoneNumberMatch* pMatch = regexRule3->IsValid(posibleNumber.get(), message);
2019     EXPECT_TRUE(pMatch == nullptr);
2020 }
2021 } // namespace I18n
2022 } // namespace Global
2023 } // namespace OHOS