From 8fbd20b5077d8c76b3de77fd57c30c4c574fed9f Mon Sep 17 00:00:00 2001 From: dingxiaochen Date: Tue, 29 Oct 2024 17:42:16 +0800 Subject: [PATCH] doc to unix. Signed-off-by: dingxiaochen --- .../state_test/state_registry_branch_test.cpp | 669 +++++++++--------- .../state_test/state_registry_branch_test.h | 307 ++++---- 2 files changed, 489 insertions(+), 487 deletions(-) diff --git a/test/unittest/state_test/state_registry_branch_test.cpp b/test/unittest/state_test/state_registry_branch_test.cpp index 0e9e04f..a86ab99 100644 --- a/test/unittest/state_test/state_registry_branch_test.cpp +++ b/test/unittest/state_test/state_registry_branch_test.cpp @@ -1,335 +1,336 @@ -/* - * Copyright (C) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define private public -#define protected public - -#include "state_registry_branch_test.h" - -#include "core_service_client.h" -#include "sim_state_type.h" -#include "state_registry_test.h" -#include "telephony_ext_wrapper.h" -#include "telephony_log_wrapper.h" -#include "telephony_observer_client.h" -#include "telephony_observer_proxy.h" -#include "telephony_state_manager.h" -#include "telephony_state_registry_client.h" -#include "telephony_state_registry_proxy.h" -#include "telephony_state_registry_service.h" - -namespace OHOS { -namespace Telephony { -using namespace testing::ext; -static constexpr int32_t DATA_STATE_CONNECTING = 1; -static constexpr int32_t NETWORK_TYPE_GSM = 1; -static constexpr int32_t DATA_FLOW_TYPE_DOWN = 1; -static constexpr int32_t PROFILE_STATE_DISCONNECTING = 3; -class StateRegistryBranchTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void StateRegistryBranchTest::SetUpTestCase(void) -{ - ASSERT_TRUE(CoreServiceClient::GetInstance().GetProxy() != nullptr); -} - -void StateRegistryBranchTest::TearDownTestCase(void) -{ -} - -void StateRegistryBranchTest::SetUp(void) {} - -void StateRegistryBranchTest::TearDown(void) {} - -class TestIRemoteObject : public IRemoteObject { -public: - uint32_t requestCode_ = -1; - int32_t result_ = 0; - -public: - TestIRemoteObject() : IRemoteObject(u"test_remote_object") {} - - ~TestIRemoteObject() {} - - int32_t GetObjectRefCount() override - { - return 0; - } - - int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override - { - TELEPHONY_LOGI("Mock SendRequest"); - requestCode_ = code; - reply.WriteInt32(result_); - return 0; - } - - bool IsProxyObject() const override - { - return true; - } - - bool CheckObjectLegality() const override - { - return true; - } - - bool AddDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool RemoveDeathRecipient(const sptr &recipient) override - { - return true; - } - - bool Marshalling(Parcel &parcel) const override - { - return true; - } - - sptr AsInterface() override - { - return nullptr; - } - - int Dump(int fd, const std::vector &args) override - { - return 0; - } - - std::u16string GetObjectDescriptor() const - { - std::u16string descriptor = std::u16string(); - return descriptor; - } -}; - -/** - * @tc.number StateRegistry_Notify_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, StateRegistry_Notify_001, Function | MediumTest | Level0) -{ - sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - ASSERT_NE(sam, nullptr); - sptr obj = sam->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID); - ASSERT_NE(obj, nullptr); - std::shared_ptr telephonyObserverProxy = - std::make_shared(obj); - CardType type = CardType::UNKNOWN_CARD; - SimState state = SimState::SIM_STATE_UNKNOWN; - LockReason reason = LockReason::SIM_NONE; - telephonyObserverProxy->OnSimStateUpdated(0, type, state, reason); - std::vector> vec; - std::unique_ptr gsmCell = std::make_unique(); - vec.push_back(gsmCell.release()); - telephonyObserverProxy->OnCellInfoUpdated(0, vec); - std::unique_ptr networkState = std::make_unique(); - telephonyObserverProxy->OnNetworkStateUpdated(0, networkState.release()); - telephonyObserverProxy->OnCellularDataConnectStateUpdated(0, DATA_STATE_CONNECTING, NETWORK_TYPE_GSM); - telephonyObserverProxy->OnCellularDataFlowUpdated(0, DATA_FLOW_TYPE_DOWN); - telephonyObserverProxy->OnCfuIndicatorUpdated(0, true); - telephonyObserverProxy->OnVoiceMailMsgIndicatorUpdated(0, true); - ASSERT_NE(telephonyObserverProxy, nullptr); -} - -/** - * @tc.number TelephonyStateRegistryService_OnStart_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_OnStart_001, Function | MediumTest | Level0) -{ - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - service->state_ = ServiceRunningState::STATE_RUNNING; - service->OnStart(); - ASSERT_EQ(static_cast(service->state_), static_cast(ServiceRunningState::STATE_RUNNING)); -} - -/** - * @tc.number TelephonyStateRegistryService_OnStart_002 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_OnStart_002, Function | MediumTest | Level0) -{ - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - service->OnStart(); - service->OnStop(); - ASSERT_EQ(static_cast(service->state_), static_cast(ServiceRunningState::STATE_STOPPED)); -} - -/** - * @tc.number TelephonyStateRegistryService_UpdateIccAccount_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_001, Function | MediumTest | Level0) -{ - AccessToken token; - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - TelephonyStateRegistryRecord record; - service->stateRecords_.push_back(record); - service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT; - service->stateRecords_[0].telephonyObserver_ = nullptr; - auto result = service->UpdateIccAccount(); - ASSERT_EQ(result, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST); -} - -/** - * @tc.number TelephonyStateRegistryService_UpdateIccAccount_002 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_002, Function | MediumTest | Level0) -{ - AccessToken token; - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - TelephonyStateRegistryRecord record; - service->stateRecords_.push_back(record); - service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT; - service->stateRecords_[0].telephonyObserver_ = std::make_unique().release(); - auto result = service->UpdateIccAccount(); - ASSERT_EQ(result, TELEPHONY_SUCCESS); -} - -/** - * @tc.number TelephonyStateRegistryService_UpdateIccAccount_003 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_003, Function | MediumTest | Level0) -{ - AccessToken token; - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - TelephonyStateRegistryRecord record; - service->stateRecords_.push_back(record); - service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE; - auto result = service->UpdateIccAccount(); - ASSERT_EQ(result, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST); -} - -/** - * @tc.number TelephonyStateRegistryService_CheckCallerIsSystemApp_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, Service_CheckCallerIsSystemApp_001, Function | MediumTest | Level0) -{ - SecurityToken token; - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - bool result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO); - ASSERT_EQ(result, false); - result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR); - ASSERT_EQ(result, false); - result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR); - ASSERT_EQ(result, false); - pid_t pid = -1; - auto ret = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); - ASSERT_EQ(ret, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API); -} - -/** - * @tc.number TelephonyStateRegistryService_UnregisterStateChange_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, Service_UnregisterStateChange_001, Function | MediumTest | Level0) -{ - AccessToken token; - auto service = DelayedSingleton::GetInstance(); - ASSERT_NE(service, nullptr); - TelephonyStateRegistryRecord record; - service->stateRecords_.push_back(record); - service->stateRecords_[0].slotId_ = 1; - pid_t pid = -1; - auto result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); - ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); - service->stateRecords_[0].slotId_ = 0; - service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW; - result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); - ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); - service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO; - service->stateRecords_[0].tokenId_ = 1234; - result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); - ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); - service->stateRecords_[0].pid_ = 1; - result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 1234, pid); - ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); -} - -/** - * @tc.number TelephonyStateRegistryService_UnregisterStateChange_001 - * @tc.name Get System Services - * @tc.desc Function test - */ -HWTEST_F(StateRegistryBranchTest, UpdateCellularDataConnectState_001, Function | MediumTest | Level0) -{ - sptr remote = new (std::nothrow) TestIRemoteObject(); - std::shared_ptr proxy = std::make_shared(remote); - auto result = proxy->UpdateCellularDataConnectState(0, PROFILE_STATE_DISCONNECTING, 0); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UpdateCellularDataFlow(0, 0); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - int32_t callState = 16; - std::string phoneNumber("137xxxxxxxx"); - std::u16string number = Str8ToStr16(phoneNumber); - result = proxy->UpdateCallState(callState, number); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UpdateCallStateForSlotId(0, callState, number); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - std::vector> vec; - std::unique_ptr signal = std::make_unique(); - ASSERT_TRUE(signal != nullptr); - vec.push_back(signal.release()); - result = proxy->UpdateSignalInfo(0, vec); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - std::vector> cellInfoList; - sptr gsmCellInformation = new GsmCellInformation(); - cellInfoList.push_back(gsmCellInformation); - result = proxy->UpdateCellInfo(0, cellInfoList); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - sptr networkState = std::make_unique().release(); - result = proxy->UpdateNetworkState(0, networkState); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - CardType type = CardType::UNKNOWN_CARD; - SimState state = SimState::SIM_STATE_UNKNOWN; - LockReason reason = LockReason::SIM_NONE; - result = proxy->UpdateSimState(0, type, state, reason); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UpdateCfuIndicator(0, true); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UpdateVoiceMailMsgIndicator(0, true); - ASSERT_EQ(result, TELEPHONY_SUCCESS); - result = proxy->UpdateIccAccount(); - ASSERT_EQ(result, TELEPHONY_SUCCESS); -} -} // namespace Telephony +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define private public +#define protected public + +#include "state_registry_branch_test.h" + +#include "core_service_client.h" +#include "sim_state_type.h" +#include "state_registry_test.h" +#include "telephony_ext_wrapper.h" +#include "telephony_log_wrapper.h" +#include "telephony_observer_client.h" +#include "telephony_observer_proxy.h" +#include "telephony_state_manager.h" +#include "telephony_state_registry_client.h" +#include "telephony_state_registry_proxy.h" +#include "telephony_state_registry_service.h" + +namespace OHOS { +namespace Telephony { +using namespace testing::ext; +static constexpr int32_t DATA_STATE_CONNECTING = 1; +static constexpr int32_t NETWORK_TYPE_GSM = 1; +static constexpr int32_t DATA_FLOW_TYPE_DOWN = 1; +static constexpr int32_t PROFILE_STATE_DISCONNECTING = 3; +class StateRegistryBranchTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void StateRegistryBranchTest::SetUpTestCase(void) +{ + ASSERT_TRUE(CoreServiceClient::GetInstance().GetProxy() != nullptr); +} + +void StateRegistryBranchTest::TearDownTestCase(void) +{ +} + +void StateRegistryBranchTest::SetUp(void) {} + +void StateRegistryBranchTest::TearDown(void) {} + +class TestIRemoteObject : public IRemoteObject { +public: + uint32_t requestCode_ = -1; + int32_t result_ = 0; + +public: + TestIRemoteObject() : IRemoteObject(u"test_remote_object") {} + + ~TestIRemoteObject() {} + + int32_t GetObjectRefCount() override + { + return 0; + } + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + TELEPHONY_LOGI("Mock SendRequest"); + requestCode_ = code; + reply.WriteInt32(result_); + return 0; + } + + bool IsProxyObject() const override + { + return true; + } + + bool CheckObjectLegality() const override + { + return true; + } + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool RemoveDeathRecipient(const sptr &recipient) override + { + return true; + } + + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + sptr AsInterface() override + { + return nullptr; + } + + int Dump(int fd, const std::vector &args) override + { + return 0; + } + + std::u16string GetObjectDescriptor() const + { + std::u16string descriptor = std::u16string(); + return descriptor; + } +}; + +/** + * @tc.number StateRegistry_Notify_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, StateRegistry_Notify_001, Function | MediumTest | Level0) +{ + sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + ASSERT_NE(sam, nullptr); + sptr obj = sam->CheckSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID); + ASSERT_NE(obj, nullptr); + std::shared_ptr telephonyObserverProxy = + std::make_shared(obj); + CardType type = CardType::UNKNOWN_CARD; + SimState state = SimState::SIM_STATE_UNKNOWN; + LockReason reason = LockReason::SIM_NONE; + telephonyObserverProxy->OnSimStateUpdated(0, type, state, reason); + std::vector> vec; + std::unique_ptr gsmCell = std::make_unique(); + vec.push_back(gsmCell.release()); + telephonyObserverProxy->OnCellInfoUpdated(0, vec); + std::unique_ptr networkState = std::make_unique(); + telephonyObserverProxy->OnNetworkStateUpdated(0, networkState.release()); + telephonyObserverProxy->OnCellularDataConnectStateUpdated(0, DATA_STATE_CONNECTING, NETWORK_TYPE_GSM); + telephonyObserverProxy->OnCellularDataFlowUpdated(0, DATA_FLOW_TYPE_DOWN); + telephonyObserverProxy->OnCfuIndicatorUpdated(0, true); + telephonyObserverProxy->OnVoiceMailMsgIndicatorUpdated(0, true); + ASSERT_NE(telephonyObserverProxy, nullptr); +} + +/** + * @tc.number TelephonyStateRegistryService_OnStart_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_OnStart_001, Function | MediumTest | Level0) +{ + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + service->state_ = ServiceRunningState::STATE_RUNNING; + service->OnStart(); + ASSERT_EQ(static_cast(service->state_), static_cast(ServiceRunningState::STATE_RUNNING)); +} + +/** + * @tc.number TelephonyStateRegistryService_OnStart_002 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_OnStart_002, Function | MediumTest | Level0) +{ + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + service->OnStart(); + service->OnStop(); + ASSERT_EQ(static_cast(service->state_), static_cast(ServiceRunningState::STATE_STOPPED)); +} + +/** + * @tc.number TelephonyStateRegistryService_UpdateIccAccount_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_001, Function | MediumTest | Level0) +{ + AccessToken token; + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + TelephonyStateRegistryRecord record; + service->stateRecords_.push_back(record); + service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT; + service->stateRecords_[0].telephonyObserver_ = nullptr; + auto result = service->UpdateIccAccount(); + ASSERT_EQ(result, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST); +} + +/** + * @tc.number TelephonyStateRegistryService_UpdateIccAccount_002 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_002, Function | MediumTest | Level0) +{ + AccessToken token; + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + TelephonyStateRegistryRecord record; + service->stateRecords_.push_back(record); + service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT; + service->stateRecords_[0].telephonyObserver_ = std::make_unique().release(); + auto result = service->UpdateIccAccount(); + ASSERT_EQ(result, TELEPHONY_SUCCESS); +} + +/** + * @tc.number TelephonyStateRegistryService_UpdateIccAccount_003 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, TelephonyStateRegistryService_UpdateIccAccount_003, Function | MediumTest | Level0) +{ + AccessToken token; + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + TelephonyStateRegistryRecord record; + service->stateRecords_.push_back(record); + service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE; + auto result = service->UpdateIccAccount(); + ASSERT_EQ(result, TELEPHONY_STATE_REGISTRY_DATA_NOT_EXIST); +} + +/** + * @tc.number TelephonyStateRegistryService_CheckCallerIsSystemApp_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, Service_CheckCallerIsSystemApp_001, Function | MediumTest | Level0) +{ + SecurityToken token; + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + bool result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO); + ASSERT_EQ(result, false); + result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR); + ASSERT_EQ(result, false); + result = service->CheckCallerIsSystemApp(TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR); + ASSERT_EQ(result, false); + pid_t pid = -1; + auto ret = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); + ASSERT_EQ(ret, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API); +} + +/** + * @tc.number TelephonyStateRegistryService_UnregisterStateChange_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, Service_UnregisterStateChange_001, Function | MediumTest | Level0) +{ + AccessToken token; + auto service = DelayedSingleton::GetInstance(); + ASSERT_NE(service, nullptr); + TelephonyStateRegistryRecord record; + service->stateRecords_.push_back(record); + service->stateRecords_[0].slotId_ = 1; + pid_t pid = -1; + auto result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); + ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); + service->stateRecords_[0].slotId_ = 0; + service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW; + result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); + ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); + service->stateRecords_[0].mask_ = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO; + service->stateRecords_[0].tokenId_ = 1234; + result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 0, pid); + ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); + service->stateRecords_[0].pid_ = 1; + result = service->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 1234, pid); + ASSERT_EQ(result, TELEPHONY_STATE_UNREGISTRY_DATA_NOT_EXIST); +} + +/** + * @tc.number TelephonyStateRegistryService_UnregisterStateChange_001 + * @tc.name Get System Services + * @tc.desc Function test + */ +HWTEST_F(StateRegistryBranchTest, UpdateCellularDataConnectState_001, Function | MediumTest | Level0) +{ + sptr remote = new (std::nothrow) TestIRemoteObject(); + std::shared_ptr proxy = std::make_shared(remote); + auto result = proxy->UpdateCellularDataConnectState(0, PROFILE_STATE_DISCONNECTING, 0); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UpdateCellularDataFlow(0, 0); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + int32_t callState = 16; + std::string phoneNumber("137xxxxxxxx"); + std::u16string number = Str8ToStr16(phoneNumber); + result = proxy->UpdateCallState(callState, number); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UpdateCallStateForSlotId(0, callState, number); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + std::vector> vec; + std::unique_ptr signal = std::make_unique(); + ASSERT_TRUE(signal != nullptr); + vec.push_back(signal.release()); + result = proxy->UpdateSignalInfo(0, vec); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + std::vector> cellInfoList; + sptr gsmCellInformation = new GsmCellInformation(); + cellInfoList.push_back(gsmCellInformation); + result = proxy->UpdateCellInfo(0, cellInfoList); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + sptr networkState = std::make_unique().release(); + result = proxy->UpdateNetworkState(0, networkState); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + CardType type = CardType::UNKNOWN_CARD; + SimState state = SimState::SIM_STATE_UNKNOWN; + LockReason reason = LockReason::SIM_NONE; + result = proxy->UpdateSimState(0, type, state, reason); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UnregisterStateChange(0, TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UpdateCfuIndicator(0, true); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UpdateVoiceMailMsgIndicator(0, true); + ASSERT_EQ(result, TELEPHONY_SUCCESS); + result = proxy->UpdateIccAccount(); + ASSERT_EQ(result, TELEPHONY_SUCCESS); +} + +} // namespace Telephony } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/state_test/state_registry_branch_test.h b/test/unittest/state_test/state_registry_branch_test.h index 64c55c0..d84e912 100644 --- a/test/unittest/state_test/state_registry_branch_test.h +++ b/test/unittest/state_test/state_registry_branch_test.h @@ -1,154 +1,155 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef OHOS_STATE_REGISTRY_BRANCH_TEST_H -#define OHOS_STATE_REGISTRY_BRANCH_TEST_H - -#include -#include "security_token.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" - -namespace OHOS { -namespace Telephony { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -inline HapInfoParams testInfoParams = { - .bundleName = "tel_state_registry_branch_test", - .userID = 1, - .instIndex = 0, - .appIDDesc = "test", - .isSystemApp = false, -}; - -inline PermissionDef testPermGetTelephonyStateDef = { - .permissionName = "ohos.permission.GET_TELEPHONY_STATE", - .bundleName = "tel_state_registry_branch_test", - .grantMode = 1, // SYSTEM_GRANT - .label = "label", - .labelId = 1, - .description = "Test state registry", - .descriptionId = 1, - .availableLevel = APL_SYSTEM_BASIC, -}; - -inline PermissionStateFull testGetTelephonyState = { - .grantFlags = { 2 }, // PERMISSION_USER_SET - .grantStatus = { PermissionState::PERMISSION_GRANTED }, - .isGeneral = true, - .permissionName = "ohos.permission.GET_TELEPHONY_STATE", - .resDeviceID = { "local" }, -}; - -inline PermissionDef testPermSetTelephonyStateDef = { - .permissionName = "ohos.permission.SET_TELEPHONY_STATE", - .bundleName = "tel_state_registry_branch_test", - .grantMode = 1, // SYSTEM_GRANT - .label = "label", - .labelId = 1, - .description = "Test core service", - .descriptionId = 1, - .availableLevel = APL_SYSTEM_BASIC, -}; - -inline PermissionStateFull testSetTelephonyState = { - .grantFlags = { 2 }, // PERMISSION_USER_SET - .grantStatus = { PermissionState::PERMISSION_GRANTED }, - .isGeneral = true, - .permissionName = "ohos.permission.SET_TELEPHONY_STATE", - .resDeviceID = { "local" }, -}; - -inline PermissionDef testPermGetNetworkInfoDef = { - .permissionName = "ohos.permission.GET_NETWORK_INFO", - .bundleName = "tel_state_registry_branch_test", - .grantMode = 1, // SYSTEM_GRANT - .label = "label", - .labelId = 1, - .description = "Test core service", - .descriptionId = 1, - .availableLevel = APL_SYSTEM_BASIC, -}; - -inline PermissionStateFull testPermGetNetworkInfo = { - .grantFlags = { 2 }, // PERMISSION_USER_SET - .grantStatus = { PermissionState::PERMISSION_GRANTED }, - .isGeneral = true, - .permissionName = "ohos.permission.GET_NETWORK_INFO", - .resDeviceID = { "local" }, -}; - -inline PermissionDef testSimPermWriteContactsDef = { - .permissionName = "ohos.permission.WRITE_CONTACTS", - .bundleName = "tel_state_registry_branch_test", - .grantMode = 1, // SYSTEM_GRANT - .label = "label", - .labelId = 1, - .description = "Test core service", - .descriptionId = 1, - .availableLevel = APL_SYSTEM_BASIC, -}; - -inline PermissionStateFull testSimPermWriteContacts = { - .grantFlags = { 2 }, // PERMISSION_USER_SET - .grantStatus = { PermissionState::PERMISSION_GRANTED }, - .isGeneral = true, - .permissionName = "ohos.permission.WRITE_CONTACTS", - .resDeviceID = { "local" }, -}; - -inline PermissionDef testSimPermReadContactsDef = { - .permissionName = "ohos.permission.READ_CONTACTS", - .bundleName = "tel_state_registry_branch_test", - .grantMode = 1, // SYSTEM_GRANT - .label = "label", - .labelId = 1, - .description = "Test core service", - .descriptionId = 1, - .availableLevel = APL_SYSTEM_BASIC, -}; - -inline PermissionStateFull testSimPermReadContacts = { - .grantFlags = { 2 }, // PERMISSION_USER_SET - .grantStatus = { PermissionState::PERMISSION_GRANTED }, - .isGeneral = true, - .permissionName = "ohos.permission.READ_CONTACTS", - .resDeviceID = { "local" }, -}; - -inline HapPolicyParams testStateRegistryPolicyParams = { - .apl = APL_SYSTEM_BASIC, - .domain = "test.domain", - .permList = { testPermGetTelephonyStateDef, testPermSetTelephonyStateDef, testPermGetNetworkInfoDef, - testSimPermWriteContactsDef, testSimPermReadContactsDef }, - .permStateList = { testGetTelephonyState, testSetTelephonyState, testPermGetNetworkInfo, testSimPermWriteContacts, - testSimPermReadContacts }, -}; - -SecurityToken::SecurityToken() -{ - currentID_ = GetSelfTokenID(); - AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testStateRegistryPolicyParams); - accessID_ = tokenIdEx.tokenIdExStruct.tokenID; - SetSelfTokenID(tokenIdEx.tokenIDEx); -} - -SecurityToken::~SecurityToken() -{ - AccessTokenKit::DeleteToken(accessID_); - SetSelfTokenID(currentID_); -} -} // namespace Telephony -} // namespace OHOS +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_STATE_REGISTRY_BRANCH_TEST_H +#define OHOS_STATE_REGISTRY_BRANCH_TEST_H + +#include +#include "security_token.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" + +namespace OHOS { +namespace Telephony { +using namespace Security::AccessToken; +using Security::AccessToken::AccessTokenID; +inline HapInfoParams testInfoParams = { + .bundleName = "tel_state_registry_branch_test", + .userID = 1, + .instIndex = 0, + .appIDDesc = "test", + .isSystemApp = false, +}; + +inline PermissionDef testPermGetTelephonyStateDef = { + .permissionName = "ohos.permission.GET_TELEPHONY_STATE", + .bundleName = "tel_state_registry_branch_test", + .grantMode = 1, // SYSTEM_GRANT + .label = "label", + .labelId = 1, + .description = "Test state registry", + .descriptionId = 1, + .availableLevel = APL_SYSTEM_BASIC, +}; + +inline PermissionStateFull testGetTelephonyState = { + .grantFlags = { 2 }, // PERMISSION_USER_SET + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .isGeneral = true, + .permissionName = "ohos.permission.GET_TELEPHONY_STATE", + .resDeviceID = { "local" }, +}; + +inline PermissionDef testPermSetTelephonyStateDef = { + .permissionName = "ohos.permission.SET_TELEPHONY_STATE", + .bundleName = "tel_state_registry_branch_test", + .grantMode = 1, // SYSTEM_GRANT + .label = "label", + .labelId = 1, + .description = "Test core service", + .descriptionId = 1, + .availableLevel = APL_SYSTEM_BASIC, +}; + +inline PermissionStateFull testSetTelephonyState = { + .grantFlags = { 2 }, // PERMISSION_USER_SET + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .isGeneral = true, + .permissionName = "ohos.permission.SET_TELEPHONY_STATE", + .resDeviceID = { "local" }, +}; + +inline PermissionDef testPermGetNetworkInfoDef = { + .permissionName = "ohos.permission.GET_NETWORK_INFO", + .bundleName = "tel_state_registry_branch_test", + .grantMode = 1, // SYSTEM_GRANT + .label = "label", + .labelId = 1, + .description = "Test core service", + .descriptionId = 1, + .availableLevel = APL_SYSTEM_BASIC, +}; + +inline PermissionStateFull testPermGetNetworkInfo = { + .grantFlags = { 2 }, // PERMISSION_USER_SET + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .isGeneral = true, + .permissionName = "ohos.permission.GET_NETWORK_INFO", + .resDeviceID = { "local" }, +}; + +inline PermissionDef testSimPermWriteContactsDef = { + .permissionName = "ohos.permission.WRITE_CONTACTS", + .bundleName = "tel_state_registry_branch_test", + .grantMode = 1, // SYSTEM_GRANT + .label = "label", + .labelId = 1, + .description = "Test core service", + .descriptionId = 1, + .availableLevel = APL_SYSTEM_BASIC, +}; + +inline PermissionStateFull testSimPermWriteContacts = { + .grantFlags = { 2 }, // PERMISSION_USER_SET + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .isGeneral = true, + .permissionName = "ohos.permission.WRITE_CONTACTS", + .resDeviceID = { "local" }, +}; + +inline PermissionDef testSimPermReadContactsDef = { + .permissionName = "ohos.permission.READ_CONTACTS", + .bundleName = "tel_state_registry_branch_test", + .grantMode = 1, // SYSTEM_GRANT + .label = "label", + .labelId = 1, + .description = "Test core service", + .descriptionId = 1, + .availableLevel = APL_SYSTEM_BASIC, +}; + +inline PermissionStateFull testSimPermReadContacts = { + .grantFlags = { 2 }, // PERMISSION_USER_SET + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .isGeneral = true, + .permissionName = "ohos.permission.READ_CONTACTS", + .resDeviceID = { "local" }, +}; + +inline HapPolicyParams testStateRegistryPolicyParams = { + .apl = APL_SYSTEM_BASIC, + .domain = "test.domain", + .permList = { testPermGetTelephonyStateDef, testPermSetTelephonyStateDef, testPermGetNetworkInfoDef, + testSimPermWriteContactsDef, testSimPermReadContactsDef }, + .permStateList = { testGetTelephonyState, testSetTelephonyState, testPermGetNetworkInfo, testSimPermWriteContacts, + testSimPermReadContacts }, +}; + +SecurityToken::SecurityToken() +{ + currentID_ = GetSelfTokenID(); + AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testStateRegistryPolicyParams); + accessID_ = tokenIdEx.tokenIdExStruct.tokenID; + SetSelfTokenID(tokenIdEx.tokenIDEx); +} + +SecurityToken::~SecurityToken() +{ + AccessTokenKit::DeleteToken(accessID_); + SetSelfTokenID(currentID_); +} + +} // namespace Telephony +} // namespace OHOS #endif // OHOS_STATE_REGISTRY_BRANCH_TEST_H \ No newline at end of file -- Gitee