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