From d909e4a355c048fb4cb50afae07497e0cadd1ea5 Mon Sep 17 00:00:00 2001 From: Tintin9529 Date: Wed, 25 Sep 2024 14:41:48 +0800 Subject: [PATCH] add tdd Signed-off-by: Tintin9529 --- .../BUILD.gn | 2 + .../ability_manager_service_fourth_test.cpp | 128 ++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/test/unittest/ability_manager_service_fourth_test/BUILD.gn b/test/unittest/ability_manager_service_fourth_test/BUILD.gn index d067398fdb..4ffb560d14 100644 --- a/test/unittest/ability_manager_service_fourth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourth_test/BUILD.gn @@ -49,6 +49,8 @@ ohos_unittest("ability_manager_service_fourth_test") { "${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/modal_system_dialog/modal_system_dialog_ui_extension.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/modal_system_dialog_util.cpp", "${ability_runtime_services_path}/common/src/ffrt_task_handler_wrap.cpp", "${ability_runtime_services_path}/common/src/queue_task_handler_wrap.cpp", "${ability_runtime_services_path}/common/src/task_handler_wrap.cpp", diff --git a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp index 0d1ffd079f..a957363062 100644 --- a/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp +++ b/test/unittest/ability_manager_service_fourth_test/ability_manager_service_fourth_test.cpp @@ -24,6 +24,8 @@ #include "mock_parameters.h" #include "ability_manager_service.h" #include "insight_intent_execute_manager.h" +#include "modal_system_dialog/modal_system_dialog_ui_extension.h" +#include "utils/modal_system_dialog_util.h" #undef private #undef protected #include "hilog_tag_wrapper.h" @@ -98,6 +100,63 @@ sptr AbilityManagerServiceFourthTest::MockToken(AbilityType abilityType) return abilityRecord->GetToken(); } +class IRemoteObjectMocker : public IRemoteObject { +public: + IRemoteObjectMocker() : IRemoteObject { u"IRemoteObjectMocker" } {} + + ~IRemoteObjectMocker() {} + + int32_t GetObjectRefCount() + { + return 0; + } + + int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + { + int32_t key = data.ReadInt32(); + std::string parameters = Str16ToStr8(data.ReadString16()); + std::string command = Str16ToStr8(data.ReadString16()); + if (command.compare("test") == 0) { + isSuccess_ = true; + return 0; + } + isSuccess_ = false; + return -1; + } + + bool IsProxyObject() const + { + return true; + } + + bool CheckObjectLegality() const + { + return true; + } + + bool AddDeathRecipient(const sptr& recipient) + { + return true; + } + + bool RemoveDeathRecipient(const sptr& recipient) + { + return true; + } + + sptr AsInterface() + { + return nullptr; + } + + int Dump(int fd, const std::vector& args) + { + return 0; + } + +public: + bool isSuccess_ = false; +}; /* * Feature: AbilityManagerService @@ -1423,5 +1482,74 @@ HWTEST_F(AbilityManagerServiceFourthTest, SetAbilityRequestSessionInfo_003, Test TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest SetAbilityRequestSessionInfo_003 end"); } +/* + * Feature: AbilityManagerService + * Function: CheckDebugAppNotInDeveloperMode + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUtil CheckDebugAppNotInDeveloperMode + */ +HWTEST_F(AbilityManagerServiceFourthTest, CheckDebugAppNotInDeveloperMode_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckDebugAppNotInDeveloperMode start"); + bool srcDeveloperMode = OHOS::system::GetBoolParameter(DEVELOPER_MODE_STATE, false); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, false); + ApplicationInfo applicationInfo; + applicationInfo.appProvisionType = "release"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + applicationInfo.appProvisionType = "debug"; + EXPECT_TRUE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, true); + applicationInfo.appProvisionType = "release"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + applicationInfo.appProvisionType = "debug"; + EXPECT_FALSE(ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo)); + + OHOS::system::SetBoolParameter(DEVELOPER_MODE_STATE, srcDeveloperMode); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest CheckDebugAppNotInDeveloperMode end"); +} + +/* + * Feature: AbilityManagerService + * Function: CreateModalUIExtension + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUIExtension CreateModalUIExtension + */ +HWTEST_F(AbilityManagerServiceFourthTest, ModalSystemDialogUIExtension_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ModalSystemDialogUIExtension_001 start"); + auto modalSystemDialog = std::make_shared(); + ASSERT_NE(modalSystemDialog, nullptr); + std::string commandStr = "test"; + auto result = modalSystemDialog->CreateModalUIExtension(commandStr); + EXPECT_FALSE(result); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest ModalSystemDialogUIExtension_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: OnAbilityConnectDone + * SubFunction: NA + * FunctionPoints: ModalSystemDialogUIExtension OnAbilityConnectDone + */ +HWTEST_F(AbilityManagerServiceFourthTest, OnAbilityConnectDone_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAbilityConnectDone_001 start"); + sptr dialogConnection( + new (std::nothrow) ModalSystemDialogUIExtension::DialogConnection("test")); + ASSERT_NE(dialogConnection, nullptr); + ElementName element("", "", "ability", ""); + dialogConnection->OnAbilityConnectDone(element, nullptr, 0); + sptr iRemoteObject = new IRemoteObjectMocker(); + dialogConnection->OnAbilityConnectDone(element, iRemoteObject, 0); + EXPECT_TRUE(iRemoteObject->isSuccess_); + dialogConnection->commandStr_ = ""; + dialogConnection->OnAbilityConnectDone(element, iRemoteObject, 0); + EXPECT_FALSE(iRemoteObject->isSuccess_); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFourthTest OnAbilityConnectDone_001 end"); +} } // namespace AAFwk } // namespace OHOS