2 * Copyright (c) 2022 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>
29 using namespace Dali::Toolkit;
31 void utc_dali_toolkit_drag_drop_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_drag_drop_detector_cleanup(void)
38 test_return_value = TET_PASS;
43 const int RENDER_FRAME_INTERVAL = 16;
47 : functorCalled(false),
55 functorCalled = false;
61 Dali::Toolkit::DragAndDropDetector detector;
64 struct DragSignalFunctor
66 DragSignalFunctor(SignalData& data, bool returnValue = true)
68 returnValue(returnValue)
72 bool operator()(Control control, Dali::Toolkit::DragAndDropDetector detector)
74 signalData.functorCalled = true;
75 signalData.control = control;
76 signalData.detector = detector;
80 SignalData& signalData;
84 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition)
86 Integration::TouchEvent touchEvent;
87 Integration::Point point;
88 point.SetState(static_cast<PointState::Type>(state));
89 point.SetScreenPosition(screenPosition);
90 touchEvent.points.push_back(point);
95 int UtcDaliDragAndDropDetectorConstructorN(void)
97 ToolkitTestApplication application;
99 Dali::Toolkit::DragAndDropDetector detector;
100 DALI_TEST_CHECK(!detector);
105 int UtcDaliDragAndDropDetectorConstructorP(void)
107 ToolkitTestApplication application;
109 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
110 DALI_TEST_CHECK(detector);
115 int UtcDaliDragAndDropDetectorAttachN(void)
117 ToolkitTestApplication application;
119 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
121 detector.Attach(control);
123 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
124 Control control1 = Control::New();
125 detector.Attach(control1);
126 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
127 detector.Attach(control1);
128 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
132 int UtcDaliDragAndDropDetectorAttachP(void)
134 ToolkitTestApplication application;
136 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
137 Control control = Control::New();
139 detector.Attach(control);
140 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
145 int UtcDaliDragAndDropDetectorDetachN(void)
147 ToolkitTestApplication application;
149 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
151 Control control2 = Control::New();
153 detector.Attach(control1);
154 detector.Attach(control2);
155 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
157 detector.Detach(control2);
158 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
160 detector.Detach(control1);
161 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
166 int UtcDaliDragAndDropDetectorDetachP(void)
168 ToolkitTestApplication application;
170 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
171 Control control1 = Control::New();
172 Control control2 = Control::New();
175 detector.Attach(control1);
176 detector.Attach(control2);
177 detector.Attach(control3);
179 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
181 detector.Detach(control3);
182 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
183 detector.Detach(control2);
184 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
186 detector.Detach(control1);
187 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
192 int UtcDaliDragAndDropDetectorDetachAllN(void)
194 ToolkitTestApplication application;
196 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
197 detector.DetachAll();
198 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
202 int UtcDaliDragAndDropDetectorDetachAllP(void)
204 ToolkitTestApplication application;
206 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
207 Control control1 = Control::New();
208 Control control2 = Control::New();
210 detector.Attach(control1);
211 detector.Attach(control2);
212 detector.DetachAll();
213 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
218 int UtcDaliDragAndDropDetectorGetAttachedControlCountP(void)
220 ToolkitTestApplication application;
222 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
223 Control control1 = Control::New();
224 Control control2 = Control::New();
226 detector.Attach(control1);
227 detector.Attach(control2);
228 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
233 int UtcDaliDragAndDropDetectorGetAttachedControlN(void)
235 ToolkitTestApplication application;
237 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
238 Control control1 = Control::New();
239 Control control2 = Control::New();
241 detector.Attach(control1);
243 Control control = detector.GetAttachedControl(1);
244 DALI_TEST_CHECK(!control);
249 int UtcDaliDragAndDropDetectorGetAttachedControlP(void)
251 ToolkitTestApplication application;
253 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
254 Control control1 = Control::New();
255 Control control2 = Control::New();
257 detector.Attach(control1);
258 detector.Attach(control2);
259 Control control = detector.GetAttachedControl(1);
260 DALI_TEST_CHECK(control);
261 DALI_TEST_EQUALS(control2, control, TEST_LOCATION);
266 int UtcDaliDragAndDropDetectorStartSignal(void)
268 ToolkitTestApplication application;
270 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
271 Control control = Control::New();
272 control.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
273 control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
274 application.GetScene().Add(control);
275 detector.Attach(control);
277 application.SendNotification();
278 application.Render(RENDER_FRAME_INTERVAL);
280 DALI_TEST_CHECK(detector);
281 DALI_TEST_CHECK(control);
284 DragSignalFunctor functor(data);
285 detector.StartedSignal().Connect(&application, functor);
287 TestGenerateMiniPan(application);
289 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
290 DALI_TEST_EQUALS(control, data.control, TEST_LOCATION);
291 DALI_TEST_EQUALS(Vector2(20.0f, 40.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
297 int UtcDaliDragAndDropDetectorEnteredSignal(void)
299 ToolkitTestApplication application;
301 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
302 Control control1 = Control::New();
303 Control control2 = Control::New();
304 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
305 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
306 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
307 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
308 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
309 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
310 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
311 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
313 application.GetScene().Add(control1);
314 application.GetScene().Add(control2);
316 detector.Attach(control1);
317 detector.Attach(control2);
319 application.SendNotification();
320 application.Render(RENDER_FRAME_INTERVAL);
323 DragSignalFunctor functor(data);
324 detector.EnteredSignal().Connect(&application, functor);
326 TestGenerateMiniPan(application);
328 Vector2 screenCoordinates(10.0f, 110.0f);
329 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
331 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
332 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
339 int UtcDaliDragAndDropDetectorMovedSignal(void)
341 ToolkitTestApplication application;
343 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
344 Control control1 = Control::New();
345 Control control2 = Control::New();
346 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
347 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
348 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
349 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
350 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
351 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
352 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
353 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
355 application.GetScene().Add(control1);
356 application.GetScene().Add(control2);
358 detector.Attach(control1);
359 detector.Attach(control2);
361 application.SendNotification();
362 application.Render(RENDER_FRAME_INTERVAL);
365 DragSignalFunctor functor(data);
366 detector.MovedSignal().Connect(&application, functor);
368 TestGenerateMiniPan(application);
370 Vector2 screenCoordinates(10.0f, 110.0f);
371 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
373 screenCoordinates.x = 10.0f;
374 screenCoordinates.y = 120.0f;
375 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
377 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
378 DALI_TEST_EQUALS(Vector2(10.0f, 120.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
379 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
386 int UtcDaliDragAndDropDetectorExitedSignal(void)
388 ToolkitTestApplication application;
390 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
391 Control control1 = Control::New();
392 Control control2 = Control::New();
393 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
394 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
395 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
396 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
397 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
398 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
399 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
400 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
402 control1.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
403 control2.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
405 application.GetScene().Add(control1);
406 application.GetScene().Add(control2);
408 detector.Attach(control1);
409 detector.Attach(control2);
411 application.SendNotification();
412 application.Render(RENDER_FRAME_INTERVAL);
415 DragSignalFunctor functor(data);
416 detector.ExitedSignal().Connect(&application, functor);
418 TestGenerateMiniPan(application);
420 Vector2 screenCoordinates(10.0f, 110.0f);
421 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
423 screenCoordinates.x = 20.0f;
424 screenCoordinates.y = 20.0f;
425 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
426 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
427 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
434 int UtcDaliDragAndDropDetectorDroppedSignal(void)
436 ToolkitTestApplication application;
438 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
439 Control control1 = Control::New();
440 Control control2 = Control::New();
441 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
442 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
443 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
444 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
445 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
446 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
447 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
448 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
450 application.GetScene().Add(control1);
451 application.GetScene().Add(control2);
453 detector.Attach(control1);
454 detector.Attach(control2);
456 application.SendNotification();
457 application.Render(RENDER_FRAME_INTERVAL);
460 DragSignalFunctor functor(data);
461 detector.DroppedSignal().Connect(&application, functor);
463 TestGenerateMiniPan(application);
465 Vector2 screenCoordinates(10.0f, 110.0f);
466 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
468 screenCoordinates.x = 10.0f;
469 screenCoordinates.y = 112.0f;
470 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
472 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
473 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
474 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
475 DALI_TEST_EQUALS(true, detector.GetContent().empty(), TEST_LOCATION);
482 int UtcDaliDragAndDropDetectorEndedSignal(void)
484 ToolkitTestApplication application;
486 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
487 Control control1 = Control::New();
488 Control control2 = Control::New();
489 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
490 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
491 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
492 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
493 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
494 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
495 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
496 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
498 application.GetScene().Add(control1);
499 application.GetScene().Add(control2);
501 application.SendNotification();
502 application.Render(RENDER_FRAME_INTERVAL);
504 detector.Attach(control1);
505 detector.Attach(control2);
508 DragSignalFunctor functor(data);
509 detector.EndedSignal().Connect(&application, functor);
511 TestGenerateMiniPan(application);
513 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
515 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
516 DALI_TEST_EQUALS(control1, data.control, TEST_LOCATION);
522 int UtcDaliDragAndDropDetectorGetContent(void)
524 ToolkitTestApplication application;
526 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
527 Control control1 = Control::New();
528 Control control2 = Control::New();
529 control1.SetProperty(Dali::Actor::Property::NAME, "control1");
530 control2.SetProperty(Dali::Actor::Property::NAME, "control2");
531 control1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
532 control2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
533 control1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
534 control2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
535 control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
536 control2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
537 control1.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
538 control2.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 100.0f));
540 application.GetScene().Add(control1);
541 application.GetScene().Add(control2);
543 detector.Attach(control1);
544 detector.Attach(control2);
546 application.SendNotification();
547 application.Render(RENDER_FRAME_INTERVAL);
550 DragSignalFunctor functor(data);
551 detector.DroppedSignal().Connect(&application, functor);
553 TestGenerateMiniPan(application);
555 Vector2 screenCoordinates(10.0f, 110.0f);
556 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
558 screenCoordinates.x = 10.0f;
559 screenCoordinates.y = 112.0f;
560 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
562 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
564 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
565 DALI_TEST_EQUALS("control1", detector.GetContent(), TEST_LOCATION);