• 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 #define private public
16 #define protected public
17 #include "cell_info.h"
18 #include "cell_location.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 #include "core_manager_inner.h"
22 #include "core_service_client.h"
23 #include "csim_file_controller.h"
24 #include "gtest/gtest.h"
25 #include "tel_ril_base_parcel.h"
26 #include "icc_file.h"
27 #include "icc_file_controller.h"
28 #include "icc_operator_rule.h"
29 #include "ims_core_service_callback_proxy.h"
30 #include "ims_core_service_callback_stub.h"
31 #include "ims_core_service_proxy.h"
32 #include "ims_reg_info_callback_proxy.h"
33 #include "isim_file_controller.h"
34 #include "multi_sim_controller.h"
35 #include "multi_sim_monitor.h"
36 #include "network_register.h"
37 #include "network_search_manager.h"
38 #include "network_search_state.h"
39 #include "operator_matching_rule.h"
40 #include "operator_name.h"
41 #include "radio_protocol_controller.h"
42 #include "ruim_file_controller.h"
43 #include "sim_file_controller.h"
44 #include "sim_file_init.h"
45 #include "sim_file_manager.h"
46 #include "sim_manager.h"
47 #include "sim_number_decode.h"
48 #include "sim_rdb_helper.h"
49 #include "sim_sms_controller.h"
50 #include "sim_state_manager.h"
51 #include "sim_utils.h"
52 #include "stk_controller.h"
53 #include "stk_manager.h"
54 #include "tag_service.h"
55 #include "tel_ril_manager.h"
56 #include "telephony_errors.h"
57 #include "telephony_hisysevent.h"
58 #include "telephony_log_wrapper.h"
59 #include "usim_file_controller.h"
60 #include "telephony_data_helper.h"
61 #include "sim_data.h"
62 #include "accesstoken_kit.h"
63 #include "token_setproc.h"
64 #include "nativetoken_kit.h"
65 #include "telephony_ext_wrapper.h"
66 
67 namespace OHOS {
68 namespace Telephony {
69 using namespace testing::ext;
70 
71 class SimUtilsTest : public testing::Test {
72 public:
73     static void SetUpTestCase();
74     static void TearDownTestCase();
75     void SetUp();
76     void TearDown();
77 };
78 
79 namespace {
80 static const int32_t SLEEP_TIME = 3;
81 } // namespace
82 
TearDownTestCase()83 void SimUtilsTest::TearDownTestCase()
84 {
85     sleep(SLEEP_TIME);
86 }
87 
SetUp()88 void SimUtilsTest::SetUp() {}
89 
TearDown()90 void SimUtilsTest::TearDown() {}
91 
SetUpTestCase()92 void SimUtilsTest::SetUpTestCase()
93 {
94     constexpr int permissionNum = 2;
95     const char *perms[permissionNum] = {"ohos.permission.GET_TELEPHONY_STATE",
96         "ohos.permission.SET_TELEPHONY_STATE"};
97     NativeTokenInfoParams infoInstance = {.dcapsNum = 0, .permsNum = permissionNum, .aclsNum = 0, .dcaps = nullptr,
98         .perms = perms, .acls = nullptr, .processName = "SimUtilsTest", .aplStr = "system_basic",
99     };
100     uint64_t tokenId = GetAccessTokenId(&infoInstance);
101     SetSelfTokenID(tokenId);
102     auto result = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
103     EXPECT_EQ(result, Security::AccessToken::RET_SUCCESS);
104 }
105 
106 /**
107  * @tc.number   Telephony_IsShowableAscii_001
108  * @tc.name     test error branch
109  * @tc.desc     Function test
110  */
111 HWTEST_F(SimUtilsTest, Telephony_IsShowableAscii_001, Function | MediumTest | Level1)
112 {
113     auto simUtils = std::make_shared<SIMUtils>();
114     char c = ' ';
115     bool result = simUtils->IsShowableAscii(c);
116     EXPECT_TRUE(result);
117 }
118 
119 /**
120  * @tc.number   Telephony_IsShowableAsciiOnly_001
121  * @tc.name     test error branch
122  * @tc.desc     Function test
123  */
124 HWTEST_F(SimUtilsTest, Telephony_IsShowableAsciiOnly_001, Function | MediumTest | Level1)
125 {
126     auto simUtils = std::make_shared<SIMUtils>();
127     std::string str1 = "HelloWorld";
128     bool result1 = simUtils->IsShowableAsciiOnly(str1);
129     EXPECT_TRUE(result1);
130     std::string str2 = "HelloWorld123!";
131     bool result2 = simUtils->IsShowableAsciiOnly(str2);
132     EXPECT_TRUE(result2);
133 }
134 
135 /**
136  * @tc.number   Telephony_CharsConvertToChar16_001
137  * @tc.name     test error branch
138  * @tc.desc     Function test
139  */
140 HWTEST_F(SimUtilsTest, Telephony_CharsConvertToChar16_001, Function | MediumTest | Level1)
141 {
142     auto simUtils = std::make_shared<SIMUtils>();
143     int outLen = 0;
144     std::shared_ptr<char16_t> result = simUtils->CharsConvertToChar16(nullptr, 0, outLen, false);
145     EXPECT_EQ(result, nullptr);
146     unsigned char input[] = {0x01, 0x02, 0x03, 0x04};
147     result = simUtils->CharsConvertToChar16(input, 4, outLen, false);
148     EXPECT_EQ(outLen, 2);
149 }
150 
151 /**
152  * @tc.number   Telephony_UcsConvertToString_001
153  * @tc.name     test error branch
154  * @tc.desc     Function test
155  */
156 HWTEST_F(SimUtilsTest, Telephony_UcsConvertToString_001, Function | MediumTest | Level1)
157 {
158     auto simUtils = std::make_shared<SIMUtils>();
159     std::u16string result = simUtils->UcsConvertToString(nullptr, 0, 0);
160     EXPECT_TRUE(result.empty());
161     unsigned char data[] = {0x00, 0x01, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63};
162     result = simUtils->UcsConvertToString(data, 10, 2);
163     EXPECT_EQ(result, u"b");
164 }
165 
166 /**
167  * @tc.number   Telephony_UcsWideConvertToString_001
168  * @tc.name     test error branch
169  * @tc.desc     Function test
170  */
171 HWTEST_F(SimUtilsTest, Telephony_UcsWideConvertToString_001, Function | MediumTest | Level1)
172 {
173     auto simUtils = std::make_shared<SIMUtils>();
174     std::u16string result = simUtils->UcsWideConvertToString(nullptr, 0, 0);
175     EXPECT_TRUE(result.empty());
176     unsigned char data[] = {0x00, 0x01, 0x00, 0x61};
177     result = simUtils->UcsWideConvertToString(data, 4, 2);
178     EXPECT_EQ(result, u"");
179 }
180 
181 } // namespace Telephony
182 } // namespace OHOS