From 18c71cb891197f509eed8d72fe4869671789c7e5 Mon Sep 17 00:00:00 2001 From: chenliming Date: Fri, 1 Aug 2025 09:53:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3ability=5Fmanager=5Fservice?= =?UTF-8?q?=5Fsixth=5Ftest=E6=B5=8B=E8=AF=95=E5=A5=97=E4=B8=8D=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenliming --- .../BUILD.gn | 1 + .../ability_manager_service_sixth_test.cpp | 5 +++ .../mock/include/mock_parameters.h | 31 +++++++++++++++++ .../mock/src/mock_parameters.cpp | 34 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 test/unittest/ability_manager_service_sixth_test/mock/include/mock_parameters.h create mode 100644 test/unittest/ability_manager_service_sixth_test/mock/src/mock_parameters.cpp diff --git a/test/unittest/ability_manager_service_sixth_test/BUILD.gn b/test/unittest/ability_manager_service_sixth_test/BUILD.gn index bb8166d642b..6f326eeea24 100644 --- a/test/unittest/ability_manager_service_sixth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_sixth_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("ability_manager_service_sixth_test") { "${ability_runtime_test_path}/mock/task_handler_wrap_mock/src/mock_task_handler_wrap.cpp", "ability_manager_service_sixth_test.cpp", "mock/src/mock_my_flag.cpp", + "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", ] diff --git a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp index d506e1db914..d9689a4e0ec 100644 --- a/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp +++ b/test/unittest/ability_manager_service_sixth_test/ability_manager_service_sixth_test.cpp @@ -35,6 +35,7 @@ #include "mock_ability_token.h" #include "mock_bundle_manager_proxy.h" #include "mock_my_flag.h" +#include "mock_parameters.h" #include "mock_permission_verification.h" #include "mock_task_handler_wrap.h" #include "process_options.h" @@ -283,6 +284,7 @@ HWTEST_F(AbilityManagerServiceSixthTest, StartAbilityDetails_001, TestSize.Level * @tc.steps: step1. DEBUG app which is not exists * @tc.expected: step1. expect RESOLVE_ABILITY_ERR */ + system::SetBoolParameter("", true); auto ret = abilityMs->StartAbilityDetails(want, abilityStartSetting_, nullptr, -1, -1, false); EXPECT_EQ(ret, RESOLVE_ABILITY_ERR); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest StartAbilityDetails_001 end"); @@ -561,6 +563,7 @@ HWTEST_F(AbilityManagerServiceSixthTest, CheckOptExtensionAbility_001, TestSize. isStartAsCaller = false; extensionType = ExtensionAbilityType::FORM; abilityRequest.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::FORM; + system::SetBoolParameter("", true); ret = abilityMs_->CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType, isImplicit, isStartAsCaller); EXPECT_EQ(ret, ERR_OK); @@ -579,6 +582,7 @@ HWTEST_F(AbilityManagerServiceSixthTest, StartExtensionAbility_001, TestSize.Lev auto abilityMs = MockAbilityManagerService(); Want want; AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UI_SERVICE; + system::SetBoolParameter("", false); auto ret = abilityMs->StartExtensionAbility(want, nullptr, -1, extensionType); EXPECT_EQ(ret, ERR_CAPABILITY_NOT_SUPPORT); @@ -1574,6 +1578,7 @@ HWTEST_F(AbilityManagerServiceSixthTest, CheckPermissionForUIService_001, TestSi ret = abilityMs->CheckPermissionForUIService(extensionType, want, abilityRequest); EXPECT_EQ(ret, ERR_WRONG_INTERFACE_CALL); extensionType = ExtensionAbilityType::UI_SERVICE; + system::SetBoolParameter("", false); ret = abilityMs->CheckPermissionForUIService(extensionType, want, abilityRequest); EXPECT_EQ(ret, ERR_CAPABILITY_NOT_SUPPORT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest CheckPermissionForUIService_001 end"); diff --git a/test/unittest/ability_manager_service_sixth_test/mock/include/mock_parameters.h b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_parameters.h new file mode 100644 index 00000000000..a451210d508 --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/include/mock_parameters.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 MOCK_PARAMETERS_H +#define MOCK_PARAMETERS_H + +#include + +namespace OHOS { +namespace system { + +void SetBoolParameter(const std::string& key, bool def); + +bool GetBoolParameter(const std::string& key, bool def); + +} // namespace system +} // namespace OHOS + +#endif // MOCK_PARAMETERS_H diff --git a/test/unittest/ability_manager_service_sixth_test/mock/src/mock_parameters.cpp b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_parameters.cpp new file mode 100644 index 00000000000..f44e89ea5ad --- /dev/null +++ b/test/unittest/ability_manager_service_sixth_test/mock/src/mock_parameters.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "parameters.h" + +namespace OHOS { +namespace system { + +bool g_returnFlag{false}; + +void SetBoolParameter(const std::string& key, bool def) +{ + g_returnFlag = def; +} + +bool GetBoolParameter(const std::string& key, bool def) +{ + return g_returnFlag; +} + +} // namespace system +} // namespace OHOS \ No newline at end of file -- Gitee