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
103 int UtcDaliBaseHandleConstructorVoid(void)
105 TestApplication application;
106 tet_infoline("Testing Dali::BaseHandle::BaseHandle()");
110 DALI_TEST_CHECK(!object);
114 int UtcDaliBaseHandleCopyConstructor(void)
116 TestApplication application;
117 tet_infoline("Testing Dali::BaseHandle::BaseHandle(const BaseHandle&)");
119 // Initialize an object, ref count == 1
120 BaseHandle object = Actor::New();
122 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
124 // Copy the object, ref count == 2
125 BaseHandle copy(object);
126 DALI_TEST_CHECK(copy);
129 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
133 // Pass by value, and return another copy, ref count == 3
134 BaseHandle anotherCopy = ImplicitCopyConstructor(copy);
136 DALI_TEST_CHECK(anotherCopy);
139 DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
143 // anotherCopy out of scope, ref count == 2
144 DALI_TEST_CHECK(copy);
147 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
152 int UtcDaliBaseHandleAssignmentOperator(void)
154 TestApplication application;
155 tet_infoline("Testing Dali::BaseHandle::operator=");
157 BaseHandle object = Actor::New();
159 DALI_TEST_CHECK(object);
162 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
165 BaseHandle copy = object;
167 DALI_TEST_CHECK(copy);
170 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
175 int UtcDaliBaseHandleMoveConstructor(void)
177 TestApplication application;
179 // Initialize an object, ref count == 1
180 BaseHandle object = Actor::New();
182 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
184 // Move the object, ref count == 1
185 BaseHandle move = std::move(object);
186 DALI_TEST_CHECK(move);
188 // Check that object is moved (not copied, so ref count keeps the same)
191 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
193 DALI_TEST_CHECK(!object);
198 int UtcDaliBaseHandleMoveAssignment(void)
200 TestApplication application;
202 // Initialize an object, ref count == 1
203 BaseHandle object = Actor::New();
205 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
207 // Move the object, ref count == 1
209 move = std::move(object);
210 DALI_TEST_CHECK(move);
212 // Check that object is moved (not copied, so ref count keeps the same)
215 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
217 DALI_TEST_CHECK(!object);
222 int UtcDaliBaseHandleGetBaseObject(void)
224 TestApplication application;
225 tet_infoline("Testing Dali::BaseHandle::GetBaseObject()");
227 BaseHandle object = Actor::New();
229 BaseObject& handle = object.GetBaseObject();
231 DALI_TEST_EQUALS(1, handle.ReferenceCount(), TEST_LOCATION);
235 int UtcDaliBaseHandleReset(void)
237 TestApplication application;
238 tet_infoline("Testing Dali::BaseHandle::Reset()");
240 // Initialize an object, ref count == 1
241 BaseHandle object = Actor::New();
243 DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION);
247 DALI_TEST_CHECK(!object);
251 int UtcDaliBaseHandleEqualityOperator01(void)
253 TestApplication application;
254 tet_infoline("Positive Test Dali::BaseHandle::operator==");
256 BaseHandle object = Actor::New();
258 DALI_TEST_CHECK(object);
260 BaseHandle theSameBaseHandle = object;
262 DALI_TEST_CHECK(object == theSameBaseHandle);
266 int UtcDaliBaseHandleEqualityOperator02(void)
268 TestApplication application;
269 tet_infoline("Negative Test Dali::BaseHandle::operator==");
271 BaseHandle object = Actor::New();
273 DALI_TEST_CHECK(object);
275 BaseHandle aDifferentBaseHandle = Actor::New();
277 DALI_TEST_CHECK(!(object == aDifferentBaseHandle));
281 int UtcDaliBaseHandleInequalityOperator01(void)
283 TestApplication application;
284 tet_infoline("Positive Test Dali::BaseHandle::operator!=");
286 BaseHandle object = Actor::New();
288 DALI_TEST_CHECK(object);
290 BaseHandle aDifferentBaseHandle = Actor::New();
292 DALI_TEST_CHECK(object != aDifferentBaseHandle);
296 int UtcDaliBaseHandleInequalityOperator02(void)
298 TestApplication application;
299 tet_infoline("Negative Test Dali::BaseHandle::operator!=");
301 BaseHandle object = Actor::New();
303 DALI_TEST_CHECK(object);
305 BaseHandle theSameBaseHandle = object;
307 DALI_TEST_CHECK(!(object != theSameBaseHandle));
311 int UtcDaliBaseHandleStlVector(void)
313 TestApplication application;
314 tet_infoline("Testing Dali::BaseHandle compatibility with std::vector");
316 const int TargetVectorSize(5);
318 std::vector<Actor> myVector;
320 for(int i = 0; i < TargetVectorSize; ++i)
322 Actor actor = Actor::New();
324 std::stringstream stream;
325 stream << "Actor " << i + 1;
326 actor.SetProperty(Actor::Property::NAME, stream.str());
328 myVector.push_back(actor);
331 DALI_TEST_EQUALS(TargetVectorSize, static_cast<int>(myVector.size()), TEST_LOCATION);
333 DALI_TEST_CHECK(myVector[0].GetProperty<std::string>(Actor::Property::NAME) == "Actor 1");
334 DALI_TEST_CHECK(myVector[1].GetProperty<std::string>(Actor::Property::NAME) == "Actor 2");
335 DALI_TEST_CHECK(myVector[2].GetProperty<std::string>(Actor::Property::NAME) == "Actor 3");
336 DALI_TEST_CHECK(myVector[3].GetProperty<std::string>(Actor::Property::NAME) == "Actor 4");
337 DALI_TEST_CHECK(myVector[4].GetProperty<std::string>(Actor::Property::NAME) == "Actor 5");
341 int UtcDaliBaseHandleDoAction(void)
343 TestApplication application;
344 tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction");
346 Actor actor = Actor::New();
347 BaseHandle actorObject = actor;
349 DALI_TEST_CHECK(actorObject);
351 // Check that an invalid command is not performed
352 Property::Map attributes;
353 DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false);
355 // Check that the actor is visible
356 actor.SetProperty(Actor::Property::VISIBLE, true);
357 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
359 // Check the actor performed an action to hide itself
360 DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true);
362 // flush the queue and render once
363 application.SendNotification();
364 application.Render();
366 // Check that the actor is now invisible
367 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
369 // Check the actor performed an action to show itself
370 DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true);
372 // flush the queue and render once
373 application.SendNotification();
374 application.Render();
376 // Check that the actor is now visible
377 DALI_TEST_CHECK(actor.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
379 application.GetScene().Add(actor);
381 // Build an animation with initial duration of 1 second
382 float durationSeconds(1.0f);
383 Animation animation = Animation::New(durationSeconds);
384 BaseHandle animationObject = animation;
386 DALI_TEST_CHECK(animationObject);
388 // Check the current animation duration is 1 second
389 DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION);
391 Vector3 targetPosition(100.0f, 100.0f, 100.0f);
392 animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR);
394 // Set the new duration to be 2 seconds
395 float newDurationSeconds(2.0f);
396 Property::Value newDurationSecondsValue = Property::Value(newDurationSeconds);
397 attributes["duration"] = newDurationSecondsValue;
399 // Check the animation performed an action to play itself with the specified duration of 2 seconds
400 animationObject.DoAction("play", attributes);
402 bool signalReceived(false);
403 AnimationFinishCheck finishCheck(signalReceived);
404 // use the handle API to connect the signal
405 animation.ConnectSignal(&application, "finished", finishCheck);
406 // just for coverage connect to non-existant signal as well
407 animation.ConnectSignal(&application, "foo", finishCheck);
408 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
410 application.SendNotification();
411 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
412 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
415 animationObject.DoAction("pause", attributes);
416 application.SendNotification();
417 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/);
418 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
421 animationObject.DoAction("play", attributes);
422 application.SendNotification();
423 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/);
425 // We expect the animation to finish
426 application.SendNotification();
427 finishCheck.CheckSignalReceived();
428 DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), targetPosition, TEST_LOCATION);
431 signalReceived = false;
432 animationObject.DoAction("play", attributes);
433 DALI_TEST_EQUALS(animation.GetCurrentProgress(), 0.f, TEST_LOCATION);
434 application.SendNotification();
435 application.Render(static_cast<uint32_t>(newDurationSeconds * 500.0f) /* half of time */);
436 animationObject.DoAction("stop", attributes);
437 application.SendNotification();
438 application.Render(static_cast<uint32_t>(newDurationSeconds * 1000.0f) /* full time */);
439 DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION);
441 // Check the new animation duration is 2 seconds
442 DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION);
446 int UtcDaliBaseHandleConnectSignal(void)
448 TestApplication application;
449 tet_infoline("Testing Dali::BaseHandle::ConnectSignal");
451 gTouchCallBackCalled = false;
453 // get the root layer
454 Actor actor = Actor::New();
455 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
456 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
457 actor.SetProperty(Actor::Property::POSITION, Vector2(240, 400));
458 actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
460 application.GetScene().Add(actor);
462 DALI_TEST_CHECK(gTouchCallBackCalled == false);
464 // connect to its touch signal
465 actor.ConnectSignal(&application, "touched", TestCallback());
467 application.SendNotification();
468 application.Render(1000);
469 application.SendNotification();
470 application.Render(1000);
472 // simulate a touch event
473 Dali::Integration::Point point;
474 point.SetState(PointState::DOWN);
475 point.SetScreenPosition(Vector2(240, 400));
476 Dali::Integration::TouchEvent event;
477 event.AddPoint(point);
478 application.ProcessEvent(event);
480 application.SendNotification();
481 application.Render(1000);
482 application.SendNotification();
483 application.Render(1000);
485 DALI_TEST_CHECK(application.GetConnectionCount() > 0);
486 DALI_TEST_CHECK(gTouchCallBackCalled == true);
488 gTouchCallBackCalled = false;
489 application.DisconnectAll();
491 // simulate another touch event
492 application.ProcessEvent(event);
494 DALI_TEST_CHECK(gTouchCallBackCalled == false);
498 int UtcDaliBaseHandleGetTypeNameP(void)
500 TestApplication application;
501 tet_infoline("Testing Dali::BaseHandle::GetTypeName");
503 // get the root layer
504 Actor actor = Actor::New();
506 std::string typeName = actor.GetTypeName();
508 DALI_TEST_CHECK(typeName.size());
509 DALI_TEST_CHECK(typeName == std::string("Actor"));
513 int UtcDaliBaseHandleGetTypeNameN(void)
515 TestApplication application;
516 tet_infoline("Testing Dali::BaseObject::GetTypeName");
518 std::string typeName = object.GetTypeName();
520 DALI_TEST_CHECK(typeName.empty());
524 int UtcDaliBaseHandleGetTypeInfoP(void)
526 TestApplication application;
527 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
530 Actor actor = Actor::New();
532 bool ok = actor.GetTypeInfo(info);
537 int UtcDaliBaseHandleGetTypeInfoN(void)
539 TestApplication application;
540 tet_infoline("Testing Dali::BaseHandle::GetTypeInfo");
545 bool ok = object.GetTypeInfo(info);
546 DALI_TEST_CHECK(!ok);
550 int UtcDaliBaseHandleGetObjectPtr(void)
552 TestApplication application;
553 tet_infoline("Testing Dali::BaseHandle::GetObjectPtr");
555 // get the root layer
556 Actor actor = Actor::New();
558 Dali::RefObject* p = actor.GetObjectPtr();
560 DALI_TEST_CHECK(p != NULL);
564 int UtcDaliBaseHandleBooleanCast(void)
566 TestApplication application;
567 tet_infoline("Testing Dali::BaseHandle::operator bool");
569 // get the root layer
570 BaseHandle handle = Actor::New();
572 DALI_TEST_CHECK(static_cast<bool>(handle));
576 int UtcDaliBaseHandleCompareOperatorN(void)
578 TestApplication application;
579 BaseHandle handle1 = Actor::New();
580 BaseHandle handle2 = handle1;
582 DALI_TEST_CHECK((handle1 < handle2) == false);
587 int UtcDaliBaseHandleDoActionNegative(void)
589 TestApplication application;
590 Dali::BaseHandle instance;
594 Dali::Property::Map arg2;
595 instance.DoAction(arg1, arg2);
596 DALI_TEST_CHECK(false); // Should not get here
600 DALI_TEST_CHECK(true); // We expect an assert
605 int UtcDaliBaseHandleGetTypeInfoNegative(void)
607 TestApplication application;
608 Dali::BaseHandle instance;
612 instance.GetTypeInfo(arg1);
613 DALI_TEST_CHECK(false); // Should not get here
617 DALI_TEST_CHECK(true); // We expect an assert
622 int UtcDaliBaseHandleGetTypeNameNegative(void)
624 TestApplication application;
625 Dali::BaseHandle instance;
628 instance.GetTypeName();
629 DALI_TEST_CHECK(false); // Should not get here
633 DALI_TEST_CHECK(true); // We expect an assert