• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <sys/stat.h>
18 #include "phone_number_format.h"
19 #include "taboo_utils.h"
20 #include "phone_number_format_test.h"
21 
22 using namespace OHOS::Global::I18n;
23 using testing::ext::TestSize;
24 using namespace std;
25 using namespace testing;
26 
27 namespace OHOS {
28 namespace Global {
29 namespace I18n {
30 
SetUpTestCase(void)31 void PhoneNumberFormatTest::SetUpTestCase(void)
32 {
33 }
34 
TearDownTestCase(void)35 void PhoneNumberFormatTest::TearDownTestCase(void)
36 {
37 }
38 
SetUp(void)39 void PhoneNumberFormatTest::SetUp(void)
40 {}
41 
TearDown(void)42 void PhoneNumberFormatTest::TearDown(void)
43 {}
44 
45 /**
46  * @tc.name: PhoneNumberFormatTest0001
47  * @tc.desc: Test getLocationName
48  * @tc.type: FUNC
49  */
50 HWTEST_F(PhoneNumberFormatTest, PhoneNumberFormatTest0001, TestSize.Level1)
51 {
52     const char* systemTabooDataPath = "/system/etc/taboo_res/";
53     map<string, string> options;
54     std::unique_ptr<PhoneNumberFormat> phoneNumberFormat =
55         std::make_unique<PhoneNumberFormat>("CN", options);
56     EXPECT_EQ(phoneNumberFormat->getLocationName("+903921234567", "tr"), "Türkiye");
57     EXPECT_EQ(phoneNumberFormat->getLocationName("+903921234567", "en"), "Türkiye");
58     EXPECT_EQ(phoneNumberFormat->getLocationName("+3596139312", "en"), "Bulgaria");
59     EXPECT_EQ(phoneNumberFormat->getLocationName("+3599355123", "en"), "Bulgaria");
60     EXPECT_EQ(phoneNumberFormat->getLocationName("+3598128123", "en"), "Bulgaria");
61     EXPECT_EQ(phoneNumberFormat->getLocationName("+3596139312", "bg"), "България");
62     EXPECT_EQ(phoneNumberFormat->getLocationName("+3599355123", "bg"), "България");
63     EXPECT_EQ(phoneNumberFormat->getLocationName("+3598128123", "bg"), "България");
64     struct stat s;
65     if (stat(systemTabooDataPath, &s) == 0) {
66         EXPECT_EQ(phoneNumberFormat->getLocationName("+212528912345", "zh"), "");
67         EXPECT_EQ(phoneNumberFormat->getLocationName("+38328012345", "zh"), "");
68     }
69     EXPECT_EQ(phoneNumberFormat->getLocationName("+913602123456", "en"), "India");
70     EXPECT_EQ(phoneNumberFormat->getLocationName("+913800123456", "en"), "India");
71     EXPECT_EQ(phoneNumberFormat->getLocationName("+39066981", "en"), "Vatican City");
72     EXPECT_EQ(phoneNumberFormat->getLocationName("+39021234", "en"), "Milan");
73     EXPECT_EQ(phoneNumberFormat->getLocationName("+393123456789", "en"), "Italy");
74 }
75 
76 /**
77  * @tc.name: PhoneNumberFormatTest0002
78  * @tc.desc: Test getLocationName
79  * @tc.type: FUNC
80  */
81 HWTEST_F(PhoneNumberFormatTest, PhoneNumberFormatTest0002, TestSize.Level1)
82 {
83     map<string, string> options;
84     std::unique_ptr<PhoneNumberFormat> phoneNumberFormat =
85         std::make_unique<PhoneNumberFormat>("CN", options);
86     ASSERT_TRUE(phoneNumberFormat != nullptr);
87     EXPECT_EQ(phoneNumberFormat->getLocationName("+886370123456", "zh"), "中国苗栗");
88     EXPECT_EQ(phoneNumberFormat->getLocationName("+886491234567", "zh"), "中国南投");
89     EXPECT_EQ(phoneNumberFormat->getLocationName("+886370123456", "en"), "Miaoli (China)");
90     EXPECT_EQ(phoneNumberFormat->getLocationName("+886491234567", "en"), "Nantou (China)");
91     EXPECT_EQ(phoneNumberFormat->getLocationName("+88652123456", "zh"), "中国嘉义、中国云林");
92 }
93 } // namespace I18n
94 } // namespace Global
95 } // namespace OHOS