0dd5e1978ef5a20c829a68a8b226e1d76ffa1efc
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2022 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.h>
20 #include <dali/integration-api/events/key-event-integ.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/wheel-event-integ.h>
23 #include <dali/integration-api/scene.h>
24 #include <dali/public-api/events/key-event.h>
25 #include <mesh-builder.h>
26 #include <stdlib.h>
27
28 #include <iostream>
29
30 // Internal headers are allowed here
31
32 namespace
33 {
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
35
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
38 {
39   /**
40    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
41    */
42   EventProcessingFinishedFunctor(bool& eventProcessingFinished)
43   : mEventProcessingFinished(eventProcessingFinished)
44   {
45   }
46
47   void operator()()
48   {
49     mEventProcessingFinished = true;
50   }
51
52   bool& mEventProcessingFinished;
53 };
54
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
57 {
58   KeyEventSignalData()
59   : functorCalled(false)
60   {
61   }
62
63   void Reset()
64   {
65     functorCalled = false;
66
67     receivedKeyEvent.Reset();
68   }
69
70   bool     functorCalled;
71   KeyEvent receivedKeyEvent;
72 };
73
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
76 {
77   KeyEventReceivedFunctor(KeyEventSignalData& data)
78   : signalData(data)
79   {
80   }
81
82   bool operator()(const KeyEvent& keyEvent)
83   {
84     signalData.functorCalled    = true;
85     signalData.receivedKeyEvent = keyEvent;
86
87     return true;
88   }
89
90   KeyEventSignalData& signalData;
91 };
92
93 // Stores data that is populated in the touched signal callback and will be read by the TET cases
94 struct TouchedSignalData
95 {
96   TouchedSignalData()
97   : functorCalled(false),
98     createNewScene(false),
99     newSceneCreated(false)
100   {
101   }
102
103   void Reset()
104   {
105     functorCalled   = false;
106     createNewScene  = false;
107     newSceneCreated = false;
108     receivedTouchEvent.Reset();
109   }
110
111   bool       functorCalled;
112   bool       createNewScene;
113   bool       newSceneCreated;
114   TouchEvent receivedTouchEvent;
115 };
116
117 // Functor that sets the data when touched signal is received
118 struct TouchFunctor
119 {
120   TouchFunctor(TouchedSignalData& data)
121   : signalData(data)
122   {
123   }
124
125   void operator()(const TouchEvent& touch)
126   {
127     signalData.functorCalled      = true;
128     signalData.receivedTouchEvent = touch;
129
130     if(signalData.createNewScene)
131     {
132       Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
133       DALI_TEST_CHECK(scene);
134
135       signalData.newSceneCreated = true;
136     }
137   }
138
139   void operator()()
140   {
141     signalData.functorCalled = true;
142   }
143
144   TouchedSignalData& signalData;
145 };
146
147 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
148 struct WheelEventSignalData
149 {
150   WheelEventSignalData()
151   : functorCalled(false)
152   {
153   }
154
155   void Reset()
156   {
157     functorCalled = false;
158   }
159
160   bool       functorCalled;
161   WheelEvent receivedWheelEvent;
162 };
163
164 // Functor that sets the data when wheel-event signal is received
165 struct WheelEventReceivedFunctor
166 {
167   WheelEventReceivedFunctor(WheelEventSignalData& data)
168   : signalData(data)
169   {
170   }
171
172   bool operator()(const WheelEvent& wheelEvent)
173   {
174     signalData.functorCalled      = true;
175     signalData.receivedWheelEvent = wheelEvent;
176
177     return true;
178   }
179
180   WheelEventSignalData& signalData;
181 };
182
183 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
184 struct KeyEventGeneratedSignalData
185 {
186   KeyEventGeneratedSignalData()
187   : functorCalled(false)
188   {
189   }
190
191   void Reset()
192   {
193     functorCalled = false;
194
195     receivedKeyEvent.Reset();
196   }
197
198   bool     functorCalled;
199   KeyEvent receivedKeyEvent;
200 };
201
202 // Functor that sets the data when called
203 struct KeyEventGeneratedReceivedFunctor
204 {
205   KeyEventGeneratedReceivedFunctor(KeyEventGeneratedSignalData& data)
206   : signalData(data)
207   {
208   }
209
210   bool operator()(const KeyEvent& keyEvent)
211   {
212     signalData.functorCalled    = true;
213     signalData.receivedKeyEvent = keyEvent;
214
215     return true;
216   }
217
218   bool operator()()
219   {
220     signalData.functorCalled = true;
221     return true;
222   }
223
224   KeyEventGeneratedSignalData& signalData;
225 };
226
227 // Stores data that is populated in the WheelEventGeneratedSignal callback and will be read by the TET cases
228 struct WheelEventGeneratedSignalData
229 {
230   WheelEventGeneratedSignalData()
231   : functorCalled(false)
232   {
233   }
234
235   void Reset()
236   {
237     functorCalled = false;
238
239     receivedWheelEvent.Reset();
240   }
241
242   bool       functorCalled;
243   WheelEvent receivedWheelEvent;
244 };
245
246 // Functor that sets the data when called
247 struct WheelEventGeneratedReceivedFunctor
248 {
249   WheelEventGeneratedReceivedFunctor(WheelEventGeneratedSignalData& data)
250   : signalData(data)
251   {
252   }
253
254   bool operator()(const WheelEvent& wheelEvent)
255   {
256     signalData.functorCalled      = true;
257     signalData.receivedWheelEvent = wheelEvent;
258
259     return true;
260   }
261
262   bool operator()()
263   {
264     signalData.functorCalled = true;
265     return true;
266   }
267
268   WheelEventGeneratedSignalData& signalData;
269 };
270
271 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
272 {
273   Integration::TouchEvent touchEvent;
274   Integration::Point      point;
275   point.SetState(state);
276   point.SetScreenPosition(screenPosition);
277   touchEvent.points.push_back(point);
278   application.ProcessEvent(touchEvent);
279 }
280
281 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
282 {
283   return true;
284 }
285
286 void FrameCallback(int frameId)
287 {
288 }
289
290 } // unnamed namespace
291
292 int UtcDaliSceneAdd(void)
293 {
294   TestApplication application;
295   tet_infoline("Testing Dali::Integration::Scene::Add");
296
297   Dali::Integration::Scene scene = application.GetScene();
298
299   Actor actor = Actor::New();
300   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
301
302   scene.Add(actor);
303   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
304
305   END_TEST;
306 }
307
308 int UtcDaliSceneRemove(void)
309 {
310   TestApplication application;
311   tet_infoline("Testing Dali::Integration::Scene::Remove");
312
313   Dali::Integration::Scene scene = application.GetScene();
314
315   Actor actor = Actor::New();
316   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
317
318   scene.Add(actor);
319   DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
320
321   scene.Remove(actor);
322   DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
323
324   END_TEST;
325 }
326
327 int UtcDaliSceneGetSize(void)
328 {
329   TestApplication application;
330   tet_infoline("Testing Dali::Integration::Scene::GetSize");
331
332   Dali::Integration::Scene scene = application.GetScene();
333   Size                     size  = scene.GetSize();
334   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION);
335   DALI_TEST_EQUALS(TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION);
336
337   END_TEST;
338 }
339
340 int UtcDaliSceneGetDpi(void)
341 {
342   TestApplication application; // Initializes core DPI to default values
343
344   // Test that setting core DPI explicitly also sets up the scene's DPI.
345   Dali::Integration::Scene scene = application.GetScene();
346   scene.SetDpi(Vector2(200.0f, 180.0f));
347   Vector2 dpi = scene.GetDpi();
348   DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
349   DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
350   END_TEST;
351 }
352
353 int UtcDaliSceneGetRenderTaskList(void)
354 {
355   TestApplication application;
356   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
357
358   Dali::Integration::Scene scene = application.GetScene();
359
360   // Check we get a valid instance.
361   const RenderTaskList& tasks = scene.GetRenderTaskList();
362
363   // There should be 1 task by default.
364   DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
365
366   // RenderTaskList has it's own UTC tests.
367   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
368   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
369
370   DALI_TEST_EQUALS(scene.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
371
372   END_TEST;
373 }
374
375 int UtcDaliSceneGetRootLayer(void)
376 {
377   TestApplication application;
378   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
379
380   Dali::Integration::Scene scene = application.GetScene();
381   Layer                    layer = scene.GetLayer(0);
382   DALI_TEST_CHECK(layer);
383
384   // Check that GetRootLayer() correctly retreived layer 0.
385   DALI_TEST_CHECK(scene.GetRootLayer() == layer);
386
387   END_TEST;
388 }
389
390 int UtcDaliSceneGetLayerCount(void)
391 {
392   TestApplication application;
393   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
394
395   Dali::Integration::Scene scene = application.GetScene();
396   // Initially we have a default layer
397   DALI_TEST_EQUALS(scene.GetLayerCount(), 1u, TEST_LOCATION);
398
399   Layer layer = Layer::New();
400   scene.Add(layer);
401
402   DALI_TEST_EQUALS(scene.GetLayerCount(), 2u, TEST_LOCATION);
403   END_TEST;
404 }
405
406 int UtcDaliSceneGetLayer(void)
407 {
408   TestApplication application;
409   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
410
411   Dali::Integration::Scene scene = application.GetScene();
412
413   Layer rootLayer = scene.GetLayer(0);
414   DALI_TEST_CHECK(rootLayer);
415
416   Layer layer = Layer::New();
417   scene.Add(layer);
418
419   Layer sameLayer = scene.GetLayer(1);
420   DALI_TEST_CHECK(layer == sameLayer);
421
422   END_TEST;
423 }
424
425 int UtcDaliSceneGet(void)
426 {
427   TestApplication application;
428   tet_infoline("Testing Dali::Integration::Scene::Get");
429
430   Dali::Integration::Scene scene = application.GetScene();
431
432   Actor parent = Actor::New();
433   Actor child  = Actor::New();
434
435   parent.Add(child);
436
437   // Should be empty scene
438   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(parent));
439   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(child));
440
441   scene.Add(parent);
442
443   // Should return the valid scene
444   DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(parent));
445   DALI_TEST_CHECK(scene == Dali::Integration::Scene::Get(child));
446
447   parent.Unparent();
448
449   // Should be empty scene
450   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(parent));
451   DALI_TEST_CHECK(Dali::Integration::Scene() == Dali::Integration::Scene::Get(child));
452
453   END_TEST;
454 }
455
456 int UtcDaliSceneDiscard(void)
457 {
458   TestApplication application;
459   tet_infoline("Testing Dali::Scene::Discard");
460
461   // Create a new Scene
462   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
463   DALI_TEST_CHECK(scene);
464
465   // One reference of scene kept here and the other one kept in the Core
466   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
467
468   // Render and notify.
469   application.SendNotification();
470   application.Render(0);
471
472   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
473   Layer rootLayer = scene.GetRootLayer();
474   DALI_TEST_CHECK(rootLayer);
475   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
476
477   // Request to discard the scene from the Core
478   scene.Discard();
479   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
480
481   // Reset the scene handle
482   scene.Reset();
483
484   // Render and notify.
485   application.SendNotification();
486   application.Render(0);
487
488   // At this point, the scene should have been automatically deleted
489   // To prove this, the ref count of the root layer handle should be decremented to 1
490   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
491
492   // Delete the root layer handle
493   rootLayer.Reset();
494
495   // Render and notify.
496   application.SendNotification();
497   application.Render(0);
498
499   END_TEST;
500 }
501
502 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
503 {
504   TestApplication application;
505
506   Dali::Integration::Scene scene = application.GetScene();
507
508   TouchedSignalData data;
509   data.createNewScene = true;
510   TouchFunctor functor(data);
511   scene.TouchedSignal().Connect(&application, functor);
512
513   // Render and notify.
514   application.SendNotification();
515   application.Render();
516
517   GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
518
519   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
520   DALI_TEST_EQUALS(true, data.createNewScene, TEST_LOCATION);
521   DALI_TEST_EQUALS(true, data.newSceneCreated, TEST_LOCATION);
522   data.Reset();
523
524   END_TEST;
525 }
526
527 int UtcDaliSceneRootLayerAndSceneAlignment(void)
528 {
529   TestApplication application;
530
531   // Create a Scene
532   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
533   DALI_TEST_CHECK(scene);
534
535   // One reference of scene kept here and the other one kept in the Core
536   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 2);
537
538   // Add a renderable actor to the scene
539   auto actor = CreateRenderableActor();
540   scene.Add(actor);
541
542   // Render and notify.
543   application.SendNotification();
544   application.Render(0);
545
546   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
547   Layer rootLayer = scene.GetRootLayer();
548   DALI_TEST_CHECK(rootLayer);
549   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 2);
550
551   // Request to discard the scene from the Core
552   scene.Discard();
553   DALI_TEST_CHECK(scene.GetBaseObject().ReferenceCount() == 1);
554
555   // Reset the scene handle
556   scene.Reset();
557
558   // Render and notify.
559   application.SendNotification();
560   application.Render(0);
561
562   // At this point, the scene should have been automatically deleted
563   // To prove this, the ref count of the root layer handle should be decremented to 1
564   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
565
566   // Create a new Scene while the root layer of the deleted scene is still alive
567   Dali::Integration::Scene newScene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
568   DALI_TEST_CHECK(newScene);
569
570   // Render and notify.
571   application.SendNotification();
572   application.Render(0);
573
574   // At this point, we have only one scene but two root layers
575   // The root layer of the deleted scene is still alive
576   DALI_TEST_CHECK(rootLayer.GetBaseObject().ReferenceCount() == 1);
577
578   // Delete the root layer of the deleted scene
579   rootLayer.Reset();
580
581   // Render and notify.
582   application.SendNotification();
583   application.Render(0);
584
585   END_TEST;
586 }
587
588 int UtcDaliSceneEventProcessingFinishedP(void)
589 {
590   TestApplication          application;
591   Dali::Integration::Scene scene = application.GetScene();
592
593   bool                           eventProcessingFinished = false;
594   EventProcessingFinishedFunctor functor(eventProcessingFinished);
595   scene.EventProcessingFinishedSignal().Connect(&application, functor);
596
597   Actor actor(Actor::New());
598   scene.Add(actor);
599
600   application.SendNotification();
601   application.Render();
602
603   DALI_TEST_CHECK(eventProcessingFinished);
604
605   END_TEST;
606 }
607
608 int UtcDaliSceneEventProcessingFinishedN(void)
609 {
610   TestApplication          application;
611   Dali::Integration::Scene scene = application.GetScene();
612
613   bool                           eventProcessingFinished = false;
614   EventProcessingFinishedFunctor functor(eventProcessingFinished);
615   scene.EventProcessingFinishedSignal().Connect(&application, functor);
616
617   Actor actor(Actor::New());
618   scene.Add(actor);
619
620   // Do not complete event processing and confirm the signal has not been emitted.
621   DALI_TEST_CHECK(!eventProcessingFinished);
622
623   END_TEST;
624 }
625
626 int UtcDaliSceneSignalKeyEventP(void)
627 {
628   TestApplication          application;
629   Dali::Integration::Scene scene = application.GetScene();
630
631   KeyEventSignalData      data;
632   KeyEventReceivedFunctor functor(data);
633   scene.KeyEventSignal().Connect(&application, functor);
634
635   Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
636   application.ProcessEvent(event);
637
638   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
640   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
641   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
642   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
643
644   data.Reset();
645
646   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
647   application.ProcessEvent(event2);
648
649   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
651   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
652   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
653   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
654
655   data.Reset();
656
657   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
658   application.ProcessEvent(event3);
659
660   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
661   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
662   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
663   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
664   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
665
666   data.Reset();
667
668   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
669   application.ProcessEvent(event4);
670
671   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
673   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
674   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
675   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
676   END_TEST;
677 }
678
679 int UtcDaliSceneSignalKeyEventN(void)
680 {
681   TestApplication          application;
682   Dali::Integration::Scene scene = application.GetScene();
683
684   KeyEventSignalData      data;
685   KeyEventReceivedFunctor functor(data);
686   scene.KeyEventSignal().Connect(&application, functor);
687
688   // Check that a non-pressed key events data is not modified.
689   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
690
691   END_TEST;
692 }
693
694 int UtcDaliSceneTouchedSignalP(void)
695 {
696   TestApplication          application;
697   Dali::Integration::Scene scene = application.GetScene();
698
699   TouchedSignalData data;
700   TouchFunctor      functor(data);
701   scene.TouchedSignal().Connect(&application, functor);
702
703   // Render and notify.
704   application.SendNotification();
705   application.Render();
706
707   // Basic test: No actors, single touch (down then up).
708   {
709     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
710
711     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
712     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
713     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
714     data.Reset();
715
716     GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
717
718     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
719     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
720     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
721     data.Reset();
722   }
723
724   // Add an actor to the scene.
725   Actor actor = Actor::New();
726   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
727   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
728   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
729   actor.TouchedSignal().Connect(&DummyTouchCallback);
730   scene.Add(actor);
731
732   // Render and notify.
733   application.SendNotification();
734   application.Render();
735
736   // Actor on scene, single touch, down in actor, motion, then up outside actor.
737   {
738     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
739
740     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
741     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
742     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
743     data.Reset();
744
745     GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
746
747     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
748     data.Reset();
749
750     GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
751
752     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
753     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
754     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
755     data.Reset();
756   }
757
758   // Multiple touch. Should only receive a touch on first down and last up.
759   {
760     Integration::TouchEvent touchEvent;
761     Integration::Point      point;
762
763     // 1st point
764     point.SetState(PointState::DOWN);
765     point.SetScreenPosition(Vector2(10.0f, 10.0f));
766     touchEvent.points.push_back(point);
767     application.ProcessEvent(touchEvent);
768     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
769     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
770     data.Reset();
771
772     // 2nd point
773     touchEvent.points[0].SetState(PointState::STATIONARY);
774     point.SetDeviceId(1);
775     point.SetScreenPosition(Vector2(50.0f, 50.0f));
776     touchEvent.points.push_back(point);
777     application.ProcessEvent(touchEvent);
778     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
779     data.Reset();
780
781     // Primary point is up
782     touchEvent.points[0].SetState(PointState::UP);
783     touchEvent.points[1].SetState(PointState::STATIONARY);
784     application.ProcessEvent(touchEvent);
785     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
786     data.Reset();
787
788     // Remove 1st point now, 2nd point is now in motion
789     touchEvent.points.erase(touchEvent.points.begin());
790     touchEvent.points[0].SetState(PointState::MOTION);
791     touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
792     application.ProcessEvent(touchEvent);
793     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
794     data.Reset();
795
796     // Final point Up
797     touchEvent.points[0].SetState(PointState::UP);
798     application.ProcessEvent(touchEvent);
799     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
800     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
801     data.Reset();
802   }
803   END_TEST;
804 }
805
806 int UtcDaliSceneTouchedSignalN(void)
807 {
808   TestApplication          application;
809   Dali::Integration::Scene scene = application.GetScene();
810
811   TouchedSignalData data;
812   TouchFunctor      functor(data);
813   scene.TouchedSignal().Connect(&application, functor);
814
815   // Render and notify.
816   application.SendNotification();
817   application.Render();
818
819   // Confirm functor not called before there has been any touch event.
820   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
821
822   // No actors, single touch, down, motion then up.
823   {
824     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
825
826     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
827     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
828     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
829
830     data.Reset();
831
832     // Confirm there is no signal when the touchpoint is only moved.
833     GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
834
835     DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
836     data.Reset();
837
838     // Confirm a following up event generates a signal.
839     GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
840
841     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
842     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
843     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
844     data.Reset();
845   }
846
847   // Add an actor to the scene.
848   Actor actor = Actor::New();
849   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
850   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
851   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
852   actor.TouchedSignal().Connect(&DummyTouchCallback);
853   scene.Add(actor);
854
855   // Render and notify.
856   application.SendNotification();
857   application.Render();
858
859   // Actor on scene. Interrupted before down and interrupted after down.
860   {
861     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
862
863     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
864     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
865     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
866     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
867     data.Reset();
868
869     GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
870
871     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
872     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
873     DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
874     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
875     data.Reset();
876
877     GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
878
879     DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
880     DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
881     DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
882     DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
883
884     DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
885
886     // Check that getting info about a non-existent point returns an empty handle
887     Actor actor = data.receivedTouchEvent.GetHitActor(1);
888     DALI_TEST_CHECK(!actor);
889
890     data.Reset();
891   }
892
893   END_TEST;
894 }
895
896 int UtcDaliSceneSignalWheelEventP(void)
897 {
898   TestApplication          application;
899   Dali::Integration::Scene scene = application.GetScene();
900
901   WheelEventSignalData      data;
902   WheelEventReceivedFunctor functor(data);
903   scene.WheelEventSignal().Connect(&application, functor);
904
905   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
906   application.ProcessEvent(event);
907
908   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
910   DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
911   DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
912   DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
913   DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
914   DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
915
916   data.Reset();
917
918   Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
919   application.ProcessEvent(event2);
920
921   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
922   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
923   DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
924   DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
925   DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
926   DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
927   DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
928   END_TEST;
929 }
930
931 int UtcDaliSceneSurfaceResizedDefaultScene(void)
932 {
933   tet_infoline("Ensure resizing of the surface is handled properly");
934
935   TestApplication application;
936
937   auto defaultScene = application.GetScene();
938   DALI_TEST_CHECK(defaultScene);
939
940   // Ensure stage size matches the scene size
941   auto stage = Stage::GetCurrent();
942   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
943
944   // Resize the scene
945   Vector2 newSize(1000.0f, 2000.0f);
946   DALI_TEST_CHECK(stage.GetSize() != newSize);
947   defaultScene.SurfaceResized(newSize.width, newSize.height);
948
949   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
950   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
951
952   END_TEST;
953 }
954
955 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
956 {
957   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
958
959   TestApplication    application;
960   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
961   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
962   glAbstraction.EnableViewportCallTrace(true);
963
964   // Initial scene setup
965   Geometry geometry = CreateQuadGeometry();
966   Shader   shader   = CreateShader();
967   Renderer renderer = Renderer::New(geometry, shader);
968
969   Actor actor = Actor::New();
970   actor.AddRenderer(renderer);
971   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
972   application.GetScene().Add(actor);
973
974   // Render before resizing surface
975   application.SendNotification();
976   application.Render(0);
977   glAbstraction.ResetViewportCallStack();
978
979   auto defaultScene = application.GetScene();
980   DALI_TEST_CHECK(defaultScene);
981
982   // consume the resize flag by first rendering
983   defaultScene.IsSurfaceRectChanged();
984
985   // Ensure stage size matches the scene size
986   auto stage = Stage::GetCurrent();
987   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
988
989   Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
990
991   bool surfaceResized;
992   // check resized flag before surface is resized.
993   surfaceResized = defaultScene.IsSurfaceRectChanged();
994   DALI_TEST_EQUALS(surfaceResized, false, TEST_LOCATION);
995
996   // Resize the scene
997   Vector2     newSize(1000.0f, 2000.0f);
998   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
999   DALI_TEST_CHECK(stage.GetSize() != newSize);
1000   defaultScene.SurfaceResized(newSize.width, newSize.height);
1001
1002   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1003   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1004
1005   // Check current surface rect
1006   Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
1007
1008   // It should not be changed yet.
1009   DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
1010
1011   // Render after resizing surface
1012   application.SendNotification();
1013   application.Render(0);
1014
1015   surfaceResized = defaultScene.IsSurfaceRectChanged();
1016   DALI_TEST_EQUALS(surfaceResized, true, TEST_LOCATION);
1017
1018   // Check that the viewport is handled properly
1019   DALI_TEST_CHECK(callStack.FindIndexFromMethodAndParams("Viewport", viewportParams) >= 0);
1020
1021   // Check current surface rect
1022   newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
1023
1024   // It should be changed
1025   DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
1026   DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
1027   DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
1028   DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
1029
1030   END_TEST;
1031 }
1032
1033 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1034 {
1035   tet_infoline("Ensure resizing of the surface & viewport is handled properly");
1036
1037   TestApplication    application;
1038   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1039   TraceCallStack&    callStack     = glAbstraction.GetViewportTrace();
1040   glAbstraction.EnableViewportCallTrace(true);
1041
1042   // Initial scene setup
1043   auto scene = application.GetScene();
1044
1045   Geometry geometry = CreateQuadGeometry();
1046   Shader   shader   = CreateShader();
1047   Renderer renderer = Renderer::New(geometry, shader);
1048
1049   Actor actor = Actor::New();
1050   actor.AddRenderer(renderer);
1051   int testWidth  = 400;
1052   int testHeight = 400;
1053   actor.SetProperty(Actor::Property::SIZE, Vector2(testWidth, testHeight));
1054   scene.Add(actor);
1055
1056   CameraActor offscreenCameraActor = CameraActor::New(Size(testWidth, testHeight));
1057   application.GetScene().Add(offscreenCameraActor);
1058
1059   FrameBuffer newFrameBuffer = FrameBuffer::New(testWidth, testHeight, FrameBuffer::Attachment::NONE);
1060
1061   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
1062   newTask.SetCameraActor(offscreenCameraActor);
1063   newTask.SetSourceActor(actor);
1064   newTask.SetFrameBuffer(newFrameBuffer);
1065   newTask.SetViewportPosition(Vector2(0, 0));
1066   newTask.SetViewportSize(Vector2(testWidth, testHeight));
1067
1068   // Render before resizing surface
1069   application.SendNotification();
1070   application.Render(0);
1071   glAbstraction.ResetViewportCallStack();
1072
1073   Rect<int32_t> initialViewport = newTask.GetViewport();
1074   int           initialWidth    = initialViewport.width;
1075   int           initialHeight   = initialViewport.height;
1076   DALI_TEST_EQUALS(initialWidth, testWidth, TEST_LOCATION);
1077   DALI_TEST_EQUALS(initialHeight, testHeight, TEST_LOCATION);
1078
1079   auto defaultScene = application.GetScene();
1080   DALI_TEST_CHECK(defaultScene);
1081
1082   // Ensure stage size matches the scene size
1083   auto stage = Stage::GetCurrent();
1084   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
1085
1086   // Resize the scene
1087   Vector2     newSize(1000.0f, 2000.0f);
1088   std::string viewportParams("0, 0, 1000, 2000"); // to match newSize
1089   DALI_TEST_CHECK(stage.GetSize() != newSize);
1090   defaultScene.SurfaceResized(newSize.width, newSize.height);
1091
1092   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
1093   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
1094
1095   // Render after resizing surface
1096   application.SendNotification();
1097   application.Render(0);
1098
1099   // Check that the viewport is handled properly
1100   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
1101
1102   // Second render-task should not be affected
1103   Rect<int32_t> viewport = newTask.GetViewport();
1104   int           width    = viewport.width;
1105   int           height   = viewport.height;
1106   DALI_TEST_EQUALS(width, testWidth, TEST_LOCATION);
1107   DALI_TEST_EQUALS(height, testHeight, TEST_LOCATION);
1108
1109   END_TEST;
1110 }
1111
1112 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1113 {
1114   tet_infoline("Ensure resizing of the surface is handled properly on additional scenes");
1115
1116   TestApplication application;
1117   Vector2         originalSurfaceSize(500.0f, 1000.0f);
1118
1119   auto scene = Integration::Scene::New(Size(originalSurfaceSize.width, originalSurfaceSize.height));
1120
1121   // Ensure stage size does NOT match the surface size
1122   auto       stage     = Stage::GetCurrent();
1123   const auto stageSize = stage.GetSize();
1124   DALI_TEST_CHECK(stageSize != originalSurfaceSize);
1125   DALI_TEST_EQUALS(originalSurfaceSize, scene.GetSize(), TEST_LOCATION);
1126
1127   // Resize the surface and inform the scene accordingly
1128   Vector2 newSize(1000.0f, 2000.0f);
1129   DALI_TEST_CHECK(stage.GetSize() != newSize);
1130   scene.SurfaceResized(newSize.width, newSize.height);
1131
1132   // Ensure the stage hasn't been resized
1133   DALI_TEST_EQUALS(stage.GetSize(), stageSize, TEST_LOCATION);
1134   DALI_TEST_EQUALS(scene.GetSize(), newSize, TEST_LOCATION);
1135
1136   END_TEST;
1137 }
1138
1139 #define CLIPPING_RECT_X (16)
1140 #define CLIPPING_RECT_Y (768)
1141 #define CLIPPING_RECT_WIDTH (32)
1142 #define CLIPPING_RECT_HEIGHT (32)
1143
1144 int UtcDaliSceneSurfaceRotatedWithAngle0(void)
1145 {
1146   tet_infoline("Ensure rotation of the surface is handled properly with Angle 0");
1147
1148   TestApplication application(
1149     TestApplication::DEFAULT_SURFACE_WIDTH,
1150     TestApplication::DEFAULT_SURFACE_HEIGHT,
1151     TestApplication::DEFAULT_HORIZONTAL_DPI,
1152     TestApplication::DEFAULT_VERTICAL_DPI,
1153     true,
1154     true);
1155
1156   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1157
1158   std::vector<Rect<int>> damagedRects;
1159   Rect<int>              clippingRect;
1160   application.SendNotification();
1161   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1162
1163   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1164
1165   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1166   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1167
1168   Actor actor = CreateRenderableActor();
1169   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1170   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1171   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1172   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1173   application.GetScene().Add(actor);
1174
1175   // consume the orientating changing flag by first rendering
1176   application.SendNotification();
1177
1178   damagedRects.clear();
1179   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1180                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1181                                         0, 0);
1182
1183   // Check current orientations
1184   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1185   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1186
1187   // It should not be changed yet.
1188   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1189   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1190
1191   application.SendNotification();
1192   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1193   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1194
1195   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1196   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1197   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1198
1199   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1200   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1201   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1202   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1203
1204   // Check current orientations
1205   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1206   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1207
1208   // It should be changed.
1209   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1210   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1211
1212   END_TEST;
1213 }
1214
1215 int UtcDaliSceneSurfaceRotatedWithAngle90(void)
1216 {
1217   tet_infoline("Ensure rotation of the surface is handled properly with Angle 90");
1218
1219   TestApplication application(
1220     TestApplication::DEFAULT_SURFACE_WIDTH,
1221     TestApplication::DEFAULT_SURFACE_HEIGHT,
1222     TestApplication::DEFAULT_HORIZONTAL_DPI,
1223     TestApplication::DEFAULT_VERTICAL_DPI,
1224     true,
1225     true);
1226
1227   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1228
1229   std::vector<Rect<int>> damagedRects;
1230   Rect<int>              clippingRect;
1231   application.SendNotification();
1232   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1233
1234   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1235
1236   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1237   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1238
1239   Actor actor = CreateRenderableActor();
1240   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1241   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1242   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1243   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1244   application.GetScene().Add(actor);
1245
1246   application.SendNotification();
1247
1248   damagedRects.clear();
1249   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1250                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1251                                         90, 0);
1252
1253   // Check current surface orientation
1254   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1255   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1256
1257   // It should not be changed yet.
1258   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1259   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1260
1261   application.SendNotification();
1262   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1263   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1264
1265   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1266   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1267   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1268
1269   // It is recalculation for glScissor.
1270   // Because surface is rotated and glScissor is called with recalcurated value.
1271   // Total angle is 90, (90 + 0 = 90)
1272   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1273   clippingRect.y      = CLIPPING_RECT_X;
1274   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1275   clippingRect.height = CLIPPING_RECT_WIDTH;
1276
1277   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1278   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1279   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1280   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1281
1282   // Check current orientations
1283   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1284   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1285
1286   // It should be changed.
1287   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1288   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1289
1290   END_TEST;
1291 }
1292
1293 int UtcDaliSceneScreenRotatedWithAngle90(void)
1294 {
1295   tet_infoline("Ensure rotation of the screen is handled properly with Angle 90");
1296
1297   TestApplication application(
1298     TestApplication::DEFAULT_SURFACE_WIDTH,
1299     TestApplication::DEFAULT_SURFACE_HEIGHT,
1300     TestApplication::DEFAULT_HORIZONTAL_DPI,
1301     TestApplication::DEFAULT_VERTICAL_DPI,
1302     true,
1303     true);
1304
1305   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1306
1307   std::vector<Rect<int>> damagedRects;
1308   Rect<int>              clippingRect;
1309   application.SendNotification();
1310   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1311
1312   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1313
1314   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1315   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1316
1317   Actor actor = CreateRenderableActor();
1318   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1319   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1320   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1321   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1322   application.GetScene().Add(actor);
1323
1324   application.SendNotification();
1325
1326   damagedRects.clear();
1327   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1328                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1329                                         0, 90);
1330
1331   // Check current surface orientation
1332   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1333   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1334
1335   // It should not be changed yet.
1336   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1337   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1338
1339   application.SendNotification();
1340   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1341   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1342
1343   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1344   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1345   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1346
1347   // It is recalculation for glScissor.
1348   // Because surface is rotated and glScissor is called with recalcurated value.
1349   // Total angle is 90, (0 + 90 = 90)
1350   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1351   clippingRect.y      = CLIPPING_RECT_X;
1352   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1353   clippingRect.height = CLIPPING_RECT_WIDTH;
1354
1355   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1356   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1357   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1358   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1359
1360   // Check current orientations
1361   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1362   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1363
1364   // It should be changed.
1365   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1366   DALI_TEST_EQUALS(screenOrientation, 90, TEST_LOCATION);
1367
1368   END_TEST;
1369 }
1370
1371 int UtcDaliSceneSurfaceAndScreenRotatedWithAngle90(void)
1372 {
1373   tet_infoline("Ensure rotation of the surface and the screen is handled properly with Angle 90");
1374
1375   TestApplication application(
1376     TestApplication::DEFAULT_SURFACE_WIDTH,
1377     TestApplication::DEFAULT_SURFACE_HEIGHT,
1378     TestApplication::DEFAULT_HORIZONTAL_DPI,
1379     TestApplication::DEFAULT_VERTICAL_DPI,
1380     true,
1381     true);
1382
1383   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1384
1385   std::vector<Rect<int>> damagedRects;
1386   Rect<int>              clippingRect;
1387   application.SendNotification();
1388   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1389
1390   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1391
1392   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1393   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1394
1395   Actor actor = CreateRenderableActor();
1396   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1397   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1398   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1399   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1400   application.GetScene().Add(actor);
1401
1402   application.SendNotification();
1403
1404   damagedRects.clear();
1405   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1406                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1407                                         90, 90);
1408
1409   // Check current surface orientation
1410   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1411   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1412
1413   // It should not be changed yet.
1414   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1415   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1416
1417   application.SendNotification();
1418   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1419   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1420
1421   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1422   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1423   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1424
1425   // It is recalculation for glScissor.
1426   // Because surface is rotated and glScissor is called with recalcurated value.
1427   // Total angle is 180.(90 + 90 = 180)
1428   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1429   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1430   clippingRect.width  = CLIPPING_RECT_WIDTH;
1431   clippingRect.height = CLIPPING_RECT_HEIGHT;
1432
1433   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1434   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1435   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1436   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1437
1438   // Check current orientations
1439   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1440   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1441
1442   // It should be changed.
1443   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1444   DALI_TEST_EQUALS(screenOrientation, 90, TEST_LOCATION);
1445
1446   END_TEST;
1447 }
1448
1449 int UtcDaliSceneSurfaceRotatedWithAngle180(void)
1450 {
1451   tet_infoline("Ensure rotation of the surface is handled properly with Angle 180");
1452
1453   TestApplication application(
1454     TestApplication::DEFAULT_SURFACE_WIDTH,
1455     TestApplication::DEFAULT_SURFACE_HEIGHT,
1456     TestApplication::DEFAULT_HORIZONTAL_DPI,
1457     TestApplication::DEFAULT_VERTICAL_DPI,
1458     true,
1459     true);
1460
1461   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1462
1463   std::vector<Rect<int>> damagedRects;
1464   Rect<int>              clippingRect;
1465   application.SendNotification();
1466   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1467
1468   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1469
1470   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1471   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1472
1473   Actor actor = CreateRenderableActor();
1474   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1475   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1476   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1477   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1478   application.GetScene().Add(actor);
1479
1480   application.SendNotification();
1481
1482   damagedRects.clear();
1483   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1484                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1485                                         180, 0);
1486
1487   // Check current surface orientation
1488   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1489   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1490
1491   // It should not be changed yet.
1492   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1493   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1494
1495   application.SendNotification();
1496   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1497   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1498
1499   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1500   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1501   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1502
1503   // It is recalculation for glScissor.
1504   // Because surface is rotated and glScissor is called with recalcurated value.
1505   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1506   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1507   clippingRect.width  = CLIPPING_RECT_WIDTH;
1508   clippingRect.height = CLIPPING_RECT_HEIGHT;
1509
1510   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1511   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1512   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1513   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1514
1515   // Check current orientations
1516   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1517   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1518
1519   // It should be changed.
1520   DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1521   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1522
1523   END_TEST;
1524 }
1525
1526 int UtcDaliSceneScreenRotatedWithAngle180(void)
1527 {
1528   tet_infoline("Ensure rotation of the screen is handled properly with Angle 180");
1529
1530   TestApplication application(
1531     TestApplication::DEFAULT_SURFACE_WIDTH,
1532     TestApplication::DEFAULT_SURFACE_HEIGHT,
1533     TestApplication::DEFAULT_HORIZONTAL_DPI,
1534     TestApplication::DEFAULT_VERTICAL_DPI,
1535     true,
1536     true);
1537
1538   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1539
1540   std::vector<Rect<int>> damagedRects;
1541   Rect<int>              clippingRect;
1542   application.SendNotification();
1543   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1544
1545   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1546
1547   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1548   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1549
1550   Actor actor = CreateRenderableActor();
1551   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1552   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1553   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1554   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1555   application.GetScene().Add(actor);
1556
1557   application.SendNotification();
1558
1559   damagedRects.clear();
1560   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1561                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1562                                         0, 180);
1563
1564   // Check current surface orientation
1565   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1566   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1567
1568   // It should not be changed yet.
1569   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1570   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1571
1572   application.SendNotification();
1573   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1574   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1575
1576   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1577   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1578   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1579
1580   // It is recalculation for glScissor.
1581   // Because surface is rotated and glScissor is called with recalcurated value.
1582   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1583   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1584   clippingRect.width  = CLIPPING_RECT_WIDTH;
1585   clippingRect.height = CLIPPING_RECT_HEIGHT;
1586
1587   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1588   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1589   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1590   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1591
1592   // Check current orientations
1593   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1594   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1595
1596   // It should be changed.
1597   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1598   DALI_TEST_EQUALS(screenOrientation, 180, TEST_LOCATION);
1599
1600   END_TEST;
1601 }
1602
1603 int UtcDaliSceneSurfaceAndScreenRotatedWithAngle180(void)
1604 {
1605   tet_infoline("Ensure rotation of the surface and the screen is handled properly with Angle 180");
1606
1607   TestApplication application(
1608     TestApplication::DEFAULT_SURFACE_WIDTH,
1609     TestApplication::DEFAULT_SURFACE_HEIGHT,
1610     TestApplication::DEFAULT_HORIZONTAL_DPI,
1611     TestApplication::DEFAULT_VERTICAL_DPI,
1612     true,
1613     true);
1614
1615   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1616
1617   std::vector<Rect<int>> damagedRects;
1618   Rect<int>              clippingRect;
1619   application.SendNotification();
1620   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1621
1622   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1623
1624   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1625   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1626
1627   Actor actor = CreateRenderableActor();
1628   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1629   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1630   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1631   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1632   application.GetScene().Add(actor);
1633
1634   // consume the orientating changing flag by first rendering
1635   application.SendNotification();
1636
1637   damagedRects.clear();
1638   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1639                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1640                                         180, 180);
1641
1642   // Check current orientations
1643   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1644   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1645
1646   // It should not be changed yet.
1647   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1648   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1649
1650   application.SendNotification();
1651   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1652   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1653
1654   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1655   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1656   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1657
1658   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1659   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1660   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1661   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1662
1663   // Check current orientations
1664   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1665   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1666
1667   // It should be changed.
1668   DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
1669   DALI_TEST_EQUALS(screenOrientation, 180, TEST_LOCATION);
1670
1671   END_TEST;
1672 }
1673
1674 int UtcDaliSceneSurfaceRotatedWithAngle270(void)
1675 {
1676   tet_infoline("Ensure rotation of the surface is handled properly with Angle 270");
1677
1678   TestApplication application(
1679     TestApplication::DEFAULT_SURFACE_WIDTH,
1680     TestApplication::DEFAULT_SURFACE_HEIGHT,
1681     TestApplication::DEFAULT_HORIZONTAL_DPI,
1682     TestApplication::DEFAULT_VERTICAL_DPI,
1683     true,
1684     true);
1685
1686   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1687
1688   std::vector<Rect<int>> damagedRects;
1689   Rect<int>              clippingRect;
1690   application.SendNotification();
1691   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1692
1693   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1694
1695   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1696   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1697
1698   Actor actor = CreateRenderableActor();
1699   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1700   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1701   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1702   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1703   application.GetScene().Add(actor);
1704
1705   application.SendNotification();
1706
1707   damagedRects.clear();
1708   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1709                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1710                                         270, 0);
1711
1712   // Check current surface orientation
1713   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1714   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1715
1716   // It should not be changed yet.
1717   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1718   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1719
1720   application.SendNotification();
1721   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1722   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1723
1724   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1725   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1726   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1727
1728   // It is recalculation for glScissor.
1729   // Because surface is rotated and glScissor is called with recalcurated value.
1730   // Total angle is 270. (270 + 0 = 270)
1731   clippingRect.x      = CLIPPING_RECT_Y;
1732   clippingRect.y      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1733   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1734   clippingRect.height = CLIPPING_RECT_WIDTH;
1735
1736   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1737   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1738   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1739   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1740
1741   // Check current orientations
1742   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1743   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1744
1745   // It should be changed.
1746   DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1747   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1748
1749   END_TEST;
1750 }
1751
1752 int UtcDaliSceneScreenRotatedWithAngle270(void)
1753 {
1754   tet_infoline("Ensure rotation of the screen is handled properly with Angle 270");
1755
1756   TestApplication application(
1757     TestApplication::DEFAULT_SURFACE_WIDTH,
1758     TestApplication::DEFAULT_SURFACE_HEIGHT,
1759     TestApplication::DEFAULT_HORIZONTAL_DPI,
1760     TestApplication::DEFAULT_VERTICAL_DPI,
1761     true,
1762     true);
1763
1764   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1765
1766   std::vector<Rect<int>> damagedRects;
1767   Rect<int>              clippingRect;
1768   application.SendNotification();
1769   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1770
1771   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1772
1773   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1774   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1775
1776   Actor actor = CreateRenderableActor();
1777   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1778   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1779   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1780   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1781   application.GetScene().Add(actor);
1782
1783   application.SendNotification();
1784
1785   damagedRects.clear();
1786   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1787                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1788                                         0, 270);
1789
1790   // Check current surface orientation
1791   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1792   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1793
1794   // It should not be changed yet.
1795   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1796   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1797
1798   application.SendNotification();
1799   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1800   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1801
1802   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1803   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1804   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1805
1806   // It is recalculation for glScissor.
1807   // Because surface is rotated and glScissor is called with recalcurated value.
1808   // Total angle is 270. (0 + 270 = 270)
1809   clippingRect.x      = CLIPPING_RECT_Y;
1810   clippingRect.y      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1811   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1812   clippingRect.height = CLIPPING_RECT_WIDTH;
1813
1814   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1815   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1816   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1817   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1818
1819   // Check current orientations
1820   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1821   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1822
1823   // It should be changed.
1824   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1825   DALI_TEST_EQUALS(screenOrientation, 270, TEST_LOCATION);
1826
1827   END_TEST;
1828 }
1829
1830 int UtcDaliSceneSurfaceAndScreenRotatedWithAngle270(void)
1831 {
1832   tet_infoline("Ensure rotation of the surface and the screen is handled properly with Angle 270");
1833
1834   TestApplication application(
1835     TestApplication::DEFAULT_SURFACE_WIDTH,
1836     TestApplication::DEFAULT_SURFACE_HEIGHT,
1837     TestApplication::DEFAULT_HORIZONTAL_DPI,
1838     TestApplication::DEFAULT_VERTICAL_DPI,
1839     true,
1840     true);
1841
1842   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1843
1844   std::vector<Rect<int>> damagedRects;
1845   Rect<int>              clippingRect;
1846   application.SendNotification();
1847   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1848
1849   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1850
1851   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
1852   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1853
1854   Actor actor = CreateRenderableActor();
1855   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1856   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1857   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1858   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1859   application.GetScene().Add(actor);
1860
1861   application.SendNotification();
1862
1863   damagedRects.clear();
1864   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1865                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1866                                         270, 270);
1867
1868   // Check current surface orientation
1869   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1870   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1871
1872   // It should not be changed yet.
1873   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1874   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1875
1876   application.SendNotification();
1877   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1878   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1879
1880   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1881   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1882   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1883
1884   // It is recalculation for glScissor.
1885   // Because surface is rotated and glScissor is called with recalcurated value.
1886   // Total angle is 180.(270 + 270 - 360 = 180)
1887   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
1888   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1889   clippingRect.width  = CLIPPING_RECT_WIDTH;
1890   clippingRect.height = CLIPPING_RECT_HEIGHT;
1891
1892   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1893   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1894   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1895   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1896
1897   // Check current orientations
1898   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1899   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1900
1901   // It should be changed.
1902   DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
1903   DALI_TEST_EQUALS(screenOrientation, 270, TEST_LOCATION);
1904
1905   END_TEST;
1906 }
1907
1908 int UtcDaliSceneSetSurfaceRotationCompletedAcknowledgementWithAngle90(void)
1909 {
1910   tet_infoline("Ensure to acknowledge for completing surface 90 angle rotaiton");
1911
1912   TestApplication application(
1913     TestApplication::DEFAULT_SURFACE_WIDTH,
1914     TestApplication::DEFAULT_SURFACE_HEIGHT,
1915     TestApplication::DEFAULT_HORIZONTAL_DPI,
1916     TestApplication::DEFAULT_VERTICAL_DPI,
1917     true,
1918     true);
1919
1920   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1921
1922   std::vector<Rect<int>> damagedRects;
1923   Rect<int>              clippingRect;
1924   application.SendNotification();
1925   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1926
1927   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1928   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1929
1930   Actor actor = CreateRenderableActor();
1931   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1932   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1933   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1934   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
1935   application.GetScene().Add(actor);
1936
1937   application.SendNotification();
1938
1939   damagedRects.clear();
1940   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
1941                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
1942                                         90, 0);
1943
1944   // Check current surface orientation
1945   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
1946   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1947
1948   // It should not be changed yet.
1949   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
1950   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1951
1952   application.GetScene().SetRotationCompletedAcknowledgement();
1953
1954   application.SendNotification();
1955   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1956   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1957
1958   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
1959   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
1960   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1961
1962   // It is recalculation for glScissor.
1963   // Because surface is rotated and glScissor is called with recalcurated value.
1964   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
1965   clippingRect.y      = CLIPPING_RECT_X;
1966   clippingRect.width  = CLIPPING_RECT_HEIGHT;
1967   clippingRect.height = CLIPPING_RECT_WIDTH;
1968
1969   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1970   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1971   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1972   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1973
1974   // Check current orientations
1975   orientation = application.GetScene().GetCurrentSurfaceOrientation();
1976   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
1977
1978   // It should be changed.
1979   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
1980   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
1981
1982   bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
1983   DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
1984
1985   END_TEST;
1986 }
1987
1988 int UtcDaliSceneSetScreenRotationCompletedAcknowledgementWithAngle90(void)
1989 {
1990   tet_infoline("Ensure to acknowledge for completing screen 90 angle rotaiton");
1991
1992   TestApplication application(
1993     TestApplication::DEFAULT_SURFACE_WIDTH,
1994     TestApplication::DEFAULT_SURFACE_HEIGHT,
1995     TestApplication::DEFAULT_HORIZONTAL_DPI,
1996     TestApplication::DEFAULT_VERTICAL_DPI,
1997     true,
1998     true);
1999
2000   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
2001
2002   std::vector<Rect<int>> damagedRects;
2003   Rect<int>              clippingRect;
2004   application.SendNotification();
2005   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2006
2007   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
2008   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2009
2010   Actor actor = CreateRenderableActor();
2011   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2012   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
2013   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
2014   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
2015   application.GetScene().Add(actor);
2016
2017   application.SendNotification();
2018
2019   damagedRects.clear();
2020   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
2021                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
2022                                         0, 90);
2023
2024   // Check current surface orientation
2025   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
2026   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
2027
2028   // It should not be changed yet.
2029   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
2030   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
2031
2032   application.GetScene().SetRotationCompletedAcknowledgement();
2033
2034   application.SendNotification();
2035   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2036   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
2037
2038   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
2039   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
2040   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2041
2042   // It is recalculation for glScissor.
2043   // Because surface is rotated and glScissor is called with recalcurated value.
2044   clippingRect.x      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
2045   clippingRect.y      = CLIPPING_RECT_X;
2046   clippingRect.width  = CLIPPING_RECT_HEIGHT;
2047   clippingRect.height = CLIPPING_RECT_WIDTH;
2048
2049   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
2050   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
2051   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
2052   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
2053
2054   // Check current orientations
2055   orientation = application.GetScene().GetCurrentSurfaceOrientation();
2056   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
2057
2058   // It should be changed.
2059   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
2060   DALI_TEST_EQUALS(screenOrientation, 90, TEST_LOCATION);
2061
2062   bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
2063   DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
2064
2065   END_TEST;
2066 }
2067
2068 int UtcDaliSceneSetSurfaceAndScreenRotationCompletedAcknowledgementWithAngle90(void)
2069 {
2070   tet_infoline("Ensure to acknowledge for completing surface and screen 90 angle rotaiton");
2071
2072   TestApplication application(
2073     TestApplication::DEFAULT_SURFACE_WIDTH,
2074     TestApplication::DEFAULT_SURFACE_HEIGHT,
2075     TestApplication::DEFAULT_HORIZONTAL_DPI,
2076     TestApplication::DEFAULT_VERTICAL_DPI,
2077     true,
2078     true);
2079
2080   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
2081
2082   std::vector<Rect<int>> damagedRects;
2083   Rect<int>              clippingRect;
2084   application.SendNotification();
2085   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2086
2087   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
2088   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2089
2090   Actor actor = CreateRenderableActor();
2091   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2092   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
2093   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
2094   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
2095   application.GetScene().Add(actor);
2096
2097   application.SendNotification();
2098
2099   damagedRects.clear();
2100   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
2101                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
2102                                         90, 90);
2103
2104   // Check current surface orientation
2105   int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
2106   int32_t screenOrientation = application.GetScene().GetCurrentScreenOrientation();
2107
2108   // It should not be changed yet.
2109   DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
2110   DALI_TEST_EQUALS(screenOrientation, 0, TEST_LOCATION);
2111
2112   application.GetScene().SetRotationCompletedAcknowledgement();
2113
2114   application.SendNotification();
2115   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2116   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
2117
2118   clippingRect = Rect<int>(CLIPPING_RECT_X, CLIPPING_RECT_Y, CLIPPING_RECT_WIDTH, CLIPPING_RECT_HEIGHT); // in screen coordinates, includes 3 last frames updates
2119   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
2120   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2121
2122   // It is recalculation for glScissor.
2123   // Because surface is rotated and glScissor is called with recalcurated value.
2124   clippingRect.x      = TestApplication::DEFAULT_SURFACE_WIDTH - (CLIPPING_RECT_X + CLIPPING_RECT_WIDTH);
2125   clippingRect.y      = TestApplication::DEFAULT_SURFACE_HEIGHT - (CLIPPING_RECT_Y + CLIPPING_RECT_HEIGHT);
2126   clippingRect.width  = CLIPPING_RECT_WIDTH;
2127   clippingRect.height = CLIPPING_RECT_HEIGHT;
2128
2129   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
2130   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
2131   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
2132   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
2133
2134   // Check current orientations
2135   orientation = application.GetScene().GetCurrentSurfaceOrientation();
2136   screenOrientation = application.GetScene().GetCurrentScreenOrientation();
2137
2138   // It should be changed.
2139   DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
2140   DALI_TEST_EQUALS(screenOrientation, 90, TEST_LOCATION);
2141
2142   bool isSetRotationCompletedAcknowledgementSet = application.GetScene().IsRotationCompletedAcknowledgementSet();
2143   DALI_TEST_EQUALS(isSetRotationCompletedAcknowledgementSet, true, TEST_LOCATION);
2144
2145   END_TEST;
2146 }
2147
2148 int UtcDaliSceneSurfaceRotatedPartialUpdate(void)
2149 {
2150   tet_infoline("Ensure rotation of the surface and partial update are handled properly");
2151
2152   TestApplication application(
2153     TestApplication::DEFAULT_SURFACE_WIDTH,
2154     TestApplication::DEFAULT_SURFACE_HEIGHT,
2155     TestApplication::DEFAULT_HORIZONTAL_DPI,
2156     TestApplication::DEFAULT_VERTICAL_DPI,
2157     true,
2158     true);
2159
2160   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
2161
2162   std::vector<Rect<int>> damagedRects;
2163   Rect<int>              clippingRect;
2164   application.SendNotification();
2165   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2166
2167   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
2168
2169   clippingRect = TestApplication::DEFAULT_SURFACE_RECT;
2170   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2171
2172   Actor actor = CreateRenderableActor();
2173   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
2174   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
2175   actor.SetProperty(Actor::Property::SIZE, Vector3(32.0f, 32.0f, 0.0f));
2176   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
2177   application.GetScene().Add(actor);
2178
2179   application.SendNotification();
2180   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2181
2182   clippingRect = Rect<int>(224, 384, 48, 48); // in screen coordinates
2183   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
2184   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
2185
2186   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2187
2188   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
2189   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
2190   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
2191   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
2192
2193   damagedRects.clear();
2194   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2195   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2196
2197   damagedRects.clear();
2198   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2199   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2200
2201   // Ensure the damaged rect is empty
2202   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
2203
2204   // Rotate surface
2205   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_HEIGHT,
2206                                         TestApplication::DEFAULT_SURFACE_WIDTH,
2207                                         90, 0);
2208
2209   damagedRects.clear();
2210
2211   application.SendNotification();
2212   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
2213
2214   clippingRect = Rect<int>(224, 224, 208, 208); // in screen coordinates, merged value with the previous rect
2215   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
2216   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
2217
2218   application.RenderWithPartialUpdate(damagedRects, clippingRect);
2219
2220   END_TEST;
2221 }
2222
2223 int UtcDaliSceneKeyEventGeneratedSignalP(void)
2224 {
2225   TestApplication          application;
2226   Dali::Integration::Scene scene = application.GetScene();
2227
2228   KeyEventGeneratedSignalData      data;
2229   KeyEventGeneratedReceivedFunctor functor(data);
2230   scene.KeyEventGeneratedSignal().Connect(&application, functor);
2231
2232   Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2233   application.ProcessEvent(event);
2234
2235   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2236   DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
2237   DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
2238   DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
2239   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
2240
2241   data.Reset();
2242
2243   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2244   application.ProcessEvent(event2);
2245
2246   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2247   DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
2248   DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
2249   DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
2250   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
2251
2252   data.Reset();
2253
2254   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2255   application.ProcessEvent(event3);
2256
2257   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2258   DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
2259   DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
2260   DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
2261   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
2262
2263   data.Reset();
2264
2265   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2266   application.ProcessEvent(event4);
2267
2268   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2269   DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
2270   DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
2271   DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
2272   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
2273   END_TEST;
2274 }
2275
2276 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
2277 {
2278   tet_infoline("Ensure we keep background color when the scene surface is replaced ");
2279
2280   TestApplication application;
2281
2282   // Create a new scene and set the background color of the main scene
2283   auto defaultScene = application.GetScene();
2284   defaultScene.SetBackgroundColor(Color::BLUE);
2285
2286   // Need to create a renderable as we don't start rendering until we have at least one
2287   // We don't need to add this to any scene
2288   auto actor = CreateRenderableActor();
2289
2290   auto& glAbstraction    = application.GetGlAbstraction();
2291   auto  clearCountBefore = glAbstraction.GetClearCountCalled();
2292
2293   application.SendNotification();
2294   application.Render();
2295
2296   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION);
2297   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
2298
2299   defaultScene.SurfaceReplaced();
2300
2301   application.SendNotification();
2302   application.Render();
2303
2304   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION);
2305   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
2306
2307   // Check when the main render task viewport is set the clear color is clipped using scissors
2308   TraceCallStack& scissorTrace        = glAbstraction.GetScissorTrace();
2309   TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
2310   scissorTrace.Enable(true);
2311   enabledDisableTrace.Enable(true);
2312
2313   defaultScene.GetRenderTaskList().GetTask(0).SetViewport(Viewport(0.0f, 0.0f, 100.0f, 100.0f));
2314
2315   application.SendNotification();
2316   application.Render();
2317
2318   // Check scissor test was enabled.
2319   std::ostringstream scissor;
2320   scissor << std::hex << GL_SCISSOR_TEST;
2321   DALI_TEST_CHECK(enabledDisableTrace.FindMethodAndParams("Enable", scissor.str()));
2322
2323   // Check the scissor was set, and the coordinates are correct.
2324   DALI_TEST_CHECK(scissorTrace.FindMethodAndParams("Scissor", "0, 700, 100, 100"));
2325
2326   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION);
2327   DALI_TEST_EQUALS(glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION);
2328
2329   scissorTrace.Enable(false);
2330   scissorTrace.Reset();
2331
2332   enabledDisableTrace.Enable(false);
2333   enabledDisableTrace.Reset();
2334
2335   END_TEST;
2336 }
2337
2338 int UtcDaliSceneEnsureRenderTargetRecreated(void)
2339 {
2340   tet_infoline("Ensure render target is re-created when surface replaced ");
2341
2342   TestApplication application;
2343
2344   // Create a new scene and set the background color of the main scene
2345   auto defaultScene = application.GetScene();
2346   defaultScene.SetBackgroundColor(Color::BLUE);
2347
2348   auto actor = CreateRenderableActor();
2349   defaultScene.Add(actor);
2350
2351   auto& graphicsController = application.GetGraphicsController();
2352
2353   application.SendNotification();
2354   application.Render();
2355
2356   TraceCallStack&                    graphicsCallStack = graphicsController.mCallStack;
2357   TraceCallStack::NamedParams        empty{};
2358   const TraceCallStack::NamedParams* matching = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
2359   DALI_TEST_CHECK(matching != nullptr);
2360
2361   graphicsCallStack.Reset();
2362
2363   int                              fakeSurface1;
2364   Graphics::RenderTargetCreateInfo createInfo{};
2365   createInfo.SetSurface(&fakeSurface1).SetExtent(Graphics::Extent2D{480u, 800u});
2366   defaultScene.SetSurfaceRenderTarget(createInfo);
2367
2368   application.SendNotification();
2369   application.Render();
2370
2371   TraceCallStack::NamedParams query1;
2372   query1["surface"] << std::hex << &fakeSurface1;
2373   const TraceCallStack::NamedParams* matching2 = graphicsCallStack.FindLastMatch("CreateRenderTarget", query1);
2374   DALI_TEST_CHECK(matching2 != nullptr);
2375
2376   const TraceCallStack::NamedParams* matching3 = graphicsCallStack.FindLastMatch("PresentRenderTarget", empty);
2377   DALI_TEST_CHECK(matching3 != nullptr);
2378   DALI_TEST_EQUALS((*matching3)["surface"].str(), query1["surface"].str(), TEST_LOCATION);
2379
2380   END_TEST;
2381 }
2382
2383 int UtcDaliSceneEmptySceneRendering(void)
2384 {
2385   tet_infoline("Ensure not rendering before a Renderer is added");
2386
2387   TestApplication    application;
2388   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2389
2390   // Render without any renderer
2391   application.SendNotification();
2392   application.Render();
2393
2394   // Check the clear count and the render status
2395   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
2396   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
2397
2398   // Add a Renderer
2399   Geometry geometry = CreateQuadGeometry();
2400   Shader   shader   = CreateShader();
2401   Renderer renderer = Renderer::New(geometry, shader);
2402
2403   // Render before adding renderer
2404   application.SendNotification();
2405   application.Render();
2406
2407   // Check the clear count and the render status
2408   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION);
2409   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), false, TEST_LOCATION);
2410
2411   Actor actor = Actor::New();
2412   actor.AddRenderer(renderer);
2413
2414   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
2415   application.GetScene().Add(actor);
2416
2417   // Render
2418   application.SendNotification();
2419   application.Render();
2420
2421   // Check the clear count and the render status
2422   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION);
2423   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
2424
2425   // Remove the Renderer
2426   application.GetScene().Remove(actor);
2427   actor.Reset();
2428   renderer.Reset();
2429
2430   // Render
2431   application.SendNotification();
2432   application.Render();
2433
2434   // Check the clear count and the render status
2435   DALI_TEST_EQUALS(glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION); // Should be cleared
2436   DALI_TEST_EQUALS(application.GetRenderNeedsPostRender(), true, TEST_LOCATION);
2437
2438   END_TEST;
2439 }
2440
2441 int UtcDaliSceneFrameRenderedPresentedCallback(void)
2442 {
2443   tet_infoline("UtcDaliSceneFrameRenderedCallback");
2444
2445   TestApplication application;
2446
2447   // Add a Renderer
2448   Geometry geometry = CreateQuadGeometry();
2449   Shader   shader   = CreateShader();
2450   Renderer renderer = Renderer::New(geometry, shader);
2451
2452   Actor actor = Actor::New();
2453   actor.AddRenderer(renderer);
2454   application.GetScene().Add(actor);
2455
2456   Dali::Integration::Scene scene = application.GetScene();
2457
2458   int frameId = 1;
2459   scene.AddFrameRenderedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
2460   scene.AddFramePresentedCallback(std::unique_ptr<CallbackBase>(MakeCallback(&FrameCallback)), frameId);
2461
2462   // Render
2463   application.SendNotification();
2464   application.Render();
2465
2466   Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
2467   scene.GetFrameRenderedCallback(callbackContainer);
2468
2469   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
2470   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
2471
2472   callbackContainer.clear();
2473
2474   scene.GetFramePresentedCallback(callbackContainer);
2475
2476   DALI_TEST_EQUALS(callbackContainer.size(), 1, TEST_LOCATION);
2477   DALI_TEST_EQUALS(callbackContainer[0].second, frameId, TEST_LOCATION);
2478
2479   END_TEST;
2480 }
2481
2482 int UtcDaliSceneWheelEventGeneratedSignalP(void)
2483 {
2484   TestApplication          application;
2485   Dali::Integration::Scene scene = application.GetScene();
2486
2487   WheelEventGeneratedSignalData      data;
2488   WheelEventGeneratedReceivedFunctor functor(data);
2489   scene.WheelEventGeneratedSignal().Connect(&application, functor);
2490
2491   Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
2492   application.ProcessEvent(event);
2493
2494   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2495   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
2496   DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
2497   DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
2498   DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
2499   DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
2500   DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
2501
2502   data.Reset();
2503
2504   Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
2505   application.ProcessEvent(event2);
2506
2507   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2508   DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
2509   DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
2510   DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
2511   DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
2512   DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
2513   DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
2514   END_TEST;
2515 }
2516
2517 int UtcDaliSceneSignalInterceptKeyEventP(void)
2518 {
2519   TestApplication          application;
2520   Dali::Integration::Scene scene = application.GetScene();
2521
2522   KeyEventSignalData      data;
2523   KeyEventReceivedFunctor functor(data);
2524   scene.KeyEventSignal().Connect(&application, functor);
2525
2526   KeyEventGeneratedSignalData      interceptData;
2527   KeyEventGeneratedReceivedFunctor interceptFunctor(interceptData);
2528   scene.InterceptKeyEventSignal().Connect(&application, interceptFunctor);
2529
2530   Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2531   application.ProcessEvent(event);
2532
2533   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2534   DALI_TEST_CHECK(event.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier());
2535   DALI_TEST_CHECK(event.keyName == interceptData.receivedKeyEvent.GetKeyName());
2536   DALI_TEST_CHECK(event.keyString == interceptData.receivedKeyEvent.GetKeyString());
2537   DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(interceptData.receivedKeyEvent.GetState()));
2538   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2539
2540   data.Reset();
2541   interceptData.Reset();
2542
2543   Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2544   application.ProcessEvent(event2);
2545
2546   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2547   DALI_TEST_CHECK(event2.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier());
2548   DALI_TEST_CHECK(event2.keyName == interceptData.receivedKeyEvent.GetKeyName());
2549   DALI_TEST_CHECK(event2.keyString == interceptData.receivedKeyEvent.GetKeyString());
2550   DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(interceptData.receivedKeyEvent.GetState()));
2551   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2552
2553   data.Reset();
2554   interceptData.Reset();
2555
2556   Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2557   application.ProcessEvent(event3);
2558
2559   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2560   DALI_TEST_CHECK(event3.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier());
2561   DALI_TEST_CHECK(event3.keyName == interceptData.receivedKeyEvent.GetKeyName());
2562   DALI_TEST_CHECK(event3.keyString == interceptData.receivedKeyEvent.GetKeyString());
2563   DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(interceptData.receivedKeyEvent.GetState()));
2564   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2565
2566   data.Reset();
2567   interceptData.Reset();
2568
2569   Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
2570   application.ProcessEvent(event4);
2571
2572   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2573   DALI_TEST_CHECK(event4.keyModifier == interceptData.receivedKeyEvent.GetKeyModifier());
2574   DALI_TEST_CHECK(event4.keyName == interceptData.receivedKeyEvent.GetKeyName());
2575   DALI_TEST_CHECK(event4.keyString == interceptData.receivedKeyEvent.GetKeyString());
2576   DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(interceptData.receivedKeyEvent.GetState()));
2577   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2578   END_TEST;
2579 }
2580
2581 int UtcDaliSceneSignalInterceptKeyEventN(void)
2582 {
2583   TestApplication          application;
2584   Dali::Integration::Scene scene = application.GetScene();
2585
2586   KeyEventGeneratedSignalData      data;
2587   KeyEventGeneratedReceivedFunctor functor(data);
2588   scene.InterceptKeyEventSignal().Connect(&application, functor);
2589
2590   // Check that a non-pressed key events data is not modified.
2591   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2592
2593   END_TEST;
2594 }