• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
18 #include <string>
19 #include <set>
20 #include <unistd.h>
21 #include "sim_manager.h"
22 #include "core_manager_inner.h"
23 #include "core_service.h"
24 #include "core_service_client.h"
25 #include "enum_convert.h"
26 #include "operator_config_cache.h"
27 #include "operator_file_parser.h"
28 #include "sim_state_type.h"
29 #include "str_convert.h"
30 #include "string_ex.h"
31 #include "tel_profile_util.h"
32 #include "telephony_ext_wrapper.h"
33 #include "gtest/gtest.h"
34 #include "tel_ril_manager.h"
35 #include "mock_tel_ril_manager.h"
36 #include "mock_sim_manager.h"
37 
38 namespace OHOS {
39 namespace Telephony {
40 using namespace testing::ext;
41 using namespace testing;
42 
43 class SimManagerTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp();
48     void TearDown();
49     static MockTelRilManager *telRilManager_;
50     static std::shared_ptr<SimManager> simManager_;
51 };
52 
53 MockTelRilManager *SimManagerTest::telRilManager_ = nullptr;
54 std::shared_ptr<SimManager> SimManagerTest::simManager_ = nullptr;
55 
SetUpTestCase()56 void SimManagerTest::SetUpTestCase()
57 {
58     telRilManager_ = new MockTelRilManager();
59     std::shared_ptr<MockTelRilManager> telRilManager(telRilManager_);
60     simManager_ = std::make_shared<SimManager>(telRilManager);
61     EXPECT_CALL(*telRilManager_, UnRegisterCoreNotify(_, _, _))
62         .WillRepeatedly(Return(0));
63 }
64 
TearDownTestCase()65 void SimManagerTest::TearDownTestCase()
66 {
67     Mock::AllowLeak(telRilManager_);
68     telRilManager_ = nullptr;
69     simManager_->telRilManager_ = nullptr;
70 }
71 
SetUp()72 void SimManagerTest::SetUp() {}
73 
TearDown()74 void SimManagerTest::TearDown() {}
75 
76 /**
77  * @tc.number   Telephony_Sim_SimManager_0100
78  * @tc.name     SimManager
79  * @tc.desc     Function test
80  */
81 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_001, Function | MediumTest | Level1)
82 {
83     int32_t slotId = 0;
84     int32_t ret = simManager_->InitTelExtraModule(slotId);
85     EXPECT_EQ(ret, TELEPHONY_ERROR);
86 }
87 
88 /**
89  * @tc.number   Telephony_Sim_SimManager_0200
90  * @tc.name     SimManager
91  * @tc.desc     Function test
92  */
93 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_002, Function | MediumTest | Level1)
94 {
95     int32_t simId = 0;
96     int32_t ret = simManager_->GetDefaultSmsSimId(simId);
97     EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
98 }
99 
100 /**
101  * @tc.number   Telephony_Sim_SimManager_0300
102  * @tc.name     SimManager
103  * @tc.desc     Function test
104  */
105 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_003, Function | MediumTest | Level1)
106 {
107     int32_t simId = 0;
108     int32_t ret = simManager_->GetDefaultCellularDataSimId(simId);
109     EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
110 }
111 
112 /**
113  * @tc.number   Telephony_Sim_SimManager_0400
114  * @tc.name     SimManager
115  * @tc.desc     Function test
116  */
117 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_004, Function | MediumTest | Level1)
118 {
119     int32_t slotId = 0;
120     int32_t ret = simManager_->UpdateOperatorConfigs(slotId);
121     EXPECT_EQ(ret, TELEPHONY_ERR_PERMISSION_ERR);
122 }
123 
124 /**
125  * @tc.number   Telephony_Sim_SimManager_0500
126  * @tc.name     SimManager
127  * @tc.desc     Function test
128  */
129 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_005, Function | MediumTest | Level1)
130 {
131     int32_t slotId = 0;
132     int32_t command = 0;
133     int32_t fileId = 0;
134     std::string data = "ABCDEFG";
135     std::string path = "";
136     SimAuthenticationResponse mResponse;
137     IccSimStatus iccStatus = IccSimStatus::ICC_CONTENT_READY;
138     CardType cardType = CardType::SINGLE_MODE_USIM_CARD;
139 
140     int32_t ret = simManager_->GetSimIO(slotId, command, fileId, data, path, mResponse);
141     EXPECT_EQ(ret, TELEPHONY_ERR_NO_SIM_CARD);
142     auto simManager = std::make_shared<MockSimManager>();
143     EXPECT_CALL(*simManager, HasSimCard(slotId, _))
144         .WillRepeatedly(Return(true));
145     simManager->GetSimIccStatus(slotId, iccStatus);
146     simManager->GetCardType(slotId, cardType);
147     ret = simManager->GetSimIO(slotId, command, fileId, data, path, mResponse);
148     EXPECT_EQ(ret, TELEPHONY_ERR_SUCCESS);
149 }
150 
151 /**
152  * @tc.number   Telephony_Sim_SimManager_006
153  * @tc.name     SimManager
154  * @tc.desc     Function test
155  */
156 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_006, Function | MediumTest | Level1)
157 {
158     int32_t slotId = 0;
159     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
160     EXPECT_EQ(slotId, 0);
161 }
162 
163 /**
164  * @tc.number   Telephony_Sim_SimManager_007
165  * @tc.name     SimManager
166  * @tc.desc     Function test
167  */
168 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_007, Function | MediumTest | Level1)
169 {
170     int32_t slotId = -1;
171     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
172     EXPECT_EQ(slotId, -1);
173 }
174 
175 /**
176  * @tc.number   Telephony_Sim_SimManager_008
177  * @tc.name     SimManager
178  * @tc.desc     Function test
179  */
180 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_008, Function | MediumTest | Level1)
181 {
182     int32_t slotId = -1;
183     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
184     EXPECT_TRUE(simManager_->simFileManager_.empty());
185 }
186 
187 /**
188  * @tc.number   Telephony_Sim_SimManager_009
189  * @tc.name     SimManager
190  * @tc.desc     Function test
191  */
192 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_009, Function | MediumTest | Level1)
193 {
194     int32_t slotId = -1;
195     std::set<std::string> ehPlmns;
196     std::set<std::string> spdiPlmns;
197     simManager_->GetEhPlmns(slotId, ehPlmns);
198     simManager_->GetSpdiPlmns(slotId, spdiPlmns);
199     simManager_->slotCount_  = -1;
200     simManager_->InitMultiSimObject();
201     simManager_->slotCount_  = 10;
202     simManager_->InitMultiSimObject();
203     EXPECT_TRUE(simManager_->simFileManager_.empty());
204 }
205 
206 /**
207  * @tc.number   Telephony_Sim_SimManager_010
208  * @tc.name     SimManager
209  * @tc.desc     Function test
210  */
211 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_010, Function | MediumTest | Level1)
212 {
213     int32_t slotId = 0;
214     simManager_->SetActiveSim(slotId, 0);
215     slotId = -1;
216     simManager_->SetActiveSim(slotId, 0);
217     slotId = 4;
218     simManager_->SetActiveSim(slotId, 0);
219     slotId = 0;
220     simManager_->multiSimController_ = nullptr;
221     simManager_->SetActiveSim(slotId, 0);
222     simManager_->SetActiveSim(slotId, 0);
223     EXPECT_TRUE(simManager_->simFileManager_.empty());
224 }
225 
226 /**
227  * @tc.number   Telephony_Sim_SimManager_011
228  * @tc.name     SimManager
229  * @tc.desc     Function test
230  */
231 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_011, Function | MediumTest | Level1)
232 {
233     int32_t slotId = 0;
234     simManager_->SetActiveSimSatellite(slotId, 0);
235     slotId = -1;
236     simManager_->SetActiveSimSatellite(slotId, 0);
237     slotId = 4;
238     simManager_->SetActiveSimSatellite(slotId, 0);
239     slotId = 0;
240     simManager_->multiSimController_ = nullptr;
241     simManager_->SetActiveSimSatellite(slotId, 0);
242     telRilManager_ = new MockTelRilManager();
243     simManager_->SetActiveSimSatellite(slotId, 0);
244     EXPECT_TRUE(simManager_->simFileManager_.empty());
245 }
246 
247 /**
248  * @tc.number   Telephony_Sim_SimManager_012
249  * @tc.name     SimManager
250  * @tc.desc     Function test
251  */
252 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_012, Function | MediumTest | Level1)
253 {
254     int32_t slotId = 0;
255     simManager_->SetDefaultCellularDataSlotId(slotId);
256     simManager_->ResetSimLoadAccount(slotId);
257     slotId = -1;
258     simManager_->SetDefaultCellularDataSlotId(slotId);
259     simManager_->ResetSimLoadAccount(slotId);
260     slotId = 4;
261     simManager_->ResetSimLoadAccount(slotId);
262     slotId = 0;
263     simManager_->multiSimController_ = nullptr;
264     simManager_->ResetSimLoadAccount(slotId);
265     simManager_->ResetSimLoadAccount(slotId);
266     simManager_->SetDefaultCellularDataSlotId(slotId);
267     EXPECT_TRUE(simManager_->simFileManager_.empty());
268 }
269 }
270 }