diff --git a/test/unittest/ability_manager_service_mock_test/BUILD.gn b/test/unittest/ability_manager_service_mock_test/BUILD.gn index 2d4c140cd04e8b022d9dad07d4167e753373354a..892baca2dce6c3a72c663edb718b1a530b8c144b 100644 --- a/test/unittest/ability_manager_service_mock_test/BUILD.gn +++ b/test/unittest/ability_manager_service_mock_test/BUILD.gn @@ -42,21 +42,22 @@ ohos_unittest("ability_manager_service_mock_test") { sources = [ "${ability_runtime_abilitymgr_path}/src/ability_auto_startup_service.cpp", "${ability_runtime_abilitymgr_path}/src/ability_bundle_event_callback.cpp", - "${ability_runtime_abilitymgr_path}/src/utils/hmsf_utils.cpp", - "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_rdb_data_mgr.cpp", - "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", - "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_db_cache.cpp", - "${ability_runtime_abilitymgr_path}/src/insight_intent/extract_insight_intent_profile.cpp", - "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_abilitymgr_path}/src/ability_connect_callback_stub.cpp", "${ability_runtime_abilitymgr_path}/src/ability_manager_client.cpp", "${ability_runtime_abilitymgr_path}/src/assert_fault_proxy.cpp", "${ability_runtime_abilitymgr_path}/src/auto_startup_info.cpp", + "${ability_runtime_abilitymgr_path}/src/dialog_session/dialog_session_manager.cpp", "${ability_runtime_abilitymgr_path}/src/exit_reason.cpp", + "${ability_runtime_abilitymgr_path}/src/insight_intent/extract_insight_intent_profile.cpp", + "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_execute_param.cpp", + "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_rdb_data_mgr.cpp", + "${ability_runtime_abilitymgr_path}/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_abilitymgr_path}/src/modal_system_dialog/modal_system_dialog_ui_extension.cpp", "${ability_runtime_abilitymgr_path}/src/utils/ability_event_util.cpp", "${ability_runtime_abilitymgr_path}/src/utils/dms_util.cpp", + "${ability_runtime_abilitymgr_path}/src/utils/hmsf_utils.cpp", "${ability_runtime_abilitymgr_path}/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", diff --git a/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp b/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp index 5fcd996f9eedc4d3b2f13573e56c51d86bca9a40..4c878edb6634be8684de0b0525474fa612048fc4 100644 --- a/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp +++ b/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp @@ -17,11 +17,13 @@ #define private public #define protected public #include "ability_manager_service.h" +#include "dialog_session_manager.h" #include "session_info.h" #include "sub_managers_helper.h" #undef private #undef protected #include "ability_manager_errors.h" +#include "ability_util.h" #include "start_ability_utils.h" using namespace testing; @@ -326,5 +328,88 @@ HWTEST_F(AbilityManagerServiceMockTest, StartUIExtensionAbility_0200, TestSize.L auto ret = abilityMs->StartUIExtensionAbility(sessionInfo, 1); EXPECT_EQ(ret, ERR_INVALID_VALUE); } + +/** + * @tc.name: GetWantElement_001 + * @tc.desc: test GetWantElement function + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerServiceMockTest, GetWantElement_001, TestSize.Level1) +{ + DialogSessionManager dialogSessionManager; + Want want; + AppExecFwk::ElementName element("", "com.test.demo", "MainAbility"); + want.SetElement(element); + AppExecFwk::ElementName result = dialogSessionManager.GetWantElement(want); + EXPECT_EQ(result.GetAbilityName(), "MainAbility"); + auto bms = AbilityUtil::GetBundleManagerHelper(); + bms->isOpenAtomicService_ = true; + result = dialogSessionManager.GetWantElement(want); + EXPECT_TRUE(result.GetAbilityName().empty()); + bms->isOpenAtomicService_ = false; +} + +/** + * @tc.name: OnStart_001 + * @tc.desc: test OnStart function + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerServiceMockTest, OnStart_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest OnStart_001 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + abilityMs->state_ = ServiceRunningState::STATE_NOT_START; + abilityMs->OnStart(); + EXPECT_EQ(abilityMs->state_, ServiceRunningState::STATE_RUNNING); + abilityMs->instance_ = nullptr; + abilityMs->OnStart(); + EXPECT_EQ(abilityMs->instance_, nullptr); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest OnStart_001 end"); +} + +/** + * @tc.name: StartAbilityWithSpecifyTokenId_001 + * @tc.desc: test StartAbilityWithSpecifyTokenId function + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerServiceMockTest, StartAbilityWithSpecifyTokenId_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest StartAbilityWithSpecifyTokenId_001 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + Want want; + uint32_t specifyTokenId = 0; + int32_t userId = 0; + int requestCode = 0; + auto ret = abilityMs->StartAbilityWithSpecifyTokenId(want, nullptr, specifyTokenId, userId, requestCode); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest StartAbilityWithSpecifyTokenId_001 end"); +} + +/** + * @tc.name: StartAbilityWithSpecifyTokenIdInner_001 + * @tc.desc: test StartAbilityWithSpecifyTokenIdInner function + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerServiceMockTest, StartAbilityWithSpecifyTokenIdInner_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest StartAbilityWithSpecifyTokenIdInner_001 start"); + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + Want want; + uint32_t specifyTokenId = 0; + int32_t userId = 0; + int requestCode = 0; + bool isPendingWantCaller = false; + auto ret = abilityMs->StartAbilityWithSpecifyTokenIdInner(want, nullptr, specifyTokenId, + isPendingWantCaller, userId, requestCode); + EXPECT_EQ(ret, ERR_NULL_INTERCEPTOR_EXECUTER); + want.SetFlags(Want::FLAG_ABILITY_CONTINUATION); + ret = abilityMs->StartAbilityWithSpecifyTokenIdInner(want, nullptr, specifyTokenId, + isPendingWantCaller, userId, requestCode); + EXPECT_EQ(ret, ERR_INVALID_CONTINUATION_FLAG); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest StartAbilityWithSpecifyTokenIdInner_001 end"); +} } } diff --git a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h index 8e7a3c0371315f1887fdf2e772d23d0e52ef27a7..a7ca6a9250dcef7036e5d186b4f39fdc024b9631 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h +++ b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h @@ -45,6 +45,8 @@ public: ErrCode GetNameForUid(const int32_t uid, std::string &name); bool QueryAppGalleryBundleName(std::string &bundleName); + bool isOpenAtomicService_ = false; + private: DECLARE_DELAYED_SINGLETON(BundleMgrHelper) bool bmsReady_ = true; diff --git a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp index c579fc0be6498a585a9da546c0e5e0e92fc51eff..4408639722357532ba66a04bc3c13605f9301bc0 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp @@ -103,6 +103,9 @@ bool BundleMgrHelper::GetBundleInfo( bool BundleMgrHelper::GetBundleInfo( const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId) { + if (isOpenAtomicService_) { + bundleInfo.applicationInfo.bundleType = AppExecFwk::BundleType::ATOMIC_SERVICE; + } return true; }