diff --git a/test/unittest/ability_manager_service_sixth_test/BUILD.gn b/test/unittest/ability_manager_service_sixth_test/BUILD.gn index bb8166d642be2c07c3674f63e50794016e9ea3fd..6f326eeea24ecb2fb8daab7ba1fc582fdf8d84bc 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 d506e1db9148538d64ff2d5a2b0746d552bfe043..d9689a4e0ec1e13203396270b423d888b2a94cc2 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 0000000000000000000000000000000000000000..a451210d5083424081e2de205ecaec198362b33a --- /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 0000000000000000000000000000000000000000..f44e89ea5ad5680bb554e2fe878135bb45c9eaa4 --- /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