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