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