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