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
27 namespace OHOS {
28 namespace Telephony {
29 using namespace testing::ext;
30
31 class SimFileTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 };
38
TearDownTestCase()39 void SimFileTest::TearDownTestCase() {}
40
SetUp()41 void SimFileTest::SetUp() {}
42
TearDown()43 void SimFileTest::TearDown() {}
44
SetUpTestCase()45 void SimFileTest::SetUpTestCase() {}
46
47 /**
48 * @tc.number Telephony_sim_file_001
49 * @tc.name SimFile
50 * @tc.desc Function test
51 */
52 HWTEST_F(SimFileTest, Telephony_sim_file_001, Function | MediumTest | Level1)
53 {
54 std::weak_ptr<Telephony::SimStateManager> simStateManager_;
55 auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
56 simFile_->ObtainMCC();
57
58 simFile_->imsi_ = "46001";
59 simFile_->lengthOfMnc_ = -1;
60 simFile_->ObtainMCC();
61
62 simFile_->lengthOfMnc_ = 5;
63 simFile_->ObtainMCC();
64
65 simFile_->lengthOfMnc_ = 0;
66 auto ret = simFile_->ObtainMCC();
67 EXPECT_EQ(ret, "");
68 }
69
70 /**
71 * @tc.number Telephony_sim_file_002
72 * @tc.name SimFile
73 * @tc.desc Function test
74 */
75 HWTEST_F(SimFileTest, Telephony_sim_file_002, Function | MediumTest | Level1)
76 {
77 std::weak_ptr<Telephony::SimStateManager> simStateManager_;
78 auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
79 simFile_->ObtainMCC();
80
81 simFile_->imsi_ = "46001";
82 simFile_->lengthOfMnc_ = -1;
83 simFile_->ObtainMNC();
84
85 simFile_->lengthOfMnc_ = 5;
86 simFile_->ObtainMNC();
87
88 simFile_->mnc_ = "123";
89 simFile_->ObtainMNC();
90
91 simFile_->mnc_ = "";
92
93 simFile_->imsi_ = "";
94 simFile_->ObtainMNC();
95
96 simFile_->imsi_ = "46001";
97 simFile_->lengthOfMnc_ = 0;
98 auto ret = simFile_->ObtainMNC();
99 EXPECT_EQ(ret, "");
100 }
101
102 /**
103 * @tc.number Telephony_sim_file_003
104 * @tc.name SimFile
105 * @tc.desc Function test
106 */
107 HWTEST_F(SimFileTest, Telephony_sim_file_003, Function | MediumTest | Level1)
108 {
109 std::weak_ptr<Telephony::SimStateManager> simStateManager_;
110 auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
111 simFile_->ObtainMCC();
112
113 simFile_->imsi_ = "46001";
114 simFile_->lengthOfMnc_ = -1;
115 simFile_->ObtainMNC();
116
117 simFile_->lengthOfMnc_ = 5;
118 simFile_->ObtainMNC();
119
120 simFile_->lengthOfMnc_ = 0;
121 auto ret = simFile_->ObtainMNC();
122 EXPECT_EQ(ret, "");
123 }
124
125 /**
126 * @tc.number Telephony_sim_file_004
127 * @tc.name SimFile
128 * @tc.desc Function test
129 */
130 HWTEST_F(SimFileTest, Telephony_sim_file_004, Function | MediumTest | Level1)
131 {
132 std::weak_ptr<Telephony::SimStateManager> simStateManager_;
133 auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
134 simFile_->ObtainMCC();
135
136 simFile_->imsi_ = "46001";
137 simFile_->lengthOfMnc_ = -1;
138 simFile_->ObtainSimOperator();
139
140 simFile_->lengthOfMnc_ = 5;
141 simFile_->ObtainSimOperator();
142
143 simFile_->ObtainCallForwardStatus();
144
145 simFile_->fileToGet_ = 0;
146 simFile_->lockQueried_ = true;
147 simFile_->fileQueried_ = false;
148 simFile_->ProcessFileLoaded(true);
149
150 simFile_->fileQueried_ = true;
151 simFile_->ProcessFileLoaded(true);
152
153 simFile_->lengthOfMnc_ = 0;
154 auto ret = simFile_->ObtainSimOperator();
155 EXPECT_EQ(ret, "");
156 }
157
158 /**
159 * @tc.number Telephony_sim_file_005
160 * @tc.name SimFile
161 * @tc.desc Function test
162 */
163 HWTEST_F(SimFileTest, Telephony_sim_file_005, Function | MediumTest | Level1)
164 {
165 std::weak_ptr<Telephony::SimStateManager> simStateManager_;
166 auto simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
167 simFile_->ObtainIsoCountryCode();
168
169 simFile_->operatorNumeric_ = "12";
170 simFile_->ObtainIsoCountryCode();
171
172 simFile_->operatorNumeric_ = "12345678901234568";
173 simFile_->ObtainIsoCountryCode();
174
175 simFile_->operatorNumeric_ = "1234";
176 auto ret = simFile_->ObtainIsoCountryCode();
177 EXPECT_EQ(ret, "");
178 }
179
180 }
181 }