From ca7192635b72ebe1f03431420ae7a4d5087b5742 Mon Sep 17 00:00:00 2001 From: Nick Holland Date: Thu, 28 May 2015 12:53:10 +0100 Subject: [PATCH] More UTC test cases 100% line coverage for base-signal.cpp base-signal.h callback.cpp callback.h connection-tracker-interface.cpp connection-tracker.cpp dali-signal.h functor-delegate.cpp functor-delegate.h signal-slot-connections.cpp signal-slot-observers.cpp slot-delegate.h Change-Id: Ied3049844e9723a6fd06710e3ce508e1093c356f --- automated-tests/src/common/signal-helper.h | 169 +++++++++++++- .../src/dali/utc-Dali-ConnectionTracker.cpp | 26 +++ .../src/dali/utc-Dali-RenderTaskList.cpp | 31 +++ .../src/dali/utc-Dali-SignalTemplates.cpp | 246 ++++++++++++++++++--- dali/public-api/signals/functor-delegate.cpp | 4 +- 5 files changed, 433 insertions(+), 43 deletions(-) diff --git a/automated-tests/src/common/signal-helper.h b/automated-tests/src/common/signal-helper.h index 11aa7ab..b1f555f 100644 --- a/automated-tests/src/common/signal-helper.h +++ b/automated-tests/src/common/signal-helper.h @@ -127,6 +127,9 @@ public: // Void return, 2 value parameters typedef Signal VoidRet2ValueParamSignal; + // Void return, 3 value parameters + typedef Signal VoidRet3ValueParamSignal; + // bool return, 1 value parameter typedef Signal< bool (float)> BoolRet1ValueParamSignal; @@ -139,28 +142,34 @@ public: // float return, 0 parameters typedef Signal< float () > FloatRet0ParamSignal; + // float return, 1 value parameters + typedef Signal< float (float ) > FloatRet1ParamSignal; + // float return, 2 value parameters typedef Signal FloatRet2ValueParamSignal; + // float return, 3 value parameters + typedef Signal FloatRet3ValueParamSignal; + // void return, 3 value parameters typedef Signal VoidSignalTypeFloatValue3; - // float return, 3 value parameters - typedef Signal FloatSignalTypeFloatValue3; VoidRetNoParamSignal& SignalVoidNone() { return mSignalVoid0; } VoidRet1RefParamSignal& SignalVoid1Ref() { return mSignalVoid1R; } VoidRet1ValueParamSignal& SignalVoid1Value() { return mSignalVoid1V; } VoidRet2ValueParamSignal& SignalVoid2Value() { return mSignalVoid2V; } + VoidRet3ValueParamSignal& SignalVoid3Value() { return mSignalVoid3V; } BoolRet1ValueParamSignal& SignalBool1Value() { return mSignalBool1V; } BoolRet2ValueParamSignal& SignalBool2Value() { return mSignalBool2V; } IntRet2ValueParamSignal& SignalInt2Value() { return mSignalInt2V; } FloatRet0ParamSignal& SignalFloat0() { return mSignalFloat0; } + FloatRet1ParamSignal& SignalFloat1Value() {return mSignalFloat1V; } FloatRet2ValueParamSignal& SignalFloat2Value() { return mSignalFloat2V; } VoidSignalTypeFloatValue3& VoidSignalFloatValue3() { return mVoidSignalFloatValue3; } - FloatSignalTypeFloatValue3& FloatSignalFloatValue3() { return mFloatSignalFloatValue3; } + FloatRet3ValueParamSignal& SignalFloat3Value() { return mFloatSignalFloatValue3; } TestSignals() { @@ -172,10 +181,12 @@ public: DALI_TEST_EQUALS( mSignalVoid1R.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalVoid1V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalVoid2V.GetConnectionCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( mSignalVoid3V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalBool1V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalBool2V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalInt2V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalFloat0.GetConnectionCount(), 0u, TEST_LOCATION ); + DALI_TEST_EQUALS( mSignalFloat1V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mSignalFloat2V.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mVoidSignalFloatValue3.GetConnectionCount(), 0u, TEST_LOCATION ); DALI_TEST_EQUALS( mFloatSignalFloatValue3.GetConnectionCount(), 0u, TEST_LOCATION ); @@ -191,16 +202,22 @@ public: mSignalVoid1R.Emit(ref); } - void EmitVoidSignalIntValue(int p1) + void EmitVoidSignal1IntValue(int p1) { mSignalVoid1V.Emit(p1); } - void EmitVoidSignalIntValueIntValue(int p1, int p2) + void EmitVoidSignal2IntValue(int p1, int p2) { mSignalVoid2V.Emit(p1,p2); } + void EmitVoidSignal3IntValue(int p1, int p2, int p3) + { + mSignalVoid3V.Emit(p1,p2,p3); + } + + bool EmitBoolSignalFloatValue(float p1) { return mSignalBool1V.Emit(p1); @@ -216,6 +233,11 @@ public: return mSignalInt2V.Emit(p1, p2); } + float EmitFloat1VSignal(float p1 ) + { + return mSignalFloat1V.Emit(p1 ); + } + float EmitFloat2VSignal(float p1, float p2) { return mSignalFloat2V.Emit(p1, p2); @@ -231,7 +253,7 @@ public: mVoidSignalFloatValue3.Emit(p1, p2, p3); } - float EmitFloatSignalFloatValue3(float p1, float p2, float p3) + float EmitFloat3VSignal(float p1, float p2, float p3) { return mFloatSignalFloatValue3.Emit(p1, p2, p3); } @@ -242,13 +264,16 @@ private: VoidRet1RefParamSignal mSignalVoid1R; VoidRet1ValueParamSignal mSignalVoid1V; VoidRet2ValueParamSignal mSignalVoid2V; + VoidRet3ValueParamSignal mSignalVoid3V; + BoolRet1ValueParamSignal mSignalBool1V; BoolRet2ValueParamSignal mSignalBool2V; IntRet2ValueParamSignal mSignalInt2V; FloatRet0ParamSignal mSignalFloat0; + FloatRet1ParamSignal mSignalFloat1V; FloatRet2ValueParamSignal mSignalFloat2V; VoidSignalTypeFloatValue3 mVoidSignalFloatValue3; - FloatSignalTypeFloatValue3 mFloatSignalFloatValue3; + FloatRet3ValueParamSignal mFloatSignalFloatValue3; }; /** @@ -627,6 +652,10 @@ public: TestEmitDuringCallback() : mVoidSignalVoid( NULL ), + mFloatRet0ParamSignal( NULL), + mFloatRet1ParamSignal( NULL ), + mFloatRet2ParamSignal( NULL ), + mFloatRet3ParamSignal( NULL ), mHandled( false ) { } @@ -637,15 +666,77 @@ public: signal.Connect( this, &TestEmitDuringCallback::VoidSlotVoid ); } + void FloatRet0ParamConnect( TestSignals::FloatRet0ParamSignal& signal ) + { + mFloatRet0ParamSignal = &signal; + signal.Connect( this, &TestEmitDuringCallback::FloatRet0Param ); + } + void FloatRet1ParamConnect( TestSignals::FloatRet1ParamSignal& signal ) + { + mFloatRet1ParamSignal = &signal; + signal.Connect( this, &TestEmitDuringCallback::FloatRet1Param ); + } + void FloatRet2ParamConnect( TestSignals::FloatRet2ValueParamSignal& signal ) + { + mFloatRet2ParamSignal = &signal; + signal.Connect( this, &TestEmitDuringCallback::FloatRet2Param ); + } + void FloatRet3ParamConnect( TestSignals::FloatRet3ValueParamSignal& signal ) + { + mFloatRet3ParamSignal = &signal; + signal.Connect( this, &TestEmitDuringCallback::FloatRet3Param ); + } + + void DeleteDuringEmitConnect( TestSignals::VoidRetNoParamSignal& signal ) + { + mVoidSignalVoid = &signal; + signal.Connect( this, &TestEmitDuringCallback::DeleteSignalDuringEmit ); + } + void VoidSlotVoid() { // Emitting during Emit is very bad! mVoidSignalVoid->Emit(); + mHandled = true; + } + void DeleteSignalDuringEmit() + { + // deleting the signal during the emit + delete mVoidSignalVoid; + } + + float FloatRet0Param() + { + // Emitting during Emit is very bad! + mHandled = true; + return mFloatRet0ParamSignal->Emit(); + } + float FloatRet1Param( float x ) + { + // Emitting during Emit is very bad! + mHandled = true; + return mFloatRet1ParamSignal->Emit(x); + } + float FloatRet2Param( float x, float y ) + { + // Emitting during Emit is very bad! + mHandled = true; + return mFloatRet2ParamSignal->Emit( x, y ); + } + float FloatRet3Param( float x, float y, float z) + { + // Emitting during Emit is very bad! mHandled = true; + return mFloatRet3ParamSignal->Emit( x, y, z ); } TestSignals::VoidRetNoParamSignal* mVoidSignalVoid; + TestSignals::FloatRet0ParamSignal* mFloatRet0ParamSignal; + TestSignals::FloatRet1ParamSignal* mFloatRet1ParamSignal; + TestSignals::FloatRet2ValueParamSignal* mFloatRet2ParamSignal; + TestSignals::FloatRet3ValueParamSignal* mFloatRet3ParamSignal; + bool mHandled; }; @@ -871,6 +962,15 @@ public: } } + /** + * RemoveNullCallback, + * testing what occurs when we pass a callback that doesn't exist + */ + void RemoveNullCallback() + { + mSlotObserver->SlotDisconnected( NULL ); + } + private: TestBasicConnectionTrackerInterface( const TestBasicConnectionTrackerInterface& ); ///< undefined copy constructor @@ -889,6 +989,61 @@ private: +// for testing static function callbacks +class StaticFunctionHandlers +{ +public: + StaticFunctionHandlers() + { + staticFunctionHandled = false; + } + void Reset() + { + staticFunctionHandled = false; + } + + static void VoidSlotVoid() + { + staticFunctionHandled = true; + } + static void VoidSlot1Param( int p1 ) + { + staticFunctionHandled = true; + } + static void VoidSlot2Param( int p1, int p2 ) + { + staticFunctionHandled = true; + } + static void VoidSlot3Param( int p1, int p2, int p3 ) + { + staticFunctionHandled = true; + } + + static float RetSlot0Param( ) + { + staticFunctionHandled = true; + return 0; + } + static float RetSlot1Param( float p1 ) + { + staticFunctionHandled = true; + return 0; + } + static float RetSlot2Param( float p1, float p2 ) + { + staticFunctionHandled = true; + return 0; + } + static float RetSlot3Param( float p1, float p2, float p3 ) + { + staticFunctionHandled = true; + return 0; + } + + static bool staticFunctionHandled; +}; + + /** * test functor, we store a reference to a bool which is outside of the functor * so when the functor is copied, the copy can reference the original data diff --git a/automated-tests/src/dali/utc-Dali-ConnectionTracker.cpp b/automated-tests/src/dali/utc-Dali-ConnectionTracker.cpp index 9aad994..a246746 100644 --- a/automated-tests/src/dali/utc-Dali-ConnectionTracker.cpp +++ b/automated-tests/src/dali/utc-Dali-ConnectionTracker.cpp @@ -163,6 +163,32 @@ int UtcConnectionTrackerSignalDisconnectP(void) } + +int UtcConnectionTrackerSignalDisconnectN(void) +{ + TestApplication app; // Create core for debug logging + + TestButton* button = new TestButton(1); + TestApp testApp; + button->DownSignal().Connect(&testApp,&TestApp::OnButtonPress); + + DALI_TEST_CHECK( button->DownSignal().GetConnectionCount( ) == 1 ); + + try + { + app.SignalDisconnected( NULL, NULL ); + tet_result( TET_FAIL ); + } + catch (Dali::DaliException& e) + { + tet_result( TET_PASS ); + } + + END_TEST; + +} + + int UtcConnectionTrackerGetConnectionCountP(void) { TestApplication app; // Create core for debug logging diff --git a/automated-tests/src/dali/utc-Dali-RenderTaskList.cpp b/automated-tests/src/dali/utc-Dali-RenderTaskList.cpp index 7b78f4b..2d69397 100644 --- a/automated-tests/src/dali/utc-Dali-RenderTaskList.cpp +++ b/automated-tests/src/dali/utc-Dali-RenderTaskList.cpp @@ -45,6 +45,37 @@ int UtcDaliRenderTaskListDefaultConstructor(void) END_TEST; } +int UtcDaliRenderTaskListCopyConstructor(void) +{ + TestApplication application; + + tet_infoline("Testing RenderTaskList::RenderTaskList(const RenderTaskList& handle)"); + + RenderTaskList taskList1; + + RenderTaskList taskList2( taskList1 ); + + DALI_TEST_CHECK( ! taskList2 ); + END_TEST; +} + +int UtcDaliRenderTaskListAssignment(void) +{ + TestApplication application; + + tet_infoline("Testing RenderTaskList::RenderTaskList(const RenderTaskList& handle)"); + + RenderTaskList taskList1; + + RenderTaskList taskList2; + + taskList1 = taskList2; + + DALI_TEST_CHECK( ! taskList1 ); + END_TEST; +} + + int UtcDaliRenderTaskListDownCast(void) { TestApplication application; diff --git a/automated-tests/src/dali/utc-Dali-SignalTemplates.cpp b/automated-tests/src/dali/utc-Dali-SignalTemplates.cpp index d840216..e1e20d5 100644 --- a/automated-tests/src/dali/utc-Dali-SignalTemplates.cpp +++ b/automated-tests/src/dali/utc-Dali-SignalTemplates.cpp @@ -26,6 +26,8 @@ using namespace Dali; +bool StaticFunctionHandlers::staticFunctionHandled; + void utc_dali_signal_templates_startup(void) { test_return_value = TET_UNDEF; @@ -288,14 +290,23 @@ int UtcDaliSignalConnectP05(void) // test function object using FunctorDelegate. // :Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate ) - TestSlotHandler handler; - TestSignals::VoidRetNoParamSignal signal; - bool functorDelegateCalled(false); - signal.Connect( &handler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) )); - DALI_TEST_CHECK( ! signal.Empty() ); - signal.Emit(); - DALI_TEST_CHECK( functorDelegateCalled == true ); - + { + TestSlotHandler handler; + TestSignals::VoidRetNoParamSignal signal; + bool functorDelegateCalled(false); + signal.Connect( &handler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) )); + DALI_TEST_CHECK( ! signal.Empty() ); + signal.Emit(); + DALI_TEST_CHECK( functorDelegateCalled == true ); + } + { + TestSlotHandler handler; + TestSignals::VoidRet1ValueParamSignal signal; + bool functorDelegateCalled(false); + signal.Connect( &handler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) )); + DALI_TEST_CHECK( ! signal.Empty() ); + signal.Emit(1); + } END_TEST; } @@ -584,7 +595,7 @@ int UtcDaliSignalEmptyCheckSlotDestruction(void) } // Positive test case for a method -int UtcDaliSignalConnectAndEmit(void) +int UtcDaliSignalConnectAndEmit01P(void) { // Test basic signal emission for each slot type @@ -619,7 +630,7 @@ int UtcDaliSignalConnectAndEmit(void) TestSlotHandler handlers; signals.SignalVoid1Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); - signals.EmitVoidSignalIntValue(5); + signals.EmitVoidSignal1IntValue(5); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 5, TEST_LOCATION ); } @@ -629,7 +640,7 @@ int UtcDaliSignalConnectAndEmit(void) TestSlotHandler handlers; signals.SignalVoid2Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); - signals.EmitVoidSignalIntValueIntValue(6, 7); + signals.EmitVoidSignal2IntValue(6, 7); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 6, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam2, 7, TEST_LOCATION ); @@ -720,10 +731,10 @@ int UtcDaliSignalConnectAndEmit(void) { TestSlotHandler handlers; - signals.FloatSignalFloatValue3().Connect(&handlers, &TestSlotHandler::FloatSlotFloatValue3); + signals.SignalFloat3Value().Connect(&handlers, &TestSlotHandler::FloatSlotFloatValue3); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); handlers.mFloatReturn = 27.0f; - float returnValue = signals.EmitFloatSignalFloatValue3(5, 33.0f, 100.0f); + float returnValue = signals.EmitFloat3VSignal(5, 33.0f, 100.0f); DALI_TEST_EQUALS( returnValue, 27.0f, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION ); @@ -734,6 +745,75 @@ int UtcDaliSignalConnectAndEmit(void) END_TEST; } +int UtcDaliSignalConnectAndEmit02P(void) +{ + // testing connection of static functions + TestSignals signals; + StaticFunctionHandlers handlers; + + // void ( void ) + signals.SignalVoidNone().Connect( &StaticFunctionHandlers::VoidSlotVoid ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitVoidSignalVoid(); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + + // void ( p1 ) + handlers.Reset(); + signals.SignalVoid1Value().Connect( &StaticFunctionHandlers::VoidSlot1Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitVoidSignal1IntValue( 1 ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + // void ( p1, p2 ) + handlers.Reset(); + signals.SignalVoid2Value().Connect( &StaticFunctionHandlers::VoidSlot2Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitVoidSignal2IntValue( 1, 2 ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + + // void ( p1, p2, p3 ) + handlers.Reset(); + signals.SignalVoid3Value().Connect( &StaticFunctionHandlers::VoidSlot3Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitVoidSignal3IntValue( 1, 2, 3 ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + // ret ( ) + handlers.Reset(); + signals.SignalFloat0().Connect( &StaticFunctionHandlers::RetSlot0Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitFloat0Signal(); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + // ret ( p1 ) + handlers.Reset(); + signals.SignalFloat1Value().Connect( &StaticFunctionHandlers::RetSlot1Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitFloat1VSignal( 1.f ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + // ret ( p1, p2 ) + handlers.Reset(); + signals.SignalFloat2Value().Connect( &StaticFunctionHandlers::RetSlot2Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitFloat2VSignal( 1.f, 2.f ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + + // ret ( p1, p2, p3 ) + handlers.Reset(); + signals.SignalFloat3Value().Connect( &StaticFunctionHandlers::RetSlot3Param ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, false, TEST_LOCATION ); + signals.EmitFloat3VSignal( 1.f, 2.f, 3.f ); + DALI_TEST_EQUALS( handlers.staticFunctionHandled, true, TEST_LOCATION ); + + END_TEST; + +} + + int UtcDaliSignalDisconnect(void) { // Test that callbacks don't occur if a signal is disconnected before emission @@ -767,7 +847,7 @@ int UtcDaliSignalDisconnect(void) signals.SignalVoid1Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); signals.SignalVoid1Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValue); - signals.EmitVoidSignalIntValue(5); + signals.EmitVoidSignal1IntValue(5); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); } @@ -777,7 +857,7 @@ int UtcDaliSignalDisconnect(void) signals.SignalVoid2Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); signals.SignalVoid2Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue); - signals.EmitVoidSignalIntValueIntValue(5, 10); + signals.EmitVoidSignal2IntValue(5, 10); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION ); @@ -869,7 +949,7 @@ int UtcDaliSignalDisconnect2(void) { TestSlotHandler handlers; signals.SignalVoid1Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValue); - signals.EmitVoidSignalIntValue(5); + signals.EmitVoidSignal1IntValue(5); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); } @@ -877,7 +957,7 @@ int UtcDaliSignalDisconnect2(void) { TestSlotHandler handlers; signals.SignalVoid2Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue); - signals.EmitVoidSignalIntValueIntValue(5, 10); + signals.EmitVoidSignal2IntValue(5, 10); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION ); @@ -1014,6 +1094,30 @@ int UtcDaliSignalCustomConnectionTracker(void) DALI_TEST_EQUALS( customTracker2.mCallbackHandled, true, TEST_LOCATION ); } DALI_TEST_EQUALS( 0u, customTracker2.GetConnectionCount(), TEST_LOCATION ); + + // Test for removing a null callback + { + TestBasicConnectionTrackerInterface customTracker3; + + TestSignals::VoidRetNoParamSignal signal; + DALI_TEST_CHECK( signal.Empty() ); + DALI_TEST_EQUALS( 0u, customTracker3.GetConnectionCount(), TEST_LOCATION ); + + signal.Connect( &customTracker3, &TestBasicConnectionTrackerInterface::VoidSlotVoid ); + DALI_TEST_CHECK( ! signal.Empty() ); + DALI_TEST_EQUALS( 1u, customTracker3.GetConnectionCount(), TEST_LOCATION ); + try + { + // should assert + customTracker3.RemoveNullCallback(); + tet_result( TET_FAIL ); + } + catch (Dali::DaliException& e) + { + tet_result( TET_PASS ); + } + } + END_TEST; } @@ -1088,7 +1192,7 @@ int UtcDaliSignalMultipleConnections(void) signals.SignalVoid1Value().Connect( &handler3, &TestSlotHandler::VoidSlotIntValue ); DALI_TEST_EQUALS( handler3.mHandled, false, TEST_LOCATION ); - signals.EmitVoidSignalIntValue( 5 ); + signals.EmitVoidSignal1IntValue( 5 ); DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handler1.mIntParam1, 5, TEST_LOCATION ); DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION ); @@ -1102,7 +1206,7 @@ int UtcDaliSignalMultipleConnections(void) handler3.Reset(); signals.SignalVoid1Value().Disconnect( &handler2, &TestSlotHandler::VoidSlotIntValue ); - signals.EmitVoidSignalIntValue( 6 ); + signals.EmitVoidSignal1IntValue( 6 ); DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handler1.mIntParam1, 6, TEST_LOCATION ); DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION ); @@ -1153,7 +1257,7 @@ int UtcDaliSignalMultipleConnections2(void) signals.SignalVoid1Value().Connect( &handler1, &TestSlotHandler::VoidSlotIntValue ); DALI_TEST_EQUALS( handler1.mHandledCount, 0, TEST_LOCATION ); - signals.EmitVoidSignalIntValue( 6 ); + signals.EmitVoidSignal1IntValue( 6 ); DALI_TEST_EQUALS( handler1.mHandledCount, 1, TEST_LOCATION ); DALI_TEST_EQUALS( handler1.mIntParam1, 6, TEST_LOCATION ); @@ -1162,7 +1266,7 @@ int UtcDaliSignalMultipleConnections2(void) DALI_TEST_CHECK( signals.SignalVoid1Value().Empty() ); handler1.mIntParam1 = 0; - signals.EmitVoidSignalIntValue( 7 ); + signals.EmitVoidSignal1IntValue( 7 ); DALI_TEST_EQUALS( handler1.mHandledCount, 1/*not incremented since last check*/, TEST_LOCATION ); DALI_TEST_EQUALS( handler1.mIntParam1, 0, TEST_LOCATION ); } @@ -1186,7 +1290,7 @@ int UtcDaliSignalMultipleConnections2(void) DALI_TEST_CHECK( signals.SignalBool1Value().Empty() ); // Should be NOOP - signals.EmitVoidSignalIntValue( 1 ); + signals.EmitVoidSignal1IntValue( 1 ); signals.EmitBoolSignalFloatValue( 1.0f ); // Test that connecting the same callback 10 times is a NOOP @@ -1474,14 +1578,81 @@ int UtcDaliSignalEmitDuringCallback(void) { TestApplication app; // Create core for debug logging - TestSignals::VoidRetNoParamSignal signal; - DALI_TEST_CHECK( signal.Empty() ); + // for coverage purposes we test the emit guard for each signal type (0,1,2,3 params) void / return value + { + TestSignals::VoidRetNoParamSignal signal; + DALI_TEST_CHECK( signal.Empty() ); + + TestEmitDuringCallback handler1; + handler1.VoidConnectVoid( signal ); + + // Test that this does not result in an infinite loop! + signal.Emit(); + } + { + TestSignals::FloatRet0ParamSignal signal; + + DALI_TEST_CHECK( signal.Empty() ); + + TestEmitDuringCallback handler1; + handler1.FloatRet0ParamConnect( signal ); + + // Test that this does not result in an infinite loop! + signal.Emit(); + } + { + TestSignals::FloatRet1ParamSignal signal; + + DALI_TEST_CHECK( signal.Empty() ); + + TestEmitDuringCallback handler1; + handler1.FloatRet1ParamConnect( signal ); + + // Test that this does not result in an infinite loop! + signal.Emit( 1.f ); + } + { + TestSignals::FloatRet2ValueParamSignal signal; + + DALI_TEST_CHECK( signal.Empty() ); + + TestEmitDuringCallback handler1; + handler1.FloatRet2ParamConnect( signal ); + + // Test that this does not result in an infinite loop! + signal.Emit( 1.f, 1.f ); + } + { + TestSignals::FloatRet3ValueParamSignal signal; + + DALI_TEST_CHECK( signal.Empty() ); + + TestEmitDuringCallback handler1; + handler1.FloatRet3ParamConnect( signal ); + + // Test that this does not result in an infinite loop! + signal.Emit( 1.f,1.f,1.f ); + } + END_TEST; +} + +int UtcDaliSignalDeleteDuringEmit(void) +{ + // testing a signal deletion during an emit + // need to dynamically allocate the signal for this to work + + TestApplication app; // Create core for debug logging + + TestSignals::VoidRetNoParamSignal* signal = new TestSignals::VoidRetNoParamSignal; TestEmitDuringCallback handler1; - handler1.VoidConnectVoid( signal ); + handler1.DeleteDuringEmitConnect( *signal ); + + // should just log an error + signal->Emit(); + + tet_result( TET_PASS ); - // Test that this does not result in an infinite loop! - signal.Emit(); END_TEST; } @@ -1675,7 +1846,7 @@ int UtcDaliSlotDelegateConnection(void) TestSlotDelegateHandler handlers; signals.SignalVoid1Value().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValue ); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); - signals.EmitVoidSignalIntValue(5); + signals.EmitVoidSignal1IntValue(5); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 5, TEST_LOCATION ); } @@ -1685,7 +1856,7 @@ int UtcDaliSlotDelegateConnection(void) TestSlotDelegateHandler handlers; signals.SignalVoid2Value().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValueIntValue ); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); - signals.EmitVoidSignalIntValueIntValue(6, 7); + signals.EmitVoidSignal2IntValue(6, 7); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 6, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam2, 7, TEST_LOCATION ); @@ -1776,10 +1947,10 @@ int UtcDaliSlotDelegateConnection(void) { TestSlotDelegateHandler handlers; - signals.FloatSignalFloatValue3().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotFloatValue3 ); + signals.SignalFloat3Value().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotFloatValue3 ); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); handlers.mFloatReturn = 27.0f; - float returnValue = signals.EmitFloatSignalFloatValue3(5, 33.0f, 100.0f); + float returnValue = signals.EmitFloat3VSignal(5, 33.0f, 100.0f); DALI_TEST_EQUALS( returnValue, 27.0f, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION ); @@ -1970,7 +2141,7 @@ int UtcDaliSlotHandlerDisconnect(void) signals.SignalVoid1Value().Connect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); signals.SignalVoid1Value().Disconnect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValue); - signals.EmitVoidSignalIntValue(5); + signals.EmitVoidSignal1IntValue(5); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); } @@ -1980,7 +2151,7 @@ int UtcDaliSlotHandlerDisconnect(void) signals.SignalVoid2Value().Connect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValueIntValue); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); signals.SignalVoid2Value().Disconnect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValueIntValue); - signals.EmitVoidSignalIntValueIntValue(5, 10); + signals.EmitVoidSignal2IntValue(5, 10); DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION ); DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION ); @@ -2046,3 +2217,12 @@ int UtcDaliSlotHandlerDisconnect(void) } END_TEST; } + + +int UtcDaliCallbackBase(void) +{ + // simple constructor for coverage + CallbackBase base; + tet_result( TET_PASS ); + END_TEST; +} diff --git a/dali/public-api/signals/functor-delegate.cpp b/dali/public-api/signals/functor-delegate.cpp index 5a18b9e..b8baee1 100644 --- a/dali/public-api/signals/functor-delegate.cpp +++ b/dali/public-api/signals/functor-delegate.cpp @@ -32,9 +32,7 @@ namespace * If this assert fails, please implement the template specialisation for C functions. */ #if !defined(EMSCRIPTEN) -void Function() __attribute__((unused)); -void Function() { } -DALI_COMPILE_TIME_ASSERT( sizeof(void*) == sizeof(&Function) ); +DALI_COMPILE_TIME_ASSERT( sizeof(void*) == sizeof( &FunctorDispatcher::Dispatch ) ); #endif } -- 2.7.4