• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19 #include "wm_common.h"
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 class WindowEffectTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     virtual void SetUp() override;
31     virtual void TearDown() override;
32     Utils::TestWindowInfo windowInfo_;
33 };
34 
SetUpTestCase()35 void WindowEffectTest::SetUpTestCase()
36 {
37 }
38 
TearDownTestCase()39 void WindowEffectTest::TearDownTestCase()
40 {
41 }
42 
SetUp()43 void WindowEffectTest::SetUp()
44 {
45     windowInfo_ = {
46             .name = "TestWindow",
47             .rect = {0, 0, 100, 200},
48             .type = WindowType::WINDOW_TYPE_FLOAT,
49             .mode = WindowMode::WINDOW_MODE_FLOATING,
50             .needAvoid = false,
51             .parentLimit = false,
52             .parentId = INVALID_WINDOW_ID,
53     };
54 }
55 
TearDown()56 void WindowEffectTest::TearDown()
57 {
58 }
59 
60 namespace {
61 /**
62  * @tc.name: WindowEffect01
63  * @tc.desc: Set window corner radius
64  * @tc.type: FUNC
65  */
66 HWTEST_F(WindowEffectTest, WindowEffect01, Function | MediumTest | Level3)
67 {
68     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
69     ASSERT_NE(nullptr, window);
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_ERROR_INVALID_PARAM, window->SetCornerRadius(-1.0));
75 
76     ASSERT_EQ(WMError::WM_OK, window->Destroy());
77 }
78 
79 /**
80  * @tc.name: WindowEffect02
81  * @tc.desc: Set window shadow radius
82  * @tc.type: FUNC
83  */
84 HWTEST_F(WindowEffectTest, WindowEffect02, Function | MediumTest | Level3)
85 {
86     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
87     ASSERT_NE(nullptr, window);
88 
89     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(0.0));
90     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(16.0));
91     ASSERT_EQ(WMError::WM_OK, window->SetShadowRadius(1000.0));
92     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowRadius(-1.0));
93 
94     ASSERT_EQ(WMError::WM_OK, window->Destroy());
95 }
96 
97 /**
98  * @tc.name: WindowEffect03
99  * @tc.desc: Set window shadow color
100  * @tc.type: FUNC
101  */
102 HWTEST_F(WindowEffectTest, WindowEffect03, Function | MediumTest | Level3)
103 {
104     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
105     ASSERT_NE(nullptr, window);
106 
107     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#FF22EE44"));
108     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#22EE44"));
109     ASSERT_EQ(WMError::WM_OK, window->SetShadowColor("#ff22ee44"));
110 
111     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("ff22ee44"));
112     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("22ee44"));
113     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ppEE44"));
114     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#eepp44"));
115     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ffeePP44"));
116     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff22ee4422"));
117     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetShadowColor("#ff"));
118 
119     ASSERT_EQ(WMError::WM_OK, window->Destroy());
120 }
121 
122 /**
123  * @tc.name: WindowEffect04
124  * @tc.desc: Set window shadow offset
125  * @tc.type: FUNC
126  */
127 HWTEST_F(WindowEffectTest, WindowEffect04, Function | MediumTest | Level3)
128 {
129     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
130     ASSERT_NE(nullptr, window);
131 
132     window->SetShadowOffsetX(0.0);
133     window->SetShadowOffsetX(16.0);
134     window->SetShadowOffsetX(1000.0);
135     window->SetShadowOffsetX(-1.0);
136 
137     window->SetShadowOffsetY(0.0);
138     window->SetShadowOffsetY(16.0);
139     window->SetShadowOffsetY(1000.0);
140     window->SetShadowOffsetY(-1.0);
141 
142     ASSERT_EQ(WMError::WM_OK, window->Destroy());
143 }
144 
145 /**
146  * @tc.name: WindowEffect05
147  * @tc.desc: Set window blur radius
148  * @tc.type: FUNC
149  */
150 HWTEST_F(WindowEffectTest, WindowEffect05, Function | MediumTest | Level3)
151 {
152     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
153     ASSERT_NE(nullptr, window);
154 
155     ASSERT_EQ(WMError::WM_OK, window->SetBlur(0.0));
156     ASSERT_EQ(WMError::WM_OK, window->SetBlur(16.0));
157     ASSERT_EQ(WMError::WM_OK, window->SetBlur(1000.0));
158     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBlur(-1.0));
159 
160     ASSERT_EQ(WMError::WM_OK, window->Destroy());
161 }
162 
163 /**
164  * @tc.name: WindowEffect06
165  * @tc.desc: Set window backdrop blur radius
166  * @tc.type: FUNC
167  */
168 HWTEST_F(WindowEffectTest, WindowEffect06, Function | MediumTest | Level3)
169 {
170     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
171     ASSERT_NE(nullptr, window);
172 
173     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(0.0));
174     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(16.0));
175     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlur(1000.0));
176     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlur(-1.0));
177 
178     ASSERT_EQ(WMError::WM_OK, window->Destroy());
179 }
180 
181 /**
182  * @tc.name: WindowEffect07
183  * @tc.desc: Set window backdrop blur style
184  * @tc.type: FUNC
185  */
186 HWTEST_F(WindowEffectTest, WindowEffect07, Function | MediumTest | Level3)
187 {
188     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
189     ASSERT_NE(nullptr, window);
190 
191     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_OFF));
192     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THIN));
193     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_REGULAR));
194     ASSERT_EQ(WMError::WM_OK, window->SetBackdropBlurStyle(WindowBlurStyle::WINDOW_BLUR_THICK));
195 
196     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(-1)));
197     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetBackdropBlurStyle(static_cast<WindowBlurStyle>(5)));
198 
199     ASSERT_EQ(WMError::WM_OK, window->Destroy());
200 }
201 } // namespace
202 } // namespace Rosen
203 } // namespace OHOS
204