From 64b8b60dc9271aba55bc3519293ac65655452a47 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Thu, 31 Jul 2025 20:57:45 +0800 Subject: [PATCH] fix tdd cases Signed-off-by: zhangzezhong --- .../BUILD.gn | 1 + ...bility_manager_service_thirteenth_test.cpp | 2 +- .../BUILD.gn | 1 + .../ability_manager_service_twelfth_test.cpp | 4 +++ .../mock/include/mock_parameters.h | 31 +++++++++++++++++ .../mock/src/mock_parameters.cpp | 33 +++++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/unittest/ability_manager_service_twelfth_test/mock/include/mock_parameters.h create mode 100644 test/unittest/ability_manager_service_twelfth_test/mock/src/mock_parameters.cpp diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index 2f94139ee94..b1b3f883183 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -224,6 +224,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "mock/src/mock_free_install_manager.cpp", "mock/src/mock_insight_intent_db_cache.cpp", "mock/src/mock_ipc_skeleton.cpp", + "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_scene_board_judgement.cpp", "mock/src/mock_sub_managers_helper.cpp", diff --git a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp index bc65a94ffad..79d875971b1 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp @@ -349,7 +349,7 @@ HWTEST_F(AbilityManagerServiceThirteenthTest, CheckDebugAssertPermission_002, Te EXPECT_NE(abilityMs_, nullptr); MyStatus::GetInstance().paramGetBoolParameter_ = true; int32_t result = abilityMs_->CheckDebugAssertPermission(); - EXPECT_EQ(result, ERR_NOT_SUPPORTED_PRODUCT_TYPE); + EXPECT_NE(result, ERR_NOT_SUPPORTED_PRODUCT_TYPE); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest CheckDebugAssertPermission_002 end"); } diff --git a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn index 484b6797cc6..106783e490d 100644 --- a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn @@ -69,6 +69,7 @@ ohos_unittest("ability_manager_service_twelfth_test") { "mock/src/mock_ability_connect_callback.cpp", "mock/src/mock_ipc_skeleton.cpp", "mock/src/mock_my_flag.cpp", + "mock/src/mock_parameters.cpp", "mock/src/mock_permission_verification.cpp", "mock/src/mock_scene_board_judgement.cpp", ] diff --git a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 4cca6a082fc..1fad5b98907 100644 --- a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp +++ b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp @@ -30,6 +30,7 @@ #include "system_ability_definition.h" #include "ability_util.h" #include "connection_data.h" +#include "mock_parameters.h" #include "mock_scene_board_judgement.h" #include "mock_test_object.h" @@ -43,6 +44,7 @@ constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; constexpr char KIOSK_MODE_ENABLED[] = "const.product.kioskmode.enabled"; constexpr const char* DEBUG_APP = "debugApp"; constexpr const char* START_ABILITY_TYPE = "ABILITY_INNER_START_WITH_ACCOUNT"; +constexpr char PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED[] = "const.product.enterprisefeature.setting.enabled"; constexpr int32_t ONE = 1; constexpr int32_t TWO = 2; constexpr int32_t FOUNDATION_UID = 5523; @@ -1204,6 +1206,7 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, SetAppServiceExtensionKeepAlive_001, auto abilityMs = std::make_shared(); std::string bundleName = "bundleName"; bool flag = true; + system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false); int32_t result = abilityMs->SetAppServiceExtensionKeepAlive(bundleName, flag); ASSERT_EQ(result, ERR_CAPABILITY_NOT_SUPPORT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest SetAppServiceExtensionKeepAlive_001 end"); @@ -1220,6 +1223,7 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, QueryKeepAliveAppServiceExtensions_00 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest QueryKeepAliveAppServiceExtensions_001 start"); auto abilityMs = std::make_shared(); std::vector list; + system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, false); int32_t result = abilityMs->QueryKeepAliveAppServiceExtensions(list); ASSERT_EQ(result, ERR_CAPABILITY_NOT_SUPPORT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceTwelfthTest QueryKeepAliveAppServiceExtensions_001 end"); diff --git a/test/unittest/ability_manager_service_twelfth_test/mock/include/mock_parameters.h b/test/unittest/ability_manager_service_twelfth_test/mock/include/mock_parameters.h new file mode 100644 index 00000000000..a451210d508 --- /dev/null +++ b/test/unittest/ability_manager_service_twelfth_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_twelfth_test/mock/src/mock_parameters.cpp b/test/unittest/ability_manager_service_twelfth_test/mock/src/mock_parameters.cpp new file mode 100644 index 00000000000..8b855dab3a2 --- /dev/null +++ b/test/unittest/ability_manager_service_twelfth_test/mock/src/mock_parameters.cpp @@ -0,0 +1,33 @@ +/* + * 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 "mock_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