• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "state_registry_test.h"
19 
20 #include "core_service_client.h"
21 #include "sim_state_type.h"
22 #include "telephony_log_wrapper.h"
23 #include "telephony_observer_client.h"
24 #include "telephony_observer_proxy.h"
25 #include "telephony_state_manager.h"
26 #include "telephony_state_registry_client.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 using namespace testing::ext;
31 sptr<StateRegistryObserver> StateRegistryTest::telephonyObserver0_ = nullptr;
32 sptr<StateRegistryObserver> StateRegistryTest::telephonyObserver1_ = nullptr;
33 static constexpr int32_t SIM_SLOT_ID_1 = DEFAULT_SIM_SLOT_ID + 1;
34 static constexpr int32_t CALL_STATUS_ACTIVE = 0;
35 static constexpr int32_t SINGLE_MODE_SIM_CARD = 10;
36 static constexpr int32_t SIM_STATE_NOT_PRESENT = 1;
37 static constexpr int32_t SIM_PIN = 1;
38 static constexpr int32_t DATA_STATE_CONNECTING = 1;
39 static constexpr int32_t NETWORK_TYPE_GSM = 1;
40 static constexpr int32_t DATA_FLOW_TYPE_DOWN = 1;
41 
SetUpTestCase(void)42 void StateRegistryTest::SetUpTestCase(void)
43 {
44     ASSERT_TRUE(CoreServiceClient::GetInstance().GetProxy() != nullptr);
45     InitTelephonyObserver();
46 }
47 
TearDownTestCase(void)48 void StateRegistryTest::TearDownTestCase(void)
49 {
50     DisableTelephonyObserver();
51 }
52 
InitTelephonyObserver()53 void StateRegistryTest::InitTelephonyObserver()
54 {
55     TELEPHONY_LOGI("Init telephony observer");
56     AccessToken token;
57     if (!telephonyObserver0_) {
58         telephonyObserver0_ = std::make_unique<StateRegistryObserver>().release();
59     }
60     auto res =
61         Telephony::TelephonyObserverClient::GetInstance().AddStateObserver(telephonyObserver0_, DEFAULT_SIM_SLOT_ID,
62             Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
63                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
64                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
65                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
66                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
67                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
68                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW |
69                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR |
70                 Telephony::TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR,
71             true);
72     TELEPHONY_LOGI("StateRegistryTest init telephony observer0 ret:%{public}d", res);
73     ASSERT_TRUE(res == TELEPHONY_SUCCESS);
74     if (!telephonyObserver1_) {
75         telephonyObserver1_ = std::make_unique<StateRegistryObserver>().release();
76     }
77     res = Telephony::TelephonyObserverClient::GetInstance().AddStateObserver(telephonyObserver1_, SIM_SLOT_ID_1,
78         Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
79             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
80             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
81             Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
82             Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
83             Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
84             Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW |
85             Telephony::TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR |
86             Telephony::TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR,
87         true);
88     TELEPHONY_LOGI("StateRegistryTest init telephony observer1 ret:%{public}d", res);
89     ASSERT_TRUE(res == TELEPHONY_SUCCESS);
90 }
91 
DisableTelephonyObserver()92 void StateRegistryTest::DisableTelephonyObserver()
93 {
94     TELEPHONY_LOGI("Disable telephony observer");
95     ASSERT_TRUE(telephonyObserver0_ != nullptr);
96     Telephony::TelephonyObserverClient::GetInstance().RemoveStateObserver(
97         DEFAULT_SIM_SLOT_ID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
98                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
99                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
100                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
101                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
102                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
103                                  Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW);
104     telephonyObserver0_ = nullptr;
105     ASSERT_TRUE(telephonyObserver1_ != nullptr);
106     Telephony::TelephonyObserverClient::GetInstance().RemoveStateObserver(
107         SIM_SLOT_ID_1, Telephony::TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE |
108                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE |
109                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO |
110                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS |
111                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE |
112                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE |
113                            Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW);
114     telephonyObserver1_ = nullptr;
115 }
116 
SetUp(void)117 void StateRegistryTest::SetUp(void)
118 {
119     // step 3: input testcase setup step
120 }
121 
TearDown(void)122 void StateRegistryTest::TearDown(void)
123 {
124     // step 3: input testcase teardown step
125 }
126 
HasSimCard(int32_t slotId)127 bool StateRegistryTest::HasSimCard(int32_t slotId)
128 {
129     bool hasSimCard = false;
130     CoreServiceClient::GetInstance().HasSimCard(slotId, hasSimCard);
131     return hasSimCard;
132 }
133 
UpdateCallState(int32_t slotId)134 void StateRegistryTest::UpdateCallState(int32_t slotId)
135 {
136     AccessToken token;
137     int32_t callState = 16;
138     std::string phoneNumber("137xxxxxxxx");
139     std::u16string number = Str8ToStr16(phoneNumber);
140     int32_t ret =
141         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallState(slotId, callState, number);
142     TELEPHONY_LOGI("StateRegistryTest::UpdateCallState ret = %{public}d", ret);
143     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
144 }
145 
UpdateCallStateForSlotId(int32_t slotId)146 void StateRegistryTest::UpdateCallStateForSlotId(int32_t slotId)
147 {
148     AccessToken token;
149     int32_t callState = 16;
150     int32_t callId = 0;
151     std::string phoneNumber("137xxxxxxxx");
152     std::u16string number = Str8ToStr16(phoneNumber);
153     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallStateForSlotId(
154         slotId, callId, callState, number);
155     TELEPHONY_LOGI("StateRegistryTest::UpdateCallStateForSlotId ret = %{public}d", ret);
156     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
157 }
158 
UpdateSignalInfo(int32_t slotId)159 void StateRegistryTest::UpdateSignalInfo(int32_t slotId)
160 {
161     AccessToken token;
162     std::vector<sptr<SignalInformation>> vec;
163     std::unique_ptr<SignalInformation> signal = std::make_unique<GsmSignalInformation>();
164     ASSERT_TRUE(signal != nullptr);
165     vec.push_back(signal.release());
166     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSignalInfo(slotId, vec);
167     TELEPHONY_LOGI("StateRegistryTest::UpdateSignalInfo ret = %{public}d", ret);
168     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
169 }
170 
UpdateCellularDataConnectState(int32_t slotId)171 void StateRegistryTest::UpdateCellularDataConnectState(int32_t slotId)
172 {
173     AccessToken token;
174     int32_t dataState = 1;
175     int32_t networkState = 1;
176     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCellularDataConnectState(
177         slotId, dataState, networkState);
178     TELEPHONY_LOGI("StateRegistryTest::UpdateCellularDataConnectState ret = %{public}d", ret);
179     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
180 }
181 
UpdateCellularDataFlow(int32_t slotId)182 void StateRegistryTest::UpdateCellularDataFlow(int32_t slotId)
183 {
184     AccessToken token;
185     int32_t dataFlowType = 0;
186     int32_t ret =
187         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCellularDataFlow(slotId, dataFlowType);
188     TELEPHONY_LOGI("StateRegistryTest::UpdateCellularDataFlow ret = %{public}d", ret);
189     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
190 }
191 
UpdateSimState(int32_t slotId)192 void StateRegistryTest::UpdateSimState(int32_t slotId)
193 {
194     AccessToken token;
195     CardType type = CardType::UNKNOWN_CARD;
196     SimState state = SimState::SIM_STATE_UNKNOWN;
197     LockReason reason = LockReason::SIM_NONE;
198     int32_t ret =
199         DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSimState(slotId, type, state, reason);
200     TELEPHONY_LOGI("StateRegistryTest::UpdateSimState ret = %{public}d", ret);
201     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
202 }
203 
UpdateNetworkState(int32_t slotId)204 void StateRegistryTest::UpdateNetworkState(int32_t slotId)
205 {
206     AccessToken token;
207     std::unique_ptr<NetworkState> networkState = std::make_unique<NetworkState>();
208     ASSERT_TRUE(networkState != nullptr);
209     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateNetworkState(
210         slotId, networkState.release());
211     TELEPHONY_LOGI("StateRegistryTest::UpdateNetworkState ret = %{public}d", ret);
212     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
213 }
214 
UpdateCfuIndicator(int32_t slotId)215 void StateRegistryTest::UpdateCfuIndicator(int32_t slotId)
216 {
217     AccessToken token;
218     bool cfuResult = true;
219     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCfuIndicator(
220         slotId, cfuResult);
221     TELEPHONY_LOGI("StateRegistryTest::UpdateCfuIndicator ret = %{public}d", ret);
222     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
223 }
224 
UpdateVoiceMailMsgIndicator(int32_t slotId)225 void StateRegistryTest::UpdateVoiceMailMsgIndicator(int32_t slotId)
226 {
227     AccessToken token;
228     bool voiceMailMsgResult = true;
229     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateVoiceMailMsgIndicator(
230         slotId, voiceMailMsgResult);
231     TELEPHONY_LOGI("StateRegistryTest::UpdateVoiceMailMsgIndicator ret = %{public}d", ret);
232     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
233 }
234 
UpdateIccAccount()235 void StateRegistryTest::UpdateIccAccount()
236 {
237     int32_t ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateIccAccount();
238     TELEPHONY_LOGI("StateRegistryTest::UpdateIccAccount ret = %{public}d", ret);
239     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
240 }
241 
242 #ifndef TEL_TEST_UNSUPPORT
243 /**
244  * @tc.number   StateRegistry_001
245  * @tc.name     Get System Services
246  * @tc.desc     Function test
247  */
248 HWTEST_F(StateRegistryTest, StateRegistry_001, Function | MediumTest | Level0)
249 {
250     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
251     ASSERT_TRUE(systemAbilityMgr != nullptr);
252     auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID);
253     ASSERT_TRUE(remote != nullptr);
254     auto stateRegistryService = iface_cast<ITelephonyStateNotify>(remote);
255     ASSERT_TRUE(stateRegistryService != nullptr);
256     TELEPHONY_LOGI("HWTEST_F StateRegistry_001");
257 }
258 
259 /**
260  * @tc.number   UpdateCallState_001
261  * @tc.name     update call state
262  * @tc.desc     Function test
263  */
264 HWTEST_F(StateRegistryTest, UpdateCallState_001, Function | MediumTest | Level1)
265 {
266     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
267         return;
268     }
269     UpdateCallState(DEFAULT_SIM_SLOT_ID);
270 }
271 
272 /**
273  * @tc.number   UpdateCallState_002
274  * @tc.name     update call state
275  * @tc.desc     Function test
276  */
277 HWTEST_F(StateRegistryTest, UpdateCallState_002, Function | MediumTest | Level1)
278 {
279     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
280         return;
281     }
282     UpdateCallState(SIM_SLOT_ID_1);
283 }
284 
285 /**
286  * @tc.number   UpdateCallStateForSlotId_001
287  * @tc.name     update call state by slotId
288  * @tc.desc     Function test
289  */
290 HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_001, Function | MediumTest | Level1)
291 {
292     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
293         return;
294     }
295     UpdateCallStateForSlotId(DEFAULT_SIM_SLOT_ID);
296 }
297 
298 /**
299  * @tc.number   UpdateCallStateForSlotId_002
300  * @tc.name     update call state by slotId
301  * @tc.desc     Function test
302  */
303 HWTEST_F(StateRegistryTest, UpdateCallStateForSlotId_002, Function | MediumTest | Level1)
304 {
305     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
306         return;
307     }
308     UpdateCallStateForSlotId(SIM_SLOT_ID_1);
309 }
310 
311 /**
312  * @tc.number   UpdateSignalInfo_001
313  * @tc.name     update signal info
314  * @tc.desc     Function test
315  */
316 HWTEST_F(StateRegistryTest, UpdateSignalInfo_001, Function | MediumTest | Level1)
317 {
318     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
319         return;
320     }
321     UpdateSignalInfo(DEFAULT_SIM_SLOT_ID);
322 }
323 
324 /**
325  * @tc.number   UpdateSignalInfo_002
326  * @tc.name     update signal info
327  * @tc.desc     Function test
328  */
329 HWTEST_F(StateRegistryTest, UpdateSignalInfo_002, Function | MediumTest | Level1)
330 {
331     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
332         return;
333     }
334     UpdateSignalInfo(SIM_SLOT_ID_1);
335 }
336 
337 /**
338  * @tc.number   UpdateCellularDataConnectState_001
339  * @tc.name     update cellular data connect state
340  * @tc.desc     Function test
341  */
342 HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_001, Function | MediumTest | Level1)
343 {
344     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
345         return;
346     }
347     UpdateCellularDataConnectState(DEFAULT_SIM_SLOT_ID);
348 }
349 
350 /**
351  * @tc.number   UpdateCellularDataConnectState_002
352  * @tc.name     update cellular data connect state
353  * @tc.desc     Function test
354  */
355 HWTEST_F(StateRegistryTest, UpdateCellularDataConnectState_002, Function | MediumTest | Level1)
356 {
357     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
358         return;
359     }
360     UpdateCellularDataConnectState(SIM_SLOT_ID_1);
361 }
362 
363 /**
364  * @tc.number   UpdateCellularDataFlow_001
365  * @tc.name     update cellular flow data
366  * @tc.desc     Function test
367  */
368 HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_001, Function | MediumTest | Level1)
369 {
370     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
371         return;
372     }
373     UpdateCellularDataFlow(DEFAULT_SIM_SLOT_ID);
374 }
375 
376 /**
377  * @tc.number   UpdateCellularDataFlow_002
378  * @tc.name     update cellular flow data
379  * @tc.desc     Function test
380  */
381 HWTEST_F(StateRegistryTest, UpdateCellularDataFlow_002, Function | MediumTest | Level1)
382 {
383     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
384         return;
385     }
386     UpdateCellularDataFlow(SIM_SLOT_ID_1);
387 }
388 
389 /**
390  * @tc.number   UpdateSimState_001
391  * @tc.name     update sim state
392  * @tc.desc     Function test
393  */
394 HWTEST_F(StateRegistryTest, UpdateSimState_001, Function | MediumTest | Level1)
395 {
396     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
397         return;
398     }
399     UpdateSimState(DEFAULT_SIM_SLOT_ID);
400 }
401 
402 /**
403  * @tc.number   UpdateSimState_002
404  * @tc.name     update sim state
405  * @tc.desc     Function test
406  */
407 HWTEST_F(StateRegistryTest, UpdateSimState_002, Function | MediumTest | Level1)
408 {
409     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
410         return;
411     }
412     UpdateSimState(SIM_SLOT_ID_1);
413 }
414 
415 /**
416  * @tc.number   UpdateNetworkState_001
417  * @tc.name     update network state
418  * @tc.desc     Function test
419  */
420 HWTEST_F(StateRegistryTest, UpdateNetworkState_001, Function | MediumTest | Level1)
421 {
422     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
423         return;
424     }
425     UpdateNetworkState(DEFAULT_SIM_SLOT_ID);
426 }
427 
428 /**
429  * @tc.number   UpdateNetworkState_002
430  * @tc.name     update network state
431  * @tc.desc     Function test
432  */
433 HWTEST_F(StateRegistryTest, UpdateNetworkState_002, Function | MediumTest | Level1)
434 {
435     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
436         return;
437     }
438     UpdateNetworkState(SIM_SLOT_ID_1);
439 }
440 
441 /**
442  * @tc.number   UpdateCfuIndicator_001
443  * @tc.name     update the result of call forwarding
444  * @tc.desc     Function test
445  */
446 HWTEST_F(StateRegistryTest, UpdateCfuIndicator_001, Function | MediumTest | Level1)
447 {
448     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
449         return;
450     }
451     UpdateCfuIndicator(DEFAULT_SIM_SLOT_ID);
452 }
453 
454 /**
455  * @tc.number   UpdateCfuIndicator_002
456  * @tc.name     update the result of call forwarding
457  * @tc.desc     Function test
458  */
459 HWTEST_F(StateRegistryTest, UpdateCfuIndicator_002, Function | MediumTest | Level1)
460 {
461     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
462         return;
463     }
464     UpdateCfuIndicator(SIM_SLOT_ID_1);
465 }
466 
467 /**
468  * @tc.number   UpdateVoiceMailMsgIndicator_001
469  * @tc.name     update voice mail message indicator
470  * @tc.desc     Function test
471  */
472 HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_001, Function | MediumTest | Level1)
473 {
474     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
475         return;
476     }
477     UpdateVoiceMailMsgIndicator(DEFAULT_SIM_SLOT_ID);
478 }
479 
480 /**
481  * @tc.number   UpdateVoiceMailMsgIndicator_002
482  * @tc.name     update voice mail message indicator
483  * @tc.desc     Function test
484  */
485 HWTEST_F(StateRegistryTest, UpdateVoiceMailMsgIndicator_002, Function | MediumTest | Level1)
486 {
487     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
488         return;
489     }
490     UpdateVoiceMailMsgIndicator(SIM_SLOT_ID_1);
491 }
492 
493 /**
494  * @tc.number   UpdateIccAccount_001
495  * @tc.name     UpdateIccAccount
496  * @tc.desc     Function test
497  */
498 HWTEST_F(StateRegistryTest, UpdateIccAccount_001, Function | MediumTest | Level1)
499 {
500     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
501         return;
502     }
503     UpdateIccAccount();
504 }
505 
506 /**
507  * @tc.number   UpdateIccAccount_002
508  * @tc.name     UpdateIccAccount
509  * @tc.desc     Function test
510  */
511 HWTEST_F(StateRegistryTest, UpdateIccAccount_002, Function | MediumTest | Level1)
512 {
513     if (!StateRegistryTest::HasSimCard(SIM_SLOT_ID_1)) {
514         return;
515     }
516     UpdateIccAccount();
517 }
518 
519 /**
520  * @tc.number   TelephonyStateManagerTest_001
521  * @tc.name     telephony state ,anager test
522  * @tc.desc     Function test
523  */
524 HWTEST_F(StateRegistryTest, TelephonyStateManagerTest_001, Function | MediumTest | Level1)
525 {
526     TELEPHONY_LOGI("TelephonyStateManagerTest_001 start!");
527     if (!StateRegistryTest::HasSimCard(DEFAULT_SIM_SLOT_ID)) {
528         return;
529     }
530     TelephonyStateManager::AddStateObserver(
531         telephonyObserver0_, DEFAULT_SIM_SLOT_ID, TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE, true);
532     wptr<IRemoteObject> wptrDeath = nullptr;
533     int32_t ret = TelephonyStateManager::RemoveStateObserver(
534         DEFAULT_SIM_SLOT_ID, Telephony::TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE);
535     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
536 }
537 
538 /**
539  * @tc.number   TelephonyObserverTest_001
540  * @tc.name     telephony observer test
541  * @tc.desc     Function test
542  */
543 HWTEST_F(StateRegistryTest, TelephonyObserverTest_001, Function | MediumTest | Level1)
544 {
545     TELEPHONY_LOGI("TelephonyObserverTest_001 start!");
546     MessageParcel dataParcel;
547     MessageParcel reply;
548     MessageOption option;
549     option.SetFlags(MessageOption::TF_ASYNC);
550     std::u16string testStr = u"test";
551     if (!dataParcel.WriteInterfaceToken(testStr)) {
552         TELEPHONY_LOGE("TelephonyObserverTest_001 WriteInterfaceToken failed!");
553         return;
554     }
555     int32_t ret = telephonyObserver.OnRemoteRequest(
556         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CALL_STATE_UPDATED), dataParcel, reply,
557         option);
558     EXPECT_EQ(TELEPHONY_ERR_DESCRIPTOR_MISMATCH, ret);
559 }
560 
561 /**
562  * @tc.number   TelephonyObserverTest_002
563  * @tc.name     telephony observer test
564  * @tc.desc     Function test
565  */
566 HWTEST_F(StateRegistryTest, TelephonyObserverTest_002, Function | MediumTest | Level1)
567 {
568     TELEPHONY_LOGI("TelephonyObserverTest_002 start!");
569     MessageParcel dataParcel;
570     MessageParcel reply;
571     MessageOption option;
572     std::u16string phoneNumber = u"123456";
573     option.SetFlags(MessageOption::TF_ASYNC);
574     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
575         TELEPHONY_LOGE("TelephonyObserverTest_002 WriteInterfaceToken failed!");
576         return;
577     }
578     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
579     dataParcel.WriteInt32(CALL_STATUS_ACTIVE);
580     dataParcel.WriteString16(phoneNumber);
581     int32_t ret = telephonyObserver.OnRemoteRequest(
582         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CALL_STATE_UPDATED), dataParcel, reply,
583         option);
584     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
585 }
586 
587 /**
588  * @tc.number   TelephonyObserverTest_003
589  * @tc.name     telephony observer test
590  * @tc.desc     Function test
591  */
592 HWTEST_F(StateRegistryTest, TelephonyObserverTest_003, Function | MediumTest | Level1)
593 {
594     TELEPHONY_LOGI("TelephonyObserverTest_003 start!");
595     MessageOption option;
596     MessageParcel dataParcel;
597     MessageParcel reply;
598     option.SetFlags(MessageOption::TF_ASYNC);
599     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
600         TELEPHONY_LOGE("TelephonyObserverTest_003 WriteInterfaceToken failed!");
601         return;
602     }
603     std::vector<sptr<SignalInformation>> vec;
604     std::unique_ptr<SignalInformation> gsmSignal = std::make_unique<GsmSignalInformation>();
605     ASSERT_TRUE(gsmSignal != nullptr);
606     vec.push_back(gsmSignal.release());
607     std::unique_ptr<WcdmaSignalInformation> wcdmaSignal = std::make_unique<WcdmaSignalInformation>();
608     ASSERT_TRUE(wcdmaSignal != nullptr);
609     vec.push_back(wcdmaSignal.release());
610     std::unique_ptr<TdScdmaSignalInformation> tdScdmaSignal = std::make_unique<TdScdmaSignalInformation>();
611     ASSERT_TRUE(tdScdmaSignal != nullptr);
612     vec.push_back(tdScdmaSignal.release());
613     std::unique_ptr<CdmaSignalInformation> cdmaSignal = std::make_unique<CdmaSignalInformation>();
614     ASSERT_TRUE(cdmaSignal != nullptr);
615     vec.push_back(cdmaSignal.release());
616     std::unique_ptr<LteSignalInformation> lteSignal = std::make_unique<LteSignalInformation>();
617     ASSERT_TRUE(lteSignal != nullptr);
618     vec.push_back(lteSignal.release());
619     int32_t size = static_cast<int32_t>(vec.size());
620     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
621     dataParcel.WriteInt32(size);
622     for (const auto &v : vec) {
623         v->Marshalling(dataParcel);
624     }
625     int32_t ret = telephonyObserver.OnRemoteRequest(
626         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_SIGNAL_INFO_UPDATED), dataParcel, reply,
627         option);
628     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
629 }
630 
631 /**
632  * @tc.number   TelephonyObserverTest_004
633  * @tc.name     telephony observer test
634  * @tc.desc     Function test
635  */
636 HWTEST_F(StateRegistryTest, TelephonyObserverTest_004, Function | MediumTest | Level1)
637 {
638     TELEPHONY_LOGI("TelephonyObserverTest_004 start!");
639     MessageOption option;
640     MessageParcel dataParcel;
641     MessageParcel reply;
642     option.SetFlags(MessageOption::TF_ASYNC);
643     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
644         TELEPHONY_LOGE("TelephonyObserverTest_004 WriteInterfaceToken failed!");
645         return;
646     }
647     std::vector<sptr<CellInformation>> vec;
648     std::unique_ptr<GsmCellInformation> gsmCell = std::make_unique<GsmCellInformation>();
649     ASSERT_TRUE(gsmCell != nullptr);
650     vec.push_back(gsmCell.release());
651     std::unique_ptr<LteCellInformation> lteCell = std::make_unique<LteCellInformation>();
652     ASSERT_TRUE(lteCell != nullptr);
653     vec.push_back(lteCell.release());
654     std::unique_ptr<WcdmaCellInformation> wcdmaCell = std::make_unique<WcdmaCellInformation>();
655     ASSERT_TRUE(wcdmaCell != nullptr);
656     vec.push_back(wcdmaCell.release());
657     int32_t size = static_cast<int32_t>(vec.size());
658     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
659     if (!dataParcel.WriteInt32(size)) {
660         TELEPHONY_LOGE("Failed to write Cellinformation array size!");
661         return;
662     }
663     for (const auto &v : vec) {
664         v->Marshalling(dataParcel);
665     }
666     int32_t ret = telephonyObserver.OnRemoteRequest(
667         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELL_INFO_UPDATED), dataParcel, reply,
668         option);
669     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
670 }
671 
672 /**
673  * @tc.number   TelephonyObserverTest_005
674  * @tc.name     telephony observer test
675  * @tc.desc     Function test
676  */
677 HWTEST_F(StateRegistryTest, TelephonyObserverTest_005, Function | MediumTest | Level1)
678 {
679     TELEPHONY_LOGI("TelephonyObserverTest_005 start!");
680     MessageOption option;
681     MessageParcel dataParcel;
682     MessageParcel reply;
683     option.SetFlags(MessageOption::TF_ASYNC);
684     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
685         TELEPHONY_LOGE("TelephonyObserverTest_005 WriteInterfaceToken failed!");
686         return;
687     }
688     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
689     std::unique_ptr<NetworkState> networkState = std::make_unique<NetworkState>();
690     ASSERT_TRUE(networkState != nullptr);
691     (networkState.release())->Marshalling(dataParcel);
692     int32_t ret = telephonyObserver.OnRemoteRequest(
693         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_NETWORK_STATE_UPDATED), dataParcel, reply,
694         option);
695     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
696 }
697 
698 /**
699  * @tc.number   TelephonyObserverTest_006
700  * @tc.name     telephony observer test
701  * @tc.desc     Function test
702  */
703 HWTEST_F(StateRegistryTest, TelephonyObserverTest_006, Function | MediumTest | Level1)
704 {
705     TELEPHONY_LOGI("TelephonyObserverTest_006 start!");
706     MessageOption option;
707     MessageParcel dataParcel;
708     MessageParcel reply;
709     option.SetFlags(MessageOption::TF_ASYNC);
710     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
711         TELEPHONY_LOGE("TelephonyObserverTest_006 WriteInterfaceToken failed!");
712         return;
713     }
714     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
715     dataParcel.WriteInt32(SINGLE_MODE_SIM_CARD);
716     dataParcel.WriteInt32(SIM_STATE_NOT_PRESENT);
717     dataParcel.WriteInt32(SIM_PIN);
718     int32_t ret = telephonyObserver.OnRemoteRequest(
719         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_SIM_STATE_UPDATED), dataParcel, reply,
720         option);
721     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
722 }
723 
724 /**
725  * @tc.number   TelephonyObserverTest_007
726  * @tc.name     telephony observer test
727  * @tc.desc     Function test
728  */
729 HWTEST_F(StateRegistryTest, TelephonyObserverTest_007, Function | MediumTest | Level1)
730 {
731     TELEPHONY_LOGI("TelephonyObserverTest_007 start!");
732     MessageOption option;
733     MessageParcel dataParcel;
734     MessageParcel reply;
735     option.SetFlags(MessageOption::TF_ASYNC);
736     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
737         TELEPHONY_LOGE("TelephonyObserverTest_007 WriteInterfaceToken failed!");
738         return;
739     }
740     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
741     dataParcel.WriteInt32(DATA_STATE_CONNECTING);
742     dataParcel.WriteInt32(NETWORK_TYPE_GSM);
743     int32_t ret = telephonyObserver.OnRemoteRequest(
744         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELLULAR_DATA_CONNECT_STATE_UPDATED),
745         dataParcel, reply, option);
746     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
747 }
748 
749 /**
750  * @tc.number   TelephonyObserverTest_008
751  * @tc.name     telephony observer test
752  * @tc.desc     Function test
753  */
754 HWTEST_F(StateRegistryTest, TelephonyObserverTest_008, Function | MediumTest | Level1)
755 {
756     TELEPHONY_LOGI("TelephonyObserverTest_008 start!");
757     MessageOption option;
758     MessageParcel dataParcel;
759     MessageParcel reply;
760     option.SetFlags(MessageOption::TF_ASYNC);
761     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
762         TELEPHONY_LOGE("TelephonyObserverTest_008 WriteInterfaceToken failed!");
763         return;
764     }
765     dataParcel.WriteInt32(DEFAULT_SIM_SLOT_ID);
766     dataParcel.WriteInt32(DATA_FLOW_TYPE_DOWN);
767     int32_t ret = telephonyObserver.OnRemoteRequest(
768         static_cast<uint32_t>(TelephonyObserverBroker::ObserverBrokerCode::ON_CELLULAR_DATA_FLOW_UPDATED), dataParcel,
769         reply, option);
770     EXPECT_EQ(TELEPHONY_ERR_SUCCESS, ret);
771 }
772 
773 /**
774  * @tc.number   TelephonyObserverTest_009
775  * @tc.name     telephony observer test
776  * @tc.desc     Function test
777  */
778 HWTEST_F(StateRegistryTest, TelephonyObserverTest_009, Function | MediumTest | Level1)
779 {
780     TELEPHONY_LOGI("TelephonyObserverTest_009 start!");
781     MessageOption option;
782     MessageParcel dataParcel;
783     MessageParcel reply;
784     option.SetFlags(MessageOption::TF_ASYNC);
785     if (!dataParcel.WriteInterfaceToken(TelephonyObserverProxy::GetDescriptor())) {
786         TELEPHONY_LOGE("TelephonyObserverTest_009 WriteInterfaceToken failed!");
787         return;
788     }
789     uint32_t testId = 123;
790     int32_t ret = telephonyObserver.OnRemoteRequest(testId, dataParcel, reply, option);
791     EXPECT_NE(TELEPHONY_ERR_SUCCESS, ret);
792 }
793 #else // TEL_TEST_UNSUPPORT
794 /**
795  * @tc.number   State_MockTest_001
796  * @tc.name     Mock test for unsupport platform
797  * @tc.desc     Function test
798  */
799 HWTEST_F(StateRegistryTest, State_MockTest_001, Function | MediumTest | Level1)
800 {
801     EXPECT_TRUE(true);
802 }
803 #endif // TEL_TEST_UNSUPPORT
804 } // namespace Telephony
805 } // namespace OHOS
806