1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <gtest/gtest.h> 17#include "display_manager_proxy.h" 18#include "mock_window_adapter.h" 19#include "singleton_mocker.h" 20#include "window_impl.h" 21 22using namespace testing; 23using namespace testing::ext; 24 25namespace OHOS { 26namespace Rosen { 27using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>; 28class WindowEffectTest : public testing::Test { 29public: 30 static void SetUpTestCase(); 31 static void TearDownTestCase(); 32 virtual void SetUp() override; 33 virtual void TearDown() override; 34private: 35 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000; 36}; 37void WindowEffectTest::SetUpTestCase() 38{ 39} 40 41void WindowEffectTest::TearDownTestCase() 42{ 43} 44 45void WindowEffectTest::SetUp() 46{ 47} 48 49void WindowEffectTest::TearDown() 50{ 51 usleep(WAIT_SYNC_IN_NS); 52} 53 54namespace { 55/** 56 * @tc.name: WindowEffect01 57 * @tc.desc: set window corner radius 58 * @tc.type: FUNC 59 * @tc.require: issueI5IUGI 60 */ 61HWTEST_F(WindowEffectTest, WindowEffect01, Function | SmallTest | Level2) 62{ 63 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 64 sptr<WindowOption> option = new WindowOption(); 65 sptr<WindowImpl> window = new WindowImpl(option); 66 ASSERT_NE(nullptr, window); 67 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 68 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 69 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 70 71 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(0.0)); 72 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(16.0)); 73 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1000.0)); 74 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(-1.0)); 75 76 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 77 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 78} 79 80/** 81 * @tc.name: WindowEffect02 82 * @tc.desc: set window shadow radius 83 * @tc.type: FUNC 84 * @tc.require: issueI5IUGI 85 */ 86HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2) 87{ 88 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 89 sptr<WindowOption> option = new WindowOption(); 90 sptr<WindowImpl> window = new WindowImpl(option); 91 ASSERT_NE(nullptr, window); 92 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 93 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 94 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 95 96 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0)); 97 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0)); 98 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0)); 99 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0)); 100 101 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 102 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 103} 104 105/** 106 * @tc.name: WindowEffect03 107 * @tc.desc: set window shadow color 108 * @tc.type: FUNC 109 * @tc.require: issueI5IUGI 110 */ 111HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2) 112{ 113 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 114 sptr<WindowOption> option = new WindowOption(); 115 sptr<WindowImpl> window = new WindowImpl(option); 116 ASSERT_NE(nullptr, window); 117 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 118 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 119 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 120 121 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44")); 122 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44")); 123 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44")); 124 125 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44")); 126 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44")); 127 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44")); 128 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44")); 129 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44")); 130 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422")); 131 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff")); 132 133 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 134 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 135} 136 137/** 138 * @tc.name: WindowEffect04 139 * @tc.desc: set window shadow offset 140 * @tc.type: FUNC 141 * @tc.require: issueI5IUGI 142 */ 143HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2) 144{ 145 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 146 sptr<WindowOption> option = new WindowOption(); 147 sptr<WindowImpl> window = new WindowImpl(option); 148 ASSERT_NE(nullptr, window); 149 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 150 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 151 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 152 153 window->SetShadowOffsetX(0.0); 154 window->SetShadowOffsetX(16.0); 155 window->SetShadowOffsetX(1000.0); 156 window->SetShadowOffsetX(-1.0); 157 158 window->SetShadowOffsetY(0.0); 159 window->SetShadowOffsetY(16.0); 160 window->SetShadowOffsetY(1000.0); 161 window->SetShadowOffsetY(-1.0); 162 163 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 164 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 165} 166 167/** 168 * @tc.name: WindowEffect05 169 * @tc.desc: set window blur radius 170 * @tc.type: FUNC 171 * @tc.require: issueI5IUGI 172 */ 173HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2) 174{ 175 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 176 sptr<WindowOption> option = new WindowOption(); 177 sptr<WindowImpl> window = new WindowImpl(option); 178 ASSERT_NE(nullptr, window); 179 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 180 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 181 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 182 183 ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0)); 184 ASSERT_EQ(WMError::WM_OK, window->SetBlur(16.0)); 185 ASSERT_EQ(WMError::WM_OK, window->SetBlur(1000.0)); 186 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0)); 187 188 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 189 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 190} 191 192/** 193 * @tc.name: WindowEffect06 194 * @tc.desc: set window backdrop blur radius 195 * @tc.type: FUNC 196 * @tc.require: issueI5IUGI 197 */ 198HWTEST_F(WindowEffectTest, WindowEffect06, Function | SmallTest | Level2) 199{ 200 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 201 sptr<WindowOption> option = new WindowOption(); 202 sptr<WindowImpl> window = new WindowImpl(option); 203 ASSERT_NE(nullptr, window); 204 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 205 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 206 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 207 208 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0)); 209 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0)); 210 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0)); 211 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0)); 212 213 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 214 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 215} 216 217/** 218 * @tc.name: WindowEffect07 219 * @tc.desc: set window backdrop blur style 220 * @tc.type: FUNC 221 * @tc.require: issueI5IUGI 222 */ 223HWTEST_F(WindowEffectTest, WindowEffect07, Function | SmallTest | Level2) 224{ 225 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 226 sptr<WindowOption> option = new WindowOption(); 227 sptr<WindowImpl> window = new WindowImpl(option); 228 ASSERT_NE(nullptr, window); 229 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK)); 230 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); 231 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID)); 232 233 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF)); 234 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN)); 235 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR)); 236 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK)); 237 238 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1))); 239 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5))); 240 241 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); 242 ASSERT_EQ(WMError::WM_OK, window->Destroy()); 243} 244} 245} // namespace Rosen 246} // namespace OHOS 247