1 /*
2  * Copyright (C) 2023 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 #include "core_service_client.h"
17 #include "gtest/gtest.h"
18 #include "i_sms_service_interface.h"
19 #include "if_system_ability_manager.h"
20 #include "iservice_registry.h"
21 #include "radio_event.h"
22 #include "sms_broadcast_subscriber_gtest.h"
23 #include "sms_mms_gtest.h"
24 #include "sms_mms_test_helper.h"
25 #include "sms_service.h"
26 #include "sms_service_manager_client.h"
27 #include "telephony_log_wrapper.h"
28 #include "telephony_types.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 namespace {
33 sptr<ISmsServiceInterface> g_telephonyService = nullptr;
34 } // namespace
35 using namespace testing::ext;
36 
37 class CbGtest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43     static sptr<ISmsServiceInterface> GetProxy();
HasSimCard(int32_t slotId)44     static bool HasSimCard(int32_t slotId)
45     {
46         bool hasSimCard = false;
47         if (CoreServiceClient::GetInstance().GetProxy() == nullptr) {
48             return hasSimCard;
49         }
50         CoreServiceClient::GetInstance().HasSimCard(slotId, hasSimCard);
51         return hasSimCard;
52     }
53 };
54 
TearDownTestCase()55 void CbGtest::TearDownTestCase() {}
56 
SetUp()57 void CbGtest::SetUp() {}
58 
TearDown()59 void CbGtest::TearDown() {}
60 
61 const int32_t DEFAULT_SIM_SLOT_ID_1 = 1;
62 const uint16_t MESSAGE_TYPE = 4;
63 const uint16_t CB_PDU_LEN = 100;
64 
SetUpTestCase()65 void CbGtest::SetUpTestCase()
66 {
67     TELEPHONY_LOGI("SetUpTestCase slotId%{public}d", DEFAULT_SIM_SLOT_ID_1);
68     g_telephonyService = GetProxy();
69     if (g_telephonyService == nullptr) {
70         return;
71     }
72     DelayedSingleton<SmsServiceManagerClient>::GetInstance()->ResetSmsServiceProxy();
73     DelayedSingleton<SmsServiceManagerClient>::GetInstance()->InitSmsServiceProxy();
74 }
75 
GetProxy()76 sptr<ISmsServiceInterface> CbGtest::GetProxy()
77 {
78     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
79     if (systemAbilityMgr == nullptr) {
80         return nullptr;
81     }
82     sptr<IRemoteObject> remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_SMS_MMS_SYS_ABILITY_ID);
83     if (remote) {
84         sptr<ISmsServiceInterface> smsService = iface_cast<ISmsServiceInterface>(remote);
85         return smsService;
86     }
87     return nullptr;
88 }
89 
90 #ifndef TEL_TEST_UNSUPPORT
OpenCellBroadcastTestFuc(SmsMmsTestHelper & helper)91 void OpenCellBroadcastTestFuc(SmsMmsTestHelper &helper)
92 {
93     AccessMmsToken token;
94     bool enable = true;
95     uint32_t fromMsgId = 0;
96     uint32_t toMsgId = 10;
97     uint8_t netType = 1;
98     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
99         helper.slotId, enable, fromMsgId, toMsgId, netType);
100     helper.SetIntResult(result);
101     helper.NotifyAll();
102 }
103 
104 /**
105  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0001
106  * @tc.name     Open cellBroadcast slotId is -1
107  * @tc.desc     Function test
108  */
109 HWTEST_F(CbGtest, OpenCellBroadcast_0001, Function | MediumTest | Level3)
110 {
111     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0001 -->");
112     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
113         TELEPHONY_LOGI("TelephonyTestService has no sim card");
114         ASSERT_TRUE(true);
115         return;
116     }
117     SmsMmsTestHelper helper;
118     helper.slotId = DEFAULT_SIM_SLOT_ID_REMOVE;
119     if (!helper.Run(OpenCellBroadcastTestFuc, std::ref(helper))) {
120         TELEPHONY_LOGI("OpenCellBroadcastTestFuc out of time");
121         ASSERT_TRUE(false);
122     }
123     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0001 -->finished");
124     EXPECT_NE(helper.GetIntResult(), 0);
125 }
126 
OpenCellBroadcastTestFuc2(SmsMmsTestHelper & helper)127 void OpenCellBroadcastTestFuc2(SmsMmsTestHelper &helper)
128 {
129     AccessMmsToken token;
130     bool enable = true;
131     uint32_t fromMsgId = 20;
132     uint32_t toMsgId = 10;
133     uint8_t netType = 1;
134     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
135         helper.slotId, enable, fromMsgId, toMsgId, netType);
136     helper.SetIntResult(result);
137     helper.NotifyAll();
138 }
139 
140 /**
141  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0002
142  * @tc.name     Open cellBroadcast fromMsgId less than toMsgId
143  * @tc.desc     Function test
144  */
145 HWTEST_F(CbGtest, OpenCellBroadcast_0002, Function | MediumTest | Level3)
146 {
147     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0002 -->");
148     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
149         TELEPHONY_LOGI("TelephonyTestService has no sim card");
150         ASSERT_TRUE(true);
151         return;
152     }
153     SmsMmsTestHelper helper;
154     helper.slotId = DEFAULT_SIM_SLOT_ID;
155     if (!helper.Run(OpenCellBroadcastTestFuc2, std::ref(helper))) {
156         TELEPHONY_LOGI("OpenCellBroadcastTestFuc2 out of time");
157         ASSERT_TRUE(false);
158     }
159     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0002 -->finished");
160     EXPECT_NE(helper.GetIntResult(), 0);
161 }
162 
OpenCellBroadcastTestFuc3(SmsMmsTestHelper & helper)163 void OpenCellBroadcastTestFuc3(SmsMmsTestHelper &helper)
164 {
165     AccessMmsToken token;
166     bool enable = true;
167     uint32_t fromMsgId = 0;
168     uint32_t toMsgId = 10;
169     uint8_t netType = 3;
170     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
171         helper.slotId, enable, fromMsgId, toMsgId, netType);
172     helper.SetIntResult(result);
173     helper.NotifyAll();
174 }
175 
176 /**
177  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0003
178  * @tc.name     Open cellBroadcast netType is unknown.
179  * @tc.desc     Function test
180  */
181 HWTEST_F(CbGtest, OpenCellBroadcast_0003, Function | MediumTest | Level3)
182 {
183     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0003 -->");
184     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
185         TELEPHONY_LOGI("TelephonyTestService has no sim card");
186         ASSERT_TRUE(true);
187         return;
188     }
189     SmsMmsTestHelper helper;
190     helper.slotId = DEFAULT_SIM_SLOT_ID;
191     if (!helper.Run(OpenCellBroadcastTestFuc3, std::ref(helper))) {
192         TELEPHONY_LOGI("OpenCellBroadcastTestFuc3 out of time");
193         ASSERT_TRUE(false);
194     }
195     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0003 -->finished");
196     EXPECT_NE(helper.GetIntResult(), 0);
197 }
198 
OpenCellBroadcastTestFuc4(SmsMmsTestHelper & helper)199 void OpenCellBroadcastTestFuc4(SmsMmsTestHelper &helper)
200 {
201     AccessMmsToken token;
202     bool enable = true;
203     uint32_t fromMsgId = 0;
204     uint32_t toMsgId = 10;
205     uint8_t netType = 1;
206     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
207         helper.slotId, enable, fromMsgId, toMsgId, netType);
208     helper.SetIntResult(result);
209     helper.NotifyAll();
210 }
211 
212 /**
213  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0004
214  * @tc.name     Open cellBroadcast parameter is valid.
215  * @tc.desc     Function test
216  */
217 HWTEST_F(CbGtest, OpenCellBroadcast_0004, Function | MediumTest | Level3)
218 {
219     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0004 -->");
220     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
221         TELEPHONY_LOGI("TelephonyTestService has no sim card");
222         ASSERT_TRUE(true);
223         return;
224     }
225     SmsMmsTestHelper helper;
226     helper.slotId = DEFAULT_SIM_SLOT_ID;
227     if (!helper.Run(OpenCellBroadcastTestFuc4, std::ref(helper))) {
228         TELEPHONY_LOGI("OpenCellBroadcastTestFuc4 out of time");
229         ASSERT_TRUE(false);
230     }
231     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0004 -->finished");
232     ASSERT_GE(helper.GetIntResult(), 0);
233 }
234 
OpenCellBroadcastTestFuc5(SmsMmsTestHelper & helper)235 void OpenCellBroadcastTestFuc5(SmsMmsTestHelper &helper)
236 {
237     AccessMmsToken token;
238     bool enable = true;
239     uint32_t fromMsgId = 0;
240     uint32_t toMsgId = 1000;
241     uint8_t netType = 1;
242     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
243         helper.slotId, enable, fromMsgId, toMsgId, netType);
244     helper.SetIntResult(result);
245     helper.NotifyAll();
246 }
247 
248 /**
249  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0005
250  * @tc.name     Open cellBroadcast parameter is valid
251  * @tc.desc     Function test
252  */
253 HWTEST_F(CbGtest, OpenCellBroadcast_0005, Function | MediumTest | Level3)
254 {
255     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0005 -->");
256     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
257         TELEPHONY_LOGI("TelephonyTestService has no sim card");
258         ASSERT_TRUE(true);
259         return;
260     }
261     SmsMmsTestHelper helper;
262     helper.slotId = DEFAULT_SIM_SLOT_ID;
263     if (!helper.Run(OpenCellBroadcastTestFuc5, std::ref(helper))) {
264         TELEPHONY_LOGI("OpenCellBroadcastTestFuc5 out of time");
265         ASSERT_TRUE(false);
266     }
267     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0005 -->finished");
268     ASSERT_GE(helper.GetIntResult(), 0);
269 }
270 
OpenCellBroadcastTestFuc6(SmsMmsTestHelper & helper)271 void OpenCellBroadcastTestFuc6(SmsMmsTestHelper &helper)
272 {
273     bool enable = true;
274     uint32_t fromMsgId = 0;
275     uint32_t toMsgId = 0;
276     uint8_t netType = 1;
277     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
278         helper.slotId, enable, fromMsgId, toMsgId, netType);
279     helper.SetIntResult(result);
280     helper.NotifyAll();
281 }
282 
OpenCellBroadcastTestFuc6WithToken(SmsMmsTestHelper & helper)283 void OpenCellBroadcastTestFuc6WithToken(SmsMmsTestHelper &helper)
284 {
285     AccessMmsToken token;
286     OpenCellBroadcastTestFuc6(helper);
287 }
288 
289 /**
290  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0006
291  * @tc.name     Open cellBroadcast parameter is valid
292  * @tc.desc     Function test
293  */
294 HWTEST_F(CbGtest, OpenCellBroadcast_0006, Function | MediumTest | Level3)
295 {
296     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0006 -->");
297     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
298         TELEPHONY_LOGI("TelephonyTestService has no sim card");
299         ASSERT_TRUE(true);
300         return;
301     }
302     SmsMmsTestHelper helper;
303     helper.slotId = DEFAULT_SIM_SLOT_ID;
304     if (!helper.Run(OpenCellBroadcastTestFuc6WithToken, std::ref(helper))) {
305         TELEPHONY_LOGI("OpenCellBroadcastTestFuc6WithToken out of time");
306         ASSERT_TRUE(false);
307     }
308     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0006 -->finished");
309     ASSERT_GE(helper.GetIntResult(), 0);
310 }
311 
312 /**
313  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0007
314  * @tc.name     Open cellBroadcast fromMsgId less than toMsgId
315  * @tc.desc     Function test
316  */
317 HWTEST_F(CbGtest, OpenCellBroadcast_0007, Function | MediumTest | Level3)
318 {
319     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0007 -->");
320     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
321         TELEPHONY_LOGI("TelephonyTestService has no sim card");
322         ASSERT_TRUE(true);
323         return;
324     }
325     SmsMmsTestHelper helper;
326     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
327     if (!helper.Run(OpenCellBroadcastTestFuc2, std::ref(helper))) {
328         TELEPHONY_LOGI("OpenCellBroadcastTestFuc2 out of time");
329         ASSERT_TRUE(false);
330     }
331     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0007 -->finished");
332     EXPECT_NE(helper.GetIntResult(), 0);
333 }
334 
335 /**
336  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0008
337  * @tc.name     Open cellBroadcast netType is unknown.
338  * @tc.desc     Function test
339  */
340 HWTEST_F(CbGtest, OpenCellBroadcast_0008, Function | MediumTest | Level3)
341 {
342     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0008 -->");
343     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
344         TELEPHONY_LOGI("TelephonyTestService has no sim card");
345         ASSERT_TRUE(true);
346         return;
347     }
348     SmsMmsTestHelper helper;
349     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
350     if (!helper.Run(OpenCellBroadcastTestFuc3, std::ref(helper))) {
351         TELEPHONY_LOGI("OpenCellBroadcastTestFuc3 out of time");
352         ASSERT_TRUE(false);
353     }
354     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0008 -->finished");
355     EXPECT_NE(helper.GetIntResult(), 0);
356 }
357 
358 /**
359  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0009
360  * @tc.name     Open cellBroadcast parameter is valid.
361  * @tc.desc     Function test
362  */
363 HWTEST_F(CbGtest, OpenCellBroadcast_0009, Function | MediumTest | Level3)
364 {
365     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0009 -->");
366     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
367         TELEPHONY_LOGI("TelephonyTestService has no sim card");
368         ASSERT_TRUE(true);
369         return;
370     }
371     SmsMmsTestHelper helper;
372     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
373     if (!helper.Run(OpenCellBroadcastTestFuc4, std::ref(helper))) {
374         TELEPHONY_LOGI("OpenCellBroadcastTestFuc4 out of time");
375         ASSERT_TRUE(false);
376     }
377     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0009 -->finished");
378     ASSERT_EQ(helper.GetIntResult(), 0);
379 }
380 
381 /**
382  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0010
383  * @tc.name     Open cellBroadcast parameter is valid
384  * @tc.desc     Function test
385  */
386 HWTEST_F(CbGtest, OpenCellBroadcast_00010, Function | MediumTest | Level3)
387 {
388     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0010 -->");
389     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
390         TELEPHONY_LOGI("TelephonyTestService has no sim card");
391         ASSERT_TRUE(true);
392         return;
393     }
394     SmsMmsTestHelper helper;
395     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
396     if (!helper.Run(OpenCellBroadcastTestFuc5, std::ref(helper))) {
397         TELEPHONY_LOGI("OpenCellBroadcastTestFuc5 out of time");
398         ASSERT_TRUE(false);
399     }
400     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0010 -->finished");
401     ASSERT_EQ(helper.GetIntResult(), 0);
402 }
403 
404 /**
405  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0011
406  * @tc.name     Open cellBroadcast parameter is valid
407  * @tc.desc     Function test
408  */
409 HWTEST_F(CbGtest, OpenCellBroadcast_0011, Function | MediumTest | Level3)
410 {
411     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0011 -->");
412     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
413         TELEPHONY_LOGI("TelephonyTestService has no sim card");
414         ASSERT_TRUE(true);
415         return;
416     }
417     SmsMmsTestHelper helper;
418     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
419     if (!helper.Run(OpenCellBroadcastTestFuc6WithToken, std::ref(helper))) {
420         TELEPHONY_LOGI("OpenCellBroadcastTestFuc6WithToken out of time");
421         ASSERT_TRUE(false);
422     }
423     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0011 -->finished");
424     ASSERT_EQ(helper.GetIntResult(), 0);
425 }
426 
427 /**
428  * @tc.number   Telephony_SmsMmsGtest_OpenCellBroadcast_0012
429  * @tc.name     Open cellBroadcast parameter is valid
430  * @tc.desc     Function test
431  */
432 HWTEST_F(CbGtest, OpenCellBroadcast_0012, Function | MediumTest | Level3)
433 {
434     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0012 -->");
435     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
436         TELEPHONY_LOGI("TelephonyTestService has no sim card");
437         ASSERT_TRUE(true);
438         return;
439     }
440     SmsMmsTestHelper helper;
441     helper.slotId = DEFAULT_SIM_SLOT_ID;
442     if (!helper.Run(OpenCellBroadcastTestFuc6, std::ref(helper))) {
443         TELEPHONY_LOGI("OpenCellBroadcastTestFuc6 out of time");
444         ASSERT_TRUE(false);
445     }
446     TELEPHONY_LOGI("TelSMSMMSTest::OpenCellBroadcast_0012 -->finished");
447     EXPECT_NE(helper.GetIntResult(), 0);
448 }
449 
CloseCellBroadcastTestFuc(SmsMmsTestHelper & helper)450 void CloseCellBroadcastTestFuc(SmsMmsTestHelper &helper)
451 {
452     AccessMmsToken token;
453     bool enable = false;
454     uint32_t fromMsgId = 0;
455     uint32_t toMsgId = 10;
456     uint8_t netType = 1;
457     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
458         helper.slotId, enable, fromMsgId, toMsgId, netType);
459     helper.SetIntResult(result);
460     helper.NotifyAll();
461 }
462 
463 /**
464  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0001
465  * @tc.name     Close cellBroadcast slotId is -1
466  * @tc.desc     Function test
467  */
468 HWTEST_F(CbGtest, CloseCellBroadcast_0001, Function | MediumTest | Level3)
469 {
470     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0001 -->");
471     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
472         TELEPHONY_LOGI("TelephonyTestService has no sim card");
473         ASSERT_TRUE(true);
474         return;
475     }
476     SmsMmsTestHelper helper;
477     helper.slotId = DEFAULT_SIM_SLOT_ID_REMOVE;
478     if (!helper.Run(CloseCellBroadcastTestFuc, std::ref(helper))) {
479         TELEPHONY_LOGI("CloseCellBroadcastTestFuc out of time");
480         ASSERT_TRUE(false);
481     }
482     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0001 -->finished");
483     EXPECT_NE(helper.GetIntResult(), 0);
484 }
485 
CloseCellBroadcastTestFuc2(SmsMmsTestHelper & helper)486 void CloseCellBroadcastTestFuc2(SmsMmsTestHelper &helper)
487 {
488     AccessMmsToken token;
489     bool enable = false;
490     uint32_t fromMsgId = 20;
491     uint32_t toMsgId = 10;
492     uint8_t netType = 1;
493     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
494         helper.slotId, enable, fromMsgId, toMsgId, netType);
495     helper.SetIntResult(result);
496     helper.NotifyAll();
497 }
498 
499 /**
500  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0002
501  * @tc.name     Close cellBroadcast fromMsgId less than toMsgId
502  * @tc.desc     Function test
503  */
504 HWTEST_F(CbGtest, CloseCellBroadcast_0002, Function | MediumTest | Level3)
505 {
506     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0002 -->");
507     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
508         TELEPHONY_LOGI("TelephonyTestService has no sim card");
509         ASSERT_TRUE(true);
510         return;
511     }
512     SmsMmsTestHelper helper;
513     helper.slotId = DEFAULT_SIM_SLOT_ID;
514     if (!helper.Run(CloseCellBroadcastTestFuc2, std::ref(helper))) {
515         TELEPHONY_LOGI("CloseCellBroadcastTestFuc2 out of time");
516         ASSERT_TRUE(false);
517     }
518     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0002 -->finished");
519     EXPECT_NE(helper.GetIntResult(), 0);
520 }
521 
CloseCellBroadcastTestFuc3(SmsMmsTestHelper & helper)522 void CloseCellBroadcastTestFuc3(SmsMmsTestHelper &helper)
523 {
524     AccessMmsToken token;
525     bool enable = false;
526     uint32_t fromMsgId = 0;
527     uint32_t toMsgId = 10;
528     uint8_t netType = 3;
529     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
530         helper.slotId, enable, fromMsgId, toMsgId, netType);
531     helper.SetIntResult(result);
532     helper.NotifyAll();
533 }
534 
535 /**
536  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0003
537  * @tc.name     Close cellBroadcast netType is unknown
538  * @tc.desc     Function test
539  */
540 HWTEST_F(CbGtest, CloseCellBroadcast_0003, Function | MediumTest | Level3)
541 {
542     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0003 -->");
543     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
544         TELEPHONY_LOGI("TelephonyTestService has no sim card");
545         ASSERT_TRUE(true);
546         return;
547     }
548     SmsMmsTestHelper helper;
549     helper.slotId = DEFAULT_SIM_SLOT_ID;
550     if (!helper.Run(CloseCellBroadcastTestFuc3, std::ref(helper))) {
551         TELEPHONY_LOGI("CloseCellBroadcastTestFuc3 out of time");
552         ASSERT_TRUE(false);
553     }
554     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0003-->finished");
555     EXPECT_NE(helper.GetIntResult(), 0);
556 }
557 
CloseCellBroadcastTestFuc4(SmsMmsTestHelper & helper)558 void CloseCellBroadcastTestFuc4(SmsMmsTestHelper &helper)
559 {
560     AccessMmsToken token;
561     bool enable = false;
562     uint32_t fromMsgId = 0;
563     uint32_t toMsgId = 10;
564     uint8_t netType = 1;
565     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
566         helper.slotId, enable, fromMsgId, toMsgId, netType);
567     helper.SetIntResult(result);
568     helper.NotifyAll();
569 }
570 
571 /**
572  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0004
573  * @tc.name     Close cellBroadcast parameter is valid
574  * @tc.desc     Function test
575  */
576 HWTEST_F(CbGtest, CloseCellBroadcast_0004, Function | MediumTest | Level3)
577 {
578     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0004 -->");
579     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
580         TELEPHONY_LOGI("TelephonyTestService has no sim card");
581         ASSERT_TRUE(true);
582         return;
583     }
584     SmsMmsTestHelper helper;
585     helper.slotId = DEFAULT_SIM_SLOT_ID;
586     if (!helper.Run(CloseCellBroadcastTestFuc4, std::ref(helper))) {
587         TELEPHONY_LOGI("CloseCellBroadcastTestFuc4 out of time");
588         ASSERT_TRUE(false);
589     }
590     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0004 -->finished");
591     ASSERT_GE(helper.GetIntResult(), 0);
592 }
593 
CloseCellBroadcastTestFuc5(SmsMmsTestHelper & helper)594 void CloseCellBroadcastTestFuc5(SmsMmsTestHelper &helper)
595 {
596     AccessMmsToken token;
597     bool enable = false;
598     uint32_t fromMsgId = 0;
599     uint32_t toMsgId = 1000;
600     uint8_t netType = 1;
601     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
602         helper.slotId, enable, fromMsgId, toMsgId, netType);
603     helper.SetIntResult(result);
604     helper.NotifyAll();
605 }
606 
607 /**
608  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0005
609  * @tc.name     Close cellBroadcast parameter is valid
610  * @tc.desc     Function test
611  */
612 HWTEST_F(CbGtest, CloseCellBroadcast_0005, Function | MediumTest | Level3)
613 {
614     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0005 -->");
615     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
616         TELEPHONY_LOGI("TelephonyTestService has no sim card");
617         ASSERT_TRUE(true);
618         return;
619     }
620     SmsMmsTestHelper helper;
621     helper.slotId = DEFAULT_SIM_SLOT_ID;
622     if (!helper.Run(CloseCellBroadcastTestFuc5, std::ref(helper))) {
623         TELEPHONY_LOGI("CloseCellBroadcastTestFuc5 out of time");
624         ASSERT_TRUE(false);
625     }
626     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0005 -->finished");
627     ASSERT_GE(helper.GetIntResult(), 0);
628 }
629 
CloseCellBroadcastTestFuc6(SmsMmsTestHelper & helper)630 void CloseCellBroadcastTestFuc6(SmsMmsTestHelper &helper)
631 {
632     bool enable = false;
633     uint32_t fromMsgId = 0;
634     uint32_t toMsgId = 0;
635     uint8_t netType = 1;
636     int32_t result = DelayedSingleton<SmsServiceManagerClient>::GetInstance()->SetCBConfig(
637         helper.slotId, enable, fromMsgId, toMsgId, netType);
638     helper.SetIntResult(result);
639     helper.NotifyAll();
640 }
641 
CloseCellBroadcastTestFuc6WithToken(SmsMmsTestHelper & helper)642 void CloseCellBroadcastTestFuc6WithToken(SmsMmsTestHelper &helper)
643 {
644     AccessMmsToken token;
645     CloseCellBroadcastTestFuc6(helper);
646 }
647 
648 /**
649  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0006
650  * @tc.name     Close cellBroadcast parameter is valid
651  * @tc.desc     Function test
652  */
653 HWTEST_F(CbGtest, CloseCellBroadcast_0006, Function | MediumTest | Level3)
654 {
655     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0006 -->");
656     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
657         TELEPHONY_LOGI("TelephonyTestService has no sim card");
658         ASSERT_TRUE(true);
659         return;
660     }
661     SmsMmsTestHelper helper;
662     helper.slotId = DEFAULT_SIM_SLOT_ID;
663     if (!helper.Run(CloseCellBroadcastTestFuc6WithToken, std::ref(helper))) {
664         TELEPHONY_LOGI("CloseCellBroadcastTestFuc6WithToken out of time");
665         ASSERT_TRUE(false);
666     }
667     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0006 -->finished");
668     ASSERT_GE(helper.GetIntResult(), 0);
669 }
670 
671 /**
672  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0007
673  * @tc.name     Close cellBroadcast fromMsgId less than toMsgId
674  * @tc.desc     Function test
675  */
676 HWTEST_F(CbGtest, CloseCellBroadcast_0007, Function | MediumTest | Level3)
677 {
678     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0007 -->");
679     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
680         TELEPHONY_LOGI("TelephonyTestService has no sim card");
681         ASSERT_TRUE(true);
682         return;
683     }
684     SmsMmsTestHelper helper;
685     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
686     if (!helper.Run(CloseCellBroadcastTestFuc2, std::ref(helper))) {
687         TELEPHONY_LOGI("CloseCellBroadcastTestFuc7 out of time");
688         ASSERT_TRUE(false);
689     }
690     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0007 -->finished");
691     EXPECT_NE(helper.GetIntResult(), 0);
692 }
693 
694 /**
695  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0008
696  * @tc.name     Close cellBroadcast netType is unknown
697  * @tc.desc     Function test
698  */
699 HWTEST_F(CbGtest, CloseCellBroadcast_0008, Function | MediumTest | Level3)
700 {
701     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0008 -->");
702     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
703         TELEPHONY_LOGI("TelephonyTestService has no sim card");
704         ASSERT_TRUE(true);
705         return;
706     }
707     SmsMmsTestHelper helper;
708     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
709     if (!helper.Run(CloseCellBroadcastTestFuc3, std::ref(helper))) {
710         TELEPHONY_LOGI("CloseCellBroadcastTestFuc8 out of time");
711         ASSERT_TRUE(false);
712     }
713     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0008-->finished");
714     EXPECT_NE(helper.GetIntResult(), 0);
715 }
716 
717 /**
718  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0009
719  * @tc.name     Close cellBroadcast parameter is valid
720  * @tc.desc     Function test
721  */
722 HWTEST_F(CbGtest, CloseCellBroadcast_0009, Function | MediumTest | Level3)
723 {
724     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0009 -->");
725     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
726         TELEPHONY_LOGI("TelephonyTestService has no sim card");
727         ASSERT_TRUE(true);
728         return;
729     }
730     SmsMmsTestHelper helper;
731     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
732     if (!helper.Run(CloseCellBroadcastTestFuc4, std::ref(helper))) {
733         TELEPHONY_LOGI("CloseCellBroadcastTestFuc9 out of time");
734         ASSERT_TRUE(false);
735     }
736     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0009 -->finished");
737     ASSERT_GE(helper.GetIntResult(), 0);
738 }
739 
740 /**
741  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0010
742  * @tc.name     Close cellBroadcast parameter is valid
743  * @tc.desc     Function test
744  */
745 HWTEST_F(CbGtest, CloseCellBroadcast_0010, Function | MediumTest | Level3)
746 {
747     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0010 -->");
748     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
749         TELEPHONY_LOGI("TelephonyTestService has no sim card");
750         ASSERT_TRUE(true);
751         return;
752     }
753     SmsMmsTestHelper helper;
754     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
755     if (!helper.Run(CloseCellBroadcastTestFuc5, std::ref(helper))) {
756         TELEPHONY_LOGI("CloseCellBroadcastTestFuc10 out of time");
757         ASSERT_TRUE(false);
758     }
759     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0010 -->finished");
760     ASSERT_GE(helper.GetIntResult(), 0);
761 }
762 
763 /**
764  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0011
765  * @tc.name     Close cellBroadcast parameter is valid
766  * @tc.desc     Function test
767  */
768 HWTEST_F(CbGtest, CloseCellBroadcast_00011, Function | MediumTest | Level3)
769 {
770     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0011 -->");
771     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID_1))) {
772         TELEPHONY_LOGI("TelephonyTestService has no sim card");
773         ASSERT_TRUE(true);
774         return;
775     }
776     SmsMmsTestHelper helper;
777     helper.slotId = DEFAULT_SIM_SLOT_ID_1;
778     if (!helper.Run(CloseCellBroadcastTestFuc6WithToken, std::ref(helper))) {
779         TELEPHONY_LOGI("CloseCellBroadcastTestFuc6WithToken out of time");
780         ASSERT_TRUE(false);
781     }
782     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0011 -->finished");
783     ASSERT_GE(helper.GetIntResult(), 0);
784 }
785 
786 /**
787  * @tc.number   Telephony_SmsMmsGtest_CloseCellBroadcast_0012
788  * @tc.name     Close cellBroadcast parameter is valid
789  * @tc.desc     Function test
790  */
791 HWTEST_F(CbGtest, CloseCellBroadcast_0012, Function | MediumTest | Level3)
792 {
793     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0012 -->");
794     if (!(CbGtest::HasSimCard(DEFAULT_SIM_SLOT_ID))) {
795         TELEPHONY_LOGI("TelephonyTestService has no sim card");
796         ASSERT_TRUE(true);
797         return;
798     }
799     SmsMmsTestHelper helper;
800     helper.slotId = DEFAULT_SIM_SLOT_ID;
801     if (!helper.Run(CloseCellBroadcastTestFuc6, std::ref(helper))) {
802         TELEPHONY_LOGI("CloseCellBroadcastTestFuc6 out of time");
803         ASSERT_TRUE(false);
804     }
805     TELEPHONY_LOGI("TelSMSMMSTest::CloseCellBroadcast_0012 -->finished");
806     EXPECT_NE(helper.GetIntResult(), 0);
807 }
808 
ReceiveCellBroadCastTestFunc(SmsMmsTestHelper & helper)809 void ReceiveCellBroadCastTestFunc(SmsMmsTestHelper &helper)
810 {
811     AccessMmsToken token;
812     auto gsmSmsCbHandler = std::make_shared<GsmSmsCbHandler>(helper.slotId);
813     auto message = std::make_shared<CBConfigReportInfo>();
814     message->indicationType = MESSAGE_TYPE;
815     message->sn = 0;
816     message->mid = 0;
817     message->page = 0;
818     message->pages = 0;
819     message->dcs = "";
820     message->data = "";
821     message->length = CB_PDU_LEN;
822     message->pdu = "01a41f51101102ea3030a830ea30a230e130fc30eb914d4fe130c630b930c8000d000a3053308c306f8a669a137528306e3"
823                    "0e130c330bb30fc30b8306730593002000d000aff080032003000310033002f00310031002f003252ea3000370020003100"
824                    "35003a00340034ff09000d000aff0830a830ea30a25e02ff090000000000000000000000000000000000000000000000000"
825                    "0000000000000000000000000000000000000000000000022";
826     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_CELL_BROADCAST, message);
827     gsmSmsCbHandler->ProcessEvent(event);
828 }
829 
ReceiveCellBroadCastTestFunc2(SmsMmsTestHelper & helper)830 void ReceiveCellBroadCastTestFunc2(SmsMmsTestHelper &helper)
831 {
832     AccessMmsToken token;
833     auto gsmSmsCbHandler = std::make_shared<GsmSmsCbHandler>(helper.slotId);
834     auto message = std::make_shared<CBConfigReportInfo>();
835     message->indicationType = MESSAGE_TYPE;
836     message->sn = 0;
837     message->mid = 0;
838     message->page = 0;
839     message->pages = 0;
840     message->dcs = "";
841     message->data = "";
842     message->length = CB_PDU_LEN;
843     message->pdu = "C0000032401174747A0E4ACF41E8B0BCFD76E741EF39685C66B34162F93B4C1E87E77410BD3CA7836EC2341D440ED3C321";
844     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_CELL_BROADCAST, message);
845     gsmSmsCbHandler->ProcessEvent(event);
846 }
847 
848 /**
849  * @tc.number   Telephony_SmsMmsGtest_Receive_Cell_BroadCast_0001
850  * @tc.name     Receive a 3g Cell Broadcast
851  * @tc.desc     Function test
852  */
853 HWTEST_F(CbGtest, Receive_Cell_BroadCast_0001, Function | MediumTest | Level2)
854 {
855     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0001 -->");
856     int32_t slotId = DEFAULT_SIM_SLOT_ID;
857     if (!(CbGtest::HasSimCard(slotId))) {
858         TELEPHONY_LOGI("TelephonyTestService has no sim card");
859         ASSERT_TRUE(true);
860         return;
861     }
862     SmsMmsTestHelper helper;
863     helper.slotId = slotId;
864 
865     EventFwk::MatchingSkills matchingSkills;
866     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED);
867     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED);
868     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
869     std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
870         std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
871     if (subscriberTest == nullptr) {
872         ASSERT_TRUE(false);
873         return;
874     }
875     bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
876     TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
877 
878     if (!helper.Run(ReceiveCellBroadCastTestFunc, helper)) {
879         TELEPHONY_LOGI("ReceiveCellBroadCastTestFunc out of time");
880         ASSERT_TRUE(true);
881         return;
882     }
883     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0001 -->finished");
884     EXPECT_TRUE(helper.GetBoolResult());
885 }
886 
887 /**
888  * @tc.number   Telephony_SmsMmsGtest_Receive_Cell_BroadCast_0002
889  * @tc.name     Receive a 2g Cell Broadcast
890  * @tc.desc     Function test
891  */
892 HWTEST_F(CbGtest, Receive_Cell_BroadCast_0002, Function | MediumTest | Level2)
893 {
894     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0002 -->");
895     int32_t slotId = DEFAULT_SIM_SLOT_ID;
896     if (!(CbGtest::HasSimCard(slotId))) {
897         TELEPHONY_LOGI("TelephonyTestService has no sim card");
898         ASSERT_TRUE(true);
899         return;
900     }
901     SmsMmsTestHelper helper;
902     helper.slotId = slotId;
903 
904     EventFwk::MatchingSkills matchingSkills;
905     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED);
906     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED);
907     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
908     std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
909         std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
910     if (subscriberTest == nullptr) {
911         ASSERT_TRUE(false);
912         return;
913     }
914     bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
915     TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
916 
917     if (!helper.Run(ReceiveCellBroadCastTestFunc2, helper)) {
918         TELEPHONY_LOGI("ReceiveCellBroadCastTestFunc2 out of time");
919         ASSERT_TRUE(true);
920         return;
921     }
922     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0002 -->finished");
923     EXPECT_TRUE(helper.GetBoolResult());
924 }
925 
926 /**
927  * @tc.number   Telephony_SmsMmsGtest_Receive_Cell_BroadCast_0003
928  * @tc.name     Receive a 3g Cell Broadcast
929  * @tc.desc     Function test
930  */
931 HWTEST_F(CbGtest, Receive_Cell_BroadCast_0003, Function | MediumTest | Level2)
932 {
933     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0003 -->");
934     int32_t slotId = DEFAULT_SIM_SLOT_ID_1;
935     if (!(CbGtest::HasSimCard(slotId))) {
936         TELEPHONY_LOGI("TelephonyTestService has no sim card");
937         ASSERT_TRUE(true);
938         return;
939     }
940     SmsMmsTestHelper helper;
941     helper.slotId = slotId;
942 
943     EventFwk::MatchingSkills matchingSkills;
944     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED);
945     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED);
946     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
947     std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
948         std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
949     if (subscriberTest == nullptr) {
950         ASSERT_TRUE(false);
951         return;
952     }
953     bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
954     TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
955 
956     if (!helper.Run(ReceiveCellBroadCastTestFunc, helper)) {
957         TELEPHONY_LOGI("ReceiveCellBroadCastTestFunc out of time");
958         ASSERT_TRUE(true);
959         return;
960     }
961     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0003 -->finished");
962     EXPECT_TRUE(helper.GetBoolResult());
963 }
964 
965 /**
966  * @tc.number   Telephony_SmsMmsGtest_Receive_Cell_BroadCast_0004
967  * @tc.name     Receive a 2g Cell Broadcast
968  * @tc.desc     Function test
969  */
970 HWTEST_F(CbGtest, Receive_Cell_BroadCast_0004, Function | MediumTest | Level2)
971 {
972     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0004 -->");
973     int32_t slotId = DEFAULT_SIM_SLOT_ID_1;
974     if (!(CbGtest::HasSimCard(slotId))) {
975         TELEPHONY_LOGI("TelephonyTestService has no sim card");
976         ASSERT_TRUE(true);
977         return;
978     }
979     SmsMmsTestHelper helper;
980     helper.slotId = slotId;
981 
982     EventFwk::MatchingSkills matchingSkills;
983     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED);
984     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED);
985     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
986     std::shared_ptr<SmsBroadcastSubscriberGtest> subscriberTest =
987         std::make_shared<SmsBroadcastSubscriberGtest>(subscriberInfo, helper);
988     if (subscriberTest == nullptr) {
989         ASSERT_TRUE(false);
990         return;
991     }
992     bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberTest);
993     TELEPHONY_LOGI("subscribeResult is : %{public}d", subscribeResult);
994 
995     if (!helper.Run(ReceiveCellBroadCastTestFunc2, helper)) {
996         TELEPHONY_LOGI("ReceiveCellBroadCastTestFunc2 out of time");
997         ASSERT_TRUE(true);
998         return;
999     }
1000     TELEPHONY_LOGI("TelSMSMMSTest::Receive_Cell_BroadCast_0004 -->finished");
1001     EXPECT_TRUE(helper.GetBoolResult());
1002 }
1003 #endif // TEL_TEST_UNSUPPORT
1004 } // namespace Telephony
1005 } // namespace OHOS