2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/devel-api/drag-drop-detector/drag-and-drop-detector.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
30 using namespace Dali::Toolkit;
32 void utc_dali_toolkit_drag_drop_detector_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_drag_drop_detector_cleanup(void)
39 test_return_value = TET_PASS;
44 const int RENDER_FRAME_INTERVAL = 16;
48 :functorCalled(false),
56 functorCalled = false;
62 Dali::Toolkit::DragAndDropDetector detector;
65 struct DragSignalFunctor
67 DragSignalFunctor(SignalData& data, bool returnValue = true)
69 returnValue(returnValue)
73 bool operator()(Control control, Dali::Toolkit::DragAndDropDetector detector)
75 signalData.functorCalled = true;
76 signalData.control = control;
77 signalData.detector = detector;
81 SignalData& signalData;
85 Integration::TouchEvent GenerateSingleTouch(TouchPoint::State state, const Vector2& screenPosition)
87 Integration::TouchEvent touchEvent;
88 Integration::Point point;
89 point.SetState(static_cast<PointState::Type>(state));
90 point.SetScreenPosition(screenPosition);
91 touchEvent.points.push_back(point);
95 Integration::PanGestureEvent GeneratePan(
97 Vector2 previousPosition,
98 Vector2 currentPosition,
99 unsigned long timeDelta,
100 unsigned int numberOfTouches = 1,
101 unsigned int time = 1u)
103 Integration::PanGestureEvent pan(state);
104 pan.previousPosition = previousPosition;
105 pan.currentPosition = currentPosition;
106 pan.timeDelta = timeDelta;
107 pan.numberOfTouches = numberOfTouches;
115 int UtcDaliDragAndDropDetectorConstructorN(void)
117 ToolkitTestApplication application;
119 Dali::Toolkit::DragAndDropDetector detector;
120 DALI_TEST_CHECK(!detector);
125 int UtcDaliDragAndDropDetectorConstructorP(void)
127 ToolkitTestApplication application;
129 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
130 DALI_TEST_CHECK(detector);
135 int UtcDaliDragAndDropDetectorAttachN(void)
137 ToolkitTestApplication application;
139 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
141 detector.Attach(control);
143 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
144 Control control1 = Control::New();
145 detector.Attach(control1);
146 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
147 detector.Attach(control1);
148 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
152 int UtcDaliDragAndDropDetectorAttachP(void)
154 ToolkitTestApplication application;
156 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
157 Control control = Control::New();
159 detector.Attach(control);
160 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
165 int UtcDaliDragAndDropDetectorDetachN(void)
167 ToolkitTestApplication application;
169 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
171 Control control2 = Control::New();
173 detector.Attach(control1);
174 detector.Attach(control2);
175 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
177 detector.Detach(control2);
178 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
180 detector.Detach(control1);
181 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
187 int UtcDaliDragAndDropDetectorDetachP(void)
189 ToolkitTestApplication application;
191 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
192 Control control1 = Control::New();
193 Control control2 = Control::New();
196 detector.Attach(control1);
197 detector.Attach(control2);
198 detector.Attach(control3);
200 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
202 detector.Detach(control3);
203 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
204 detector.Detach(control2);
205 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
207 detector.Detach(control1);
208 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
213 int UtcDaliDragAndDropDetectorDetachAllN(void)
215 ToolkitTestApplication application;
217 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
218 detector.DetachAll();
219 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
223 int UtcDaliDragAndDropDetectorDetachAllP(void)
225 ToolkitTestApplication application;
227 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
228 Control control1 = Control::New();
229 Control control2 = Control::New();
231 detector.Attach(control1);
232 detector.Attach(control2);
233 detector.DetachAll();
234 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
239 int UtcDaliDragAndDropDetectorGetAttachedControlCountP(void)
241 ToolkitTestApplication application;
243 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
244 Control control1 = Control::New();
245 Control control2 = Control::New();
247 detector.Attach(control1);
248 detector.Attach(control2);
249 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
254 int UtcDaliDragAndDropDetectorGetAttachedControlN(void)
256 ToolkitTestApplication application;
258 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
259 Control control1 = Control::New();
260 Control control2 = Control::New();
262 detector.Attach(control1);
264 Control control = detector.GetAttachedControl(1);
265 DALI_TEST_CHECK(!control);
270 int UtcDaliDragAndDropDetectorGetAttachedControlP(void)
272 ToolkitTestApplication application;
274 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
275 Control control1 = Control::New();
276 Control control2 = Control::New();
278 detector.Attach(control1);
279 detector.Attach(control2);
280 Control control = detector.GetAttachedControl(1);
281 DALI_TEST_CHECK(control);
282 DALI_TEST_EQUALS(control2, control, TEST_LOCATION);
287 int UtcDaliDragAndDropDetectorStartSignal(void)
289 TestApplication application;
291 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
292 Control control = Control::New();
293 control.SetSize(100.0f, 100.0f);
294 control.SetAnchorPoint(AnchorPoint::TOP_LEFT);
295 Stage::GetCurrent().Add(control);
296 detector.Attach(control);
298 application.SendNotification();
299 application.Render(RENDER_FRAME_INTERVAL);
301 DALI_TEST_CHECK(detector);
302 DALI_TEST_CHECK(control);
305 DragSignalFunctor functor(data);
306 detector.StartedSignal().Connect(&application, functor);
308 Vector2 screenCoordinates(10.0f, 10.0f);
309 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
311 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
312 DALI_TEST_EQUALS(control, data.control, TEST_LOCATION);
313 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
319 int UtcDaliDragAndDropDetectorEnteredSignal(void)
321 TestApplication application;
323 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
324 Control control1 = Control::New();
325 Control control2 = Control::New();
326 control1.SetSize(100.0f,100.0f);
327 control2.SetSize(100.0f, 100.0f);
328 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
329 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
330 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
331 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
332 control1.SetPosition(0.0f, 0.0f);
333 control2.SetPosition(0.0f, 100.0f);
335 Stage::GetCurrent().Add(control1);
336 Stage::GetCurrent().Add(control2);
338 detector.Attach(control1);
339 detector.Attach(control2);
341 application.SendNotification();
342 application.Render(RENDER_FRAME_INTERVAL);
345 DragSignalFunctor functor(data);
346 detector.EnteredSignal().Connect(&application, functor);
348 Vector2 screenCoordinates(10.0f, 10.0f);
349 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
351 screenCoordinates.x = 10.0f;
352 screenCoordinates.y = 110.0f;
353 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
355 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
356 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
364 int UtcDaliDragAndDropDetectorMovedSignal(void)
366 TestApplication application;
368 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
369 Control control1 = Control::New();
370 Control control2 = Control::New();
371 control1.SetSize(100.0f,100.0f);
372 control2.SetSize(100.0f, 100.0f);
373 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
374 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
375 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
376 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
377 control1.SetPosition(0.0f, 0.0f);
378 control2.SetPosition(0.0f, 100.0f);
380 Stage::GetCurrent().Add(control1);
381 Stage::GetCurrent().Add(control2);
383 detector.Attach(control1);
384 detector.Attach(control2);
386 application.SendNotification();
387 application.Render(RENDER_FRAME_INTERVAL);
390 DragSignalFunctor functor(data);
391 detector.MovedSignal().Connect(&application, functor);
393 Vector2 screenCoordinates(10.0f, 10.0f);
394 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
396 screenCoordinates.x = 10.0f;
397 screenCoordinates.y = 110.0f;
398 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
400 screenCoordinates.x = 10.0f;
401 screenCoordinates.y = 120.0f;
402 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
404 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
405 DALI_TEST_EQUALS(Vector2(10.0f, 120.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
406 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
413 int UtcDaliDragAndDropDetectorExitedSignal(void)
415 TestApplication application;
417 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
418 Control control1 = Control::New();
419 Control control2 = Control::New();
420 control1.SetSize(100.0f,100.0f);
421 control2.SetSize(100.0f, 100.0f);
422 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
423 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
424 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
425 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
426 control1.SetPosition(0.0f, 0.0f);
427 control2.SetPosition(0.0f, 100.0f);
429 control1.SetLeaveRequired(true);
430 control2.SetLeaveRequired(true);
432 Stage::GetCurrent().Add(control1);
433 Stage::GetCurrent().Add(control2);
435 detector.Attach(control1);
436 detector.Attach(control2);
438 application.SendNotification();
439 application.Render(RENDER_FRAME_INTERVAL);
442 DragSignalFunctor functor(data);
443 detector.ExitedSignal().Connect(&application, functor);
445 Vector2 screenCoordinates(10.0f, 10.0f);
446 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
448 screenCoordinates.x = 10.0f;
449 screenCoordinates.y = 110.0f;
450 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
452 screenCoordinates.x = 20.0f;
453 screenCoordinates.y = 20.0f;
454 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
455 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
463 int UtcDaliDragAndDropDetectorDroppedSignal(void)
465 TestApplication application;
467 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
468 Control control1 = Control::New();
469 Control control2 = Control::New();
470 control1.SetSize(100.0f,100.0f);
471 control2.SetSize(100.0f, 100.0f);
472 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
473 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
474 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
475 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
476 control1.SetPosition(0.0f, 0.0f);
477 control2.SetPosition(0.0f, 100.0f);
479 Stage::GetCurrent().Add(control1);
480 Stage::GetCurrent().Add(control2);
482 detector.Attach(control1);
483 detector.Attach(control2);
485 application.SendNotification();
486 application.Render(RENDER_FRAME_INTERVAL);
489 DragSignalFunctor functor(data);
490 detector.DroppedSignal().Connect(&application, functor);
492 Vector2 screenCoordinates(10.0f, 10.0f);
493 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
495 screenCoordinates.x = 10.0f;
496 screenCoordinates.y = 110.0f;
497 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
499 screenCoordinates.x = 10.0f;
500 screenCoordinates.y = 112.0f;
501 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
503 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
504 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
505 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
506 DALI_TEST_EQUALS(true, detector.GetContent().empty(), TEST_LOCATION);
513 int UtcDaliDragAndDropDetectorEndedSignal(void)
515 TestApplication application;
517 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
518 Control control1 = Control::New();
519 Control control2 = Control::New();
520 control1.SetSize(100.0f,100.0f);
521 control2.SetSize(100.0f, 100.0f);
522 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
523 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
524 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
525 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
526 control1.SetPosition(0.0f, 0.0f);
527 control2.SetPosition(0.0f, 100.0f);
529 Stage::GetCurrent().Add(control1);
530 Stage::GetCurrent().Add(control2);
532 application.SendNotification();
533 application.Render(RENDER_FRAME_INTERVAL);
535 detector.Attach(control1);
536 detector.Attach(control2);
539 DragSignalFunctor functor(data);
540 detector.EndedSignal().Connect(&application, functor);
542 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
543 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
545 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, Vector2(10.0f, 10.0f)));
547 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 10.0f), Vector2(120.0f, 12.0f), 10));
548 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(120.0f, 12.0f), Vector2(120.0f, 20.0f), 10));
550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551 DALI_TEST_EQUALS(control1, data.control, TEST_LOCATION);
557 int UtcDaliDragAndDropDetectorGetContent(void)
559 TestApplication application;
561 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
562 Control control1 = Control::New();
563 Control control2 = Control::New();
564 control1.SetName("control1");
565 control2.SetName("control2");
566 control1.SetSize(100.0f,100.0f);
567 control2.SetSize(100.0f, 100.0f);
568 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
569 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
570 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
571 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
572 control1.SetPosition(0.0f, 0.0f);
573 control2.SetPosition(0.0f, 100.0f);
575 Stage::GetCurrent().Add(control1);
576 Stage::GetCurrent().Add(control2);
578 detector.Attach(control1);
579 detector.Attach(control2);
581 application.SendNotification();
582 application.Render(RENDER_FRAME_INTERVAL);
585 DragSignalFunctor functor(data);
586 detector.DroppedSignal().Connect(&application, functor);
588 Vector2 screenCoordinates(10.0f, 10.0f);
589 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordinates));
591 screenCoordinates.x = 10.0f;
592 screenCoordinates.y = 110.0f;
593 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
595 screenCoordinates.x = 10.0f;
596 screenCoordinates.y = 112.0f;
597 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
601 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
602 DALI_TEST_EQUALS("control1", detector.GetContent(), TEST_LOCATION);