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