• 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 
18 #include <string>
19 #include <unistd.h>
20 #include "telephony_ext_wrapper.h"
21 #include "tel_ril_manager.h"
22 #include "gtest/gtest.h"
23 #include "sim_file.h"
24 #include "sim_file_init.h"
25 #include "string_ex.h"
26 #include "usim_file_controller.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 using namespace testing::ext;
31 
32 class SimFileTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38 };
39 
TearDownTestCase()40 void SimFileTest::TearDownTestCase() {}
41 
SetUp()42 void SimFileTest::SetUp() {}
43 
TearDown()44 void SimFileTest::TearDown() {}
45 
SetUpTestCase()46 void SimFileTest::SetUpTestCase() {}
47 
48 /**
49  * @tc.number   Telephony_sim_file_001
50  * @tc.name     SimFile
51  * @tc.desc     Function test
52  */
53 HWTEST_F(SimFileTest, Telephony_sim_file_001, Function | MediumTest | Level1)
54 {
55     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
56     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
57     simFile_->ObtainMCC();
58 
59     simFile_->imsi_ = "46001";
60     simFile_->lengthOfMnc_ = -1;
61     simFile_->ObtainMCC();
62 
63     simFile_->lengthOfMnc_ = 5;
64     simFile_->ObtainMCC();
65 
66     simFile_->lengthOfMnc_ = 0;
67     auto ret = simFile_->ObtainMCC();
68     EXPECT_EQ(ret, "");
69 }
70 
71 /**
72  * @tc.number   Telephony_sim_file_002
73  * @tc.name     SimFile
74  * @tc.desc     Function test
75  */
76 HWTEST_F(SimFileTest, Telephony_sim_file_002, Function | MediumTest | Level1)
77 {
78     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
79     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
80     simFile_->ObtainMCC();
81 
82     simFile_->imsi_ = "46001";
83     simFile_->lengthOfMnc_ = -1;
84     simFile_->ObtainMNC();
85 
86     simFile_->lengthOfMnc_ = 5;
87     simFile_->ObtainMNC();
88 
89     simFile_->mnc_ = "123";
90     simFile_->ObtainMNC();
91 
92     simFile_->mnc_ = "";
93 
94     simFile_->imsi_ = "";
95     simFile_->ObtainMNC();
96 
97     simFile_->imsi_ = "46001";
98     simFile_->lengthOfMnc_ = 0;
99     auto ret = simFile_->ObtainMNC();
100     EXPECT_EQ(ret, "");
101 }
102 
103 /**
104  * @tc.number   Telephony_sim_file_003
105  * @tc.name     SimFile
106  * @tc.desc     Function test
107  */
108 HWTEST_F(SimFileTest, Telephony_sim_file_003, Function | MediumTest | Level1)
109 {
110     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
111     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
112     simFile_->ObtainMCC();
113 
114     simFile_->imsi_ = "46001";
115     simFile_->lengthOfMnc_ = -1;
116     simFile_->ObtainMNC();
117 
118     simFile_->lengthOfMnc_ = 5;
119     simFile_->ObtainMNC();
120 
121     simFile_->lengthOfMnc_ = 0;
122     auto ret = simFile_->ObtainMNC();
123     EXPECT_EQ(ret, "");
124 }
125 
126 /**
127  * @tc.number   Telephony_sim_file_004
128  * @tc.name     SimFile
129  * @tc.desc     Function test
130  */
131 HWTEST_F(SimFileTest, Telephony_sim_file_004, Function | MediumTest | Level1)
132 {
133     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
134     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
135     simFile_->ObtainMCC();
136 
137     simFile_->imsi_ = "46001";
138     simFile_->lengthOfMnc_ = -1;
139     simFile_->ObtainSimOperator();
140 
141     simFile_->lengthOfMnc_ = 5;
142     simFile_->ObtainSimOperator();
143 
144     simFile_->ObtainCallForwardStatus();
145 
146     simFile_->fileToGet_ = 0;
147     simFile_->lockQueried_ = true;
148     simFile_->fileQueried_ = false;
149     simFile_->ProcessFileLoaded(true);
150 
151     simFile_->fileQueried_ = true;
152     simFile_->ProcessFileLoaded(true);
153 
154     simFile_->lengthOfMnc_ = 0;
155     auto ret = simFile_->ObtainSimOperator();
156     EXPECT_EQ(ret, "");
157 }
158 
159 /**
160  * @tc.number   Telephony_sim_file_005
161  * @tc.name     SimFile
162  * @tc.desc     Function test
163  */
164 HWTEST_F(SimFileTest, Telephony_sim_file_005, Function | MediumTest | Level1)
165 {
166     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
167     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
168     simFile_->ObtainIsoCountryCode();
169 
170     simFile_->operatorNumeric_ = "12";
171     simFile_->ObtainIsoCountryCode();
172 
173     simFile_->operatorNumeric_ = "12345678901234568";
174     simFile_->ObtainIsoCountryCode();
175 
176     simFile_->operatorNumeric_ = "1234";
177     auto ret = simFile_->ObtainIsoCountryCode();
178     EXPECT_EQ(ret, "");
179 }
180 
181 /**
182  * @tc.number   Telephony_sim_file_006
183  * @tc.name     SimFile
184  * @tc.desc     Function test
185  */
186 HWTEST_F(SimFileTest, Telephony_sim_file_006, Function | MediumTest | Level1)
187 {
188     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
189     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
190     simFile_->fileController_ = std::make_shared<UsimFileController>(0);
191     simFile_->serviceTable_ = "not null";
192     simFile_->LoadSimOtherFile();
193 
194     simFile_->serviceTable_ = "";
195     simFile_->LoadSimOtherFile();
196     simFile_->IsServiceAvailable(UsimService::USIM_FDN);
197 
198     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(1, 1);
199     simFile_->ProcessGetOpl5gDone(event);
200     simFile_->ProcessSpnShortCphs(event);
201     simFile_->ProcessSpnCphs(event);
202     std::string operatorNum = "";
203     simFile_ ->displayConditionOfSpn_  = 4;
204     simFile_->ObtainSpnCondition(true, operatorNum);
205 
206     event = nullptr;
207     simFile_->ProcessGetSpnCphsDone(event);
208     simFile_->ProcessGetSpnShortCphsDone(event);
209     EXPECT_TRUE(simFile_->ProcessGetOpl5gDone(event));
210 }
211 
212 /**
213  * @tc.number   Telephony_sim_file_007
214  * @tc.name     SimFile
215  * @tc.desc     Function test
216  */
217 HWTEST_F(SimFileTest, Telephony_sim_file_007, Function | MediumTest | Level1)
218 {
219     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
220     auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
221     simFile_->fileController_ = std::make_shared<UsimFileController>(0);
222     simFile_->cphsInfo_ = "not null";
223 
224     simFile_->voiceMailConfig_  = nullptr;
225     simFile_->SetVoiceMailByOperator("spn");
226     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);;
227     simFile_->ProcessEvent(event);
228 
229     event = AppExecFwk::InnerEvent::Get(MSG_SIM_OBTAIN_ICC_FILE_DONE, 1);
230     simFile_->ProcessEvent(event);
231 
232     event = AppExecFwk::InnerEvent::Get(MSG_ICC_REFRESH, 1);
233     simFile_->ProcessEvent(event);
234 
235     EXPECT_FALSE(simFile_->CphsVoiceMailAvailable());
236 }
237 
238 }
239 }