Revert "Revert "HoverEvent class pimpling""
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Stage.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/common/stage-devel.h>
24 #include <dali/integration-api/context-notifier.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/wheel-event-integ.h>
29
30 #include <dali-test-suite-utils.h>
31
32 using namespace Dali;
33
34 void stage_test_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void stage_test_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 namespace
45 {
46
47 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
48
49 // Functor for EventProcessingFinished signal
50 struct EventProcessingFinishedFunctor
51 {
52   /**
53    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
54    */
55   EventProcessingFinishedFunctor( bool& eventProcessingFinished )
56   : mEventProcessingFinished( eventProcessingFinished )
57   {}
58
59   void operator()()
60   {
61     mEventProcessingFinished = true;
62   }
63
64   bool& mEventProcessingFinished;
65 };
66
67 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
68 struct KeyEventGeneratedSignalData
69 {
70   KeyEventGeneratedSignalData()
71   : functorCalled(false)
72   {}
73
74   void Reset()
75   {
76     functorCalled = false;
77
78     receivedKeyEvent.keyModifier = 0;
79     receivedKeyEvent.keyPressedName.clear();
80     receivedKeyEvent.keyPressed.clear();
81   }
82
83   bool functorCalled;
84   KeyEvent receivedKeyEvent;
85 };
86
87 // Functor that sets the data when called
88 struct KeyEventGeneratedReceivedFunctor
89 {
90   KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
91   : signalData( data )
92   {}
93
94   bool operator()( const KeyEvent& keyEvent )
95   {
96     signalData.functorCalled = true;
97     signalData.receivedKeyEvent = keyEvent;
98
99     return true;
100   }
101
102   bool operator()()
103   {
104     signalData.functorCalled = true;
105     return true;
106   }
107
108   KeyEventGeneratedSignalData& signalData;
109 };
110
111 // Stores data that is populated in the key-event callback and will be read by the TET cases
112 struct KeyEventSignalData
113 {
114   KeyEventSignalData()
115   : functorCalled(false)
116   {}
117
118   void Reset()
119   {
120     functorCalled = false;
121
122     receivedKeyEvent.keyModifier = 0;
123     receivedKeyEvent.keyPressedName.clear();
124     receivedKeyEvent.keyPressed.clear();
125   }
126
127   bool functorCalled;
128   KeyEvent receivedKeyEvent;
129 };
130
131 // Functor that sets the data when called
132 struct KeyEventReceivedFunctor
133 {
134   KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
135
136   bool operator()( const KeyEvent& keyEvent )
137   {
138     signalData.functorCalled = true;
139     signalData.receivedKeyEvent = keyEvent;
140
141     return true;
142   }
143
144   KeyEventSignalData& signalData;
145 };
146
147 // Stores data that is populated in the touched signal callback and will be read by the TET cases
148 struct TouchedSignalData
149 {
150   TouchedSignalData()
151   : functorCalled(false)
152   {}
153
154   void Reset()
155   {
156     functorCalled = false;
157
158     receivedTouchEvent.points.clear();
159     receivedTouchEvent.time = 0;
160
161     receivedTouchData.Reset();
162   }
163
164   bool functorCalled;
165   TouchEvent receivedTouchEvent;
166   TouchData receivedTouchData;
167 };
168
169 // Functor that sets the data when touched signal is received
170 struct TouchedFunctor
171 {
172   TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
173
174   void operator()( const TouchEvent& touch )
175   {
176     signalData.functorCalled = true;
177     signalData.receivedTouchEvent = touch;
178   }
179
180   TouchedSignalData& signalData;
181 };
182
183
184 // Functor that sets the data when touched signal is received
185 struct TouchFunctor
186 {
187   TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
188
189   void operator()( const TouchData& touch )
190   {
191     signalData.functorCalled = true;
192     signalData.receivedTouchData = touch;
193   }
194
195   void operator()()
196   {
197     signalData.functorCalled = true;
198   }
199
200   TouchedSignalData& signalData;
201 };
202
203 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
204 struct WheelEventSignalData
205 {
206   WheelEventSignalData()
207   : functorCalled(false)
208   {}
209
210   void Reset()
211   {
212     functorCalled = false;
213   }
214
215   bool functorCalled;
216   WheelEvent receivedWheelEvent;
217 };
218
219 // Functor that sets the data when wheel-event signal is received
220 struct WheelEventReceivedFunctor
221 {
222   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
223
224   bool operator()( const WheelEvent& wheelEvent )
225   {
226     signalData.functorCalled = true;
227     signalData.receivedWheelEvent = wheelEvent;
228
229     return true;
230   }
231
232   WheelEventSignalData& signalData;
233 };
234
235 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
236 {
237   return true;
238 }
239
240 struct ContextStatusFunctor
241 {
242   ContextStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
243   {
244     mCalledFlag = false;
245   }
246
247   void operator()()
248   {
249     mCalledFlag = true;
250   }
251   void Reset()
252   {
253     mCalledFlag = false;
254   }
255
256   bool& mCalledFlag;
257 };
258
259 struct SceneCreatedStatusFunctor
260 {
261   SceneCreatedStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
262   {
263     mCalledFlag = false;
264   }
265
266   void operator()()
267   {
268     mCalledFlag = true;
269   }
270   void Reset()
271   {
272     mCalledFlag = false;
273   }
274
275   bool& mCalledFlag;
276 };
277
278 struct ActorCreatedFunctor
279 {
280   ActorCreatedFunctor( bool& signalReceived )
281   : mSignalVerified( signalReceived )
282   {
283   }
284
285   void operator()( BaseHandle object )
286   {
287     tet_infoline( "Verifying TestActorCallback()" );
288     Actor actor = Actor::DownCast( object );
289     if( actor )
290     {
291       mSignalVerified = true;
292     }
293   }
294
295   bool& mSignalVerified;
296 };
297
298 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
299 {
300   Integration::TouchEvent touchEvent;
301   Integration::Point point;
302   point.SetState( state );
303   point.SetScreenPosition( screenPosition );
304   touchEvent.points.push_back( point );
305   application.ProcessEvent( touchEvent );
306 }
307
308 } // unnamed namespace
309
310
311 int UtcDaliStageDefaultConstructorP(void)
312 {
313   TestApplication application;
314   Stage stage;
315
316   DALI_TEST_CHECK( !stage );
317   END_TEST;
318 }
319
320 // Note: No negative test for default constructor.
321
322 int UtcDaliStageDestructorP(void)
323 {
324   TestApplication application;
325   Stage* stage = new Stage();
326   delete stage;
327   stage = NULL;
328
329   DALI_TEST_CHECK( true );
330   END_TEST;
331 }
332
333 // Note: No negative test for default destructor.
334
335 int UtcDaliStageGetCurrentP(void)
336 {
337   TestApplication application;
338   Stage stage = Stage::GetCurrent();
339
340   DALI_TEST_CHECK( stage );
341   END_TEST;
342 }
343
344 int UtcDaliStageGetCurrentN(void)
345 {
346   bool asserted = false;
347   try
348   {
349     Stage stage = Stage::GetCurrent();
350   }
351   catch( Dali::DaliException& e )
352   {
353     DALI_TEST_PRINT_ASSERT( e );
354     DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
355     asserted = true;
356   }
357
358   DALI_TEST_CHECK( asserted );
359   END_TEST;
360 }
361
362 int UtcDaliStageIsInstalledP(void)
363 {
364   TestApplication application;
365
366   Stage::GetCurrent();
367
368   DALI_TEST_CHECK( Stage::IsInstalled() );
369   END_TEST;
370 }
371
372 int UtcDaliStageIsInstalledN(void)
373 {
374   DALI_TEST_CHECK( !Stage::IsInstalled() );
375
376   END_TEST;
377 }
378
379 int UtcDaliStageCopyConstructorP(void)
380 {
381   TestApplication application;
382   Stage stage = Stage::GetCurrent();
383
384   Stage copyStage( stage );
385
386   DALI_TEST_CHECK( copyStage );
387   DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
388
389   END_TEST;
390 }
391
392 // Note: no negative test for UtcDaliStageCopyConstructor.
393
394 int UtcDaliStageAssignmentOperatorP(void)
395 {
396   TestApplication application;
397   const Stage stage = Stage::GetCurrent();
398
399   Stage copyStage = stage;
400
401   DALI_TEST_CHECK( copyStage );
402   DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
403
404   END_TEST;
405 }
406
407 // Note: No negative test for UtcDaliStageAssignmentOperator.
408
409 int UtcDaliStageAddP(void)
410 {
411   TestApplication application;
412
413   Stage stage = Stage::GetCurrent();
414
415   Actor actor = Actor::New();
416   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
417
418   stage.Add( actor );
419   DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
420   END_TEST;
421 }
422
423 int UtcDaliStageAddN(void)
424 {
425   TestApplication application;
426
427   Stage stage = Stage::GetCurrent();
428   Actor actor;
429
430   bool asserted = false;
431   try
432   {
433     stage.Add( actor );
434   }
435   catch( Dali::DaliException& e )
436   {
437     DALI_TEST_PRINT_ASSERT( e );
438     DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
439     asserted = true;
440   }
441
442   DALI_TEST_CHECK( asserted );
443
444   END_TEST;
445 }
446
447 int UtcDaliStageRemoveP(void)
448 {
449   TestApplication application;
450
451   Stage stage = Stage::GetCurrent();
452
453   Actor actor = Actor::New();
454   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
455
456   stage.Add( actor );
457   DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
458
459   stage.Remove(actor);
460   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
461   END_TEST;
462 }
463
464 int UtcDaliStageRemoveN1(void)
465 {
466   TestApplication application;
467
468   Stage stage = Stage::GetCurrent();
469   Actor actor;
470
471   bool asserted = false;
472   try
473   {
474     // Actor is not valid, confirm a removal attempt does assert.
475     stage.Remove( actor );
476   }
477   catch( Dali::DaliException& e )
478   {
479     DALI_TEST_PRINT_ASSERT( e );
480     DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
481     asserted = true;
482   }
483
484   DALI_TEST_CHECK( asserted );
485   END_TEST;
486 }
487
488 int UtcDaliStageRemoveN2(void)
489 {
490   TestApplication application;
491
492   Stage stage = Stage::GetCurrent();
493   Actor actor = Actor::New();
494   DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
495
496   bool asserted = false;
497   try
498   {
499     // Actor is not on stage, confirm a removal attempt does not assert / segfault.
500     stage.Remove( actor );
501   }
502   catch( Dali::DaliException& e )
503   {
504     DALI_TEST_PRINT_ASSERT( e );
505     asserted = true;
506   }
507
508   DALI_TEST_CHECK( !asserted );
509   END_TEST;
510 }
511
512 int UtcDaliStageRemoveN3(void)
513 {
514   TestApplication application;
515
516   Stage stage = Stage::GetCurrent();
517
518   // Initially we have a default layer
519   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
520
521   // Check we cannot remove the root layer from the stage.
522   Layer layer = stage.GetRootLayer();
523   bool asserted = true;
524   try
525   {
526     stage.Remove( layer );
527   }
528   catch( Dali::DaliException& e )
529   {
530     DALI_TEST_PRINT_ASSERT( e );
531     DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
532     asserted = true;
533   }
534
535   DALI_TEST_CHECK( asserted );
536   DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
537   END_TEST;
538 }
539
540 int UtcDaliStageGetSizeP(void)
541 {
542   TestApplication application;
543
544   Stage stage = Stage::GetCurrent();
545
546   Vector2 size = stage.GetSize();
547
548   DALI_TEST_EQUALS( size.width,  static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ),  TEST_LOCATION );
549   DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
550   END_TEST;
551 }
552
553 int UtcDaliStageGetSizeN(void)
554 {
555   TestApplication application;
556
557   Stage stage;
558
559   bool asserted = false;
560   Vector2 size;
561   try
562   {
563     size = stage.GetSize();
564   }
565   catch( Dali::DaliException& e )
566   {
567     DALI_TEST_PRINT_ASSERT( e );
568     DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
569     asserted = true;
570   }
571
572   DALI_TEST_CHECK( asserted );
573   END_TEST;
574 }
575
576 int UtcDaliStageGetDpiP1(void)
577 {
578   TestApplication application; // Initializes core DPI to default values
579
580   Stage stage = Stage::GetCurrent();
581
582   // Test the default DPI.
583   Vector2 dpi = stage.GetDpi();
584   DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
585   DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ),   TEST_LOCATION );
586   END_TEST;
587 }
588
589 int UtcDaliStageGetDpiP2(void)
590 {
591   TestApplication application; // Initializes core DPI to default values
592
593   // Test that setting core DPI explicitly also sets up the Stage's DPI.
594   Dali::Integration::Scene scene = application.GetScene();
595   scene.SetDpi( Vector2(200.0f, 180.0f) );
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, 120 ); // 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, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1032   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1033   actor.SetProperty( Actor::Property::PARENT_ORIGIN, 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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1157   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1158   actor.SetProperty( Actor::Property::PARENT_ORIGIN, 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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1247   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1248   actor.SetProperty( Actor::Property::PARENT_ORIGIN, 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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1378   actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1379   actor.SetProperty( Actor::Property::PARENT_ORIGIN, 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 application;
1462   Stage stage = Stage::GetCurrent();
1463
1464   bool contextLost = false;
1465   ContextStatusFunctor contextLostFunctor( contextLost );
1466   stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1467
1468   Integration::ContextNotifierInterface* notifier = application.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 application;
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( &application, 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 application;
1502   Stage stage = Stage::GetCurrent();
1503
1504   bool contextRegained = false;
1505   ContextStatusFunctor contextRegainedFunctor( contextRegained );
1506   stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1507
1508   Integration::ContextNotifierInterface* notifier = application.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 application;
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( &application, 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 application;
1543   Stage stage = Stage::GetCurrent();
1544
1545   bool signalCalled = false;
1546   SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1547   stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1548
1549   Integration::Core& core = application.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 application;
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( &application, 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 application;
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 application;
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 application;
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( &application, 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 application;
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 application;
1666   Stage stage;
1667   DALI_TEST_CHECK( !stage );
1668
1669   stage = Stage::GetCurrent();
1670   DALI_TEST_CHECK( stage );
1671
1672   END_TEST;
1673 }
1674
1675 int UtcDaliStageRenderingBehavior(void)
1676 {
1677   TestApplication application;
1678   Stage stage = Stage::GetCurrent();
1679
1680   tet_infoline( "Check default rendering behavior is only if required" );
1681   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1682
1683   tet_infoline( "No update required with an empty application" );
1684   application.SendNotification();
1685   DALI_TEST_CHECK( application.UpdateOnly() == false );
1686   application.RenderOnly();
1687
1688   tet_infoline( "Change to continuous rendering, further updates should be required" );
1689   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::CONTINUOUSLY );
1690
1691   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::CONTINUOUSLY );
1692
1693   application.SendNotification();
1694   DALI_TEST_CHECK( application.UpdateOnly() == true );
1695   application.RenderOnly();
1696
1697   application.SendNotification();
1698   DALI_TEST_CHECK( application.UpdateOnly() == true );
1699   application.RenderOnly();
1700
1701   tet_infoline( "Change to rendering only if required, further updates should NOT be required" );
1702   DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::IF_REQUIRED );
1703
1704   DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1705
1706   application.SendNotification();
1707   DALI_TEST_CHECK( application.UpdateOnly() == false );
1708   application.RenderOnly();
1709
1710   tet_infoline( "The next update is not required so TestApplication should print a warning" );
1711   application.SendNotification();
1712   DALI_TEST_CHECK( application.UpdateOnly() == false );
1713   application.RenderOnly();
1714
1715   END_TEST;
1716 }