X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-BaseHandle.cpp;h=5b2061b92afa981181a4851a35637f2115146707;hb=d74980db456b3203610275b126efc63778c41c30;hp=626fb3741707415f028709fd6012ef5e2b98ef1c;hpb=0a5fc48f2c929d1ee2202664d626d1e4909bf55a;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-BaseHandle.cpp b/automated-tests/src/dali/utc-Dali-BaseHandle.cpp index 626fb37..5b2061b 100644 --- a/automated-tests/src/dali/utc-Dali-BaseHandle.cpp +++ b/automated-tests/src/dali/utc-Dali-BaseHandle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,16 @@ * */ -#include - -#include -#include #include +#include +#include + +#include #include "dali-test-suite-utils/dali-test-suite-utils.h" using namespace Dali; - void utc_base_handle_startup(void) { test_return_value = TET_UNDEF; @@ -39,7 +38,6 @@ void utc_base_handle_cleanup(void) namespace { - // Functor to test whether an animation finish signal is emitted struct AnimationFinishCheck { @@ -48,7 +46,7 @@ struct AnimationFinishCheck { } - void operator()(Animation& animation) + void operator()() { mSignalReceived = true; } @@ -60,7 +58,7 @@ struct AnimationFinishCheck void CheckSignalReceived() { - if (!mSignalReceived) + if(!mSignalReceived) { tet_printf("Expected Finish signal was not received\n"); tet_result(TET_FAIL); @@ -78,7 +76,7 @@ BaseHandle ImplicitCopyConstructor(BaseHandle passedByValue) { // object + copy + passedByValue, ref count == 3 DALI_TEST_CHECK(passedByValue); - if (passedByValue) + if(passedByValue) { DALI_TEST_EQUALS(3, passedByValue.GetBaseObject().ReferenceCount(), TEST_LOCATION); } @@ -96,7 +94,11 @@ struct TestCallback } }; -} // anon namespace +// Used for testing BaseObject::GetTypeName with an object that is not registered +class FakeObject : public BaseObject +{ +}; +} // namespace int UtcDaliBaseHandleConstructorVoid(void) { @@ -109,7 +111,6 @@ int UtcDaliBaseHandleConstructorVoid(void) END_TEST; } - int UtcDaliBaseHandleCopyConstructor(void) { TestApplication application; @@ -123,7 +124,7 @@ int UtcDaliBaseHandleCopyConstructor(void) // Copy the object, ref count == 2 BaseHandle copy(object); DALI_TEST_CHECK(copy); - if (copy) + if(copy) { DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION); } @@ -133,7 +134,7 @@ int UtcDaliBaseHandleCopyConstructor(void) BaseHandle anotherCopy = ImplicitCopyConstructor(copy); DALI_TEST_CHECK(anotherCopy); - if (anotherCopy) + if(anotherCopy) { DALI_TEST_EQUALS(3, anotherCopy.GetBaseObject().ReferenceCount(), TEST_LOCATION); } @@ -141,7 +142,7 @@ int UtcDaliBaseHandleCopyConstructor(void) // anotherCopy out of scope, ref count == 2 DALI_TEST_CHECK(copy); - if (copy) + if(copy) { DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION); } @@ -156,7 +157,7 @@ int UtcDaliBaseHandleAssignmentOperator(void) BaseHandle object = Actor::New(); DALI_TEST_CHECK(object); - if (object) + if(object) { DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION); } @@ -164,13 +165,60 @@ int UtcDaliBaseHandleAssignmentOperator(void) BaseHandle copy = object; DALI_TEST_CHECK(copy); - if (copy) + if(copy) { DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION); } END_TEST; } +int UtcDaliBaseHandleMoveConstructor(void) +{ + TestApplication application; + + // Initialize an object, ref count == 1 + BaseHandle object = Actor::New(); + + DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION); + + // Move the object, ref count == 1 + BaseHandle move = std::move(object); + DALI_TEST_CHECK(move); + + // Check that object is moved (not copied, so ref count keeps the same) + if(move) + { + DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION); + } + DALI_TEST_CHECK(!object); + + END_TEST; +} + +int UtcDaliBaseHandleMoveAssignment(void) +{ + TestApplication application; + + // Initialize an object, ref count == 1 + BaseHandle object = Actor::New(); + + DALI_TEST_EQUALS(1, object.GetBaseObject().ReferenceCount(), TEST_LOCATION); + + // Move the object, ref count == 1 + BaseHandle move; + move = std::move(object); + DALI_TEST_CHECK(move); + + // Check that object is moved (not copied, so ref count keeps the same) + if(move) + { + DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION); + } + DALI_TEST_CHECK(!object); + + END_TEST; +} + int UtcDaliBaseHandleGetBaseObject(void) { TestApplication application; @@ -260,6 +308,30 @@ int UtcDaliBaseHandleInequalityOperator02(void) END_TEST; } +int UtcDaliBaseHandleInequalityWithNullptr(void) +{ + TestApplication application; + tet_infoline("Test for Dali::BaseHandle::operator == nullptr"); + + BaseHandle object; + + // object is nullptr. + DALI_TEST_CHECK(object == nullptr); + DALI_TEST_CHECK(nullptr == object); + DALI_TEST_CHECK(!(object != nullptr)); + DALI_TEST_CHECK(!(nullptr != object)); + + object = Actor::New(); + + // object is not nullptr. + DALI_TEST_CHECK(!(object == nullptr)); + DALI_TEST_CHECK(!(nullptr == object)); + DALI_TEST_CHECK(object != nullptr); + DALI_TEST_CHECK(nullptr != object); + + END_TEST; +} + int UtcDaliBaseHandleStlVector(void) { TestApplication application; @@ -269,24 +341,24 @@ int UtcDaliBaseHandleStlVector(void) std::vector myVector; - for (int i=0; i(myVector.size()), TEST_LOCATION); - DALI_TEST_CHECK(myVector[0].GetName() == "Actor 1"); - DALI_TEST_CHECK(myVector[1].GetName() == "Actor 2"); - DALI_TEST_CHECK(myVector[2].GetName() == "Actor 3"); - DALI_TEST_CHECK(myVector[3].GetName() == "Actor 4"); - DALI_TEST_CHECK(myVector[4].GetName() == "Actor 5"); + DALI_TEST_CHECK(myVector[0].GetProperty(Actor::Property::NAME) == "Actor 1"); + DALI_TEST_CHECK(myVector[1].GetProperty(Actor::Property::NAME) == "Actor 2"); + DALI_TEST_CHECK(myVector[2].GetProperty(Actor::Property::NAME) == "Actor 3"); + DALI_TEST_CHECK(myVector[3].GetProperty(Actor::Property::NAME) == "Actor 4"); + DALI_TEST_CHECK(myVector[4].GetProperty(Actor::Property::NAME) == "Actor 5"); END_TEST; } @@ -295,18 +367,18 @@ int UtcDaliBaseHandleDoAction(void) TestApplication application; tet_infoline("Positive Test Dali::BaseHandle::UtcDaliBaseHandleDoAction"); - Actor actor = Actor::New(); + Actor actor = Actor::New(); BaseHandle actorObject = actor; DALI_TEST_CHECK(actorObject); // Check that an invalid command is not performed - std::vector attributes; + Property::Map attributes; DALI_TEST_CHECK(actorObject.DoAction("invalidCommand", attributes) == false); // Check that the actor is visible - actor.SetVisible(true); - DALI_TEST_CHECK(actor.IsVisible() == true); + actor.SetProperty(Actor::Property::VISIBLE, true); + DALI_TEST_CHECK(actor.GetCurrentProperty(Actor::Property::VISIBLE) == true); // Check the actor performed an action to hide itself DALI_TEST_CHECK(actorObject.DoAction("hide", attributes) == true); @@ -316,7 +388,7 @@ int UtcDaliBaseHandleDoAction(void) application.Render(); // Check that the actor is now invisible - DALI_TEST_CHECK(actor.IsVisible() == false); + DALI_TEST_CHECK(actor.GetCurrentProperty(Actor::Property::VISIBLE) == false); // Check the actor performed an action to show itself DALI_TEST_CHECK(actorObject.DoAction("show", attributes) == true); @@ -326,13 +398,13 @@ int UtcDaliBaseHandleDoAction(void) application.Render(); // Check that the actor is now visible - DALI_TEST_CHECK(actor.IsVisible() == true); + DALI_TEST_CHECK(actor.GetCurrentProperty(Actor::Property::VISIBLE) == true); - Stage::GetCurrent().Add(actor); + application.GetScene().Add(actor); // Build an animation with initial duration of 1 second - float durationSeconds(1.0f); - Animation animation = Animation::New(durationSeconds); + float durationSeconds(1.0f); + Animation animation = Animation::New(durationSeconds); BaseHandle animationObject = animation; DALI_TEST_CHECK(animationObject); @@ -341,34 +413,60 @@ int UtcDaliBaseHandleDoAction(void) DALI_TEST_EQUALS(animation.GetDuration(), durationSeconds, TEST_LOCATION); Vector3 targetPosition(100.0f, 100.0f, 100.0f); - animation.MoveTo(actor, targetPosition, AlphaFunctions::Linear); + animation.AnimateTo(Property(actor, Actor::Property::POSITION), targetPosition, AlphaFunction::LINEAR); // Set the new duration to be 2 seconds - float newDurationSeconds(2.0f); - Property::Value newDurationSecondsValue = Property::Value( newDurationSeconds ); - attributes.push_back(newDurationSecondsValue); + float newDurationSeconds(2.0f); + Property::Value newDurationSecondsValue = Property::Value(newDurationSeconds); + attributes["duration"] = newDurationSecondsValue; // Check the animation performed an action to play itself with the specified duration of 2 seconds animationObject.DoAction("play", attributes); - bool signalReceived(false); + bool signalReceived(false); AnimationFinishCheck finishCheck(signalReceived); - animation.FinishedSignal().Connect(&application, finishCheck); + // use the handle API to connect the signal + animation.ConnectSignal(&application, "finished", finishCheck); + // just for coverage connect to non-existant signal as well + animation.ConnectSignal(&application, "foo", finishCheck); + DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION); + + application.SendNotification(); + application.Render(static_cast(newDurationSeconds * 500.0f) /* half of time */); + DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION); + // pause + animationObject.DoAction("pause", attributes); application.SendNotification(); - application.Render(static_cast(newDurationSeconds * 1000.0f) + 1u/*just beyond the animation duration*/); + application.Render(static_cast(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/); + DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION); + + // continue + animationObject.DoAction("play", attributes); + application.SendNotification(); + application.Render(static_cast(newDurationSeconds * 500.0f) + 1u /*just beyond the animation duration*/); // We expect the animation to finish application.SendNotification(); finishCheck.CheckSignalReceived(); - DALI_TEST_EQUALS( actor.GetCurrentPosition(), targetPosition, TEST_LOCATION ); + DALI_TEST_EQUALS(actor.GetCurrentProperty(Actor::Property::POSITION), targetPosition, TEST_LOCATION); + + // play again + signalReceived = false; + animationObject.DoAction("play", attributes); + DALI_TEST_EQUALS(animation.GetCurrentProgress(), 0.f, TEST_LOCATION); + application.SendNotification(); + application.Render(static_cast(newDurationSeconds * 500.0f) /* half of time */); + animationObject.DoAction("stop", attributes); + application.SendNotification(); + application.Render(static_cast(newDurationSeconds * 1000.0f) /* full time */); + DALI_TEST_EQUALS(signalReceived, false, TEST_LOCATION); // Check the new animation duration is 2 seconds DALI_TEST_EQUALS(animation.GetDuration(), newDurationSeconds, TEST_LOCATION); END_TEST; } - int UtcDaliBaseHandleConnectSignal(void) { TestApplication application; @@ -378,17 +476,17 @@ int UtcDaliBaseHandleConnectSignal(void) // get the root layer Actor actor = Actor::New(); - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actor.SetPosition( 240, 400 ); - actor.SetSize( 100, 100 ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + actor.SetProperty(Actor::Property::POSITION, Vector2(240, 400)); + actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add(actor); - DALI_TEST_CHECK( gTouchCallBackCalled == false ); + DALI_TEST_CHECK(gTouchCallBackCalled == false); // connect to its touch signal - actor.ConnectSignal( &application, "touched", TestCallback() ); + actor.ConnectSignal(&application, "touched", TestCallback()); application.SendNotification(); application.Render(1000); @@ -396,30 +494,32 @@ int UtcDaliBaseHandleConnectSignal(void) application.Render(1000); // simulate a touch event - Dali::TouchPoint point( 0, TouchPoint::Down, 240, 400 ); + Dali::Integration::Point point; + point.SetState(PointState::DOWN); + point.SetScreenPosition(Vector2(240, 400)); Dali::Integration::TouchEvent event; - event.AddPoint( point ); - application.ProcessEvent( event ); + event.AddPoint(point); + application.ProcessEvent(event); application.SendNotification(); application.Render(1000); application.SendNotification(); application.Render(1000); - DALI_TEST_CHECK( application.GetConnectionCount() > 0 ); - DALI_TEST_CHECK( gTouchCallBackCalled == true ); + DALI_TEST_CHECK(application.GetConnectionCount() > 0); + DALI_TEST_CHECK(gTouchCallBackCalled == true); gTouchCallBackCalled = false; application.DisconnectAll(); // simulate another touch event - application.ProcessEvent( event ); + application.ProcessEvent(event); - DALI_TEST_CHECK( gTouchCallBackCalled == false ); + DALI_TEST_CHECK(gTouchCallBackCalled == false); END_TEST; } -int UtcDaliBaseHandleGetTypeName(void) +int UtcDaliBaseHandleGetTypeNameP(void) { TestApplication application; tet_infoline("Testing Dali::BaseHandle::GetTypeName"); @@ -429,8 +529,45 @@ int UtcDaliBaseHandleGetTypeName(void) std::string typeName = actor.GetTypeName(); - DALI_TEST_CHECK( typeName.size() ); - DALI_TEST_CHECK( typeName == std::string("Actor") ); + DALI_TEST_CHECK(typeName.size()); + DALI_TEST_CHECK(typeName == std::string("Actor")); + END_TEST; +} + +int UtcDaliBaseHandleGetTypeNameN(void) +{ + TestApplication application; + tet_infoline("Testing Dali::BaseObject::GetTypeName"); + FakeObject object; + std::string typeName = object.GetTypeName(); + + DALI_TEST_CHECK(typeName.empty()); + END_TEST; +} + +int UtcDaliBaseHandleGetTypeInfoP(void) +{ + TestApplication application; + tet_infoline("Testing Dali::BaseHandle::GetTypeInfo"); + + Dali::TypeInfo info; + Actor actor = Actor::New(); + + bool ok = actor.GetTypeInfo(info); + DALI_TEST_CHECK(ok); + END_TEST; +} + +int UtcDaliBaseHandleGetTypeInfoN(void) +{ + TestApplication application; + tet_infoline("Testing Dali::BaseHandle::GetTypeInfo"); + + Dali::TypeInfo info; + FakeObject object; + + bool ok = object.GetTypeInfo(info); + DALI_TEST_CHECK(!ok); END_TEST; } @@ -444,18 +581,80 @@ int UtcDaliBaseHandleGetObjectPtr(void) Dali::RefObject* p = actor.GetObjectPtr(); - DALI_TEST_CHECK( p != NULL ); + DALI_TEST_CHECK(p != NULL); END_TEST; } int UtcDaliBaseHandleBooleanCast(void) { TestApplication application; - tet_infoline("Testing Dali::BaseHandle::BooleanType"); + tet_infoline("Testing Dali::BaseHandle::operator bool"); // get the root layer BaseHandle handle = Actor::New(); - DALI_TEST_CHECK( static_cast( handle ) ); + DALI_TEST_CHECK(static_cast(handle)); + END_TEST; +} + +int UtcDaliBaseHandleCompareOperatorN(void) +{ + TestApplication application; + BaseHandle handle1 = Actor::New(); + BaseHandle handle2 = handle1; + + DALI_TEST_CHECK((handle1 < handle2) == false); + + END_TEST; +} + +int UtcDaliBaseHandleDoActionNegative(void) +{ + TestApplication application; + Dali::BaseHandle instance; + try + { + std::string arg1; + Dali::Property::Map arg2; + instance.DoAction(arg1, arg2); + DALI_TEST_CHECK(false); // Should not get here + } + catch(...) + { + DALI_TEST_CHECK(true); // We expect an assert + } + END_TEST; +} + +int UtcDaliBaseHandleGetTypeInfoNegative(void) +{ + TestApplication application; + Dali::BaseHandle instance; + try + { + Dali::TypeInfo arg1; + instance.GetTypeInfo(arg1); + DALI_TEST_CHECK(false); // Should not get here + } + catch(...) + { + DALI_TEST_CHECK(true); // We expect an assert + } + END_TEST; +} + +int UtcDaliBaseHandleGetTypeNameNegative(void) +{ + TestApplication application; + Dali::BaseHandle instance; + try + { + instance.GetTypeName(); + DALI_TEST_CHECK(false); // Should not get here + } + catch(...) + { + DALI_TEST_CHECK(true); // We expect an assert + } END_TEST; }