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 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
309 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
311 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
312 DALI_TEST_EQUALS(control, data.control, TEST_LOCATION);
313 DALI_TEST_EQUALS(Vector2(12.0f, 12.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 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
349 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
351 Vector2 screenCoordinates(10.0f, 110.0f);
352 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
354 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
355 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
363 int UtcDaliDragAndDropDetectorMovedSignal(void)
365 TestApplication application;
367 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
368 Control control1 = Control::New();
369 Control control2 = Control::New();
370 control1.SetSize(100.0f,100.0f);
371 control2.SetSize(100.0f, 100.0f);
372 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
373 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
374 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
375 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
376 control1.SetPosition(0.0f, 0.0f);
377 control2.SetPosition(0.0f, 100.0f);
379 Stage::GetCurrent().Add(control1);
380 Stage::GetCurrent().Add(control2);
382 detector.Attach(control1);
383 detector.Attach(control2);
385 application.SendNotification();
386 application.Render(RENDER_FRAME_INTERVAL);
389 DragSignalFunctor functor(data);
390 detector.MovedSignal().Connect(&application, functor);
392 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
393 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
395 Vector2 screenCoordinates(10.0f, 110.0f);
396 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
398 screenCoordinates.x = 10.0f;
399 screenCoordinates.y = 120.0f;
400 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
402 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
403 DALI_TEST_EQUALS(Vector2(10.0f, 120.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
404 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
411 int UtcDaliDragAndDropDetectorExitedSignal(void)
413 TestApplication application;
415 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
416 Control control1 = Control::New();
417 Control control2 = Control::New();
418 control1.SetSize(100.0f,100.0f);
419 control2.SetSize(100.0f, 100.0f);
420 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
421 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
422 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
423 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
424 control1.SetPosition(0.0f, 0.0f);
425 control2.SetPosition(0.0f, 100.0f);
427 control1.SetLeaveRequired(true);
428 control2.SetLeaveRequired(true);
430 Stage::GetCurrent().Add(control1);
431 Stage::GetCurrent().Add(control2);
433 detector.Attach(control1);
434 detector.Attach(control2);
436 application.SendNotification();
437 application.Render(RENDER_FRAME_INTERVAL);
440 DragSignalFunctor functor(data);
441 detector.ExitedSignal().Connect(&application, functor);
443 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
444 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
446 Vector2 screenCoordinates(10.0f, 110.0f);
447 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
449 screenCoordinates.x = 20.0f;
450 screenCoordinates.y = 20.0f;
451 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
452 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
453 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
460 int UtcDaliDragAndDropDetectorDroppedSignal(void)
462 TestApplication application;
464 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
465 Control control1 = Control::New();
466 Control control2 = Control::New();
467 control1.SetSize(100.0f,100.0f);
468 control2.SetSize(100.0f, 100.0f);
469 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
470 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
471 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
472 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
473 control1.SetPosition(0.0f, 0.0f);
474 control2.SetPosition(0.0f, 100.0f);
476 Stage::GetCurrent().Add(control1);
477 Stage::GetCurrent().Add(control2);
479 detector.Attach(control1);
480 detector.Attach(control2);
482 application.SendNotification();
483 application.Render(RENDER_FRAME_INTERVAL);
486 DragSignalFunctor functor(data);
487 detector.DroppedSignal().Connect(&application, functor);
489 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
490 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
492 Vector2 screenCoordinates(10.0f, 110.0f);
493 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
495 screenCoordinates.x = 10.0f;
496 screenCoordinates.y = 112.0f;
497 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
499 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
500 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
501 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
502 DALI_TEST_EQUALS(true, detector.GetContent().empty(), TEST_LOCATION);
509 int UtcDaliDragAndDropDetectorEndedSignal(void)
511 TestApplication application;
513 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
514 Control control1 = Control::New();
515 Control control2 = Control::New();
516 control1.SetSize(100.0f,100.0f);
517 control2.SetSize(100.0f, 100.0f);
518 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
519 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
520 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
521 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
522 control1.SetPosition(0.0f, 0.0f);
523 control2.SetPosition(0.0f, 100.0f);
525 Stage::GetCurrent().Add(control1);
526 Stage::GetCurrent().Add(control2);
528 application.SendNotification();
529 application.Render(RENDER_FRAME_INTERVAL);
531 detector.Attach(control1);
532 detector.Attach(control2);
535 DragSignalFunctor functor(data);
536 detector.EndedSignal().Connect(&application, functor);
538 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
539 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
541 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, Vector2(10.0f, 10.0f)));
543 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 10.0f), Vector2(120.0f, 12.0f), 10));
544 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(120.0f, 12.0f), Vector2(120.0f, 20.0f), 10));
546 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
547 DALI_TEST_EQUALS(control1, data.control, TEST_LOCATION);
553 int UtcDaliDragAndDropDetectorGetContent(void)
555 TestApplication application;
557 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
558 Control control1 = Control::New();
559 Control control2 = Control::New();
560 control1.SetName("control1");
561 control2.SetName("control2");
562 control1.SetSize(100.0f,100.0f);
563 control2.SetSize(100.0f, 100.0f);
564 control1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
565 control2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
566 control1.SetParentOrigin(ParentOrigin::TOP_LEFT);
567 control2.SetParentOrigin(ParentOrigin::TOP_LEFT);
568 control1.SetPosition(0.0f, 0.0f);
569 control2.SetPosition(0.0f, 100.0f);
571 Stage::GetCurrent().Add(control1);
572 Stage::GetCurrent().Add(control2);
574 detector.Attach(control1);
575 detector.Attach(control2);
577 application.SendNotification();
578 application.Render(RENDER_FRAME_INTERVAL);
581 DragSignalFunctor functor(data);
582 detector.DroppedSignal().Connect(&application, functor);
584 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
585 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 10.0f), Vector2(12.0f, 12.0f), 10));
587 Vector2 screenCoordinates(10.0f, 110.0f);
588 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
590 screenCoordinates.x = 10.0f;
591 screenCoordinates.y = 112.0f;
592 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
594 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
596 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
597 DALI_TEST_EQUALS("control1", detector.GetContent(), TEST_LOCATION);