• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
16 #define private public
17 #define protected public
18 
19 #include <fstream>
20 #include "gtest/gtest.h"
21 #include "cellular_call_supplement.h"
22 #include "telephony_ext_wrapper.h"
23 #include "ims_control.h"
24 #include "parameters.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 using namespace testing::ext;
29 class CellularCallSupplementTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp();
34     void TearDown();
35 };
36 
IsEmptyMmiResultFilteredMock(int slotId)37 bool IsEmptyMmiResultFilteredMock(int slotId)
38 {
39     return true;
40 }
41 
IsEmptyMmiResultFilteredMockFalse(int slotId)42 bool IsEmptyMmiResultFilteredMockFalse(int slotId)
43 {
44     return false;
45 }
46 
IsMmiCodeMock(int32_t slotId,std::string & number)47 bool IsMmiCodeMock(int32_t slotId, std::string &number)
48 {
49     return true;
50 }
51 
IsMmiCodeMockFalse(int32_t slotId,std::string & number)52 bool IsMmiCodeMockFalse(int32_t slotId, std::string &number)
53 {
54     return false;
55 }
56 
IsUssdReleaseMsgFilteredMock(int32_t slotId)57 bool IsUssdReleaseMsgFilteredMock(int32_t slotId)
58 {
59     return true;
60 }
61 
IsUssdReleaseMsgFilteredMockFalse(int32_t slotId)62 bool IsUssdReleaseMsgFilteredMockFalse(int32_t slotId)
63 {
64     return false;
65 }
66 
UnescapeHtmlCodeMock(int32_t slotId,std::string & content)67 void UnescapeHtmlCodeMock(int32_t slotId, std::string &content)
68 {}
69 
RenameFile(std::string from,std::string to)70 static void RenameFile(std::string from, std::string to)
71 {
72     std::fstream fs;
73     fs.open(from.c_str());
74     if (fs.fail()) {
75         fs.close();
76         return;
77     }
78     fs.close();
79     rename(from.c_str(), to.c_str());
80 }
81 
SetUpTestCase()82 void CellularCallSupplementTest::SetUpTestCase()
83 {}
84 
TearDownTestCase()85 void CellularCallSupplementTest::TearDownTestCase()
86 {}
87 
SetUp()88 void CellularCallSupplementTest::SetUp()
89 {}
90 
TearDown()91 void CellularCallSupplementTest::TearDown()
92 {}
93 
94 /**
95  * @tc.number   CellularCallSupplementTest_001
96  * @tc.name     Test CellularCallSupplement
97  * @tc.desc     Function test
98  */
99 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_001, Function | MediumTest | Level1)
100 {
101     TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ = IsEmptyMmiResultFilteredMock;
102     UssdNoticeInfo ussdNoticeInfo;
103     ussdNoticeInfo.str = "";
104     ussdNoticeInfo.m = 1;
105     CellularCallSupplement callSup;
106     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
107 }
108 
109 /**
110  * @tc.number   CellularCallSupplementTest_002
111  * @tc.name     Test CellularCallSupplement
112  * @tc.desc     Function test
113  */
114 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_002, Function | MediumTest | Level1)
115 {
116     TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ = IsEmptyMmiResultFilteredMock;
117     UssdNoticeInfo ussdNoticeInfo;
118     ussdNoticeInfo.str = "abc";
119     ussdNoticeInfo.m = 1;
120     CellularCallSupplement callSup;
121     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
122 }
123 
124 /**
125  * @tc.number   CellularCallSupplementTest_003
126  * @tc.name     Test CellularCallSupplement
127  * @tc.desc     Function test
128  */
129 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_003, Function | MediumTest | Level1)
130 {
131     TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ = IsEmptyMmiResultFilteredMockFalse;
132     UssdNoticeInfo ussdNoticeInfo;
133     ussdNoticeInfo.str = "";
134     ussdNoticeInfo.m = 1;
135     CellularCallSupplement callSup;
136     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
137 }
138 
139 /**
140  * @tc.number   CellularCallSupplementTest_004
141  * @tc.name     Test CellularCallSupplement
142  * @tc.desc     Function test
143  */
144 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_004, Function | MediumTest | Level1)
145 {
146     TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ = nullptr;
147     UssdNoticeInfo ussdNoticeInfo;
148     ussdNoticeInfo.str = "";
149     ussdNoticeInfo.m = 1;
150     CellularCallSupplement callSup;
151     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
152 }
153 
154 /**
155  * @tc.number   CellularCallSupplementTest_005
156  * @tc.name     Test CellularCallSupplement
157  * @tc.desc     Function test
158  */
159 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_005, Function | MediumTest | Level1)
160 {
161     TELEPHONY_EXT_WRAPPER.isUssdReleaseMsgFiltered_ = IsUssdReleaseMsgFilteredMock;
162     UssdNoticeInfo ussdNoticeInfo;
163     ussdNoticeInfo.str = "abc";
164     ussdNoticeInfo.m = 2;
165     CellularCallSupplement callSup;
166     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
167 }
168 
169 /**
170  * @tc.number   CellularCallSupplementTest_006
171  * @tc.name     Test CellularCallSupplement
172  * @tc.desc     Function test
173  */
174 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_006, Function | MediumTest | Level1)
175 {
176     TELEPHONY_EXT_WRAPPER.isUssdReleaseMsgFiltered_ = IsUssdReleaseMsgFilteredMockFalse;
177     UssdNoticeInfo ussdNoticeInfo;
178     ussdNoticeInfo.str = "abc";
179     ussdNoticeInfo.m = 2;
180     CellularCallSupplement callSup;
181     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
182 }
183 
184 /**
185  * @tc.number   CellularCallSupplementTest_007
186  * @tc.name     Test CellularCallSupplement
187  * @tc.desc     Function test
188  */
189 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_007, Function | MediumTest | Level1)
190 {
191     TELEPHONY_EXT_WRAPPER.isUssdReleaseMsgFiltered_ = nullptr;
192     UssdNoticeInfo ussdNoticeInfo;
193     ussdNoticeInfo.str = "abc";
194     ussdNoticeInfo.m = 2;
195     CellularCallSupplement callSup;
196     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
197 }
198 
199 /**
200  * @tc.number   CellularCallSupplementTest_008
201  * @tc.name     Test CellularCallSupplement
202  * @tc.desc     Function test
203  */
204 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_008, Function | MediumTest | Level1)
205 {
206     TELEPHONY_EXT_WRAPPER.unescapeHtmlCode_ = UnescapeHtmlCodeMock;
207     UssdNoticeInfo ussdNoticeInfo;
208     ussdNoticeInfo.str = "&amp;";
209     ussdNoticeInfo.m = 2;
210     CellularCallSupplement callSup;
211     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
212 }
213 
214 /**
215  * @tc.number   CellularCallSupplementTest_009
216  * @tc.name     Test CellularCallSupplement
217  * @tc.desc     Function test
218  */
219 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_009, Function | MediumTest | Level1)
220 {
221     TELEPHONY_EXT_WRAPPER.unescapeHtmlCode_ = nullptr;
222     UssdNoticeInfo ussdNoticeInfo;
223     ussdNoticeInfo.str = "&amp;";
224     ussdNoticeInfo.m = 2;
225     CellularCallSupplement callSup;
226     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
227 }
228 
229 /**
230  * @tc.number   CellularCallSupplementTest_010
231  * @tc.name     Test CellularCallSupplement
232  * @tc.desc     Function test
233  */
234 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_010, Function | MediumTest | Level1)
235 {
236     TELEPHONY_EXT_WRAPPER.isMmiCode_ = IsMmiCodeMock;
237     IMSControl control;
238     std::string phoneNum = "*9";
239     CLIRMode mode = CLIRMode::DEFAULT;
240     bool isNeed = control.IsNeedExecuteMMI(0, phoneNum, mode, true);
241     EXPECT_FALSE(isNeed);
242 }
243 
244 /**
245  * @tc.number   CellularCallSupplementTest_011
246  * @tc.name     Test CellularCallSupplement
247  * @tc.desc     Function test
248  */
249 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_011, Function | MediumTest | Level1)
250 {
251     TELEPHONY_EXT_WRAPPER.isMmiCode_ = nullptr;
252     IMSControl control;
253     std::string phoneNum = "*9";
254     CLIRMode mode = CLIRMode::DEFAULT;
255     bool isNeed = control.IsNeedExecuteMMI(0, phoneNum, mode, true);
256     EXPECT_FALSE(isNeed);
257 }
258 
259 /**
260  * @tc.number   CellularCallSupplementTest_012
261  * @tc.name     Test CellularCallSupplement
262  * @tc.desc     Function test
263  */
264 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_012, Function | MediumTest | Level1)
265 {
266     TELEPHONY_EXT_WRAPPER.isMmiCode_ = IsMmiCodeMockFalse;
267     IMSControl control;
268     std::string phoneNum = "*100#";
269     CLIRMode mode = CLIRMode::DEFAULT;
270     bool isNeed = control.IsNeedExecuteMMI(0, phoneNum, mode, true);
271     EXPECT_FALSE(isNeed);
272 }
273 
274 /**
275  * @tc.number   CellularCallSupplementTest_013
276  * @tc.name     Test CellularCallSupplement
277  * @tc.desc     Function test
278  */
279 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_013, Function | MediumTest | Level1)
280 {
281     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
282     TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ != nullptr;
283     TELEPHONY_EXT_WRAPPER.isMmiCode_ != nullptr;
284     TELEPHONY_EXT_WRAPPER.isUssdReleaseMsgFiltered_ != nullptr;
285     TELEPHONY_EXT_WRAPPER.unescapeHtmlCode_ != nullptr;
286     TELEPHONY_EXT_WRAPPER.~TelephonyExtWrapper();
287     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
288 }
289 
290 /**
291  * @tc.number   CellularCallSupplementTest_014
292  * @tc.name     Test CellularCallSupplement
293  * @tc.desc     Function test
294  */
295 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_014, Function | MediumTest | Level1)
296 {
297     std::string filePath = "/system/lib64/libtelephony_ext_service.z.so";
298     std::string bakFilePath = "/system/lib64/libtelephony_ext_service.z.so.bak";
299     RenameFile(filePath, bakFilePath);
300     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
301     EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.isEmptyMmiResultFiltered_ == nullptr);
302     TELEPHONY_EXT_WRAPPER.isMmiCode_ == nullptr;
303     TELEPHONY_EXT_WRAPPER.isUssdReleaseMsgFiltered_ == nullptr;
304     TELEPHONY_EXT_WRAPPER.unescapeHtmlCode_ == nullptr;
305     TELEPHONY_EXT_WRAPPER.~TelephonyExtWrapper();
306     RenameFile(bakFilePath, filePath);
307     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
308 }
309 
310 /**
311  * @tc.number   CellularCallSupplementTest_015
312  * @tc.name     Test CellularCallSupplement
313  * @tc.desc     Function test
314  */
315 HWTEST_F(CellularCallSupplementTest, CellularCallSupplementTest_015, Function | MediumTest | Level1)
316 {
317     UssdNoticeInfo ussdNoticeInfo;
318     ussdNoticeInfo.str = "";
319     ussdNoticeInfo.m = 2;
320     CellularCallSupplement callSup;
321     SetParameter("const.telephony.hw_show_mmi_error", "true");
322     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
323     SetParameter("const.telephony.hw_show_mmi_error", "false");
324     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
325     ussdNoticeInfo.str = "12345";
326     SetParameter("const.telephony.hw_show_mmi_error", "true");
327     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
328     SetParameter("const.telephony.hw_show_mmi_error", "false");
329     EXPECT_NO_FATAL_FAILURE(callSup.EventUssdNotify(ussdNoticeInfo, 0));
330 }
331 
332 }  // namespace Telephony
333 }  // namespace OHOS