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: SetOriginalValue
147 * @tc.desc: test function : SetOriginalValue
148 * @tc.type: FUNC
149 */
150 HWTEST_F(MoveDragControllerTest, SetOriginalValue, 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 WSRect winRect = { 100, 100, 1000, 1000 };
159 moveDragController->SetOriginalValue(pointerId, pointerType, pointerPosX, pointerPosY, winRect);
160 ASSERT_EQ(0, res);
161 }
162
163 /**
164 * @tc.name: SetAspectRatio
165 * @tc.desc: test function : SetAspectRatio
166 * @tc.type: FUNC
167 */
168 HWTEST_F(MoveDragControllerTest, SetAspectRatio, Function | SmallTest | Level1)
169 {
170 int32_t res = 0;
171 moveDragController->SetAspectRatio(0.5);
172 ASSERT_EQ(0, res);
173 }
174
175 /**
176 * @tc.name: UpdateGravityWhenDrag
177 * @tc.desc: test function : UpdateGravityWhenDrag
178 * @tc.type: FUNC
179 */
180 HWTEST_F(MoveDragControllerTest, UpdateGravityWhenDrag, Function | SmallTest | Level1)
181 {
182 int32_t res = 0;
183 struct RSSurfaceNodeConfig config;
184 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
185
186 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
187 if (!surfaceNode || !pointerEvent) {
188 return;
189 }
190 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
191 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
192 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
193 auto tempPointerEvent = pointerEvent;
194 pointerEvent = nullptr;
195 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
196 pointerEvent = tempPointerEvent;
197 auto tempSurfaceNode = surfaceNode;
198 surfaceNode = nullptr;
199 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
200 surfaceNode = tempSurfaceNode;
201 moveDragController->type_ = AreaType::UNDEFINED;
202 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
203 moveDragController->type_ = AreaType::RIGHT;
204 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
205 ASSERT_EQ(0, res);
206 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
207 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
208 ASSERT_EQ(0, res);
209
210 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
211 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
212 ASSERT_EQ(0, res);
213
214 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
215 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
216 ASSERT_EQ(0, res);
217
218 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
219 moveDragController->UpdateGravityWhenDrag(pointerEvent, surfaceNode);
220 ASSERT_EQ(0, res);
221 }
222
223 /**
224 * @tc.name: CalcMoveTargetRect
225 * @tc.desc: test function : CalcMoveTargetRect
226 * @tc.type: FUNC
227 */
228 HWTEST_F(MoveDragControllerTest, CalcMoveTargetRect, Function | SmallTest | Level1)
229 {
230 int32_t res = 0;
231 moveDragController->InitMoveDragProperty();
232 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
233 WSRect originalRect = { 100, 100, 1000, 1000 };
234
235 moveDragController->CalcMoveTargetRect(pointerEvent, originalRect);
236 ASSERT_EQ(0, res);
237
238 pointerEvent = MMI::PointerEvent::Create();
239 int32_t pointerId = pointerEvent->GetPointerId();
240 int32_t pointerType = pointerEvent->GetSourceType();
241 int32_t pointerPosX = 10;
242 int32_t pointerPosY = 30;
243 moveDragController->SetOriginalValue(pointerId, pointerType, pointerPosX, pointerPosY, originalRect);
244 moveDragController->CalcMoveTargetRect(pointerEvent, originalRect);
245 ASSERT_EQ(0, res);
246 }
247
248 /**
249 * @tc.name: EventDownInit
250 * @tc.desc: test function : EventDownInit
251 * @tc.type: FUNC
252 */
253 HWTEST_F(MoveDragControllerTest, EventDownInit, Function | SmallTest | Level1)
254 {
255 sptr<WindowSessionProperty> property = new WindowSessionProperty();
256 SystemSessionConfig sysConfig;
257 moveDragController->InitMoveDragProperty();
258 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
259 WSRect originalRect = { 100, 100, 1000, 1000 };
260
261 pointerEvent = MMI::PointerEvent::Create();
262 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
263 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
264
265 auto res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
266 ASSERT_EQ(false, res);
267 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
268 pointerEvent->SetTargetDisplayId(0);
269 MMI::PointerEvent::PointerItem pointerItem;
270 pointerItem.SetPointerId(0);
271 originalRect = { 10, 10, 10, 10 };
272 pointerItem.SetWindowX(100000000);
273 pointerItem.SetWindowY(100000000);
274 pointerEvent->AddPointerItem(pointerItem);
275 res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
276 ASSERT_EQ(true, res);
277 }
278
279 /**
280 * @tc.name: EventDownInit01
281 * @tc.desc: test function : EventDownInit
282 * @tc.type: FUNC
283 */
284 HWTEST_F(MoveDragControllerTest, EventDownInit01, Function | SmallTest | Level1)
285 {
286 sptr<WindowSessionProperty> property = new WindowSessionProperty();
287 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
288 property->SetDecorEnable(true);
289
290 SystemSessionConfig sysConfig;
291 moveDragController->InitMoveDragProperty();
292 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
293 WSRect originalRect = { 100, 100, 1000, 1000 };
294 MMI::PointerEvent::PointerItem pointerItem;
295 pointerItem.SetPointerId(1);
296 pointerItem.SetWindowX(1);
297 pointerItem.SetWindowY(1);
298 pointerEvent->AddPointerItem(pointerItem);
299 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
300 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
301 auto res = moveDragController->EventDownInit(pointerEvent, originalRect, property, sysConfig);
302 ASSERT_EQ(true, res);
303 }
304
305 /**
306 * @tc.name: CalcFreeformTargetRect
307 * @tc.desc: test function : CalcFreeformTargetRect
308 * @tc.type: FUNC
309 */
310 HWTEST_F(MoveDragControllerTest, CalcFreeformTargetRect, Function | SmallTest | Level1)
311 {
312 AreaType type = AreaType::RIGHT;
313 WSRect originalRect = { 100, 100, 1000, 1000 };
314 int32_t tranX = 10;
315 int32_t tranY = 30;
316 ASSERT_TRUE((moveDragController != nullptr));
317 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
318 type = AreaType::LEFT;
319 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
320 type = AreaType::RIGHT;
321 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
322 type = AreaType::BOTTOM;
323 ASSERT_TRUE((moveDragController != nullptr));
324 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
325 originalRect = { 100, 100, 1000, 0 };
326 ASSERT_TRUE((moveDragController != nullptr));
327 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
328 originalRect = { 100, 100, 500, 100 };
329 moveDragController->limits_ = { 3, 3, 3, 3, 2.0, 2.0 };
330 ASSERT_TRUE((moveDragController != nullptr));
331 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
332 type = AreaType::RIGHT;
333 originalRect = { 100, 100, 500, 0 };
334 ASSERT_TRUE((moveDragController != nullptr));
335 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
336 originalRect = { 100, 100, 100, 100 };
337 ASSERT_TRUE((moveDragController != nullptr));
338 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
339 type = AreaType::UNDEFINED;
340 originalRect = { 100, 100, 500, 100 };
341 ASSERT_TRUE((moveDragController != nullptr));
342 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
343 type = AreaType::RIGHT;
344 ASSERT_TRUE((moveDragController != nullptr));
345 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
346 moveDragController->limits_ = { 3, 3, 3, 3, 0.0001, 0.0001 };
347 ASSERT_TRUE((moveDragController != nullptr));
348 moveDragController->CalcFreeformTargetRect(type, tranX, tranY, originalRect);
349 }
350
351 /**
352 * @tc.name: CalcFixedAspectRatioTargetRect01
353 * @tc.desc: test function : CalcFixedAspectRatioTargetRect01
354 * @tc.type: FUNC
355 */
356 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect01, Function | SmallTest | Level1)
357 {
358 AreaType type = AreaType::RIGHT;
359 float aspectRatio = 0.5;
360 WSRect originalRect = { 100, 100, 1000, 1000 };
361 int32_t tranX = 0;
362 int32_t tranY = 0;
363 ASSERT_TRUE((moveDragController != nullptr));
364 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
365 }
366
367 /**
368 * @tc.name: CalcFixedAspectRatioTargetRect02
369 * @tc.desc: test function : CalcFixedAspectRatioTargetRect02
370 * @tc.type: FUNC
371 */
372 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTargetRect02, Function | SmallTest | Level1)
373 {
374 AreaType type = AreaType::RIGHT;
375 float aspectRatio = 0.5;
376 WSRect originalRect = { 100, 100, 1000, 1000 };
377 int32_t tranX = 20;
378 int32_t tranY = 20;
379 ASSERT_TRUE((moveDragController != nullptr));
380 type = AreaType::UNDEFINED;
381 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::UNDEFINED;
382 tranX = 0;
383 tranY = 0;
384 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
385 type = AreaType::RIGHT;
386 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
387 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::X_AXIS;
388 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
389 type = AreaType::LEFT_TOP;
390 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
391 type = AreaType::RIGHT_TOP;
392 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
393 type = AreaType::RIGHT_BOTTOM;
394 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
395 type = AreaType::LEFT_BOTTOM;
396 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
397 type = AreaType::LEFT;
398 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
399 type = AreaType::TOP;
400 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
401 type = AreaType::RIGHT;
402 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
403 type = AreaType::BOTTOM;
404 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
405 type = AreaType::UNDEFINED;
406 moveDragController->CalcFixedAspectRatioTargetRect(type, tranX, tranY, aspectRatio, originalRect);
407 }
408
409 /**
410 * @tc.name: CalcFreeformTranslateLimits01
411 * @tc.desc: test function : CalcFreeformTranslateLimits01
412 * @tc.type: FUNC
413 */
414 HWTEST_F(MoveDragControllerTest, CalcFreeformTranslateLimits01, Function | SmallTest | Level1)
415 {
416 AreaType type = AreaType::RIGHT;
417 ASSERT_TRUE((moveDragController != nullptr));
418 moveDragController->CalcFreeformTranslateLimits(type);
419 type = AreaType::BOTTOM;
420 moveDragController->CalcFreeformTranslateLimits(type);
421 type = AreaType::TOP;
422 moveDragController->CalcFreeformTranslateLimits(type);
423 type = AreaType::LEFT;
424 moveDragController->CalcFreeformTranslateLimits(type);
425 }
426
427 /**
428 * @tc.name: CalcFixedAspectRatioTranslateLimits01
429 * @tc.desc: test function : CalcFixedAspectRatioTranslateLimits01
430 * @tc.type: FUNC
431 */
432 HWTEST_F(MoveDragControllerTest, CalcFixedAspectRatioTranslateLimits01, Function | SmallTest | Level1)
433 {
434 moveDragController->limits_ = { 30, 60, 30, 60, 2.0, 2.0 };
435 moveDragController->aspectRatio_ = 1.0f;
436 MoveDragController::AxisType axis = MoveDragController::AxisType::X_AXIS;
437 AreaType type = AreaType::RIGHT;
438 ASSERT_TRUE((moveDragController != nullptr));
439 moveDragController->isDecorEnable_ = true;
440 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
441 moveDragController->isDecorEnable_ = false;
442 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
443 moveDragController->limits_ = { 60, 60, 60, 60, 2.0, 2.0 };
444 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
445 type = AreaType::LEFT;
446 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
447 axis = MoveDragController::AxisType::Y_AXIS;
448 type = AreaType::BOTTOM;
449 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
450 axis = MoveDragController::AxisType::X_AXIS;
451 type = AreaType::TOP;
452 moveDragController->CalcFixedAspectRatioTranslateLimits(type, axis);
453 }
454
455 /**
456 * @tc.name: FixTranslateByLimits01
457 * @tc.desc: test function : FixTranslateByLimits01
458 * @tc.type: FUNC
459 */
460 HWTEST_F(MoveDragControllerTest, FixTranslateByLimits01, Function | SmallTest | Level1)
461 {
462 int32_t tranX = 100;
463 int32_t tranY = 100;
464 moveDragController->maxTranX_ = 50;
465 moveDragController->maxTranY_ = 50;
466 ASSERT_TRUE((moveDragController != nullptr));
467 moveDragController->FixTranslateByLimits(tranX, tranY);
468 tranX = 10;
469 moveDragController->FixTranslateByLimits(tranX, tranY);
470 tranY = 10;
471 moveDragController->FixTranslateByLimits(tranX, tranY);
472 }
473
474 /**
475 * @tc.name: InitMainAxis01
476 * @tc.desc: test function : InitMainAxis01
477 * @tc.type: FUNC
478 */
479 HWTEST_F(MoveDragControllerTest, InitMainAxis01, Function | SmallTest | Level1)
480 {
481 AreaType type = AreaType::LEFT;
482 int32_t tranX = 100;
483 int32_t tranY = 100;
484 ASSERT_TRUE((moveDragController != nullptr));
485 moveDragController->InitMainAxis(type, tranX, tranY);
486 type = AreaType::RIGHT;
487 moveDragController->InitMainAxis(type, tranX, tranY);
488 type = AreaType::TOP;
489 moveDragController->InitMainAxis(type, tranX, tranY);
490 type = AreaType::BOTTOM;
491 moveDragController->InitMainAxis(type, tranX, tranY);
492 type = AreaType::UNDEFINED;
493 tranX = 0;
494 tranY = 0;
495 moveDragController->InitMainAxis(type, tranX, tranY);
496 tranY = 1;
497 moveDragController->InitMainAxis(type, tranX, tranY);
498 }
499
500 /**
501 * @tc.name: ConvertXYByAspectRatio01
502 * @tc.desc: test function : ConvertXYByAspectRatio01
503 * @tc.type: FUNC
504 */
505 HWTEST_F(MoveDragControllerTest, ConvertXYByAspectRatio01, Function | SmallTest | Level1)
506 {
507 float aspectRatio = 1.0f;
508 int32_t tx = 100;
509 int32_t ty = 100;
510 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::X_AXIS;
511 ASSERT_TRUE((moveDragController != nullptr));
512 moveDragController->ConvertXYByAspectRatio(tx, ty, aspectRatio);
513 moveDragController->mainMoveAxis_ = MoveDragController::AxisType::Y_AXIS;
514 moveDragController->ConvertXYByAspectRatio(tx, ty, aspectRatio);
515 }
516
517 /**
518 * @tc.name: InitDecorValue01
519 * @tc.desc: test function : InitDecorValue01
520 * @tc.type: FUNC
521 */
522 HWTEST_F(MoveDragControllerTest, InitDecorValue01, Function | SmallTest | Level1)
523 {
524 sptr<WindowSessionProperty> property = new WindowSessionProperty();
525 SystemSessionConfig sysConfig;
526 ASSERT_TRUE((moveDragController != nullptr));
527 moveDragController->InitDecorValue(property, sysConfig);
528 }
529
530 /**
531 * @tc.name: ConsumeMoveEvent
532 * @tc.desc: test function : ConsumeMoveEvent
533 * @tc.type: FUNC
534 */
535 HWTEST_F(MoveDragControllerTest, ConsumeMoveEvent, Function | SmallTest | Level1)
536 {
537 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
538 if (!pointerEvent) {
539 return;
540 }
541 WSRect originalRect = { 100, 100, 1000, 1000 };
542 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(nullptr, originalRect));
543 auto preStratDragFlag = moveDragController->GetStartDragFlag();
544 moveDragController->isStartDrag_ = true;
545 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
546 moveDragController->isStartDrag_ = false;
547 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
548 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
549 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
550 pointerEvent->SetSourceType(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
551 moveDragController->SetStartMoveFlag(false);
552 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
553 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
554 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
555 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
556 moveDragController->SetStartMoveFlag(true);
557 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
558 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
559 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
560 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
561 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UNKNOWN);
562 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
563 moveDragController->moveDragProperty_.pointerId_ = -2;
564 moveDragController->moveDragProperty_.pointerType_ = -2;
565 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
566 ASSERT_EQ(false, moveDragController->ConsumeMoveEvent(pointerEvent, originalRect));
567 moveDragController->isStartDrag_ = preStratDragFlag;
568 }
569
570
571 /**
572 * @tc.name: ProcessWindowDragHotAreaFunc
573 * @tc.desc: test function : ProcessWindowDragHotAreaFunc
574 * @tc.type: FUNC
575 */
576 HWTEST_F(MoveDragControllerTest, ProcessWindowDragHotAreaFunc, Function | SmallTest | Level1)
577 {
578 bool isSendHotAreaMessage = true;
579 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
580 moveDragController->ProcessWindowDragHotAreaFunc(isSendHotAreaMessage, reason);
581 ASSERT_EQ(true, isSendHotAreaMessage);
__anon63e752480202(int32_t type, const SizeChangeReason& reason) 582 auto dragHotAreaFunc = [](int32_t type, const SizeChangeReason& reason) {
583 type = 0;
584 };
585 auto preFunc = moveDragController->windowDragHotAreaFunc_;
586 moveDragController->windowDragHotAreaFunc_ = dragHotAreaFunc;
587 moveDragController->ProcessWindowDragHotAreaFunc(isSendHotAreaMessage, reason);
588 ASSERT_EQ(true, isSendHotAreaMessage);
589 moveDragController->windowDragHotAreaFunc_ = preFunc;
590 }
591
592 /**
593 * @tc.name: ConsumeDragEvent
594 * @tc.desc: test function : ConsumeDragEvent
595 * @tc.type: FUNC
596 */
597 HWTEST_F(MoveDragControllerTest, ConsumeDragEvent, Function | SmallTest | Level1)
598 {
599 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
600 if (!pointerEvent) {
601 return;
602 }
603 WSRect originalRect = { 100, 100, 1000, 1000 };
604 sptr<WindowSessionProperty> property = new WindowSessionProperty();
605 if (!property) {
606 return;
607 }
608 SystemSessionConfig sysConfig;
609 moveDragController->GetVirtualPixelRatio();
610 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(nullptr, originalRect, property, sysConfig));
611 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, nullptr, sysConfig));
612 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
613 moveDragController->SetStartMoveFlag(true);
614 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
615 moveDragController->SetStartMoveFlag(false);
616 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
617 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
618 MMI::PointerEvent::PointerItem pointerItem;
619 pointerItem.SetPointerId(0);
620 pointerItem.SetWindowX(0);
621 pointerItem.SetWindowY(0);
622 pointerEvent->AddPointerItem(pointerItem);
623 pointerEvent->SetPointerId(0);
624 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
625 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
626 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
627 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
628 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
629 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_MOVE));
630 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
631 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
632 ASSERT_EQ(true, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
633 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UNKNOWN));
634 ASSERT_EQ(false, moveDragController->ConsumeDragEvent(pointerEvent, originalRect, property, sysConfig));
635 }
636
637
638 /**
639 * @tc.name: UpdateDragType01
640 * @tc.desc: test function : UpdateDragType
641 * @tc.type: FUNC
642 */
643 HWTEST_F(MoveDragControllerTest, UpdateDragType01, Function | SmallTest | Level1)
644 {
645 moveDragController->rectExceptCorner_.posX_ = 2;
646 moveDragController->rectExceptCorner_.width_ = 2;
647 moveDragController->rectExceptCorner_.posY_ = 0;
648 moveDragController->rectExceptCorner_.height_ = 0;
649 moveDragController->UpdateDragType(3, 3);
650 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_BOTTOM_OR_TOP);
651 }
652
653 /**
654 * @tc.name: UpdateDragType02
655 * @tc.desc: test function : UpdateDragType
656 * @tc.type: FUNC
657 */
658 HWTEST_F(MoveDragControllerTest, UpdateDragType02, Function | SmallTest | Level1)
659 {
660 moveDragController->rectExceptCorner_.posX_ = 0;
661 moveDragController->rectExceptCorner_.width_ = 0;
662 moveDragController->rectExceptCorner_.posY_ = 2;
663 moveDragController->rectExceptCorner_.height_ = 2;
664 moveDragController->UpdateDragType(3, 3);
665 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_LEFT_OR_RIGHT);
666 }
667
668 /**
669 * @tc.name: UpdateDragType03
670 * @tc.desc: test function : UpdateDragType
671 * @tc.type: FUNC
672 */
673 HWTEST_F(MoveDragControllerTest, UpdateDragType03, Function | SmallTest | Level1)
674 {
675 moveDragController->rectExceptCorner_.posX_ = 1;
676 moveDragController->rectExceptCorner_.width_ = 0;
677 moveDragController->rectExceptCorner_.posY_ = 1;
678 moveDragController->rectExceptCorner_.height_ = 0;
679 moveDragController->UpdateDragType(1, 1);
680 ASSERT_EQ(moveDragController->dragType_, MoveDragController::DragType::DRAG_LEFT_TOP_CORNER);
681 }
682
683 /**
684 * @tc.name: IsPointInDragHotZone01
685 * @tc.desc: test function : IsPointInDragHotZone
686 * @tc.type: FUNC
687 */
688 HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone01, Function | SmallTest | Level1)
689 {
690 WSRect winRect = { 10, 10, 10, 10 };
691 int32_t sourceType = MMI::PointerEvent::SOURCE_TYPE_MOUSE;
692 int32_t startPointPosX = 1;
693 int32_t startPointPosY = 1;
694 bool res = moveDragController->IsPointInDragHotZone(startPointPosX, startPointPosY, sourceType, winRect);
695 ASSERT_EQ(res, false);
696 }
697
698 /**
699 * @tc.name: IsPointInDragHotZone02
700 * @tc.desc: test function : IsPointInDragHotZone
701 * @tc.type: FUNC
702 */
703 HWTEST_F(MoveDragControllerTest, IsPointInDragHotZone02, Function | SmallTest | Level1)
704 {
705 WSRect winRect = { 5, 5, 0, 0 };
706 int32_t startPointPosX = 1;
707 int32_t startPointPosY = 1;
708 bool res = moveDragController->IsPointInDragHotZone(startPointPosX, startPointPosY, 0, winRect);
709 ASSERT_EQ(res, true);
710 }
711
712 /**
713 * @tc.name: CalculateStartRectExceptHotZone
714 * @tc.desc: test function : CalculateStartRectExceptHotZone
715 * @tc.type: FUNC
716 */
717 HWTEST_F(MoveDragControllerTest, CalculateStartRectExceptHotZone, Function | SmallTest | Level1)
718 {
719 float vpr = 1.0f;
720 WSRect winRect;
721 winRect.posX_ = 100;
722 winRect.posY_ = 100;
723 winRect.width_ = 100;
724 winRect.height_ = 100;
725 moveDragController->CalculateStartRectExceptHotZone(vpr, winRect);
726
727 EXPECT_EQ(moveDragController->rectExceptFrame_.posX_, 105);
728 EXPECT_EQ(moveDragController->rectExceptFrame_.posY_, 105);
729 EXPECT_EQ(moveDragController->rectExceptFrame_.width_, 90);
730 EXPECT_EQ(moveDragController->rectExceptFrame_.height_, 90);
731
732 EXPECT_EQ(moveDragController->rectExceptCorner_.posX_, 116);
733 EXPECT_EQ(moveDragController->rectExceptCorner_.posY_, 116);
734 EXPECT_EQ(moveDragController->rectExceptCorner_.width_, 68);
735 EXPECT_EQ(moveDragController->rectExceptCorner_.height_, 68);
736 }
737
738 /**
739 * @tc.name: CalcFirstMoveTargetRect
740 * @tc.desc: test function : CalcFirstMoveTargetRect
741 * @tc.type: FUNC
742 */
743 HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect, Function | SmallTest | Level1)
744 {
745 int res = 0;
746 WSRect windowRect = { 0, 0, 0, 0 };
747 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
748 res++;
749 moveDragController->moveTempProperty_.pointerId_ = 0;
750 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
751 ASSERT_EQ(res, 1);
752 auto preIsStartMove = moveDragController->GetStartMoveFlag();
753 auto preMoveTempProperty = moveDragController->moveTempProperty_;
754 moveDragController->isStartMove_ = false;
755 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
756 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
757 ASSERT_EQ(res, 1);
758 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
759 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
760 ASSERT_EQ(res, 1);
761 moveDragController->isStartMove_ = true;
762 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
763 ASSERT_EQ(res, 1);
764 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
765 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
766 ASSERT_EQ(res, 1);
767 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
768 moveDragController->CalcFirstMoveTargetRect(windowRect, false);
769 ASSERT_EQ(res, 1);
770 moveDragController->CalcFirstMoveTargetRect(windowRect, true);
771 ASSERT_EQ(res, 1);
772 moveDragController->isStartMove_ = preIsStartMove;
773 moveDragController->moveTempProperty_ = preMoveTempProperty;
774 }
775
776 /**
777 * @tc.name: CalcFirstMoveTargetRect001
778 * @tc.desc: test function : CalcFirstMoveTargetRect001
779 * @tc.type: FUNC
780 */
781 HWTEST_F(MoveDragControllerTest, CalcFirstMoveTargetRect001, Function | SmallTest | Level1)
782 {
783 WSRect windowRect = { 1, 2, 3, 4 };
784 moveDragController->InitMoveDragProperty();
785 moveDragController->SetStartMoveFlag(true);
786 moveDragController->CalcFirstMoveTargetRect(windowRect, true);
787 WSRect targetRect = moveDragController->GetTargetRect();
788 ASSERT_EQ(targetRect.posX_, 0);
789 }
790
791 /**
792 * @tc.name: GetFullScreenToFloatingRect
793 * @tc.desc: test function : GetFullScreenToFloatingRect
794 * @tc.type: FUNC
795 */
796 HWTEST_F(MoveDragControllerTest, GetFullScreenToFloatingRect, Function | SmallTest | Level1)
797 {
798 WSRect originalRect = { 1, 2, 0, 4 };
799 WSRect windowRect = { 5, 6, 7, 8 };
800 auto preMoveTempProperty = moveDragController->moveTempProperty_;
801 moveDragController->moveTempProperty_ = { -1, -1, -1, -1, -1, -1, -1, -1 };
802 WSRect rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
803 // move temporary property is empty
804 ASSERT_EQ(originalRect.posX_, rect.posX_);
805 moveDragController->moveTempProperty_ = { 1, 1, 1, 1, 1, 1, 1, 1 };
806 rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
807 // original rect witch is zero
808 ASSERT_EQ(windowRect.posX_, rect.posX_);
809 originalRect = { 1, 2, 3, 4 };
810 rect = moveDragController->GetFullScreenToFloatingRect(originalRect, windowRect);
811 WSRect targetRect = { 1, 2, 7, 8 };
812 ASSERT_EQ(targetRect.posX_, rect.posX_);
813 moveDragController->moveTempProperty_ = preMoveTempProperty;
814 }
815
816 /**
817 * @tc.name: CheckDragEventLegal
818 * @tc.desc: test function : CheckDragEventLegal
819 * @tc.type: FUNC
820 */
821 HWTEST_F(MoveDragControllerTest, CheckDragEventLegal, Function | SmallTest | Level1)
822 {
823 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
824 ASSERT_NE(pointerEvent, nullptr);
825 sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
826 ASSERT_NE(property, nullptr);
827 auto tempPointerEvent = pointerEvent;
828 pointerEvent = nullptr;
829 auto result = moveDragController->CheckDragEventLegal(pointerEvent, property);
830 ASSERT_EQ(result, false);
831 pointerEvent = tempPointerEvent;
832 result = moveDragController->CheckDragEventLegal(pointerEvent, nullptr);
833 ASSERT_EQ(result, false);
834 moveDragController->isStartMove_ = true;
835 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
836 ASSERT_EQ(result, false);
837 moveDragController->isStartMove_ = false;
838 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
839 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
840 ASSERT_EQ(result, false);
841 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
842 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
843 ASSERT_EQ(result, true);
844 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN));
845 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
846 ASSERT_EQ(result, true);
847 auto preMoveDragProperty = moveDragController->moveDragProperty_;
848 moveDragController->moveDragProperty_.pointerId_ = -1;
849 result = moveDragController->CheckDragEventLegal(pointerEvent, property);
850 ASSERT_EQ(result, true);
851 moveDragController->moveDragProperty_ = preMoveDragProperty;
852 }
853
854 /**
855 * @tc.name: UpdateMoveTempProperty
856 * @tc.desc: test function : UpdateMoveTempProperty
857 * @tc.type: FUNC
858 */
859 HWTEST_F(MoveDragControllerTest, UpdateMoveTempProperty, Function | SmallTest | Level1)
860 {
861 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
862 ASSERT_NE(pointerEvent, nullptr);
863 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
864 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
865 auto result = moveDragController->UpdateMoveTempProperty(pointerEvent);
866 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
867 MMI::PointerEvent::PointerItem pointerItem;
868 pointerItem.SetPointerId(0);
869 pointerEvent->AddPointerItem(pointerItem);
870 pointerEvent->SetPointerId(0);
871 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
872 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
873 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
874 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
875 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
876 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
877 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
878 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_LEFT);
879 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN));
880 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
881 ASSERT_EQ(result, WSError::WS_OK);
882 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_DOWN));
883 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
884 ASSERT_EQ(result, WSError::WS_OK);
885 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_MOVE));
886 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
887 ASSERT_EQ(result, WSError::WS_OK);
888 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UP));
889 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
890 ASSERT_EQ(result, WSError::WS_OK);
891 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP));
892 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
893 ASSERT_EQ(result, WSError::WS_OK);
894 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_CANCEL));
895 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
896 ASSERT_EQ(result, WSError::WS_OK);
897 pointerEvent->SetPointerAction(static_cast<int32_t>(MMI::PointerEvent::POINTER_ACTION_UNKNOWN));
898 result = moveDragController->UpdateMoveTempProperty(pointerEvent);
899 ASSERT_EQ(result, WSError::WS_OK);
900 }
901
902 /**
903 * @tc.name: UpdateHotAreaType
904 * @tc.desc: UpdateHotAreaType
905 * @tc.type: FUNC
906 */
907 HWTEST_F(MoveDragControllerTest, UpdateHotAreaType, Function | SmallTest | Level1)
908 {
909 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
910 ASSERT_NE(pointerEvent, nullptr);
911 moveDragController->UpdateHotAreaType(pointerEvent);
912 MMI::PointerEvent::PointerItem pointerItem;
913 pointerItem.SetPointerId(0);
914 pointerEvent->AddPointerItem(pointerItem);
915 pointerEvent->SetPointerId(0);
916 moveDragController->UpdateHotAreaType(pointerEvent);
917 auto preWindowDragHotAreaType = moveDragController->windowDragHotAreaType_;
918 moveDragController->windowDragHotAreaType_ = WINDOW_HOT_AREA_TYPE_UNDEFINED;
919 moveDragController->UpdateHotAreaType(pointerEvent);
920 moveDragController->windowDragHotAreaType_ = preWindowDragHotAreaType;
921 }
922
923 /**
924 * @tc.name: OnLostFocus
925 * @tc.desc: OnLostFocus
926 * @tc.type: FUNC
927 */
928 HWTEST_F(MoveDragControllerTest, OnLostFocus, Function | SmallTest | Level1)
929 {
930 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
931 ASSERT_NE(pointerEvent, nullptr);
932 moveDragController->isStartMove_ = true;
933 moveDragController->isStartDrag_ = false;
934 moveDragController->OnLostFocus();
935 moveDragController->isStartMove_ = false;
936 moveDragController->isStartDrag_ = true;
937 int windowHotAreaTypeOther = 1;
938 moveDragController->windowDragHotAreaType_ = windowHotAreaTypeOther;
939 moveDragController->OnLostFocus();
940 moveDragController->windowDragHotAreaType_ = WINDOW_HOT_AREA_TYPE_UNDEFINED;
941 moveDragController->OnLostFocus();
942 }
943
944 /**
945 * @tc.name: NotifyWindowInputPidChange
946 * @tc.desc: NotifyWindowInputPidChange
947 * @tc.type: FUNC
948 */
949 HWTEST_F(MoveDragControllerTest, NotifyWindowInputPidChange, Function | SmallTest | Level1)
950 {
951 bool isServerPid = true;
952 auto preCallback = moveDragController->pidChangeCallback_;
953 moveDragController->NotifyWindowInputPidChange(isServerPid);
954 isServerPid = false;
955 moveDragController->NotifyWindowInputPidChange(isServerPid);
956 moveDragController->SetNotifyWindowPidChangeCallback(nullptr);
957 ASSERT_EQ(moveDragController->pidChangeCallback_, nullptr);
958 isServerPid = true;
959 moveDragController->NotifyWindowInputPidChange(isServerPid);
960 isServerPid = false;
961 moveDragController->NotifyWindowInputPidChange(isServerPid);
962 moveDragController->SetNotifyWindowPidChangeCallback(preCallback);
963 }
964
965 /**
966 * @tc.name: HasPointDown
967 * @tc.desc: HasPointDown
968 * @tc.type: FUNC
969 */
970 HWTEST_F(MoveDragControllerTest, HasPointDown, Function | SmallTest | Level1)
971 {
972 bool preHasPointDown = moveDragController->hasPointDown_;
973 moveDragController->hasPointDown_ = true;
974 bool res = moveDragController->HasPointDown();
975 ASSERT_EQ(res, true);
976 moveDragController->hasPointDown_ = false;
977 res = moveDragController->HasPointDown();
978 ASSERT_EQ(res, false);
979 moveDragController->hasPointDown_ = preHasPointDown;
980 }
981
982 /**
983 * @tc.name: ProcessSessionRectChange
984 * @tc.desc: ProcessSessionRectChange
985 * @tc.type: FUNC
986 */
987 HWTEST_F(MoveDragControllerTest, ProcessSessionRectChange, Function | SmallTest | Level1)
988 {
989 int32_t res = 0;
990 auto preCallback = moveDragController->moveDragCallback_;
991 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
__anon63e752480302(const SizeChangeReason& reason) 992 MoveDragCallback callBack = [](const SizeChangeReason& reason) {
993 return;
994 };
995 moveDragController->moveDragCallback_ = callBack;
996 moveDragController->ProcessSessionRectChange(reason);
997 moveDragController->moveDragCallback_ = nullptr;
998 moveDragController->ProcessSessionRectChange(reason);
999 moveDragController->moveDragCallback_ = preCallback;
1000 ASSERT_EQ(0, res);
1001 }
1002
1003 /**
1004 * @tc.name: GetOriginalPointerPosX
1005 * @tc.desc: GetOriginalPointerPosX
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosX, Function | SmallTest | Level1)
1009 {
1010 int32_t posX = moveDragController->moveDragProperty_.originalPointerPosX_;
1011 int32_t res = moveDragController->GetOriginalPointerPosX();
1012 ASSERT_EQ(posX, res);
1013 }
1014
1015 /**
1016 * @tc.name: GetOriginalPointerPosY
1017 * @tc.desc: GetOriginalPointerPosY
1018 * @tc.type: FUNC
1019 */
1020 HWTEST_F(MoveDragControllerTest, GetOriginalPointerPosY, Function | SmallTest | Level1)
1021 {
1022 int32_t posY = moveDragController->moveDragProperty_.originalPointerPosY_;
1023 int32_t res = moveDragController->GetOriginalPointerPosY();
1024 ASSERT_EQ(posY, res);
1025 }
1026 }
1027 }
1028 }