• 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 <unistd.h>
20 #include "sim_manager.h"
21 #include "core_manager_inner.h"
22 #include "core_service.h"
23 #include "core_service_client.h"
24 #include "enum_convert.h"
25 #include "operator_config_cache.h"
26 #include "operator_file_parser.h"
27 #include "sim_state_type.h"
28 #include "str_convert.h"
29 #include "string_ex.h"
30 #include "tel_profile_util.h"
31 #include "telephony_ext_wrapper.h"
32 #include "gtest/gtest.h"
33 #include "tel_ril_manager.h"
34 #include "mock_tel_ril_manager.h"
35 
36 namespace OHOS {
37 namespace Telephony {
38 using namespace testing::ext;
39 using namespace testing;
40 
41 class SimManagerTest : public testing::Test {
42 public:
43     static void SetUpTestCase();
44     static void TearDownTestCase();
45     void SetUp();
46     void TearDown();
47     static MockTelRilManager *telRilManager_;
48     static std::shared_ptr<SimManager> simManager_;
49 };
50 
51 MockTelRilManager *SimManagerTest::telRilManager_ = nullptr;
52 std::shared_ptr<SimManager> SimManagerTest::simManager_ = nullptr;
53 
SetUpTestCase()54 void SimManagerTest::SetUpTestCase()
55 {
56     telRilManager_ = new MockTelRilManager();
57     std::shared_ptr<MockTelRilManager> telRilManager(telRilManager_);
58     simManager_ = std::make_shared<SimManager>(telRilManager);
59     EXPECT_CALL(*telRilManager_, UnRegisterCoreNotify(_, _, _))
60         .WillRepeatedly(Return(0));
61 }
62 
TearDownTestCase()63 void SimManagerTest::TearDownTestCase()
64 {
65     Mock::AllowLeak(telRilManager_);
66     telRilManager_ = nullptr;
67     simManager_->telRilManager_ = nullptr;
68 }
69 
SetUp()70 void SimManagerTest::SetUp() {}
71 
TearDown()72 void SimManagerTest::TearDown() {}
73 
74 /**
75  * @tc.number   Telephony_Sim_SimManager_0100
76  * @tc.name     SimManager
77  * @tc.desc     Function test
78  */
79 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_001, Function | MediumTest | Level1)
80 {
81     int32_t slotId = 0;
82     int32_t ret = simManager_->InitTelExtraModule(slotId);
83     EXPECT_EQ(ret, TELEPHONY_ERROR);
84 }
85 
86 /**
87  * @tc.number   Telephony_Sim_SimManager_0200
88  * @tc.name     SimManager
89  * @tc.desc     Function test
90  */
91 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_002, Function | MediumTest | Level1)
92 {
93     int32_t simId = 0;
94     int32_t ret = simManager_->GetDefaultSmsSimId(simId);
95     EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
96 }
97 
98 /**
99  * @tc.number   Telephony_Sim_SimManager_0300
100  * @tc.name     SimManager
101  * @tc.desc     Function test
102  */
103 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_003, Function | MediumTest | Level1)
104 {
105     int32_t simId = 0;
106     int32_t ret = simManager_->GetDefaultCellularDataSimId(simId);
107     EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
108 }
109 
110 /**
111  * @tc.number   Telephony_Sim_SimManager_0400
112  * @tc.name     SimManager
113  * @tc.desc     Function test
114  */
115 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_004, Function | MediumTest | Level1)
116 {
117     int32_t slotId = 0;
118     int32_t ret = simManager_->UpdateOperatorConfigs(slotId);
119     EXPECT_EQ(ret, TELEPHONY_ERR_PERMISSION_ERR);
120 }
121 
122 /**
123  * @tc.number   Telephony_Sim_SimManager_0500
124  * @tc.name     SimManager
125  * @tc.desc     Function test
126  */
127 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_005, Function | MediumTest | Level1)
128 {
129     int32_t slotId = 0;
130     int32_t command = 0;
131     int32_t fileId = 0;
132     std::string data = "ABCDEFG";
133     std::string path = "";
134     SimAuthenticationResponse mResponse;
135     int32_t ret = simManager_->GetSimIO(slotId, command, fileId, data, path, mResponse);
136     EXPECT_EQ(ret, TELEPHONY_ERR_NO_SIM_CARD);
137 }
138 
139 /**
140  * @tc.number   Telephony_Sim_SimManager_006
141  * @tc.name     SimManager
142  * @tc.desc     Function test
143  */
144 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_006, Function | MediumTest | Level1)
145 {
146     int32_t slotId = 0;
147     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
148     EXPECT_EQ(slotId, 0);
149 }
150 
151 /**
152  * @tc.number   Telephony_Sim_SimManager_007
153  * @tc.name     SimManager
154  * @tc.desc     Function test
155  */
156 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_007, Function | MediumTest | Level1)
157 {
158     int32_t slotId = -1;
159     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
160     EXPECT_EQ(slotId, -1);
161 }
162 
163 /**
164  * @tc.number   Telephony_Sim_SimManager_008
165  * @tc.name     SimManager
166  * @tc.desc     Function test
167  */
168 HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_008, Function | MediumTest | Level1)
169 {
170     int32_t slotId = -1;
171     simManager_->UpdateImsCapFromChip(slotId, {0, 0, 0, 0});
172     EXPECT_TRUE(simManager_->simFileManager_.empty());
173 }
174 }
175 }