1 /*
2  * Copyright (c) 2022 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 <gtest/gtest.h>
17 #include "entity_recognizer.h"
18 #include "i18n_break_iterator.h"
19 #include "i18n_calendar.h"
20 #include "i18n_normalizer.h"
21 #include "i18n_timezone_mock.h"
22 #include "locale_config.h"
23 #include "locale_info.h"
24 #include "locale_matcher.h"
25 #include "locale_util.h"
26 #include "lunar_calendar.h"
27 #include "measure_data.h"
28 #include "phone_number_format_mock.h"
29 #include "preferred_language.h"
30 
31 using namespace OHOS::Global::I18n;
32 using testing::ext::TestSize;
33 using namespace std;
34 
35 namespace OHOS {
36 namespace Global {
37 namespace I18n {
38 class I18nTest : public testing::Test {
39 public:
40     static void SetUpTestCase(void);
41     static void TearDownTestCase(void);
42     void SetUp();
43     void TearDown();
44 };
45 
SetUpTestCase(void)46 void I18nTest::SetUpTestCase(void)
47 {}
48 
TearDownTestCase(void)49 void I18nTest::TearDownTestCase(void)
50 {}
51 
SetUp(void)52 void I18nTest::SetUp(void)
53 {}
54 
TearDown(void)55 void I18nTest::TearDown(void)
56 {}
57 
58 /**
59  * @tc.name: I18nFuncTest001
60  * @tc.desc: Test I18n PreferredLanguage GetPreferredLocale
61  * @tc.type: FUNC
62  */
63 HWTEST_F(I18nTest, I18nFuncTest001, TestSize.Level1)
64 {
65     string preferredLocale = PreferredLanguage::GetPreferredLocale();
66     EXPECT_TRUE(preferredLocale.size() > 0);
67     string systemLocale = "zh-Hans-CN";
68     I18nErrorCode status = LocaleConfig::SetSystemLocale(systemLocale);
69     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
70     status = PreferredLanguage::AddPreferredLanguage("en-US", 0);
71     EXPECT_EQ(status, I18nErrorCode::SUCCESS);
72     preferredLocale = PreferredLanguage::GetPreferredLocale();
73     EXPECT_EQ(preferredLocale, "en-CN");
74     PreferredLanguage::RemovePreferredLanguage(0);
75 #ifdef SUPPORT_APP_PREFERRED_LANGUAGE
76     I18nErrorCode errCode = I18nErrorCode::SUCCESS;
77     PreferredLanguage::SetAppPreferredLanguage("en-US", errCode);
78     EXPECT_EQ(errCode, I18nErrorCode::SUCCESS);
79     std::string appPreferLanguage = PreferredLanguage::GetAppPreferredLanguage();
80     EXPECT_EQ(appPreferLanguage, "en-US");
81 #endif
82 }
83 
84 /**
85  * @tc.name: I18nFuncTest002
86  * @tc.desc: Test I18n Normalizer
87  * @tc.type: FUNC
88  */
89 HWTEST_F(I18nTest, I18nFuncTest002, TestSize.Level1)
90 {
91     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
92     I18nNormalizer normalizer(I18nNormalizerMode::NFD, errorCode);
93     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
94 
95     string text = "\uFB01"; // \uFB01 is fi
96     string normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
97     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
98     EXPECT_EQ(normalizedText.length(), 3); // 3 is the NFD normalized length of fi.
99     EXPECT_EQ(normalizedText, "\uFB01");
100 
101     text = "\u0032\u2075";
102     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
103     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
104     EXPECT_EQ(normalizedText.length(), 4); // 4 is the expected normalized text length.
105     EXPECT_EQ(normalizedText, "\u0032\u2075");
106 
107     text = "\u1E9B\u0323";
108     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
109     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
110     EXPECT_EQ(normalizedText.length(), 6); // 6 is the expected normalized text length.
111     EXPECT_EQ(normalizedText, "\u017F\u0323\u0307");
112     std::string result = normalizer.Normalize(nullptr, 0, errorCode);
113     EXPECT_EQ(result, "");
114 }
115 
116 /**
117  * @tc.name: I18nFuncTest003
118  * @tc.desc: Test I18n Normalizer
119  * @tc.type: FUNC
120  */
121 HWTEST_F(I18nTest, I18nFuncTest003, TestSize.Level1)
122 {
123     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
124     I18nNormalizer normalizer(I18nNormalizerMode::NFC, errorCode);
125     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
126 
127     string text = "\uFB01"; // \uFB01 is fi
128     string normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
129     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
130     EXPECT_EQ(normalizedText.length(), 3); // 3 is the NFC normalized length of fi.
131     EXPECT_EQ(normalizedText, "\uFB01");
132 
133     text = "\u0032\u2075";
134     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
135     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
136     EXPECT_EQ(normalizedText.length(), 4); // 4 is the expected normalized text length.
137     EXPECT_EQ(normalizedText, "\u0032\u2075");
138 
139     text = "\u1E9B\u0323";
140     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
141     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
142     EXPECT_EQ(normalizedText.length(), 5); // 5 is the expected normalized text length.
143     EXPECT_EQ(normalizedText, "\u1E9B\u0323");
144 }
145 
146 /**
147  * @tc.name: I18nFuncTest004
148  * @tc.desc: Test I18n Normalizer
149  * @tc.type: FUNC
150  */
151 HWTEST_F(I18nTest, I18nFuncTest004, TestSize.Level1)
152 {
153     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
154     I18nNormalizer normalizer(I18nNormalizerMode::NFKD, errorCode);
155     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
156 
157     string text = "\uFB01"; // \uFB01 is fi
158     string normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
159     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
160     EXPECT_EQ(normalizedText.length(), 2); // 2 is the NFKD normalized length of fi.
161     EXPECT_EQ(normalizedText, "\u0066\u0069");
162 
163     text = "\u0032\u2075";
164     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
165     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
166     EXPECT_EQ(normalizedText.length(), 2); // 2 is the expected normalized text length.
167     EXPECT_EQ(normalizedText, "\u0032\u0035");
168 
169     text = "\u1E9B\u0323";
170     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
171     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
172     EXPECT_EQ(normalizedText.length(), 5); // 5 is the expected normalized text length.
173     EXPECT_EQ(normalizedText, "\u0073\u0323\u0307");
174 }
175 
176 /**
177  * @tc.name: I18nFuncTest005
178  * @tc.desc: Test I18n Normalizer
179  * @tc.type: FUNC
180  */
181 HWTEST_F(I18nTest, I18nFuncTest005, TestSize.Level1)
182 {
183     I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
184     I18nNormalizer normalizer(I18nNormalizerMode::NFKC, errorCode);
185     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
186 
187     string text = "\uFB01"; // \uFB01 is fi
188     string normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
189     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
190     EXPECT_EQ(normalizedText.length(), 2); // 2 is the NFKC normalized length of fi.
191     EXPECT_EQ(normalizedText, "\u0066\u0069");
192 
193     text = "\u0032\u2075";
194     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
195     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
196     EXPECT_EQ(normalizedText.length(), 2); // 2 is the expected normalized text length.
197     EXPECT_EQ(normalizedText, "\u0032\u0035");
198 
199     text = "\u1E9B\u0323";
200     normalizedText = normalizer.Normalize(text.c_str(), text.length(), errorCode);
201     EXPECT_EQ(errorCode, I18nErrorCode::SUCCESS);
202     EXPECT_EQ(normalizedText.length(), 3); // 3 is the expected normalized text length.
203     EXPECT_EQ(normalizedText, "\u1E69");
204 }
205 
206 /**
207  * @tc.name: I18nFuncTest006
208  * @tc.desc: Test I18n I18nCalendar
209  * @tc.type: FUNC
210  */
211 HWTEST_F(I18nTest, I18nFuncTest006, TestSize.Level1)
212 {
213     I18nCalendar buddhistCalendar("zh-Hans", CalendarType::BUDDHIST);
214     buddhistCalendar.Set(UCalendarDateFields::UCAL_YEAR, 2023);
215     int32_t year = buddhistCalendar.Get(UCalendarDateFields::UCAL_YEAR);
216     EXPECT_EQ(year, 2023);
217     I18nCalendar chineseCalendar("zh-Hans", CalendarType::CHINESE);
218     chineseCalendar.SetMinimalDaysInFirstWeek(3);
219     int32_t minimalDaysInFirstWeek = chineseCalendar.GetMinimalDaysInFirstWeek();
220     EXPECT_EQ(minimalDaysInFirstWeek, 3);
221     I18nCalendar copticCalendar("zh-Hans", CalendarType::COPTIC);
222     copticCalendar.SetFirstDayOfWeek(2);
223     int32_t firstDayOfWeek = copticCalendar.GetFirstDayOfWeek();
224     EXPECT_EQ(firstDayOfWeek, 2);
225     I18nCalendar ethiopicCalendar("zh-Hans", CalendarType::ETHIOPIC);
226     int64_t date = 1687244448234;
227     UErrorCode status = U_ZERO_ERROR;
228     bool isWeekend = ethiopicCalendar.IsWeekend(date, status);
229     EXPECT_EQ(isWeekend, false);
230     I18nCalendar hebrewCalendar("zh-Hans", CalendarType::HEBREW);
231     std::string displayLocaleTag = "en-US";
232     std::string displayName = hebrewCalendar.GetDisplayName(displayLocaleTag);
233     EXPECT_EQ(displayName, "Hebrew Calendar");
234     I18nCalendar gregoryCalendar("zh-Hans", CalendarType::GREGORY);
235     gregoryCalendar.Set(UCalendarDateFields::UCAL_MONTH, 2);
236     int32_t month = gregoryCalendar.Get(UCalendarDateFields::UCAL_MONTH);
237     EXPECT_EQ(month, 2);
238     I18nCalendar indianCalendar("zh-Hans", CalendarType::INDIAN);
239     indianCalendar.Set(UCalendarDateFields::UCAL_WEEK_OF_YEAR, 10);
240     int32_t weekOfYear = indianCalendar.Get(UCalendarDateFields::UCAL_WEEK_OF_YEAR);
241     EXPECT_EQ(weekOfYear, 10);
242     I18nCalendar islamicCivilCalendar("zh-Hans", CalendarType::ISLAMIC_CIVIL);
243     islamicCivilCalendar.Set(UCalendarDateFields::UCAL_WEEK_OF_MONTH, 2);
244     int32_t weekOfMonth = islamicCivilCalendar.Get(UCalendarDateFields::UCAL_WEEK_OF_MONTH);
245     EXPECT_EQ(weekOfMonth, 2);
246     I18nCalendar islamicTblaCalendar("zh-Hans", CalendarType::ISLAMIC_TBLA);
247     islamicTblaCalendar.Set(UCalendarDateFields::UCAL_DATE, 3);
248     int32_t dateValue = islamicTblaCalendar.Get(UCalendarDateFields::UCAL_DATE);
249     EXPECT_EQ(dateValue, 3);
250     I18nCalendar islamicUmalquraCalendar("zh-Hans", CalendarType::ISLAMIC_UMALQURA);
251     islamicUmalquraCalendar.Set(UCalendarDateFields::UCAL_DAY_OF_YEAR, 123);
252     int32_t dayOfYear = islamicUmalquraCalendar.Get(UCalendarDateFields::UCAL_DAY_OF_YEAR);
253     EXPECT_EQ(dayOfYear, 123);
254     I18nCalendar japaneseCalendar("zh-Hans", CalendarType::JAPANESE);
255     japaneseCalendar.Set(UCalendarDateFields::UCAL_DAY_OF_WEEK, 3);
256     int32_t dayOfWeek = japaneseCalendar.Get(UCalendarDateFields::UCAL_DAY_OF_WEEK);
257     EXPECT_EQ(dayOfWeek, 3);
258 }
259 
260 /**
261  * @tc.name: I18nFuncTest007
262  * @tc.desc: Test I18n I18nCalendar
263  * @tc.type: FUNC
264  */
265 HWTEST_F(I18nTest, I18nFuncTest007, TestSize.Level1)
266 {
267     I18nCalendar persianTblaCalendar("zh-Hans", CalendarType::PERSIAN);
268     persianTblaCalendar.Set(UCalendarDateFields::UCAL_DAY_OF_WEEK_IN_MONTH, 1);
269     int32_t dayOfWeekInMonth = persianTblaCalendar.Get(UCalendarDateFields::UCAL_DAY_OF_WEEK_IN_MONTH);
270     EXPECT_EQ(dayOfWeekInMonth, 1);
271     I18nCalendar defaultCalendar("zh-Hans", CalendarType::UNDEFINED);
272     defaultCalendar.Set(UCalendarDateFields::UCAL_HOUR, 12);
273     int32_t hour = defaultCalendar.Get(UCalendarDateFields::UCAL_HOUR);
274     EXPECT_EQ(hour, 0);
275     defaultCalendar.Set(UCalendarDateFields::UCAL_YEAR, 100);
276     defaultCalendar.Add(UCalendarDateFields::UCAL_YEAR, 100);
277     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_YEAR), 200);
278     defaultCalendar.Set(UCalendarDateFields::UCAL_MONTH, 10);
279     defaultCalendar.Add(UCalendarDateFields::UCAL_MONTH, 2);
280     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_MONTH), 0);
281     defaultCalendar.Set(UCalendarDateFields::UCAL_DATE, 20);
282     defaultCalendar.Add(UCalendarDateFields::UCAL_DATE, 15);
283     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_DATE), 4);
284     defaultCalendar.Set(UCalendarDateFields::UCAL_HOUR, 10);
285     defaultCalendar.Add(UCalendarDateFields::UCAL_HOUR, 11);
286     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_HOUR), 9);
287     defaultCalendar.Set(UCalendarDateFields::UCAL_MINUTE, 31);
288     defaultCalendar.Add(UCalendarDateFields::UCAL_MINUTE, 31);
289     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_MINUTE), 2);
290     defaultCalendar.Set(UCalendarDateFields::UCAL_SECOND, 21);
291     defaultCalendar.Add(UCalendarDateFields::UCAL_SECOND, 51);
292     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_SECOND), 12);
293     defaultCalendar.Set(UCalendarDateFields::UCAL_MILLISECOND, 1000);
294     defaultCalendar.Add(UCalendarDateFields::UCAL_MILLISECOND, 165);
295     EXPECT_EQ(defaultCalendar.Get(UCalendarDateFields::UCAL_MILLISECOND), 165);
296     defaultCalendar.Set(2023, 8, 2);
297     UDate millis = defaultCalendar.GetTimeInMillis();
298     I18nCalendar checkCalendar("zh-Hans", CalendarType::UNDEFINED);
299     checkCalendar.SetTime(millis);
300     EXPECT_EQ(checkCalendar.Get(UCalendarDateFields::UCAL_YEAR), 2023);
301     EXPECT_EQ(checkCalendar.Get(UCalendarDateFields::UCAL_MONTH), 8);
302     EXPECT_EQ(checkCalendar.Get(UCalendarDateFields::UCAL_DATE), 2);
303     defaultCalendar.SetTime(1684742124645);
304     int32_t compareDays = defaultCalendar.CompareDays(1684742124650);
305     EXPECT_EQ(compareDays, 1);
306 }
307 
308 /**
309  * @tc.name: I18nFuncTest008
310  * @tc.desc: Test I18n I18nBreakIterator
311  * @tc.type: FUNC
312  */
313 HWTEST_F(I18nTest, I18nFuncTest008, TestSize.Level1)
314 {
315     std::string fakeLocaleTag = "FakeLocaleTag";
316     I18nBreakIterator brkIterator(fakeLocaleTag);
317     int32_t res = brkIterator.Current();
318     EXPECT_EQ(res, 0);
319     res = brkIterator.First();
320     EXPECT_EQ(res, 0);
321     res = brkIterator.Last();
322     EXPECT_EQ(res, 0);
323     res = brkIterator.Previous();
324     EXPECT_EQ(res, -1);
325     int32_t offset = 1;
326     res = brkIterator.Next(offset);
327     EXPECT_EQ(res, -1);
328     res = brkIterator.Next();
329     EXPECT_EQ(res, -1);
330     res = brkIterator.Following(offset);
331     EXPECT_EQ(res, -1);
332     bool status = brkIterator.IsBoundary(offset);
333     EXPECT_FALSE(status);
334 
335     std::string localeTag = "en-Latn-US";
336     I18nBreakIterator enBrkIterator(localeTag);
337     std::string text = "Test I18nBreakIterator";
338     enBrkIterator.SetText(text.c_str());
339     std::string resText;
340     enBrkIterator.GetText(resText);
341     EXPECT_EQ(resText, text);
342     res = enBrkIterator.Next();
343     EXPECT_EQ(res, 5);
344 }
345 
346 /**
347  * @tc.name: I18nFuncTest009
348  * @tc.desc: Test I18n MeasureData GetDefaultPreferredUnit
349  * @tc.type: FUNC
350  */
351 HWTEST_F(I18nTest, I18nFuncTest009, TestSize.Level1)
352 {
353     std::string regionTags[] = {"GB", "US", "CN"};
354     std::string usage = "length";
355     std::vector<std::string> units;
356     for (size_t i = 0; i < sizeof(regionTags) / sizeof(std::string); ++i) {
357         GetDefaultPreferredUnit(regionTags[i], usage, units);
358         EXPECT_EQ(units.size(), 3);
359         units.clear();
360     }
361 }
362 
363 /**
364  * @tc.name: I18nFuncTest010
365  * @tc.desc: Test I18n MeasureData GetFallbackPreferredUnit
366  * @tc.type: FUNC
367  */
368 HWTEST_F(I18nTest, I18nFuncTest010, TestSize.Level1)
369 {
370     std::string regionTags1[] = {"MX", "NL", "NO", "PL", "RU"};
371     std::string usage = "length-person-informal";
372     std::vector<std::string> units;
373     for (size_t i = 0; i < sizeof(regionTags1) / sizeof(std::string); ++i) {
374         GetFallbackPreferredUnit(regionTags1[i], usage, units);
375         EXPECT_EQ(units.size(), 2);
376         units.clear();
377     }
378 
379     std::string regionTag2 = "SE";
380     usage = "length-person";
381     GetFallbackPreferredUnit(regionTag2, usage, units);
382     EXPECT_EQ(units.size(), 2);
383     units.clear();
384 
385     std::string regionTags3[] = {"US", "CN"};
386     for (size_t i = 0; i < sizeof(regionTags3) / sizeof(std::string); ++i) {
387         GetFallbackPreferredUnit(regionTags3[i], usage, units);
388         EXPECT_EQ(units.size(), 1);
389         units.clear();
390     }
391 }
392 
393 /**
394  * @tc.name: I18nFuncTest011
395  * @tc.desc: Test I18n MeasureData GetRestPreferredUnit
396  * @tc.type: FUNC
397  */
398 HWTEST_F(I18nTest, I18nFuncTest011, TestSize.Level1)
399 {
400     std::string regionTags1[] = {"CA", "IN"};
401     std::string usage = "length-person";
402     std::vector<std::string> units;
403     for (size_t i = 0; i < sizeof(regionTags1) / sizeof(std::string); ++i) {
404         GetRestPreferredUnit(regionTags1[i], usage, units);
405         EXPECT_EQ(units.size(), 1);
406         units.clear();
407     }
408 
409     std::string regionTags2[] = {"CN", "DK", "PT", "DE", "GB"};
410     usage = "length-person-informal";
411     for (size_t i = 0; i < sizeof(regionTags2) / sizeof(std::string); ++i) {
412         GetRestPreferredUnit(regionTags2[i], usage, units);
413         EXPECT_EQ(units.size(), 2);
414         units.clear();
415     }
416 
417     std::string regionTag3 = "KR";
418     usage = "speed-wind";
419     GetRestPreferredUnit(regionTag3, usage, units);
420     EXPECT_EQ(units.size(), 1);
421     units.clear();
422 
423     std::string regionTag4 = "XX";
424     usage = "fake usage";
425     GetRestPreferredUnit(regionTag4, usage, units);
426     EXPECT_EQ(units.size(), 0);
427 }
428 
429 /**
430  * @tc.name: I18nFuncTest012
431  * @tc.desc: Test I18n MeasureData GetPreferredUnit
432  * @tc.type: FUNC
433  */
434 HWTEST_F(I18nTest, I18nFuncTest012, TestSize.Level1)
435 {
436     std::string regionTags1[] = {
437         "AT", "BE", "DZ", "EG", "ES", "FR", "HK", "ID", "IL", "IT", "JO", "MY", "SA", "TR", "VN"
438     };
439     std::string usage = "length-person";
440     std::vector<std::string> units;
441     for (size_t i = 0; i < sizeof(regionTags1) / sizeof(std::string); ++i) {
442         GetPreferredUnit(regionTags1[i], usage, units);
443         EXPECT_EQ(units.size(), 2);
444         units.clear();
445     }
446 
447     std::string regionTag2 = "BR";
448     usage = "length-person-informal";
449     GetPreferredUnit(regionTag2, usage, units);
450     EXPECT_EQ(units.size(), 2);
451     units.clear();
452 
453     std::string regionTags3[] = {"BS", "BZ", "PR", "PW"};
454     usage = "temperature-weather";
455     for (size_t i = 0; i < sizeof(regionTags3) / sizeof(std::string); i++) {
456         GetPreferredUnit(regionTags3[i], usage, units);
457         EXPECT_EQ(units.size(), 1);
458         units.clear();
459     }
460 
461     std::string regionTag4 = "XX";
462     usage = "fake usage";
463     GetPreferredUnit(regionTag4, usage, units);
464     EXPECT_EQ(units.size(), 0);
465 }
466 
467 /**
468  * @tc.name: I18nFuncTest013
469  * @tc.desc: Test I18n MeasureData
470  * @tc.type: FUNC
471  */
472 HWTEST_F(I18nTest, I18nFuncTest013, TestSize.Level1)
473 {
474     double value = 10.0;
475     std::string fromUnit = "acre";
476     std::string fromMeasSys = "US";
477     std::string toUnit = "foot";
478     std::string toMeasSys = "US";
479     int status = Convert(value, fromUnit, fromMeasSys, toUnit, toMeasSys);
480     EXPECT_EQ(status, 0);
481 
482     std::string fakeUnit = "fake unit";
483     status = Convert(value, fakeUnit, fromMeasSys, toUnit, toMeasSys);
484     EXPECT_EQ(status, 0);
485     status = Convert(value, fromUnit, fromMeasSys, fakeUnit, toMeasSys);
486     EXPECT_EQ(status, 0);
487 
488     toUnit = "hectare";
489     status = Convert(value, fromUnit, fromMeasSys, toUnit, toMeasSys);
490     EXPECT_EQ(status, 1);
491     EXPECT_TRUE(fabs(value - 4.0468564) < 1e-6);
492 
493     std::string unit = "tablespoon";
494     std::string measSys = "UK";
495     std::vector<double> factors = {0.0, 0.0};
496     ComputeFactorValue(unit, measSys, factors);
497     EXPECT_EQ(factors.size(), 2);
498     EXPECT_TRUE(fabs(factors[0] - 1.77582e-05) < 1e-6);
499     unit = "acre";
500     factors = {0.0, 0.0};
501     ComputeFactorValue(unit, measSys, factors);
502     EXPECT_EQ(factors.size(), 2);
503     EXPECT_TRUE(fabs(factors[0] - 4046.856422) < 1e-6);
504 
505     double res = ComputeSIPrefixValue(unit);
506     EXPECT_TRUE(fabs(res - 0) < 1e-6);
507     unit = "deci";
508     res = ComputeSIPrefixValue(unit);
509     EXPECT_TRUE(fabs(res - 0.1) < 1e-6);
510 
511     unit = "square-acre";
512     factors = {0.0, 0.0};
513     ComputePowerValue(unit, measSys, factors);
514     EXPECT_EQ(factors.size(), 2);
515 
516     unit = "fake-per-hour";
517     factors = {0.0, 0.0};
518     status = ComputeValue(unit, measSys, factors);
519     EXPECT_EQ(status, 0);
520     unit = "kilometer-per-fake";
521     factors = {0.0, 0.0};
522     status = ComputeValue(unit, measSys, factors);
523     EXPECT_EQ(status, 0);
524 }
525 
526 /**
527  * @tc.name: I18nFuncTest014
528  * @tc.desc: Test I18n PhoneNumberFormat
529  * @tc.type: FUNC
530  */
531 HWTEST_F(I18nTest, I18nFuncTest014, TestSize.Level1)
532 {
533     std::string countryTag = "";
534     std::map<std::string, std::string> options = {
535         {"type", "INTERNATIONAL"}
536     };
537     std::unique_ptr<PhoneNumberFormat> formatter = PhoneNumberFormat::CreateInstance(countryTag, options);
538     std::string fakePhoneNumber = "93827393872723482";
539     bool isValid = formatter->isValidPhoneNumber(fakePhoneNumber);
540     EXPECT_FALSE(isValid);
541     std::string formattedPhoneNumber = formatter->format(fakePhoneNumber);
542     EXPECT_EQ(formattedPhoneNumber, "");
543     std::unique_ptr<PhoneNumberFormat> formatter1 = std::make_unique<PhoneNumberFormatMock>("XK", options);
544     std::string blocklRegion = formatter1->getLocationName("0038312345678", "zh-CN");
545     EXPECT_EQ(blocklRegion, "");
546     std::unique_ptr<PhoneNumberFormat> formatter2 = std::make_unique<PhoneNumberFormatMock>("CN", options);
547     std::string blocklCity = formatter2->getLocationName("13731630016", "zh-CN");
548     EXPECT_EQ(blocklCity, "");
549     std::string replaceCity = formatter2->getLocationName("13731930016", "zh-CN");
550     EXPECT_EQ(replaceCity, "安徽省宣城市2");
551     std::string number192 = "19200707087";
552     std::string formattedNumber = formatter2->format(number192);
553     EXPECT_EQ(formattedNumber, "+86 192 0070 7087");
554 }
555 
556 /**
557  * @tc.name: I18nFuncTest015
558  * @tc.desc: Test I18n I18nTimeZone
559  * @tc.type: FUNC
560  */
561 HWTEST_F(I18nTest, I18nFuncTest015, TestSize.Level1)
562 {
563     std::string id = "Asia/Shanghai";
564     bool isZoneID = true;
565     I18nTimeZone timezone1(id, isZoneID);
566     std::string timezoneId = timezone1.GetID();
567     EXPECT_EQ(timezoneId, "Asia/Shanghai");
568 
569     id = "Shanghai";
570     isZoneID = false;
571     I18nTimeZone timezone2(id, isZoneID);
572     timezoneId = timezone2.GetID();
573     EXPECT_EQ(timezoneId, "Asia/Shanghai");
574 
575     id = "Auckland";
576     I18nTimeZone timezone3(id, isZoneID);
577     timezoneId = timezone3.GetID();
578     EXPECT_EQ(timezoneId, "Pacific/Auckland");
579     std::string localeTag = "en-Latn-US";
580     std::string displayName = timezone3.GetDisplayName(localeTag);
581     EXPECT_EQ(timezoneId, "Pacific/Auckland");
582 
583     std::string fakeId = "fake city id";
584     std::string cityDisplayName = I18nTimeZone::GetCityDisplayName(fakeId, localeTag);
585     EXPECT_EQ(cityDisplayName, "");
586 
587     cityDisplayName = I18nTimeZone::GetCityDisplayName(id, localeTag);
588     EXPECT_EQ(cityDisplayName, "Auckland (New Zealand)");
589 
590     std::string fakeLocale = "fake locale tag";
591     cityDisplayName = I18nTimeZone::GetCityDisplayName(id, fakeLocale);
592     EXPECT_EQ(cityDisplayName, "");
593 
594     id = "Pacific/Enderbury";
595     std::unique_ptr<I18nTimeZone> timezone4 = std::make_unique<I18nTimeZoneMock>(id, true);
596     std::string cityName = timezone4->GetDisplayName("zh-CN", false);
597     EXPECT_EQ(cityName, "菲尼克斯群岛标准时间");
598 }
599 
600 /**
601  * @tc.name: I18nFuncTest016
602  * @tc.desc: Test I18n EntityRecognizer
603  * @tc.type: FUNC
604  */
605 HWTEST_F(I18nTest, I18nFuncTest016, TestSize.Level1)
606 {
607     std::string localeStr = "zh-CN";
608     UErrorCode status = U_ZERO_ERROR;
609     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
610     std::string message = "您好,您的包裹已送至指定地点,请尽快签收:快递员:刘某某,手机:15912345678,QQ:123456789。";
611     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
612     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
613     EXPECT_EQ(res[0][0], 1);
614     EXPECT_EQ(res[0][1], 32);
615     EXPECT_EQ(res[0][2], 43);
616 }
617 
618 /**
619  * @tc.name: I18nFuncTest017
620  * @tc.desc: Test I18n EntityRecognizer
621  * @tc.type: FUNC
622  */
623 HWTEST_F(I18nTest, I18nFuncTest017, TestSize.Level1)
624 {
625     std::string localeStr = "zh-CN";
626     UErrorCode status = U_ZERO_ERROR;
627     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
628     std::string message = "您好,您的包裹已送至指定地点,请尽快签收:快递员:刘某某,手机:15912345678 15512345678。";
629     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
630     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
631     EXPECT_EQ(res[0][0], 2);
632     EXPECT_EQ(res[0][1], 32);
633     EXPECT_EQ(res[0][2], 43);
634     EXPECT_EQ(res[0][3], 44);
635     EXPECT_EQ(res[0][4], 55);
636 }
637 
638 /**
639  * @tc.name: I18nFuncTest018
640  * @tc.desc: Test I18n EntityRecognizer
641  * @tc.type: FUNC
642  */
643 HWTEST_F(I18nTest, I18nFuncTest018, TestSize.Level1)
644 {
645     std::string localeStr = "en-GB";
646     UErrorCode status = U_ZERO_ERROR;
647     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
648     std::string message = "The stunning xxxxxx xxx in Verbier is availble for Christmas - call +44 (0)20 1234 5678.";
649     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
650     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
651     EXPECT_EQ(res[0][0], 1);
652     EXPECT_EQ(res[0][1], 68);
653     EXPECT_EQ(res[0][2], 87);
654 }
655 
656 /**
657  * @tc.name: I18nFuncTest019
658  * @tc.desc: Test I18n EntityRecognizer
659  * @tc.type: FUNC
660  */
661 HWTEST_F(I18nTest, I18nFuncTest019, TestSize.Level1)
662 {
663     std::string localeStr = "en-GB";
664     UErrorCode status = U_ZERO_ERROR;
665     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
666     std::string message = "RT @missingpeople: RT 32 yo missing since 26/09/2013 from Newry, NI. Seen him? Call 116000.";
667     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
668     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
669     EXPECT_EQ(res[0][0], 1);
670     EXPECT_EQ(res[0][1], 84);
671     EXPECT_EQ(res[0][2], 90);
672 }
673 
674 /**
675  * @tc.name: I18nFuncTest020
676  * @tc.desc: Test I18n EntityRecognizer
677  * @tc.type: FUNC
678  */
679 HWTEST_F(I18nTest, I18nFuncTest020, TestSize.Level1)
680 {
681     std::string localeStr = "zh-CN";
682     UErrorCode status = U_ZERO_ERROR;
683     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
684     std::string message = "xxxx海滩 xxxxx xxxxxx街上的饰品店,皮革花朵戒指10000印尼盾,不到10块人民币。";
685     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
686     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
687     EXPECT_EQ(res[0][0], 0);
688 }
689 
690 /**
691  * @tc.name: I18nFuncTest021
692  * @tc.desc: Test I18n EntityRecognizer
693  * @tc.type: FUNC
694  */
695 HWTEST_F(I18nTest, I18nFuncTest021, TestSize.Level1)
696 {
697     std::string localeStr = "en-GB";
698     UErrorCode status = U_ZERO_ERROR;
699     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
700     std::string message = "New Job: Java Developer, Dublin, Republic of Ireland, $350000.00 - $45000 per annum.";
701     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
702     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
703     EXPECT_EQ(res[0][0], 0);
704 }
705 
706 /**
707  * @tc.name: I18nFuncTest022
708  * @tc.desc: Test I18n EntityRecognizer
709  * @tc.type: FUNC
710  */
711 HWTEST_F(I18nTest, I18nFuncTest022, TestSize.Level1)
712 {
713     std::string localeStr = "zh-CN";
714     UErrorCode status = U_ZERO_ERROR;
715     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
716     std::string message = "您好,关于您的问题,可以拨打(0511) 8812 1234咨询,如果还有其他疑问,可联系刘某某(15512345678)";
717     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
718     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
719     EXPECT_EQ(res[0][0], 2);
720     EXPECT_EQ(res[0][1], 14);
721     EXPECT_EQ(res[0][2], 30);
722     EXPECT_EQ(res[0][3], 49);
723     EXPECT_EQ(res[0][4], 60);
724 }
725 
726 /**
727  * @tc.name: I18nFuncTest023
728  * @tc.desc: Test I18n EntityRecognizer
729  * @tc.type: FUNC
730  */
731 HWTEST_F(I18nTest, I18nFuncTest023, TestSize.Level1)
732 {
733     std::string localeStr = "zh-CN";
734     UErrorCode status = U_ZERO_ERROR;
735     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
736     std::string message = "给10086/10010发了一条短信:“我爱你”,收到了回复:尊敬的用户,我也爱您。";
737     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
738     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
739     EXPECT_EQ(res[0][0], 2);
740     EXPECT_EQ(res[0][1], 1);
741     EXPECT_EQ(res[0][2], 6);
742     EXPECT_EQ(res[0][3], 7);
743     EXPECT_EQ(res[0][4], 12);
744 }
745 
746 /**
747  * @tc.name: I18nFuncTest024
748  * @tc.desc: Test I18n EntityRecognizer
749  * @tc.type: FUNC
750  */
751 HWTEST_F(I18nTest, I18nFuncTest024, TestSize.Level1)
752 {
753     std::string localeStr = "zh-CN";
754     UErrorCode status = U_ZERO_ERROR;
755     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
756     std::string message = "您好,您的包裹已送至指定地点,请尽快签收:快递员:刘某某,手机:159/1234/5678,QQ:123456789。";
757     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
758     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
759     EXPECT_EQ(res[0][0], 1);
760     EXPECT_EQ(res[0][1], 32);
761     EXPECT_EQ(res[0][2], 45);
762 }
763 
764 /**
765  * @tc.name: I18nFuncTest025
766  * @tc.desc: Test I18n EntityRecognizer
767  * @tc.type: FUNC
768  */
769 HWTEST_F(I18nTest, I18nFuncTest025, TestSize.Level1)
770 {
771     std::string localeStr = "zh-CN";
772     UErrorCode status = U_ZERO_ERROR;
773     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
774     std::string message = "您好,您的包裹已送至指定地点,请尽快签收:快递员:刘某某,手机:15912345678/15512345678。";
775     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
776     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
777     EXPECT_EQ(res[0][0], 2);
778     EXPECT_EQ(res[0][1], 32);
779     EXPECT_EQ(res[0][2], 43);
780     EXPECT_EQ(res[0][3], 44);
781     EXPECT_EQ(res[0][4], 55);
782 }
783 
784 /**
785  * @tc.name: I18nFuncTest026
786  * @tc.desc: Test I18n EntityRecognizer
787  * @tc.type: FUNC
788  */
789 HWTEST_F(I18nTest, I18nFuncTest026, TestSize.Level1)
790 {
791     std::string localeStr = "zh-CN";
792     UErrorCode status = U_ZERO_ERROR;
793     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
794     std::string message = "今天一起去看的那个电影太搞笑了,2333333";
795     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
796     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
797     EXPECT_EQ(res[0][0], 0);
798 }
799 
800 /**
801  * @tc.name: I18nFuncTest027
802  * @tc.desc: Test I18n EntityRecognizer
803  * @tc.type: FUNC
804  */
805 HWTEST_F(I18nTest, I18nFuncTest027, TestSize.Level1)
806 {
807     std::string localeStr = "pt-PT";
808     UErrorCode status = U_ZERO_ERROR;
809     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
810     std::string message = "Se você tiver alguma dúvida, ligue para 912345678 ou 1820 para consulta";
811     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
812     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
813     EXPECT_EQ(res[0][0], 2);
814     EXPECT_EQ(res[0][1], 40);
815     EXPECT_EQ(res[0][2], 49);
816     EXPECT_EQ(res[0][3], 53);
817     EXPECT_EQ(res[0][4], 57);
818 }
819 
820 /**
821  * @tc.name: I18nFuncTest028
822  * @tc.desc: Test I18n EntityRecognizer
823  * @tc.type: FUNC
824  */
825 HWTEST_F(I18nTest, I18nFuncTest028, TestSize.Level1)
826 {
827     std::string localeStr = "en-GB";
828     UErrorCode status = U_ZERO_ERROR;
829     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
830     std::string message = "+44 (0)20 1234 5678 is my phone number. If you need anything, please contact me.";
831     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
832     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
833     EXPECT_EQ(res[0][0], 1);
834     EXPECT_EQ(res[0][1], 0);
835     EXPECT_EQ(res[0][2], 19);
836 }
837 
838 /**
839  * @tc.name: I18nFuncTest029
840  * @tc.desc: Test I18n EntityRecognizer
841  * @tc.type: FUNC
842  */
843 HWTEST_F(I18nTest, I18nFuncTest029, TestSize.Level1)
844 {
845     std::string localeStr = "en-GB";
846     UErrorCode status = U_ZERO_ERROR;
847     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
848     std::string message = "To book a room, please call (+44 (0)20 1234 5678;ext=588)";
849     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
850     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
851     EXPECT_EQ(res[0][0], 1);
852     EXPECT_EQ(res[0][1], 29);
853     EXPECT_EQ(res[0][2], 48);
854 }
855 
856 /**
857  * @tc.name: I18nFuncTest030
858  * @tc.desc: Test I18n EntityRecognizer
859  * @tc.type: FUNC
860  */
861 HWTEST_F(I18nTest, I18nFuncTest030, TestSize.Level1)
862 {
863     std::string localeStr = "zh-CN";
864     UErrorCode status = U_ZERO_ERROR;
865     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
866     std::string message = "我们提供23 24两种尺寸的屏幕,如有需要,请拨打11808 15512345678。";
867     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
868     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
869     EXPECT_EQ(res[0][0], 1);
870     EXPECT_EQ(res[0][1], 25);
871     EXPECT_EQ(res[0][2], 42);
872 }
873 
874 /**
875  * @tc.name: I18nFuncTest031
876  * @tc.desc: Test I18n EntityRecognizer
877  * @tc.type: FUNC
878  */
879 HWTEST_F(I18nTest, I18nFuncTest031, TestSize.Level1)
880 {
881     std::string localeStr = "zh-CN";
882     UErrorCode status = U_ZERO_ERROR;
883     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
884     std::string message = "售后问题请拨打95528|95188。";
885     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
886     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
887     EXPECT_EQ(res[0][0], 2);
888     EXPECT_EQ(res[0][1], 7);
889     EXPECT_EQ(res[0][2], 12);
890     EXPECT_EQ(res[0][3], 13);
891     EXPECT_EQ(res[0][4], 18);
892 }
893 
894 /**
895  * @tc.name: I18nFuncTest032
896  * @tc.desc: Test I18n EntityRecognizer
897  * @tc.type: FUNC
898  */
899 HWTEST_F(I18nTest, I18nFuncTest032, TestSize.Level1)
900 {
901     std::string localeStr = "en-GB";
902     UErrorCode status = U_ZERO_ERROR;
903     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
904     std::string message = "If you need anything, please contact mob:(0)20 1234 5678.";
905     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
906     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
907     EXPECT_EQ(res[0][0], 1);
908     EXPECT_EQ(res[0][1], 41);
909     EXPECT_EQ(res[0][2], 56);
910 }
911 
912 /**
913  * @tc.name: I18nFuncTest033
914  * @tc.desc: Test I18n EntityRecognizer
915  * @tc.type: FUNC
916  */
917 HWTEST_F(I18nTest, I18nFuncTest033, TestSize.Level1)
918 {
919     std::string localeStr = "zh-CN";
920     UErrorCode status = U_ZERO_ERROR;
921     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
922     std::string message = "尊敬的客户您好!4G套餐火热申办中,每月最高可获得20G手机上网流量,升级4G套餐享更多优惠。咨询及办理请致电10086。中国移动";
923     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
924     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
925     EXPECT_EQ(res[0][0], 1);
926     EXPECT_EQ(res[0][1], 55);
927     EXPECT_EQ(res[0][2], 60);
928 }
929 
930 /**
931  * @tc.name: I18nFuncTest034
932  * @tc.desc: Test I18n EntityRecognizer
933  * @tc.type: FUNC
934  */
935 HWTEST_F(I18nTest, I18nFuncTest034, TestSize.Level1)
936 {
937     std::string localeStr = "zh-CN";
938     UErrorCode status = U_ZERO_ERROR;
939     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
940     std::string message = "今天晚上10点,我们商量一下10月1日至7日的旅游安排。";
941     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
942     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
943     EXPECT_EQ(res[1][0], 2);
944     EXPECT_EQ(res[1][1], 0);
945     EXPECT_EQ(res[1][2], 7);
946     EXPECT_EQ(res[1][3], 14);
947     EXPECT_EQ(res[1][4], 22);
948 }
949 
950 /**
951  * @tc.name: I18nFuncTest035
952  * @tc.desc: Test I18n EntityRecognizer
953  * @tc.type: FUNC
954  */
955 HWTEST_F(I18nTest, I18nFuncTest035, TestSize.Level1)
956 {
957     std::string localeStr = "zh-CN";
958     UErrorCode status = U_ZERO_ERROR;
959     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
960     std::string message = "7月1日周一到7月5日周五都是工作日,所以在2023年7月6日下午17:00到19:00聚餐。";
961     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
962     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
963     EXPECT_EQ(res[1][0], 2);
964     EXPECT_EQ(res[1][1], 0);
965     EXPECT_EQ(res[1][2], 13);
966     EXPECT_EQ(res[1][3], 22);
967     EXPECT_EQ(res[1][4], 44);
968 }
969 
970 /**
971  * @tc.name: I18nFuncTest036
972  * @tc.desc: Test I18n EntityRecognizer
973  * @tc.type: FUNC
974  */
975 HWTEST_F(I18nTest, I18nFuncTest036, TestSize.Level1)
976 {
977     std::string localeStr = "zh-CN";
978     UErrorCode status = U_ZERO_ERROR;
979     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
980     std::string message = "昨天8:30:00的会议没有讨论出结果,我们2023年11月11日的8:30:00再开一次会吧。";
981     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
982     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
983     EXPECT_EQ(res[1][0], 1);
984     EXPECT_EQ(res[1][1], 22);
985     EXPECT_EQ(res[1][2], 41);
986 }
987 
988 /**
989  * @tc.name: I18nFuncTest037
990  * @tc.desc: Test I18n EntityRecognizer
991  * @tc.type: FUNC
992  */
993 HWTEST_F(I18nTest, I18nFuncTest037, TestSize.Level1)
994 {
995     std::string localeStr = "zh-CN";
996     UErrorCode status = U_ZERO_ERROR;
997     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
998     std::string message = "我们2023年10月23日(周六)一起完成作业,并且2023年10月24日周天 晚上8:00上交。";
999     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1000     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1001     EXPECT_EQ(res[1][0], 2);
1002     EXPECT_EQ(res[1][1], 2);
1003     EXPECT_EQ(res[1][2], 17);
1004     EXPECT_EQ(res[1][3], 26);
1005     EXPECT_EQ(res[1][4], 46);
1006 }
1007 
1008 /**
1009  * @tc.name: I18nFuncTest038
1010  * @tc.desc: Test I18n EntityRecognizer
1011  * @tc.type: FUNC
1012  */
1013 HWTEST_F(I18nTest, I18nFuncTest038, TestSize.Level1)
1014 {
1015     std::string localeStr = "zh-CN";
1016     UErrorCode status = U_ZERO_ERROR;
1017     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1018     std::string message = "2023/10/1是国庆节,我们可以在GMT+0800 上午9時30分00秒去参观博物馆,后续星期六 晚上 7:00我们一起吃饭。";
1019     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1020     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1021     EXPECT_EQ(res[1][0], 3);
1022     EXPECT_EQ(res[1][1], 0);
1023     EXPECT_EQ(res[1][2], 9);
1024     EXPECT_EQ(res[1][3], 19);
1025     EXPECT_EQ(res[1][4], 38);
1026     EXPECT_EQ(res[1][5], 47);
1027     EXPECT_EQ(res[1][6], 58);
1028 }
1029 
1030 /**
1031  * @tc.name: I18nFuncTest039
1032  * @tc.desc: Test I18n EntityRecognizer
1033  * @tc.type: FUNC
1034  */
1035 HWTEST_F(I18nTest, I18nFuncTest039, TestSize.Level1)
1036 {
1037     std::string localeStr = "zh-CN";
1038     UErrorCode status = U_ZERO_ERROR;
1039     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1040     std::string message = "我们上午 7:30:00 (GMT+8:30)可以去看日出,下午5:00-晚上7:00看日落。";
1041     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1042     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1043     EXPECT_EQ(res[1][0], 2);
1044     EXPECT_EQ(res[1][1], 2);
1045     EXPECT_EQ(res[1][2], 23);
1046     EXPECT_EQ(res[1][3], 30);
1047     EXPECT_EQ(res[1][4], 43);
1048 }
1049 
1050 /**
1051  * @tc.name: I18nFuncTest040
1052  * @tc.desc: Test I18n EntityRecognizer
1053  * @tc.type: FUNC
1054  */
1055 HWTEST_F(I18nTest, I18nFuncTest040, TestSize.Level1)
1056 {
1057     std::string localeStr = "en-GB";
1058     UErrorCode status = U_ZERO_ERROR;
1059     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1060     std::string message = "We'll have dinner at GMT-8:15 PM 17:30:00, and go shopping at tomorrow 8:00.";
1061     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1062     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1063     EXPECT_EQ(res[1][0], 2);
1064     EXPECT_EQ(res[1][1], 21);
1065     EXPECT_EQ(res[1][2], 41);
1066     EXPECT_EQ(res[1][3], 62);
1067     EXPECT_EQ(res[1][4], 75);
1068 }
1069 
1070 /**
1071  * @tc.name: I18nFuncTest041
1072  * @tc.desc: Test I18n EntityRecognizer
1073  * @tc.type: FUNC
1074  */
1075 HWTEST_F(I18nTest, I18nFuncTest041, TestSize.Level1)
1076 {
1077     std::string localeStr = "en-GB";
1078     UErrorCode status = U_ZERO_ERROR;
1079     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1080     std::string message = "Our time zone is GMT+12:00.";
1081     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1082     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1083     EXPECT_EQ(res[1][0], 0);
1084 }
1085 
1086 /**
1087  * @tc.name: I18nFuncTest042
1088  * @tc.desc: Test I18n EntityRecognizer
1089  * @tc.type: FUNC
1090  */
1091 HWTEST_F(I18nTest, I18nFuncTest042, TestSize.Level1)
1092 {
1093     std::string localeStr = "en-GB";
1094     UErrorCode status = U_ZERO_ERROR;
1095     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1096     std::string message = "The festivities will take place on Sunday, jan 1, 2023, and run until Wed, 1/4/2023";
1097     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1098     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1099     EXPECT_EQ(res[1][0], 2);
1100     EXPECT_EQ(res[1][1], 35);
1101     EXPECT_EQ(res[1][2], 54);
1102     EXPECT_EQ(res[1][3], 70);
1103     EXPECT_EQ(res[1][4], 83);
1104 }
1105 
1106 /**
1107  * @tc.name: I18nFuncTest043
1108  * @tc.desc: Test I18n EntityRecognizer
1109  * @tc.type: FUNC
1110  */
1111 HWTEST_F(I18nTest, I18nFuncTest043, TestSize.Level1)
1112 {
1113     std::string localeStr = "zh-CN";
1114     UErrorCode status = U_ZERO_ERROR;
1115     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1116     // std::string message = "2023年1月2日至3日周三是一个好日子,上午可以11:00:00(周三)去逛街";
1117     std::string message = "2023年1月2日至3日是一个好日子,12:00:00(2023年1月3日)一起吃饭。";
1118     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1119     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1120     EXPECT_EQ(res[1][0], 2);
1121     EXPECT_EQ(res[1][1], 0);
1122     EXPECT_EQ(res[1][2], 12);
1123     EXPECT_EQ(res[1][3], 19);
1124     EXPECT_EQ(res[1][4], 38);
1125 }
1126 
1127 /**
1128  * @tc.name: I18nFuncTest044
1129  * @tc.desc: Test I18n EntityRecognizer
1130  * @tc.type: FUNC
1131  */
1132 HWTEST_F(I18nTest, I18nFuncTest044, TestSize.Level1)
1133 {
1134     std::string localeStr = "zh-CN";
1135     UErrorCode status = U_ZERO_ERROR;
1136     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1137     std::string message = "(2023年1月1日)12:00:00聚会,2023年1月2日,16:00:00返回深圳。";
1138     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1139     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1140     EXPECT_EQ(res[1][0], 2);
1141     EXPECT_EQ(res[1][1], 0);
1142     EXPECT_EQ(res[1][2], 19);
1143     EXPECT_EQ(res[1][3], 22);
1144     EXPECT_EQ(res[1][4], 40);
1145 }
1146 
1147 
1148 /**
1149  * @tc.name: I18nFuncTest045
1150  * @tc.desc: Test I18n EntityRecognizer
1151  * @tc.type: FUNC
1152  */
1153 HWTEST_F(I18nTest, I18nFuncTest045, TestSize.Level1)
1154 {
1155     std::string localeStr = "zh-CN";
1156     UErrorCode status = U_ZERO_ERROR;
1157     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1158     std::string message = "2023年1月3日(今天(本周五))和2023年1月3日(12:00:00)是指同一天";
1159     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1160     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1161     EXPECT_EQ(res[1][0], 3);
1162     EXPECT_EQ(res[1][1], 0);
1163     EXPECT_EQ(res[1][2], 17);
1164     EXPECT_EQ(res[1][3], 19);
1165     EXPECT_EQ(res[1][4], 28);
1166     EXPECT_EQ(res[1][5], 29);
1167     EXPECT_EQ(res[1][6], 37);
1168 }
1169 
1170 /**
1171  * @tc.name: I18nFuncTest046
1172  * @tc.desc: Test I18n EntityRecognizer
1173  * @tc.type: FUNC
1174  */
1175 HWTEST_F(I18nTest, I18nFuncTest046, TestSize.Level1)
1176 {
1177     std::string localeStr = "zh-CN";
1178     UErrorCode status = U_ZERO_ERROR;
1179     icu::Locale locale = icu::Locale::forLanguageTag(localeStr, status);
1180     std::string message = "2023年1月3日今天(本周五)在7:00:00的2023年1月3日可以看日出";
1181     std::unique_ptr<EntityRecognizer> m = std::make_unique<EntityRecognizer>(locale);
1182     std::vector<std::vector<int>> res = m->FindEntityInfo(message);
1183     EXPECT_EQ(res[1][0], 2);
1184     EXPECT_EQ(res[1][1], 0);
1185     EXPECT_EQ(res[1][2], 16);
1186     EXPECT_EQ(res[1][3], 17);
1187     EXPECT_EQ(res[1][4], 34);
1188 }
1189 
1190 /**
1191  * @tc.name: I18nFuncTest047
1192  * @tc.desc: Test I18n LocaleUtil
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(I18nTest, I18nFuncTest047, TestSize.Level1)
1196 {
1197     LocaleInfo *locale = new LocaleInfo("zh-Hans-CN");
1198     uint16_t encodedLanguage = LocaleUtil::EncodeLanguageByLocaleInfo(locale);
1199     EXPECT_EQ(encodedLanguage, 31336);
1200     delete locale;
1201 }
1202 
1203 /**
1204  * @tc.name: I18nFuncTest048
1205  * @tc.desc: Test I18n LocaleUtil
1206  * @tc.type: FUNC
1207  */
1208 HWTEST_F(I18nTest, I18nFuncTest048, TestSize.Level1)
1209 {
1210     LocaleInfo *locale = new LocaleInfo("zh-Hans-CN");
1211     uint16_t encodedScript = LocaleUtil::EncodeScriptByLocaleInfo(locale);
1212     EXPECT_EQ(encodedScript, 28275);
1213     delete locale;
1214 }
1215 
1216 /**
1217  * @tc.name: I18nFuncTest049
1218  * @tc.desc: Test I18n LocaleUtil
1219  * @tc.type: FUNC
1220  */
1221 HWTEST_F(I18nTest, I18nFuncTest049, TestSize.Level1)
1222 {
1223     LocaleInfo *locale = new LocaleInfo("zh-Hans-CN");
1224     uint16_t encodedRegion = LocaleUtil::EncodeRegionByLocaleInfo(locale);
1225     EXPECT_EQ(encodedRegion, 17230);
1226     uint16_t result = LocaleUtil::EncodeRegionByLocaleInfo(nullptr);
1227     EXPECT_EQ(result, 0);
1228     delete locale;
1229 }
1230 
1231 /**
1232  * @tc.name: I18nFuncTest050
1233  * @tc.desc: Test I18n LocaleUtil
1234  * @tc.type: FUNC
1235  */
1236 HWTEST_F(I18nTest, I18nFuncTest050, TestSize.Level1)
1237 {
1238     LocaleInfo locale("zh-Hans-CN");
1239     uint16_t encodedLanguage = LocaleUtil::EncodeLanguage(locale.GetLanguage().c_str());
1240     EXPECT_EQ(encodedLanguage, 31336);
1241 }
1242 
1243 /**
1244  * @tc.name: I18nFuncTest051
1245  * @tc.desc: Test I18n LocaleUtil
1246  * @tc.type: FUNC
1247  */
1248 HWTEST_F(I18nTest, I18nFuncTest051, TestSize.Level1)
1249 {
1250     LocaleInfo locale("zh-Hans-CN");
1251     uint16_t encodedScript = LocaleUtil::EncodeScript(locale.GetScript().c_str());
1252     EXPECT_EQ(encodedScript, 28275);
1253 }
1254 
1255 /**
1256  * @tc.name: I18nFuncTest052
1257  * @tc.desc: Test I18n LocaleUtil
1258  * @tc.type: FUNC
1259  */
1260 HWTEST_F(I18nTest, I18nFuncTest052, TestSize.Level1)
1261 {
1262     LocaleInfo locale("zh-Hans-CN");
1263     uint16_t encodedRegion = LocaleUtil::EncodeRegion(locale.GetRegion().c_str());
1264     EXPECT_EQ(encodedRegion, 17230);
1265 }
1266 
1267 /**
1268  * @tc.name: I18nFuncTest053
1269  * @tc.desc: Test I18n LocaleUtil
1270  * @tc.type: FUNC
1271  */
1272 HWTEST_F(I18nTest, I18nFuncTest053, TestSize.Level1)
1273 {
1274     LocaleInfo locale("zh-Hans-CN");
1275     uint16_t encodedLocale = LocaleUtil::EncodeLocale(locale.GetLanguage().c_str(), locale.GetScript().c_str(),
1276         locale.GetRegion().c_str());
1277     EXPECT_EQ(encodedLocale, 17230);
1278 }
1279 
1280 /**
1281  * @tc.name: I18nFuncTest054
1282  * @tc.desc: Test I18n LocaleUtil
1283  * @tc.type: FUNC
1284  */
1285 HWTEST_F(I18nTest, I18nFuncTest054, TestSize.Level1)
1286 {
1287     std::string str1 = "non-empty";
1288     std::string str2 = "";
1289     bool isEmpty = LocaleUtil::IsStrEmpty(str1.c_str());
1290     EXPECT_FALSE(isEmpty);
1291     isEmpty = LocaleUtil::IsStrEmpty(str2.c_str());
1292     EXPECT_TRUE(isEmpty);
1293 }
1294 
1295 /**
1296  * @tc.name: I18nFuncTest055
1297  * @tc.desc: Test I18n LocaleUtil
1298  * @tc.type: FUNC
1299  */
1300 HWTEST_F(I18nTest, I18nFuncTest055, TestSize.Level1)
1301 {
1302     LocaleInfo locale("zh-Hans-CN");
1303     uint32_t encodedScript = LocaleUtil::EncodeScript(locale.GetScript().c_str());
1304     char decodedScript[5] = { 0 };
1305     LocaleUtil::DecodeScript(encodedScript, decodedScript);
1306     std::string originScript = "Hans";
1307     EXPECT_EQ(originScript.compare(decodedScript), 0);
1308     LocaleUtil::DecodeScript(encodedScript, nullptr);
1309 }
1310 
1311 /**
1312  * @tc.name: I18nFuncTest056
1313  * @tc.desc: Test I18n LocaleUtil
1314  * @tc.type: FUNC
1315  */
1316 HWTEST_F(I18nTest, I18nFuncTest056, TestSize.Level1)
1317 {
1318     std::string alphaString = "abc";
1319     std::string nonAlphaString = "abc123abc";
1320     bool isAlpha = LocaleUtil::IsAlphaString(alphaString.c_str(), alphaString.length());
1321     EXPECT_TRUE(isAlpha);
1322     isAlpha = LocaleUtil::IsAlphaString(nonAlphaString.c_str(), nonAlphaString.length());
1323     EXPECT_FALSE(isAlpha);
1324     isAlpha = LocaleUtil::IsAlphaString(nullptr, nonAlphaString.length());
1325     EXPECT_FALSE(isAlpha);
1326 }
1327 
1328 /**
1329  * @tc.name: I18nFuncTest057
1330  * @tc.desc: Test I18n LocaleUtil
1331  * @tc.type: FUNC
1332  */
1333 HWTEST_F(I18nTest, I18nFuncTest057, TestSize.Level1)
1334 {
1335     std::string numericString = "123";
1336     std::string nonNumericString = "123abc123";
1337     bool isNumeric = LocaleUtil::IsNumericString(numericString.c_str(), numericString.length());
1338     EXPECT_TRUE(isNumeric);
1339     isNumeric = LocaleUtil::IsNumericString(nonNumericString.c_str(), nonNumericString.length());
1340     EXPECT_FALSE(isNumeric);
1341     isNumeric = LocaleUtil::IsNumericString(nullptr, nonNumericString.length());
1342     EXPECT_FALSE(isNumeric);
1343     std::string locale = "ug-CN";
1344     bool rtl = LocaleUtil::IsRTL(locale);
1345     EXPECT_TRUE(rtl);
1346 }
1347 
1348 /**
1349  * @tc.name: I18nFuncTest058
1350  * @tc.desc: Test I18n LocaleUtil
1351  * @tc.type: FUNC
1352  */
1353 HWTEST_F(I18nTest, I18nFuncTest058, TestSize.Level1)
1354 {
1355     LocaleInfo *locale1 = new LocaleInfo("zh-Hans-CN");
1356     LocaleInfo *locale2 = new LocaleInfo("en-Latn-US");
1357     bool isMatched = LocaleMatcher::Match(locale1, locale2);
1358     EXPECT_FALSE(isMatched);
1359     delete locale1;
1360     delete locale2;
1361 
1362     locale1 = new LocaleInfo("zh-Hans-CN");
1363     locale2 = new LocaleInfo("zh-Hant-TW");
1364     isMatched = LocaleMatcher::Match(locale1, locale2);
1365     EXPECT_FALSE(isMatched);
1366     delete locale1;
1367     delete locale2;
1368 
1369     locale1 = new LocaleInfo("zh-Hans-CN");
1370     locale2 = new LocaleInfo("zh-Hant-TW");
1371     isMatched = LocaleMatcher::Match(locale1, locale2);
1372     EXPECT_FALSE(isMatched);
1373     delete locale1;
1374     delete locale2;
1375 
1376     locale1 = new LocaleInfo("zh-Hans-CN");
1377     locale2 = new LocaleInfo("zh-Hans-MO");
1378     isMatched = LocaleMatcher::Match(locale1, locale2);
1379     EXPECT_TRUE(isMatched);
1380     delete locale1;
1381     delete locale2;
1382 }
1383 
1384 /**
1385  * @tc.name: I18nFuncTest059
1386  * @tc.desc: Test I18n LocaleUtil
1387  * @tc.type: FUNC
1388  */
1389 HWTEST_F(I18nTest, I18nFuncTest059, TestSize.Level1)
1390 {
1391     LocaleInfo *request = nullptr;
1392     LocaleInfo *current = new LocaleInfo("zh-Hans-CN");
1393     LocaleInfo *other = nullptr;
1394     int8_t res = LocaleMatcher::IsMoreSuitable(current, other, request);
1395     EXPECT_TRUE(res < 0);
1396     delete current;
1397     current = nullptr;
1398 
1399     res = LocaleMatcher::IsMoreSuitable(current, other, request);
1400     EXPECT_TRUE(res == 0);
1401 
1402     request = new LocaleInfo("en-GB");
1403     current = new LocaleInfo("en-AU");
1404     res = LocaleMatcher::IsMoreSuitable(current, other, request);
1405     EXPECT_TRUE(res > 0);
1406 
1407     other = new LocaleInfo("en-GB");
1408     res = LocaleMatcher::IsMoreSuitable(current, other, request);
1409     EXPECT_TRUE(res < 0);
1410 
1411     delete request;
1412     delete current;
1413     delete other;
1414     request = new LocaleInfo("iw-Lant-GB");
1415     current = new LocaleInfo("iw-Lant-AU");
1416     other = new LocaleInfo("he-Latn-AU");
1417     res = LocaleMatcher::IsMoreSuitable(current, other, request);
1418     EXPECT_TRUE(res > 0);
1419     delete other;
1420 
1421     other = new LocaleInfo("iw-Latn-AG");
1422     res = LocaleMatcher::IsMoreSuitable(current, other, request);
1423     EXPECT_TRUE(res < 0);
1424     delete request;
1425     delete current;
1426     delete other;
1427 }
1428 
1429 /**
1430  * @tc.name: I18nFuncTest061
1431  * @tc.desc: Test I18n GetISO3Language
1432  * @tc.type: FUNC
1433  */
1434 HWTEST_F(I18nTest, I18nFuncTest061, TestSize.Level1)
1435 {
1436     std::string language = GetISO3Language("zh");
1437     EXPECT_EQ(language, "zho");
1438     language = GetISO3Language("en");
1439     EXPECT_EQ(language, "eng");
1440     language = GetISO3Language("zh-CN");
1441     EXPECT_EQ(language, "zho");
1442     language = GetISO3Language("en-US");
1443     EXPECT_EQ(language, "eng");
1444     language = GetISO3Language("zz");
1445     EXPECT_EQ(language, "");
1446     language = GetISO3Language("sdfsdf");
1447     EXPECT_EQ(language, "");
1448 }
1449 
1450 /**
1451  * @tc.name: I18nFuncTest062
1452  * @tc.desc: Test I18n GetISO3Country
1453  * @tc.type: FUNC
1454  */
1455 HWTEST_F(I18nTest, I18nFuncTest062, TestSize.Level1)
1456 {
1457     std::string country = GetISO3Country("CN");
1458     EXPECT_EQ(country, "CHN");
1459     country = GetISO3Country("US");
1460     EXPECT_EQ(country, "USA");
1461     country = GetISO3Country("zh-CN");
1462     EXPECT_EQ(country, "CHN");
1463     country = GetISO3Country("en-US");
1464     EXPECT_EQ(country, "USA");
1465     country = GetISO3Country("ZX");
1466     EXPECT_EQ(country, "");
1467     country = GetISO3Country("zh");
1468     EXPECT_EQ(country, "");
1469     country = GetISO3Country("sdfsdf");
1470     EXPECT_EQ(country, "");
1471 }
1472 
1473 /**
1474  * @tc.name: I18nFuncTest063
1475  * @tc.desc: Test I18n lunar calendar
1476  * @tc.type: FUNC
1477  */
1478 HWTEST_F(I18nTest, I18nFuncTest063, TestSize.Level1)
1479 {
1480     std::unique_ptr<LunarCalendar> ptr = std::make_unique<LunarCalendar>();
1481     if (ptr == nullptr) {
1482         return;
1483     }
1484     ptr->SetGregorianDate(1900, 1, 31);
1485     int32_t year = ptr->GetLunarYear();
1486     int32_t month = ptr->GetLunarMonth();
1487     int32_t day = ptr->GetLunarDay();
1488     bool isLeap = ptr->IsLeapMonth();
1489     EXPECT_EQ(year, 1900);
1490     EXPECT_EQ(month, 1);
1491     EXPECT_EQ(day, 1);
1492     EXPECT_EQ(isLeap, false);
1493 
1494     ptr->SetGregorianDate(1900, 6, 15);
1495     year = ptr->GetLunarYear();
1496     month = ptr->GetLunarMonth();
1497     day = ptr->GetLunarDay();
1498     isLeap = ptr->IsLeapMonth();
1499     EXPECT_EQ(year, 1900);
1500     EXPECT_EQ(month, 5);
1501     EXPECT_EQ(day, 19);
1502     EXPECT_EQ(isLeap, false);
1503 
1504     ptr->SetGregorianDate(2100, 2, 15);
1505     year = ptr->GetLunarYear();
1506     month = ptr->GetLunarMonth();
1507     day = ptr->GetLunarDay();
1508     isLeap = ptr->IsLeapMonth();
1509     EXPECT_EQ(year, 2100);
1510     EXPECT_EQ(month, 1);
1511     EXPECT_EQ(day, 7);
1512     EXPECT_EQ(isLeap, false);
1513 
1514     ptr->SetGregorianDate(2100, 12, 31);
1515     year = ptr->GetLunarYear();
1516     month = ptr->GetLunarMonth();
1517     day = ptr->GetLunarDay();
1518     isLeap = ptr->IsLeapMonth();
1519     EXPECT_EQ(year, 2100);
1520     EXPECT_EQ(month, 12);
1521     EXPECT_EQ(day, 1);
1522     EXPECT_EQ(isLeap, false);
1523 }
1524 
1525 /**
1526  * @tc.name: I18nFuncTest064
1527  * @tc.desc: Test I18n lunar calendar
1528  * @tc.type: FUNC
1529  */
1530 HWTEST_F(I18nTest, I18nFuncTest064, TestSize.Level1)
1531 {
1532     std::unique_ptr<LunarCalendar> ptr = std::make_unique<LunarCalendar>();
1533     if (ptr == nullptr) {
1534         return;
1535     }
1536     ptr->SetGregorianDate(2087, 1, 11);
1537     int32_t year = ptr->GetLunarYear();
1538     int32_t month = ptr->GetLunarMonth();
1539     int32_t day = ptr->GetLunarDay();
1540     bool isLeap = ptr->IsLeapMonth();
1541     EXPECT_EQ(year, 2086);
1542     EXPECT_EQ(month, 12);
1543     EXPECT_EQ(day, 7);
1544     EXPECT_EQ(isLeap, false);
1545 
1546     ptr->SetGregorianDate(2024, 10, 11);
1547     year = ptr->GetLunarYear();
1548     month = ptr->GetLunarMonth();
1549     day = ptr->GetLunarDay();
1550     isLeap = ptr->IsLeapMonth();
1551     EXPECT_EQ(year, 2024);
1552     EXPECT_EQ(month, 9);
1553     EXPECT_EQ(day, 9);
1554     EXPECT_EQ(isLeap, false);
1555 
1556     ptr->SetGregorianDate(1963, 6, 15);
1557     year = ptr->GetLunarYear();
1558     month = ptr->GetLunarMonth();
1559     day = ptr->GetLunarDay();
1560     isLeap = ptr->IsLeapMonth();
1561     EXPECT_EQ(year, 1963);
1562     EXPECT_EQ(month, 4);
1563     EXPECT_EQ(day, 24);
1564     EXPECT_EQ(isLeap, true);
1565 
1566     ptr->SetGregorianDate(1923, 1, 11);
1567     year = ptr->GetLunarYear();
1568     month = ptr->GetLunarMonth();
1569     day = ptr->GetLunarDay();
1570     isLeap = ptr->IsLeapMonth();
1571     EXPECT_EQ(year, 1922);
1572     EXPECT_EQ(month, 11);
1573     EXPECT_EQ(day, 25);
1574     EXPECT_EQ(isLeap, false);
1575 }
1576 
1577 /**
1578  * @tc.name: I18nFuncTest065
1579  * @tc.desc: Test I18n lunar calendar
1580  * @tc.type: FUNC
1581  */
1582 HWTEST_F(I18nTest, I18nFuncTest065, TestSize.Level1)
1583 {
1584     std::unique_ptr<LunarCalendar> ptr = std::make_unique<LunarCalendar>();
1585     if (ptr == nullptr) {
1586         return;
1587     }
1588     ptr->SetGregorianDate(2024, 8, 51);
1589     int32_t year = ptr->GetLunarYear();
1590     int32_t month = ptr->GetLunarMonth();
1591     int32_t day = ptr->GetLunarDay();
1592     bool isLeap = ptr->IsLeapMonth();
1593     EXPECT_EQ(year, 2024);
1594     EXPECT_EQ(month, 8);
1595     EXPECT_EQ(day, 18);
1596     EXPECT_EQ(isLeap, false);
1597 
1598     ptr->SetGregorianDate(2024, 12, 43);
1599     year = ptr->GetLunarYear();
1600     month = ptr->GetLunarMonth();
1601     day = ptr->GetLunarDay();
1602     isLeap = ptr->IsLeapMonth();
1603     EXPECT_EQ(year, 2024);
1604     EXPECT_EQ(month, 12);
1605     EXPECT_EQ(day, 13);
1606     EXPECT_EQ(isLeap, false);
1607 }
1608 } // namespace I18n
1609 } // namespace Global
1610 } // namespace OHOS