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