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