1 /*
2 * Copyright (c) 2021 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 "i18n_test.h"
17 #include <gtest/gtest.h>
18 #include "date_time_format.h"
19 #include "locale_info.h"
20 #include "number_format.h"
21 #include "plural_format.h"
22 #include "types.h"
23 #include "week_info.h"
24
25 using namespace std;
26 using namespace testing::ext;
27 using namespace OHOS::I18N;
28
29 class I18NTest : public testing::Test {
30 public:
31 void SetUp();
32 void TearDown();
33 };
34
SetUp()35 void I18NTest::SetUp()
36 {
37 }
38
TearDown()39 void I18NTest::TearDown()
40 {
41 }
42
43 /**
44 * @tc.name: I18nFuncTest001
45 * @tc.desc: Test LocaleInfo constructor1
46 * @tc.type: FUNC
47 */
48 HWTEST_F(I18NTest, I18NFuncTest001, TestSize.Level1)
49 {
50 LocaleInfo *locale = new LocaleInfo("zh", "Hans", "CN");
51 EXPECT_TRUE(locale != nullptr);
52 delete locale;
53 }
54
55 /**
56 * @tc.name: I18nFuncTest002
57 * @tc.desc: Test LocaleInfo constructor2
58 * @tc.type: FUNC
59 */
60 HWTEST_F(I18NTest, I18NFuncTest002, TestSize.Level1)
61 {
62 LocaleInfo *locale = new LocaleInfo("zh", "CN");
63 EXPECT_TRUE(locale != nullptr);
64 delete locale;
65 }
66
67 /**
68 * @tc.name: I18nFuncTest003
69 * @tc.desc: Test LocaleInfo default Constructor
70 * @tc.type: FUNC
71 */
72 HWTEST_F(I18NTest, I18NFuncTest003, TestSize.Level1)
73 {
74 LocaleInfo *locale = new LocaleInfo();
75 EXPECT_TRUE(locale != nullptr);
76 delete locale;
77 }
78
79 /**
80 * @tc.name: I18nFuncTest004
81 * @tc.desc: Test LocaleInfo copy constructor
82 * @tc.type: FUNC
83 */
84 HWTEST_F(I18NTest, I18NFuncTest004, TestSize.Level1)
85 {
86 LocaleInfo locale("zh", "CN");
87 LocaleInfo locale2(locale);
88 const char *language = locale2.GetLanguage();
89 const char *region = locale2.GetRegion();
90 EXPECT_TRUE(language != nullptr);
91 EXPECT_TRUE(region != nullptr);
92 if (language != nullptr) {
93 EXPECT_TRUE(strcmp(language, "zh") == 0);
94 }
95 if (region != nullptr) {
96 EXPECT_TRUE(strcmp(region, "CN") == 0);
97 }
98 }
99
100 /**
101 * @tc.name: I18nFuncTest005
102 * @tc.desc: Test LocaleInfo equals function
103 * @tc.type: FUNC
104 */
105 HWTEST_F(I18NTest, I18NFuncTest005, TestSize.Level1)
106 {
107 LocaleInfo locale("zh", "CN");
108 LocaleInfo locale2("zh", "CN");
109 EXPECT_TRUE(locale == locale2);
110 }
111
112 /**
113 * @tc.name: I18nFuncTest006
114 * @tc.desc: Test LocaleInfo GetLanguage function
115 * @tc.type: FUNC
116 */
117 HWTEST_F(I18NTest, I18NFuncTest006, TestSize.Level1)
118 {
119 LocaleInfo locale("ar", "AE");
120 const char *language = locale.GetLanguage();
121 EXPECT_TRUE(language != nullptr);
122 if (language != nullptr) {
123 EXPECT_TRUE(strcmp(language, "ar") == 0);
124 }
125 }
126
127 /**
128 * @tc.name: I18nFuncTest007
129 * @tc.desc: Test LocaleInfo GetRegion function
130 * @tc.type: FUNC
131 */
132 HWTEST_F(I18NTest, I18NFuncTest007, TestSize.Level1)
133 {
134 LocaleInfo locale("ar", "AE");
135 const char *region = locale.GetRegion();
136 EXPECT_TRUE(region != nullptr);
137 if (region != nullptr) {
138 EXPECT_TRUE(strcmp(region, "AE") == 0);
139 }
140 }
141
142 /**
143 * @tc.name: I18nFuncTest008
144 * @tc.desc: Test LocaleInfo GetScript function
145 * @tc.type: FUNC
146 */
147 HWTEST_F(I18NTest, I18NFuncTest008, TestSize.Level1)
148 {
149 LocaleInfo locale("zh", "Hans", "CN");
150 const char *script = locale.GetScript();
151 EXPECT_TRUE(script != nullptr);
152 if (script != nullptr) {
153 EXPECT_TRUE(strcmp(script, "Hans") == 0);
154 }
155 }
156
157 /**
158 * @tc.name: I18nFuncTest009
159 * @tc.desc: Test LocaleInfo GetId function
160 * @tc.type: FUNC
161 */
162 HWTEST_F(I18NTest, I18NFuncTest009, TestSize.Level1)
163 {
164 LocaleInfo locale("zh", "Hans", "CN");
165 const char *id = locale.GetId();
166 EXPECT_TRUE(id != nullptr);
167 if (id != nullptr) {
168 EXPECT_TRUE(strcmp(id, "zh-Hans-CN") == 0);
169 }
170 }
171
172 /**
173 * @tc.name: I18nFuncTest010
174 * @tc.desc: Test LocaleInfo IsDefaultLocale function
175 * @tc.type: FUNC
176 */
177 HWTEST_F(I18NTest, I18NFuncTest010, TestSize.Level1)
178 {
179 LocaleInfo locale("zh", "Hans", "CN");
180 EXPECT_TRUE(!locale.IsDefaultLocale());
181 LocaleInfo locale2("en", "US");
182 EXPECT_TRUE(locale2.IsDefaultLocale());
183 }
184
185 /**
186 * @tc.name: I18nFuncTest011
187 * @tc.desc: Test DateTimeFormat Constructor
188 * @tc.type: FUNC
189 */
190 HWTEST_F(I18NTest, I18NFuncTest011, TestSize.Level1)
191 {
192 LocaleInfo locale("zh", "Hans", "CN");
193 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::HOUR_MINUTE;
194 DateTimeFormat *formatter = new DateTimeFormat(pattern, locale);
195 EXPECT_TRUE(formatter != nullptr);
196 delete formatter;
197 }
198
199 /**
200 * @tc.name: I18nFuncTest012
201 * @tc.desc: Test DateTimeFormat Init function
202 * @tc.type: FUNC
203 */
204 HWTEST_F(I18NTest, I18NFuncTest012, TestSize.Level1)
205 {
206 LocaleInfo locale("zh", "Hans", "CN");
207 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::HOUR_MINUTE;
208 DateTimeFormat formatter(pattern, locale);
209 EXPECT_TRUE(formatter.Init());
210 }
211
212 /**
213 * @tc.name: I18nFuncTest013
214 * @tc.desc: Test DateTimeFormat Format function
215 * @tc.type: FUNC
216 */
217 HWTEST_F(I18NTest, I18NFuncTest013, TestSize.Level1)
218 {
219 LocaleInfo locale("zh", "", "");
220 std::string out = "";
221 time_t now = 3600 * 3 + 3600 * 24 * 6;
222 I18nStatus status = I18nStatus::ISUCCESS;
223 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::FULL;
224 DateTimeFormat formatter(pattern, locale);
225 formatter.Format(now, "-1:45", out, status);
226 std::string expect = "1970年1月7日星期三";
227 EXPECT_TRUE(expect == out);
228 }
229
230 /**
231 * @tc.name: I18nFuncTest014
232 * @tc.desc: Test DateTimeFormat Format function
233 * @tc.type: FUNC
234 */
235 HWTEST_F(I18NTest, I18NFuncTest014, TestSize.Level1)
236 {
237 LocaleInfo locale("ar", "", "");
238 std::string out = "";
239 time_t now = 3600 * 3 + 3600 * 24 * 6;
240 I18nStatus status = I18nStatus::ISUCCESS;
241 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::FULL;
242 DateTimeFormat formatter(pattern, locale);
243 formatter.Format(now, "-1:45", out, status);
244 std::string expect = "الأربعاء، ٧ يناير، ١٩٧٠";
245 EXPECT_TRUE(expect == out);
246 }
247
248 /**
249 * @tc.name: I18nFuncTest015
250 * @tc.desc: Test DateTimeFormat Format function
251 * @tc.type: FUNC
252 */
253 HWTEST_F(I18NTest, I18NFuncTest015, TestSize.Level1)
254 {
255 LocaleInfo locale("en", "", "US");
256 std::string out = "";
257 time_t now = 3600 * 3 + 3600 * 24 * 6;
258 I18nStatus status = I18nStatus::ISUCCESS;
259 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::FULL;
260 DateTimeFormat formatter(pattern, locale);
261 formatter.Format(now, "-1:45", out, status);
262 std::string expect = "Wednesday, January 7, 1970";
263 EXPECT_TRUE(expect == out);
264 }
265
266 /**
267 * @tc.name: I18nFuncTest016
268 * @tc.desc: Test DateTimeFormat ApplyPattern function
269 * @tc.type: FUNC
270 */
271 HWTEST_F(I18NTest, I18NFuncTest016, TestSize.Level1)
272 {
273 LocaleInfo locale("zh", "", "");
274 std::string out = "";
275 time_t now = 3600 * 3 + 3600 * 24 * 6;
276 I18nStatus status = I18nStatus::ISUCCESS;
277 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::SHORT;
278 DateTimeFormat formatter(pattern, locale);
279 formatter.ApplyPattern(AvailableDateTimeFormatPattern::FULL);
280 formatter.Format(now, "-1:45", out, status);
281 std::string expect = "1970年1月7日星期三";
282 EXPECT_TRUE(expect == out);
283 }
284
285 /**
286 * @tc.name: I18nFuncTest017
287 * @tc.desc: Test DateTimeFormat ApplyPattern function
288 * @tc.type: FUNC
289 */
290 HWTEST_F(I18NTest, I18NFuncTest017, TestSize.Level1)
291 {
292 LocaleInfo locale("ar", "", "");
293 std::string out = "";
294 time_t now = 3600 * 3 + 3600 * 24 * 6;
295 I18nStatus status = I18nStatus::ISUCCESS;
296 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::SHORT;
297 DateTimeFormat formatter(pattern, locale);
298 formatter.ApplyPattern(AvailableDateTimeFormatPattern::FULL);
299 formatter.Format(now, "-1:45", out, status);
300 std::string expect = "الأربعاء، ٧ يناير، ١٩٧٠";
301 EXPECT_TRUE(expect == out);
302 }
303
304 /**
305 * @tc.name: I18nFuncTest018
306 * @tc.desc: Test DateTimeFormat ApplyPattern function
307 * @tc.type: FUNC
308 */
309 HWTEST_F(I18NTest, I18NFuncTest018, TestSize.Level1)
310 {
311 LocaleInfo locale("en", "", "US");
312 std::string out = "";
313 time_t now = 3600 * 3 + 3600 * 24 * 6;
314 I18nStatus status = I18nStatus::ISUCCESS;
315 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::SHORT;
316 DateTimeFormat formatter(pattern, locale);
317 formatter.ApplyPattern(AvailableDateTimeFormatPattern::FULL);
318 formatter.Format(now, "-1:45", out, status);
319 std::string expect = "Wednesday, January 7, 1970";
320 EXPECT_TRUE(expect == out);
321 }
322
323 /**
324 * @tc.name: I18nFuncTest019
325 * @tc.desc: Test DateTimeFormat GetWeekName
326 * @tc.type: FUNC
327 */
328 HWTEST_F(I18NTest, I18NFuncTest019, TestSize.Level1)
329 {
330 LocaleInfo locale("zh", "", "CN");
331 std::string weekDays[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
332 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::SHORT;
333 DateTimeFormat formatter(pattern, locale);
334 for (int i = 0; i < 7; ++i) {
335 std::string out = formatter.GetWeekName(i, DateTimeDataType::FORMAT_WIDE);
336 EXPECT_TRUE(weekDays[i] == out);
337 }
338 }
339
340 /**
341 * @tc.name: I18nFuncTest020
342 * @tc.desc: Test DateTimeFormat GetMonthName
343 * @tc.type: FUNC
344 */
345 HWTEST_F(I18NTest, I18NFuncTest020, TestSize.Level1)
346 {
347 LocaleInfo locale("en", "", "US");
348 std::string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
349 "October", "November", "December" };
350 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::SHORT;
351 DateTimeFormat formatter(pattern, locale);
352 for (int i = 0; i < 12; ++i) {
353 std::string out = formatter.GetMonthName(i, DateTimeDataType::FORMAT_WIDE);
354 EXPECT_TRUE(months[i] == out);
355 }
356 }
357
358 /**
359 * @tc.name: I18nFuncTest021
360 * @tc.desc: Test numberFormat format integer
361 * @tc.type: FUNC
362 */
363 HWTEST_F(I18NTest, I18NFuncTest021, TestSize.Level1)
364 {
365 LocaleInfo locale("am", "", "");
366 int status = 0;
367 NumberFormat formatter(locale, status);
368 EXPECT_TRUE(status == 0);
369 int intNum1 = 1234567;
370 int intNum2 = 123456789;
371 int intNum3 = 1234;
372 std::string out = formatter.Format(intNum1, status);
373 std::string out2 = formatter.Format(intNum2, status);
374 std::string out3 = formatter.Format(intNum3, status);
375 EXPECT_TRUE(out == "1,234,567");
376 EXPECT_TRUE(out2 == "123,456,789");
377 EXPECT_TRUE(out3 == "1,234");
378 }
379
380 /**
381 * @tc.name: I18nFuncTest022
382 * @tc.desc: Test numberFormat format no group integer
383 * @tc.type: FUNC
384 */
385 HWTEST_F(I18NTest, I18NFuncTest022, TestSize.Level1)
386 {
387 LocaleInfo locale("am", "", "");
388 int status = 0;
389 NumberFormat formatter(locale, status);
390 EXPECT_TRUE(status == 0);
391 int intNum1 = 1234567;
392 int intNum2 = 123456789;
393 int intNum3 = 1234;
394 std::string out = formatter.FormatNoGroup(intNum1, status);
395 std::string out2 = formatter.FormatNoGroup(intNum2, status);
396 std::string out3 = formatter.FormatNoGroup(intNum3, status);
397 EXPECT_TRUE(out == "1234567");
398 EXPECT_TRUE(out2 == "123456789");
399 EXPECT_TRUE(out3 == "1234");
400 }
401
402 /**
403 * @tc.name: I18nFuncTest023
404 * @tc.desc: Test numberFormat format double
405 * @tc.type: FUNC
406 */
407 HWTEST_F(I18NTest, I18NFuncTest023, TestSize.Level1)
408 {
409 LocaleInfo locale("am", "", "");
410 int status = 0;
411 NumberFormat formatter(locale, status);
412 EXPECT_TRUE(status == 0);
413 double doubleNum1 = 1234567.567;
414 double doubleNum2 = 1.23456789567E8;
415 double doubleNum3 = 1234.0;
416 std::string out = formatter.Format(doubleNum1, NumberFormatType::DECIMAL, status);
417 std::string out2 = formatter.Format(doubleNum2, NumberFormatType::DECIMAL, status);
418 std::string out3 = formatter.Format(doubleNum3, NumberFormatType::DECIMAL, status);
419 EXPECT_TRUE(out == "1,234,567.567");
420 EXPECT_TRUE(out2 == "123,456,789.567");
421 EXPECT_TRUE(out3 == "1,234");
422 }
423
424 /**
425 * @tc.name: I18nFuncTest024
426 * @tc.desc: Test numberFormat format no group double
427 * @tc.type: FUNC
428 */
429 HWTEST_F(I18NTest, I18NFuncTest024, TestSize.Level1)
430 {
431 LocaleInfo locale("am", "", "");
432 int status = 0;
433 NumberFormat formatter(locale, status);
434 EXPECT_TRUE(status == 0);
435 double doubleNum1 = 1234567.567;
436 double doubleNum2 = 1.23456789567E8;
437 double doubleNum3 = 1234.0;
438 std::string out = formatter.FormatNoGroup(doubleNum1, NumberFormatType::DECIMAL, status);
439 std::string out2 = formatter.FormatNoGroup(doubleNum2, NumberFormatType::DECIMAL, status);
440 std::string out3 = formatter.FormatNoGroup(doubleNum3, NumberFormatType::DECIMAL, status);
441 EXPECT_TRUE(out == "1234567.567");
442 EXPECT_TRUE(out2 == "123456789.567");
443 EXPECT_TRUE(out3 == "1234");
444 }
445
446 /**
447 * @tc.name: I18nFuncTest025
448 * @tc.desc: Test numberFormat format SetMaxDecimalLength;
449 * @tc.type: FUNC
450 */
451 HWTEST_F(I18NTest, I18NFuncTest025, TestSize.Level1)
452 {
453 LocaleInfo locale("am", "", "");
454 int status = 0;
455 NumberFormat formatter(locale, status);
456 EXPECT_TRUE(status == 0);
457 double doubleNum1 = 1234567.567;
458 double doubleNum2 = 1.23456789567E8;
459 double doubleNum3 = 1234.0;
460 formatter.SetMaxDecimalLength(1);
461 std::string out = formatter.FormatNoGroup(doubleNum1, NumberFormatType::DECIMAL, status);
462 std::string out2 = formatter.FormatNoGroup(doubleNum2, NumberFormatType::DECIMAL, status);
463 std::string out3 = formatter.FormatNoGroup(doubleNum3, NumberFormatType::DECIMAL, status);
464 EXPECT_TRUE(out == "1234567.6");
465 EXPECT_TRUE(out2 == "123456789.6");
466 EXPECT_TRUE(out3 == "1234");
467 }
468
469 /**
470 * @tc.name: I18nFuncTest026
471 * @tc.desc: Test numberFormat format SetMinDecimalLength;
472 * @tc.type: FUNC
473 */
474 HWTEST_F(I18NTest, I18NFuncTest026, TestSize.Level1)
475 {
476 LocaleInfo locale("am", "", "");
477 int status = 0;
478 NumberFormat formatter(locale, status);
479 EXPECT_TRUE(status == 0);
480 double doubleNum1 = 1234567.56;
481 double doubleNum2 = 1.2;
482 double doubleNum3 = 1234.0;
483 formatter.SetMinDecimalLength(3);
484 std::string out = formatter.FormatNoGroup(doubleNum1, NumberFormatType::DECIMAL, status);
485 std::string out2 = formatter.FormatNoGroup(doubleNum2, NumberFormatType::DECIMAL, status);
486 std::string out3 = formatter.FormatNoGroup(doubleNum3, NumberFormatType::DECIMAL, status);
487 EXPECT_TRUE(out == "1234567.560");
488 EXPECT_TRUE(out2 == "1.200");
489 EXPECT_TRUE(out3 == "1234.000");
490 }
491
492 /**
493 * @tc.name: I18nFuncTest027
494 * @tc.desc: Test numberFormat format percent;
495 * @tc.type: FUNC
496 */
497 HWTEST_F(I18NTest, I18NFuncTest027, TestSize.Level1)
498 {
499 LocaleInfo locale("am", "", "");
500 int status = 0;
501 NumberFormat formatter(locale, status);
502 EXPECT_TRUE(status == 0);
503 double percentNum1 = 0.1234;
504 double percentNum2 = 0.123456;
505 std::string out = formatter.Format(percentNum1, NumberFormatType::PERCENT, status);
506 std::string out2 = formatter.Format(percentNum2, NumberFormatType::PERCENT, status);
507 EXPECT_TRUE(out == "12%");
508 EXPECT_TRUE(out2 == "12%");
509 }
510 /**
511 * @tc.name: I18nFuncTest028
512 * @tc.desc: Test NumberFormat Format function
513 * @tc.type: FUNC
514 */
515 HWTEST_F(I18NTest, I18NFuncTest0028, TestSize.Level1)
516 {
517 LocaleInfo locale("zh", "", "");
518 int status = 0;
519 NumberFormat formatter(locale, status);
520 std::string out = formatter.Format(1234567, status);
521 std::string expect = "1,234,567";
522 EXPECT_TRUE(expect == out);
523 }
524
525 /**
526 * @tc.name: I18nFuncTest029
527 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
528 * @tc.type: FUNC
529 */
530 HWTEST_F(I18NTest, I18nFuncTest029, TestSize.Level1)
531 {
532 LocaleInfo locale("am", "", "");
533 I18nStatus status = I18nStatus::ISUCCESS;
534 PluralFormat formatter(locale, status);
535 int out = formatter.GetPluralRuleIndex(0, status);
536 int expect = PluralRuleType::ONE;
537 EXPECT_TRUE(expect == out);
538 out = formatter.GetPluralRuleIndex(1, status);
539 expect = PluralRuleType::ONE;
540 EXPECT_TRUE(expect == out);
541 out = formatter.GetPluralRuleIndex(2, status);
542 expect = PluralRuleType::OTHER;
543 EXPECT_TRUE(expect == out);
544 out = formatter.GetPluralRuleIndex(17, status);
545 expect = PluralRuleType::OTHER;
546 EXPECT_TRUE(expect == out);
547 out = formatter.GetPluralRuleIndex(100, status);
548 expect = PluralRuleType::OTHER;
549 EXPECT_TRUE(expect == out);
550 out = formatter.GetPluralRuleIndex(1000, status);
551 expect = PluralRuleType::OTHER;
552 EXPECT_TRUE(expect == out);
553 out = formatter.GetPluralRuleIndex(10000, status);
554 expect = PluralRuleType::OTHER;
555 EXPECT_TRUE(expect == out);
556 out = formatter.GetPluralRuleIndex(100000, status);
557 expect = PluralRuleType::OTHER;
558 EXPECT_TRUE(expect == out);
559 out = formatter.GetPluralRuleIndex(1000000, status);
560 expect = PluralRuleType::OTHER;
561 EXPECT_TRUE(expect == out);
562 }
563
564 /**
565 * @tc.name: I18nFuncTest030
566 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
567 * @tc.type: FUNC
568 */
569 HWTEST_F(I18NTest, I18nFuncTest030, TestSize.Level1)
570 {
571 LocaleInfo locale("ar", "", "");
572 I18nStatus status = I18nStatus::ISUCCESS;
573 PluralFormat formatter(locale, status);
574 int out = formatter.GetPluralRuleIndex(3, status);
575 int expect = PluralRuleType::FEW;
576 EXPECT_TRUE(expect == out);
577 out = formatter.GetPluralRuleIndex(10, status);
578 expect = PluralRuleType::FEW;
579 EXPECT_TRUE(expect == out);
580 out = formatter.GetPluralRuleIndex(11, status);
581 expect = PluralRuleType::MANY;
582 EXPECT_TRUE(expect == out);
583 out = formatter.GetPluralRuleIndex(26, status);
584 expect = PluralRuleType::MANY;
585 EXPECT_TRUE(expect == out);
586 out = formatter.GetPluralRuleIndex(1, status);
587 expect = PluralRuleType::ONE;
588 EXPECT_TRUE(expect == out);
589 out = formatter.GetPluralRuleIndex(100, status);
590 expect = PluralRuleType::OTHER;
591 EXPECT_TRUE(expect == out);
592 out = formatter.GetPluralRuleIndex(2, status);
593 expect = PluralRuleType::TWO;
594 EXPECT_TRUE(expect == out);
595 out = formatter.GetPluralRuleIndex(0, status);
596 expect = PluralRuleType::ZERO;
597 EXPECT_TRUE(expect == out);
598 }
599
600 /**
601 * @tc.name: I18nFuncTest031
602 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
603 * @tc.type: FUNC
604 */
605 HWTEST_F(I18NTest, I18nFuncTest031, TestSize.Level1)
606 {
607 LocaleInfo locale("as", "", "");
608 I18nStatus status = I18nStatus::ISUCCESS;
609 PluralFormat formatter(locale, status);
610 int out = formatter.GetPluralRuleIndex(0, status);
611 int expect = PluralRuleType::ONE;
612 EXPECT_TRUE(expect == out);
613 out = formatter.GetPluralRuleIndex(1, status);
614 expect = PluralRuleType::ONE;
615 EXPECT_TRUE(expect == out);
616 out = formatter.GetPluralRuleIndex(2, status);
617 expect = PluralRuleType::OTHER;
618 EXPECT_TRUE(expect == out);
619 }
620
621 /**
622 * @tc.name: I18nFuncTest032
623 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
624 * @tc.type: FUNC
625 */
626 HWTEST_F(I18NTest, I18nFuncTest032, TestSize.Level1)
627 {
628 LocaleInfo locale("az", "", "");
629 I18nStatus status = I18nStatus::ISUCCESS;
630 PluralFormat formatter(locale, status);
631 int out = formatter.GetPluralRuleIndex(1, status);
632 int expect = PluralRuleType::ONE;
633 EXPECT_TRUE(expect == out);
634 out = formatter.GetPluralRuleIndex(0, status);
635 expect = PluralRuleType::OTHER;
636 EXPECT_TRUE(expect == out);
637 out = formatter.GetPluralRuleIndex(2, status);
638 expect = PluralRuleType::OTHER;
639 EXPECT_TRUE(expect == out);
640 out = formatter.GetPluralRuleIndex(16, status);
641 expect = PluralRuleType::OTHER;
642 EXPECT_TRUE(expect == out);
643 out = formatter.GetPluralRuleIndex(100, status);
644 expect = PluralRuleType::OTHER;
645 EXPECT_TRUE(expect == out);
646 }
647
648 /**
649 * @tc.name: I18nFuncTest033
650 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
651 * @tc.type: FUNC
652 */
653 HWTEST_F(I18NTest, I18nFuncTest033, TestSize.Level1)
654 {
655 LocaleInfo locale("be", "", "");
656 I18nStatus status = I18nStatus::ISUCCESS;
657 PluralFormat formatter(locale, status);
658 int out = formatter.GetPluralRuleIndex(2, status);
659 int expect = PluralRuleType::FEW;
660 EXPECT_TRUE(expect == out);
661 out = formatter.GetPluralRuleIndex(4, status);
662 expect = PluralRuleType::FEW;
663 EXPECT_TRUE(expect == out);
664 out = formatter.GetPluralRuleIndex(0, status);
665 expect = PluralRuleType::MANY;
666 EXPECT_TRUE(expect == out);
667 out = formatter.GetPluralRuleIndex(5, status);
668 expect = PluralRuleType::MANY;
669 EXPECT_TRUE(expect == out);
670 out = formatter.GetPluralRuleIndex(19, status);
671 expect = PluralRuleType::MANY;
672 EXPECT_TRUE(expect == out);
673 out = formatter.GetPluralRuleIndex(1, status);
674 expect = PluralRuleType::ONE;
675 EXPECT_TRUE(expect == out);
676 out = formatter.GetPluralRuleIndex(21, status);
677 expect = PluralRuleType::ONE;
678 EXPECT_TRUE(expect == out);
679 }
680
681 /**
682 * @tc.name: I18nFuncTest034
683 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
684 * @tc.type: FUNC
685 */
686 HWTEST_F(I18NTest, I18nFuncTest034, TestSize.Level1)
687 {
688 LocaleInfo locale("bg", "", "");
689 I18nStatus status = I18nStatus::ISUCCESS;
690 PluralFormat formatter(locale, status);
691 int out = formatter.GetPluralRuleIndex(1, status);
692 int expect = PluralRuleType::ONE;
693 EXPECT_TRUE(expect == out);
694 out = formatter.GetPluralRuleIndex(0, status);
695 expect = PluralRuleType::OTHER;
696 EXPECT_TRUE(expect == out);
697 out = formatter.GetPluralRuleIndex(2, status);
698 expect = PluralRuleType::OTHER;
699 EXPECT_TRUE(expect == out);
700 out = formatter.GetPluralRuleIndex(16, status);
701 expect = PluralRuleType::OTHER;
702 EXPECT_TRUE(expect == out);
703 out = formatter.GetPluralRuleIndex(100, status);
704 expect = PluralRuleType::OTHER;
705 EXPECT_TRUE(expect == out);
706 out = formatter.GetPluralRuleIndex(1000, status);
707 expect = PluralRuleType::OTHER;
708 EXPECT_TRUE(expect == out);
709 out = formatter.GetPluralRuleIndex(10000, status);
710 expect = PluralRuleType::OTHER;
711 EXPECT_TRUE(expect == out);
712 out = formatter.GetPluralRuleIndex(100000, status);
713 expect = PluralRuleType::OTHER;
714 EXPECT_TRUE(expect == out);
715 out = formatter.GetPluralRuleIndex(1000000, status);
716 expect = PluralRuleType::OTHER;
717 EXPECT_TRUE(expect == out);
718 }
719
720 /**
721 * @tc.name: I18nFuncTest035
722 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
723 * @tc.type: FUNC
724 */
725 HWTEST_F(I18NTest, I18nFuncTest035, TestSize.Level1)
726 {
727 LocaleInfo locale("bn", "", "");
728 I18nStatus status = I18nStatus::ISUCCESS;
729 PluralFormat formatter(locale, status);
730 int out = formatter.GetPluralRuleIndex(0, status);
731 int expect = PluralRuleType::ONE;
732 EXPECT_TRUE(expect == out);
733 out = formatter.GetPluralRuleIndex(1, status);
734 expect = PluralRuleType::ONE;
735 EXPECT_TRUE(expect == out);
736 out = formatter.GetPluralRuleIndex(2, status);
737 expect = PluralRuleType::OTHER;
738 EXPECT_TRUE(expect == out);
739 out = formatter.GetPluralRuleIndex(17, status);
740 expect = PluralRuleType::OTHER;
741 EXPECT_TRUE(expect == out);
742 out = formatter.GetPluralRuleIndex(100, status);
743 expect = PluralRuleType::OTHER;
744 EXPECT_TRUE(expect == out);
745 out = formatter.GetPluralRuleIndex(1000, status);
746 expect = PluralRuleType::OTHER;
747 EXPECT_TRUE(expect == out);
748 out = formatter.GetPluralRuleIndex(10000, status);
749 expect = PluralRuleType::OTHER;
750 EXPECT_TRUE(expect == out);
751 out = formatter.GetPluralRuleIndex(100000, status);
752 expect = PluralRuleType::OTHER;
753 EXPECT_TRUE(expect == out);
754 out = formatter.GetPluralRuleIndex(1000000, status);
755 expect = PluralRuleType::OTHER;
756 EXPECT_TRUE(expect == out);
757 }
758
759 /**
760 * @tc.name: I18nFuncTest036
761 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
762 * @tc.type: FUNC
763 */
764 HWTEST_F(I18NTest, I18nFuncTest036, TestSize.Level1)
765 {
766 LocaleInfo locale("bo", "", "");
767 I18nStatus status = I18nStatus::ISUCCESS;
768 PluralFormat formatter(locale, status);
769 int out = formatter.GetPluralRuleIndex(0, status);
770 int expect = PluralRuleType::OTHER;
771 EXPECT_TRUE(expect == out);
772 out = formatter.GetPluralRuleIndex(15, status);
773 expect = PluralRuleType::OTHER;
774 EXPECT_TRUE(expect == out);
775 out = formatter.GetPluralRuleIndex(100, status);
776 expect = PluralRuleType::OTHER;
777 EXPECT_TRUE(expect == out);
778 out = formatter.GetPluralRuleIndex(1000, status);
779 expect = PluralRuleType::OTHER;
780 EXPECT_TRUE(expect == out);
781 out = formatter.GetPluralRuleIndex(10000, status);
782 expect = PluralRuleType::OTHER;
783 EXPECT_TRUE(expect == out);
784 out = formatter.GetPluralRuleIndex(100000, status);
785 expect = PluralRuleType::OTHER;
786 EXPECT_TRUE(expect == out);
787 out = formatter.GetPluralRuleIndex(1000000, status);
788 expect = PluralRuleType::OTHER;
789 EXPECT_TRUE(expect == out);
790 }
791
792 /**
793 * @tc.name: I18nFuncTest037
794 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
795 * @tc.type: FUNC
796 */
797 HWTEST_F(I18NTest, I18nFuncTest037, TestSize.Level1)
798 {
799 LocaleInfo locale("bs", "", "");
800 I18nStatus status = I18nStatus::ISUCCESS;
801 PluralFormat formatter(locale, status);
802 int out = formatter.GetPluralRuleIndex(2, status);
803 int expect = PluralRuleType::FEW;
804 EXPECT_TRUE(expect == out);
805 out = formatter.GetPluralRuleIndex(4, status);
806 expect = PluralRuleType::FEW;
807 EXPECT_TRUE(expect == out);
808 out = formatter.GetPluralRuleIndex(22, status);
809 expect = PluralRuleType::FEW;
810 EXPECT_TRUE(expect == out);
811 out = formatter.GetPluralRuleIndex(1, status);
812 expect = PluralRuleType::ONE;
813 EXPECT_TRUE(expect == out);
814 out = formatter.GetPluralRuleIndex(21, status);
815 expect = PluralRuleType::ONE;
816 EXPECT_TRUE(expect == out);
817 out = formatter.GetPluralRuleIndex(0, status);
818 expect = PluralRuleType::OTHER;
819 EXPECT_TRUE(expect == out);
820 }
821
822 /**
823 * @tc.name: I18nFuncTest038
824 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
825 * @tc.type: FUNC
826 */
827 HWTEST_F(I18NTest, I18nFuncTest038, TestSize.Level1)
828 {
829 LocaleInfo locale("ca", "", "");
830 I18nStatus status = I18nStatus::ISUCCESS;
831 PluralFormat formatter(locale, status);
832 int out = formatter.GetPluralRuleIndex(1, status);
833 int expect = PluralRuleType::ONE;
834 EXPECT_TRUE(expect == out);
835 out = formatter.GetPluralRuleIndex(0, status);
836 expect = PluralRuleType::OTHER;
837 EXPECT_TRUE(expect == out);
838 }
839
840 /**
841 * @tc.name: I18nFuncTest039
842 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
843 * @tc.type: FUNC
844 */
845 HWTEST_F(I18NTest, I18nFuncTest039, TestSize.Level1)
846 {
847 LocaleInfo locale("cs", "", "");
848 I18nStatus status = I18nStatus::ISUCCESS;
849 PluralFormat formatter(locale, status);
850 int out = formatter.GetPluralRuleIndex(2, status);
851 int expect = PluralRuleType::FEW;
852 EXPECT_TRUE(expect == out);
853 out = formatter.GetPluralRuleIndex(4, status);
854 expect = PluralRuleType::FEW;
855 EXPECT_TRUE(expect == out);
856 out = formatter.GetPluralRuleIndex(1, status);
857 expect = PluralRuleType::ONE;
858 EXPECT_TRUE(expect == out);
859 out = formatter.GetPluralRuleIndex(0, status);
860 expect = PluralRuleType::OTHER;
861 EXPECT_TRUE(expect == out);
862 }
863
864 /**
865 * @tc.name: I18nFuncTest040
866 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
867 * @tc.type: FUNC
868 */
869 HWTEST_F(I18NTest, I18nFuncTest040, TestSize.Level1)
870 {
871 LocaleInfo locale("da", "", "");
872 I18nStatus status = I18nStatus::ISUCCESS;
873 PluralFormat formatter(locale, status);
874 int out = formatter.GetPluralRuleIndex(1, status);
875 int expect = PluralRuleType::ONE;
876 EXPECT_TRUE(expect == out);
877 out = formatter.GetPluralRuleIndex(0, status);
878 expect = PluralRuleType::OTHER;
879 EXPECT_TRUE(expect == out);
880 }
881
882 /**
883 * @tc.name: I18nFuncTest041
884 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
885 * @tc.type: FUNC
886 */
887 HWTEST_F(I18NTest, I18nFuncTest041, TestSize.Level1)
888 {
889 LocaleInfo locale("de", "", "");
890 I18nStatus status = I18nStatus::ISUCCESS;
891 PluralFormat formatter(locale, status);
892 int out = formatter.GetPluralRuleIndex(1, status);
893 int expect = PluralRuleType::ONE;
894 EXPECT_TRUE(expect == out);
895 out = formatter.GetPluralRuleIndex(0, status);
896 expect = PluralRuleType::OTHER;
897 EXPECT_TRUE(expect == out);
898 out = formatter.GetPluralRuleIndex(1000000, status);
899 expect = PluralRuleType::OTHER;
900 EXPECT_TRUE(expect == out);
901 }
902
903 /**
904 * @tc.name: I18nFuncTest042
905 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
906 * @tc.type: FUNC
907 */
908 HWTEST_F(I18NTest, I18nFuncTest042, TestSize.Level1)
909 {
910 LocaleInfo locale("el", "", "");
911 I18nStatus status = I18nStatus::ISUCCESS;
912 PluralFormat formatter(locale, status);
913 int out = formatter.GetPluralRuleIndex(1, status);
914 int expect = PluralRuleType::ONE;
915 EXPECT_TRUE(expect == out);
916 out = formatter.GetPluralRuleIndex(100, status);
917 expect = PluralRuleType::OTHER;
918 EXPECT_TRUE(expect == out);
919 }
920
921 /**
922 * @tc.name: I18nFuncTest043
923 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
924 * @tc.type: FUNC
925 */
926 HWTEST_F(I18NTest, I18nFuncTest043, TestSize.Level1)
927 {
928 LocaleInfo locale("en", "", "");
929 I18nStatus status = I18nStatus::ISUCCESS;
930 PluralFormat formatter(locale, status);
931 int out = formatter.GetPluralRuleIndex(1, status);
932 int expect = PluralRuleType::ONE;
933 EXPECT_TRUE(expect == out);
934 out = formatter.GetPluralRuleIndex(16, status);
935 expect = PluralRuleType::OTHER;
936 EXPECT_TRUE(expect == out);
937 }
938
939 /**
940 * @tc.name: I18nFuncTest044
941 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
942 * @tc.type: FUNC
943 */
944 HWTEST_F(I18NTest, I18nFuncTest044, TestSize.Level1)
945 {
946 LocaleInfo locale("es", "", "");
947 I18nStatus status = I18nStatus::ISUCCESS;
948 PluralFormat formatter(locale, status);
949 int out = formatter.GetPluralRuleIndex(1, status);
950 int expect = PluralRuleType::ONE;
951 EXPECT_TRUE(expect == out);
952 out = formatter.GetPluralRuleIndex(0, status);
953 expect = PluralRuleType::OTHER;
954 EXPECT_TRUE(expect == out);
955 out = formatter.GetPluralRuleIndex(2, status);
956 expect = PluralRuleType::OTHER;
957 EXPECT_TRUE(expect == out);
958 }
959
960 /**
961 * @tc.name: I18nFuncTest045
962 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
963 * @tc.type: FUNC
964 */
965 HWTEST_F(I18NTest, I18nFuncTest045, TestSize.Level1)
966 {
967 LocaleInfo locale("et", "", "");
968 I18nStatus status = I18nStatus::ISUCCESS;
969 PluralFormat formatter(locale, status);
970 int out = formatter.GetPluralRuleIndex(1, status);
971 int expect = PluralRuleType::ONE;
972 EXPECT_TRUE(expect == out);
973 out = formatter.GetPluralRuleIndex(2, status);
974 expect = PluralRuleType::OTHER;
975 EXPECT_TRUE(expect == out);
976 out = formatter.GetPluralRuleIndex(100000, status);
977 expect = PluralRuleType::OTHER;
978 EXPECT_TRUE(expect == out);
979 }
980
981 /**
982 * @tc.name: I18nFuncTest046
983 * @tc.desc: Test NumberFormat Format percent
984 * @tc.type: FUNC
985 */
986 HWTEST_F(I18NTest, I18nFuncTest046, TestSize.Level1)
987 {
988 LocaleInfo locale("de", "DE");
989 int status = I18nStatus::ISUCCESS;
990 NumberFormat format(locale, status);
991 std::string out = format.Format(0.12, NumberFormatType::PERCENT, status);
992 std::string expect = "12 %";
993 EXPECT_TRUE(expect == out);
994 }
995
996 /**
997 * @tc.name: I18nFuncTest047
998 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
999 * @tc.type: FUNC
1000 */
1001 HWTEST_F(I18NTest, I18nFuncTest047, TestSize.Level1)
1002 {
1003 LocaleInfo locale("lv", "", "");
1004 I18nStatus status = I18nStatus::ISUCCESS;
1005 PluralFormat formatter(locale, status);
1006 double number = 2.1;
1007 int out = formatter.GetPluralRuleIndex(number, status);
1008 int expect = PluralRuleType::ONE;
1009 EXPECT_TRUE(expect == out);
1010 number = 10.0;
1011 out = formatter.GetPluralRuleIndex(number, status);
1012 expect = PluralRuleType::ZERO;
1013 EXPECT_TRUE(expect == out);
1014 number = 100.2;
1015 out = formatter.GetPluralRuleIndex(number, status);
1016 expect = PluralRuleType::OTHER;
1017 EXPECT_TRUE(expect == out);
1018 }
1019
1020 /**
1021 * @tc.name: I18nFuncTest048
1022 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
1023 * @tc.type: FUNC
1024 */
1025 HWTEST_F(I18NTest, I18nFuncTest048, TestSize.Level1)
1026 {
1027 LocaleInfo locale("hr", "", "");
1028 I18nStatus status = I18nStatus::ISUCCESS;
1029 PluralFormat formatter(locale, status);
1030 double number = 2.3;
1031 int out = formatter.GetPluralRuleIndex(number, status);
1032 int expect = PluralRuleType::FEW;
1033 EXPECT_TRUE(expect == out);
1034 number = 10.1;
1035 out = formatter.GetPluralRuleIndex(number, status);
1036 expect = PluralRuleType::ONE;
1037 EXPECT_TRUE(expect == out);
1038 number = 1.5;
1039 out = formatter.GetPluralRuleIndex(number, status);
1040 expect = PluralRuleType::OTHER;
1041 EXPECT_TRUE(expect == out);
1042 }
1043
1044 /**
1045 * @tc.name: I18nFuncTest049
1046 * @tc.desc: Test LocaleInfo ForLanguageTag
1047 * @tc.type: FUNC
1048 */
1049 HWTEST_F(I18NTest, I18nFuncTest049, TestSize.Level1)
1050 {
1051 I18nStatus status = I18nStatus::ISUCCESS;
1052 LocaleInfo locale = LocaleInfo::ForLanguageTag("zh-Hant-CN-u-nu-arab", status);
1053 EXPECT_TRUE(status == I18nStatus::ISUCCESS);
1054 }
1055
1056 /**
1057 * @tc.name: I18nFuncTest050
1058 * @tc.desc: Test LocaleInfo GetExtension
1059 * @tc.type: FUNC
1060 */
1061 HWTEST_F(I18NTest, I18nFuncTest050, TestSize.Level1)
1062 {
1063 I18nStatus status = I18nStatus::ISUCCESS;
1064 LocaleInfo locale = LocaleInfo::ForLanguageTag("zh-Hant-CN-u-nu-arab", status);
1065 EXPECT_TRUE(status == I18nStatus::ISUCCESS);
1066 const char *numberDigits = locale.GetExtension("nu");
1067 EXPECT_TRUE(numberDigits != nullptr);
1068 if (numberDigits != nullptr) {
1069 EXPECT_TRUE(strcmp("arab", numberDigits) == 0);
1070 }
1071 }
1072
1073 /**
1074 * @tc.name: I18nFuncTest051
1075 * @tc.desc: Test WeekInfo constructor;
1076 * @tc.type: FUNC
1077 */
1078 HWTEST_F(I18NTest, I18nFuncTest051, TestSize.Level1)
1079 {
1080 I18nStatus status = I18nStatus::ISUCCESS;
1081 LocaleInfo locale("zh", "CN");
1082 WeekInfo weekInfo(locale, status);
1083 EXPECT_TRUE(status == I18nStatus::ISUCCESS);
1084 }
1085
1086 /**
1087 * @tc.name: I18nFuncTest052
1088 * @tc.desc: Test WeekInfo GetFirstDayOfWeek()
1089 * @tc.type: FUNC
1090 */
1091 HWTEST_F(I18NTest, I18nFuncTest052, TestSize.Level1)
1092 {
1093 I18nStatus status = I18nStatus::ISUCCESS;
1094 LocaleInfo locale("zh", "CN");
1095 WeekInfo weekInfo(locale, status);
1096 uint8_t ret = weekInfo.GetFirstDayOfWeek();
1097 EXPECT_TRUE(ret == 1);
1098 }
1099
1100 /**
1101 * @tc.name: I18nFuncTest053
1102 * @tc.desc: Test WeekInfo GetMinimalDaysInFirstWeek()
1103 * @tc.type: FUNC
1104 */
1105 HWTEST_F(I18NTest, I18nFuncTest053, TestSize.Level1)
1106 {
1107 I18nStatus status = I18nStatus::ISUCCESS;
1108 LocaleInfo locale("zh", "CN");
1109 WeekInfo weekInfo(locale, status);
1110 uint8_t ret = weekInfo.GetMinimalDaysInFirstWeek();
1111 EXPECT_TRUE(ret == 1);
1112 }
1113
1114 /**
1115 * @tc.name: I18nFuncTest054
1116 * @tc.desc: Test WeekInfo GetFirstDayOfWeekend()
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(I18NTest, I18nFuncTest054, TestSize.Level1)
1120 {
1121 I18nStatus status = I18nStatus::ISUCCESS;
1122 LocaleInfo locale("zh", "CN");
1123 WeekInfo weekInfo(locale, status);
1124 uint8_t ret = weekInfo.GetFirstDayOfWeekend();
1125 EXPECT_TRUE(ret == 7);
1126 }
1127
1128 /**
1129 * @tc.name: I18nFuncTest055
1130 * @tc.desc: Test WeekInfo GetLastDayOfWeekend()
1131 * @tc.type: FUNC
1132 */
1133 HWTEST_F(I18NTest, I18nFuncTest055, TestSize.Level1)
1134 {
1135 I18nStatus status = I18nStatus::ISUCCESS;
1136 LocaleInfo locale("zh", "CN");
1137 WeekInfo weekInfo(locale, status);
1138 uint8_t ret = weekInfo.GetLastDayOfWeekend();
1139 EXPECT_TRUE(ret == 1);
1140 }
1141
1142 /**
1143 * @tc.name: I18nFuncTest056
1144 * @tc.desc: Test DateTimeFormat be
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(I18NTest, I18nFuncTest056, TestSize.Level1)
1148 {
1149 I18nStatus status = I18nStatus::ISUCCESS;
1150 LocaleInfo locale("be", "", "");
1151 AvailableDateTimeFormatPattern pattern = AvailableDateTimeFormatPattern::ABBR_MONTH_WEEKDAY_DAY;
1152 DateTimeFormat formatter(pattern, locale);
1153 string out;
1154 formatter.Format(0, "", out, status);
1155 EXPECT_TRUE(out == "чц, 1 сту");
1156 }
1157
1158 /**
1159 * @tc.name: I18nFuncTest057
1160 * @tc.desc: Test numberFormat be
1161 * @tc.type: FUNC
1162 */
1163 HWTEST_F(I18NTest, I18nFuncTest057, TestSize.Level1)
1164 {
1165 LocaleInfo locale("be", "", "");
1166 int status = 0;
1167 NumberFormat formatter(locale, status);
1168 EXPECT_TRUE(status == 0);
1169 int intNum1 = 1234567;
1170 int intNum2 = 123456789;
1171 int intNum3 = 1234;
1172 std::string out = formatter.Format(intNum1, status);
1173 signed char array1[] = { 49, -62, -96, 50, 51, 52, -62, -96, 53, 54, 55, 0 };
1174 string expect1(reinterpret_cast<char *>(array1));
1175 std::string out2 = formatter.Format(intNum2, status);
1176 signed char array2[] = { 49, 50, 51, -62, -96, 52, 53, 54, -62, -96, 55, 56, 57, 0 };
1177 string expect2(reinterpret_cast<char *>(array2));
1178 std::string out3 = formatter.Format(intNum3, status);
1179 signed char array3[] = { 49, -62, -96, 50, 51, 52, 0 };
1180 string expect3(reinterpret_cast<char *>(array3));
1181 EXPECT_TRUE(out == expect1);
1182 EXPECT_TRUE(out2 == expect2);
1183 EXPECT_TRUE(out3 == expect3);
1184 }
1185
1186 /**
1187 * @tc.name: I18nFuncTest058
1188 * @tc.desc: Test PluralFormat GetPluralRuleIndex function
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(I18NTest, I18nFuncTest058, TestSize.Level1)
1192 {
1193 LocaleInfo locale("be", "", "");
1194 I18nStatus status = I18nStatus::ISUCCESS;
1195 PluralFormat formatter(locale, status);
1196 int out = formatter.GetPluralRuleIndex(3, status);
1197 int expect = PluralRuleType::FEW;
1198 EXPECT_TRUE(expect == out);
1199 out = formatter.GetPluralRuleIndex(10, status);
1200 expect = PluralRuleType::MANY;
1201 EXPECT_TRUE(expect == out);
1202 out = formatter.GetPluralRuleIndex(11, status);
1203 expect = PluralRuleType::MANY;
1204 EXPECT_TRUE(expect == out);
1205 out = formatter.GetPluralRuleIndex(26, status);
1206 expect = PluralRuleType::MANY;
1207 EXPECT_TRUE(expect == out);
1208 out = formatter.GetPluralRuleIndex(1, status);
1209 expect = PluralRuleType::ONE;
1210 EXPECT_TRUE(expect == out);
1211 out = formatter.GetPluralRuleIndex(2, status);
1212 expect = PluralRuleType::FEW;
1213 EXPECT_TRUE(expect == out);
1214 out = formatter.GetPluralRuleIndex(0, status);
1215 expect = PluralRuleType::MANY;
1216 EXPECT_TRUE(expect == out);
1217 }