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