2 * Copyright (c) 2020 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.
18 #include <dali/integration-api/events/touch-event-integ.h>
19 #include <dali/public-api/dali-core.h>
24 #include "dali-test-suite-utils/dali-test-suite-utils.h"
28 void utc_base_handle_startup(void)
30 test_return_value = TET_UNDEF;
33 // Called after each test
34 void utc_base_handle_cleanup(void)
36 test_return_value = TET_PASS;
41 // Functor to test whether an animation finish signal is emitted
42 struct AnimationFinishCheck
44 AnimationFinishCheck(bool& signalReceived)
45 : mSignalReceived(signalReceived)
51 mSignalReceived = true;
56 mSignalReceived = false;
59 void CheckSignalReceived()
63 tet_printf("Expected Finish signal was not received\n");
72 bool& mSignalReceived; // owned by individual tests
75 BaseHandle ImplicitCopyConstructor(BaseHandle passedByValue)
77 // object + copy + passedByValue, ref count == 3
78 DALI_TEST_CHECK(passedByValue);
81 DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION);
87 static bool gTouchCallBackCalled;
93 gTouchCallBackCalled = true;
97 // Used for testing BaseObject::GetTypeName with an object that is not registered
98 class FakeObject : public BaseObject
101 // used for testing ThisIsSaferThanReturningVoidStar
102 class FakeHandle : public BaseHandle
107 return ThisIsSaferThanReturningVoidStar();
112 int UtcDaliBaseHandleConstructorVoid(void)
114 TestApplication application;
115 tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
119 DALI_TEST_CHECK(!object);
123 int UtcDaliBaseHandleCopyConstructor(void)
125 TestApplication application;
126 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
128 // Initialize an object, ref count == 1
129 BaseHandle object = Actor::New();
131 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
133 // Copy the object, ref count == 2
134 BaseHandle copy(object);
135 DALI_TEST_CHECK(copy);
138 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142 // Pass by value, and return another copy, ref count == 3
143 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
145 DALI_TEST_CHECK(anotherCopy);
148 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
152 // anotherCopy out of scope, ref count == 2
153 DALI_TEST_CHECK(copy);
156 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
161 int UtcDaliBaseHandleAssignmentOperator(void)
163 TestApplication application;
164 tet_infoline("Testing Dali::BaseHandle::operator=");
166 BaseHandle object = Actor::New();
168 DALI_TEST_CHECK(object);
171 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
174 BaseHandle copy = object;
176 DALI_TEST_CHECK(copy);
179 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
184 int UtcDaliBaseHandleMoveConstructor(void)
186 TestApplication application;
188 // Initialize an object, ref count == 1
189 BaseHandle object = Actor::New();
191 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
193 // Move the object, ref count == 1
194 BaseHandle move = std::move(object);
195 DALI_TEST_CHECK(move);
197 // Check that object is moved (not copied, so ref count keeps the same)
200 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
202 DALI_TEST_CHECK(!object);
207 int UtcDaliBaseHandleMoveAssignment(void)
209 TestApplication application;
211 // Initialize an object, ref count == 1
212 BaseHandle object = Actor::New();
214 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
216 // Move the object, ref count == 1
218 move = std::move(object);
219 DALI_TEST_CHECK(move);
221 // Check that object is moved (not copied, so ref count keeps the same)
224 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
226 DALI_TEST_CHECK(!object);
231 int UtcDaliBaseHandleGetBaseObject(void)
233 TestApplication application;
234 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
236 BaseHandle object = Actor::New();
238 BaseObject& handle = object.GetBaseObject();
240 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
244 int UtcDaliBaseHandleReset(void)
246 TestApplication application;
247 tet_infoline("Testing Dali::BaseHandle::Reset()");
249 // Initialize an object, ref count == 1
250 BaseHandle object = Actor::New();
252 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
256 DALI_TEST_CHECK(!object);
260 int UtcDaliBaseHandleEqualityOperator01(void)
262 TestApplication application;
263 tet_infoline("Positive Test Dali::BaseHandle::operator==");
265 BaseHandle object = Actor::New();
267 DALI_TEST_CHECK(object);
269 BaseHandle theSameBaseHandle = object;
271 DALI_TEST_CHECK(object == theSameBaseHandle);
275 int UtcDaliBaseHandleEqualityOperator02(void)
277 TestApplication application;
278 tet_infoline("Negative Test Dali::BaseHandle::operator==");
280 BaseHandle object = Actor::New();
282 DALI_TEST_CHECK(object);
284 BaseHandle aDifferentBaseHandle = Actor::New();
286 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
290 int UtcDaliBaseHandleInequalityOperator01(void)
292 TestApplication application;
293 tet_infoline("Positive Test Dali::BaseHandle::operator!=");
295 BaseHandle object = Actor::New();
297 DALI_TEST_CHECK(object);
299 BaseHandle aDifferentBaseHandle = Actor::New();
301 DALI_TEST_CHECK(object != aDifferentBaseHandle);
305 int UtcDaliBaseHandleInequalityOperator02(void)
307 TestApplication application;
308 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
310 BaseHandle object = Actor::New();
312 DALI_TEST_CHECK(object);
314 BaseHandle theSameBaseHandle = object;
316 DALI_TEST_CHECK(!(object != theSameBaseHandle));
320 int UtcDaliBaseHandleStlVector(void)
322 TestApplication application;
323 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
325 const int TargetVectorSize(5);
327 std::vector<Actor> myVector;
329 for(int i = 0; i < TargetVectorSize; ++i)
331 Actor actor = Actor::New();
333 std::stringstream stream;
334 stream << "Actor " << i + 1;
335 actor.SetProperty(Actor::Property::NAME, stream.str());
337 myVector.push_back(actor);
340 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
342 DALI_TEST_CHECK(myVector[0].GetProperty<std::string>(Actor::Property::NAME) == "Actor 1");
343 DALI_TEST_CHECK(myVector[1].GetProperty<std::string>(Actor::Property::NAME) == "Actor 2");
344 DALI_TEST_CHECK(myVector[2].GetProperty<std::string>(Actor::Property::NAME) == "Actor 3");
345 DALI_TEST_CHECK(myVector[3].GetProperty<std::string>(Actor::Property::NAME) == "Actor 4");
346 DALI_TEST_CHECK(myVector[4].GetProperty<std::string>(Actor::Property::NAME) == "Actor 5");
350 int UtcDaliBaseHandleDoAction(void)
352 TestApplication application;
353 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
355 Actor actor = Actor::New();
356 BaseHandle actorObject = actor;
358 DALI_TEST_CHECK(actorObject);
360 // Check that an invalid command is not performed
361 Property::Map attributes;
362 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
364 // Check that the actor is visible
365 actor.SetProperty(Actor::Property::VISIBLE, true);
366 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
368 // Check the actor performed an action to hide itself
369 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
371 // flush the queue and render once
372 application.SendNotification();
373 application.Render();
375 // Check that the actor is now invisible
376 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
378 // Check the actor performed an action to show itself
379 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
381 // flush the queue and render once
382 application.SendNotification();
383 application.Render();
385 // Check that the actor is now visible
386 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
388 application.GetScene().Add(actor);
390 // Build an animation with initial duration of 1 second
391 float durationSeconds(1.0f);
392 Animation animation = Animation::New(durationSeconds);
393 BaseHandle animationObject = animation;
395 DALI_TEST_CHECK(animationObject);
397 // Check the current animation duration is 1 second
398 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
400 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
401 animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
403 // Set the new duration to be 2 seconds
404 float newDurationSeconds(2.0f);
405 Property::Value newDurationSecondsValue = Property::Value(newDurationSeconds);
406 attributes["duration"] = newDurationSecondsValue;
408 // Check the animation performed an action to play itself with the specified duration of 2 seconds
409 animationObject.DoAction("play", attributes);
411 bool signalReceived(false);
412 AnimationFinishCheck finishCheck(signalReceived);
413 // use the handle API to connect the signal
414 animation.ConnectSignal(&application, "finished", finishCheck);
415 // just for coverage connect to non-existant signal as well
416 animation.ConnectSignal(&application, "foo", finishCheck);
417 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
419 application.SendNotification();
420 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
421 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
424 animationObject.DoAction("pause", attributes);
425 application.SendNotification();
426 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/);
427 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
430 animationObject.DoAction("play", attributes);
431 application.SendNotification();
432 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/);
434 // We expect the animation to finish
435 application.SendNotification();
436 finishCheck.CheckSignalReceived();
437 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), targetPosition, TEST_LOCATION);
440 signalReceived = false;
441 animationObject.DoAction("play", attributes);
442 DALI_TEST_EQUALS(animation.GetCurrentProgress(), 0.f, TEST_LOCATION);
443 application.SendNotification();
444 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
445 animationObject.DoAction("stop", attributes);
446 application.SendNotification();
447 application.Render(static_cast<uint32_t>(newDurationSeconds * 1000.0f) /* full time */);
448 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
450 // Check the new animation duration is 2 seconds
451 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
455 int UtcDaliBaseHandleConnectSignal(void)
457 TestApplication application;
458 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
460 gTouchCallBackCalled = false;
462 // get the root layer
463 Actor actor = Actor::New();
464 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
465 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
466 actor.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
467 actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
469 application.GetScene().Add(actor);
471 DALI_TEST_CHECK(gTouchCallBackCalled == false);
473 // connect to its touch signal
474 actor.ConnectSignal(&application, "touched", TestCallback());
476 application.SendNotification();
477 application.Render(1000);
478 application.SendNotification();
479 application.Render(1000);
481 // simulate a touch event
482 Dali::Integration::Point point;
483 point.SetState(PointState::DOWN);
484 point.SetScreenPosition(Vector2(240, 400));
485 Dali::Integration::TouchEvent event;
486 event.AddPoint(point);
487 application.ProcessEvent(event);
489 application.SendNotification();
490 application.Render(1000);
491 application.SendNotification();
492 application.Render(1000);
494 DALI_TEST_CHECK(application.GetConnectionCount() > 0);
495 DALI_TEST_CHECK(gTouchCallBackCalled == true);
497 gTouchCallBackCalled = false;
498 application.DisconnectAll();
500 // simulate another touch event
501 application.ProcessEvent(event);
503 DALI_TEST_CHECK(gTouchCallBackCalled == false);
507 int UtcDaliBaseHandleGetTypeNameP(void)
509 TestApplication application;
510 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
512 // get the root layer
513 Actor actor = Actor::New();
515 std::string typeName = actor.GetTypeName();
517 DALI_TEST_CHECK(typeName.size());
518 DALI_TEST_CHECK(typeName == std::string("Actor"));
522 int UtcDaliBaseHandleGetTypeNameN(void)
524 TestApplication application;
525 tet_infoline("Testing Dali::BaseObject::GetTypeName");
527 std::string typeName = object.GetTypeName();
529 DALI_TEST_CHECK(typeName.empty());
533 int UtcDaliBaseHandleGetTypeInfoP(void)
535 TestApplication application;
536 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
539 Actor actor = Actor::New();
541 bool ok = actor.GetTypeInfo(info);
546 int UtcDaliBaseHandleThisIsSaferThanReturningVoidStar(void)
548 TestApplication application;
549 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
552 tet_result(TET_PASS);
556 int UtcDaliBaseHandleGetTypeInfoN(void)
558 TestApplication application;
559 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
564 bool ok = object.GetTypeInfo(info);
565 DALI_TEST_CHECK(!ok);
569 int UtcDaliBaseHandleGetObjectPtr(void)
571 TestApplication application;
572 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
574 // get the root layer
575 Actor actor = Actor::New();
577 Dali::RefObject* p = actor.GetObjectPtr();
579 DALI_TEST_CHECK(p != NULL);
583 int UtcDaliBaseHandleBooleanCast(void)
585 TestApplication application;
586 tet_infoline("Testing Dali::BaseHandle::BooleanType");
588 // get the root layer
589 BaseHandle handle = Actor::New();
591 DALI_TEST_CHECK(static_cast<BaseHandle::BooleanType>(handle));
595 int UtcDaliBaseHandleCompareOperatorN(void)
597 TestApplication application;
598 BaseHandle handle1 = Actor::New();
599 BaseHandle handle2 = handle1;
601 DALI_TEST_CHECK((handle1 < handle2) == false);
606 int UtcDaliBaseHandleDoActionNegative(void)
608 TestApplication application;
609 Dali::BaseHandle instance;
613 Dali::Property::Map arg2;
614 instance.DoAction(arg1, arg2);
615 DALI_TEST_CHECK(false); // Should not get here
619 DALI_TEST_CHECK(true); // We expect an assert
624 int UtcDaliBaseHandleGetTypeInfoNegative(void)
626 TestApplication application;
627 Dali::BaseHandle instance;
631 instance.GetTypeInfo(arg1);
632 DALI_TEST_CHECK(false); // Should not get here
636 DALI_TEST_CHECK(true); // We expect an assert
641 int UtcDaliBaseHandleGetTypeNameNegative(void)
643 TestApplication application;
644 Dali::BaseHandle instance;
647 instance.GetTypeName();
648 DALI_TEST_CHECK(false); // Should not get here
652 DALI_TEST_CHECK(true); // We expect an assert