From 6c87a14570a76bb030dd25467d6d98a1fe5eb8fc Mon Sep 17 00:00:00 2001 From: shuangshuangliu Date: Mon, 25 Aug 2025 14:41:15 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shuangshuangliu Change-Id: I5695e9433e1286ac7d546784f4a546c1335bde54 --- wm/test/unittest/BUILD.gn | 11 + wm/test/unittest/window_effect_new_test.cpp | 241 ++++++++++++++++++++ 2 files changed, 252 insertions(+) create mode 100644 wm/test/unittest/window_effect_new_test.cpp diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 6a9fca35b8..89d5425e32 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -37,6 +37,7 @@ group("unittest") { ":wm_web_picture_in_picture_controller_test", ":wm_window_agent_test", ":wm_window_display_change_adapter_test", + ":wm_window_effect_new_test", ":wm_window_effect_test", ":wm_window_impl_listener_test", ":wm_window_impl_test", @@ -306,6 +307,16 @@ ohos_unittest("wm_window_effect_test") { external_deps = test_external_deps } +ohos_unittest("wm_window_effect_new_test") { + module_out_path = module_out_path + + sources = [ "window_effect_new_test.cpp" ] + + deps = [ ":wm_unittest_common" ] + + external_deps = test_external_deps +} + ohos_unittest("wm_gtx_input_event_sender_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/window_effect_new_test.cpp b/wm/test/unittest/window_effect_new_test.cpp new file mode 100644 index 0000000000..8e89157278 --- /dev/null +++ b/wm/test/unittest/window_effect_new_test.cpp @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2021-2022 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 +#include "display_manager_proxy.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" +#include "window_impl.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +class WindowEffectNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + +private: + static constexpr uint32_t WAIT_SYNC_IN_NS = 500000; +}; +void WindowEffectNewTest::SetUpTestCase() {} + +void WindowEffectNewTest::TearDownTestCase() {} + +void WindowEffectNewTest::SetUp() {} + +void WindowEffectNewTest::TearDown() +{ + usleep(WAIT_SYNC_IN_NS); +} + +namespace { +/** + * @tc.name: WindowEffect01 + * @tc.desc: set window corner radius + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect01, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetCornerRadius(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetCornerRadius(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetCornerRadius(1000.0)); + EXPECT_EQ(WMError::WM_OK, window->SetCornerRadius(-1.0)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect02 + * @tc.desc: set window shadow radius + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect02, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0)); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect03 + * @tc.desc: set window shadow color + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect03, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44")); + EXPECT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44")); + EXPECT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44")); + + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422")); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect04 + * @tc.desc: set window shadow offset + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect04, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetX(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetX(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetX(1000.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetX(-1.0)); + + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetY(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetY(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetY(1000.0)); + EXPECT_EQ(WMError::WM_OK, window->SetShadowOffsetY(-1.0)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect05 + * @tc.desc: set window blur radius + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect05, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetBlur(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetBlur(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetBlur(1000.0)); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect06 + * @tc.desc: set window backdrop blur radius + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect06, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0)); + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0)); + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0)); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0)); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: WindowEffect07 + * @tc.desc: set window backdrop blur style + * @tc.type: FUNC + * @tc.require: issueI5IUGI + */ +HWTEST_F(WindowEffectNewTest, WindowEffect07, TestSize.Level1) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + sptr window = new WindowImpl(option); + ASSERT_NE(nullptr, window); + EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); + + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF)); + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN)); + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR)); + EXPECT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK)); + + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast(-1))); + EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast(5))); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_EQ(WMError::WM_OK, window->Destroy()); +} +} // namespace +} // namespace Rosen +} // namespace OHOS -- Gitee