1 /*
2 * Copyright (C) 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 <memory>
18 #include "accessibility_window_info.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Accessibility {
25 constexpr int32_t INNER_WINDOW_ID = 2;
26 constexpr int64_t UI_NODE_ID = 2;
27
28 class AccessibilityWindowInfoUnitTest : public ::testing::Test {
29 public:
AccessibilityWindowInfoUnitTest()30 AccessibilityWindowInfoUnitTest()
31 {}
~AccessibilityWindowInfoUnitTest()32 ~AccessibilityWindowInfoUnitTest()
33 {}
SetUpTestCase()34 static void SetUpTestCase()
35 {
36 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest Start";
37 }
TearDownTestCase()38 static void TearDownTestCase()
39 {
40 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest End";
41 }
SetUp()42 void SetUp()
43 {
44 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest SetUp() Start";
45 windowInfo_ = std::make_shared<AccessibilityWindowInfo>();
46 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest SetUp() End";
47 };
TearDown()48 void TearDown()
49 {
50 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest TearDown()";
51 windowInfo_ = nullptr;
52 }
53
54 std::shared_ptr<AccessibilityWindowInfo> windowInfo_ = nullptr;
55 };
56
57 /**
58 * @tc.number: SetAccessibilityWindowType_001
59 * @tc.name: SetAccessibilityWindowType
60 * @tc.desc: Test function SetAccessibilityWindowType
61 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityWindowType_001, TestSize.Level1)62 HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityWindowType_001, TestSize.Level1)
63 {
64 GTEST_LOG_(INFO) << "SetAccessibilityWindowType_001 start";
65 if (!windowInfo_) {
66 GTEST_LOG_(INFO) << "windowInfo_ is null";
67 return;
68 }
69 windowInfo_->SetAccessibilityWindowType(AccessibilityWindowType::TYPE_APPLICATION);
70 EXPECT_EQ(windowInfo_->GetAccessibilityWindowType(), AccessibilityWindowType::TYPE_APPLICATION);
71 GTEST_LOG_(INFO) << "SetAccessibilityWindowType_001 end";
72 }
73
74 /**
75 * @tc.number: SetWindowLayer_001
76 * @tc.name: SetWindowLayer
77 * @tc.desc: Test function SetWindowLayer
78 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowLayer_001, TestSize.Level1)79 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowLayer_001, TestSize.Level1)
80 {
81 GTEST_LOG_(INFO) << "SetWindowLayer_001 start";
82 if (!windowInfo_) {
83 GTEST_LOG_(INFO) << "windowInfo_ is null";
84 return;
85 }
86 windowInfo_->SetWindowLayer(1);
87 EXPECT_EQ(windowInfo_->GetWindowLayer(), 1);
88 GTEST_LOG_(INFO) << "SetWindowLayer_001 end";
89 }
90
91 /**
92 * @tc.number: SetWindowId_001
93 * @tc.name: SetWindowId
94 * @tc.desc: Test function SetWindowId
95 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowId_001, TestSize.Level1)96 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowId_001, TestSize.Level1)
97 {
98 GTEST_LOG_(INFO) << "SetWindowId_001 start";
99 if (!windowInfo_) {
100 GTEST_LOG_(INFO) << "windowInfo_ is null";
101 return;
102 }
103 windowInfo_->SetWindowId(1);
104 EXPECT_EQ(windowInfo_->GetWindowId(), 1);
105 GTEST_LOG_(INFO) << "SetWindowId_001 end";
106 }
107
108 /**
109 * @tc.number: SetRectInScreen_001
110 * @tc.name: SetRectInScreen
111 * @tc.desc: Test function SetRectInScreen
112 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetRectInScreen_001, TestSize.Level1)113 HWTEST_F(AccessibilityWindowInfoUnitTest, SetRectInScreen_001, TestSize.Level1)
114 {
115 GTEST_LOG_(INFO) << "SetRectInScreen_001 start";
116 if (!windowInfo_) {
117 GTEST_LOG_(INFO) << "windowInfo_ is null";
118 return;
119 }
120 Rect boundParam(1, 1, 2, 2);
121 windowInfo_->SetRectInScreen(boundParam);
122 Rect boundRet = windowInfo_->GetRectInScreen();
123 EXPECT_EQ(boundRet.GetLeftTopXScreenPostion(), 1);
124 EXPECT_EQ(boundRet.GetLeftTopYScreenPostion(), 1);
125 EXPECT_EQ(boundRet.GetRightBottomXScreenPostion(), 2);
126 EXPECT_EQ(boundRet.GetRightBottomYScreenPostion(), 2);
127 GTEST_LOG_(INFO) << "SetRectInScreen_001 end";
128 }
129
130 /**
131 * @tc.number: SetActive_001
132 * @tc.name: SetActive
133 * @tc.desc: Test function SetActive
134 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetActive_001, TestSize.Level1)135 HWTEST_F(AccessibilityWindowInfoUnitTest, SetActive_001, TestSize.Level1)
136 {
137 GTEST_LOG_(INFO) << "SetActive_001 start";
138 if (!windowInfo_) {
139 GTEST_LOG_(INFO) << "windowInfo_ is null";
140 return;
141 }
142 windowInfo_->SetActive(true);
143 EXPECT_TRUE(windowInfo_->IsActive());
144 GTEST_LOG_(INFO) << "SetActive_001 end";
145 }
146
147 /**
148 * @tc.number: SetFocused_001
149 * @tc.name: SetFocused
150 * @tc.desc: Test function SetFocused
151 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetFocused_001, TestSize.Level1)152 HWTEST_F(AccessibilityWindowInfoUnitTest, SetFocused_001, TestSize.Level1)
153 {
154 GTEST_LOG_(INFO) << "SetFocused_001 start";
155 if (!windowInfo_) {
156 GTEST_LOG_(INFO) << "windowInfo_ is null";
157 return;
158 }
159 windowInfo_->SetFocused(true);
160 EXPECT_TRUE(windowInfo_->IsFocused());
161 GTEST_LOG_(INFO) << "SetFocused_001 end";
162 }
163
164 /**
165 * @tc.number: SetAccessibilityFocused_001
166 * @tc.name: SetAccessibilityFocused
167 * @tc.desc: Test function SetAccessibilityFocused
168 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityFocused_001, TestSize.Level1)169 HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityFocused_001, TestSize.Level1)
170 {
171 GTEST_LOG_(INFO) << "SetAccessibilityFocused_001 start";
172 if (!windowInfo_) {
173 GTEST_LOG_(INFO) << "windowInfo_ is null";
174 return;
175 }
176 windowInfo_->SetAccessibilityFocused(true);
177 EXPECT_TRUE(windowInfo_->IsAccessibilityFocused());
178 GTEST_LOG_(INFO) << "SetAccessibilityFocused_001 end";
179 }
180
181 /**
182 * @tc.number: SetDisplayId_001
183 * @tc.name: SetDisplayId
184 * @tc.desc: Test function SetDisplayId
185 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetDisplayId_001, TestSize.Level1)186 HWTEST_F(AccessibilityWindowInfoUnitTest, SetDisplayId_001, TestSize.Level1)
187 {
188 GTEST_LOG_(INFO) << "SetDisplayId_001 start";
189 if (!windowInfo_) {
190 GTEST_LOG_(INFO) << "windowInfo_ is null";
191 return;
192 }
193 windowInfo_->SetDisplayId(100);
194 EXPECT_EQ(windowInfo_->GetDisplayId(), 100);
195 GTEST_LOG_(INFO) << "SetDisplayId_001 end";
196 }
197
198 /**
199 * @tc.number: SetWindowType_001
200 * @tc.name: SetWindowType
201 * @tc.desc: Test function SetWindowType
202 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowType_001, TestSize.Level1)203 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowType_001, TestSize.Level1)
204 {
205 GTEST_LOG_(INFO) << "SetWindowType_001 start";
206 if (!windowInfo_) {
207 GTEST_LOG_(INFO) << "windowInfo_ is null";
208 return;
209 }
210 windowInfo_->SetWindowType(1);
211 EXPECT_EQ(windowInfo_->GetWindowType(), 1);
212 GTEST_LOG_(INFO) << "SetWindowType_001 end";
213 }
214
215 /**
216 * @tc.number: SetWindowMode_001
217 * @tc.name: SetWindowMode
218 * @tc.desc: Test function SetWindowMode
219 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowMode_001, TestSize.Level1)220 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowMode_001, TestSize.Level1)
221 {
222 GTEST_LOG_(INFO) << "SetWindowMode_001 start";
223 if (!windowInfo_) {
224 GTEST_LOG_(INFO) << "windowInfo_ is null";
225 return;
226 }
227 GTEST_LOG_(INFO) << "SetWindowMode_001 begin";
228 windowInfo_->SetWindowMode(1);
229 EXPECT_EQ(windowInfo_->GetWindowMode(), 1);
230 GTEST_LOG_(INFO) << "SetWindowMode_001 end";
231 }
232
233 /**
234 * @tc.number: SetDecorEnable_001
235 * @tc.name: SetDecorEnable
236 * @tc.desc: Test function SetDecorEnable
237 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetDecorEnable_001, TestSize.Level1)238 HWTEST_F(AccessibilityWindowInfoUnitTest, SetDecorEnable_001, TestSize.Level1)
239 {
240 GTEST_LOG_(INFO) << "SetDecorEnable_001 start";
241 if (!windowInfo_) {
242 GTEST_LOG_(INFO) << "windowInfo_ is null";
243 return;
244 }
245 windowInfo_->SetDecorEnable(true);
246 EXPECT_TRUE(windowInfo_->IsDecorEnable());
247 GTEST_LOG_(INFO) << "SetDecorEnable_001 end";
248 }
249
250 /**
251 * @tc.number: GetInnerWid_001
252 * @tc.name: GetInnerWid
253 * @tc.desc: Test function GetInnerWid
254 */
HWTEST_F(AccessibilityWindowInfoUnitTest, GetInnerWid_001, TestSize.Level1)255 HWTEST_F(AccessibilityWindowInfoUnitTest, GetInnerWid_001, TestSize.Level1)
256 {
257 GTEST_LOG_(INFO) << "GetInnerWid_001 start";
258 if (!windowInfo_) {
259 GTEST_LOG_(INFO) << "windowInfo_ is null";
260 return;
261 }
262 windowInfo_->SetInnerWid(INNER_WINDOW_ID);
263 EXPECT_EQ(windowInfo_->GetInnerWid(), INNER_WINDOW_ID);
264 GTEST_LOG_(INFO) << "GetInnerWid_001 end";
265 }
266
267 /**
268 * @tc.number: GetUiNodeId_001
269 * @tc.name: GetUiNodeId
270 * @tc.desc: Test function GetUiNodeId
271 */
HWTEST_F(AccessibilityWindowInfoUnitTest, GetUiNodeId_001, TestSize.Level1)272 HWTEST_F(AccessibilityWindowInfoUnitTest, GetUiNodeId_001, TestSize.Level1)
273 {
274 GTEST_LOG_(INFO) << "GetUiNodeId_001 start";
275 if (!windowInfo_) {
276 GTEST_LOG_(INFO) << "windowInfo_ is null";
277 return;
278 }
279 windowInfo_->SetUiNodeId(UI_NODE_ID);
280 EXPECT_EQ(windowInfo_->GetUiNodeId(), UI_NODE_ID);
281 GTEST_LOG_(INFO) << "GetUiNodeId_001 end";
282 }
283
284 /**
285 * @tc.number: GetScaleVal_001
286 * @tc.name: GetScaleVal
287 * @tc.desc: Test function GetScaleVal
288 */
HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleVal_001, TestSize.Level1)289 HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleVal_001, TestSize.Level1)
290 {
291 GTEST_LOG_(INFO) << "GetScaleVal_001 start";
292 if (!windowInfo_) {
293 GTEST_LOG_(INFO) << "windowInfo_ is null";
294 return;
295 }
296 windowInfo_->SetScaleVal(1.1);
297 EXPECT_FLOAT_EQ(windowInfo_->GetScaleVal(), 1.1f);
298 GTEST_LOG_(INFO) << "GetScaleVal_001 end";
299 }
300
301 /**
302 * @tc.number: GetScaleX_001
303 * @tc.name: GetScaleX
304 * @tc.desc: Test function GetScaleX
305 */
HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleX_001, TestSize.Level1)306 HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleX_001, TestSize.Level1)
307 {
308 GTEST_LOG_(INFO) << "GetScaleX_001 start";
309 if (!windowInfo_) {
310 GTEST_LOG_(INFO) << "windowInfo_ is null";
311 return;
312 }
313 windowInfo_->SetScaleX(1.1);
314 EXPECT_FLOAT_EQ(windowInfo_->GetScaleX(), 1.1f);
315 GTEST_LOG_(INFO) << "GetScaleX_001 end";
316 }
317
318 /**
319 * @tc.number: GetScaleY_001
320 * @tc.name: GetScaleY
321 * @tc.desc: Test function GetScaleY
322 */
HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleY_001, TestSize.Level1)323 HWTEST_F(AccessibilityWindowInfoUnitTest, GetScaleY_001, TestSize.Level1)
324 {
325 GTEST_LOG_(INFO) << "GetScaleY_001 start";
326 if (!windowInfo_) {
327 GTEST_LOG_(INFO) << "windowInfo_ is null";
328 return;
329 }
330 windowInfo_->SetScaleY(1.1);
331 EXPECT_FLOAT_EQ(windowInfo_->GetScaleY(), 1.1f);
332 GTEST_LOG_(INFO) << "GetScaleY_001 end";
333 }
334
335 /**
336 * @tc.number: SetMainWindowId_001
337 * @tc.name: SetMainWindowId
338 * @tc.desc: Test function SetMainWindowId
339 */
HWTEST_F(AccessibilityWindowInfoUnitTest, SetMainWindowId_001, TestSize.Level1)340 HWTEST_F(AccessibilityWindowInfoUnitTest, SetMainWindowId_001, TestSize.Level1)
341 {
342 GTEST_LOG_(INFO) << "SetMainWindowId_001 start";
343 if (!windowInfo_) {
344 GTEST_LOG_(INFO) << "windowInfo_ is null";
345 return;
346 }
347 windowInfo_->SetMainWindowId(1);
348 EXPECT_EQ(windowInfo_->GetMainWindowId(), 1);
349 GTEST_LOG_(INFO) << "SetMainWindowId_001 end";
350 }
351 } // namespace Accessibility
352 } // namespace OHOS