Dali 3D User Interface Engine
utc-Dali-SignalTemplates.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 // EXTERNAL INCLUDES
19 #include <iostream>
20 #include <stdlib.h>
21 
22 // INTERNAL INCLUDES
24 #include <dali-test-suite-utils.h>
25 #include "signal-helper.h"
26 
27 using namespace Dali;
28 
30 
32 {
34 }
35 
37 {
39 }
40 
41 namespace {
42 
43 
49 float staticFloatValue1 = 0.0f;
50 float staticFloatValue2 = 0.0f;
51 
53 {
54  wasStaticVoidCallbackVoidCalled = true;
55 }
56 
58 {
59 }
60 
62 {
63  wasStaticFloatCallbackVoidCalled = true;
64  return 7.0f;
65 }
66 
67 void StaticVoidCallbackIntValue( int value )
68 {
69  wasStaticVoidCallbackIntValueCalled = true;
70  staticIntValue = value;
71 }
72 
74 {
75  wasStaticFloatCallbackFloatValueFloatValueCalled = true;
76  staticFloatValue1 = value1;
77  staticFloatValue2 = value2;
78  return value1 + value2;
79 }
80 
81 } // anon namespace
82 
83 
84 
85 /*******************************************
86  *
87  * Start of Utc test cases.
88  * Test cases performed in order of API listed in dali-signal.h
89  * UtcDaliSignal + FunctionName + P=positive test, N = Negative test
90  *
91  */
92 
94 {
95  TestApplication app; // Create core for debug logging
96 
97  // Test that Empty() is true, when no slots connected to the signal
98 
99  {
101  DALI_TEST_CHECK( signal.Empty() );
102  }
103 
104  // Test that Empty() is true, when a slot has connected and disconnected
105  {
107  TestSlotHandler handler;
108  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
109  signal.Disconnect( &handler, &TestSlotHandler::VoidSlotVoid );
110  DALI_TEST_CHECK( signal.Empty() );
111  }
112 
113  END_TEST;
114 }
115 
117 {
118  TestApplication app; // Create core for debug logging
119 
120  // Test that Empty() is false after signal connection
122  TestSlotHandler handler;
123  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
124  DALI_TEST_CHECK( ! signal.Empty() );
125 
126  END_TEST;
127 }
128 
130 {
131  TestApplication app; // Create core for debug logging
132 
134  TestSlotHandler handler;
135  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
136  DALI_TEST_CHECK( signal.GetConnectionCount() == 1 );
137 
138  TestSlotHandler handler2;
139  signal.Connect( &handler2, &TestSlotHandler::VoidSlotVoid );
140  DALI_TEST_CHECK( signal.GetConnectionCount() == 2 );
141 
142  END_TEST;
143 }
144 
146 {
147  TestApplication app; // Create core for debug logging
149  DALI_TEST_CHECK( signal.GetConnectionCount() == 0 );
150  END_TEST;
151 }
152 
158 {
159  TestApplication app; // Create core for debug logging
160 
161  // test static function: void Connect( void (*func)() )
163  signal.Connect( StaticVoidCallbackVoid );
164  DALI_TEST_CHECK( ! signal.Empty() );
165 
166 
167  END_TEST;
168 }
169 
171 {
172  // difficult to perform a negative test on Connect as no checks are performed
173  // when creating a callback for a null function ( during Connect).
174  // so we test an assert on Emit
175  TestApplication app; // Create core for debug logging
176 
178  signal.Connect( NULL );
179  try
180  {
181  signal.Emit();
182  }
183  catch (Dali::DaliException& e)
184  {
185  // Tests that a negative test of an assertion succeeds
188  }
189  END_TEST;
190 }
191 
192 
194 {
195  TestApplication app; // Create core for debug logging
196 
197  // test member function: Connect( X* obj, void (X::*func)() ))
199  TestSlotHandler handler;
200  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
201  DALI_TEST_CHECK( ! signal.Empty() );
202  signal.Emit();
203  DALI_TEST_CHECK( handler.mHandled == true );
204  END_TEST;
205 }
206 
208 {
209  TestApplication app; // Create core for debug logging
210 
212  try
213  {
214  // test member function: Connect( X* obj, void (X::*func)() )) with NULL object
215  signal.Connect( static_cast<TestSlotHandler*>(NULL), &TestSlotHandler::VoidSlotVoid );
216  }
217  catch (Dali::DaliException& e)
218  {
219  // Tests that a negative test of an assertion succeeds
222  }
223  END_TEST;
224 }
225 
226 
228 {
229  TestApplication app; // Create core for debug logging
230 
231  // test slot delegate: Connect( SlotDelegate<X>& delegate, void (X::*func)() )
233  TestSlotDelegateHandler handler;
234  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
235  DALI_TEST_CHECK( ! signal.Empty() );
236  signal.Emit();
237  DALI_TEST_CHECK( handler.mHandled == true );
238 
239  END_TEST;
240 }
241 
243 {
244  TestApplication app; // Create core for debug logging
245  // the delegate is passed by reference, so you can't pass null.
246  tet_result( TET_PASS );
247  END_TEST;
248 }
249 
251 {
252  TestApplication app; // Create core for debug logging
253 
254  // test function object: Connect( ConnectionTrackerInterface* connectionTracker, const X& func )
255  TestSlotHandler handler;
257  bool functorCalled(false);
258  TestFunctor functor( functorCalled );
259  signal.Connect( &handler, functor );
260  DALI_TEST_CHECK( ! signal.Empty() );
261  signal.Emit();
262  DALI_TEST_CHECK( functorCalled == true );
263 
264  END_TEST;
265 }
266 
268 {
269  // for negative test we try to connect a null connection tracker to the signal
271  TestSlotHandler *nullHandler( NULL );
272  try
273  {
274  signal.Connect( nullHandler , &TestSlotHandler::VoidSlotVoid );
275  }
276  catch (Dali::DaliException& e)
277  {
278  // Tests that a negative test of an assertion succeeds
280  tet_result( TET_PASS );
281  }
282 
283  END_TEST;
284 
285 }
286 
288 {
289  TestApplication app; // Create core for debug logging
290 
291  // test function object using FunctorDelegate.
292  // :Connect( ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate )
293  {
294  TestSlotHandler handler;
296  bool functorDelegateCalled(false);
297  signal.Connect( &handler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) ));
298  DALI_TEST_CHECK( ! signal.Empty() );
299  signal.Emit();
300  DALI_TEST_CHECK( functorDelegateCalled == true );
301  }
302  {
303  TestSlotHandler handler;
305  bool functorDelegateCalled(false);
306  signal.Connect( &handler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) ));
307  DALI_TEST_CHECK( ! signal.Empty() );
308  signal.Emit(1);
309  }
310  END_TEST;
311 }
312 
314 {
315  TestApplication app; // Create core for debug logging
316 
317  // for negative test we try to connect a null connection tracker to the signal
318  // :Connect( ConnectionTrackerInterface == NULL, FunctorDelegate* delegate )
319  TestSlotHandler *nullHandler( NULL );
321  bool functorDelegateCalled(false);
322  try
323  {
324  signal.Connect( nullHandler, FunctorDelegate::New( VoidFunctorVoid(functorDelegateCalled) ));
325  }
326  catch (Dali::DaliException& e)
327  {
329  tet_result( TET_PASS );
330  }
331  END_TEST;
332 }
333 
334 
340 {
341  TestApplication app; // Create core for debug logging
342 
343  // test static function: Disconnect( void (*func)( Arg0 arg0 ) )
344 
346  signal.Connect( StaticVoidCallbackVoid );
347  DALI_TEST_CHECK( ! signal.Empty() );
348  signal.Disconnect( StaticVoidCallbackVoid );
349  DALI_TEST_CHECK( signal.Empty() );
350 
351  END_TEST;
352 
353  }
355 {
356  TestApplication app; // Create core for debug logging
357 
358  // 1. Disconnect using the function
360  signal.Connect( StaticVoidCallbackVoid );
361  DALI_TEST_CHECK( ! signal.Empty() );
362 
363  signal.Disconnect( AlternativeVoidCallbackVoid );
364 
365  DALI_TEST_CHECK( ! signal.Empty() );
366 
367  END_TEST;
368 }
369 
371 {
372  TestApplication app; // Create core for debug logging
373 
374  // test member function: Disconnect( X* obj, void (X::*func)( Arg0 arg0 ) )
376  TestSlotHandler handler;
377  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
378  DALI_TEST_CHECK( ! signal.Empty() );
379  signal.Disconnect( &handler, &TestSlotHandler::VoidSlotVoid );
380  DALI_TEST_CHECK( signal.Empty() );
381 
382  END_TEST;
383 
384 }
386 {
387  TestApplication app; // Create core for debug logging
388 
389  // 1. Disconnect using a null connection tracker
391  TestSlotHandler handler;
392 
393  signal.Connect( &handler , &TestSlotHandler::VoidSlotVoid );
394  DALI_TEST_CHECK( !signal.Empty() );
395 
396  try
397  {
398  TestSlotHandler* nullHandler( NULL );
399  signal.Disconnect( nullHandler , &TestSlotHandler::VoidSlotVoid );
400  }
401  catch(Dali::DaliException& e)
402  {
403  // Tests that a negative test of an assertion succeeds
405  DALI_TEST_CHECK( !signal.Empty() );
406  }
407  END_TEST;
408 }
409 
411 {
412  TestApplication app; // Create core for debug logging
413 
414  // test slot delegate: Disconnect( SlotDelegate<X>& delegate, void (X::*func)( Arg0 arg0 ) )
416  TestSlotDelegateHandler handler;
417  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
418  DALI_TEST_CHECK( ! signal.Empty() );
419  signal.Disconnect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
420  DALI_TEST_CHECK( signal.Empty() );
421 
422  END_TEST;
423 }
424 
426 {
427  TestApplication app; // Create core for debug logging
428 
429  // try to disconnect from the wrong signal
431  TestSlotDelegateHandler handler;
432  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
433 
434  // use different signal
435  signal.Disconnect( handler.mSlotDelegate , &TestSlotDelegateHandler::AlternativeVoidSlotVoid );
436 
437  DALI_TEST_CHECK( !signal.Empty() );
438 
439  END_TEST;
440 
441 }
442 
443 /*******************************************
444  *
445  * End of Utc test cases for the individual API's of Signals
446  * The following testing Signals functionality as a whole
447  *
448  *
449  */
450 
452 {
453  // Test that signal disconnect works when slot is destroyed (goes out of scope)
454  {
456  {
457  DALI_TEST_CHECK( signal.Empty() );
458  TestSlotHandler handler;
459  signal.Connect( &handler, &TestSlotHandler::VoidSlotVoid );
460  DALI_TEST_CHECK( ! signal.Empty() );
461  }
462  // End of slot lifetime
463  DALI_TEST_CHECK( signal.Empty() );
464 
465  // Signal emission should be a NOOP
466  signal.Emit();
467  }
468 
469  {
471  {
472  DALI_TEST_CHECK( signal.Empty() );
473  TestSlotHandler handler;
474  signal.Connect( &handler, &TestSlotHandler::VoidSlotIntValue );
475  DALI_TEST_CHECK( ! signal.Empty() );
476  }
477  // End of slot lifetime
478  DALI_TEST_CHECK( signal.Empty() );
479 
480  // Signal emission should be a NOOP
481  signal.Emit( 10 );
482  }
483 
484  {
486  {
487  DALI_TEST_CHECK( signal.Empty() );
488  TestSlotHandler handler;
489  signal.Connect( &handler, &TestSlotHandler::VoidSlotIntRef );
490  DALI_TEST_CHECK( ! signal.Empty() );
491  }
492  // End of slot lifetime
493  DALI_TEST_CHECK( signal.Empty() );
494 
495  // Signal emission should be a NOOP
496  int temp( 5 );
497  signal.Emit( temp );
498  }
499 
500  {
502  {
503  DALI_TEST_CHECK( signal.Empty() );
504  TestSlotHandler handler;
505  signal.Connect( &handler, &TestSlotHandler::VoidSlotIntValueIntValue );
506  DALI_TEST_CHECK( ! signal.Empty() );
507  }
508  // End of slot lifetime
509  DALI_TEST_CHECK( signal.Empty() );
510 
511  // Signal emission should be a NOOP
512  signal.Emit( 1, 2 );
513  }
514 
515  {
517  {
518  DALI_TEST_CHECK( signal.Empty() );
519  TestSlotHandler handler;
520  signal.Connect( &handler, &TestSlotHandler::BoolSlotFloatValue );
521  DALI_TEST_CHECK( ! signal.Empty() );
522  }
523  // End of slot lifetime
524  DALI_TEST_CHECK( signal.Empty() );
525 
526  // Signal emission should be a NOOP
527  bool blah = signal.Emit( 1.0f );
528  DALI_TEST_CHECK( ! blah );
529  }
530 
531  {
533  {
534  DALI_TEST_CHECK( signal.Empty() );
535  TestSlotHandler handler;
536  signal.Connect( &handler, &TestSlotHandler::BoolSlotFloatValueIntValue );
537  DALI_TEST_CHECK( ! signal.Empty() );
538  }
539  // End of slot lifetime
540  DALI_TEST_CHECK( signal.Empty() );
541 
542  // Signal emission should be a NOOP
543  bool blah = signal.Emit( 1.0f, 2 );
544  DALI_TEST_CHECK( ! blah );
545  }
546 
547  {
549  {
550  DALI_TEST_CHECK( signal.Empty() );
551  TestSlotHandler handler;
552  signal.Connect( &handler, &TestSlotHandler::IntSlotFloatValueIntValue );
553  DALI_TEST_CHECK( ! signal.Empty() );
554  }
555  // End of slot lifetime
556  DALI_TEST_CHECK( signal.Empty() );
557 
558  // Signal emission should be a NOOP
559  int blah = signal.Emit( 10.0f, 100 );
560  DALI_TEST_CHECK( 0 == blah );
561  }
562 
563  {
565  {
566  DALI_TEST_CHECK( signal.Empty() );
567  TestSlotHandler handler;
568  signal.Connect( &handler, &TestSlotHandler::FloatSlotVoid );
569  DALI_TEST_CHECK( ! signal.Empty() );
570  }
571  // End of slot lifetime
572  DALI_TEST_CHECK( signal.Empty() );
573 
574  // Signal emission should be a NOOP
575  float blah = signal.Emit();
576  DALI_TEST_CHECK( 0.0f == blah );
577  }
578 
579  {
581  {
582  DALI_TEST_CHECK( signal.Empty() );
583  TestSlotHandler handler;
584  signal.Connect(&handler, &TestSlotHandler::FloatSlotFloatValueFloatValue);
585  DALI_TEST_CHECK( ! signal.Empty() );
586  }
587  // End of slot lifetime
588  DALI_TEST_CHECK( signal.Empty() );
589 
590  // Signal emission should be a NOOP
591  float blah = signal.Emit( 3.0f, 4.0f );
592  DALI_TEST_CHECK( 0.0f == blah );
593  }
594  END_TEST;
595 }
596 
597 // Positive test case for a method
599 {
600  // Test basic signal emission for each slot type
601 
602  TestSignals signals;
603 
604  {
605  TestSlotHandler handlers;
606  signals.SignalVoidNone().Connect(&handlers, &TestSlotHandler::VoidSlotVoid);
607  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
608  signals.EmitVoidSignalVoid();
609  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
610 
611  // Test double emission
612  handlers.mHandled = false;
613  signals.EmitVoidSignalVoid();
614  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
615  }
616  signals.CheckNoConnections();
617 
618  {
619  TestSlotHandler handlers;
620  signals.SignalVoid1Ref().Connect(&handlers, &TestSlotHandler::VoidSlotIntRef);
621  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
622  int x = 7;
623  signals.EmitVoidSignalIntRef(x);
624  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
625  DALI_TEST_EQUALS( handlers.mIntParam1, 7, TEST_LOCATION );
626  }
627  signals.CheckNoConnections();
628 
629  {
630  TestSlotHandler handlers;
631  signals.SignalVoid1Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValue);
632  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
633  signals.EmitVoidSignal1IntValue(5);
634  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
635  DALI_TEST_EQUALS( handlers.mIntParam1, 5, TEST_LOCATION );
636  }
637  signals.CheckNoConnections();
638 
639  {
640  TestSlotHandler handlers;
641  signals.SignalVoid2Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue);
642  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
643  signals.EmitVoidSignal2IntValue(6, 7);
644  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
645  DALI_TEST_EQUALS( handlers.mIntParam1, 6, TEST_LOCATION );
646  DALI_TEST_EQUALS( handlers.mIntParam2, 7, TEST_LOCATION );
647  }
648  signals.CheckNoConnections();
649 
650  {
651  TestSlotHandler handlers;
652  signals.SignalBool1Value().Connect(&handlers, &TestSlotHandler::BoolSlotFloatValue);
653  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
654 
655  handlers.mBoolReturn = true;
657  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
658  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
659 
660  // repeat with opposite return value
661  handlers.mBoolReturn = false;
662  handlers.mHandled = false;
664  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
665  DALI_TEST_EQUALS( handlers.mFloatParam1, 6.0f, TEST_LOCATION );
666  }
667  signals.CheckNoConnections();
668 
669  {
670  TestSlotHandler handlers;
671  signals.SignalBool2Value().Connect(&handlers, &TestSlotHandler::BoolSlotFloatValueIntValue);
672  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
673  handlers.mBoolReturn = true;
675  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
676  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
677  DALI_TEST_EQUALS( handlers.mIntParam2, 10, TEST_LOCATION );
678  }
679  signals.CheckNoConnections();
680 
681  {
682  TestSlotHandler handlers;
683  signals.SignalInt2Value().Connect(&handlers, &TestSlotHandler::IntSlotFloatValueIntValue);
684  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
685  handlers.mIntReturn = 27;
686  int x = signals.EmitIntSignalFloatValueIntValue(33.5f, 5);
688  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
689  DALI_TEST_EQUALS( handlers.mFloatParam1, 33.5f, TEST_LOCATION );
690  DALI_TEST_EQUALS( handlers.mIntParam2, 5, TEST_LOCATION );
691  }
692  signals.CheckNoConnections();
693 
694  {
695  TestSlotHandler handlers;
696  signals.SignalFloat0().Connect(&handlers, &TestSlotHandler::FloatSlotVoid);
697  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
698  handlers.mFloatReturn = 27.0f;
699  float f = signals.EmitFloat0Signal();
700  DALI_TEST_EQUALS( f, 27.0f, TEST_LOCATION );
701  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
702  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
703  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
704  }
705  signals.CheckNoConnections();
706 
707  {
708  TestSlotHandler handlers;
710  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
711  handlers.mFloatReturn = 27.0f;
712  float f = signals.EmitFloat2VSignal(5, 33.0f);
713  DALI_TEST_EQUALS( f, 27.0f, TEST_LOCATION );
714  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
715  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
716  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
717  }
718  signals.CheckNoConnections();
719 
720  {
721  TestSlotHandler handlers;
722  signals.VoidSignalFloatValue3().Connect(&handlers, &TestSlotHandler::VoidSlotFloatValue3);
723  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
724  signals.EmitVoidSignalFloatValue3(5, 33.0f, 100.0f);
725  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
726  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
727  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
728  DALI_TEST_EQUALS( handlers.mFloatParam3, 100.0f, 0.001f, TEST_LOCATION );
729  }
730  signals.CheckNoConnections();
731 
732  {
733  TestSlotHandler handlers;
734  signals.SignalFloat3Value().Connect(&handlers, &TestSlotHandler::FloatSlotFloatValue3);
735  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
736  handlers.mFloatReturn = 27.0f;
737  float returnValue = signals.EmitFloat3VSignal(5, 33.0f, 100.0f);
738  DALI_TEST_EQUALS( returnValue, 27.0f, TEST_LOCATION );
739  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
740  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
741  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
742  DALI_TEST_EQUALS( handlers.mFloatParam3, 100.0f, 0.001f, TEST_LOCATION );
743  }
744  signals.CheckNoConnections();
745  END_TEST;
746 }
747 
749 {
750  // testing connection of static functions
751  TestSignals signals;
752  StaticFunctionHandlers handlers;
753 
754  // void ( void )
757  signals.EmitVoidSignalVoid();
759 
760 
761  // void ( p1 )
762  handlers.Reset();
765  signals.EmitVoidSignal1IntValue( 1 );
767 
768  // void ( p1, p2 )
769  handlers.Reset();
772  signals.EmitVoidSignal2IntValue( 1, 2 );
774 
775 
776  // void ( p1, p2, p3 )
777  handlers.Reset();
780  signals.EmitVoidSignal3IntValue( 1, 2, 3 );
782 
783  // ret ( )
784  handlers.Reset();
787  signals.EmitFloat0Signal();
789 
790  // ret ( p1 )
791  handlers.Reset();
794  signals.EmitFloat1VSignal( 1.f );
796 
797  // ret ( p1, p2 )
798  handlers.Reset();
801  signals.EmitFloat2VSignal( 1.f, 2.f );
803 
804 
805  // ret ( p1, p2, p3 )
806  handlers.Reset();
809  signals.EmitFloat3VSignal( 1.f, 2.f, 3.f );
811 
812  END_TEST;
813 
814 }
815 
816 
818 {
819  // Test that callbacks don't occur if a signal is disconnected before emission
820 
821  TestSignals signals;
822 
823  {
824  TestSlotHandler handlers;
825  signals.SignalVoidNone().Connect(&handlers, &TestSlotHandler::VoidSlotVoid);
826  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
827  signals.SignalVoidNone().Disconnect(&handlers, &TestSlotHandler::VoidSlotVoid);
828  signals.EmitVoidSignalVoid();
829  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
830  }
831 
832  {
833  TestSlotHandler handlers;
834  signals.SignalVoid1Ref().Connect(&handlers, &TestSlotHandler::VoidSlotIntRef);
835  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
836  int r = 7;
837  handlers.mIntReturn = 5;
838  signals.SignalVoid1Ref().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntRef);
839  signals.EmitVoidSignalIntRef(r);
840  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
841  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
843  }
844 
845  {
846  TestSlotHandler handlers;
847  signals.SignalVoid1Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValue);
848  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
849  signals.SignalVoid1Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValue);
850  signals.EmitVoidSignal1IntValue(5);
851  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
852  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
853  }
854 
855  {
856  TestSlotHandler handlers;
857  signals.SignalVoid2Value().Connect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue);
858  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
859  signals.SignalVoid2Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue);
860  signals.EmitVoidSignal2IntValue(5, 10);
861  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
862  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
863  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
864  }
865 
866  {
867  TestSlotHandler handlers;
868  signals.SignalBool1Value().Connect(&handlers, &TestSlotHandler::BoolSlotFloatValue);
869  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
870  handlers.mBoolReturn = true;
871  signals.SignalBool1Value().Disconnect(&handlers, &TestSlotHandler::BoolSlotFloatValue);
873  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
874  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
875  }
876 
877  {
878  TestSlotHandler handlers;
879  signals.SignalBool2Value().Connect(&handlers, &TestSlotHandler::BoolSlotFloatValueIntValue);
880  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
881  handlers.mBoolReturn = true;
882  signals.SignalBool2Value().Disconnect(&handlers, &TestSlotHandler::BoolSlotFloatValueIntValue);
884  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
885  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
886  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
887  }
888 
889  {
890  TestSlotHandler handlers;
891  signals.SignalInt2Value().Connect(&handlers, &TestSlotHandler::IntSlotFloatValueIntValue);
892  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
893  handlers.mIntReturn = 27;
894  signals.SignalInt2Value().Disconnect(&handlers, &TestSlotHandler::IntSlotFloatValueIntValue);
895  signals.EmitIntSignalFloatValueIntValue(5, 33.0f);
896  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
897  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
898  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
899  }
900 
901  {
902  TestSlotHandler handlers;
903  signals.SignalFloat0().Connect(&handlers, &TestSlotHandler::FloatSlotVoid);
904  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
905  handlers.mFloatReturn = 27.0f;
906  signals.SignalFloat0().Disconnect(&handlers, &TestSlotHandler::FloatSlotVoid);
907  signals.EmitFloat0Signal();
908  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
909  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
910  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
911  }
912 
913  {
914  TestSlotHandler handlers;
916  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
917  handlers.mFloatReturn = 27.0f;
918  signals.SignalFloat2Value().Disconnect(&handlers, &TestSlotHandler::FloatSlotFloatValueFloatValue);
919  signals.EmitFloat2VSignal(5, 33.0f);
920  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
921  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
922  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
923  }
924  END_TEST;
925 }
926 
928 {
929  // Test that nothing happens when attempting to disconnect an unconnected slot
930 
931  TestSignals signals;
932  {
933  TestSlotHandler handlers;
934  signals.SignalVoidNone().Disconnect(&handlers, &TestSlotHandler::VoidSlotVoid);
935  signals.EmitVoidSignalVoid();
936  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
937  }
938 
939  {
940  TestSlotHandler handlers;
941  int r = 7;
942  signals.SignalVoid1Ref().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntRef);
943  signals.EmitVoidSignalIntRef(r);
944  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
945  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
947  }
948 
949  {
950  TestSlotHandler handlers;
951  signals.SignalVoid1Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValue);
952  signals.EmitVoidSignal1IntValue(5);
953  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
954  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
955  }
956 
957  {
958  TestSlotHandler handlers;
959  signals.SignalVoid2Value().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntValueIntValue);
960  signals.EmitVoidSignal2IntValue(5, 10);
961  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
962  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
963  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
964  }
965 
966  {
967  TestSlotHandler handlers;
968  handlers.mBoolReturn = true;
969  signals.SignalBool1Value().Disconnect(&handlers, &TestSlotHandler::BoolSlotFloatValue);
971  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
972  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
973  }
974 
975  {
976  TestSlotHandler handlers;
977  handlers.mBoolReturn = true;
978  signals.SignalBool2Value().Disconnect(&handlers, &TestSlotHandler::BoolSlotFloatValueIntValue);
980  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
981  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
982  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
983  }
984 
985  {
986  TestSlotHandler handlers;
987  handlers.mIntReturn = 27;
988  signals.SignalInt2Value().Disconnect(&handlers, &TestSlotHandler::IntSlotFloatValueIntValue);
989  signals.EmitIntSignalFloatValueIntValue(5, 33.0f);
990  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
991  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
992  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
993  }
994 
995  {
996  TestSlotHandler handlers;
997  handlers.mFloatReturn = 27.0f;
998  signals.SignalFloat2Value().Disconnect(&handlers, &TestSlotHandler::FloatSlotFloatValueFloatValue);
999  signals.EmitFloat2VSignal(5, 33.0f);
1000  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1001  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
1002  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
1003  }
1004 
1005  {
1006  TestSlotHandler handlers;
1007  handlers.mFloatReturn = 27.0f;
1008  signals.SignalFloat0().Disconnect(&handlers, &TestSlotHandler::FloatSlotVoid);
1009  signals.EmitFloat0Signal();
1010  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1011  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
1012  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
1013  }
1014  END_TEST;
1015 }
1016 
1018 {
1019  // Test that callbacks stop after a signal is disconnected
1020 
1021  TestSignals signals;
1022 
1023  {
1024  TestSlotHandler handlers;
1025  signals.SignalVoidNone().Connect(&handlers, &TestSlotHandler::VoidSlotVoid);
1026  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1027 
1028  // Emit first
1029  signals.EmitVoidSignalVoid();
1030  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1031 
1032  // Disconnect and emit again
1033  handlers.mHandled = false;
1034  signals.SignalVoidNone().Disconnect(&handlers, &TestSlotHandler::VoidSlotVoid);
1035  signals.EmitVoidSignalVoid();
1036  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1037  }
1038 
1039  {
1040  TestSlotHandler handlers;
1041  signals.SignalVoid1Ref().Connect(&handlers, &TestSlotHandler::VoidSlotIntRef);
1042  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1043  int r = 7;
1044 
1045  // Emit first
1046  signals.EmitVoidSignalIntRef(r);
1047  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1048  DALI_TEST_EQUALS( handlers.mIntParam1, 7, TEST_LOCATION );
1049 
1050  // Disconnect and emit again
1051  handlers.mHandled = false;
1052  handlers.mIntParam1 = 0;
1053  signals.SignalVoid1Ref().Disconnect(&handlers, &TestSlotHandler::VoidSlotIntRef);
1054  signals.EmitVoidSignalIntRef(r);
1055  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1056  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
1058  }
1059  END_TEST;
1060 }
1061 
1063 {
1064  // Test slot destruction
1065  {
1067  {
1068  DALI_TEST_CHECK( signal.Empty() );
1070  signal.Connect( &customTracker, &TestBasicConnectionTrackerInterface::VoidSlotVoid );
1071  DALI_TEST_CHECK( ! signal.Empty() );
1072  }
1073  // End of slot lifetime
1074  DALI_TEST_CHECK( signal.Empty() );
1075 
1076  // Signal emission should be a NOOP
1077  signal.Emit();
1078  }
1079 
1080  TestBasicConnectionTrackerInterface customTracker2;
1081 
1082  // Test signal emission & destruction
1083  {
1085  DALI_TEST_CHECK( signal.Empty() );
1086  DALI_TEST_EQUALS( 0u, customTracker2.GetConnectionCount(), TEST_LOCATION );
1087 
1088  signal.Connect( &customTracker2, &TestBasicConnectionTrackerInterface::VoidSlotVoid );
1089  DALI_TEST_CHECK( ! signal.Empty() );
1090  DALI_TEST_EQUALS( 1u, customTracker2.GetConnectionCount(), TEST_LOCATION );
1091 
1092  DALI_TEST_EQUALS( customTracker2.mCallbackHandled, false, TEST_LOCATION );
1093  signal.Emit();
1094  DALI_TEST_EQUALS( customTracker2.mCallbackHandled, true, TEST_LOCATION );
1095  }
1096  DALI_TEST_EQUALS( 0u, customTracker2.GetConnectionCount(), TEST_LOCATION );
1097 
1098  // Test for removing a null callback
1099  {
1100  TestBasicConnectionTrackerInterface customTracker3;
1101 
1103  DALI_TEST_CHECK( signal.Empty() );
1104  DALI_TEST_EQUALS( 0u, customTracker3.GetConnectionCount(), TEST_LOCATION );
1105 
1106  signal.Connect( &customTracker3, &TestBasicConnectionTrackerInterface::VoidSlotVoid );
1107  DALI_TEST_CHECK( ! signal.Empty() );
1108  DALI_TEST_EQUALS( 1u, customTracker3.GetConnectionCount(), TEST_LOCATION );
1109  try
1110  {
1111  // should assert
1112  customTracker3.RemoveNullCallback();
1113  tet_result( TET_FAIL );
1114  }
1115  catch (Dali::DaliException& e)
1116  {
1117  tet_result( TET_PASS );
1118  }
1119  }
1120 
1121  END_TEST;
1122 }
1123 
1125 {
1126  // Test that multiple callbacks can be connected to the same signal
1127 
1128  TestSignals signals;
1129 
1130  {
1131  TestSlotHandler handler1;
1132  signals.SignalVoidNone().Connect( &handler1, &TestSlotHandler::VoidSlotVoid );
1133  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1134 
1135  TestSlotHandler handler2;
1136  signals.SignalVoidNone().Connect( &handler2, &TestSlotHandler::VoidSlotVoid );
1137  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1138 
1139  signals.EmitVoidSignalVoid();
1140  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1141  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1142 
1143  // Remove first connection and repeat
1144  handler1.Reset();
1145  handler2.Reset();
1146  signals.SignalVoidNone().Disconnect( &handler1, &TestSlotHandler::VoidSlotVoid );
1147 
1148  signals.EmitVoidSignalVoid();
1149  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1150  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1151  }
1152 
1153  {
1154  TestSlotHandler handler1;
1155  signals.SignalVoid1Ref().Connect( &handler1, &TestSlotHandler::VoidSlotIntRef );
1156  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1157 
1158  TestSlotHandler handler2;
1159  signals.SignalVoid1Ref().Connect( &handler2, &TestSlotHandler::VoidSlotIntRef );
1160  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1161 
1162  int x = 7;
1163  signals.EmitVoidSignalIntRef(x);
1164  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1165  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1166  DALI_TEST_EQUALS( handler1.mIntParam1, 7, TEST_LOCATION );
1167  DALI_TEST_EQUALS( handler2.mIntParam1, 7, TEST_LOCATION );
1168 
1169  // Remove second connection and repeat
1170  handler1.Reset();
1171  handler2.Reset();
1172  x = 8;
1173  signals.SignalVoid1Ref().Disconnect( &handler2, &TestSlotHandler::VoidSlotIntRef );
1174 
1175  signals.EmitVoidSignalIntRef(x);
1176  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1177  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1178  DALI_TEST_EQUALS( handler1.mIntParam1, 8, TEST_LOCATION );
1179  DALI_TEST_EQUALS( handler2.mIntParam1, 0, TEST_LOCATION );
1180  }
1181 
1182  {
1183  TestSlotHandler handler1;
1184  signals.SignalVoid1Value().Connect( &handler1, &TestSlotHandler::VoidSlotIntValue );
1185  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1186 
1187  TestSlotHandler handler2;
1188  signals.SignalVoid1Value().Connect( &handler2, &TestSlotHandler::VoidSlotIntValue );
1189  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1190 
1191  TestSlotHandler handler3;
1192  signals.SignalVoid1Value().Connect( &handler3, &TestSlotHandler::VoidSlotIntValue );
1193  DALI_TEST_EQUALS( handler3.mHandled, false, TEST_LOCATION );
1194 
1195  signals.EmitVoidSignal1IntValue( 5 );
1196  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1197  DALI_TEST_EQUALS( handler1.mIntParam1, 5, TEST_LOCATION );
1198  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1199  DALI_TEST_EQUALS( handler2.mIntParam1, 5, TEST_LOCATION );
1200  DALI_TEST_EQUALS( handler3.mHandled, true, TEST_LOCATION );
1201  DALI_TEST_EQUALS( handler3.mIntParam1, 5, TEST_LOCATION );
1202 
1203  // Remove middle connection and repeat
1204  handler1.Reset();
1205  handler2.Reset();
1206  handler3.Reset();
1207  signals.SignalVoid1Value().Disconnect( &handler2, &TestSlotHandler::VoidSlotIntValue );
1208 
1209  signals.EmitVoidSignal1IntValue( 6 );
1210  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1211  DALI_TEST_EQUALS( handler1.mIntParam1, 6, TEST_LOCATION );
1212  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1213  DALI_TEST_EQUALS( handler2.mIntParam1, 0, TEST_LOCATION );
1214  DALI_TEST_EQUALS( handler3.mHandled, true, TEST_LOCATION );
1215  DALI_TEST_EQUALS( handler3.mIntParam1, 6, TEST_LOCATION );
1216  }
1217 
1218  // Test that multiple callbacks are disconnected when a signal is destroyed
1219 
1220  TestSlotHandler handler4;
1221  TestSlotHandler handler5;
1222  TestSlotHandler handler6;
1223 
1224  {
1226 
1227  DALI_TEST_EQUALS( handler4.GetConnectionCount(), 0u, TEST_LOCATION );
1228  DALI_TEST_EQUALS( handler5.GetConnectionCount(), 0u, TEST_LOCATION );
1229  DALI_TEST_EQUALS( handler6.GetConnectionCount(), 0u, TEST_LOCATION );
1230 
1231  tempSignal.Connect( &handler4, &TestSlotHandler::VoidSlotIntValue );
1232  tempSignal.Connect( &handler5, &TestSlotHandler::VoidSlotIntValue );
1233  tempSignal.Connect( &handler6, &TestSlotHandler::VoidSlotIntValue );
1234 
1235  DALI_TEST_EQUALS( handler4.GetConnectionCount(), 1u, TEST_LOCATION );
1236  DALI_TEST_EQUALS( handler5.GetConnectionCount(), 1u, TEST_LOCATION );
1237  DALI_TEST_EQUALS( handler6.GetConnectionCount(), 1u, TEST_LOCATION );
1238  }
1239  // End of tempSignal lifetime
1240 
1241  DALI_TEST_EQUALS( handler4.GetConnectionCount(), 0u, TEST_LOCATION );
1242  DALI_TEST_EQUALS( handler5.GetConnectionCount(), 0u, TEST_LOCATION );
1243  DALI_TEST_EQUALS( handler6.GetConnectionCount(), 0u, TEST_LOCATION );
1244  END_TEST;
1245 }
1246 
1248 {
1249  TestSignals signals;
1250 
1251  // Test that connecting the same callback twice is a NOOP
1252  {
1253  TestSlotHandler handler1;
1254 
1255  // Note the double connection is intentional
1256  signals.SignalVoid1Value().Connect( &handler1, &TestSlotHandler::VoidSlotIntValue );
1257  signals.SignalVoid1Value().Connect( &handler1, &TestSlotHandler::VoidSlotIntValue );
1259 
1260  signals.EmitVoidSignal1IntValue( 6 );
1262  DALI_TEST_EQUALS( handler1.mIntParam1, 6, TEST_LOCATION );
1263 
1264  // Calling Disconnect once should be enough
1265  signals.SignalVoid1Value().Disconnect( &handler1, &TestSlotHandler::VoidSlotIntValue );
1266  DALI_TEST_CHECK( signals.SignalVoid1Value().Empty() );
1267  handler1.mIntParam1 = 0;
1268 
1269  signals.EmitVoidSignal1IntValue( 7 );
1270  DALI_TEST_EQUALS( handler1.mHandledCount, 1/*not incremented since last check*/, TEST_LOCATION );
1271  DALI_TEST_EQUALS( handler1.mIntParam1, 0, TEST_LOCATION );
1272  }
1273 
1274  // Test automatic disconnect after multiple Connect() calls
1275  {
1276  TestSlotHandler handler2;
1277  signals.SignalVoid1Value().Connect( &handler2, &TestSlotHandler::VoidSlotIntValue );
1278  signals.SignalVoid1Value().Connect( &handler2, &TestSlotHandler::VoidSlotIntValue );
1279 
1280  TestSlotHandler handler3;
1281  signals.SignalBool1Value().Connect( &handler3, &TestSlotHandler::BoolSlotFloatValue );
1282  signals.SignalBool1Value().Connect( &handler3, &TestSlotHandler::BoolSlotFloatValue );
1283 
1286  DALI_TEST_CHECK( ! signals.SignalVoid1Value().Empty() );
1287  DALI_TEST_CHECK( ! signals.SignalBool1Value().Empty() );
1288  }
1289  DALI_TEST_CHECK( signals.SignalVoid1Value().Empty() );
1290  DALI_TEST_CHECK( signals.SignalBool1Value().Empty() );
1291 
1292  // Should be NOOP
1293  signals.EmitVoidSignal1IntValue( 1 );
1294  signals.EmitBoolSignalFloatValue( 1.0f );
1295 
1296  // Test that connecting the same callback 10 times is a NOOP
1297  TestSlotHandler handler4;
1299  DALI_TEST_EQUALS( handler4.mFloatParam1, 0.0f, TEST_LOCATION );
1300 
1301  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1302  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1303  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1304  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1305  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1306  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1307  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1308  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1309  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1310  signals.SignalBool1Value().Connect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1311 
1312  signals.EmitBoolSignalFloatValue( 2.0f );
1314  DALI_TEST_EQUALS( handler4.mFloatParam1, 2.0f, TEST_LOCATION );
1315 
1316  // Calling Disconnect once should be enough
1317  signals.SignalBool1Value().Disconnect( &handler4, &TestSlotHandler::BoolSlotFloatValue );
1318  DALI_TEST_CHECK( signals.SignalBool1Value().Empty() );
1319 
1320  signals.EmitBoolSignalFloatValue( 3.0f );
1321  DALI_TEST_EQUALS( handler4.mHandledCount, 1/*not incremented since last check*/, TEST_LOCATION );
1322  DALI_TEST_EQUALS( handler4.mFloatParam1, 2.0f, TEST_LOCATION );
1323  END_TEST;
1324 }
1325 
1327 {
1328  TestSignals signals;
1329 
1330  // Test connecting two difference callbacks for the same ConnectionTracker
1331 
1332  TestSlotHandler handler1;
1333 
1334  {
1336 
1337  DALI_TEST_EQUALS( handler1.GetConnectionCount(), 0u, TEST_LOCATION );
1339  DALI_TEST_EQUALS( handler1.mIntParam1, 0, TEST_LOCATION );
1340 
1341  // Note that the duplicate connection is deliberate
1342  tempSignal.Connect( &handler1, &TestSlotHandler::VoidSlotIntValue );
1343  tempSignal.Connect( &handler1, &TestSlotHandler::VoidDuplicateSlotIntValue );
1344 
1345  DALI_TEST_EQUALS( handler1.GetConnectionCount(), 2u, TEST_LOCATION );
1347 
1348  tempSignal.Emit( 10 );
1349 
1351  DALI_TEST_EQUALS( handler1.mIntParam1, 10, TEST_LOCATION );
1352  DALI_TEST_EQUALS( handler1.mIntParam2, 10, TEST_LOCATION );
1353  }
1354  // End of tempSignal lifetime
1355 
1356  DALI_TEST_EQUALS( handler1.GetConnectionCount(), 0u, TEST_LOCATION );
1357  END_TEST;
1358 }
1359 
1360 
1362 {
1363  // void Func()
1364 
1365  {
1367  DALI_TEST_CHECK( signal.Empty() );
1368 
1369  signal.Connect( StaticVoidCallbackVoid );
1370  DALI_TEST_CHECK( ! signal.Empty() );
1371 
1373  signal.Emit();
1374  DALI_TEST_EQUALS( wasStaticVoidCallbackVoidCalled, true, TEST_LOCATION );
1375 
1376  signal.Disconnect( StaticVoidCallbackVoid );
1377  DALI_TEST_CHECK( signal.Empty() );
1378 
1379  wasStaticVoidCallbackVoidCalled = false;
1380  signal.Emit();
1381  DALI_TEST_EQUALS( wasStaticVoidCallbackVoidCalled, false, TEST_LOCATION );
1382  }
1383 
1384  // float Func()
1385 
1386  {
1388  DALI_TEST_CHECK( signal.Empty() );
1389 
1390  signal.Connect( StaticFloatCallbackVoid );
1391  DALI_TEST_CHECK( ! signal.Empty() );
1392 
1394  float result = signal.Emit();
1395  DALI_TEST_EQUALS( wasStaticFloatCallbackVoidCalled, true, TEST_LOCATION );
1396  DALI_TEST_EQUALS( result, 7.0f, TEST_LOCATION );
1397 
1398  signal.Disconnect( StaticFloatCallbackVoid );
1399  DALI_TEST_CHECK( signal.Empty() );
1400 
1401  wasStaticFloatCallbackVoidCalled = false;
1402  result = signal.Emit();
1403  DALI_TEST_EQUALS( wasStaticFloatCallbackVoidCalled, false, TEST_LOCATION );
1404  DALI_TEST_EQUALS( result, 0.0f, TEST_LOCATION );
1405  }
1406 
1407  // void Func( int )
1408 
1409  {
1411  DALI_TEST_CHECK( signal.Empty() );
1412 
1413  signal.Connect( StaticVoidCallbackIntValue );
1414  DALI_TEST_CHECK( ! signal.Empty() );
1415 
1417  staticIntValue = 0;
1418  signal.Emit( 10 );
1419  DALI_TEST_EQUALS( wasStaticVoidCallbackIntValueCalled, true, TEST_LOCATION );
1421 
1422  signal.Disconnect( StaticVoidCallbackIntValue );
1423  DALI_TEST_CHECK( signal.Empty() );
1424 
1425  wasStaticVoidCallbackIntValueCalled = false;
1426  staticIntValue = 0;
1427  signal.Emit( 11 );
1428  DALI_TEST_EQUALS( wasStaticVoidCallbackIntValueCalled, false, TEST_LOCATION );
1430  }
1431 
1432  // float Func( float, float )
1433 
1434  {
1436  DALI_TEST_CHECK( signal.Empty() );
1437 
1438  signal.Connect( StaticFloatCallbackFloatValueFloatValue );
1439  DALI_TEST_CHECK( ! signal.Empty() );
1440 
1442  staticFloatValue1 = 0.0f;
1443  staticFloatValue2 = 0.0f;
1444  float result = signal.Emit( 5.0f, 6.0f );
1445  DALI_TEST_EQUALS( wasStaticFloatCallbackFloatValueFloatValueCalled, true, TEST_LOCATION );
1448  DALI_TEST_EQUALS( result, 5.0f+6.0f, TEST_LOCATION );
1449 
1450  signal.Disconnect( StaticFloatCallbackFloatValueFloatValue );
1451  DALI_TEST_CHECK( signal.Empty() );
1452 
1453  wasStaticFloatCallbackFloatValueFloatValueCalled = false;
1454  staticFloatValue1 = 0.0f;
1455  staticFloatValue2 = 0.0f;
1456  result = signal.Emit( 7.0f, 8.0f );
1457  DALI_TEST_EQUALS( wasStaticFloatCallbackFloatValueFloatValueCalled, false, TEST_LOCATION );
1460  DALI_TEST_EQUALS( result, 0.0f, TEST_LOCATION );
1461  }
1462  END_TEST;
1463 }
1464 
1466 {
1467  // Test disconnection during each callback
1468 
1470  DALI_TEST_CHECK( signal.Empty() );
1471 
1472  TestSlotDisconnector handler1;
1473  handler1.VoidConnectVoid( signal );
1474  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1475  DALI_TEST_CHECK( ! signal.Empty() );
1476 
1477  signal.Emit();
1478  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1479  DALI_TEST_CHECK( signal.Empty() );
1480 
1481  // Repeat with 2 callbacks
1482 
1483  handler1.mHandled = false;
1484 
1485  TestSlotDisconnector handler2;
1486  handler1.VoidConnectVoid( signal );
1487  handler2.VoidConnectVoid( signal );
1488  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1489  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1490  DALI_TEST_CHECK( ! signal.Empty() );
1491 
1492  signal.Emit();
1493  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1494  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1495  DALI_TEST_CHECK( signal.Empty() );
1496 
1497  // Repeat with no callbacks
1498 
1499  handler1.mHandled = false;
1500  handler2.mHandled = false;
1501 
1502  signal.Emit();
1503  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1504  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1505 
1506  // Repeat with 3 callbacks
1507 
1508  TestSlotDisconnector handler3;
1509  handler1.VoidConnectVoid( signal );
1510  handler2.VoidConnectVoid( signal );
1511  handler3.VoidConnectVoid( signal );
1512  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1513  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1514  DALI_TEST_EQUALS( handler3.mHandled, false, TEST_LOCATION );
1515  DALI_TEST_CHECK( ! signal.Empty() );
1516 
1517  signal.Emit();
1518  DALI_TEST_EQUALS( handler1.mHandled, true, TEST_LOCATION );
1519  DALI_TEST_EQUALS( handler2.mHandled, true, TEST_LOCATION );
1520  DALI_TEST_EQUALS( handler3.mHandled, true, TEST_LOCATION );
1521  DALI_TEST_CHECK( signal.Empty() );
1522 
1523  // Repeat with no callbacks
1524 
1525  handler1.mHandled = false;
1526  handler2.mHandled = false;
1527  handler3.mHandled = false;
1528 
1529  signal.Emit();
1530  DALI_TEST_EQUALS( handler1.mHandled, false, TEST_LOCATION );
1531  DALI_TEST_EQUALS( handler2.mHandled, false, TEST_LOCATION );
1532  DALI_TEST_EQUALS( handler3.mHandled, false, TEST_LOCATION );
1533  END_TEST;
1534 }
1535 
1537 {
1538  // Test disconnection of some (but not all) callbacks during sigmal emission
1539 
1541  DALI_TEST_CHECK( signal.Empty() );
1542 
1543  TestSlotMultiDisconnector handler;
1544  handler.ConnectAll( signal );
1545  DALI_TEST_EQUALS( handler.mSlotHandled[0], false, TEST_LOCATION );
1546  DALI_TEST_EQUALS( handler.mSlotHandled[1], false, TEST_LOCATION );
1547  DALI_TEST_EQUALS( handler.mSlotHandled[2], false, TEST_LOCATION );
1548  DALI_TEST_EQUALS( handler.mSlotHandled[3], false, TEST_LOCATION );
1549  DALI_TEST_EQUALS( handler.mSlotHandled[4], false, TEST_LOCATION );
1550  DALI_TEST_EQUALS( handler.mSlotHandled[5], false, TEST_LOCATION );
1551  DALI_TEST_EQUALS( handler.mSlotHandled[6], false, TEST_LOCATION );
1552  DALI_TEST_EQUALS( handler.mSlotHandled[7], false, TEST_LOCATION );
1553  DALI_TEST_EQUALS( handler.mSlotHandled[8], false, TEST_LOCATION );
1554  DALI_TEST_EQUALS( handler.mSlotHandled[9], false, TEST_LOCATION );
1555  DALI_TEST_CHECK( ! signal.Empty() );
1556 
1557  signal.Emit();
1558 
1559  // Slots 5, 7, & 9 should be disconnected before being called
1560  DALI_TEST_EQUALS( handler.mSlotHandled[0], true, TEST_LOCATION );
1561  DALI_TEST_EQUALS( handler.mSlotHandled[1], true, TEST_LOCATION );
1562  DALI_TEST_EQUALS( handler.mSlotHandled[2], true, TEST_LOCATION );
1563  DALI_TEST_EQUALS( handler.mSlotHandled[3], true, TEST_LOCATION );
1564  DALI_TEST_EQUALS( handler.mSlotHandled[4], true, TEST_LOCATION );
1565  DALI_TEST_EQUALS( handler.mSlotHandled[5], false, TEST_LOCATION );
1566  DALI_TEST_EQUALS( handler.mSlotHandled[6], true, TEST_LOCATION );
1567  DALI_TEST_EQUALS( handler.mSlotHandled[7], false, TEST_LOCATION );
1568  DALI_TEST_EQUALS( handler.mSlotHandled[8], true, TEST_LOCATION );
1569  DALI_TEST_EQUALS( handler.mSlotHandled[9], false, TEST_LOCATION );
1570  DALI_TEST_CHECK( ! signal.Empty() );
1571 
1572  // Odd slots are disconnected
1573  DALI_TEST_EQUALS( handler.GetConnectionCount(), 5u, TEST_LOCATION );
1574  END_TEST;
1575 }
1576 
1578 {
1579  TestApplication app; // Create core for debug logging
1580 
1581  // for coverage purposes we test the emit guard for each signal type (0,1,2,3 params) void / return value
1582  {
1584  DALI_TEST_CHECK( signal.Empty() );
1585 
1586  TestEmitDuringCallback handler1;
1587  handler1.VoidConnectVoid( signal );
1588 
1589  // Test that this does not result in an infinite loop!
1590  signal.Emit();
1591  }
1592  {
1594 
1595  DALI_TEST_CHECK( signal.Empty() );
1596 
1597  TestEmitDuringCallback handler1;
1598  handler1.FloatRet0ParamConnect( signal );
1599 
1600  // Test that this does not result in an infinite loop!
1601  signal.Emit();
1602  }
1603  {
1605 
1606  DALI_TEST_CHECK( signal.Empty() );
1607 
1608  TestEmitDuringCallback handler1;
1609  handler1.FloatRet1ParamConnect( signal );
1610 
1611  // Test that this does not result in an infinite loop!
1612  signal.Emit( 1.f );
1613  }
1614  {
1616 
1617  DALI_TEST_CHECK( signal.Empty() );
1618 
1619  TestEmitDuringCallback handler1;
1620  handler1.FloatRet2ParamConnect( signal );
1621 
1622  // Test that this does not result in an infinite loop!
1623  signal.Emit( 1.f, 1.f );
1624  }
1625  {
1627 
1628  DALI_TEST_CHECK( signal.Empty() );
1629 
1630  TestEmitDuringCallback handler1;
1631  handler1.FloatRet3ParamConnect( signal );
1632 
1633  // Test that this does not result in an infinite loop!
1634  signal.Emit( 1.f,1.f,1.f );
1635  }
1636  END_TEST;
1637 }
1638 
1640 {
1641  // testing a signal deletion during an emit
1642  // need to dynamically allocate the signal for this to work
1643 
1644  TestApplication app; // Create core for debug logging
1645 
1647 
1648  TestEmitDuringCallback handler1;
1649  handler1.DeleteDuringEmitConnect( *signal );
1650 
1651  // should just log an error
1652  signal->Emit();
1653 
1654  tet_result( TET_PASS );
1655 
1656  END_TEST;
1657 }
1658 
1660 {
1661  // Test 1 signal connected to 1 Slot.
1662  // Signal dies first.
1663 
1664  TestButton* button = new TestButton(1);
1665  TestApp app;
1666  button->DownSignal().Connect(&app,&TestApp::OnButtonPress);
1667 
1668  // check we have both the button, and the app have 1 connection
1669  DALI_TEST_EQUALS( app.GetConnectionCount(), 1u, TEST_LOCATION );
1670  DALI_TEST_EQUALS( button->DownSignal().GetConnectionCount(), 1u, TEST_LOCATION );
1671 
1672  delete button; // should automatically destroy the connection
1673 
1674  // check we have a 0 connections
1675  DALI_TEST_EQUALS( app.GetConnectionCount(), 0u, TEST_LOCATION );
1676 
1677  END_TEST;
1678 }
1679 
1681 {
1682  // Test 1 signal connected to 1 Slot.
1683  // Slot owning object dies first.
1684 
1685  TestButton button(1);
1686  TestApp *app = new TestApp;
1687  button.DownSignal().Connect( app, &TestApp::OnButtonPress);
1688 
1689  // check we have a 1 connection
1690  DALI_TEST_EQUALS( app->GetConnectionCount(), 1u, TEST_LOCATION );
1691  DALI_TEST_EQUALS( button.DownSignal().GetConnectionCount(), 1u, TEST_LOCATION );
1692 
1693  delete app; // should automatically destroy the connection
1694 
1695  // check we have a 0 connections
1696  DALI_TEST_EQUALS( button.DownSignal().GetConnectionCount(), 0u, TEST_LOCATION );
1697  END_TEST;
1698 }
1699 
1701 {
1702  // Test 1 Signal connect to 2 slots
1703  // 1 of the slot owners dies. Then the second slot owner dies
1704 
1705  TestButton button(1);
1706  TestApp *app1 = new TestApp;
1707  TestApp *app2 = new TestApp;
1708 
1709  button.DownSignal().Connect( app1, &TestApp::OnButtonPress);
1710  button.DownSignal().Connect( app2, &TestApp::OnButtonPress);
1711 
1712  // check we have a 2 connections to the signal
1713  DALI_TEST_EQUALS( button.DownSignal().GetConnectionCount(), 2u, TEST_LOCATION );
1714 
1715  // kill the first slot
1716  delete app1; // should automatically destroy the connection
1717 
1718  // check we have 1 connection left
1719  DALI_TEST_EQUALS( button.DownSignal().GetConnectionCount(), 1u, TEST_LOCATION );
1720 
1721  button.Press(); // emit the signal (to ensure it doesn't seg fault)
1722 
1723  // kill the second slot
1724  delete app2; // should automatically destroy the connection
1725 
1726  // check we have 1 connection left
1727  DALI_TEST_EQUALS( button.DownSignal().GetConnectionCount(), 0u, TEST_LOCATION );
1728 
1729  END_TEST;
1730 }
1731 
1733 {
1734  // Test 1 Signal connected to 2 slots (with different owners)
1735  // The Signal dies, check the 2 slots disconnect automatically
1736 
1737  TestButton* button = new TestButton(1);
1738  TestApp app1;
1739  TestApp app2;
1740 
1741  button->DownSignal().Connect(&app1,&TestApp::OnButtonPress);
1742  button->DownSignal().Connect(&app2,&TestApp::OnButtonPress);
1743 
1744  // check the connection counts
1745  DALI_TEST_EQUALS( app1.GetConnectionCount(), 1u, TEST_LOCATION );
1746  DALI_TEST_EQUALS( app2.GetConnectionCount(), 1u, TEST_LOCATION );
1747  DALI_TEST_EQUALS( button->DownSignal().GetConnectionCount(), 2u, TEST_LOCATION );
1748 
1749  delete button; // should automatically destroy the connection
1750 
1751  // check both slot owners have zero connections
1752  DALI_TEST_EQUALS( app1.GetConnectionCount(), 0u, TEST_LOCATION );
1753  DALI_TEST_EQUALS( app2.GetConnectionCount(), 0u, TEST_LOCATION );
1754  END_TEST;
1755 }
1756 
1758 {
1759  // Test 2 Signals (with different owners) connected to 1 slots
1760  // 1 Signal dies, check that the remaining connection is valid
1761 
1762  TestButton* button1 = new TestButton(1); // use for signal 1
1763  TestButton* button2 = new TestButton(2); // use for signal 2
1764 
1765  TestApp app;
1766 
1767  button1->DownSignal().Connect(&app,&TestApp::OnButtonPress);
1768  button2->DownSignal().Connect(&app,&TestApp::OnButtonPress);
1769 
1770  // check the connection counts
1771  DALI_TEST_EQUALS( app.GetConnectionCount(), 2u, TEST_LOCATION );
1772  DALI_TEST_EQUALS( button1->DownSignal().GetConnectionCount(), 1u, TEST_LOCATION );
1773  DALI_TEST_EQUALS( button2->DownSignal().GetConnectionCount(), 1u, TEST_LOCATION );
1774 
1775  // make sure both signals emit ok
1776  button2->Press();
1778 
1779  button1->Press();
1781 
1782  delete button1; // should automatically destroy 1 connection
1783 
1784  // check both slot owners have zero connections
1785  DALI_TEST_EQUALS( app.GetConnectionCount(), 1u, TEST_LOCATION );
1786 
1787  // check remaining connection still works
1788  button2->Press();
1790 
1791  // kill the last signal
1792  delete button2;
1793  DALI_TEST_EQUALS( app.GetConnectionCount(), 0u, TEST_LOCATION );
1794  END_TEST;
1795 }
1796 
1798 {
1799  Signal< bool () > boolSignal;
1800  TestApp app;
1801  bool result(false);
1802 
1803  // connect a slot which will return false
1804  boolSignal.Connect( &app, &TestApp::BoolReturnTestFalse);
1805  result = boolSignal.Emit();
1806  DALI_TEST_EQUALS( result, false, TEST_LOCATION );
1807 
1808  // disconnect last slot, and connect a slot which returns true
1809  boolSignal.Disconnect( &app, &TestApp::BoolReturnTestFalse);
1810  boolSignal.Connect( &app, &TestApp::BoolReturnTestTrue);
1811  result = boolSignal.Emit();
1812  DALI_TEST_EQUALS( result, true, TEST_LOCATION );
1813  END_TEST;
1814 }
1815 
1817 {
1818  TestSignals signals;
1819 
1820  {
1821  TestSlotDelegateHandler handlers;
1822  signals.SignalVoidNone().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
1823  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1824  signals.EmitVoidSignalVoid();
1825  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1826 
1827  // Test double emission
1828  handlers.mHandled = false;
1829  signals.EmitVoidSignalVoid();
1830  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1831  }
1832  signals.CheckNoConnections();
1833 
1834  {
1835  TestSlotDelegateHandler handlers;
1837  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1838  int x = 7;
1839  signals.EmitVoidSignalIntRef(x);
1840  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1841  DALI_TEST_EQUALS( handlers.mIntParam1, 7, TEST_LOCATION );
1842  }
1843  signals.CheckNoConnections();
1844 
1845  {
1846  TestSlotDelegateHandler handlers;
1848  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1849  signals.EmitVoidSignal1IntValue(5);
1850  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1851  DALI_TEST_EQUALS( handlers.mIntParam1, 5, TEST_LOCATION );
1852  }
1853  signals.CheckNoConnections();
1854 
1855  {
1856  TestSlotDelegateHandler handlers;
1858  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1859  signals.EmitVoidSignal2IntValue(6, 7);
1860  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1861  DALI_TEST_EQUALS( handlers.mIntParam1, 6, TEST_LOCATION );
1862  DALI_TEST_EQUALS( handlers.mIntParam2, 7, TEST_LOCATION );
1863  }
1864  signals.CheckNoConnections();
1865 
1866  {
1867  TestSlotDelegateHandler handlers;
1869  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1870 
1871  handlers.mBoolReturn = true;
1873  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1874  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
1875 
1876  // repeat with opposite return value
1877  handlers.mBoolReturn = false;
1878  handlers.mHandled = false;
1879  DALI_TEST_EQUALS( signals.EmitBoolSignalFloatValue(6.0f), false, TEST_LOCATION );
1880  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1881  DALI_TEST_EQUALS( handlers.mFloatParam1, 6.0f, TEST_LOCATION );
1882  }
1883  signals.CheckNoConnections();
1884 
1885  {
1886  TestSlotDelegateHandler handlers;
1888  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1889  handlers.mBoolReturn = true;
1891  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1892  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
1893  DALI_TEST_EQUALS( handlers.mIntParam2, 10, TEST_LOCATION );
1894  }
1895  signals.CheckNoConnections();
1896 
1897  {
1898  TestSlotDelegateHandler handlers;
1900  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1901  handlers.mIntReturn = 27;
1902  int x = signals.EmitIntSignalFloatValueIntValue(33.5f, 5);
1903  DALI_TEST_EQUALS( x, 27, TEST_LOCATION );
1904  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1905  DALI_TEST_EQUALS( handlers.mFloatParam1, 33.5f, TEST_LOCATION );
1906  DALI_TEST_EQUALS( handlers.mIntParam2, 5, TEST_LOCATION );
1907  }
1908  signals.CheckNoConnections();
1909 
1910  {
1911  TestSlotDelegateHandler handlers;
1912  signals.SignalFloat0().Connect( handlers.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotVoid );
1913  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1914  handlers.mFloatReturn = 27.0f;
1915  float f = signals.EmitFloat0Signal();
1916  DALI_TEST_EQUALS( f, 27.0f, TEST_LOCATION );
1917  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1918  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
1919  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
1920  }
1921  signals.CheckNoConnections();
1922 
1923  {
1924  TestSlotDelegateHandler handlers;
1926  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1927  handlers.mFloatReturn = 27.0f;
1928  float f = signals.EmitFloat2VSignal(5, 33.0f);
1929  DALI_TEST_EQUALS( f, 27.0f, TEST_LOCATION );
1930  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1931  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
1932  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
1933  }
1934  signals.CheckNoConnections();
1935 
1936  {
1937  TestSlotDelegateHandler handlers;
1939  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1940  signals.EmitVoidSignalFloatValue3(5, 33.0f, 100.0f);
1941  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1942  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
1943  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
1944  DALI_TEST_EQUALS( handlers.mFloatParam3, 100.0f, 0.001f, TEST_LOCATION );
1945  }
1946  signals.CheckNoConnections();
1947 
1948  {
1949  TestSlotDelegateHandler handlers;
1951  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
1952  handlers.mFloatReturn = 27.0f;
1953  float returnValue = signals.EmitFloat3VSignal(5, 33.0f, 100.0f);
1954  DALI_TEST_EQUALS( returnValue, 27.0f, TEST_LOCATION );
1955  DALI_TEST_EQUALS( handlers.mHandled, true, TEST_LOCATION );
1956  DALI_TEST_EQUALS( handlers.mFloatParam1, 5.0f, TEST_LOCATION );
1957  DALI_TEST_EQUALS( handlers.mFloatParam2, 33.0f, 0.001f, TEST_LOCATION );
1958  DALI_TEST_EQUALS( handlers.mFloatParam3, 100.0f, 0.001f, TEST_LOCATION );
1959  }
1960  signals.CheckNoConnections();
1961  END_TEST;
1962 }
1963 
1965 {
1966  // Test that signal disconnect works when slot-delegate is destroyed (goes out of scope)
1967 
1968  {
1970  {
1971  DALI_TEST_CHECK( signal.Empty() );
1972  TestSlotDelegateHandler handler;
1973  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid );
1974  DALI_TEST_CHECK( ! signal.Empty() );
1975  }
1976  // End of slot lifetime
1977  DALI_TEST_CHECK( signal.Empty() );
1978 
1979  // Signal emission should be a NOOP
1980  signal.Emit();
1981  }
1982 
1983  {
1985  {
1986  DALI_TEST_CHECK( signal.Empty() );
1987  TestSlotDelegateHandler handler;
1988  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValue );
1989  DALI_TEST_CHECK( ! signal.Empty() );
1990  }
1991  // End of slot lifetime
1992  DALI_TEST_CHECK( signal.Empty() );
1993 
1994  // Signal emission should be a NOOP
1995  signal.Emit( 10 );
1996  }
1997 
1998  {
2000  {
2001  DALI_TEST_CHECK( signal.Empty() );
2002  TestSlotDelegateHandler handler;
2003  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntRef );
2004  DALI_TEST_CHECK( ! signal.Empty() );
2005  }
2006  // End of slot lifetime
2007  DALI_TEST_CHECK( signal.Empty() );
2008 
2009  // Signal emission should be a NOOP
2010  int temp( 5 );
2011  signal.Emit( temp );
2012  }
2013 
2014  {
2016  {
2017  DALI_TEST_CHECK( signal.Empty() );
2018  TestSlotDelegateHandler handler;
2019  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntValueIntValue );
2020  DALI_TEST_CHECK( ! signal.Empty() );
2021  }
2022  // End of slot lifetime
2023  DALI_TEST_CHECK( signal.Empty() );
2024 
2025  // Signal emission should be a NOOP
2026  signal.Emit( 1, 2 );
2027  }
2028 
2029  {
2031  {
2032  DALI_TEST_CHECK( signal.Empty() );
2033  TestSlotDelegateHandler handler;
2034  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::BoolSlotFloatValue );
2035  DALI_TEST_CHECK( ! signal.Empty() );
2036  }
2037  // End of slot lifetime
2038  DALI_TEST_CHECK( signal.Empty() );
2039 
2040  // Signal emission should be a NOOP
2041  bool blah = signal.Emit( 1.0f );
2042  DALI_TEST_CHECK( ! blah );
2043  }
2044 
2045  {
2047  {
2048  DALI_TEST_CHECK( signal.Empty() );
2049  TestSlotDelegateHandler handler;
2050  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::BoolSlotFloatValueIntValue );
2051  DALI_TEST_CHECK( ! signal.Empty() );
2052  }
2053  // End of slot lifetime
2054  DALI_TEST_CHECK( signal.Empty() );
2055 
2056  // Signal emission should be a NOOP
2057  bool blah = signal.Emit( 1.0f, 2 );
2058  DALI_TEST_CHECK( ! blah );
2059  }
2060 
2061  {
2063  {
2064  DALI_TEST_CHECK( signal.Empty() );
2065  TestSlotDelegateHandler handler;
2066  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::IntSlotFloatValueIntValue );
2067  DALI_TEST_CHECK( ! signal.Empty() );
2068  }
2069  // End of slot lifetime
2070  DALI_TEST_CHECK( signal.Empty() );
2071 
2072  // Signal emission should be a NOOP
2073  int blah = signal.Emit( 10.0f, 100 );
2074  DALI_TEST_CHECK( 0 == blah );
2075  }
2076 
2077  {
2079  {
2080  DALI_TEST_CHECK( signal.Empty() );
2081  TestSlotDelegateHandler handler;
2082  signal.Connect( handler.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotVoid );
2083  DALI_TEST_CHECK( ! signal.Empty() );
2084  }
2085  // End of slot lifetime
2086  DALI_TEST_CHECK( signal.Empty() );
2087 
2088  // Signal emission should be a NOOP
2089  float blah = signal.Emit();
2090  DALI_TEST_CHECK( 0.0f == blah );
2091  }
2092 
2093  {
2095  {
2096  DALI_TEST_CHECK( signal.Empty() );
2097  TestSlotDelegateHandler handler;
2098  signal.Connect(handler.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotFloatValueFloatValue);
2099  DALI_TEST_CHECK( ! signal.Empty() );
2100  }
2101  // End of slot lifetime
2102  DALI_TEST_CHECK( signal.Empty() );
2103 
2104  // Signal emission should be a NOOP
2105  float blah = signal.Emit( 3.0f, 4.0f );
2106  DALI_TEST_CHECK( 0.0f == blah );
2107  }
2108  END_TEST;
2109 }
2110 
2112 {
2113  // Test that callbacks don't occur if a signal is disconnected before emission
2114 
2115  TestSignals signals;
2116 
2117  {
2118  TestSlotDelegateHandler handlers;
2120  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2121  signals.SignalVoidNone().Disconnect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotVoid);
2122  signals.EmitVoidSignalVoid();
2123  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2124  }
2125 
2126  {
2127  TestSlotDelegateHandler handlers;
2129  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2130  int r = 7;
2131  handlers.mIntReturn = 5;
2132  signals.SignalVoid1Ref().Disconnect(handlers.mSlotDelegate, &TestSlotDelegateHandler::VoidSlotIntRef);
2133  signals.EmitVoidSignalIntRef(r);
2134  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2135  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
2137  }
2138 
2139  {
2140  TestSlotDelegateHandler handlers;
2142  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2144  signals.EmitVoidSignal1IntValue(5);
2145  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2146  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
2147  }
2148 
2149  {
2150  TestSlotDelegateHandler handlers;
2152  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2154  signals.EmitVoidSignal2IntValue(5, 10);
2155  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2156  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
2157  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
2158  }
2159 
2160  {
2161  TestSlotDelegateHandler handlers;
2163  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2164  handlers.mBoolReturn = true;
2166  DALI_TEST_EQUALS( signals.EmitBoolSignalFloatValue(5.0f), false, TEST_LOCATION );
2167  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2168  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
2169  }
2170 
2171  {
2172  TestSlotDelegateHandler handlers;
2174  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2175  handlers.mBoolReturn = true;
2178  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2179  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, TEST_LOCATION );
2180  DALI_TEST_EQUALS( handlers.mIntParam2, 0, TEST_LOCATION );
2181  }
2182 
2183  {
2184  TestSlotDelegateHandler handlers;
2186  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2187  handlers.mIntReturn = 27;
2189  signals.EmitIntSignalFloatValueIntValue(5, 33.0f);
2190  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2191  DALI_TEST_EQUALS( handlers.mIntParam1, 0, TEST_LOCATION );
2192  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
2193  }
2194 
2195  {
2196  TestSlotDelegateHandler handlers;
2198  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2199  handlers.mFloatReturn = 27.0f;
2200  signals.SignalFloat0().Disconnect(handlers.mSlotDelegate, &TestSlotDelegateHandler::FloatSlotVoid);
2201  signals.EmitFloat0Signal();
2202  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2203  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
2204  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
2205  }
2206 
2207  {
2208  TestSlotDelegateHandler handlers;
2210  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2211  handlers.mFloatReturn = 27.0f;
2213  signals.EmitFloat2VSignal(5, 33.0f);
2214  DALI_TEST_EQUALS( handlers.mHandled, false, TEST_LOCATION );
2215  DALI_TEST_EQUALS( handlers.mFloatParam1, 0.0f, 0.001f, TEST_LOCATION );
2216  DALI_TEST_EQUALS( handlers.mFloatParam2, 0.0f, 0.001f, TEST_LOCATION );
2217  }
2218  END_TEST;
2219 }
2220 
2221 
2223 {
2224  // simple constructor for coverage
2225  CallbackBase base;
2226  tet_result( TET_PASS );
2227  END_TEST;
2228 }
Dali Docs Home
Read more about Dali