[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2019 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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/integration-api/scene.h>
22 #include <dali/integration-api/events/key-event-integ.h>
23 #include <dali/public-api/events/key-event.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
26
27 #include <dali-test-suite-utils.h>
28 #include <mesh-builder.h>
29
30 // Internal headers are allowed here
31
32 namespace
33 {
34
35 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
36
37 // Functor for EventProcessingFinished signal
38 struct EventProcessingFinishedFunctor
39 {
40   /**
41    * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
42    */
43   EventProcessingFinishedFunctor( bool& eventProcessingFinished )
44   : mEventProcessingFinished( eventProcessingFinished )
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   void Reset()
63   {
64     functorCalled = false;
65
66     receivedKeyEvent.keyModifier = 0;
67     receivedKeyEvent.keyPressedName.clear();
68     receivedKeyEvent.keyPressed.clear();
69   }
70
71   bool functorCalled;
72   KeyEvent receivedKeyEvent;
73 };
74
75 // Functor that sets the data when called
76 struct KeyEventReceivedFunctor
77 {
78   KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
79
80   bool operator()( const KeyEvent& keyEvent )
81   {
82     signalData.functorCalled = true;
83     signalData.receivedKeyEvent = keyEvent;
84
85     return true;
86   }
87
88   KeyEventSignalData& signalData;
89 };
90
91 // Stores data that is populated in the touched signal callback and will be read by the TET cases
92 struct TouchedSignalData
93 {
94   TouchedSignalData()
95   : functorCalled(false),
96     createNewScene(false),
97     newSceneCreated(false)
98   {}
99
100   void Reset()
101   {
102     functorCalled = false;
103     createNewScene = false;
104     newSceneCreated = false;
105
106     receivedTouchEvent.points.clear();
107     receivedTouchEvent.time = 0;
108
109     receivedTouchData.Reset();
110   }
111
112   bool functorCalled;
113   bool createNewScene;
114   bool newSceneCreated;
115   TouchEvent receivedTouchEvent;
116   TouchData receivedTouchData;
117 };
118
119 // Functor that sets the data when touched signal is received
120 struct TouchedFunctor
121 {
122   TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
123
124   void operator()( const TouchEvent& touch )
125   {
126     signalData.functorCalled = true;
127     signalData.receivedTouchEvent = touch;
128   }
129
130   TouchedSignalData& signalData;
131 };
132
133 // Functor that sets the data when touched signal is received
134 struct TouchFunctor
135 {
136   TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
137
138   void operator()( const TouchData& touch )
139   {
140     signalData.functorCalled = true;
141     signalData.receivedTouchData = touch;
142
143     if ( signalData.createNewScene )
144     {
145       TestRenderSurface* surface = new TestRenderSurface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); // This is a leak, but we need to keep the surface alive till the end
146       Dali::Integration::Scene scene = Dali::Integration::Scene::New( *surface );
147       DALI_TEST_CHECK( scene );
148
149       signalData.newSceneCreated = true;
150     }
151   }
152
153   void operator()()
154   {
155     signalData.functorCalled = true;
156   }
157
158   TouchedSignalData& signalData;
159 };
160
161 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
162 struct WheelEventSignalData
163 {
164   WheelEventSignalData()
165   : functorCalled(false)
166   {}
167
168   void Reset()
169   {
170     functorCalled = false;
171   }
172
173   bool functorCalled;
174   WheelEvent receivedWheelEvent;
175 };
176
177 // Functor that sets the data when wheel-event signal is received
178 struct WheelEventReceivedFunctor
179 {
180   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
181
182   bool operator()( const WheelEvent& wheelEvent )
183   {
184     signalData.functorCalled = true;
185     signalData.receivedWheelEvent = wheelEvent;
186
187     return true;
188   }
189
190   WheelEventSignalData& signalData;
191 };
192
193 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
194 {
195   Integration::TouchEvent touchEvent;
196   Integration::Point point;
197   point.SetState( state );
198   point.SetScreenPosition( screenPosition );
199   touchEvent.points.push_back( point );
200   application.ProcessEvent( touchEvent );
201 }
202
203 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
204 {
205   return true;
206 }
207
208 } // unnamed namespace
209
210 int UtcDaliSceneAdd(void)
211 {
212   TestApplication application;
213   tet_infoline("Testing Dali::Integration::Scene::Add");
214
215   Dali::Integration::Scene scene = application.GetScene();
216
217   Actor actor = Actor::New();
218   DALI_TEST_CHECK( !actor.OnStage() );
219
220   scene.Add( actor );
221   DALI_TEST_CHECK( actor.OnStage() );
222
223   END_TEST;
224 }
225
226 int UtcDaliSceneRemove(void)
227 {
228   TestApplication application;
229   tet_infoline("Testing Dali::Integration::Scene::Remove");
230
231   Dali::Integration::Scene scene = application.GetScene();
232
233   Actor actor = Actor::New();
234   DALI_TEST_CHECK( !actor.OnStage() );
235
236   scene.Add( actor );
237   DALI_TEST_CHECK( actor.OnStage() );
238
239   scene.Remove(actor);
240   DALI_TEST_CHECK( !actor.OnStage() );
241
242   END_TEST;
243 }
244
245 int UtcDaliSceneGetSize(void)
246 {
247   TestApplication application;
248   tet_infoline("Testing Dali::Integration::Scene::GetSize");
249
250   Dali::Integration::Scene scene = application.GetScene();
251   Size size = scene.GetSize();
252   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
253   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
254
255   END_TEST;
256 }
257
258 int UtcDaliSceneGetDpi(void)
259 {
260   TestApplication application; // Initializes core DPI to default values
261
262   // Test that setting core DPI explicitly also sets up the scene's DPI.
263   Dali::Integration::Scene scene = application.GetScene();
264   scene.SetDpi( Vector2(200.0f, 180.0f) );
265   Vector2 dpi = scene.GetDpi();
266   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
267   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
268   END_TEST;
269 }
270
271 int UtcDaliSceneGetRenderTaskList(void)
272 {
273   TestApplication application;
274   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
275
276   Dali::Integration::Scene scene = application.GetScene();
277
278   // Check we get a valid instance.
279   const RenderTaskList& tasks = scene.GetRenderTaskList();
280
281   // There should be 1 task by default.
282   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
283
284   // RenderTaskList has it's own UTC tests.
285   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
286   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
287
288   DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
289
290   END_TEST;
291 }
292
293 int UtcDaliSceneGetRootLayer(void)
294 {
295   TestApplication application;
296   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
297
298   Dali::Integration::Scene scene = application.GetScene();
299   Layer layer = scene.GetLayer( 0 );
300   DALI_TEST_CHECK( layer );
301
302   // Check that GetRootLayer() correctly retreived layer 0.
303   DALI_TEST_CHECK( scene.GetRootLayer() == layer );
304
305   END_TEST;
306 }
307
308 int UtcDaliSceneGetLayerCount(void)
309 {
310   TestApplication application;
311   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
312
313   Dali::Integration::Scene scene = application.GetScene();
314   // Initially we have a default layer
315   DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
316
317   Layer layer = Layer::New();
318   scene.Add( layer );
319
320   DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
321   END_TEST;
322 }
323
324 int UtcDaliSceneGetLayer(void)
325 {
326   TestApplication application;
327   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
328
329   Dali::Integration::Scene scene = application.GetScene();
330
331   Layer rootLayer = scene.GetLayer( 0 );
332   DALI_TEST_CHECK( rootLayer );
333
334   Layer layer = Layer::New();
335   scene.Add( layer );
336
337   Layer sameLayer = scene.GetLayer( 1 );
338   DALI_TEST_CHECK( layer == sameLayer );
339
340   END_TEST;
341 }
342
343 int UtcDaliSceneGet(void)
344 {
345   TestApplication application;
346   tet_infoline("Testing Dali::Integration::Scene::Get");
347
348   Dali::Integration::Scene scene = application.GetScene();
349
350   Actor actor = Actor::New();
351   DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
352
353   scene.Add( actor );
354
355   DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
356
357   END_TEST;
358 }
359
360 int UtcDaliSceneDiscard(void)
361 {
362   TestApplication application;
363   tet_infoline("Testing Dali::Scene::Discard");
364
365   // Create a new Scene
366   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
367   Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
368   DALI_TEST_CHECK( scene );
369
370   // One reference of scene kept here and the other one kept in the Core
371   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
372
373   // Render and notify.
374   application.SendNotification();
375   application.Render(0);
376
377   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
378   Layer rootLayer = scene.GetRootLayer();
379   DALI_TEST_CHECK( rootLayer );
380   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
381
382   // Request to discard the scene from the Core
383   scene.Discard();
384   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
385
386   // Reset the scene handle
387   scene.Reset();
388
389   // Render and notify.
390   application.SendNotification();
391   application.Render(0);
392
393   // At this point, the scene should have been automatically deleted
394   // To prove this, the ref count of the root layer handle should be decremented to 1
395   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
396
397   // Delete the root layer handle
398   rootLayer.Reset();
399
400   // Render and notify.
401   application.SendNotification();
402   application.Render(0);
403
404   END_TEST;
405 }
406
407 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
408 {
409   TestApplication application;
410
411   Dali::Integration::Scene scene = application.GetScene();
412
413   TouchedSignalData data;
414   data.createNewScene = true;
415   TouchFunctor functor( data );
416   scene.TouchSignal().Connect( &application, functor );
417
418   // Render and notify.
419   application.SendNotification();
420   application.Render();
421
422   GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
423
424   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
425   DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
426   DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
427   data.Reset();
428
429   END_TEST;
430 }
431
432 int UtcDaliSceneRootLayerAndSceneAlignment(void)
433 {
434   TestApplication application;
435
436   // Create a Scene
437   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
438   Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
439   DALI_TEST_CHECK( scene );
440
441   // One reference of scene kept here and the other one kept in the Core
442   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
443
444   // Add a renderable actor to the scene
445   auto actor = CreateRenderableActor();
446   scene.Add( actor );
447
448   // Render and notify.
449   application.SendNotification();
450   application.Render(0);
451
452   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
453   Layer rootLayer = scene.GetRootLayer();
454   DALI_TEST_CHECK( rootLayer );
455   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
456
457   // Request to discard the scene from the Core
458   scene.Discard();
459   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
460
461   // Reset the scene handle
462   scene.Reset();
463
464   // Render and notify.
465   application.SendNotification();
466   application.Render(0);
467
468   // At this point, the scene should have been automatically deleted
469   // To prove this, the ref count of the root layer handle should be decremented to 1
470   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
471
472   // Create a new Scene while the root layer of the deleted scene is still alive
473   TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
474   Dali::Integration::Scene newScene = Dali::Integration::Scene::New( surface2 );
475   DALI_TEST_CHECK( newScene );
476
477   // Render and notify.
478   application.SendNotification();
479   application.Render(0);
480
481   // At this point, we have only one scene but two root layers
482   // The root layer of the deleted scene is still alive
483   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
484
485   // Delete the root layer of the deleted scene
486   rootLayer.Reset();
487
488   // Render and notify.
489   application.SendNotification();
490   application.Render(0);
491
492   END_TEST;
493 }
494
495 int UtcDaliSceneDeleteSurface(void)
496 {
497   TestApplication application;
498
499   // Create the render surface for the scene
500   TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
501
502   // Create a Scene
503   Dali::Integration::Scene scene = Dali::Integration::Scene::New( *renderSurface );
504   DALI_TEST_CHECK( scene );
505
506   // Render and notify.
507   application.SendNotification();
508   application.Render(0);
509
510   // Add a renderable actor to the scene
511   auto actor = CreateRenderableActor();
512   scene.Add( actor );
513
514   // Render and notify.
515   application.SendNotification();
516   application.Render(0);
517
518   // Notify the Core that the render surface will be deleted.
519   application.GetCore().SurfaceDeleted( renderSurface );
520
521   // Delete the render surface
522   delete renderSurface;
523   renderSurface = nullptr;
524
525   // Render and notify.
526   application.SendNotification();
527   application.Render(0);
528
529   END_TEST;
530 }
531
532 int UtcDaliSceneEventProcessingFinishedP(void)
533 {
534   TestApplication application;
535   Dali::Integration::Scene scene = application.GetScene();
536
537   bool eventProcessingFinished = false;
538   EventProcessingFinishedFunctor functor( eventProcessingFinished );
539   scene.EventProcessingFinishedSignal().Connect( &application, functor );
540
541   Actor actor( Actor::New() );
542   scene.Add( actor );
543
544   application.SendNotification();
545   application.Render();
546
547   DALI_TEST_CHECK( eventProcessingFinished );
548
549   END_TEST;
550 }
551
552 int UtcDaliSceneEventProcessingFinishedN(void)
553 {
554   TestApplication application;
555   Dali::Integration::Scene scene = application.GetScene();
556
557   bool eventProcessingFinished = false;
558   EventProcessingFinishedFunctor functor( eventProcessingFinished );
559   scene.EventProcessingFinishedSignal().Connect( &application, functor );
560
561   Actor actor( Actor::New() );
562   scene.Add( actor );
563
564   // Do not complete event processing and confirm the signal has not been emitted.
565   DALI_TEST_CHECK( !eventProcessingFinished );
566
567   END_TEST;
568 }
569
570 int UtcDaliSceneSignalKeyEventP(void)
571 {
572   TestApplication application;
573   Dali::Integration::Scene scene = application.GetScene();
574
575   KeyEventSignalData data;
576   KeyEventReceivedFunctor functor( data );
577   scene.KeyEventSignal().Connect( &application, functor );
578
579   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580   application.ProcessEvent( event );
581
582   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
584   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
585   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
586   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
587
588   data.Reset();
589
590   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591   application.ProcessEvent( event2 );
592
593   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
595   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
596   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
597   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
598
599   data.Reset();
600
601   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602   application.ProcessEvent( event3 );
603
604   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
606   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
607   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
608   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
609
610   data.Reset();
611
612   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
613   application.ProcessEvent( event4 );
614
615   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
616   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
617   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
618   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
619   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
620   END_TEST;
621 }
622
623 int UtcDaliSceneSignalKeyEventN(void)
624 {
625   TestApplication application;
626   Dali::Integration::Scene scene = application.GetScene();
627
628   KeyEventSignalData data;
629   KeyEventReceivedFunctor functor( data );
630   scene.KeyEventSignal().Connect( &application, functor );
631
632   // Check that a non-pressed key events data is not modified.
633   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
634
635   END_TEST;
636 }
637
638 int UtcDaliSceneTouchSignalP(void)
639 {
640   TestApplication application;
641   Dali::Integration::Scene scene = application.GetScene();
642
643   TouchedSignalData data;
644   TouchFunctor functor( data );
645   scene.TouchSignal().Connect( &application, functor );
646
647   // Render and notify.
648   application.SendNotification();
649   application.Render();
650
651   // Basic test: No actors, single touch (down then up).
652   {
653     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
654
655     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
656     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
657     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
658     data.Reset();
659
660     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
661
662     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
663     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
664     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
665     data.Reset();
666   }
667
668   // Add an actor to the scene.
669   Actor actor = Actor::New();
670   actor.SetSize( 100.0f, 100.0f );
671   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
673   actor.TouchedSignal().Connect( &DummyTouchCallback );
674   scene.Add( actor );
675
676   // Render and notify.
677   application.SendNotification();
678   application.Render();
679
680   // Actor on scene, single touch, down in actor, motion, then up outside actor.
681   {
682     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
683
684     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
686     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
687     data.Reset();
688
689     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
690
691     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
692     data.Reset();
693
694     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
695
696     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
697     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
698     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
699     data.Reset();
700   }
701
702   // Multiple touch. Should only receive a touch on first down and last up.
703   {
704     Integration::TouchEvent touchEvent;
705     Integration::Point point;
706
707     // 1st point
708     point.SetState( PointState::DOWN );
709     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
710     touchEvent.points.push_back( point );
711     application.ProcessEvent( touchEvent );
712     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
714     data.Reset();
715
716     // 2nd point
717     touchEvent.points[0].SetState( PointState::STATIONARY );
718     point.SetDeviceId( 1 );
719     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
720     touchEvent.points.push_back( point );
721     application.ProcessEvent( touchEvent );
722     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
723     data.Reset();
724
725     // Primary point is up
726     touchEvent.points[0].SetState( PointState::UP );
727     touchEvent.points[1].SetState( PointState::STATIONARY );
728     application.ProcessEvent( touchEvent );
729     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730     data.Reset();
731
732     // Remove 1st point now, 2nd point is now in motion
733     touchEvent.points.erase( touchEvent.points.begin() );
734     touchEvent.points[0].SetState( PointState::MOTION );
735     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
736     application.ProcessEvent( touchEvent );
737     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
738     data.Reset();
739
740     // Final point Up
741     touchEvent.points[0].SetState( PointState::UP );
742     application.ProcessEvent( touchEvent );
743     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
744     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
745     data.Reset();
746   }
747   END_TEST;
748 }
749
750 int UtcDaliSceneTouchSignalN(void)
751 {
752   TestApplication application;
753   Dali::Integration::Scene scene = application.GetScene();
754
755   TouchedSignalData data;
756   TouchFunctor functor( data );
757   scene.TouchSignal().Connect( &application, functor );
758
759   // Render and notify.
760   application.SendNotification();
761   application.Render();
762
763   // Confirm functor not called before there has been any touch event.
764   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
765
766   // No actors, single touch, down, motion then up.
767   {
768     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
769
770     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
771     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
772     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
773
774     data.Reset();
775
776     // Confirm there is no signal when the touchpoint is only moved.
777     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
778
779     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
780     data.Reset();
781
782     // Confirm a following up event generates a signal.
783     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
784
785     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
787     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
788     data.Reset();
789   }
790
791   // Add an actor to the scene.
792   Actor actor = Actor::New();
793   actor.SetSize( 100.0f, 100.0f );
794   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
795   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
796   actor.TouchedSignal().Connect( &DummyTouchCallback );
797   scene.Add( actor );
798
799   // Render and notify.
800   application.SendNotification();
801   application.Render();
802
803   // Actor on scene. Interrupted before down and interrupted after down.
804   {
805     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
806
807     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
808     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
809     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
810     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
811     data.Reset();
812
813     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
814
815     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
816     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
817     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
818     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
819     data.Reset();
820
821     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
822
823     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
824     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
825     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
826     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
827
828     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
829
830     // Check that getting info about a non-existent point returns an empty handle
831     Actor actor = data.receivedTouchData.GetHitActor( 1 );
832     DALI_TEST_CHECK( !actor );
833
834     data.Reset();
835   }
836
837   END_TEST;
838 }
839
840 int UtcDaliSceneSignalWheelEventP(void)
841 {
842   TestApplication application;
843   Dali::Integration::Scene scene = application.GetScene();
844
845   WheelEventSignalData data;
846   WheelEventReceivedFunctor functor( data );
847   scene.WheelEventSignal().Connect( &application, functor );
848
849   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
850   application.ProcessEvent( event );
851
852   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
853   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
854   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
855   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
856   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
857   DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
858   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
859
860   data.Reset();
861
862   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
863   application.ProcessEvent( event2 );
864
865   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
866   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
867   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
868   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
869   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
870   DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
871   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
872   END_TEST;
873 }
874
875 int UtcDaliSceneEnsureEmptySceneCleared(void)
876 {
877   tet_infoline( "Ensure we clear the newly added window" );
878
879   TestApplication application;
880
881   // Create a new scene and set the background colors of both the new and the main scenes
882   auto defaultScene = application.GetScene();
883   defaultScene.SetBackgroundColor( Color::WHITE );
884
885   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
886   auto newScene = Integration::Scene::New( surface );
887   newScene.SetBackgroundColor( Color::RED );
888
889   // Need to create a renderable as we don't start rendering until we have at least one
890   // We don't need to add this to any scene
891   auto actor = CreateRenderableActor();
892
893   auto& glAbstraction = application.GetGlAbstraction();
894   auto clearCountBefore = glAbstraction.GetClearCountCalled();
895
896   application.SendNotification();
897   application.Render();
898
899   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
900
901   // Add the actor to the main scene
902   defaultScene.Add( actor );
903
904   application.SendNotification();
905   application.Render();
906
907   // Add another scene and set its background color, ensure we clear it to the appropriate color
908
909   TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
910   auto thirdScene = Integration::Scene::New( surface2 );
911   thirdScene.SetBackgroundColor( Color::BLUE );
912
913   clearCountBefore = glAbstraction.GetClearCountCalled();
914
915   application.SendNotification();
916   application.Render();
917
918   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
919
920   END_TEST;
921 }
922
923 int UtcDaliSceneSurfaceResizedDefaultScene(void)
924 {
925   tet_infoline( "Ensure resizing of the surface is handled properly" );
926
927   TestApplication application;
928
929   auto defaultScene = application.GetScene();
930   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
931   DALI_TEST_CHECK( defaultSurface );
932
933   // Ensure stage size matches the surface size
934   auto stage = Stage::GetCurrent();
935   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
936
937   // Resize the surface and inform the scene accordingly
938   Vector2 newSize( 1000.0f, 2000.0f );
939   DALI_TEST_CHECK( stage.GetSize() != newSize );
940   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
941   defaultScene.SurfaceResized( false );
942
943   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
944   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
945
946   END_TEST;
947 }
948
949 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
950 {
951   tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
952
953   TestApplication application;
954   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
955   TraceCallStack& callStack = glAbstraction.GetViewportTrace();
956   glAbstraction.EnableViewportCallTrace( true );
957
958   // Initial scene setup
959   Geometry geometry = CreateQuadGeometry();
960   Shader shader = CreateShader();
961   Renderer renderer = Renderer::New( geometry, shader );
962
963   Actor actor = Actor::New();
964   actor.AddRenderer(renderer);
965   actor.SetSize(400, 400);
966   Stage::GetCurrent().Add(actor);
967
968   // Render before resizing surface
969   application.SendNotification();
970   application.Render(0);
971   glAbstraction.ResetViewportCallStack();
972
973   auto defaultScene = application.GetScene();
974   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
975   DALI_TEST_CHECK( defaultSurface );
976
977   // Ensure stage size matches the surface size
978   auto stage = Stage::GetCurrent();
979   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
980
981   // Resize the surface and inform the scene accordingly
982   Vector2 newSize( 1000.0f, 2000.0f );
983   std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
984   DALI_TEST_CHECK( stage.GetSize() != newSize );
985   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
986   defaultScene.SurfaceResized();
987
988   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
989   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
990
991   // Render after resizing surface
992   application.SendNotification();
993   application.Render(0);
994
995   // Check that the viewport is handled properly
996   DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
997
998   END_TEST;
999 }
1000
1001 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
1002 {
1003   tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
1004
1005   TestApplication application;
1006   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1007   TraceCallStack& callStack = glAbstraction.GetViewportTrace();
1008   glAbstraction.EnableViewportCallTrace( true );
1009
1010   // Initial scene setup
1011   auto stage = Stage::GetCurrent();
1012
1013   Geometry geometry = CreateQuadGeometry();
1014   Shader shader = CreateShader();
1015   Renderer renderer = Renderer::New( geometry, shader );
1016
1017   Actor actor = Actor::New();
1018   actor.AddRenderer(renderer);
1019   int testWidth = 400;
1020   int testHeight = 400;
1021   actor.SetSize(testWidth, testHeight);
1022   stage.Add(actor);
1023
1024   CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
1025   Stage::GetCurrent().Add( offscreenCameraActor );
1026
1027   FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
1028
1029   RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1030   newTask.SetCameraActor( offscreenCameraActor );
1031   newTask.SetSourceActor( actor );
1032   newTask.SetFrameBuffer( newFrameBuffer );
1033   newTask.SetViewportPosition( Vector2(0, 0) );
1034   newTask.SetViewportSize( Vector2(testWidth, testHeight) );
1035
1036   // Render before resizing surface
1037   application.SendNotification();
1038   application.Render(0);
1039   glAbstraction.ResetViewportCallStack();
1040
1041   Rect<int32_t> initialViewport = newTask.GetViewport();
1042   int initialWidth = initialViewport.width;
1043   int initialHeight = initialViewport.height;
1044   DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
1045   DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
1046
1047   auto defaultScene = application.GetScene();
1048   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
1049   DALI_TEST_CHECK( defaultSurface );
1050
1051   // Ensure stage size matches the surface size
1052   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
1053
1054   // Resize the surface and inform the scene accordingly
1055   Vector2 newSize( 800.0f, 480.0f );
1056   std::string viewportParams( "0, 0, 800, 480" ); // to match newSize
1057   DALI_TEST_CHECK( stage.GetSize() != newSize );
1058   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1059   defaultScene.SurfaceResized();
1060
1061   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1062   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1063
1064   // Render after resizing surface
1065   application.SendNotification();
1066   application.Render(0);
1067
1068   // Check that the viewport is handled properly
1069   DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1070
1071   // Second render-task should not be affected
1072   Rect<int32_t> viewport = newTask.GetViewport();
1073   int width = viewport.width;
1074   int height = viewport.height;
1075   DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1076   DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1077
1078   END_TEST;
1079 }
1080
1081 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1082 {
1083   tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1084
1085   TestApplication application;
1086   Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1087
1088   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
1089 <<<<<<< HEAD
1090   auto scene = Integration::Scene::New( surface );
1091 =======
1092   scene.SetSurface( surface, false );
1093 >>>>>>> e6df4fb... Support Client and Screen Rotation
1094
1095   // Ensure stage size does NOT match the surface size
1096   auto stage = Stage::GetCurrent();
1097   const auto stageSize = stage.GetSize();
1098   DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1099   DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1100
1101   // Resize the surface and inform the scene accordingly
1102   Vector2 newSize( 1000.0f, 2000.0f );
1103   DALI_TEST_CHECK( stage.GetSize() != newSize );
1104   surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
1105   scene.SurfaceResized( false );
1106
1107   // Ensure the stage hasn't been resized
1108   DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1109   DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1110
1111   END_TEST;
1112 }
1113
1114 int UtcDaliSceneSetSurface(void)
1115 {
1116   tet_infoline( "Scene::SetSurface test" );
1117
1118   TestApplication application;
1119
1120   // Create a scene with a surface and ensure the size and surface is set correctly on the scene
1121   Vector2 surfaceSize( 480.0f, 800.0f );
1122   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, surfaceSize.width, surfaceSize.height ) );
1123   auto scene = Integration::Scene::New( surface );
1124   DALI_TEST_EQUALS( scene.GetSize(), surfaceSize, TEST_LOCATION );
1125   DALI_TEST_CHECK( scene.GetSurface() == &surface );
1126
1127   // Create a new surface and set that on the scene
1128   Vector2 newSurfaceSize( 1000.0f, 1000.0f );
1129   TestRenderSurface newSurface( PositionSize( 0.0f, 0.0f, newSurfaceSize.width, newSurfaceSize.height ) );
1130   scene.SetSurface( newSurface );
1131   DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1132   DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
1133
1134   // Ensure setting the same surface again doesn't have any side effects
1135   scene.SetSurface( newSurface );
1136   DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1137   DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
1138
1139   END_TEST;
1140 }