From 56b4ea70c3d00b35bd517f532c5229902795bff6 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 3 Aug 2016 15:34:34 +0100 Subject: [PATCH] Adding ObjectDestructionTracker to dali-test-suite-utils for testing object destruction ControlImpl tests using ObjectDestructionFunctor to pass to object destrcution signal and confirm control has been destroyed. Change-Id: I9e59089213b6257d5c2a4094e2fbf352f2f376d1 --- .../dali-test-suite-utils.cpp | 48 ++++++++++++++++++++++ .../dali-test-suite-utils.h | 42 +++++++++++++++++++ .../src/dali-toolkit/utc-Dali-ControlImpl.cpp | 42 +++++++++---------- 3 files changed, 111 insertions(+), 21 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.cpp index 467bb52..b50f506 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.cpp @@ -337,3 +337,51 @@ BufferImage CreateBufferImage() { return CreateBufferImage(4, 4, Color::WHITE); } + +namespace Test +{ + +struct ObjectDestructionFunctor +{ + // Create a ObjectDestructionFunctor passing in a Dali::RefObject* to be monitored and a bool variable. + // Create ObjectRegistry instance and connect to the ObjectDestroyedSignal passing in the above functor for the callback. + // Get the ObjectPointer (Actor::GetObjectPtr) of the Actor to be checked for destruction and assign it to the Dali::RefObject* + // Check the bool variable which would be true when object destroyed. + ObjectDestructionFunctor( Dali::RefObject* objectPtr, bool& refObjectDestroyed ) + : refObjectPointerToCheck( objectPtr ), + refObjectDestroyedBoolean( refObjectDestroyed ) + { + refObjectDestroyed = false; + } + + void operator()( const Dali::RefObject* objectPointer ) + { + if ( refObjectPointerToCheck == objectPointer ) + { + refObjectDestroyedBoolean = true; + } + } + + Dali::RefObject* refObjectPointerToCheck; + bool& refObjectDestroyedBoolean; +}; + +ObjectDestructionTracker::ObjectDestructionTracker() + :mRefObjectDestroyed( false) +{ +} + +void ObjectDestructionTracker::Start( Actor actor ) +{ + ObjectDestructionFunctor destructionFunctor( actor.GetObjectPtr(), mRefObjectDestroyed ); + + ObjectRegistry objectRegistry = Stage::GetCurrent().GetObjectRegistry(); + objectRegistry.ObjectDestroyedSignal().Connect( this, destructionFunctor ); +} + +bool ObjectDestructionTracker::IsDestroyed() +{ + return mRefObjectDestroyed; +} + +} // namespace Test diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.h index 7f81872..9e0364b 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.h @@ -499,4 +499,46 @@ struct DefaultFunctionCoverage BufferImage CreateBufferImage(); BufferImage CreateBufferImage(int width, int height, const Vector4& color); +// Test namespace to prevent pollution of Dali namespace, add Test helper functions here +namespace Test +{ +/** + * @brief + * + * Helper to check object destruction occurred + * 1) In main part of code create an ObjectDestructionTracker + * 2) Within sub section of main create object Actor test and call Start with Actor to test for destruction + * 3) Perform code which is expected to destroy Actor + * 4) Back in main part of code use IsDestroyed() to test if Actor was destroyed + */ +class ObjectDestructionTracker : public ConnectionTracker +{ +public: + + /** + * @brief + * + * Call in main part of code + */ + ObjectDestructionTracker(); + + /** + * @brief Call in sub bock of code where the Actor being checked is still alive. + * + * @param[in] actor Actor to be checked for destruction + */ + void Start( Actor actor ); + + /** + * @brief Call to check if Actor alive or destroyed. + * @return bool true if Actor was destroyed + */ + bool IsDestroyed(); + +private: + bool mRefObjectDestroyed; +}; + +} // namespace Test + #endif // __DALI_TEST_SUITE_UTILS_H__ diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp index 07c6fe4..09d1dd7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp @@ -1011,8 +1011,6 @@ int UtcDaliControlImplRegisterVisaulThenReRegisterToSelf(void) // ReRegister to self dummyImpl.RegisterVisual( index, dummy, visual ); - tet_result(TET_PASS); - END_TEST; } @@ -1020,31 +1018,36 @@ int UtcDaliControlImplRegisterVisualToSelf(void) { ToolkitTestApplication application; - DummyControl dummy = DummyControl::New(); - DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + Test::ObjectDestructionTracker objectDestructionTracker; - Property::Index index =1; - Actor placementActor = Actor::New(); + { + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + objectDestructionTracker.Start( dummy ); - Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); - Toolkit::Visual::Base visual; + Property::Index index = 1; + Actor placementActor = Actor::New(); - Property::Map map; - map[Visual::Property::TYPE] = Visual::COLOR; - map[ColorVisual::Property::MIX_COLOR] = Color::RED; + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; - visual = visualFactory.CreateVisual( map ); - DALI_TEST_CHECK(visual); + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; - // ReRegister to self - dummyImpl.RegisterVisual( index, dummy, visual ); + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); - tet_result(TET_PASS); + // Register to self + dummyImpl.RegisterVisual( index, dummy, visual ); + DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), false, TEST_LOCATION ); // Control not destroyed yet + } + + DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), true, TEST_LOCATION ); // Should be destroyed END_TEST; } - int UtcDaliControlImplRegisterTwoVisuals(void) { ToolkitTestApplication application; @@ -1077,12 +1080,11 @@ int UtcDaliControlImplRegisterTwoVisuals(void) newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE; secondVisual = visualFactory.CreateVisual( newMap ); + DALI_TEST_CHECK( secondVisual ); // ReRegister with altered color visual dummyImpl.RegisterVisual( index2, secondPlacementActor, secondVisual ); - tet_result(TET_PASS); - END_TEST; } @@ -1112,7 +1114,5 @@ int UtcDaliControlImplRegisterUnregisterVisual(void) // Unregister visual dummyImpl.UnregisterVisual( index ); - tet_result(TET_PASS); - END_TEST; } -- 2.7.4