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