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