Moved (DEFAULT|DEBUG)_BACKGROUND_COLOR out of Stage and over to constants.h
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Stage.cpp
1 /*
2  * Copyright (c) 2020 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 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/common/stage-devel.h>
24 #include <dali/integration-api/context-notifier.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/wheel-event-integ.h>
29
30 #include <dali-test-suite-utils.h>
31
32 using namespace Dali;
33
34 void stage_test_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void stage_test_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 namespace
45 {
46
47 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
48
49 // Functor for EventProcessingFinished signal
50 struct EventProcessingFinishedFunctor
51 {
52   /**
53    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
54    */
55   EventProcessingFinishedFunctor( bool& eventProcessingFinished )
56   : mEventProcessingFinished( eventProcessingFinished )
57   {}
58
59   void operator()()
60   {
61     mEventProcessingFinished = true;
62   }
63
64   bool& mEventProcessingFinished;
65 };
66
67 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
68 struct KeyEventGeneratedSignalData
69 {
70   KeyEventGeneratedSignalData()
71   : functorCalled(false)
72   {}
73
74   void Reset()
75   {
76     functorCalled = false;
77
78     receivedKeyEvent.Reset();
79   }
80
81   bool functorCalled;
82   KeyEvent receivedKeyEvent;
83 };
84
85 // Functor that sets the data when called
86 struct KeyEventGeneratedReceivedFunctor
87 {
88   KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
89   : signalData( data )
90   {}
91
92   bool operator()( const KeyEvent& keyEvent )
93   {
94     signalData.functorCalled = true;
95     signalData.receivedKeyEvent = keyEvent;
96
97     return true;
98   }
99
100   bool operator()()
101   {
102     signalData.functorCalled = true;
103     return true;
104   }
105
106   KeyEventGeneratedSignalData& signalData;
107 };
108
109 // Stores data that is populated in the key-event callback and will be read by the TET cases
110 struct KeyEventSignalData
111 {
112   KeyEventSignalData()
113   : functorCalled(false)
114   {}
115
116   void Reset()
117   {
118     functorCalled = false;
119
120     receivedKeyEvent.Reset();
121   }
122
123   bool functorCalled;
124   KeyEvent receivedKeyEvent;
125 };
126
127 // Functor that sets the data when called
128 struct KeyEventReceivedFunctor
129 {
130   KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
131
132   bool operator()( const KeyEvent& keyEvent )
133   {
134     signalData.functorCalled = true;
135     signalData.receivedKeyEvent = keyEvent;
136
137     return true;
138   }
139
140   KeyEventSignalData& signalData;
141 };
142
143 // Stores data that is populated in the touched signal callback and will be read by the TET cases
144 struct TouchSignalData
145 {
146   TouchSignalData()
147   : functorCalled(false)
148   {}
149
150   void Reset()
151   {
152     functorCalled = false;
153
154     receivedTouchEvent.Reset();
155   }
156
157   bool functorCalled;
158   TouchEvent receivedTouchEvent;
159 };
160
161 // Functor that sets the data when touched signal is received
162 struct TouchFunctor
163 {
164   TouchFunctor( TouchSignalData& data ) : signalData( data ) { }
165
166   void operator()( const TouchEvent& touch )
167   {
168     signalData.functorCalled = true;
169     TouchEvent handle(touch);
170     signalData.receivedTouchEvent = handle;
171   }
172
173   void operator()()
174   {
175     signalData.functorCalled = true;
176   }
177
178   TouchSignalData& signalData;
179 };
180
181 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
182 struct WheelEventSignalData
183 {
184   WheelEventSignalData()
185   : functorCalled(false)
186   {}
187
188   void Reset()
189   {
190     functorCalled = false;
191   }
192
193   bool functorCalled;
194   WheelEvent receivedWheelEvent;
195 };
196
197 // Functor that sets the data when wheel-event signal is received
198 struct WheelEventReceivedFunctor
199 {
200   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
201
202   bool operator()( const WheelEvent& wheelEvent )
203   {
204     signalData.functorCalled = true;
205     signalData.receivedWheelEvent = wheelEvent;
206
207     return true;
208   }
209
210   WheelEventSignalData& signalData;
211 };
212
213 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
214 {
215   return true;
216 }
217
218 struct ContextStatusFunctor
219 {
220   ContextStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
221   {
222     mCalledFlag = false;
223   }
224
225   void operator()()
226   {
227     mCalledFlag = true;
228   }
229   void Reset()
230   {
231     mCalledFlag = false;
232   }
233
234   bool& mCalledFlag;
235 };
236
237 struct SceneCreatedStatusFunctor
238 {
239   SceneCreatedStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
240   {
241     mCalledFlag = false;
242   }
243
244   void operator()()
245   {
246     mCalledFlag = true;
247   }
248   void Reset()
249   {
250     mCalledFlag = false;
251   }
252
253   bool& mCalledFlag;
254 };
255
256 struct ActorCreatedFunctor
257 {
258   ActorCreatedFunctor( bool& signalReceived )
259   : mSignalVerified( signalReceived )
260   {
261   }
262
263   void operator()( BaseHandle object )
264   {
265     tet_infoline( "Verifying TestActorCallback()" );
266     Actor actor = Actor::DownCast( object );
267     if( actor )
268     {
269       mSignalVerified = true;
270     }
271   }
272
273   bool& mSignalVerified;
274 };
275
276 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
277 {
278   Integration::TouchEvent touchEvent;
279   Integration::Point point;
280   point.SetState( state );
281   point.SetScreenPosition( screenPosition );
282   touchEvent.points.push_back( point );
283   application.ProcessEvent( touchEvent );
284 }
285
286 } // unnamed namespace
287
288
289 int UtcDaliStageDefaultConstructorP(void)
290 {
291   TestApplication application;
292   Stage stage;
293
294   DALI_TEST_CHECK( !stage );
295   END_TEST;
296 }
297
298 // Note: No negative test for default constructor.
299
300 int UtcDaliStageDestructorP(void)
301 {
302   TestApplication application;
303   Stage* stage = new Stage();
304   delete stage;
305   stage = NULL;
306
307   DALI_TEST_CHECK( true );
308   END_TEST;
309 }
310
311 // Note: No negative test for default destructor.
312
313 int UtcDaliStageGetCurrentP(void)
314 {
315   TestApplication application;
316   Stage stage = Stage::GetCurrent();
317
318   DALI_TEST_CHECK( stage );
319   END_TEST;
320 }
321
322 int UtcDaliStageGetCurrentN(void)
323 {
324   bool asserted = false;
325   try
326   {
327     Stage stage = Stage::GetCurrent();
328   }
329   catch( Dali::DaliException& e )
330   {
331     DALI_TEST_PRINT_ASSERT( e );
332     DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
333     asserted = true;
334   }
335
336   DALI_TEST_CHECK( asserted );
337   END_TEST;
338 }
339
340 int UtcDaliStageIsInstalledP(void)
341 {
342   TestApplication application;
343
344   Stage::GetCurrent();
345
346   DALI_TEST_CHECK( Stage::IsInstalled() );
347   END_TEST;
348 }
349
350 int UtcDaliStageIsInstalledN(void)
351 {
352   DALI_TEST_CHECK( !Stage::IsInstalled() );
353
354   END_TEST;
355 }
356
357 int UtcDaliStageCopyConstructorP(void)
358 {
359   TestApplication application;
360   Stage stage = Stage::GetCurrent();
361
362   Stage copyStage( stage );
363
364   DALI_TEST_CHECK( copyStage );
365   DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
366
367   END_TEST;
368 }
369
370 // Note: no negative test for UtcDaliStageCopyConstructor.
371
372 int UtcDaliStageAssignmentOperatorP(void)
373 {
374   TestApplication application;
375   const Stage stage = Stage::GetCurrent();
376
377   Stage copyStage = stage;
378
379   DALI_TEST_CHECK( copyStage );
380   DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
381
382   END_TEST;
383 }
384
385 // Note: No negative test for UtcDaliStageAssignmentOperator.
386
387 int UtcDaliStageAddP(void)
388 {
389   TestApplication application;
390
391   Stage stage = Stage::GetCurrent();
392
393   Actor actor = Actor::New();
394   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
395
396   stage.Add( actor );
397   DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
398   END_TEST;
399 }
400
401 int UtcDaliStageAddN(void)
402 {
403   TestApplication application;
404
405   Stage stage = Stage::GetCurrent();
406   Actor actor;
407
408   bool asserted = false;
409   try
410   {
411     stage.Add( actor );
412   }
413   catch( Dali::DaliException& e )
414   {
415     DALI_TEST_PRINT_ASSERT( e );
416     DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
417     asserted = true;
418   }
419
420   DALI_TEST_CHECK( asserted );
421
422   END_TEST;
423 }
424
425 int UtcDaliStageRemoveP(void)
426 {
427   TestApplication application;
428
429   Stage stage = Stage::GetCurrent();
430
431   Actor actor = Actor::New();
432   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
433
434   stage.Add( actor );
435   DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
436
437   stage.Remove(actor);
438   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
439   END_TEST;
440 }
441
442 int UtcDaliStageRemoveN1(void)
443 {
444   TestApplication application;
445
446   Stage stage = Stage::GetCurrent();
447   Actor actor;
448
449   bool asserted = false;
450   try
451   {
452     // Actor is not valid, confirm a removal attempt does assert.
453     stage.Remove( actor );
454   }
455   catch( Dali::DaliException& e )
456   {
457     DALI_TEST_PRINT_ASSERT( e );
458     DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
459     asserted = true;
460   }
461
462   DALI_TEST_CHECK( asserted );
463   END_TEST;
464 }
465
466 int UtcDaliStageRemoveN2(void)
467 {
468   TestApplication application;
469
470   Stage stage = Stage::GetCurrent();
471   Actor actor = Actor::New();
472   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
473
474   bool asserted = false;
475   try
476   {
477     // Actor is not on stage, confirm a removal attempt does not assert / segfault.
478     stage.Remove( actor );
479   }
480   catch( Dali::DaliException& e )
481   {
482     DALI_TEST_PRINT_ASSERT( e );
483     asserted = true;
484   }
485
486   DALI_TEST_CHECK( !asserted );
487   END_TEST;
488 }
489
490 int UtcDaliStageRemoveN3(void)
491 {
492   TestApplication application;
493
494   Stage stage = Stage::GetCurrent();
495
496   // Initially we have a default layer
497   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
498
499   // Check we cannot remove the root layer from the stage.
500   Layer layer = stage.GetRootLayer();
501   bool asserted = true;
502   try
503   {
504     stage.Remove( layer );
505   }
506   catch( Dali::DaliException& e )
507   {
508     DALI_TEST_PRINT_ASSERT( e );
509     DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
510     asserted = true;
511   }
512
513   DALI_TEST_CHECK( asserted );
514   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
515   END_TEST;
516 }
517
518 int UtcDaliStageGetSizeP(void)
519 {
520   TestApplication application;
521
522   Stage stage = Stage::GetCurrent();
523
524   Vector2 size = stage.GetSize();
525
526   DALI_TEST_EQUALS( size.width,  static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ),  TEST_LOCATION );
527   DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
528   END_TEST;
529 }
530
531 int UtcDaliStageGetSizeN(void)
532 {
533   TestApplication application;
534
535   Stage stage;
536
537   bool asserted = false;
538   Vector2 size;
539   try
540   {
541     size = stage.GetSize();
542   }
543   catch( Dali::DaliException& e )
544   {
545     DALI_TEST_PRINT_ASSERT( e );
546     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
547     asserted = true;
548   }
549
550   DALI_TEST_CHECK( asserted );
551   END_TEST;
552 }
553
554 int UtcDaliStageGetDpiP1(void)
555 {
556   TestApplication application; // Initializes core DPI to default values
557
558   Stage stage = Stage::GetCurrent();
559
560   // Test the default DPI.
561   Vector2 dpi = stage.GetDpi();
562   DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
563   DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ),   TEST_LOCATION );
564   END_TEST;
565 }
566
567 int UtcDaliStageGetDpiP2(void)
568 {
569   TestApplication application; // Initializes core DPI to default values
570
571   // Test that setting core DPI explicitly also sets up the Stage's DPI.
572   Dali::Integration::Scene scene = application.GetScene();
573   scene.SetDpi( Vector2(200.0f, 180.0f) );
574
575   Stage stage = Stage::GetCurrent();
576   Vector2 dpi = stage.GetDpi();
577   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
578   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
579   END_TEST;
580 }
581
582 int UtcDaliStageGetDpiP3(void)
583 {
584   TestApplication application( 480, 800, 72, 120 ); // Initializes core DPI with specific values
585
586   Stage stage = Stage::GetCurrent();
587
588   // Test that setting core DPI explicitly also sets up the Stage's DPI.
589   Vector2 dpi = stage.GetDpi();
590   DALI_TEST_EQUALS( dpi.x, 72.0f, TEST_LOCATION );
591   DALI_TEST_EQUALS( dpi.y, 120.0f, TEST_LOCATION) ;
592   END_TEST;
593 }
594
595 /*
596  * This is not a true negative test, we are checking the DPI if it has not been set.
597  * A test for setting negative DPI values would be part of the application core utc tests.
598  */
599 int UtcDaliStageGetDpiN(void)
600 {
601   TestApplication application; // Initializes core DPI to default values
602
603   Stage stage = Stage::GetCurrent();
604   Vector2 dpi = stage.GetDpi();
605
606   DALI_TEST_EQUALS( dpi.x, 220.0f, TEST_LOCATION );
607   DALI_TEST_EQUALS( dpi.y, 217.0f, TEST_LOCATION );
608   END_TEST;
609 }
610
611 int UtcDaliStageGetLayerCountP(void)
612 {
613   TestApplication application;
614
615   Stage stage = Stage::GetCurrent();
616
617   // Initially we have a default layer
618   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
619
620   Layer layer = Layer::New();
621   stage.Add( layer );
622
623   DALI_TEST_EQUALS( stage.GetLayerCount(), 2u, TEST_LOCATION );
624   END_TEST;
625 }
626
627 /*
628  * Not a true negative test, but confirms layer count is not affected by an invalid removal.
629  */
630 int UtcDaliStageGetLayerCountN(void)
631 {
632   TestApplication application;
633
634   Stage stage = Stage::GetCurrent();
635
636   // Initially we have a default layer
637   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
638
639   Layer layer = Layer::New();
640   stage.Remove( layer );
641
642   // Still have 1 layer.
643   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
644   END_TEST;
645 }
646
647 int UtcDaliStageGetLayerP(void)
648 {
649   TestApplication application;
650
651   Stage stage = Stage::GetCurrent();
652
653   Layer rootLayer = stage.GetLayer( 0 );
654   DALI_TEST_CHECK( rootLayer );
655
656   Layer layer = Layer::New();
657   stage.Add( layer );
658
659   Layer sameLayer = stage.GetLayer( 1 );
660   DALI_TEST_CHECK( layer == sameLayer );
661   END_TEST;
662 }
663
664 int UtcDaliStageGetLayerN(void)
665 {
666   TestApplication application;
667
668   Stage stage = Stage::GetCurrent();
669
670   bool asserted = false;
671   try
672   {
673     // Try to get a layer that doesn't exist (note: 0 is the root layer).
674     Layer layer = stage.GetLayer( 1 );
675   }
676   catch( Dali::DaliException& e )
677   {
678     DALI_TEST_PRINT_ASSERT( e );
679     DALI_TEST_ASSERT( e, "depth < mLayers.size()", TEST_LOCATION );
680     asserted = true;
681   }
682
683   DALI_TEST_CHECK( asserted );
684   END_TEST;
685 }
686
687 int UtcDaliStageGetRootLayerP(void)
688 {
689   TestApplication application;
690
691   Stage stage = Stage::GetCurrent();
692
693   Layer layer = stage.GetLayer( 0 );
694   DALI_TEST_CHECK( layer );
695
696   // Check that GetRootLayer() correctly retreived layer 0.
697   DALI_TEST_CHECK( stage.GetRootLayer() == layer );
698
699   END_TEST;
700 }
701
702 int UtcDaliStageGetRootLayerN(void)
703 {
704   TestApplication application;
705
706   Stage stage = Stage::GetCurrent();
707
708   Layer rootLayer = stage.GetLayer( 0 );
709   DALI_TEST_CHECK( rootLayer );
710   DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
711
712   // Create a new layer and attempt to lower it below the root layer.
713   Layer layer = Layer::New();
714   stage.Add( layer );
715   layer.LowerToBottom();
716
717   // Check that GetRootLayer still retrieves the same original layer.
718   DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
719
720   // Check modifying the root layer is also blocked.
721   rootLayer.RaiseToTop();
722   DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
723
724   END_TEST;
725 }
726
727 int UtcDaliStageSetBackgroundColorP(void)
728 {
729   TestApplication application;
730
731   Stage stage = Stage::GetCurrent();
732
733   Vector4 testColor( 0.1f, 0.2f, 0.3f, 1.0f );
734   stage.SetBackgroundColor( testColor );
735
736   DALI_TEST_EQUALS( testColor, stage.GetBackgroundColor(), TEST_LOCATION );
737   END_TEST;
738 }
739
740 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
741 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
742
743 int UtcDaliStageGetBackgroundColorP(void)
744 {
745   TestApplication application;
746
747   Stage stage = Stage::GetCurrent();
748
749   DALI_TEST_EQUALS( DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION );
750   END_TEST;
751 }
752
753 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
754
755 int UtcDaliStageKeepRenderingP(void)
756 {
757   TestApplication application;
758
759   Stage stage = Stage::GetCurrent();
760
761   // Run core until it wants to sleep
762   bool keepUpdating( true );
763   while ( keepUpdating )
764   {
765     application.SendNotification();
766     keepUpdating = application.Render( 1000.0f /*1 second*/ );
767   }
768
769   // Force rendering for the next 5 seconds
770   stage.KeepRendering( 5.0f );
771
772   application.SendNotification();
773
774   // Test that core wants to sleep after 10 seconds
775   keepUpdating = application.Render( 1000.0f /*1 second*/ );
776   DALI_TEST_CHECK( keepUpdating );
777   keepUpdating = application.Render( 1000.0f /*2 seconds*/ );
778   DALI_TEST_CHECK( keepUpdating );
779   keepUpdating = application.Render( 1000.0f /*3 seconds*/ );
780   DALI_TEST_CHECK( keepUpdating );
781   keepUpdating = application.Render( 1000.0f /*4 seconds*/ );
782   DALI_TEST_CHECK( keepUpdating );
783   keepUpdating = application.Render( 1000.0f /*5 seconds*/ );
784   DALI_TEST_CHECK( !keepUpdating );
785   END_TEST;
786 }
787
788 int UtcDaliStageKeepRenderingN(void)
789 {
790   TestApplication application;
791
792   Stage stage = Stage::GetCurrent();
793
794   // Run core until it wants to sleep
795   bool keepUpdating( true );
796   while ( keepUpdating )
797   {
798     application.SendNotification();
799     keepUpdating = application.Render( 1000.0f /*1 second*/ );
800   }
801
802   // Force rendering for the next 5 seconds
803   stage.KeepRendering( -1.0f );
804
805   application.SendNotification();
806
807   // Test that core wants to sleep after 10 seconds
808   keepUpdating = application.Render( 1000.0f /*1 second*/ );
809   DALI_TEST_CHECK( !keepUpdating );
810
811   END_TEST;
812 }
813
814 int UtcDaliStageEventProcessingFinishedP(void)
815 {
816   TestApplication application;
817   Stage stage = Stage::GetCurrent();
818
819   bool eventProcessingFinished = false;
820   EventProcessingFinishedFunctor functor( eventProcessingFinished );
821   stage.EventProcessingFinishedSignal().Connect( &application, functor );
822
823   Actor actor( Actor::New() );
824   stage.Add( actor );
825
826   application.SendNotification();
827   application.Render();
828
829   DALI_TEST_CHECK( eventProcessingFinished );
830
831   END_TEST;
832 }
833
834 int UtcDaliStageEventProcessingFinishedN(void)
835 {
836   TestApplication application;
837   Stage stage = Stage::GetCurrent();
838
839   bool eventProcessingFinished = false;
840   EventProcessingFinishedFunctor functor( eventProcessingFinished );
841   stage.EventProcessingFinishedSignal().Connect( &application, functor );
842
843   Actor actor( Actor::New() );
844   stage.Add( actor );
845
846   // Do not complete event processing and confirm the signal has not been emitted.
847   DALI_TEST_CHECK( !eventProcessingFinished );
848
849   END_TEST;
850 }
851
852 int UtcDaliStageKeyEventGeneratedSignalP(void)
853 {
854   TestApplication application;
855   Stage stage = Stage::GetCurrent();
856
857   KeyEventGeneratedSignalData data;
858   KeyEventGeneratedReceivedFunctor functor( data );
859   DevelStage::KeyEventGeneratedSignal( stage ).Connect( &application, functor );
860
861   KeyEventGeneratedSignalData data2;
862   KeyEventGeneratedReceivedFunctor functor2( data2 );
863   GetImplementation( stage ).ConnectSignal( &application, "keyEventGenerated", functor2 );
864
865   Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
866   application.ProcessEvent( event );
867
868   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
869   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
870   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.GetKeyName() );
871   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.GetKeyString() );
872   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
873
874   data.Reset();
875
876   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
877   application.ProcessEvent( event2 );
878
879   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
880   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
881   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.GetKeyName() );
882   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.GetKeyString() );
883   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
884
885   data.Reset();
886
887   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
888   application.ProcessEvent( event3 );
889
890   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
891   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
892   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.GetKeyName() );
893   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.GetKeyString() );
894   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
895
896   data.Reset();
897
898   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
899   application.ProcessEvent( event4 );
900
901   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
902   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
903   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.GetKeyName() );
904   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.GetKeyString() );
905   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
906   END_TEST;
907 }
908
909 int UtcDaliStageSignalKeyEventP(void)
910 {
911   TestApplication application;
912   Stage stage = Stage::GetCurrent();
913
914   KeyEventSignalData data;
915   KeyEventReceivedFunctor functor( data );
916   stage.KeyEventSignal().Connect( &application, functor );
917
918   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
919   application.ProcessEvent( event );
920
921   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
922   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
923   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.GetKeyName() );
924   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.GetKeyString() );
925   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
926
927   data.Reset();
928
929   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
930   application.ProcessEvent( event2 );
931
932   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
933   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
934   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.GetKeyName() );
935   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.GetKeyString() );
936   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
937
938   data.Reset();
939
940   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
941   application.ProcessEvent( event3 );
942
943   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
944   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
945   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.GetKeyName() );
946   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.GetKeyString() );
947   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
948
949   data.Reset();
950
951   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
952   application.ProcessEvent( event4 );
953
954   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
955   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.GetKeyModifier() );
956   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.GetKeyName() );
957   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.GetKeyString() );
958   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.GetState() ) );
959   END_TEST;
960 }
961
962 int UtcDaliStageSignalKeyEventN(void)
963 {
964   TestApplication application;
965   Stage stage = Stage::GetCurrent();
966
967   KeyEventSignalData data;
968   KeyEventReceivedFunctor functor( data );
969   stage.KeyEventSignal().Connect( &application, functor );
970
971   // Check that a non-pressed key events data is not modified.
972   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
973
974   END_TEST;
975 }
976
977 int UtcDaliStageTouchedSignalP(void)
978 {
979   TestApplication application;
980   Stage stage = Stage::GetCurrent();
981
982   TouchSignalData data;
983   TouchFunctor functor( data );
984   stage.TouchSignal().Connect( &application, functor );
985
986   // Render and notify.
987   application.SendNotification();
988   application.Render();
989
990   // Basic test: No actors, single touch (down then up).
991   {
992     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
993
994     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
995     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
996     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
997     data.Reset();
998
999     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
1000
1001     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1002     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1003     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1004
1005     data.Reset();
1006   }
1007
1008   // Add an actor to the scene.
1009   Actor actor = Actor::New();
1010   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1011   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1012   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1013   actor.TouchSignal().Connect( &DummyTouchCallback );
1014   stage.Add( actor );
1015
1016   // Render and notify.
1017   application.SendNotification();
1018   application.Render();
1019
1020   // Actor on scene, single touch, down in actor, motion, then up outside actor.
1021   {
1022     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1023
1024     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1025     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1026     DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) );
1027     data.Reset();
1028
1029     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
1030
1031     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1032     data.Reset();
1033
1034     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
1035
1036     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1037     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1038     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1039     data.Reset();
1040   }
1041
1042   // Multiple touch. Should only receive a touch on first down and last up.
1043   {
1044     Integration::TouchEvent touchEvent;
1045     Integration::Point point;
1046
1047     // 1st point
1048     point.SetState( PointState::DOWN );
1049     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1050     touchEvent.points.push_back( point );
1051     application.ProcessEvent( touchEvent );
1052     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1053     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1054     data.Reset();
1055
1056     // 2nd point
1057     touchEvent.points[0].SetState( PointState::STATIONARY );
1058     point.SetDeviceId( 1 );
1059     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
1060     touchEvent.points.push_back( point );
1061     application.ProcessEvent( touchEvent );
1062     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1063     DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1064     data.Reset();
1065
1066     // Primary point is up
1067     touchEvent.points[0].SetState( PointState::UP );
1068     touchEvent.points[1].SetState( PointState::STATIONARY );
1069     application.ProcessEvent( touchEvent );
1070     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1071     DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1072     data.Reset();
1073
1074     // Remove 1st point now, 2nd point is now in motion
1075     touchEvent.points.erase( touchEvent.points.begin() );
1076     touchEvent.points[0].SetState( PointState::MOTION );
1077     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
1078     application.ProcessEvent( touchEvent );
1079     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1080     DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1081     data.Reset();
1082
1083     // Final point Up
1084     touchEvent.points[0].SetState( PointState::UP );
1085     application.ProcessEvent( touchEvent );
1086     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1087     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1088     data.Reset();
1089   }
1090   END_TEST;
1091 }
1092
1093 int UtcDaliStageTouchedSignalN(void)
1094 {
1095   TestApplication application;
1096   Stage stage = Stage::GetCurrent();
1097
1098   TouchSignalData data;
1099   TouchFunctor functor( data );
1100   stage.TouchSignal().Connect( &application, functor );
1101
1102   // Render and notify.
1103   application.SendNotification();
1104   application.Render();
1105
1106   // Confirm functor not called before there has been any touch event.
1107   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1108
1109   // No actors, single touch, down, motion then up.
1110   {
1111     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1112
1113     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1114     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1115     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1116     data.Reset();
1117
1118     // Confirm there is no signal when the touchpoint is only moved.
1119     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1120
1121     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1122     data.Reset();
1123
1124     // Confirm a following up event generates a signal.
1125     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1126
1127     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1128     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1129     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1130     data.Reset();
1131   }
1132
1133   // Add an actor to the scene.
1134   Actor actor = Actor::New();
1135   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1136   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1137   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1138   actor.TouchSignal().Connect( &DummyTouchCallback );
1139   stage.Add( actor );
1140
1141   // Render and notify.
1142   application.SendNotification();
1143   application.Render();
1144
1145   // Actor on scene. Interrupted before down and interrupted after down.
1146   {
1147     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1148
1149     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1150     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1151     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1152     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1153     data.Reset();
1154
1155     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1156
1157     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1158     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1159     DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1160     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
1161     data.Reset();
1162
1163     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1164
1165     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1166     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1167     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1168     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1169
1170     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1171
1172     // Check that getting info about a non-existent point causes an assert.
1173     DALI_TEST_EQUALS( data.receivedTouchEvent.GetState( 1 ), PointState::FINISHED, TEST_LOCATION );
1174
1175     data.Reset();
1176   }
1177
1178   END_TEST;
1179 }
1180
1181
1182 int UtcDaliStageTouchSignalP(void)
1183 {
1184   TestApplication application;
1185   Stage stage = Stage::GetCurrent();
1186
1187   TouchSignalData data;
1188   TouchFunctor functor( data );
1189   stage.TouchSignal().Connect( &application, functor );
1190
1191   // Render and notify.
1192   application.SendNotification();
1193   application.Render();
1194
1195   // Basic test: No actors, single touch (down then up).
1196   {
1197     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1198
1199     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1200     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1201     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1202     data.Reset();
1203
1204     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
1205
1206     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1207     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1208     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1209     data.Reset();
1210   }
1211
1212   // Add an actor to the scene.
1213   Actor actor = Actor::New();
1214   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1215   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1216   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1217   actor.TouchSignal().Connect( &DummyTouchCallback );
1218   stage.Add( actor );
1219
1220   // Render and notify.
1221   application.SendNotification();
1222   application.Render();
1223
1224   // Actor on scene, single touch, down in actor, motion, then up outside actor.
1225   {
1226     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1227
1228     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1229     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1230     DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1231     data.Reset();
1232
1233     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
1234
1235     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1236     data.Reset();
1237
1238     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
1239
1240     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1241     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1242     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1243     data.Reset();
1244   }
1245
1246   // Multiple touch. Should only receive a touch on first down and last up.
1247   {
1248     Integration::TouchEvent touchEvent;
1249     Integration::Point point;
1250
1251     // 1st point
1252     point.SetState( PointState::DOWN );
1253     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1254     touchEvent.points.push_back( point );
1255     application.ProcessEvent( touchEvent );
1256     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1257     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1258     data.Reset();
1259
1260     // 2nd point
1261     touchEvent.points[0].SetState( PointState::STATIONARY );
1262     point.SetDeviceId( 1 );
1263     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
1264     touchEvent.points.push_back( point );
1265     application.ProcessEvent( touchEvent );
1266     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1267     data.Reset();
1268
1269     // Primary point is up
1270     touchEvent.points[0].SetState( PointState::UP );
1271     touchEvent.points[1].SetState( PointState::STATIONARY );
1272     application.ProcessEvent( touchEvent );
1273     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1274     data.Reset();
1275
1276     // Remove 1st point now, 2nd point is now in motion
1277     touchEvent.points.erase( touchEvent.points.begin() );
1278     touchEvent.points[0].SetState( PointState::MOTION );
1279     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
1280     application.ProcessEvent( touchEvent );
1281     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1282     data.Reset();
1283
1284     // Final point Up
1285     touchEvent.points[0].SetState( PointState::UP );
1286     application.ProcessEvent( touchEvent );
1287     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1288     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1289     data.Reset();
1290   }
1291   END_TEST;
1292 }
1293
1294 int UtcDaliStageTouchSignalN(void)
1295 {
1296   TestApplication application;
1297   Stage stage = Stage::GetCurrent();
1298
1299   TouchSignalData data;
1300   TouchFunctor functor( data );
1301   stage.TouchSignal().Connect( &application, functor );
1302
1303   TouchSignalData data2;
1304   TouchFunctor functor2( data2 );
1305   GetImplementation( stage ).ConnectSignal( &application, "touch", functor2 );
1306
1307   // Render and notify.
1308   application.SendNotification();
1309   application.Render();
1310
1311   // Confirm functor not called before there has been any touch event.
1312   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1313   DALI_TEST_EQUALS( false, data2.functorCalled, TEST_LOCATION );
1314
1315   // No actors, single touch, down, motion then up.
1316   {
1317     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1318
1319     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1320     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1321     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
1322
1323     DALI_TEST_EQUALS( true, data2.functorCalled, TEST_LOCATION );
1324
1325     data.Reset();
1326     data2.Reset();
1327
1328     // Confirm there is no signal when the touchpoint is only moved.
1329     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1330
1331     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1332     data.Reset();
1333
1334     // Confirm a following up event generates a signal.
1335     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1336
1337     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1338     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1339     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
1340     data.Reset();
1341   }
1342
1343   // Add an actor to the scene.
1344   Actor actor = Actor::New();
1345   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1346   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1347   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1348   actor.TouchSignal().Connect( &DummyTouchCallback );
1349   stage.Add( actor );
1350
1351   // Render and notify.
1352   application.SendNotification();
1353   application.Render();
1354
1355   // Actor on scene. Interrupted before down and interrupted after down.
1356   {
1357     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1358
1359     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1360     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1361     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1362     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1363     data.Reset();
1364
1365     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1366
1367     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1368     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1369     DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1370     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
1371     data.Reset();
1372
1373     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1374
1375     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1376     DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1377     DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1378     DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1379
1380     DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1381
1382     // Check that getting info about a non-existent point returns an empty handle
1383     Actor actor = data.receivedTouchEvent.GetHitActor( 1 );
1384     DALI_TEST_CHECK( !actor );
1385
1386     data.Reset();
1387   }
1388
1389   END_TEST;
1390 }
1391
1392 int UtcDaliStageSignalWheelEventP(void)
1393 {
1394   TestApplication application;
1395   Stage stage = Stage::GetCurrent();
1396
1397   WheelEventSignalData data;
1398   WheelEventReceivedFunctor functor( data );
1399   stage.WheelEventSignal().Connect( &application, functor );
1400
1401   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1402   application.ProcessEvent( event );
1403
1404   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1405   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.GetType() );
1406   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.GetDirection() );
1407   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.GetModifiers() );
1408   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.GetPoint() );
1409   DALI_TEST_CHECK( event.delta == data.receivedWheelEvent.GetDelta() );
1410   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.GetTime() );
1411
1412   data.Reset();
1413
1414   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1415   application.ProcessEvent( event2 );
1416
1417   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1418   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.GetType() );
1419   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.GetDirection() );
1420   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.GetModifiers() );
1421   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.GetPoint() );
1422   DALI_TEST_CHECK( event2.delta == data.receivedWheelEvent.GetDelta() );
1423   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.GetTime() );
1424   END_TEST;
1425 }
1426
1427 int UtcDaliStageContextLostSignalP(void)
1428 {
1429   TestApplication application;
1430   Stage stage = Stage::GetCurrent();
1431
1432   bool contextLost = false;
1433   ContextStatusFunctor contextLostFunctor( contextLost );
1434   stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1435
1436   Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1437   notifier->NotifyContextLost();
1438   DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1439
1440   END_TEST;
1441 }
1442
1443 int UtcDaliStageContextLostSignalN(void)
1444 {
1445   TestApplication application;
1446   Stage stage;
1447
1448   // Check that connecting to the signal with a bad stage instance causes an assert.
1449   bool asserted = false;
1450   bool contextLost = false;
1451   ContextStatusFunctor contextLostFunctor( contextLost );
1452   try
1453   {
1454     stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1455   }
1456   catch( Dali::DaliException& e )
1457   {
1458     DALI_TEST_PRINT_ASSERT( e );
1459     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1460     asserted = true;
1461   }
1462   DALI_TEST_CHECK( asserted );
1463
1464   END_TEST;
1465 }
1466
1467 int UtcDaliStageContextRegainedSignalP(void)
1468 {
1469   TestApplication application;
1470   Stage stage = Stage::GetCurrent();
1471
1472   bool contextRegained = false;
1473   ContextStatusFunctor contextRegainedFunctor( contextRegained );
1474   stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1475
1476   Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1477   notifier->NotifyContextLost();
1478   notifier->NotifyContextRegained();
1479   DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1480
1481   END_TEST;
1482 }
1483
1484 int UtcDaliStageContextRegainedSignalN(void)
1485 {
1486   TestApplication application;
1487   Stage stage;
1488
1489   // Check that connecting to the signal with a bad stage instance causes an assert.
1490   bool asserted = false;
1491   bool contextRegained = false;
1492   ContextStatusFunctor contextRegainedFunctor( contextRegained );
1493   try
1494   {
1495     stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1496   }
1497   catch( Dali::DaliException& e )
1498   {
1499     DALI_TEST_PRINT_ASSERT( e );
1500     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1501     asserted = true;
1502   }
1503   DALI_TEST_CHECK( asserted );
1504
1505   END_TEST;
1506 }
1507
1508 int UtcDaliStageSceneCreatedSignalP(void)
1509 {
1510   TestApplication application;
1511   Stage stage = Stage::GetCurrent();
1512
1513   bool signalCalled = false;
1514   SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1515   stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1516
1517   Integration::Core& core = application.GetCore();
1518   core.SceneCreated();
1519   DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1520
1521   END_TEST;
1522 }
1523
1524 int UtcDaliStageSceneCreatedSignalN(void)
1525 {
1526   TestApplication application;
1527   Stage stage;
1528
1529   // Check that connecting to the signal with a bad stage instance causes an assert.
1530   bool asserted = false;
1531   bool signalCalled = false;
1532   SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1533   try
1534   {
1535     stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1536   }
1537   catch( Dali::DaliException& e )
1538   {
1539     DALI_TEST_PRINT_ASSERT( e );
1540     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1541     asserted = true;
1542   }
1543   DALI_TEST_CHECK( asserted );
1544
1545   END_TEST;
1546 }
1547
1548 int UtcDaliStageGetRenderTaskListP(void)
1549 {
1550   TestApplication application;
1551   Stage stage = Stage::GetCurrent();
1552
1553   // Check we get a valid instance.
1554   const RenderTaskList& tasks = stage.GetRenderTaskList();
1555
1556   // There should be 1 task by default.
1557   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1558
1559   // RenderTaskList has it's own UTC tests.
1560   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1561   RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1562
1563   DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1564
1565   END_TEST;
1566 }
1567
1568 int UtcDaliStageGetRenderTaskListN(void)
1569 {
1570   TestApplication application;
1571   Stage stage;
1572
1573   // Check that getting the render task list with a bad stage instance causes an assert.
1574   bool asserted = false;
1575   try
1576   {
1577     stage.GetRenderTaskList();
1578   }
1579   catch( Dali::DaliException& e )
1580   {
1581     DALI_TEST_PRINT_ASSERT( e );
1582     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1583     asserted = true;
1584   }
1585   DALI_TEST_CHECK( asserted );
1586
1587   END_TEST;
1588 }
1589
1590 int UtcDaliStageGetObjectRegistryP(void)
1591 {
1592   TestApplication application;
1593   Stage stage = Stage::GetCurrent();
1594
1595   ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1596
1597   // Object registry tests are covered in their own module.
1598   // However we want a basic test to confirm the returned registry is valid and works.
1599   bool verified = false;
1600   ActorCreatedFunctor test( verified );
1601   objectRegistry.ObjectCreatedSignal().Connect( &application, test );
1602
1603   Actor actor = Actor::New();
1604   DALI_TEST_CHECK( test.mSignalVerified );
1605
1606   END_TEST;
1607 }
1608
1609 int UtcDaliStageGetObjectRegistryN(void)
1610 {
1611   TestApplication application;
1612   Stage stage;
1613
1614   // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1615   // This is because GetCurrent() is used, always creating a stage if one does not exist.
1616   bool asserted = false;
1617   try
1618   {
1619     stage.GetObjectRegistry();
1620   }
1621   catch( Dali::DaliException& e )
1622   {
1623     DALI_TEST_PRINT_ASSERT( e );
1624     asserted = true;
1625   }
1626   DALI_TEST_CHECK( !asserted );
1627
1628   END_TEST;
1629 }
1630
1631 int UtcDaliStageOperatorAssign(void)
1632 {
1633   TestApplication application;
1634   Stage stage;
1635   DALI_TEST_CHECK( !stage );
1636
1637   stage = Stage::GetCurrent();
1638   DALI_TEST_CHECK( stage );
1639
1640   END_TEST;
1641 }
1642
1643 int UtcDaliStageRenderingBehavior(void)
1644 {
1645   TestApplication application;
1646   Stage stage = Stage::GetCurrent();
1647
1648   tet_infoline( "Check default rendering behavior is only if required" );
1649   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1650
1651   tet_infoline( "No update required with an empty application" );
1652   application.SendNotification();
1653   DALI_TEST_CHECK( application.UpdateOnly() == false );
1654   application.RenderOnly();
1655
1656   tet_infoline( "Change to continuous rendering, further updates should be required" );
1657   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::CONTINUOUSLY );
1658
1659   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::CONTINUOUSLY );
1660
1661   application.SendNotification();
1662   DALI_TEST_CHECK( application.UpdateOnly() == true );
1663   application.RenderOnly();
1664
1665   application.SendNotification();
1666   DALI_TEST_CHECK( application.UpdateOnly() == true );
1667   application.RenderOnly();
1668
1669   tet_infoline( "Change to rendering only if required, further updates should NOT be required" );
1670   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::IF_REQUIRED );
1671
1672   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1673
1674   application.SendNotification();
1675   DALI_TEST_CHECK( application.UpdateOnly() == false );
1676   application.RenderOnly();
1677
1678   tet_infoline( "The next update is not required so TestApplication should print a warning" );
1679   application.SendNotification();
1680   DALI_TEST_CHECK( application.UpdateOnly() == false );
1681   application.RenderOnly();
1682
1683   END_TEST;
1684 }