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