2 * Copyright (c) 2019 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(TouchPoint::State 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);
167 int UtcDaliDragAndDropDetectorDetachP(void)
169 ToolkitTestApplication application;
171 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
172 Control control1 = Control::New();
173 Control control2 = Control::New();
176 detector.Attach(control1);
177 detector.Attach(control2);
178 detector.Attach(control3);
180 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
182 detector.Detach(control3);
183 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
184 detector.Detach(control2);
185 DALI_TEST_EQUALS(1, detector.GetAttachedControlCount(), TEST_LOCATION);
187 detector.Detach(control1);
188 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
193 int UtcDaliDragAndDropDetectorDetachAllN(void)
195 ToolkitTestApplication application;
197 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
198 detector.DetachAll();
199 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
203 int UtcDaliDragAndDropDetectorDetachAllP(void)
205 ToolkitTestApplication application;
207 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
208 Control control1 = Control::New();
209 Control control2 = Control::New();
211 detector.Attach(control1);
212 detector.Attach(control2);
213 detector.DetachAll();
214 DALI_TEST_EQUALS(0, detector.GetAttachedControlCount(), TEST_LOCATION);
219 int UtcDaliDragAndDropDetectorGetAttachedControlCountP(void)
221 ToolkitTestApplication application;
223 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
224 Control control1 = Control::New();
225 Control control2 = Control::New();
227 detector.Attach(control1);
228 detector.Attach(control2);
229 DALI_TEST_EQUALS(2, detector.GetAttachedControlCount(), TEST_LOCATION);
234 int UtcDaliDragAndDropDetectorGetAttachedControlN(void)
236 ToolkitTestApplication application;
238 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
239 Control control1 = Control::New();
240 Control control2 = Control::New();
242 detector.Attach(control1);
244 Control control = detector.GetAttachedControl(1);
245 DALI_TEST_CHECK(!control);
250 int UtcDaliDragAndDropDetectorGetAttachedControlP(void)
252 ToolkitTestApplication application;
254 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
255 Control control1 = Control::New();
256 Control control2 = Control::New();
258 detector.Attach(control1);
259 detector.Attach(control2);
260 Control control = detector.GetAttachedControl(1);
261 DALI_TEST_CHECK(control);
262 DALI_TEST_EQUALS(control2, control, TEST_LOCATION);
267 int UtcDaliDragAndDropDetectorStartSignal(void)
269 ToolkitTestApplication application;
271 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
272 Control control = Control::New();
273 control.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
274 control.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
275 Stage::GetCurrent().Add(control);
276 detector.Attach(control);
278 application.SendNotification();
279 application.Render(RENDER_FRAME_INTERVAL);
281 DALI_TEST_CHECK(detector);
282 DALI_TEST_CHECK(control);
285 DragSignalFunctor functor(data);
286 detector.StartedSignal().Connect(&application, functor);
288 TestGenerateMiniPan(application);
290 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
291 DALI_TEST_EQUALS(control, data.control, TEST_LOCATION);
292 DALI_TEST_EQUALS(Vector2(20.0f, 40.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
298 int UtcDaliDragAndDropDetectorEnteredSignal(void)
300 ToolkitTestApplication application;
302 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
303 Control control1 = Control::New();
304 Control control2 = Control::New();
305 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f,100.0f) );
306 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
307 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
308 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
309 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
310 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
311 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
312 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
314 Stage::GetCurrent().Add(control1);
315 Stage::GetCurrent().Add(control2);
317 detector.Attach(control1);
318 detector.Attach(control2);
320 application.SendNotification();
321 application.Render(RENDER_FRAME_INTERVAL);
324 DragSignalFunctor functor(data);
325 detector.EnteredSignal().Connect(&application, functor);
327 TestGenerateMiniPan(application);
329 Vector2 screenCoordinates(10.0f, 110.0f);
330 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
332 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
333 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
341 int UtcDaliDragAndDropDetectorMovedSignal(void)
343 ToolkitTestApplication application;
345 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
346 Control control1 = Control::New();
347 Control control2 = Control::New();
348 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f,100.0f) );
349 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
350 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
351 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
352 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
353 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
354 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
355 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
357 Stage::GetCurrent().Add(control1);
358 Stage::GetCurrent().Add(control2);
360 detector.Attach(control1);
361 detector.Attach(control2);
363 application.SendNotification();
364 application.Render(RENDER_FRAME_INTERVAL);
367 DragSignalFunctor functor(data);
368 detector.MovedSignal().Connect(&application, functor);
370 TestGenerateMiniPan(application);
372 Vector2 screenCoordinates(10.0f, 110.0f);
373 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
375 screenCoordinates.x = 10.0f;
376 screenCoordinates.y = 120.0f;
377 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
379 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
380 DALI_TEST_EQUALS(Vector2(10.0f, 120.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
381 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
388 int UtcDaliDragAndDropDetectorExitedSignal(void)
390 ToolkitTestApplication application;
392 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
393 Control control1 = Control::New();
394 Control control2 = Control::New();
395 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f,100.0f) );
396 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
397 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
398 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
399 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
400 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
401 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
402 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
404 control1.SetProperty( Actor::Property::LEAVE_REQUIRED,true);
405 control2.SetProperty( Actor::Property::LEAVE_REQUIRED,true);
407 Stage::GetCurrent().Add(control1);
408 Stage::GetCurrent().Add(control2);
410 detector.Attach(control1);
411 detector.Attach(control2);
413 application.SendNotification();
414 application.Render(RENDER_FRAME_INTERVAL);
417 DragSignalFunctor functor(data);
418 detector.ExitedSignal().Connect(&application, functor);
420 TestGenerateMiniPan(application);
422 Vector2 screenCoordinates(10.0f, 110.0f);
423 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
425 screenCoordinates.x = 20.0f;
426 screenCoordinates.y = 20.0f;
427 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
428 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
429 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
436 int UtcDaliDragAndDropDetectorDroppedSignal(void)
438 ToolkitTestApplication application;
440 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
441 Control control1 = Control::New();
442 Control control2 = Control::New();
443 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f,100.0f) );
444 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
445 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
446 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
447 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
448 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
449 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
450 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
452 Stage::GetCurrent().Add(control1);
453 Stage::GetCurrent().Add(control2);
455 detector.Attach(control1);
456 detector.Attach(control2);
458 application.SendNotification();
459 application.Render(RENDER_FRAME_INTERVAL);
462 DragSignalFunctor functor(data);
463 detector.DroppedSignal().Connect(&application, functor);
465 TestGenerateMiniPan(application);
467 Vector2 screenCoordinates(10.0f, 110.0f);
468 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
470 screenCoordinates.x = 10.0f;
471 screenCoordinates.y = 112.0f;
472 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
474 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
475 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
476 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
477 DALI_TEST_EQUALS(true, detector.GetContent().empty(), TEST_LOCATION);
484 int UtcDaliDragAndDropDetectorEndedSignal(void)
486 ToolkitTestApplication application;
488 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
489 Control control1 = Control::New();
490 Control control2 = Control::New();
491 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f,100.0f) );
492 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
493 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
494 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
495 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
496 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
497 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
498 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
500 Stage::GetCurrent().Add(control1);
501 Stage::GetCurrent().Add(control2);
503 application.SendNotification();
504 application.Render(RENDER_FRAME_INTERVAL);
506 detector.Attach(control1);
507 detector.Attach(control2);
510 DragSignalFunctor functor(data);
511 detector.EndedSignal().Connect(&application, functor);
513 TestGenerateMiniPan(application);
515 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, Vector2(10.0f, 10.0f)));
517 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
518 DALI_TEST_EQUALS(control1, data.control, TEST_LOCATION);
524 int UtcDaliDragAndDropDetectorGetContent(void)
526 ToolkitTestApplication application;
528 Dali::Toolkit::DragAndDropDetector detector = Dali::Toolkit::DragAndDropDetector::New();
529 Control control1 = Control::New();
530 Control control2 = Control::New();
531 control1.SetProperty( Dali::Actor::Property::NAME,"control1");
532 control2.SetProperty( Dali::Actor::Property::NAME,"control2");
533 control1.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
534 control2.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
535 control1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
536 control2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
537 control1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
538 control2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
539 control1.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 0.0f));
540 control2.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 100.0f));
542 Stage::GetCurrent().Add(control1);
543 Stage::GetCurrent().Add(control2);
545 detector.Attach(control1);
546 detector.Attach(control2);
548 application.SendNotification();
549 application.Render(RENDER_FRAME_INTERVAL);
552 DragSignalFunctor functor(data);
553 detector.DroppedSignal().Connect(&application, functor);
555 TestGenerateMiniPan(application);
557 Vector2 screenCoordinates(10.0f, 110.0f);
558 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Motion, screenCoordinates));
560 screenCoordinates.x = 10.0f;
561 screenCoordinates.y = 112.0f;
562 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Up, screenCoordinates));
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(control2, data.control, TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(10.0f, 112.0f), data.detector.GetCurrentScreenPosition(), TEST_LOCATION);
567 DALI_TEST_EQUALS("control1", detector.GetContent(), TEST_LOCATION);