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