• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <errno.h>
2 #include <gtest/gtest.h>
3 #include <langinfo.h>
4 #include <limits.h>
5 #include <locale.h>
6 
7 using namespace testing::ext;
8 
9 class LocaleLocaleconvTest : public testing::Test {
SetUp()10     void SetUp() override {}
TearDown()11     void TearDown() override {}
12 };
13 
14 /**
15  * @tc.name: localeconv_001
16  * @tc.desc: The viewpoint of this test is to verify whether the fields in the struct lconv structure returned by
17  *           localeconv match the expected empty string.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(LocaleLocaleconvTest, localeconv_001, TestSize.Level1)
21 {
22     struct lconv* pconv = localeconv();
23     EXPECT_TRUE(strcmp(".", pconv->decimal_point) == 0);
24     EXPECT_TRUE(strcmp("", pconv->thousands_sep) == 0);
25     EXPECT_TRUE(strcmp("", pconv->grouping) == 0);
26     EXPECT_TRUE(strcmp("", pconv->int_curr_symbol) == 0);
27     EXPECT_TRUE(strcmp("", pconv->currency_symbol) == 0);
28     EXPECT_TRUE(strcmp("", pconv->mon_decimal_point) == 0);
29     EXPECT_TRUE(strcmp("", pconv->mon_thousands_sep) == 0);
30     EXPECT_TRUE(strcmp("", pconv->mon_grouping) == 0);
31     EXPECT_TRUE(strcmp("", pconv->positive_sign) == 0);
32     EXPECT_TRUE(strcmp("", pconv->negative_sign) == 0);
33 }
34 /**
35  * @tc.name: localeconv_002
36  * @tc.desc: This test verifies whether the fields in the struct lconv structure returned by localeconv are equal to
37  *           CHAR_MAX.
38  * @tc.type: FUNC
39  */
40 HWTEST_F(LocaleLocaleconvTest, localeconv_002, TestSize.Level1)
41 {
42     struct lconv* pconv = localeconv();
43     EXPECT_TRUE(pconv->int_frac_digits == CHAR_MAX);
44     EXPECT_TRUE(pconv->frac_digits == CHAR_MAX);
45     EXPECT_TRUE(pconv->p_cs_precedes == CHAR_MAX);
46     EXPECT_TRUE(pconv->p_sep_by_space == CHAR_MAX);
47     EXPECT_TRUE(pconv->n_cs_precedes == CHAR_MAX);
48     EXPECT_TRUE(pconv->n_sep_by_space == CHAR_MAX);
49     EXPECT_TRUE(pconv->p_sign_posn == CHAR_MAX);
50     EXPECT_TRUE(pconv->n_sign_posn == CHAR_MAX);
51 }
52 
53 /**
54  * @tc.name: localeconv_003
55  * @tc.desc: This test verifies the use of nl_langinfo() function consistent with the decimal character returned by the
56  *           localeconv() function to ensure the correctness of the decimal character under the local setting.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(LocaleLocaleconvTest, localeconv_003, TestSize.Level1)
60 {
61     char* radixChar = nl_langinfo(RADIXCHAR);
62     ASSERT_NE(radixChar, nullptr);
63     EXPECT_TRUE(strcmp(localeconv()->decimal_point, radixChar) == 0);
64 }
65 
66 /**
67  * @tc.name: localeconv_004
68  * @tc.desc: The testing point of this test (in English) is to verify whether the thousands separator obtained using the
69  *           nl_langinfo() function matches the thousands separator returned by the localeconv() function, in order to
70  *           ensure the correctness of the thousands separator in the locale setting.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(LocaleLocaleconvTest, localeconv_004, TestSize.Level1)
74 {
75     char* thousandsSep = nl_langinfo(THOUSEP);
76     ASSERT_NE(thousandsSep, nullptr);
77     EXPECT_TRUE(strcmp(localeconv()->thousands_sep, thousandsSep) == 0);
78 }