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