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