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