1 /*
2 * Copyright (c) 2023 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 <pointer_event.h>
19 #include "session/host/include/move_drag_controller.h"
20 #include "session/host/include/session.h"
21 #include "ui/rs_surface_node.h"
22 #include "window_manager_hilog.h"
23 #include "session/host/include/scene_session.h"
24 #include "session/screen/include/screen_session.h"
25 #include "screen_session_manager_client/include/screen_session_manager_client.h"
26 #include "screen_manager.h"
27
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Rosen {
34 class MoveDragControllerTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40 sptr<MoveDragController> moveDragController;
41 sptr<Session> session_;
42 };
43
SetUpTestCase()44 void MoveDragControllerTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void MoveDragControllerTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void MoveDragControllerTest::SetUp()
53 {
54 SessionInfo info;
55 info.abilityName_ = "testSession1";
56 info.moduleName_ = "testSession2";
57 info.bundleName_ = "testSession3";
58 session_ = new (std::nothrow) Session(info);
59 moveDragController = new MoveDragController(session_->GetPersistentId());
60 }
61
TearDown()62 void MoveDragControllerTest::TearDown()
63 {
64 session_ = nullptr;
65 moveDragController = nullptr;
66 }
67
68 namespace {
69 /**
70 * @tc.name: SetStartMoveFlag
71 * @tc.desc: test function : SetStartMoveFlag
72 * @tc.type: FUNC
73 */
HWTEST_F(MoveDragControllerTest, SetStartMoveFlag, Function | SmallTest | Level1)74 HWTEST_F(MoveDragControllerTest, SetStartMoveFlag, Function | SmallTest | Level1)
75 {
76 int32_t res = 0;
77 moveDragController->SetStartMoveFlag(true);
78 ASSERT_EQ(0, res);
79 }
80
81 /**
82 * @tc.name: GetStartMoveFlag
83 * @tc.desc: test function : GetStartMoveFlag
84 * @tc.type: FUNC
85 */
HWTEST_F(MoveDragControllerTest, GetStartMoveFlag, Function | SmallTest | Level1)86 HWTEST_F(MoveDragControllerTest, GetStartMoveFlag, Function | SmallTest | Level1)
87 {
88 auto preIsStartMove = moveDragController->isStartMove_;
89 auto preHasPointDown = moveDragController->hasPointDown_;
90 moveDragController->hasPointDown_ = false;
91 moveDragController->SetStartMoveFlag(true);
92 bool res = moveDragController->GetStartMoveFlag();
93 ASSERT_EQ(preIsStartMove, res);
94 moveDragController->SetStartMoveFlag(false);
95 res = moveDragController->GetStartMoveFlag();
96 ASSERT_EQ(false, res);
97 moveDragController->hasPointDown_ = true;
98 moveDragController->SetStartMoveFlag(true);
99 res = moveDragController->GetStartMoveFlag();
100 ASSERT_EQ(true, res);
101 moveDragController->SetStartMoveFlag(false);
102 res = moveDragController->GetStartMoveFlag();
103 ASSERT_EQ(false, res);
104 moveDragController->isStartMove_ = preIsStartMove;
105 moveDragController->hasPointDown_ = preHasPointDown;
106 }
107
108 /**
109 * @tc.name: GetStartDragFlag
110 * @tc.desc: test function : GetStartDragFlag
111 * @tc.type: FUNC
112 */
HWTEST_F(MoveDragControllerTest, GetStartDragFlag, Function | SmallTest | Level1)113 HWTEST_F(MoveDragControllerTest, GetStartDragFlag, Function | SmallTest | Level1)
114 {
115 bool res = moveDragController->GetStartDragFlag();
116 ASSERT_EQ(false, res);
117 }
118
119 /**
120 * @tc.name: GetMoveDragStartDisplayId
121 * @tc.desc: test function : GetMoveDragStartDisplayId
122 * @tc.type: FUNC
123 */
HWTEST_F(MoveDragControllerTest, GetMoveDragStartDisplayId, Function | SmallTest | Level1)124 HWTEST_F(MoveDragControllerTest, GetMoveDragStartDisplayId, Function | SmallTest | Level1)
125 {
126 uint64_t res = moveDragController->GetMoveDragStartDisplayId();
127 ASSERT_EQ(-1ULL, res);
128 }
129
130 /**
131 * @tc.name: GetMoveDragEndDisplayId
132 * @tc.desc: test function : GetMoveDragEndDisplayId
133 * @tc.type: FUNC
134 */
HWTEST_F(MoveDragControllerTest, GetMoveDragEndDisplayId, Function | SmallTest | Level1)135 HWTEST_F(MoveDragControllerTest, GetMoveDragEndDisplayId, Function | SmallTest | Level1)
136 {
137 uint64_t res = moveDragController->GetMoveDragEndDisplayId();
138 ASSERT_EQ(-1ULL, res);
139 }
140
141 /**
142 * @tc.name: GetInitParentNodeId
143 * @tc.desc: test function : GetInitParentNodeId
144 * @tc.type: FUNC
145 */
HWTEST_F(MoveDragControllerTest, GetInitParentNodeId, Function | SmallTest | Level1)146 HWTEST_F(MoveDragControllerTest, GetInitParentNodeId, Function | SmallTest | Level1)
147 {
148 uint64_t res = moveDragController->GetInitParentNodeId();
149 ASSERT_EQ(-1ULL, res);
150 }
151
152 /**
153 * @tc.name: GetDisplayIdsDuringMoveDrag
154 * @tc.desc: test function : GetDisplayIdsDuringMoveDrag
155 * @tc.type: FUNC
156 */
HWTEST_F(MoveDragControllerTest, GetDisplayIdsDuringMoveDrag, Function | SmallTest | Level1)157 HWTEST_F(MoveDragControllerTest, GetDisplayIdsDuringMoveDrag, Function | SmallTest | Level1)
158 {
159 std::set<uint64_t> res = moveDragController->GetDisplayIdsDuringMoveDrag();
160 ASSERT_EQ(true, res.empty());
161 }
162
163 /**
164 * @tc.name: GetTargetRect
165 * @tc.desc: test function : GetTargetRect
166 * @tc.type: FUNC
167 */
HWTEST_F(MoveDragControllerTest, GetTargetRect, Function | SmallTest | Level1)168 HWTEST_F(MoveDragControllerTest, GetTargetRect, Function | SmallTest | Level1)
169 {
170 uint32_t tmp = 0;
171 int32_t pos = 0;
172 moveDragController->InitMoveDragProperty();
173 WSRect res = moveDragController->GetTargetRect(MoveDragController::TargetRectCoordinate::GLOBAL);
174 ASSERT_EQ(tmp, res.height_);
175 ASSERT_EQ(tmp, res.width_);
176 ASSERT_EQ(pos, res.posX_);
177 ASSERT_EQ(pos, res.posY_);
178
179 res = moveDragController->GetTargetRect();
180 ASSERT_EQ(tmp, res.height_);
181 ASSERT_EQ(tmp, res.width_);
182 ASSERT_EQ(pos, res.posX_);
183 ASSERT_EQ(pos, res.posY_);
184 }
185
186 /**
187 * @tc.name: InitMoveDragProperty
188 * @tc.desc: test function : InitMoveDragProperty
189 * @tc.type: FUNC
190 */
HWTEST_F(MoveDragControllerTest, InitMoveDragProperty, Function | SmallTest | Level1)191 HWTEST_F(MoveDragControllerTest, InitMoveDragProperty, Function | SmallTest | Level1)
192 {
193 int32_t res = 0;
194 moveDragController->InitMoveDragProperty();
195 ASSERT_EQ(0, res);
196 }
197
198 /**
199 * @tc.name: InitCrossDisplayProperty
200 * @tc.desc: test function : InitCrossDisplayProperty
201 * @tc.type: FUNC
202 */
HWTEST_F(MoveDragControllerTest, InitCrossDisplayProperty, Function | SmallTest | Level1)203 HWTEST_F(MoveDragControllerTest, InitCrossDisplayProperty, Function | SmallTest | Level1)
204 {
205 moveDragController->InitCrossDisplayProperty(1, 2);
206 ASSERT_EQ(1, moveDragController->GetMoveDragStartDisplayId());
207 ASSERT_EQ(2, moveDragController->GetInitParentNodeId());
208 ASSERT_EQ(true, moveDragController->GetDisplayIdsDuringMoveDrag().find(1) !=
209 moveDragController->GetDisplayIdsDuringMoveDrag().end());
210 }
211
212 /**
213 * @tc.name: SetOriginalValue
214 * @tc.desc: test function : SetOriginalValue
215 * @tc.type: FUNC
216 */
HWTEST_F(MoveDragControllerTest, SetOriginalValue, Function | SmallTest | Level1)217 HWTEST_F(MoveDragControllerTest, SetOriginalValue, Function | SmallTest | Level1)
218 {
219 int32_t res = 0;
220 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
221 int32_t pointerId = pointerEvent->GetPointerId();
222 int32_t pointerType = pointerEvent->GetSourceType();
223 int32_t pointerPosX = 10;
224 int32_t pointerPosY = 30;
225 WSRect winRect = { 100, 100, 1000, 1000 };
226 moveDragController->SetOriginalValue(pointerId, pointerType, pointerPosX, pointerPosY, winRect);
227 ASSERT_EQ(0, res);
228 }
229
230 /**
231 * @tc.name: SetAspectRatio
232 * @tc.desc: test function : SetAspectRatio
233 * @tc.type: FUNC
234 */
HWTEST_F(MoveDragControllerTest, SetAspectRatio, Function | SmallTest | Level1)235 HWTEST_F(MoveDragControllerTest, SetAspectRatio, Function | SmallTest | Level1)
236 {
237 int32_t res = 0;
238 moveDragController->SetAspectRatio(0.5);
239 ASSERT_EQ(0, res);
240 }
241
242 /**
243 * @tc.name: UpdateGravityWhenDrag
244 * @tc.desc: test function : UpdateGravityWhenDrag
245 * @tc.type: FUNC
246 */
HWTEST_F(MoveDragControllerTest, UpdateGravityWhenDrag, Function | SmallTest | Level1)247 HWTEST_F(MoveDragControllerTest, UpdateGravityWhenDrag, Function | SmallTest | Level1)
248 {
249 int32_t res = 0;
250 struct RSSurfaceNodeConfig config;
251 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
252
253 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
254 if (!surfaceNode || !pointerEvent) {
255 return;
256 }
257 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
258 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
259 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
260 auto tempPointerEvent = pointerEvent;
261 pointerEvent = nullptr;
262 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
263 pointerEvent = tempPointerEvent;
264 auto tempSurfaceNode = surfaceNode;
265 surfaceNode = nullptr;
266 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
267 surfaceNode = tempSurfaceNode;
268 moveDragController->type_ = AreaType::UNDEFINED;
269 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
270 moveDragController->type_ = AreaType::RIGHT;
271 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
272 ASSERT_EQ(0, res);
273 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
274 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
275 ASSERT_EQ(0, res);
276
277 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
278 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
279 ASSERT_EQ(0, res);
280
281 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
282 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
283 ASSERT_EQ(0, res);
284
285 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
286 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
287 ASSERT_EQ(0, res);
288 }
289
290 /**
291 * @tc.name: CalcMoveTargetRect
292 * @tc.desc: test function : CalcMoveTargetRect
293 * @tc.type: FUNC
294 */
HWTEST_F(MoveDragControllerTest, CalcMoveTargetRect, Function | SmallTest | Level1)295 HWTEST_F(MoveDragControllerTest, CalcMoveTargetRect, Function | SmallTest | Level1)
296 {
297 int32_t res = 0;
298 moveDragController->InitMoveDragProperty();
299 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
300 WSRect originalRect = { 100, 100, 1000, 1000 };
301
302 moveDragController->CalcMoveTargetRect(pointerEvent, originalRect);
303 ASSERT_EQ(0, res);
304
305 pointerEvent = MMI::PointerEvent::Create();
306 int32_t pointerId = pointerEvent->GetPointerId();
307 int32_t pointerType = pointerEvent->GetSourceType();
308 int32_t pointerPosX = 10;
309 int32_t pointerPosY = 30;
310 moveDragController->SetOriginalValue(pointerId, pointerType, pointerPosX, pointerPosY, originalRect);
311 moveDragController->CalcMoveTargetRect(pointerEvent, originalRect);
312 ASSERT_EQ(0, res);
313 }
314
315 /**
316 * @tc.name: EventDownInit
317 * @tc.desc: test function : EventDownInit
318 * @tc.type: FUNC
319 */
HWTEST_F(MoveDragControllerTest, EventDownInit, Function | SmallTest | Level1)320 HWTEST_F(MoveDragControllerTest, EventDownInit, Function | SmallTest | Level1)
321 {
322 sptr<WindowSessionProperty> property = new WindowSessionProperty();
323 SystemSessionConfig sysConfig;
324 moveDragController->InitMoveDragProperty();
325 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
326 WSRect originalRect = { 100, 100, 1000, 1000 };
327
328 pointerEvent = MMI::PointerEvent::Create();
329 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
330 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
331
332 auto res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
333 ASSERT_EQ(false, res);
334 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
335 pointerEvent->SetTargetDisplayId(0);
336 MMI::PointerEvent::PointerItem pointerItem;
337 pointerItem.SetPointerId(0);
338 originalRect = { 10, 10, 10, 10 };
339 pointerItem.SetWindowX(100000000);
340 pointerItem.SetWindowY(100000000);
341 pointerEvent->AddPointerItem(pointerItem);
342 res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
343 ASSERT_EQ(true, res);
344 }
345
346 /**
347 * @tc.name: EventDownInit01
348 * @tc.desc: test function : EventDownInit
349 * @tc.type: FUNC
350 */
HWTEST_F(MoveDragControllerTest, EventDownInit01, Function | SmallTest | Level1)351 HWTEST_F(MoveDragControllerTest, EventDownInit01, Function | SmallTest | Level1)
352 {
353 sptr<WindowSessionProperty> property = new WindowSessionProperty();
354 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
355 property->SetDecorEnable(true);
356
357 SystemSessionConfig sysConfig;
358 moveDragController->InitMoveDragProperty();
359 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
360 WSRect originalRect = { 100, 100, 1000, 1000 };
361 MMI::PointerEvent::PointerItem pointerItem;
362 pointerItem.SetPointerId(1);
363 pointerItem.SetWindowX(1);
364 pointerItem.SetWindowY(1);
365 pointerEvent->AddPointerItem(pointerItem);
366 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
367 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
368 auto res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
369 ASSERT_EQ(true, res);
370 }
371
372 /**
373 * @tc.name: CalcFreeformTargetRect
374 * @tc.desc: test function : CalcFreeformTargetRect
375 * @tc.type: FUNC
376 */
HWTEST_F(MoveDragControllerTest, CalcFreeformTargetRect, Function | SmallTest | Level1)377 HWTEST_F(MoveDragControllerTest, CalcFreeformTargetRect, Function | SmallTest | Level1)
378 {
379 AreaType type = AreaType::RIGHT;
380 WSRect originalRect = { 100, 100, 1000, 1000 };
381 int32_t tranX = 10;
382 int32_t tranY = 30;
383 ASSERT_TRUE((moveDragController != nullptr));
384 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
385 type = AreaType::LEFT;
386 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
387 type = AreaType::RIGHT;
388 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
389 type = AreaType::BOTTOM;
390 ASSERT_TRUE((moveDragController != nullptr));
391 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
392 originalRect = { 100, 100, 1000, 0 };
393 ASSERT_TRUE((moveDragController != nullptr));
394 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
395 originalRect = { 100, 100, 500, 100 };
396 moveDragController->limits_ = { 3, 3, 3, 3, 2.0, 2.0 };
397 ASSERT_TRUE((moveDragController != nullptr));
398 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
399 type = AreaType::RIGHT;
400 originalRect = { 100, 100, 500, 0 };
401 ASSERT_TRUE((moveDragController != nullptr));
402 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
403 originalRect = { 100, 100, 100, 100 };
404 ASSERT_TRUE((moveDragController != nullptr));
405 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
406 type = AreaType::UNDEFINED;
407 originalRect = { 100, 100, 500, 100 };
408 ASSERT_TRUE((moveDragController != nullptr));
409 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
410 type = AreaType::RIGHT;
411 ASSERT_TRUE((moveDragController != nullptr));
412 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
413 moveDragController->limits_ = { 3, 3, 3, 3, 0.0001, 0.0001 };
414 ASSERT_TRUE((moveDragController != nullptr));
415 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
416 }
417
418 /**
419 * @tc.name: CalcFixedAspectRatioTargetRect01
420 * @tc.desc: test function : CalcFixedAspectRatioTargetRect01
421 * @tc.type: FUNC
422 */
HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect01, Function | SmallTest | Level1)423 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect01, Function | SmallTest | Level1)
424 {
425 AreaType type = AreaType::RIGHT;
426 float aspectRatio = 0.5;
427 WSRect originalRect = { 100, 100, 1000, 1000 };
428 int32_t tranX = 0;
429 int32_t tranY = 0;
430 ASSERT_TRUE((moveDragController != nullptr));
431 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
432 }
433
434 /**
435 * @tc.name: CalcFixedAspectRatioTargetRect02
436 * @tc.desc: test function : CalcFixedAspectRatioTargetRect02
437 * @tc.type: FUNC
438 */
HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect02, Function | SmallTest | Level1)439 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect02, Function | SmallTest | Level1)
440 {
441 AreaType type = AreaType::RIGHT;
442 float aspectRatio = 0.5;
443 WSRect originalRect = { 100, 100, 1000, 1000 };
444 int32_t tranX = 20;
445 int32_t tranY = 20;
446 ASSERT_TRUE((moveDragController != nullptr));
447 type = AreaType::UNDEFINED;
448 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::UNDEFINED;
449 tranX = 0;
450 tranY = 0;
451 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
452 type = AreaType::RIGHT;
453 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
454 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::X_AXIS;
455 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
456 type = AreaType::LEFT_TOP;
457 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
458 type = AreaType::RIGHT_TOP;
459 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
460 type = AreaType::RIGHT_BOTTOM;
461 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
462 type = AreaType::LEFT_BOTTOM;
463 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
464 type = AreaType::LEFT;
465 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
466 type = AreaType::TOP;
467 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
468 type = AreaType::RIGHT;
469 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
470 type = AreaType::BOTTOM;
471 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
472 type = AreaType::UNDEFINED;
473 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
474 }
475
476 /**
477 * @tc.name: CalcFreeformTranslateLimits01
478 * @tc.desc: test function : CalcFreeformTranslateLimits01
479 * @tc.type: FUNC
480 */
HWTEST_F(MoveDragControllerTest, CalcFreeformTranslateLimits01, Function | SmallTest | Level1)481 HWTEST_F(MoveDragControllerTest, CalcFreeformTranslateLimits01, Function | SmallTest | Level1)
482 {
483 AreaType type = AreaType::RIGHT;
484 ASSERT_TRUE((moveDragController != nullptr));
485 moveDragController->CalcFreeformTranslateLimits(type);
486 type = AreaType::BOTTOM;
487 moveDragController->CalcFreeformTranslateLimits(type);
488 type = AreaType::TOP;
489 moveDragController->CalcFreeformTranslateLimits(type);
490 type = AreaType::LEFT;
491 moveDragController->CalcFreeformTranslateLimits(type);
492 }
493
494 /**
495 * @tc.name: CalcFixedAspectRatioTranslateLimits01
496 * @tc.desc: test function : CalcFixedAspectRatioTranslateLimits01
497 * @tc.type: FUNC
498 */
HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTranslateLimits01, Function | SmallTest | Level1)499 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTranslateLimits01, Function | SmallTest | Level1)
500 {
501 moveDragController->limits_ = { 30, 60, 30, 60, 2.0, 2.0 };
502 moveDragController->aspectRatio_ = 1.0f;
503 MoveDragController::AxisType axis = MoveDragController::AxisType::X_AXIS;
504 AreaType type = AreaType::RIGHT;
505 ASSERT_TRUE((moveDragController != nullptr));
506 moveDragController->isDecorEnable_ = true;
507 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
508 moveDragController->isDecorEnable_ = false;
509 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
510 moveDragController->limits_ = { 60, 60, 60, 60, 2.0, 2.0 };
511 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
512 type = AreaType::LEFT;
513 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
514 axis = MoveDragController::AxisType::Y_AXIS;
515 type = AreaType::BOTTOM;
516 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
517 axis = MoveDragController::AxisType::X_AXIS;
518 type = AreaType::TOP;
519 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
520 }
521
522 /**
523 * @tc.name: FixTranslateByLimits01
524 * @tc.desc: test function : FixTranslateByLimits01
525 * @tc.type: FUNC
526 */
HWTEST_F(MoveDragControllerTest, FixTranslateByLimits01, Function | SmallTest | Level1)527 HWTEST_F(MoveDragControllerTest, FixTranslateByLimits01, Function | SmallTest | Level1)
528 {
529 int32_t tranX = 100;
530 int32_t tranY = 100;
531 moveDragController->maxTranX_ = 50;
532 moveDragController->maxTranY_ = 50;
533 ASSERT_TRUE((moveDragController != nullptr));
534 moveDragController->FixTranslateByLimits(tranX, tranY);
535 tranX = 10;
536 moveDragController->FixTranslateByLimits(tranX, tranY);
537 tranY = 10;
538 moveDragController->FixTranslateByLimits(tranX, tranY);
539 }
540
541 /**
542 * @tc.name: InitMainAxis01
543 * @tc.desc: test function : InitMainAxis01
544 * @tc.type: FUNC
545 */
HWTEST_F(MoveDragControllerTest, InitMainAxis01, Function | SmallTest | Level1)546 HWTEST_F(MoveDragControllerTest, InitMainAxis01, Function | SmallTest | Level1)
547 {
548 AreaType type = AreaType::LEFT;
549 int32_t tranX = 100;
550 int32_t tranY = 100;
551 ASSERT_TRUE((moveDragController != nullptr));
552 moveDragController->InitMainAxis(type, tranX, tranY);
553 type = AreaType::RIGHT;
554 moveDragController->InitMainAxis(type, tranX, tranY);
555 type = AreaType::TOP;
556 moveDragController->InitMainAxis(type, tranX, tranY);
557 type = AreaType::BOTTOM;
558 moveDragController->InitMainAxis(type, tranX, tranY);
559 type = AreaType::UNDEFINED;
560 tranX = 0;
561 tranY = 0;
562 moveDragController->InitMainAxis(type, tranX, tranY);
563 tranY = 1;
564 moveDragController->InitMainAxis(type, tranX, tranY);
565 }
566
567 /**
568 * @tc.name: ConvertXYByAspectRatio01
569 * @tc.desc: test function : ConvertXYByAspectRatio01
570 * @tc.type: FUNC
571 */
HWTEST_F(MoveDragControllerTest, ConvertXYByAspectRatio01, Function | SmallTest | Level1)572 HWTEST_F(MoveDragControllerTest, ConvertXYByAspectRatio01, Function | SmallTest | Level1)
573 {
574 float aspectRatio = 1.0f;
575 int32_t tx = 100;
576 int32_t ty = 100;
577 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::X_AXIS;
578 ASSERT_TRUE((moveDragController != nullptr));
579 moveDragController->ConvertXYByAspectRatio(tx, ty, aspectRatio);
580 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::Y_AXIS;
581 moveDragController->ConvertXYByAspectRatio(tx, ty, aspectRatio);
582 }
583
584 /**
585 * @tc.name: InitDecorValue01
586 * @tc.desc: test function : InitDecorValue01
587 * @tc.type: FUNC
588 */
HWTEST_F(MoveDragControllerTest, InitDecorValue01, Function | SmallTest | Level1)589 HWTEST_F(MoveDragControllerTest, InitDecorValue01, Function | SmallTest | Level1)
590 {
591 sptr<WindowSessionProperty> property = new WindowSessionProperty();
592 SystemSessionConfig sysConfig;
593 ASSERT_TRUE((moveDragController != nullptr));
594 moveDragController->InitDecorValue(property, sysConfig);
595 }
596
597 /**
598 * @tc.name: ConsumeMoveEvent
599 * @tc.desc: test function : ConsumeMoveEvent
600 * @tc.type: FUNC
601 */
HWTEST_F(MoveDragControllerTest, ConsumeMoveEvent, Function | SmallTest | Level1)602 HWTEST_F(MoveDragControllerTest, ConsumeMoveEvent, Function | SmallTest | Level1)
603 {
604 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
605 if (!pointerEvent) {
606 return;
607 }
608 WSRect originalRect = { 100, 100, 1000, 1000 };
609 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(nullptr, originalRect));
610 auto preStratDragFlag = moveDragController->GetStartDragFlag();
611 moveDragController->isStartDrag_ = true;
612 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
613 moveDragController->isStartDrag_ = false;
614 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
615 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
616 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
617 pointerEvent->SetSourceType(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
618 moveDragController->SetStartMoveFlag(false);
619 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
620 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
621 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
622 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
623 moveDragController->SetStartMoveFlag(true);
624 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
625 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
626 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
627 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
628 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UNKNOWN);
629 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
630 moveDragController->moveDragProperty_.pointerId_ = -2;
631 moveDragController->moveDragProperty_.pointerType_ = -2;
632 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
633 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
634 moveDragController->isStartDrag_ = preStratDragFlag;
635 }
636
637
638 /**
639 * @tc.name: ProcessWindowDragHotAreaFunc
640 * @tc.desc: test function : ProcessWindowDragHotAreaFunc
641 * @tc.type: FUNC
642 */
HWTEST_F(MoveDragControllerTest, ProcessWindowDragHotAreaFunc, Function | SmallTest | Level1)643 HWTEST_F(MoveDragControllerTest, ProcessWindowDragHotAreaFunc, Function | SmallTest | Level1)
644 {
645 bool isSendHotAreaMessage = true;
646 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
647 moveDragController->ProcessWindowDragHotAreaFunc(isSendHotAreaMessage, reason);
648 ASSERT_EQ(true, isSendHotAreaMessage);
649 auto dragHotAreaFunc = [](DisplayId displayId, int32_t type, const SizeChangeReason reason) {
650 type = 0;
651 };
652 auto preFunc = moveDragController->windowDragHotAreaFunc_;
653 moveDragController->windowDragHotAreaFunc_ = dragHotAreaFunc;
654 moveDragController->ProcessWindowDragHotAreaFunc(isSendHotAreaMessage, reason);
655 ASSERT_EQ(true, isSendHotAreaMessage);
656 moveDragController->windowDragHotAreaFunc_ = preFunc;
657 }
658
659 /**
660 * @tc.name: ConsumeDragEvent
661 * @tc.desc: test function : ConsumeDragEvent
662 * @tc.type: FUNC
663 */
HWTEST_F(MoveDragControllerTest, ConsumeDragEvent, Function | SmallTest | Level1)664 HWTEST_F(MoveDragControllerTest, ConsumeDragEvent, Function | SmallTest | Level1)
665 {
666 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
667 if (!pointerEvent) {
668 return;
669 }
670 WSRect originalRect = { 100, 100, 1000, 1000 };
671 sptr<WindowSessionProperty> property = new WindowSessionProperty();
672 if (!property) {
673 return;
674 }
675 SystemSessionConfig sysConfig;
676 moveDragController->GetVirtualPixelRatio();
677 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(nullptr, originalRect, property, sysConfig));
678 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, nullptr, sysConfig));
679 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
680 moveDragController->SetStartMoveFlag(true);
681 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
682 moveDragController->SetStartMoveFlag(false);
683 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
684 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
685 MMI::PointerEvent::PointerItem pointerItem;
686 pointerItem.SetPointerId(0);
687 pointerItem.SetWindowX(0);
688 pointerItem.SetWindowY(0);
689 pointerEvent->AddPointerItem(pointerItem);
690 pointerEvent->SetPointerId(0);
691 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
692 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
693 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
694 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
695 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
696 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_MOVE));
697 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
698 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
699 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
700 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UNKNOWN));
701 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
702 }
703
704 /**
705 * @tc.name: UpdateDragType01
706 * @tc.desc: test function : UpdateDragType
707 * @tc.type: FUNC
708 */
HWTEST_F(MoveDragControllerTest, UpdateDragType01, Function | SmallTest | Level1)709 HWTEST_F(MoveDragControllerTest, UpdateDragType01, Function | SmallTest | Level1)
710 {
711 moveDragController->rectExceptCorner_.posX_ = 2;
712 moveDragController->rectExceptCorner_.width_ = 2;
713 moveDragController->rectExceptCorner_.posY_ = 0;
714 moveDragController->rectExceptCorner_.height_ = 0;
715 moveDragController->UpdateDragType(3, 3);
716 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_BOTTOM_OR_TOP);
717 }
718
719 /**
720 * @tc.name: UpdateDragType02
721 * @tc.desc: test function : UpdateDragType
722 * @tc.type: FUNC
723 */
HWTEST_F(MoveDragControllerTest, UpdateDragType02, Function | SmallTest | Level1)724 HWTEST_F(MoveDragControllerTest, UpdateDragType02, Function | SmallTest | Level1)
725 {
726 moveDragController->rectExceptCorner_.posX_ = 0;
727 moveDragController->rectExceptCorner_.width_ = 0;
728 moveDragController->rectExceptCorner_.posY_ = 2;
729 moveDragController->rectExceptCorner_.height_ = 2;
730 moveDragController->UpdateDragType(3, 3);
731 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_LEFT_OR_RIGHT);
732 }
733
734 /**
735 * @tc.name: UpdateDragType03
736 * @tc.desc: test function : UpdateDragType
737 * @tc.type: FUNC
738 */
HWTEST_F(MoveDragControllerTest, UpdateDragType03, Function | SmallTest | Level1)739 HWTEST_F(MoveDragControllerTest, UpdateDragType03, Function | SmallTest | Level1)
740 {
741 moveDragController->rectExceptCorner_.posX_ = 1;
742 moveDragController->rectExceptCorner_.width_ = 0;
743 moveDragController->rectExceptCorner_.posY_ = 1;
744 moveDragController->rectExceptCorner_.height_ = 0;
745 moveDragController->UpdateDragType(1, 1);
746 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_LEFT_TOP_CORNER);
747 }
748
749 /**
750 * @tc.name: IsPointInDragHotZone01
751 * @tc.desc: test function : IsPointInDragHotZone
752 * @tc.type: FUNC
753 */
HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone01, Function | SmallTest | Level1)754 HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone01, Function | SmallTest | Level1)
755 {
756 WSRect winRect = { 10, 10, 10, 10 };
757 int32_t sourceType = MMI::PointerEvent::SOURCE_TYPE_MOUSE;
758 int32_t startPointPosX = 1;
759 int32_t startPointPosY = 1;
760 bool res = moveDragController->IsPointInDragHotZone(startPointPosX, startPointPosY, sourceType, winRect);
761 ASSERT_EQ(res, false);
762 }
763
764 /**
765 * @tc.name: IsPointInDragHotZone02
766 * @tc.desc: test function : IsPointInDragHotZone
767 * @tc.type: FUNC
768 */
HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone02, Function | SmallTest | Level1)769 HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone02, Function | SmallTest | Level1)
770 {
771 WSRect winRect = { 5, 5, 0, 0 };
772 int32_t startPointPosX = 1;
773 int32_t startPointPosY = 1;
774 bool res = moveDragController->IsPointInDragHotZone(startPointPosX, startPointPosY, 0, winRect);
775 ASSERT_EQ(res, true);
776 }
777
778 /**
779 * @tc.name: CalculateStartRectExceptHotZone
780 * @tc.desc: test function : CalculateStartRectExceptHotZone
781 * @tc.type: FUNC
782 */
HWTEST_F(MoveDragControllerTest, CalculateStartRectExceptHotZone, Function | SmallTest | Level1)783 HWTEST_F(MoveDragControllerTest, CalculateStartRectExceptHotZone, Function | SmallTest | Level1)
784 {
785 float vpr = 1.0f;
786 WSRect winRect;
787 winRect.posX_ = 100;
788 winRect.posY_ = 100;
789 winRect.width_ = 100;
790 winRect.height_ = 100;
791 moveDragController->CalculateStartRectExceptHotZone(vpr, winRect);
792
793 EXPECT_EQ(moveDragController->rectExceptFrame_.posX_, 105);
794 EXPECT_EQ(moveDragController->rectExceptFrame_.posY_, 105);
795 EXPECT_EQ(moveDragController->rectExceptFrame_.width_, 90);
796 EXPECT_EQ(moveDragController->rectExceptFrame_.height_, 90);
797
798 EXPECT_EQ(moveDragController->rectExceptCorner_.posX_, 116);
799 EXPECT_EQ(moveDragController->rectExceptCorner_.posY_, 116);
800 EXPECT_EQ(moveDragController->rectExceptCorner_.width_, 68);
801 EXPECT_EQ(moveDragController->rectExceptCorner_.height_, 68);
802 }
803
804 /**
805 * @tc.name: CalcFirstMoveTargetRect
806 * @tc.desc: test function : CalcFirstMoveTargetRect
807 * @tc.type: FUNC
808 */
HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect, Function | SmallTest | Level1)809 HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect, Function | SmallTest | Level1)
810 {
811 int res = 0;
812 WSRect windowRect = { 0, 0, 0, 0 };
813 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
814 res++;
815 moveDragController->moveTempProperty_.pointerId_ = 0;
816 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
817 ASSERT_EQ(res, 1);
818 auto preIsStartMove = moveDragController->GetStartMoveFlag();
819 auto preMoveTempProperty = moveDragController->moveTempProperty_;
820 moveDragController->isStartMove_ = false;
821 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
822 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
823 ASSERT_EQ(res, 1);
824 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
825 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
826 ASSERT_EQ(res, 1);
827 moveDragController->isStartMove_ = true;
828 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
829 ASSERT_EQ(res, 1);
830 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
831 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
832 ASSERT_EQ(res, 1);
833 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
834 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
835 ASSERT_EQ(res, 1);
836 moveDragController->CalcFirstMoveTargetRect(windowRect, true);
837 ASSERT_EQ(res, 1);
838 moveDragController->isStartMove_ = preIsStartMove;
839 moveDragController->moveTempProperty_ = preMoveTempProperty;
840 }
841
842 /**
843 * @tc.name: CalcFirstMoveTargetRect001
844 * @tc.desc: test function : CalcFirstMoveTargetRect001
845 * @tc.type: FUNC
846 */
HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect001, Function | SmallTest | Level1)847 HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect001, Function | SmallTest | Level1)
848 {
849 WSRect windowRect = { 1, 2, 3, 4 };
850 moveDragController->InitMoveDragProperty();
851 moveDragController->SetStartMoveFlag(true);
852 moveDragController->CalcFirstMoveTargetRect(windowRect, true);
853 WSRect targetRect = moveDragController->GetTargetRect();
854 ASSERT_EQ(targetRect.posX_, 0);
855 }
856
857 /**
858 * @tc.name: GetFullScreenToFloatingRect
859 * @tc.desc: test function : GetFullScreenToFloatingRect
860 * @tc.type: FUNC
861 */
HWTEST_F(MoveDragControllerTest, GetFullScreenToFloatingRect, Function | SmallTest | Level1)862 HWTEST_F(MoveDragControllerTest, GetFullScreenToFloatingRect, Function | SmallTest | Level1)
863 {
864 WSRect originalRect = { 1, 2, 0, 4 };
865 WSRect windowRect = { 5, 6, 7, 8 };
866 auto preMoveTempProperty = moveDragController->moveTempProperty_;
867 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
868 WSRect rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
869 ASSERT_EQ(originalRect.posX_, rect.posX_);
870 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
871 rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
872 ASSERT_EQ(windowRect.posX_, rect.posX_);
873 originalRect = { 1, 2, 3, 4 };
874 rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
875 WSRect targetRect = { -1, 2, 7, 8, };
876 ASSERT_EQ(targetRect.posX_, rect.posX_);
877 moveDragController->moveTempProperty_ = preMoveTempProperty;
878 }
879
880 /**
881 * @tc.name: CheckDragEventLegal
882 * @tc.desc: test function : CheckDragEventLegal
883 * @tc.type: FUNC
884 */
HWTEST_F(MoveDragControllerTest, CheckDragEventLegal, Function | SmallTest | Level1)885 HWTEST_F(MoveDragControllerTest, CheckDragEventLegal, Function | SmallTest | Level1)
886 {
887 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
888 ASSERT_NE(pointerEvent, nullptr);
889 sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
890 ASSERT_NE(property, nullptr);
891 auto tempPointerEvent = pointerEvent;
892 pointerEvent = nullptr;
893 auto result = moveDragController->CheckDragEventLegal(pointerEvent, property);
894 ASSERT_EQ(result, false);
895 pointerEvent = tempPointerEvent;
896 result = moveDragController->CheckDragEventLegal(pointerEvent, nullptr);
897 ASSERT_EQ(result, false);
898 moveDragController->isStartMove_ = true;
899 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
900 ASSERT_EQ(result, false);
901 moveDragController->isStartMove_ = false;
902 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
903 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
904 ASSERT_EQ(result, false);
905 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
906 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
907 ASSERT_EQ(result, true);
908 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN));
909 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
910 ASSERT_EQ(result, true);
911 auto preMoveDragProperty = moveDragController->moveDragProperty_;
912 moveDragController->moveDragProperty_.pointerId_ = -1;
913 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
914 ASSERT_EQ(result, true);
915 moveDragController->moveDragProperty_ = preMoveDragProperty;
916 }
917
918 /**
919 * @tc.name: UpdateMoveTempProperty
920 * @tc.desc: test function : UpdateMoveTempProperty
921 * @tc.type: FUNC
922 */
HWTEST_F(MoveDragControllerTest, UpdateMoveTempProperty, Function | SmallTest | Level1)923 HWTEST_F(MoveDragControllerTest, UpdateMoveTempProperty, Function | SmallTest | Level1)
924 {
925 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
926 ASSERT_NE(pointerEvent, nullptr);
927 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
928 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
929 auto result = moveDragController->UpdateMoveTempProperty(pointerEvent);
930 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
931 MMI::PointerEvent::PointerItem pointerItem;
932 pointerItem.SetPointerId(0);
933 pointerEvent->AddPointerItem(pointerItem);
934 pointerEvent->SetPointerId(0);
935 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
936 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
937 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
938 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
939 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
940 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
941 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
942 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
943 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN));
944 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
945 ASSERT_EQ(result, WSError::WS_OK);
946 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
947 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
948 ASSERT_EQ(result, WSError::WS_OK);
949 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_MOVE));
950 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
951 ASSERT_EQ(result, WSError::WS_OK);
952 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
953 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
954 ASSERT_EQ(result, WSError::WS_OK);
955 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP));
956 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
957 ASSERT_EQ(result, WSError::WS_OK);
958 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_CANCEL));
959 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
960 ASSERT_EQ(result, WSError::WS_OK);
961 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UNKNOWN));
962 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
963 ASSERT_EQ(result, WSError::WS_OK);
964 }
965
966 /**
967 * @tc.name: UpdateHotAreaType
968 * @tc.desc: UpdateHotAreaType
969 * @tc.type: FUNC
970 */
HWTEST_F(MoveDragControllerTest, UpdateHotAreaType, Function | SmallTest | Level1)971 HWTEST_F(MoveDragControllerTest, UpdateHotAreaType, Function | SmallTest | Level1)
972 {
973 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
974 ASSERT_NE(pointerEvent, nullptr);
975 moveDragController->UpdateHotAreaType(pointerEvent);
976 MMI::PointerEvent::PointerItem pointerItem;
977 pointerItem.SetPointerId(0);
978 pointerEvent->AddPointerItem(pointerItem);
979 pointerEvent->SetPointerId(0);
980 moveDragController->UpdateHotAreaType(pointerEvent);
981 auto preWindowDragHotAreaType = moveDragController->windowDragHotAreaType_;
982 moveDragController->windowDragHotAreaType_ = WINDOW_HOT_AREA_TYPE_UNDEFINED;
983 moveDragController->UpdateHotAreaType(pointerEvent);
984 moveDragController->windowDragHotAreaType_ = preWindowDragHotAreaType;
985 }
986
987 /**
988 * @tc.name: OnLostFocus
989 * @tc.desc: OnLostFocus
990 * @tc.type: FUNC
991 */
HWTEST_F(MoveDragControllerTest, OnLostFocus, Function | SmallTest | Level1)992 HWTEST_F(MoveDragControllerTest, OnLostFocus, Function | SmallTest | Level1)
993 {
994 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
995 ASSERT_NE(pointerEvent, nullptr);
996 moveDragController->isStartMove_ = true;
997 moveDragController->isStartDrag_ = false;
998 moveDragController->OnLostFocus();
999 moveDragController->isStartMove_ = false;
1000 moveDragController->isStartDrag_ = true;
1001 int windowHotAreaTypeOther = 1;
1002 moveDragController->windowDragHotAreaType_ = windowHotAreaTypeOther;
1003 moveDragController->OnLostFocus();
1004 moveDragController->windowDragHotAreaType_ = WINDOW_HOT_AREA_TYPE_UNDEFINED;
1005 moveDragController->OnLostFocus();
1006 }
1007
1008 /**
1009 * @tc.name: NotifyWindowInputPidChange
1010 * @tc.desc: NotifyWindowInputPidChange
1011 * @tc.type: FUNC
1012 */
HWTEST_F(MoveDragControllerTest, NotifyWindowInputPidChange, Function | SmallTest | Level1)1013 HWTEST_F(MoveDragControllerTest, NotifyWindowInputPidChange, Function | SmallTest | Level1)
1014 {
1015 bool isServerPid = true;
1016 auto preCallback = moveDragController->pidChangeCallback_;
1017 moveDragController->NotifyWindowInputPidChange(isServerPid);
1018 isServerPid = false;
1019 moveDragController->NotifyWindowInputPidChange(isServerPid);
1020 moveDragController->SetNotifyWindowPidChangeCallback(nullptr);
1021 ASSERT_EQ(moveDragController->pidChangeCallback_, nullptr);
1022 isServerPid = true;
1023 moveDragController->NotifyWindowInputPidChange(isServerPid);
1024 isServerPid = false;
1025 moveDragController->NotifyWindowInputPidChange(isServerPid);
1026 moveDragController->SetNotifyWindowPidChangeCallback(preCallback);
1027 }
1028
1029 /**
1030 * @tc.name: HasPointDown
1031 * @tc.desc: HasPointDown
1032 * @tc.type: FUNC
1033 */
HWTEST_F(MoveDragControllerTest, HasPointDown, Function | SmallTest | Level1)1034 HWTEST_F(MoveDragControllerTest, HasPointDown, Function | SmallTest | Level1)
1035 {
1036 bool preHasPointDown = moveDragController->hasPointDown_;
1037 moveDragController->hasPointDown_ = true;
1038 bool res = moveDragController->HasPointDown();
1039 ASSERT_EQ(res, true);
1040 moveDragController->hasPointDown_ = false;
1041 res = moveDragController->HasPointDown();
1042 ASSERT_EQ(res, false);
1043 moveDragController->hasPointDown_ = preHasPointDown;
1044 }
1045
1046 /**
1047 * @tc.name: ProcessSessionRectChange
1048 * @tc.desc: ProcessSessionRectChange
1049 * @tc.type: FUNC
1050 */
HWTEST_F(MoveDragControllerTest, ProcessSessionRectChange, Function | SmallTest | Level1)1051 HWTEST_F(MoveDragControllerTest, ProcessSessionRectChange, Function | SmallTest | Level1)
1052 {
1053 int32_t res = 0;
1054 auto preCallback = moveDragController->moveDragCallback_;
1055 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1056 MoveDragCallback callBack = [](const SizeChangeReason reason) {
1057 return;
1058 };
1059 moveDragController->moveDragCallback_ = callBack;
1060 moveDragController->ProcessSessionRectChange(reason);
1061 moveDragController->moveDragCallback_ = nullptr;
1062 moveDragController->ProcessSessionRectChange(reason);
1063 moveDragController->moveDragCallback_ = preCallback;
1064 ASSERT_EQ(0, res);
1065 }
1066
1067 /**
1068 * @tc.name: GetOriginalPointerPosX
1069 * @tc.desc: GetOriginalPointerPosX
1070 * @tc.type: FUNC
1071 */
HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosX, Function | SmallTest | Level1)1072 HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosX, Function | SmallTest | Level1)
1073 {
1074 int32_t posX = moveDragController->moveDragProperty_.originalPointerPosX_;
1075 int32_t res = moveDragController->GetOriginalPointerPosX();
1076 ASSERT_EQ(posX, res);
1077 }
1078
1079 /**
1080 * @tc.name: GetOriginalPointerPosY
1081 * @tc.desc: GetOriginalPointerPosY
1082 * @tc.type: FUNC
1083 */
HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosY, Function | SmallTest | Level1)1084 HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosY, Function | SmallTest | Level1)
1085 {
1086 int32_t posY = moveDragController->moveDragProperty_.originalPointerPosY_;
1087 int32_t res = moveDragController->GetOriginalPointerPosY();
1088 ASSERT_EQ(posY, res);
1089 }
1090
1091 /**
1092 * @tc.name: GetNewAddedDisplayIdsDuringMoveDrag
1093 * @tc.desc: test function : GetNewAddedDisplayIdsDuringMoveDrag
1094 * @tc.type: FUNC
1095 */
HWTEST_F(MoveDragControllerTest, GetNewAddedDisplayIdsDuringMoveDrag, Function | SmallTest | Level1)1096 HWTEST_F(MoveDragControllerTest, GetNewAddedDisplayIdsDuringMoveDrag, Function | SmallTest | Level1)
1097 {
1098 std::set<uint64_t> res = moveDragController->GetDisplayIdsDuringMoveDrag();
1099 ASSERT_EQ(true, res.empty());
1100 }
1101
1102 /**
1103 * @tc.name: CalcUnifiedTranslate
1104 * @tc.desc: test function : CalcUnifiedTranslate
1105 * @tc.type: FUNC
1106 */
HWTEST_F(MoveDragControllerTest, CalcUnifiedTranslate, Function | SmallTest | Level1)1107 HWTEST_F(MoveDragControllerTest, CalcUnifiedTranslate, Function | SmallTest | Level1)
1108 {
1109 moveDragController->InitMoveDragProperty();
1110 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
1111 pointerEvent->SetTargetDisplayId(0);
1112 MMI::PointerEvent::PointerItem pointerItem;
1113 pointerItem.SetPointerId(0);
1114 pointerItem.SetDisplayX(10);
1115 pointerItem.SetDisplayY(30);
1116 pointerEvent->AddPointerItem(pointerItem);
1117 std::pair<int32_t, int32_t> res = moveDragController->CalcUnifiedTranslate(pointerEvent);
1118 ASSERT_EQ(0, res.first);
1119 ASSERT_EQ(0, res.second);
1120 }
1121
1122 /**
1123 * @tc.name: GetSysWindowFlag
1124 * @tc.desc: test function : GetSysWindowFlag
1125 * @tc.type: FUNC
1126 */
HWTEST_F(MoveDragControllerTest, GetSysWindowFlag, Function | SmallTest | Level1)1127 HWTEST_F(MoveDragControllerTest, GetSysWindowFlag, Function | SmallTest | Level1)
1128 {
1129 bool preSystemWindowFlag = moveDragController->IsSystemWindow();
1130 moveDragController->SetAsSystemWindow(true);
1131 ASSERT_EQ(true, moveDragController->IsSystemWindow());
1132 moveDragController->SetAsSystemWindow(false);
1133 ASSERT_EQ(false, moveDragController->IsSystemWindow());
1134 moveDragController->SetAsSystemWindow(preSystemWindowFlag);
1135 }
1136
1137 /**
1138 * @tc.name: MoveDragInterrupt
1139 * @tc.desc: test function : MoveDragInterrupt
1140 * @tc.type: FUNC
1141 */
HWTEST_F(MoveDragControllerTest, MoveDragInterrupt, Function | SmallTest | Level1)1142 HWTEST_F(MoveDragControllerTest, MoveDragInterrupt, Function | SmallTest | Level1)
1143 {
1144 moveDragController->MoveDragInterrupt();
1145 ASSERT_EQ(false, moveDragController->GetStartDragFlag());
1146 ASSERT_EQ(false, moveDragController->GetStartMoveFlag());
1147 ASSERT_EQ(false, moveDragController->hasPointDown_);
1148 }
1149
1150 /**
1151 * @tc.name: ResetCrossMoveDragProperty
1152 * @tc.desc: test function : ResetCrossMoveDragProperty
1153 * @tc.type: FUNC
1154 */
HWTEST_F(MoveDragControllerTest, ResetCrossMoveDragProperty, Function | SmallTest | Level1)1155 HWTEST_F(MoveDragControllerTest, ResetCrossMoveDragProperty, Function | SmallTest | Level1)
1156 {
1157 moveDragController->ResetCrossMoveDragProperty();
1158 ASSERT_EQ(false, moveDragController->IsSystemWindow());
1159 ASSERT_EQ(false, moveDragController->hasPointDown_);
1160 }
1161 }
1162 }
1163 }