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
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
28 class WindowEffectTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 virtual void SetUp() override;
33 virtual void TearDown() override;
34 };
SetUpTestCase()35 void WindowEffectTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void WindowEffectTest::TearDownTestCase()
40 {
41 }
42
SetUp()43 void WindowEffectTest::SetUp()
44 {
45 }
46
TearDown()47 void WindowEffectTest::TearDown()
48 {
49 }
50
51 namespace {
52 /**
53 * @tc.name: WindowEffect01
54 * @tc.desc: set window corner radius
55 * @tc.type: FUNC
56 * @tc.require: issueI5IUGI
57 */
58 HWTEST_F(WindowEffectTest, WindowEffect01, Function | SmallTest | Level2)
59 {
60 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
61 sptr<WindowOption> option = new WindowOption();
62 sptr<WindowImpl> window = new WindowImpl(option);
63 ASSERT_NE(nullptr, window);
64 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
65 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
66 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
67
68 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(0.0));
69 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(16.0));
70 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(1000.0));
71 ASSERT_EQ(WMError::WM_OK, window->SetCornerRadius(-1.0));
72
73 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
74 ASSERT_EQ(WMError::WM_OK, window->Destroy());
75 }
76
77 /**
78 * @tc.name: WindowEffect02
79 * @tc.desc: set window shadow radius
80 * @tc.type: FUNC
81 * @tc.require: issueI5IUGI
82 */
83 HWTEST_F(WindowEffectTest, WindowEffect02, Function | SmallTest | Level2)
84 {
85 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
86 sptr<WindowOption> option = new WindowOption();
87 sptr<WindowImpl> window = new WindowImpl(option);
88 ASSERT_NE(nullptr, window);
89 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
90 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
91 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
92
93 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0));
94 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0));
95 ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0));
96 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
97
98 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
99 ASSERT_EQ(WMError::WM_OK, window->Destroy());
100 }
101
102 /**
103 * @tc.name: WindowEffect03
104 * @tc.desc: set window shadow color
105 * @tc.type: FUNC
106 * @tc.require: issueI5IUGI
107 */
108 HWTEST_F(WindowEffectTest, WindowEffect03, Function | SmallTest | Level2)
109 {
110 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
111 sptr<WindowOption> option = new WindowOption();
112 sptr<WindowImpl> window = new WindowImpl(option);
113 ASSERT_NE(nullptr, window);
114 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
115 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
116 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
117
118 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44"));
119 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44"));
120 ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
121
122 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44"));
123 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44"));
124 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44"));
125 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44"));
126 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44"));
127 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422"));
128 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff"));
129
130 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
131 ASSERT_EQ(WMError::WM_OK, window->Destroy());
132 }
133
134 /**
135 * @tc.name: WindowEffect04
136 * @tc.desc: set window shadow offset
137 * @tc.type: FUNC
138 * @tc.require: issueI5IUGI
139 */
140 HWTEST_F(WindowEffectTest, WindowEffect04, Function | SmallTest | Level2)
141 {
142 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
143 sptr<WindowOption> option = new WindowOption();
144 sptr<WindowImpl> window = new WindowImpl(option);
145 ASSERT_NE(nullptr, window);
146 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
147 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
148 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
149
150 window->SetShadowOffsetX(0.0);
151 window->SetShadowOffsetX(16.0);
152 window->SetShadowOffsetX(1000.0);
153 window->SetShadowOffsetX(-1.0);
154
155 window->SetShadowOffsetY(0.0);
156 window->SetShadowOffsetY(16.0);
157 window->SetShadowOffsetY(1000.0);
158 window->SetShadowOffsetY(-1.0);
159
160 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
161 ASSERT_EQ(WMError::WM_OK, window->Destroy());
162 }
163
164 /**
165 * @tc.name: WindowEffect05
166 * @tc.desc: set window blur radius
167 * @tc.type: FUNC
168 * @tc.require: issueI5IUGI
169 */
170 HWTEST_F(WindowEffectTest, WindowEffect05, Function | SmallTest | Level2)
171 {
172 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
173 sptr<WindowOption> option = new WindowOption();
174 sptr<WindowImpl> window = new WindowImpl(option);
175 ASSERT_NE(nullptr, window);
176 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
177 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
178 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
179
180 ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0));
181 ASSERT_EQ(WMError::WM_OK, window->SetBlur(16.0));
182 ASSERT_EQ(WMError::WM_OK, window->SetBlur(1000.0));
183 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
184
185 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
186 ASSERT_EQ(WMError::WM_OK, window->Destroy());
187 }
188
189 /**
190 * @tc.name: WindowEffect06
191 * @tc.desc: set window backdrop blur radius
192 * @tc.type: FUNC
193 * @tc.require: issueI5IUGI
194 */
195 HWTEST_F(WindowEffectTest, WindowEffect06, Function | SmallTest | Level2)
196 {
197 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
198 sptr<WindowOption> option = new WindowOption();
199 sptr<WindowImpl> window = new WindowImpl(option);
200 ASSERT_NE(nullptr, window);
201 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
202 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
203 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
204
205 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0));
206 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0));
207 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0));
208 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
209
210 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
211 ASSERT_EQ(WMError::WM_OK, window->Destroy());
212 }
213
214 /**
215 * @tc.name: WindowEffect07
216 * @tc.desc: set window backdrop blur style
217 * @tc.type: FUNC
218 * @tc.require: issueI5IUGI
219 */
220 HWTEST_F(WindowEffectTest, WindowEffect07, Function | SmallTest | Level2)
221 {
222 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
223 sptr<WindowOption> option = new WindowOption();
224 sptr<WindowImpl> window = new WindowImpl(option);
225 ASSERT_NE(nullptr, window);
226 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
227 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
228 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
229
230 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
231 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN));
232 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR));
233 ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK));
234
235 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1)));
236 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5)));
237
238 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
239 ASSERT_EQ(WMError::WM_OK, window->Destroy());
240 }
241 }
242 } // namespace Rosen
243 } // namespace OHOS
244