Merge "Renamed TouchSignal to TouchedSignal" into devel/master
[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 TouchedSignalData
145 {
146   TouchedSignalData()
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( TouchedSignalData& 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   TouchedSignalData& 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   TouchedSignalData data;
983   TouchFunctor functor( data );
984   stage.TouchedSignal().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.TouchedSignal().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   TouchedSignalData data;
1099   TouchFunctor functor( data );
1100   stage.TouchedSignal().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.TouchedSignal().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 int UtcDaliStageSignalWheelEventP(void)
1182 {
1183   TestApplication application;
1184   Stage stage = Stage::GetCurrent();
1185
1186   WheelEventSignalData data;
1187   WheelEventReceivedFunctor functor( data );
1188   stage.WheelEventSignal().Connect( &application, functor );
1189
1190   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1191   application.ProcessEvent( event );
1192
1193   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1194   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.GetType() );
1195   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.GetDirection() );
1196   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.GetModifiers() );
1197   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.GetPoint() );
1198   DALI_TEST_CHECK( event.delta == data.receivedWheelEvent.GetDelta() );
1199   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.GetTime() );
1200
1201   data.Reset();
1202
1203   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1204   application.ProcessEvent( event2 );
1205
1206   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1207   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.GetType() );
1208   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.GetDirection() );
1209   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.GetModifiers() );
1210   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.GetPoint() );
1211   DALI_TEST_CHECK( event2.delta == data.receivedWheelEvent.GetDelta() );
1212   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.GetTime() );
1213   END_TEST;
1214 }
1215
1216 int UtcDaliStageContextLostSignalP(void)
1217 {
1218   TestApplication application;
1219   Stage stage = Stage::GetCurrent();
1220
1221   bool contextLost = false;
1222   ContextStatusFunctor contextLostFunctor( contextLost );
1223   stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1224
1225   Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1226   notifier->NotifyContextLost();
1227   DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1228
1229   END_TEST;
1230 }
1231
1232 int UtcDaliStageContextLostSignalN(void)
1233 {
1234   TestApplication application;
1235   Stage stage;
1236
1237   // Check that connecting to the signal with a bad stage instance causes an assert.
1238   bool asserted = false;
1239   bool contextLost = false;
1240   ContextStatusFunctor contextLostFunctor( contextLost );
1241   try
1242   {
1243     stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1244   }
1245   catch( Dali::DaliException& e )
1246   {
1247     DALI_TEST_PRINT_ASSERT( e );
1248     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1249     asserted = true;
1250   }
1251   DALI_TEST_CHECK( asserted );
1252
1253   END_TEST;
1254 }
1255
1256 int UtcDaliStageContextRegainedSignalP(void)
1257 {
1258   TestApplication application;
1259   Stage stage = Stage::GetCurrent();
1260
1261   bool contextRegained = false;
1262   ContextStatusFunctor contextRegainedFunctor( contextRegained );
1263   stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1264
1265   Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1266   notifier->NotifyContextLost();
1267   notifier->NotifyContextRegained();
1268   DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1269
1270   END_TEST;
1271 }
1272
1273 int UtcDaliStageContextRegainedSignalN(void)
1274 {
1275   TestApplication application;
1276   Stage stage;
1277
1278   // Check that connecting to the signal with a bad stage instance causes an assert.
1279   bool asserted = false;
1280   bool contextRegained = false;
1281   ContextStatusFunctor contextRegainedFunctor( contextRegained );
1282   try
1283   {
1284     stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1285   }
1286   catch( Dali::DaliException& e )
1287   {
1288     DALI_TEST_PRINT_ASSERT( e );
1289     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1290     asserted = true;
1291   }
1292   DALI_TEST_CHECK( asserted );
1293
1294   END_TEST;
1295 }
1296
1297 int UtcDaliStageSceneCreatedSignalP(void)
1298 {
1299   TestApplication application;
1300   Stage stage = Stage::GetCurrent();
1301
1302   bool signalCalled = false;
1303   SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1304   stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1305
1306   Integration::Core& core = application.GetCore();
1307   core.SceneCreated();
1308   DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1309
1310   END_TEST;
1311 }
1312
1313 int UtcDaliStageSceneCreatedSignalN(void)
1314 {
1315   TestApplication application;
1316   Stage stage;
1317
1318   // Check that connecting to the signal with a bad stage instance causes an assert.
1319   bool asserted = false;
1320   bool signalCalled = false;
1321   SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1322   try
1323   {
1324     stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1325   }
1326   catch( Dali::DaliException& e )
1327   {
1328     DALI_TEST_PRINT_ASSERT( e );
1329     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1330     asserted = true;
1331   }
1332   DALI_TEST_CHECK( asserted );
1333
1334   END_TEST;
1335 }
1336
1337 int UtcDaliStageGetRenderTaskListP(void)
1338 {
1339   TestApplication application;
1340   Stage stage = Stage::GetCurrent();
1341
1342   // Check we get a valid instance.
1343   const RenderTaskList& tasks = stage.GetRenderTaskList();
1344
1345   // There should be 1 task by default.
1346   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1347
1348   // RenderTaskList has it's own UTC tests.
1349   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1350   RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1351
1352   DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1353
1354   END_TEST;
1355 }
1356
1357 int UtcDaliStageGetRenderTaskListN(void)
1358 {
1359   TestApplication application;
1360   Stage stage;
1361
1362   // Check that getting the render task list with a bad stage instance causes an assert.
1363   bool asserted = false;
1364   try
1365   {
1366     stage.GetRenderTaskList();
1367   }
1368   catch( Dali::DaliException& e )
1369   {
1370     DALI_TEST_PRINT_ASSERT( e );
1371     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1372     asserted = true;
1373   }
1374   DALI_TEST_CHECK( asserted );
1375
1376   END_TEST;
1377 }
1378
1379 int UtcDaliStageGetObjectRegistryP(void)
1380 {
1381   TestApplication application;
1382   Stage stage = Stage::GetCurrent();
1383
1384   ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1385
1386   // Object registry tests are covered in their own module.
1387   // However we want a basic test to confirm the returned registry is valid and works.
1388   bool verified = false;
1389   ActorCreatedFunctor test( verified );
1390   objectRegistry.ObjectCreatedSignal().Connect( &application, test );
1391
1392   Actor actor = Actor::New();
1393   DALI_TEST_CHECK( test.mSignalVerified );
1394
1395   END_TEST;
1396 }
1397
1398 int UtcDaliStageGetObjectRegistryN(void)
1399 {
1400   TestApplication application;
1401   Stage stage;
1402
1403   // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1404   // This is because GetCurrent() is used, always creating a stage if one does not exist.
1405   bool asserted = false;
1406   try
1407   {
1408     stage.GetObjectRegistry();
1409   }
1410   catch( Dali::DaliException& e )
1411   {
1412     DALI_TEST_PRINT_ASSERT( e );
1413     asserted = true;
1414   }
1415   DALI_TEST_CHECK( !asserted );
1416
1417   END_TEST;
1418 }
1419
1420 int UtcDaliStageOperatorAssign(void)
1421 {
1422   TestApplication application;
1423   Stage stage;
1424   DALI_TEST_CHECK( !stage );
1425
1426   stage = Stage::GetCurrent();
1427   DALI_TEST_CHECK( stage );
1428
1429   END_TEST;
1430 }
1431
1432 int UtcDaliStageRenderingBehavior(void)
1433 {
1434   TestApplication application;
1435   Stage stage = Stage::GetCurrent();
1436
1437   tet_infoline( "Check default rendering behavior is only if required" );
1438   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1439
1440   tet_infoline( "No update required with an empty application" );
1441   application.SendNotification();
1442   DALI_TEST_CHECK( application.UpdateOnly() == false );
1443   application.RenderOnly();
1444
1445   tet_infoline( "Change to continuous rendering, further updates should be required" );
1446   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::CONTINUOUSLY );
1447
1448   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::CONTINUOUSLY );
1449
1450   application.SendNotification();
1451   DALI_TEST_CHECK( application.UpdateOnly() == true );
1452   application.RenderOnly();
1453
1454   application.SendNotification();
1455   DALI_TEST_CHECK( application.UpdateOnly() == true );
1456   application.RenderOnly();
1457
1458   tet_infoline( "Change to rendering only if required, further updates should NOT be required" );
1459   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::IF_REQUIRED );
1460
1461   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1462
1463   application.SendNotification();
1464   DALI_TEST_CHECK( application.UpdateOnly() == false );
1465   application.RenderOnly();
1466
1467   tet_infoline( "The next update is not required so TestApplication should print a warning" );
1468   application.SendNotification();
1469   DALI_TEST_CHECK( application.UpdateOnly() == false );
1470   application.RenderOnly();
1471
1472   END_TEST;
1473 }