• 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_TRUE(set0.size() > 400);
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     flag = LocaleConfig::IsSuggested("pt-Latn-PT");
554     EXPECT_FALSE(flag);
555     flag = LocaleConfig::IsSuggested("es-Latn-BR");
556     EXPECT_FALSE(flag);
557     flag = LocaleConfig::IsSuggested("es-Latn-419");
558     EXPECT_FALSE(flag);
559 }
560 
561 /**
562  * @tc.name: IntlFuncTest0062
563  * @tc.desc: Test Intl utils.cpp
564  * @tc.type: FUNC
565  */
566 HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1)
567 {
568     string emptyStr = "";
569     string sep = ";";
570     vector<string> dest;
571     std::unordered_set<std::string> allValidLocalesLanguageTag;
572     Split(emptyStr, sep, dest);
573     int32_t status = 0;
574     string numberStr = "12345678901234567890123456789012345678901234567890987654321";
575     ConvertString2Int(numberStr, status);
576     numberStr = "@#";
577     ConvertString2Int(numberStr, status);
578     icu::Locale locale("$$$$5%%%");
579     bool isValid = IsValidLocaleTag(locale);
580     EXPECT_TRUE(!isValid);
581     GetAllValidLocalesTag(allValidLocalesLanguageTag);
582     EXPECT_TRUE(allValidLocalesLanguageTag.size() == 0);
583     const std::string str = "zh_Hans_CN";
584     const std::string target = "-";
585     const std::string replace = "";
586     StrReplaceAll(str, target, replace);
587 
588     double a = 403.21;
589     double b = 403.2;
590     EXPECT_TRUE(Geq(a, b));
591     EXPECT_TRUE(Leq(b, a));
592 
593     std::string localeTag = "zh-Hans-CN";
594     std::string localeCode = LocaleEncode(localeTag);
595     std::string targetCode = "58400008334651000314";
596     EXPECT_EQ(localeCode, targetCode);
597     std::vector<std::string> resultVec = {"zh", "en", "fr", "de", "zh-Hant", "fil"};
598     const std::string separator = ",";
599     std::string source;
600     Merge(resultVec, separator, source);
601     EXPECT_EQ(source, "zh,en,fr,de,zh-Hant,fil");
602 
603     std::filesystem::path pathDir("/data/log/faultlog");
604     ClearDir(pathDir);
605 
606     std::string localeRule = "zh-Hans";
607     DateTimeRule* dateTimeRule = new DateTimeRule(localeRule);
608     DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule);
609     EXPECT_TRUE(dateTimeRule->GetPatternByKey("abc") == nullptr);
610     std::string key1 = "9000";
611     std::string key2 = "10000";
612     EXPECT_EQ(dateTimeRule->CompareLevel(key1, key2), 1);
613     delete dateTimeFilter;
614     delete dateTimeRule;
615 }
616 
617 /**
618  * @tc.name: IntlFuncTest0063
619  * @tc.desc: Test Intl RegexRule
620  * @tc.type: FUNC
621  */
622 HWTEST_F(IntlTest, IntlFuncTest0063, TestSize.Level1)
623 {
624     using namespace i18n::phonenumbers;
625     std::string regexStr = "[a-z]1?";
626     icu::UnicodeString regex(regexStr.c_str());
627     std::string isValidType = "PrexxxxSuf";
628     std::string handleType = "EndWithMobile";
629     std::string insensitive = "False";
630     std::string type = "xxx";
631     std::unique_ptr<RegexRule> regexRule = std::make_unique<RegexRule>(regex,
632         isValidType, handleType, insensitive, type);
633     handleType = "fake";
634     isValidType = "Code";
635     std::unique_ptr<RegexRule> regexRule2 = std::make_unique<RegexRule>(regex, isValidType,
636         handleType, insensitive, type);
637     icu::UnicodeString message(type.c_str());
638 
639     i18n::phonenumbers::PhoneNumber phoneNumber;
640     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
641     std::string input = "[010111111111111;ext=0782";
642     std::string country = "CN";
643     size_t size = input.length();
644     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
645     std::unique_ptr<PhoneNumberMatch> possibleNumber =
646         std::make_unique<PhoneNumberMatch>(size, input, phoneNumber);
647     PhoneNumberMatch* phoneNumberMatch =
648         regexRule2->IsValid(possibleNumber.get(), message);
649     EXPECT_TRUE(phoneNumberMatch != nullptr);
650     regexRule2->GetType();
651     std::unique_ptr<icu::RegexPattern> regexPattern =
652         std::unique_ptr<icu::RegexPattern>(regexRule2->GetPattern());
653     isValidType = "Rawstr";
654     std::unique_ptr<RegexRule> regexRule3 = std::make_unique<RegexRule>(regex, isValidType,
655         handleType, insensitive, type);
656     PhoneNumberMatch* phoneNumMatch =
657         regexRule3->IsValid(possibleNumber.get(), message);
658     EXPECT_TRUE(phoneNumMatch != nullptr);
659     type = "CONTAIN";
660     string newRegexStr;
661     icu::UnicodeString unicRegex(newRegexStr.c_str());
662     std::unique_ptr<RegexRule> regexRule4 = std::make_unique<RegexRule>(unicRegex, isValidType,
663         handleType, insensitive, type);
664     type = "CONTAIN_OR_INTERSECT";
665     std::unique_ptr<RegexRule> regexRule5 = std::make_unique<RegexRule>(unicRegex, isValidType,
666         handleType, insensitive, type);
667     EXPECT_TRUE(regexRule5 != nullptr);
668 }
669 
670 /**
671  * @tc.name: IntlFuncTest0064
672  * @tc.desc: Test GetLanguageInfoArray
673  * @tc.type: FUNC
674  */
675 HWTEST_F(IntlTest, IntlFuncTest0064, TestSize.Level1)
676 {
677     std::unique_ptr<SystemLocaleManager> systemLocaleManager = std::make_unique<SystemLocaleManager>();
678     std::vector<std::string> languages = {"en", "zh-Hans", "es", "fr"};
679     SortOptions sortOptions = {"en-US", true, true};
680     I18nErrorCode status;
681     std::vector<LocaleItem> languageInfos = systemLocaleManager->GetLanguageInfoArray(languages, sortOptions, status);
682     EXPECT_EQ(languageInfos.size(), 4);
683     EXPECT_EQ(languageInfos[0].id, "zh-Hans");
684     EXPECT_EQ(languageInfos[0].suggestionType, 2);
685 }
686 
687 /**
688  * @tc.name: IntlFuncTest0065
689  * @tc.desc: Test relative time format default parameter
690  * @tc.type: FUNC
691  */
692 HWTEST_F(IntlTest, IntlFuncTest0065, TestSize.Level1)
693 {
694     vector<string> locales;
695     locales.push_back("fr-FR");
696     map<string, string> options;
697     RelativeTimeFormat *formatter = new RelativeTimeFormat(locales, options);
698 
699     double number = -1;
700     string unit = "day";
701     string res = formatter->Format(number, unit);
702     if (IntlTest::deviceType == "wearable" || IntlTest::deviceType == "liteWearable" ||
703         IntlTest::deviceType == "watch") {
704         EXPECT_EQ(res, "-1 j");
705     } else if (IntlTest::deviceType == "tablet" || IntlTest::deviceType == "2in1" || IntlTest::deviceType == "tv" ||
706         IntlTest::deviceType == "pc") {
707         EXPECT_EQ(res, "il y a 1 jour");
708     } else {
709         EXPECT_EQ(res, "il y a 1 jour");
710     }
711     delete formatter;
712 }
713 
714 /**
715  * @tc.name: IntlFuncTest0066
716  * @tc.desc: Test datetime format default parameter
717  * @tc.type: FUNC
718  */
719 HWTEST_F(IntlTest, IntlFuncTest0066, TestSize.Level1)
720 {
721     vector<string> locales;
722     locales.push_back("en-GB");
723     int64_t milliseconds = 987654321;
724 
725     map<string, string> defaultOptions;
726     std::unique_ptr<DateTimeFormat> defaultFormatter = DateTimeFormat::CreateInstance(locales, defaultOptions);
727     string defaultRes = defaultFormatter->Format(milliseconds);
728 
729     map<string, string> dateOptions = {
730         { "dateStyle", "auto" }
731     };
732     std::unique_ptr<DateTimeFormat> dateFormatter = DateTimeFormat::CreateInstance(locales, dateOptions);
733     string dateRes = dateFormatter->Format(milliseconds);
734 
735     map<string, string> timeOptions = {
736         { "timeStyle", "auto" }
737     };
738     std::unique_ptr<DateTimeFormat> timeFormatter = DateTimeFormat::CreateInstance(locales, timeOptions);
739     string timeRes = timeFormatter->Format(milliseconds);
740 
741     if (IntlTest::deviceType == "wearable" || IntlTest::deviceType == "liteWearable" ||
742         IntlTest::deviceType == "watch") {
743         EXPECT_EQ(defaultRes, "12/01/1970");
744         EXPECT_EQ(dateRes, "12/01/1970");
745         EXPECT_EQ(timeRes, "06:20");
746     } else if (IntlTest::deviceType == "tablet" || IntlTest::deviceType == "2in1" || IntlTest::deviceType == "tv" ||
747         IntlTest::deviceType == "pc") {
748         EXPECT_EQ(defaultRes, "12 Jan 1970");
749         EXPECT_EQ(dateRes, "12 Jan 1970");
750         EXPECT_EQ(timeRes, "06:20:54");
751     } else {
752         EXPECT_EQ(defaultRes, "12/01/1970");
753         EXPECT_EQ(dateRes, "12/01/1970");
754         EXPECT_EQ(timeRes, "06:20");
755     }
756 }
757 
758 /**
759  * @tc.name: IntlFuncTest0067
760  * @tc.desc: Test datetime format default parameter
761  * @tc.type: FUNC
762  */
763 HWTEST_F(IntlTest, IntlFuncTest0067, TestSize.Level1)
764 {
765     vector<string> locales;
766     locales.push_back("en-GB");
767     int64_t milliseconds = 987654321;
768 
769     map<string, string> monthOptions = {
770         { "month", "auto" }
771     };
772     std::unique_ptr<DateTimeFormat> monthFormatter = DateTimeFormat::CreateInstance(locales, monthOptions);
773     string monthRes = monthFormatter->Format(milliseconds);
774 
775     map<string, string> weekdayOptions = {
776         { "weekday", "auto" }
777     };
778     std::unique_ptr<DateTimeFormat> weekdayFormatter = DateTimeFormat::CreateInstance(locales, weekdayOptions);
779     string weekdayRes = weekdayFormatter->Format(milliseconds);
780 
781     map<string, string> eraOptions = {
782         { "year", "2-digit" },
783         { "era", "auto" }
784     };
785     std::unique_ptr<DateTimeFormat> eraFormatter = DateTimeFormat::CreateInstance(locales, eraOptions);
786     string eraRes = eraFormatter->Format(milliseconds);
787 
788     if (IntlTest::deviceType == "wearable" || IntlTest::deviceType == "liteWearable" ||
789         IntlTest::deviceType == "watch") {
790         EXPECT_EQ(monthRes, "Jan");
791         EXPECT_EQ(weekdayRes, "Mon");
792         EXPECT_EQ(eraRes, "70 A");
793     } else if (IntlTest::deviceType == "tablet" || IntlTest::deviceType == "2in1" || IntlTest::deviceType == "tv" ||
794         IntlTest::deviceType == "pc") {
795         EXPECT_EQ(monthRes, "January");
796         EXPECT_EQ(weekdayRes, "Monday");
797         EXPECT_EQ(eraRes, "70 Anno Domini");
798     } else {
799         EXPECT_EQ(monthRes, "Jan");
800         EXPECT_EQ(weekdayRes, "Mon");
801         EXPECT_EQ(eraRes, "70 AD");
802     }
803 }
804 
805 /**
806  * @tc.name: IntlFuncTest0068
807  * @tc.desc: Test datetime format default parameter
808  * @tc.type: FUNC
809  */
810 HWTEST_F(IntlTest, IntlFuncTest0068, TestSize.Level1)
811 {
812     vector<string> locales;
813     locales.push_back("fr-FR");
814     int64_t milliseconds = 987654321;
815 
816     map<string, string> dayPeriodOptions = {
817         { "hour", "numeric" },
818         { "hourCycle", "h12" },
819         { "dayPeriod", "auto" },
820         { "timeZone", "UTC" }
821     };
822     std::unique_ptr<DateTimeFormat> dayPeriodFormatter = DateTimeFormat::CreateInstance(locales, dayPeriodOptions);
823     string dayPeriodRes = dayPeriodFormatter->Format(milliseconds);
824 
825     map<string, string> timeZoneNameOptions = {
826         { "hour", "2-digit" },
827         { "timeZoneName", "auto" }
828     };
829     std::unique_ptr<DateTimeFormat> timeZoneNameFormatter
830         = DateTimeFormat::CreateInstance(locales, timeZoneNameOptions);
831     string timeZoneNameRes = timeZoneNameFormatter->Format(milliseconds);
832 
833     if (IntlTest::deviceType == "wearable" || IntlTest::deviceType == "liteWearable" ||
834         IntlTest::deviceType == "watch") {
835         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAFmat.");
836         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
837     } else if (IntlTest::deviceType == "tablet" || IntlTest::deviceType == "2in1" || IntlTest::deviceType == "tv" ||
838         IntlTest::deviceType == "pc") {
839         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAF" "du matin");
840         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM heure normale de la Chine");
841     } else {
842         EXPECT_EQ(dayPeriodRes, "10\xE2\x80\xAFmatin");
843         EXPECT_EQ(timeZoneNameRes, "6\xE2\x80\xAFPM UTC+8");
844     }
845 }
846 
847 /**
848  * @tc.name: IntlFuncTest0069
849  * @tc.desc: Test number format unitUsage
850  * @tc.type: FUNC
851  */
852 HWTEST_F(IntlTest, IntlFuncTest0069, TestSize.Level1)
853 {
854     std::string locale = "&&%";
855     DateTimeSequence::GetDateOrder(locale);
856     trim(locale);
857     const std::string destPath = "/data/log/copy.txt";
858     EXPECT_TRUE(IsLegalPath(destPath));
859     const std::string relativePath = "../log/copy.txt";
860     EXPECT_FALSE(IsLegalPath(relativePath));
861     const char* dirPath = "/data/log";
862     EXPECT_TRUE(IsDirExist(dirPath));
863 }
864 
865 /**
866  * @tc.name: IntlFuncTest0070
867  * @tc.desc: Test Merge
868  * @tc.type: FUNC
869  */
870 HWTEST_F(IntlTest, IntlFuncTest0070, TestSize.Level1)
871 {
872     std::vector<std::string> resultVec;
873     const std::string separator = ",";
874     std::string source;
875     Merge(resultVec, separator, source);
876     EXPECT_EQ(source, "");
877 }
878 
879 /**
880  * @tc.name: IntlFuncTest0071
881  * @tc.desc: Test number format unitUsage
882  * @tc.type: FUNC
883  */
884 HWTEST_F(IntlTest, IntlFuncTest0071, TestSize.Level1)
885 {
886     std::string path = "/data/log/faultlog";
887     char delimiter = '\0';
888     const std::string localeStr = "ar";
889     std::shared_ptr<LocaleInfo> localeInfo = std::make_shared<LocaleInfo>(localeStr);
890     std::string errorCode;
891     std::string res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
892     EXPECT_EQ(res, path);
893     delimiter = '/';
894     res = LocaleConfig::GetUnicodeWrappedFilePath("", delimiter, localeInfo, errorCode);
895     EXPECT_EQ(res, "");
896     std::shared_ptr<LocaleInfo> invalidLocale = std::make_shared<LocaleInfo>("@@@");
897     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, invalidLocale, errorCode);
898     EXPECT_EQ(res, path);
899     std::shared_ptr<LocaleInfo> zhLocale = std::make_shared<LocaleInfo>("zh-Hans");
900     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, invalidLocale, errorCode);
901     EXPECT_EQ(res, path);
902     path = "data-log-faultlog";
903     res = LocaleConfig::GetUnicodeWrappedFilePath(path, delimiter, localeInfo, errorCode);
904     EXPECT_EQ(res, path);
905 }
906 
907 /**
908  * @tc.name: IntlFuncTest0072
909  * @tc.desc: Test date order
910  * @tc.type: FUNC
911  */
912 HWTEST_F(IntlTest, IntlFuncTest0072, TestSize.Level1)
913 {
914     std::string locale = "en-GB";
915     std::string result = DateTimeSequence::GetDateOrder(locale);
916     EXPECT_EQ(result, "d-LLL-y");
917     locale = "zh-Hans";
918     result = DateTimeSequence::GetDateOrder(locale);
919     EXPECT_EQ(result, "y-L-d");
920     locale = "bo-CN";
921     result = DateTimeSequence::GetDateOrder(locale);
922     EXPECT_EQ(result, "y-LLL-d");
923     locale = "zh-Hant";
924     result = DateTimeSequence::GetDateOrder(locale);
925     EXPECT_EQ(result, "y-L-d");
926     locale = "ug";
927     result = DateTimeSequence::GetDateOrder(locale);
928     EXPECT_EQ(result, "L-d-y");
929     std::string localeBg = "bg-BG";
930     DateTimeSequence::GetDateOrder(localeBg);
931 }
932 
933 /**
934  * @tc.name: IntlFuncTest0073
935  * @tc.desc: Test PhoneNumberFormat.format()
936  * @tc.type: FUNC
937  */
938 HWTEST_F(IntlTest, IntlFuncTest0073, TestSize.Level1)
939 {
940     map<string, string> options = {
941         { "type", "TYPING" }
942     };
943     std::unique_ptr<PhoneNumberFormat> phoneNumFmt =
944         std::make_unique<PhoneNumberFormat>("zh-CN", options);
945     std::string number = "186223500";
946     std::string formated = "";
947     for (char c : number) {
948         formated = formated + c;
949         formated = phoneNumFmt->format(formated);
950     }
951     EXPECT_EQ(formated, "186 2235 00");
952     number = "186223500102933884747757758585885858854774";
953     phoneNumFmt->format(number);
954     number = "(020) 6355";
955     phoneNumFmt->format(number);
956     number = "123";
957     phoneNumFmt->format(number);
958     number = "2134";
959     phoneNumFmt->format(number);
960 
961     formated = "";
962     number = "075576453";
963     for (char c : number) {
964         formated = formated + c;
965         formated = phoneNumFmt->format(formated);
966     }
967     EXPECT_EQ(formated, "0755 7645 3");
968 
969     std::unique_ptr<PhoneNumberFormat> phoneNumFmt2 =
970         std::make_unique<PhoneNumberFormat>("AD", options);
971     formated = "";
972     number = "7123945";
973     for (char c : number) {
974         if (c == '4') {
975             formated = formated.substr(0, formated.length() - 1);
976             formated = phoneNumFmt->format(formated);
977         }
978         formated = formated + c;
979         formated = phoneNumFmt->format(formated);
980     }
981     EXPECT_EQ(formated, "712 345");
982     PhoneNumberFormat::CloseDynamicHandler();
983 }
984 
985 /**
986  * @tc.name: IntlFuncTest0074
987  * @tc.desc: Test LocaleMatcher
988  * @tc.type: FUNC
989  */
990 HWTEST_F(IntlTest, IntlFuncTest0074, TestSize.Level1)
991 {
992     const LocaleInfo* other = new LocaleInfo("fil");
993     LocaleMatcher::IsMoreSuitable(nullptr, other, nullptr);
994     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, nullptr);
995     const LocaleInfo* request = new LocaleInfo("en-Qaag-GB");
996     std::unique_ptr<LocaleInfo> currentHE = std::make_unique<LocaleInfo>("he");
997     std::unique_ptr<LocaleInfo> otherIW = std::make_unique<LocaleInfo>("iw");
998     LocaleMatcher::IsMoreSuitable(currentHE.get(), otherIW.get(), request);
999     const LocaleInfo* currentTL = new LocaleInfo("tl");
1000     LocaleMatcher::IsMoreSuitable(currentTL, other, request);
1001     LocaleMatcher::IsMoreSuitable(other, currentTL, request);
1002     const LocaleInfo* currentJI = new LocaleInfo("ji");
1003     const LocaleInfo* otherYI = new LocaleInfo("yi");
1004     LocaleMatcher::IsMoreSuitable(currentJI, otherYI, request);
1005     LocaleMatcher::IsMoreSuitable(otherYI, currentJI, request);
1006     std::unique_ptr<LocaleInfo> currentJW = std::make_unique<LocaleInfo>("jw");
1007     std::unique_ptr<LocaleInfo> otherJV = std::make_unique<LocaleInfo>("jv");
1008     LocaleMatcher::IsMoreSuitable(currentJW.get(), otherJV.get(), request);
1009     LocaleMatcher::IsMoreSuitable(otherJV.get(), currentJW.get(), request);
1010     const LocaleInfo* currentIN = new LocaleInfo("in-PH");
1011     const LocaleInfo* otherID = new LocaleInfo("id-MY");
1012     LocaleMatcher::IsMoreSuitable(currentIN, otherID, request);
1013     LocaleMatcher::IsMoreSuitable(otherID, currentIN, request);
1014     LocaleMatcher::IsMoreSuitable(nullptr, currentIN, request);
1015     LocaleMatcher::IsMoreSuitable(currentIN, nullptr, request);
1016     LocaleMatcher::IsMoreSuitable(nullptr, nullptr, request);
1017     const LocaleInfo* enLatn = new LocaleInfo("en-Latn-US");
1018     LocaleMatcher::Match(request, enLatn);
1019     std::unique_ptr<LocaleInfo> otherIN = std::make_unique<LocaleInfo>("in-MY");
1020     LocaleMatcher::Match(currentIN, otherIN.get());
1021     LocaleMatcher::Match(currentIN, nullptr);
1022     std::unique_ptr<LocaleInfo> newRequest = std::make_unique<LocaleInfo>("en-Latn");
1023     std::unique_ptr<LocaleInfo> currentEn = std::make_unique<LocaleInfo>("en-GB");
1024     std::unique_ptr<LocaleInfo> otherEn = std::make_unique<LocaleInfo>("en-US");
1025     int8_t result = LocaleMatcher::IsMoreSuitable(currentEn.get(), otherEn.get(), newRequest.get());
1026     LocaleMatcher::Match(enLatn, currentEn.get());
1027     EXPECT_EQ(result, -1);
1028     delete other;
1029     delete request;
1030     delete currentTL;
1031     delete currentJI;
1032     delete otherYI;
1033     delete currentIN;
1034     delete otherID;
1035     delete enLatn;
1036 }
1037 
1038 /**
1039  * @tc.name: IntlFuncTest0075
1040  * @tc.desc: Test RulesEngine
1041  * @tc.type: FUNC
1042  */
1043 HWTEST_F(IntlTest, IntlFuncTest0075, TestSize.Level1)
1044 {
1045     using testing::_;
1046     DateTimeRule* dateTimeRule = nullptr;
1047     std::unordered_map<std::string, std::string> rulesMap = {};
1048     std::unordered_map<std::string, std::string> subRules = {};
1049     std::unordered_map<std::string, std::string> param = {};
1050     std::unordered_map<std::string, std::string> paramBackup = {};
1051     RulesSet rulesSet(rulesMap, subRules, param, paramBackup);
1052     RulesEngine rulesEngine(dateTimeRule, rulesSet);
1053 
1054     std::string str = "abc123";
1055     icu::UnicodeString message(str.c_str());
1056     std::string locale = "en";
1057     std::unique_ptr<DateTimeRule> dtRule = std::make_unique<DateTimeRule>(locale);
1058     ASSERT_TRUE(dtRule != nullptr);
1059     MockRulesEngine ruleEngineMock(dtRule.get(), rulesSet);
1060     EXPECT_CALL(ruleEngineMock, IsRegexPatternInvalid(_))
1061     .WillRepeatedly(Return(true));
1062     std::vector<MatchedDateTimeInfo> matches = ruleEngineMock.Match(message);
1063     EXPECT_EQ(matches.size(), 0);
1064 
1065     MockRulesEngine ruleEngineMock2(dtRule.get(), rulesSet);
1066     EXPECT_CALL(ruleEngineMock2, IsRegexMatcherInvalid(_))
1067     .WillRepeatedly(Return(true));
1068     matches = ruleEngineMock2.Match(message);
1069     EXPECT_EQ(matches.size(), 0);
1070 }
1071 
1072 /**
1073  * @tc.name: IntlFuncTest0076
1074  * @tc.desc: Test RulesEngine
1075  * @tc.type: FUNC
1076  */
1077 HWTEST_F(IntlTest, IntlFuncTest0076, TestSize.Level1)
1078 {
1079     i18n::phonenumbers::PhoneNumber phoneNumber;
1080     size_t start = 10;
1081     std::string rawStr = "1 800 234 45 67";
1082     std::unique_ptr<PhoneNumberMatch> possibleNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1083     icu::UnicodeString regex;
1084     std::string handleType = "Operator";
1085     std::string insensitive = "True";
1086     std::unique_ptr<PositiveRule> pRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1087     icu::RegexPattern* regexP = pRule->GetPattern();
1088     std::string msg = "(0075 665";
1089     icu::UnicodeString message(msg.c_str());
1090     std::vector<MatchedNumberInfo> vector = pRule->HandleInner(possibleNumber.get(), message);
1091     handleType = "EndWithMobile";
1092     std::unique_ptr<PositiveRule> pRule2 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1093     vector = pRule2->HandleInner(possibleNumber.get(), message);
1094     vector = pRule2->Handle(possibleNumber.get(), message);
1095     handleType = "default";
1096     std::unique_ptr<PositiveRule> pRule3 = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1097     vector = pRule3->HandleInner(possibleNumber.get(), message);
1098     vector = pRule3->Handle(possibleNumber.get(), message);
1099     rawStr = "(1 800 234 45 67";
1100     std::unique_ptr<PhoneNumberMatch> posbNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1101     vector = pRule3->Handle(posbNumber.get(), message);
1102     EXPECT_EQ(vector.size(), 1);
1103     delete regexP;
1104 
1105     EXPECT_FALSE(IsDirExist(nullptr));
1106     std::string strForTrim;
1107     EXPECT_EQ(trim(strForTrim), "");
1108     bool copyResult = FileCopy("/data/123/abc.txt", "/data/456/abc.txt");
1109     EXPECT_FALSE(copyResult);
1110 }
1111 
1112 /**
1113  * @tc.name: IntlFuncTest0077
1114  * @tc.desc: Test RegexRule
1115  * @tc.type: FUNC
1116  */
1117 HWTEST_F(IntlTest, IntlFuncTest0077, TestSize.Level1)
1118 {
1119     using namespace i18n::phonenumbers;
1120     std::string regexStr = "\\d{3}";
1121     icu::UnicodeString regex(regexStr.c_str());
1122     std::string isValidType = "Default";
1123     std::string handleType = "Operator";
1124     std::string insensitive = "False";
1125     std::string type = "xxx";
1126     icu::UnicodeString message(type.c_str());
1127 
1128     i18n::phonenumbers::PhoneNumber phoneNumber;
1129     PhoneNumberUtil* phoneNumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1130     std::string input = "(010)86753564";
1131     std::string country = "CN";
1132     phoneNumberUtil->ParseAndKeepRawInput(input, country, &phoneNumber);
1133     size_t start = 10;
1134     std::string rawString = "1 800 234 45 67";
1135     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1136         std::make_unique<PhoneNumberMatch>(start, rawString, phoneNumber);
1137     std::unique_ptr<RegexRule> regexRule =
1138         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1139     ASSERT_TRUE(possibleNumber != nullptr);
1140     PhoneNumberMatch* phoneNumMatch = regexRule->IsValid(possibleNumber.get(), message);
1141     if (phoneNumMatch != nullptr) {
1142         std::vector<MatchedNumberInfo> list = regexRule->Handle(phoneNumMatch, message);
1143         EXPECT_EQ(list.size(), 1);
1144     }
1145 }
1146 
1147 /**
1148  * @tc.name: IntlFuncTest0078
1149  * @tc.desc: Test CodeRule
1150  * @tc.type: FUNC
1151  */
1152 HWTEST_F(IntlTest, IntlFuncTest0078, TestSize.Level1)
1153 {
1154     std::string isValidType = "Default";
1155     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1156     std::string msg = "00222a-1 800 234 45 670A-";
1157     icu::UnicodeString message(msg.c_str());
1158     i18n::phonenumbers::PhoneNumber phoneNumber;
1159     size_t start = 7;
1160     std::string rawStr = "1 800 234 45 67";
1161     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1162         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1163     ASSERT_TRUE(possibleNumber != nullptr);
1164     codeRule->IsValid(possibleNumber.get(), message);
1165     std::string country = "../supported_locales";
1166     std::unique_ptr<PhoneNumberRule> phoneNumberRule = std::make_unique<PhoneNumberRule>(country);
1167     EXPECT_TRUE(phoneNumberRule != nullptr);
1168 }
1169 
1170 /**
1171  * @tc.name: IntlFuncTest0079
1172  * @tc.desc: Test CodeRule
1173  * @tc.type: FUNC
1174  */
1175 HWTEST_F(IntlTest, IntlFuncTest0079, TestSize.Level1)
1176 {
1177     std::string isValidType = "PreSuf";
1178     std::string msg = "00222a-1 800 234 45 670A-";
1179     icu::UnicodeString message(msg.c_str());
1180     i18n::phonenumbers::PhoneNumber phoneNumber;
1181     size_t start = 7;
1182     std::string rawStr = "1 800 234 45 67";
1183     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1184         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1185     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1186     ASSERT_TRUE(possibleNumber != nullptr);
1187     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1188     EXPECT_TRUE(match != nullptr);
1189 }
1190 
1191 /**
1192  * @tc.name: IntlFuncTest0080
1193  * @tc.desc: Test RegexRule
1194  * @tc.type: FUNC
1195  */
1196 HWTEST_F(IntlTest, IntlFuncTest0080, TestSize.Level1)
1197 {
1198     using namespace i18n::phonenumbers;
1199     std::string regexStr = "\\d{3}";
1200     icu::UnicodeString regex(regexStr.c_str());
1201     std::string isValidType = "Default";
1202     std::string handleType = "Operator";
1203     std::string insensitive = "True";
1204     std::string type = "xxx";
1205     std::string input = "(010)86753564";
1206     size_t start = 10;
1207     std::string rawStr = "1 800 234 45 67";
1208     i18n::phonenumbers::PhoneNumber phoneNumber;
1209     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1210         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1211     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1212     std::unique_ptr<icu::RegexPattern> regexPattern =
1213         std::unique_ptr<icu::RegexPattern>(regexRule->GetPattern());
1214     std::string msg = "00222a-86753564A-";
1215     icu::UnicodeString message(msg.c_str());
1216     ASSERT_TRUE(possibleNumber != nullptr);
1217     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1218     EXPECT_EQ(list.size(), 1);
1219     delete regexRule;
1220 }
1221 
1222 /**
1223  * @tc.name: IntlFuncTest0081
1224  * @tc.desc: Test RegexRule
1225  * @tc.type: FUNC
1226  */
1227 HWTEST_F(IntlTest, IntlFuncTest0081, TestSize.Level1)
1228 {
1229     using namespace i18n::phonenumbers;
1230     std::string regexStr = "\\d{3}";
1231     icu::UnicodeString regex(regexStr.c_str());
1232     std::string isValidType = "PreSuf";
1233     std::string handleType = "Blank";
1234     std::string insensitive = "False";
1235     std::string type = "xxx";
1236     std::string input = "(010)86753564";
1237     size_t start = 0;
1238     std::string rawStr = "1 800 234 45 67";
1239     i18n::phonenumbers::PhoneNumber phoneNumber;
1240     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1241         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1242     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1243     std::string msg = "00222a-86753564A-";
1244     icu::UnicodeString message(msg.c_str());
1245     ASSERT_TRUE(possibleNumber != nullptr);
1246     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1247     EXPECT_EQ(list.size(), 1);
1248     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1249     EXPECT_TRUE(match != nullptr);
1250     PhoneNumberMatch* match2 = regexRule->IsValid(nullptr, message);
1251     EXPECT_TRUE(match2 == nullptr);
1252     rawStr = "5201314";
1253     std::unique_ptr<PhoneNumberMatch> possibleNum =
1254         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1255     ASSERT_TRUE(possibleNum != nullptr);
1256     std::vector<MatchedNumberInfo> list2 = regexRule->Handle(possibleNum.get(), message);
1257     EXPECT_EQ(list2.size(), 0);
1258     delete regexRule;
1259 }
1260 
1261 /**
1262  * @tc.name: IntlFuncTest0082
1263  * @tc.desc: Test RegexRule
1264  * @tc.type: FUNC
1265  */
1266 HWTEST_F(IntlTest, IntlFuncTest0082, TestSize.Level1)
1267 {
1268     using namespace i18n::phonenumbers;
1269     std::string regexStr = "\\d{3}";
1270     icu::UnicodeString regex(regexStr.c_str());
1271     std::string isValidType = "Code";
1272     std::string handleType = "Slant";
1273     std::string insensitive = "False";
1274     std::string type = "xxx";
1275     std::string input = "(010)120/110";
1276     size_t start = 10;
1277     i18n::phonenumbers::PhoneNumber phoneNumber;
1278     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1279         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1280     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1281     std::string msg = "00222a-86753564A-";
1282     icu::UnicodeString message(msg.c_str());
1283     ASSERT_TRUE(possibleNumber != nullptr);
1284     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1285     EXPECT_EQ(list.size(), 1);
1286     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1287     EXPECT_TRUE(match != nullptr);
1288     delete regexRule;
1289 }
1290 
1291 /**
1292  * @tc.name: IntlFuncTest0083
1293  * @tc.desc: Test RegexRule
1294  * @tc.type: FUNC
1295  */
1296 HWTEST_F(IntlTest, IntlFuncTest0083, TestSize.Level1)
1297 {
1298     using namespace i18n::phonenumbers;
1299     std::string regexStr = "\\d{3}";
1300     icu::UnicodeString regex(regexStr.c_str());
1301     std::string isValidType = "PreSuf";
1302     std::string handleType = "StartWithMobile";
1303     std::string insensitive = "False";
1304     std::string type = "xxx";
1305     std::string input = "86753564";
1306     size_t start = 0;
1307     i18n::phonenumbers::PhoneNumber phoneNumber;
1308     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1309         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1310     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1311     std::string msg = "86753564a-";
1312     icu::UnicodeString message(msg.c_str());
1313     ASSERT_TRUE(possibleNumber != nullptr);
1314     regexRule->IsValid(possibleNumber.get(), message);
1315     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1316     EXPECT_EQ(list.size(), 0);
1317     msg = "86753564A1";
1318     icu::UnicodeString message2(msg.c_str());
1319     PhoneNumberMatch* match2 = regexRule->IsValid(possibleNumber.get(), message2);
1320     EXPECT_TRUE(match2 == nullptr);
1321     msg = "86753564Aa";
1322     icu::UnicodeString message3(msg.c_str());
1323     PhoneNumberMatch* match3 = regexRule->IsValid(possibleNumber.get(), message3);
1324     EXPECT_TRUE(match3 != nullptr);
1325     msg = "86753564AA-";
1326     icu::UnicodeString message4(msg.c_str());
1327     PhoneNumberMatch* match4 = regexRule->IsValid(possibleNumber.get(), message4);
1328     EXPECT_TRUE(match4 != nullptr);
1329     msg = "86753564AA2";
1330     icu::UnicodeString message5(msg.c_str());
1331     PhoneNumberMatch* match5 = regexRule->IsValid(possibleNumber.get(), message5);
1332     EXPECT_TRUE(match5 == nullptr);
1333     msg = "86753564AA@";
1334     icu::UnicodeString message6(msg.c_str());
1335     PhoneNumberMatch* match6 = regexRule->IsValid(possibleNumber.get(), message6);
1336     EXPECT_TRUE(match6 == nullptr);
1337     msg = "86753564AAc";
1338     icu::UnicodeString message7(msg.c_str());
1339     PhoneNumberMatch* match7 = regexRule->IsValid(possibleNumber.get(), message7);
1340     EXPECT_TRUE(match7 != nullptr);
1341     delete regexRule;
1342 }
1343 
1344 /**
1345  * @tc.name: IntlFuncTest0084
1346  * @tc.desc: Test RegexRule
1347  * @tc.type: FUNC
1348  */
1349 HWTEST_F(IntlTest, IntlFuncTest0084, TestSize.Level1)
1350 {
1351     using namespace i18n::phonenumbers;
1352     std::string regexStr = "\\d{3}";
1353     icu::UnicodeString regex(regexStr.c_str());
1354     std::string isValidType = "Default";
1355     std::string handleType = "Default";
1356     std::string insensitive = "False";
1357     std::string type = "xxx";
1358     std::string input = "(010)86753564";
1359     size_t start = 10;
1360     i18n::phonenumbers::PhoneNumber phoneNumber;
1361     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1362         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1363     RegexRule* regexRule = new RegexRule(regex, isValidType, handleType, insensitive, type);
1364     std::string msg = "00222a-86753564A-";
1365     icu::UnicodeString message(msg.c_str());
1366     ASSERT_TRUE(possibleNumber != nullptr);
1367     std::vector<MatchedNumberInfo> list = regexRule->Handle(possibleNumber.get(), message);
1368     EXPECT_EQ(list.size(), 1);
1369     delete regexRule;
1370 }
1371 
1372 /**
1373  * @tc.name: IntlFuncTest0085
1374  * @tc.desc: Test BorderRule
1375  * @tc.type: FUNC
1376  */
1377 HWTEST_F(IntlTest, IntlFuncTest0085, TestSize.Level1)
1378 {
1379     using namespace i18n::phonenumbers;
1380     std::string str = "\\d+";
1381     icu::UnicodeString regex(str.c_str());
1382     std::string insensitive = "False";
1383     std::string type = "CONTAIN_OR_INTERSECT";
1384     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1385     icu::RegexPattern* regexPattern = borderRule->GetPattern();
1386     std::string msg = "2222U-(010)86753564a-hha";
1387     std::string input = "(010)86753564";
1388     size_t start = 6;
1389     i18n::phonenumbers::PhoneNumber phoneNumber;
1390     icu::UnicodeString message(msg.c_str());
1391     std::unique_ptr<PhoneNumberMatch> match =
1392         std::make_unique<PhoneNumberMatch>(start, input, phoneNumber);
1393     bool flag = borderRule->Handle(match.get(), message);
1394     EXPECT_TRUE(flag);
1395 
1396     type = "CONTAIN";
1397     std::unique_ptr<BorderRule> bRule = std::make_unique<BorderRule>(regex, insensitive, type);
1398     flag = bRule->Handle(match.get(), message);
1399     EXPECT_TRUE(flag);
1400     delete regexPattern;
1401 }
1402 
1403 /**
1404  * @tc.name: IntlFuncTest0086
1405  * @tc.desc: Test BorderRule
1406  * @tc.type: FUNC
1407  */
1408 HWTEST_F(IntlTest, IntlFuncTest0086, TestSize.Level1)
1409 {
1410     using namespace i18n::phonenumbers;
1411     std::string str = "\\d+";
1412     icu::UnicodeString regex(str.c_str());
1413     std::string insensitive = "False";
1414     std::string type = "xx@@";
1415     std::unique_ptr<BorderRule> borderRule = std::make_unique<BorderRule>(regex, insensitive, type);
1416     icu::UnicodeString newRegex;
1417     insensitive = "True";
1418     std::unique_ptr<FindRule> findRule = std::make_unique<FindRule>(newRegex, insensitive);
1419     icu::RegexPattern* regexPattern = findRule->GetPattern();
1420     EXPECT_TRUE(regexPattern != nullptr);
1421     delete regexPattern;
1422     std::string emptyStr = "";
1423     icu::UnicodeString emptyRegex(emptyStr.c_str());
1424     std::unique_ptr<BorderRule> emptyBorderRule =
1425         std::make_unique<BorderRule>(emptyRegex, insensitive, type);
1426 }
1427 
1428 /**
1429  * @tc.name: IntlFuncTest0087
1430  * @tc.desc: Test LocaleMatcher
1431  * @tc.type: FUNC
1432  */
1433 HWTEST_F(IntlTest, IntlFuncTest0087, TestSize.Level1)
1434 {
1435     const std::unique_ptr<LocaleInfo> request = std::make_unique<LocaleInfo>("en-Qaag-GB");
1436     const std::unique_ptr<LocaleInfo> enLatn = std::make_unique<LocaleInfo>("en-US");
1437     LocaleMatcher::Match(request.get(), enLatn.get());
1438     std::vector<LocaleInfo*> candidateLocales;
1439     LocaleInfo* locale0 = new LocaleInfo("en-US");
1440     LocaleInfo* locale1 = new LocaleInfo("en-Qaag-US");
1441     LocaleInfo* locale2 = new LocaleInfo("en-Latn-GB");
1442     LocaleInfo* locale3 = new LocaleInfo("en");
1443     candidateLocales.push_back(locale0);
1444     candidateLocales.push_back(locale1);
1445     candidateLocales.push_back(locale2);
1446     candidateLocales.push_back(locale3);
1447     std::string bestMatch = LocaleMatcher::GetBestMatchedLocale(request.get(), candidateLocales);
1448     EXPECT_EQ(bestMatch, "en-Latn-GB");
1449     delete locale0;
1450     delete locale1;
1451     delete locale2;
1452     delete locale3;
1453 }
1454 
1455 /**
1456  * @tc.name: IntlFuncTest0088
1457  * @tc.desc: Test SignatureVerifier
1458  * @tc.type: FUNC
1459  */
1460 HWTEST_F(IntlTest, IntlFuncTest0088, TestSize.Level1)
1461 {
1462     std::string localVersionPath = "/data/log/local_version.txt";
1463     std::string updateVersionPath = "/data/log/update_version.txt";
1464     std::string localVersionContent = "version=1.0.24.100";
1465     std::string updateVersionContent = "version=1.0.24.101";
1466     IcsFileWriter icsFileWriter;
1467     bool status = icsFileWriter.WriteFile(localVersionContent, localVersionPath);
1468     ASSERT_TRUE(status);
1469     status = icsFileWriter.WriteFile(updateVersionContent, updateVersionPath);
1470     ASSERT_TRUE(status);
1471     bool isNecessary = UpgradeUtils::CheckIfUpdateNecessary(updateVersionPath, localVersionPath);
1472     ASSERT_TRUE(isNecessary);
1473 }
1474 
1475 /**
1476  * @tc.name: IntlFuncTest0089
1477  * @tc.desc: Test CodeRule
1478  * @tc.type: FUNC
1479  */
1480 HWTEST_F(IntlTest, IntlFuncTest0089, TestSize.Level1)
1481 {
1482     std::string isValidType = "PreSuf";
1483     std::string msg = "1 800 234 45 67a-";
1484     icu::UnicodeString message(msg.c_str());
1485     i18n::phonenumbers::PhoneNumber phoneNumber;
1486     size_t start = 0;
1487     std::string rawStr = "1 800 234 45 67";
1488     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1489         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1490     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1491     if (possibleNumber != nullptr) {
1492         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1493         EXPECT_TRUE(match != nullptr);
1494         msg = "1 800 234 45 67A1";
1495         icu::UnicodeString message2(msg.c_str());
1496         PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1497         EXPECT_TRUE(match2 == nullptr);
1498         msg = "1 800 234 45 67Aa";
1499         icu::UnicodeString message3(msg.c_str());
1500         PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1501         EXPECT_TRUE(match3 != nullptr);
1502         msg = "1 800 234 45 67AA-";
1503         icu::UnicodeString message4(msg.c_str());
1504         PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1505         EXPECT_TRUE(match4 != nullptr);
1506         msg = "1 800 234 45 67AA2";
1507         icu::UnicodeString message5(msg.c_str());
1508         PhoneNumberMatch* match5 = codeRule->IsValid(possibleNumber.get(), message5);
1509         EXPECT_TRUE(match5 == nullptr);
1510         msg = "1 800 234 45 67AA@";
1511         icu::UnicodeString message6(msg.c_str());
1512         PhoneNumberMatch* match6 = codeRule->IsValid(possibleNumber.get(), message6);
1513         EXPECT_TRUE(match6 == nullptr);
1514         msg = "1 800 234 45 67AAc";
1515         icu::UnicodeString message7(msg.c_str());
1516         PhoneNumberMatch* match7 = codeRule->IsValid(possibleNumber.get(), message7);
1517         EXPECT_TRUE(match7 != nullptr);
1518     }
1519     PhoneNumberMatch* match8 = codeRule->Handle(nullptr, message);
1520     EXPECT_TRUE(match8 == nullptr);
1521 }
1522 
1523 /**
1524  * @tc.name: IntlFuncTest0090
1525  * @tc.desc: Test CodeRule
1526  * @tc.type: FUNC
1527  */
1528 HWTEST_F(IntlTest, IntlFuncTest0090, TestSize.Level1)
1529 {
1530     std::string isValidType = "Code";
1531     std::string msg = "00222a-1 800 234 45 67A-";
1532     icu::UnicodeString message(msg.c_str());
1533     i18n::phonenumbers::PhoneNumber phoneNumber;
1534     size_t start = 10;
1535     std::string rawStr = "[17777]8;ext=123";
1536     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1537         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1538     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1539     if (possibleNumber != nullptr) {
1540         PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1541         EXPECT_TRUE(match == nullptr);
1542         PhoneNumberMatch* match2 = codeRule->IsValid(nullptr, message);
1543         EXPECT_TRUE(match2 == nullptr);
1544     }
1545 }
1546 
1547 /**
1548  * @tc.name: IntlFuncTest0091
1549  * @tc.desc: Test CodeRule
1550  * @tc.type: FUNC
1551  */
1552 HWTEST_F(IntlTest, IntlFuncTest0091, TestSize.Level1)
1553 {
1554     size_t start = 10;
1555     i18n::phonenumbers::PhoneNumber phoneNumber;
1556     std::string msg = "00222a-(0755)36661888A-";
1557     icu::UnicodeString message(msg.c_str());
1558     std::string rawStr = "(0755)36661888";
1559     std::unique_ptr<PhoneNumberMatch> possibleNum = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1560     std::string regexStr = "\\d{4}";
1561     icu::UnicodeString regex(regexStr.c_str());
1562     std::string handleType = "Operator";
1563     std::string insensitive = "True";
1564     std::unique_ptr<PositiveRule> pRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1565     std::vector<MatchedNumberInfo> list = pRule->HandleInner(possibleNum.get(), message);
1566     EXPECT_EQ(list.size(), 1);
1567     handleType = "Blank";
1568     start = 0;
1569     rawStr = "0755 36661888";
1570     i18n::phonenumbers::PhoneNumber phoneNumber2;
1571     std::unique_ptr<PhoneNumberMatch> maybeNumber = std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1572     std::unique_ptr<PositiveRule> posiRule = std::make_unique<PositiveRule>(regex, handleType, insensitive);
1573     std::vector<MatchedNumberInfo> list2 = posiRule->HandleInner(maybeNumber.get(), message);
1574     EXPECT_EQ(list2.size(), 1);
1575 }
1576 
1577 /**
1578  * @tc.name: IntlFuncTest0092
1579  * @tc.desc: Test I18nBreakIterator
1580  * @tc.type: FUNC
1581  */
1582 HWTEST_F(IntlTest, IntlFuncTest0092, TestSize.Level1)
1583 {
1584     std::unique_ptr<I18nBreakIteratorMock> breakIteratorMock = std::make_unique<I18nBreakIteratorMock>("en-GB");
1585     EXPECT_CALL(*breakIteratorMock, GetBreakIterator())
1586     .WillRepeatedly(Return(nullptr));
1587     breakIteratorMock->Current();
1588     breakIteratorMock->First();
1589     breakIteratorMock->Last();
1590     breakIteratorMock->Previous();
1591     breakIteratorMock->Next();
1592     breakIteratorMock->Next(1);
1593     breakIteratorMock->Following(3);
1594     bool flag = breakIteratorMock->IsBoundary(1);
1595     EXPECT_FALSE(flag);
1596 }
1597 
1598 /**
1599  * @tc.name: IntlFuncTest0093
1600  * @tc.desc: Test RegexRule
1601  * @tc.type: FUNC
1602  */
1603 HWTEST_F(IntlTest, IntlFuncTest0093, TestSize.Level1)
1604 {
1605     using namespace i18n::phonenumbers;
1606     std::string regexStr = "\\d{3}";
1607     icu::UnicodeString regex(regexStr.c_str());
1608     std::string isValidType = "PreSuf";
1609     std::string insensitive = "False";
1610     std::string handleType = "EndWithMobile";
1611     std::string type = "xxx";
1612     std::string msg = "00222a-1 800 234 45 67A-";
1613     icu::UnicodeString message(msg.c_str());
1614     i18n::phonenumbers::PhoneNumber phoneNumber;
1615     size_t start = 10;
1616     std::string rawStr = "1 800 234 45 67";
1617     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1618         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1619     std::unique_ptr<RegexRule> regexRule =
1620         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1621     if (possibleNumber != nullptr) {
1622         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1623         EXPECT_TRUE(match != nullptr);
1624     }
1625 
1626     isValidType = "Code";
1627     rawStr = "119";
1628     start = 0;
1629     i18n::phonenumbers::PhoneNumber phoneNumber2;
1630     std::unique_ptr<PhoneNumberMatch> possibleNum =
1631         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1632     std::unique_ptr<RegexRule> regexRule2 =
1633         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1634     if (possibleNum != nullptr) {
1635         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1636         EXPECT_TRUE(pnMatch == nullptr);
1637     }
1638 }
1639 
1640 /**
1641  * @tc.name: IntlFuncTest0094
1642  * @tc.desc: Test RegexRule
1643  * @tc.type: FUNC
1644  */
1645 HWTEST_F(IntlTest, IntlFuncTest0094, TestSize.Level1)
1646 {
1647     using namespace i18n::phonenumbers;
1648     std::string regexStr = "\\d{3}";
1649     icu::UnicodeString regex(regexStr.c_str());
1650     std::string isValidType = "PreSuf";
1651     std::string insensitive = "False";
1652     std::string handleType = "EndWithMobile";
1653     std::string type = "xxx";
1654     std::string msg = "00222a-1 800 234 45 67a1";
1655     icu::UnicodeString message(msg.c_str());
1656     i18n::phonenumbers::PhoneNumber phoneNumber;
1657     size_t start = 10;
1658     std::string rawStr = "1 800 234 45 67";
1659     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1660         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1661     std::unique_ptr<RegexRule> regexRule =
1662         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1663     if (possibleNumber != nullptr) {
1664         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1665         EXPECT_TRUE(match != nullptr);
1666     }
1667 
1668     isValidType = "Code";
1669     rawStr = "118057628100000001";
1670     start = 0;
1671     i18n::phonenumbers::PhoneNumber phoneNumber2;
1672     std::unique_ptr<PhoneNumberMatch> possibleNum =
1673         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1674     std::unique_ptr<RegexRule> regexRule2 =
1675         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1676     if (possibleNum != nullptr) {
1677         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1678         EXPECT_TRUE(pnMatch == nullptr);
1679     }
1680 
1681     isValidType = "Code";
1682     rawStr = "40082088201";
1683     start = 0;
1684     i18n::phonenumbers::PhoneNumber phoneNumber3;
1685     std::unique_ptr<PhoneNumberMatch> maybeNumber =
1686         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber3);
1687     std::unique_ptr<RegexRule> regexRule3 =
1688         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1689     if (maybeNumber != nullptr) {
1690         PhoneNumberMatch* pnMatch = regexRule3->IsValid(maybeNumber.get(), message);
1691         EXPECT_TRUE(pnMatch == nullptr);
1692     }
1693 }
1694 
1695 /**
1696  * @tc.name: IntlFuncTest0095
1697  * @tc.desc: Test RegexRule
1698  * @tc.type: FUNC
1699  */
1700 HWTEST_F(IntlTest, IntlFuncTest0095, TestSize.Level1)
1701 {
1702     using namespace i18n::phonenumbers;
1703     std::string regexStr = "\\d{3}";
1704     icu::UnicodeString regex(regexStr.c_str());
1705     std::string isValidType = "PreSuf";
1706     std::string insensitive = "False";
1707     std::string handleType = "EndWithMobile";
1708     std::string type = "xxx";
1709     std::string msg = "00222a-1 800 234 45 67a@";
1710     icu::UnicodeString message(msg.c_str());
1711     i18n::phonenumbers::PhoneNumber phoneNumber;
1712     size_t start = 10;
1713     std::string rawStr = "1 800 234 45 67";
1714     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1715         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1716     std::unique_ptr<RegexRule> regexRule =
1717         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1718     if (possibleNumber != nullptr) {
1719         PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1720         EXPECT_TRUE(match != nullptr);
1721     }
1722 
1723     isValidType = "Code";
1724     rawStr = "0106857628100000001";
1725     start = 0;
1726     i18n::phonenumbers::PhoneNumber phoneNumber2;
1727     std::unique_ptr<PhoneNumberMatch> possibleNum =
1728         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1729     std::unique_ptr<RegexRule> regexRule2 =
1730         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1731     if (possibleNum != nullptr) {
1732         PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1733         EXPECT_TRUE(pnMatch == nullptr);
1734     }
1735 }
1736 
1737 /**
1738  * @tc.name: IntlFuncTest0096
1739  * @tc.desc: Test RegexRule
1740  * @tc.type: FUNC
1741  */
1742 HWTEST_F(IntlTest, IntlFuncTest0096, TestSize.Level1)
1743 {
1744     using namespace i18n::phonenumbers;
1745     std::string regexStr = "\\d{3}";
1746     icu::UnicodeString regex(regexStr.c_str());
1747     std::string isValidType = "PreSuf";
1748     std::string insensitive = "False";
1749     std::string handleType = "EndWithMobile";
1750     std::string type = "xxx";
1751     std::string msg = "--a86753564";
1752     icu::UnicodeString message(msg.c_str());
1753     i18n::phonenumbers::PhoneNumber phoneNumber;
1754     size_t start = 3;
1755     std::string rawStr = "86753564";
1756     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1757         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1758     std::unique_ptr<RegexRule> regexRule =
1759         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1760     ASSERT_TRUE(possibleNumber != nullptr);
1761     PhoneNumberMatch* match = regexRule->IsValid(possibleNumber.get(), message);
1762     EXPECT_TRUE(match != nullptr);
1763     msg = "a1A86753564";
1764     icu::UnicodeString message1(msg.c_str());
1765     regexRule->IsValid(possibleNumber.get(), message1);
1766     msg = "0aA86753564";
1767     icu::UnicodeString message2(msg.c_str());
1768     regexRule->IsValid(possibleNumber.get(), message2);
1769     msg = "-AA86753564";
1770     icu::UnicodeString message3(msg.c_str());
1771     regexRule->IsValid(possibleNumber.get(), message3);
1772     msg = "2AA86753564";
1773     icu::UnicodeString message4(msg.c_str());
1774     regexRule->IsValid(possibleNumber.get(), message4);
1775     msg = "@AA86753564";
1776     icu::UnicodeString message5(msg.c_str());
1777     regexRule->IsValid(possibleNumber.get(), message5);
1778     msg = "cAA86753564";
1779     icu::UnicodeString message6(msg.c_str());
1780     PhoneNumberMatch* match6 = regexRule->IsValid(possibleNumber.get(), message6);
1781     EXPECT_TRUE(match6 != nullptr);
1782     regexRule->Handle(possibleNumber.get(), message);
1783 }
1784 
1785 /**
1786  * @tc.name: IntlFuncTest0097
1787  * @tc.desc: Test Intl I18nCalendarMock
1788  * @tc.type: FUNC
1789  */
1790 HWTEST_F(IntlTest, IntlFuncTest0097, TestSize.Level1)
1791 {
1792     std::unique_ptr<I18nCalendarMock> calendarMock = std::make_unique<I18nCalendarMock>("zh-Hans-CN");
1793     EXPECT_CALL(*calendarMock, GetIcuCalendar())
1794     .WillRepeatedly(Return(nullptr));
1795 
1796     calendarMock->SetTime(1684742124645);
1797     calendarMock->Get(UCalendarDateFields::UCAL_YEAR);
1798     calendarMock->SetFirstDayOfWeek(-1);
1799     calendarMock->GetTimeInMillis();
1800 
1801     calendarMock->GetMinimalDaysInFirstWeek();
1802     int32_t minimalDaysInFirstWeek = calendarMock->GetMinimalDaysInFirstWeek();
1803     EXPECT_EQ(minimalDaysInFirstWeek, 1);
1804     int32_t firstDayOfWeek = calendarMock->GetFirstDayOfWeek();
1805     EXPECT_EQ(firstDayOfWeek, 1);
1806     calendarMock->Set(2023, 5, 28);
1807     UErrorCode status = U_ZERO_ERROR;
1808     calendarMock->IsWeekend(168473854645, status);
1809     calendarMock->CompareDays(1684742124650);
1810     bool isWeekend = calendarMock->IsWeekend();
1811     EXPECT_FALSE(isWeekend);
1812     std::string localeTag = "en";
1813     std::string displayName = calendarMock->GetDisplayName(localeTag);
1814     EXPECT_EQ(displayName, "");
1815 }
1816 
1817 /**
1818  * @tc.name: IntlFuncTest0098
1819  * @tc.desc: Test Intl multi users
1820  * @tc.type: FUNC
1821  */
1822 HWTEST_F(IntlTest, IntlFuncTest0098, TestSize.Level1)
1823 {
1824 #ifdef SUPPORT_MULTI_USER
1825     std::string path = "/data/service/el1/public/i18n/global/GlobalParamData";
1826     OHOS::NativePreferences::Options opt(path);
1827     int status;
1828     std::shared_ptr<NativePreferences::Preferences> preferences =
1829         NativePreferences::PreferencesHelper::GetPreferences(opt, status);
1830     MultiUsers::AddUser("101");
1831     MultiUsers::SwitchUser("101");
1832     MultiUsers::RemoveUser("100");
1833     if (preferences != nullptr) {
1834         std::string language = preferences->GetString("languageData", "");
1835         std::string locale = preferences->GetString("localeData", "");
1836         std::string is24Hour = preferences->GetString("is24HourData", "");
1837         EXPECT_EQ(language, "101:zh-Hans");
1838         EXPECT_EQ(locale, "101:zh-Hans-CN");
1839         EXPECT_EQ(is24Hour, "101:false");
1840     }
1841     MultiUsers::RemoveUser("101");
1842     if (preferences != nullptr) {
1843         std::string language = preferences->GetString("languageData", "");
1844         std::string locale = preferences->GetString("localeData", "");
1845         std::string is24Hour = preferences->GetString("is24HourData", "");
1846         EXPECT_EQ(language, "");
1847         EXPECT_EQ(locale, "");
1848         EXPECT_EQ(is24Hour, "");
1849     }
1850 #endif
1851 }
1852 
1853 /**
1854  * @tc.name: IntlFuncTest0099
1855  * @tc.desc: Test CodeRule
1856  * @tc.type: FUNC
1857  */
1858 HWTEST_F(IntlTest, IntlFuncTest0099, TestSize.Level1)
1859 {
1860     std::string isValidType = "PreSuf";
1861     std::string msg = "1 800 234 45";
1862     icu::UnicodeString message(msg.c_str());
1863     i18n::phonenumbers::PhoneNumber phoneNumber;
1864     size_t start = 0;
1865     std::string rawStr = "1 800 234 45 67";
1866     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1867         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1868     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1869     ASSERT_TRUE(possibleNumber != nullptr);
1870     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1871     EXPECT_TRUE(match != nullptr);
1872 }
1873 
1874 /**
1875  * @tc.name: IntlFuncTest00100
1876  * @tc.desc: Test CodeRule
1877  * @tc.type: FUNC
1878  */
1879 HWTEST_F(IntlTest, IntlFuncTest00100, TestSize.Level1)
1880 {
1881     std::string isValidType = "PreSuf";
1882     std::string msg = "0ca1 800 234 45 67";
1883     icu::UnicodeString message(msg.c_str());
1884     i18n::phonenumbers::PhoneNumber phoneNumber;
1885     size_t start = 3;
1886     std::string rawStr = "1 800 234 45 67";
1887     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1888         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1889     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1890     ASSERT_TRUE(possibleNumber != nullptr);
1891     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1892     EXPECT_TRUE(match != nullptr);
1893     msg = "abA1 800 234 45 67";
1894     icu::UnicodeString message2(msg.c_str());
1895     PhoneNumberMatch* match2 = codeRule->IsValid(possibleNumber.get(), message2);
1896     EXPECT_TRUE(match2 != nullptr);
1897     msg = "0aA1 800 234 45 67";
1898     icu::UnicodeString message3(msg.c_str());
1899     PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber.get(), message3);
1900     EXPECT_TRUE(match3 != nullptr);
1901     msg = "-AA1 800 234 45 67";
1902     icu::UnicodeString message4(msg.c_str());
1903     PhoneNumberMatch* match4 = codeRule->IsValid(possibleNumber.get(), message4);
1904     EXPECT_TRUE(match4 != nullptr);
1905     msg = "3AA1 800 234 45 67";
1906     icu::UnicodeString message5(msg.c_str());
1907     PhoneNumberMatch* match5 = codeRule->IsValid(possibleNumber.get(), message5);
1908     EXPECT_TRUE(match5 == nullptr);
1909     msg = "$AA1 800 234 45 67";
1910     icu::UnicodeString message6(msg.c_str());
1911     PhoneNumberMatch* match6 = codeRule->IsValid(possibleNumber.get(), message6);
1912     EXPECT_TRUE(match6 == nullptr);
1913     msg = "vAA1 800 234 45 67";
1914     icu::UnicodeString message7(msg.c_str());
1915     PhoneNumberMatch* match7 = codeRule->IsValid(possibleNumber.get(), message7);
1916     EXPECT_TRUE(match7 != nullptr);
1917 }
1918 
1919 /**
1920  * @tc.name: IntlFuncTest00101
1921  * @tc.desc: Test CodeRule
1922  * @tc.type: FUNC
1923  */
1924 HWTEST_F(IntlTest, IntlFuncTest00101, TestSize.Level1)
1925 {
1926     std::string isValidType = "Rawstr";
1927     std::string msg = "13649372A-";
1928     icu::UnicodeString message(msg.c_str());
1929     i18n::phonenumbers::PhoneNumber phoneNumber;
1930     size_t start = 0;
1931     std::string rawStr = "13649372;ext=123";
1932     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1933         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1934     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1935     ASSERT_TRUE(possibleNumber != nullptr);
1936     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1937     if (match != nullptr) {
1938         EXPECT_EQ(match->raw_string(), rawStr);
1939     }
1940     PhoneNumberMatch* match2 = codeRule->IsValid(nullptr, message);
1941     EXPECT_TRUE(match2 == nullptr);
1942     rawStr = "12345678";
1943     std::unique_ptr<PhoneNumberMatch> possibleNumber2 =
1944         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1945     ASSERT_TRUE(possibleNumber2 != nullptr);
1946     PhoneNumberMatch* match3 = codeRule->IsValid(possibleNumber2.get(), message);
1947     EXPECT_TRUE(match3 == nullptr);
1948 }
1949 
1950 /**
1951  * @tc.name: IntlFuncTest00102
1952  * @tc.desc: Test CodeRule
1953  * @tc.type: FUNC
1954  */
1955 HWTEST_F(IntlTest, IntlFuncTest00102, TestSize.Level1)
1956 {
1957     std::string isValidType = "Rawstr";
1958     std::string msg = "400A-";
1959     icu::UnicodeString message(msg.c_str());
1960     i18n::phonenumbers::PhoneNumber phoneNumber;
1961     size_t start = 0;
1962     std::string rawStr = "400";
1963     std::unique_ptr<PhoneNumberMatch> possibleNumber =
1964         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber);
1965     std::unique_ptr<CodeRule> codeRule = std::make_unique<CodeRule>(isValidType);
1966     ASSERT_TRUE(possibleNumber != nullptr);
1967     PhoneNumberMatch* match = codeRule->IsValid(possibleNumber.get(), message);
1968     EXPECT_TRUE(match == nullptr);
1969 }
1970 
1971 /**
1972  * @tc.name: IntlFuncTest00103
1973  * @tc.desc: Test RegexRule
1974  * @tc.type: FUNC
1975  */
1976 HWTEST_F(IntlTest, IntlFuncTest00103, TestSize.Level1)
1977 {
1978     using namespace i18n::phonenumbers;
1979     std::string regexStr = "\\d{3}";
1980     icu::UnicodeString regex(regexStr.c_str());
1981     std::string isValidType = "Rawstr";
1982     std::string insensitive = "False";
1983     std::string handleType = "EndWithMobile";
1984     std::string type = "xxx";
1985     std::string msg = "--a86753564";
1986     icu::UnicodeString message(msg.c_str());
1987     std::string rawStr = "10645656";
1988     size_t start = 0;
1989     i18n::phonenumbers::PhoneNumber phoneNumber2;
1990     std::unique_ptr<PhoneNumberMatch> possibleNum =
1991         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber2);
1992     std::unique_ptr<RegexRule> regexRule2 =
1993         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
1994     ASSERT_TRUE(possibleNum != nullptr);
1995     PhoneNumberMatch* pnMatch = regexRule2->IsValid(possibleNum.get(), message);
1996     EXPECT_TRUE(pnMatch == nullptr);
1997 
1998     isValidType = "Rawstr";
1999     rawStr = "119";
2000     start = 0;
2001     i18n::phonenumbers::PhoneNumber phoneNumber3;
2002     std::unique_ptr<PhoneNumberMatch> posibleNumber =
2003         std::make_unique<PhoneNumberMatch>(start, rawStr, phoneNumber3);
2004     std::unique_ptr<RegexRule> regexRule3 =
2005         std::make_unique<RegexRule>(regex, isValidType, handleType, insensitive, type);
2006     ASSERT_TRUE(posibleNumber != nullptr);
2007     PhoneNumberMatch* pMatch = regexRule3->IsValid(posibleNumber.get(), message);
2008     EXPECT_TRUE(pMatch == nullptr);
2009 }
2010 
2011 /**
2012  * @tc.name: IntlFuncTest00104
2013  * @tc.desc: Test DateTimeFormat
2014  * @tc.type: FUNC
2015  */
2016 HWTEST_F(IntlTest, IntlFuncTest00104, TestSize.Level1)
2017 {
2018     icu::UnicodeString pattern = DateTimeFormat::GetPatternFromLocale("123");
2019     EXPECT_EQ(pattern, "");
2020     pattern = DateTimeFormat::GetPatternFromLocale("zh-Hans-CN");
2021     EXPECT_EQ(pattern, "y/M/d");
2022 
2023     auto patterns = DateTimeFormat::GetPatternsFromLocale("zh-Hans-CN");
2024     EXPECT_EQ(patterns.size(), 11);
2025 
2026     pattern = DateTimeFormat::GetYMDPatternFromNumber("0001");
2027     EXPECT_EQ(pattern, "d/MM/y");
2028     pattern = DateTimeFormat::GetYMDPatternFromNumber("0013");
2029     EXPECT_EQ(pattern, "");
2030 
2031     std::string dateSample = DateTimeFormat::GetDateSampleFromPattern("d/MM/y", "zh-Hans-CN");
2032     EXPECT_EQ(dateSample, "18/07/2025");
2033 
2034     pattern = DateTimeFormat::GetSingleDayPatternFromLocale("zh-Hans-CN");
2035     EXPECT_EQ(pattern, "y/M/d");
2036 
2037     bool isValid = DateTimeFormat::IsValidPatternNumber("0001");
2038     EXPECT_EQ(isValid, true);
2039     isValid = DateTimeFormat::IsValidPatternNumber("0021");
2040     EXPECT_EQ(isValid, false);
2041 }
2042 } // namespace I18n
2043 } // namespace Global
2044 } // namespace OHOS