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