Remove Core::SurfaceResized() method as we can call the required Scene method directly
[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
29 // Internal headers are allowed here
30
31 namespace
32 {
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   void operator()()
47   {
48     mEventProcessingFinished = true;
49   }
50
51   bool& mEventProcessingFinished;
52 };
53
54 // Stores data that is populated in the key-event callback and will be read by the TET cases
55 struct KeyEventSignalData
56 {
57   KeyEventSignalData()
58   : functorCalled(false)
59   {}
60
61   void Reset()
62   {
63     functorCalled = false;
64
65     receivedKeyEvent.keyModifier = 0;
66     receivedKeyEvent.keyPressedName.clear();
67     receivedKeyEvent.keyPressed.clear();
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 ) : signalData( data ) { }
78
79   bool operator()( const KeyEvent& keyEvent )
80   {
81     signalData.functorCalled = true;
82     signalData.receivedKeyEvent = keyEvent;
83
84     return true;
85   }
86
87   KeyEventSignalData& signalData;
88 };
89
90 // Stores data that is populated in the touched signal callback and will be read by the TET cases
91 struct TouchedSignalData
92 {
93   TouchedSignalData()
94   : functorCalled(false),
95     createNewScene(false),
96     newSceneCreated(false)
97   {}
98
99   void Reset()
100   {
101     functorCalled = false;
102     createNewScene = false;
103     newSceneCreated = false;
104
105     receivedTouchEvent.points.clear();
106     receivedTouchEvent.time = 0;
107
108     receivedTouchData.Reset();
109   }
110
111   bool functorCalled;
112   bool createNewScene;
113   bool newSceneCreated;
114   TouchEvent receivedTouchEvent;
115   TouchData receivedTouchData;
116 };
117
118 // Functor that sets the data when touched signal is received
119 struct TouchedFunctor
120 {
121   TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
122
123   void operator()( const TouchEvent& touch )
124   {
125     signalData.functorCalled = true;
126     signalData.receivedTouchEvent = touch;
127   }
128
129   TouchedSignalData& signalData;
130 };
131
132 // Functor that sets the data when touched signal is received
133 struct TouchFunctor
134 {
135   TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
136
137   void operator()( const TouchData& touch )
138   {
139     signalData.functorCalled = true;
140     signalData.receivedTouchData = touch;
141
142     if ( signalData.createNewScene )
143     {
144       Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
145       DALI_TEST_CHECK( scene );
146
147       signalData.newSceneCreated = true;
148     }
149   }
150
151   void operator()()
152   {
153     signalData.functorCalled = true;
154   }
155
156   TouchedSignalData& signalData;
157 };
158
159 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
160 struct WheelEventSignalData
161 {
162   WheelEventSignalData()
163   : functorCalled(false)
164   {}
165
166   void Reset()
167   {
168     functorCalled = false;
169   }
170
171   bool functorCalled;
172   WheelEvent receivedWheelEvent;
173 };
174
175 // Functor that sets the data when wheel-event signal is received
176 struct WheelEventReceivedFunctor
177 {
178   WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
179
180   bool operator()( const WheelEvent& wheelEvent )
181   {
182     signalData.functorCalled = true;
183     signalData.receivedWheelEvent = wheelEvent;
184
185     return true;
186   }
187
188   WheelEventSignalData& signalData;
189 };
190
191 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
192 {
193   Integration::TouchEvent touchEvent;
194   Integration::Point point;
195   point.SetState( state );
196   point.SetScreenPosition( screenPosition );
197   touchEvent.points.push_back( point );
198   application.ProcessEvent( touchEvent );
199 }
200
201 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
202 {
203   return true;
204 }
205
206 } // unnamed namespace
207
208 int UtcDaliSceneAdd(void)
209 {
210   TestApplication application;
211   tet_infoline("Testing Dali::Integration::Scene::Add");
212
213   Dali::Integration::Scene scene = application.GetScene();
214
215   Actor actor = Actor::New();
216   DALI_TEST_CHECK( !actor.OnStage() );
217
218   scene.Add( actor );
219   DALI_TEST_CHECK( actor.OnStage() );
220
221   END_TEST;
222 }
223
224 int UtcDaliSceneRemove(void)
225 {
226   TestApplication application;
227   tet_infoline("Testing Dali::Integration::Scene::Remove");
228
229   Dali::Integration::Scene scene = application.GetScene();
230
231   Actor actor = Actor::New();
232   DALI_TEST_CHECK( !actor.OnStage() );
233
234   scene.Add( actor );
235   DALI_TEST_CHECK( actor.OnStage() );
236
237   scene.Remove(actor);
238   DALI_TEST_CHECK( !actor.OnStage() );
239
240   END_TEST;
241 }
242
243 int UtcDaliSceneGetSize(void)
244 {
245   TestApplication application;
246   tet_infoline("Testing Dali::Integration::Scene::GetSize");
247
248   Dali::Integration::Scene scene = application.GetScene();
249   Size size = scene.GetSize();
250   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
251   DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
252
253   END_TEST;
254 }
255
256 int UtcDaliSceneGetDpi(void)
257 {
258   TestApplication application; // Initializes core DPI to default values
259
260   // Test that setting core DPI explicitly also sets up the scene's DPI.
261   Dali::Integration::Scene scene = application.GetScene();
262   scene.SetDpi( Vector2(200.0f, 180.0f) );
263   Vector2 dpi = scene.GetDpi();
264   DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
265   DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
266   END_TEST;
267 }
268
269 int UtcDaliSceneGetRenderTaskList(void)
270 {
271   TestApplication application;
272   tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
273
274   Dali::Integration::Scene scene = application.GetScene();
275
276   // Check we get a valid instance.
277   const RenderTaskList& tasks = scene.GetRenderTaskList();
278
279   // There should be 1 task by default.
280   DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
281
282   // RenderTaskList has it's own UTC tests.
283   // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
284   RenderTask newTask = scene.GetRenderTaskList().CreateTask();
285
286   DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
287
288   END_TEST;
289 }
290
291 int UtcDaliSceneGetRootLayer(void)
292 {
293   TestApplication application;
294   tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
295
296   Dali::Integration::Scene scene = application.GetScene();
297   Layer layer = scene.GetLayer( 0 );
298   DALI_TEST_CHECK( layer );
299
300   // Check that GetRootLayer() correctly retreived layer 0.
301   DALI_TEST_CHECK( scene.GetRootLayer() == layer );
302
303   END_TEST;
304 }
305
306 int UtcDaliSceneGetLayerCount(void)
307 {
308   TestApplication application;
309   tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
310
311   Dali::Integration::Scene scene = application.GetScene();
312   // Initially we have a default layer
313   DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
314
315   Layer layer = Layer::New();
316   scene.Add( layer );
317
318   DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
319   END_TEST;
320 }
321
322 int UtcDaliSceneGetLayer(void)
323 {
324   TestApplication application;
325   tet_infoline("Testing Dali::Integration::Scene::GetLayer");
326
327   Dali::Integration::Scene scene = application.GetScene();
328
329   Layer rootLayer = scene.GetLayer( 0 );
330   DALI_TEST_CHECK( rootLayer );
331
332   Layer layer = Layer::New();
333   scene.Add( layer );
334
335   Layer sameLayer = scene.GetLayer( 1 );
336   DALI_TEST_CHECK( layer == sameLayer );
337
338   END_TEST;
339 }
340
341 int UtcDaliSceneGet(void)
342 {
343   TestApplication application;
344   tet_infoline("Testing Dali::Integration::Scene::Get");
345
346   Dali::Integration::Scene scene = application.GetScene();
347
348   Actor actor = Actor::New();
349   DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
350
351   scene.Add( actor );
352
353   DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
354
355   END_TEST;
356 }
357
358 int UtcDaliSceneDiscard(void)
359 {
360   TestApplication application;
361   tet_infoline("Testing Dali::Scene::Discard");
362
363   // Create a new Scene
364   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
365   DALI_TEST_CHECK( scene );
366
367   // One reference of scene kept here and the other one kept in the Core
368   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
369
370   // Render and notify.
371   application.SendNotification();
372   application.Render(0);
373
374   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
375   Layer rootLayer = scene.GetRootLayer();
376   DALI_TEST_CHECK( rootLayer );
377   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
378
379   // Request to discard the scene from the Core
380   scene.Discard();
381   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
382
383   // Reset the scene handle
384   scene.Reset();
385
386   // Render and notify.
387   application.SendNotification();
388   application.Render(0);
389
390   // At this point, the scene should have been automatically deleted
391   // To prove this, the ref count of the root layer handle should be decremented to 1
392   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
393
394   // Delete the root layer handle
395   rootLayer.Reset();
396
397   // Render and notify.
398   application.SendNotification();
399   application.Render(0);
400
401   END_TEST;
402 }
403
404 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
405 {
406   TestApplication application;
407
408   Dali::Integration::Scene scene = application.GetScene();
409
410   TouchedSignalData data;
411   data.createNewScene = true;
412   TouchFunctor functor( data );
413   scene.TouchSignal().Connect( &application, functor );
414
415   // Render and notify.
416   application.SendNotification();
417   application.Render();
418
419   GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
420
421   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
422   DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
423   DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
424   data.Reset();
425
426   END_TEST;
427 }
428
429 int UtcDaliSceneRootLayerAndSceneAlignment(void)
430 {
431   TestApplication application;
432
433   // Create a Scene
434   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
435   DALI_TEST_CHECK( scene );
436
437   // One reference of scene kept here and the other one kept in the Core
438   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
439
440   // Render and notify.
441   application.SendNotification();
442   application.Render(0);
443
444   // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
445   Layer rootLayer = scene.GetRootLayer();
446   DALI_TEST_CHECK( rootLayer );
447   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
448
449   // Request to discard the scene from the Core
450   scene.Discard();
451   DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
452
453   // Reset the scene handle
454   scene.Reset();
455
456   // Render and notify.
457   application.SendNotification();
458   application.Render(0);
459
460   // At this point, the scene should have been automatically deleted
461   // To prove this, the ref count of the root layer handle should be decremented to 1
462   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
463
464   // Create a new Scene while the root layer of the deleted scene is still alive
465   Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
466   DALI_TEST_CHECK( newScene );
467
468   // Render and notify.
469   application.SendNotification();
470   application.Render(0);
471
472   // At this point, we have only one scene but two root layers
473   // The root layer of the deleted scene is still alive
474   DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
475
476   // Delete the root layer of the deleted scene
477   rootLayer.Reset();
478
479   // Render and notify.
480   application.SendNotification();
481   application.Render(0);
482
483   END_TEST;
484 }
485
486 int UtcDaliSceneDeleteSurface(void)
487 {
488   TestApplication application;
489
490   // Create a Scene
491   Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
492   DALI_TEST_CHECK( scene );
493
494   // Create the render surface for the scene
495   TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
496   scene.SetSurface( *renderSurface );
497
498   // Render and notify.
499   application.SendNotification();
500   application.Render(0);
501
502   // Add a renderable actor to the scene
503   auto actor = CreateRenderableActor();
504   scene.Add( actor );
505
506   // Render and notify.
507   application.SendNotification();
508   application.Render(0);
509
510   // Notify the Core that the render surface will be deleted.
511   application.GetCore().SurfaceDeleted( renderSurface );
512
513   // Delete the render surface
514   delete renderSurface;
515   renderSurface = nullptr;
516
517   // Render and notify.
518   application.SendNotification();
519   application.Render(0);
520
521   END_TEST;
522 }
523
524 int UtcDaliSceneEventProcessingFinishedP(void)
525 {
526   TestApplication application;
527   Dali::Integration::Scene scene = application.GetScene();
528
529   bool eventProcessingFinished = false;
530   EventProcessingFinishedFunctor functor( eventProcessingFinished );
531   scene.EventProcessingFinishedSignal().Connect( &application, functor );
532
533   Actor actor( Actor::New() );
534   scene.Add( actor );
535
536   application.SendNotification();
537   application.Render();
538
539   DALI_TEST_CHECK( eventProcessingFinished );
540
541   END_TEST;
542 }
543
544 int UtcDaliSceneEventProcessingFinishedN(void)
545 {
546   TestApplication application;
547   Dali::Integration::Scene scene = application.GetScene();
548
549   bool eventProcessingFinished = false;
550   EventProcessingFinishedFunctor functor( eventProcessingFinished );
551   scene.EventProcessingFinishedSignal().Connect( &application, functor );
552
553   Actor actor( Actor::New() );
554   scene.Add( actor );
555
556   // Do not complete event processing and confirm the signal has not been emitted.
557   DALI_TEST_CHECK( !eventProcessingFinished );
558
559   END_TEST;
560 }
561
562 int UtcDaliSceneSignalKeyEventP(void)
563 {
564   TestApplication application;
565   Dali::Integration::Scene scene = application.GetScene();
566
567   KeyEventSignalData data;
568   KeyEventReceivedFunctor functor( data );
569   scene.KeyEventSignal().Connect( &application, functor );
570
571   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
572   application.ProcessEvent( event );
573
574   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
575   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
576   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
577   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
578   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
579
580   data.Reset();
581
582   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
583   application.ProcessEvent( event2 );
584
585   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
586   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
587   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
588   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
589   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
590
591   data.Reset();
592
593   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
594   application.ProcessEvent( event3 );
595
596   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
597   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
598   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
599   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
600   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
601
602   data.Reset();
603
604   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
605   application.ProcessEvent( event4 );
606
607   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
608   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
609   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
610   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
611   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
612   END_TEST;
613 }
614
615 int UtcDaliSceneSignalKeyEventN(void)
616 {
617   TestApplication application;
618   Dali::Integration::Scene scene = application.GetScene();
619
620   KeyEventSignalData data;
621   KeyEventReceivedFunctor functor( data );
622   scene.KeyEventSignal().Connect( &application, functor );
623
624   // Check that a non-pressed key events data is not modified.
625   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
626
627   END_TEST;
628 }
629
630 int UtcDaliSceneTouchSignalP(void)
631 {
632   TestApplication application;
633   Dali::Integration::Scene scene = application.GetScene();
634
635   TouchedSignalData data;
636   TouchFunctor functor( data );
637   scene.TouchSignal().Connect( &application, functor );
638
639   // Render and notify.
640   application.SendNotification();
641   application.Render();
642
643   // Basic test: No actors, single touch (down then up).
644   {
645     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
646
647     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
648     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
649     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
650     data.Reset();
651
652     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
653
654     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
655     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
656     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
657     data.Reset();
658   }
659
660   // Add an actor to the scene.
661   Actor actor = Actor::New();
662   actor.SetSize( 100.0f, 100.0f );
663   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
664   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
665   actor.TouchedSignal().Connect( &DummyTouchCallback );
666   scene.Add( actor );
667
668   // Render and notify.
669   application.SendNotification();
670   application.Render();
671
672   // Actor on scene, single touch, down in actor, motion, then up outside actor.
673   {
674     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
675
676     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
677     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
678     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
679     data.Reset();
680
681     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
682
683     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
684     data.Reset();
685
686     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
687
688     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
689     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
690     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
691     data.Reset();
692   }
693
694   // Multiple touch. Should only receive a touch on first down and last up.
695   {
696     Integration::TouchEvent touchEvent;
697     Integration::Point point;
698
699     // 1st point
700     point.SetState( PointState::DOWN );
701     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
702     touchEvent.points.push_back( point );
703     application.ProcessEvent( touchEvent );
704     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
705     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
706     data.Reset();
707
708     // 2nd point
709     touchEvent.points[0].SetState( PointState::STATIONARY );
710     point.SetDeviceId( 1 );
711     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
712     touchEvent.points.push_back( point );
713     application.ProcessEvent( touchEvent );
714     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
715     data.Reset();
716
717     // Primary point is up
718     touchEvent.points[0].SetState( PointState::UP );
719     touchEvent.points[1].SetState( PointState::STATIONARY );
720     application.ProcessEvent( touchEvent );
721     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
722     data.Reset();
723
724     // Remove 1st point now, 2nd point is now in motion
725     touchEvent.points.erase( touchEvent.points.begin() );
726     touchEvent.points[0].SetState( PointState::MOTION );
727     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
728     application.ProcessEvent( touchEvent );
729     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730     data.Reset();
731
732     // Final point Up
733     touchEvent.points[0].SetState( PointState::UP );
734     application.ProcessEvent( touchEvent );
735     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
736     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
737     data.Reset();
738   }
739   END_TEST;
740 }
741
742 int UtcDaliSceneTouchSignalN(void)
743 {
744   TestApplication application;
745   Dali::Integration::Scene scene = application.GetScene();
746
747   TouchedSignalData data;
748   TouchFunctor functor( data );
749   scene.TouchSignal().Connect( &application, functor );
750
751   // Render and notify.
752   application.SendNotification();
753   application.Render();
754
755   // Confirm functor not called before there has been any touch event.
756   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
757
758   // No actors, single touch, down, motion then up.
759   {
760     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
761
762     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
763     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
764     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
765
766     data.Reset();
767
768     // Confirm there is no signal when the touchpoint is only moved.
769     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
770
771     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
772     data.Reset();
773
774     // Confirm a following up event generates a signal.
775     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
776
777     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
778     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
779     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
780     data.Reset();
781   }
782
783   // Add an actor to the scene.
784   Actor actor = Actor::New();
785   actor.SetSize( 100.0f, 100.0f );
786   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
787   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
788   actor.TouchedSignal().Connect( &DummyTouchCallback );
789   scene.Add( actor );
790
791   // Render and notify.
792   application.SendNotification();
793   application.Render();
794
795   // Actor on scene. Interrupted before down and interrupted after down.
796   {
797     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
798
799     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
800     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
801     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
802     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
803     data.Reset();
804
805     GenerateTouch( application, PointState::DOWN, 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) == actor );
810     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
811     data.Reset();
812
813     GenerateTouch( application, PointState::INTERRUPTED, 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) );
818     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
819
820     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
821
822     // Check that getting info about a non-existent point returns an empty handle
823     Actor actor = data.receivedTouchData.GetHitActor( 1 );
824     DALI_TEST_CHECK( !actor );
825
826     data.Reset();
827   }
828
829   END_TEST;
830 }
831
832 int UtcDaliSceneSignalWheelEventP(void)
833 {
834   TestApplication application;
835   Dali::Integration::Scene scene = application.GetScene();
836
837   WheelEventSignalData data;
838   WheelEventReceivedFunctor functor( data );
839   scene.WheelEventSignal().Connect( &application, functor );
840
841   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
842   application.ProcessEvent( event );
843
844   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
845   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
846   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
847   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
848   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
849   DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
850   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
851
852   data.Reset();
853
854   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
855   application.ProcessEvent( event2 );
856
857   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
858   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
859   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
860   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
861   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
862   DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
863   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
864   END_TEST;
865 }
866
867 int UtcDaliSceneEnsureEmptySceneCleared(void)
868 {
869   tet_infoline( "Ensure we clear the newly added window" );
870
871   TestApplication application;
872
873   // Create a new scene and set the background colors of both the new and the main scenes
874   auto defaultScene = application.GetScene();
875   defaultScene.SetBackgroundColor( Color::WHITE );
876
877   auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
878   newScene.SetBackgroundColor( Color::RED );
879
880   // Need to create a renderable as we don't start rendering until we have at least one
881   // We don't need to add this to any scene
882   auto actor = CreateRenderableActor();
883
884   auto& glAbstraction = application.GetGlAbstraction();
885   auto clearCountBefore = glAbstraction.GetClearCountCalled();
886
887   application.SendNotification();
888   application.Render();
889
890   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
891
892   // Add the actor to the main scene
893   defaultScene.Add( actor );
894
895   application.SendNotification();
896   application.Render();
897
898   // Add another scene and set its background color, ensure we clear it to the appropriate color
899
900   auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) );
901   thirdScene.SetBackgroundColor( Color::BLUE );
902
903   clearCountBefore = glAbstraction.GetClearCountCalled();
904
905   application.SendNotification();
906   application.Render();
907
908   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
909
910   END_TEST;
911 }
912
913 int UtcDaliSceneSurfaceResizedDefaultScene(void)
914 {
915   tet_infoline( "Ensure resizing of the surface is handled properly" );
916
917   TestApplication application;
918
919   auto defaultScene = application.GetScene();
920   Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
921   DALI_TEST_CHECK( defaultSurface );
922
923   // Ensure stage size matches the surface size
924   auto stage = Stage::GetCurrent();
925   DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
926
927   // Resize the surface and inform the scene accordingly
928   Vector2 newSize( 1000.0f, 2000.0f );
929   DALI_TEST_CHECK( stage.GetSize() != newSize );
930   defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
931   defaultScene.SurfaceResized();
932
933   DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
934   DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
935
936   END_TEST;
937 }
938
939 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
940 {
941   tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
942
943   TestApplication application;
944   Vector2 originalSurfaceSize( 500.0f, 1000.0f );
945
946   auto scene = Integration::Scene::New( Vector2::ZERO );
947   TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
948   scene.SetSurface( surface );
949
950   // Ensure stage size does NOT match the surface size
951   auto stage = Stage::GetCurrent();
952   const auto stageSize = stage.GetSize();
953   DALI_TEST_CHECK( stageSize != originalSurfaceSize );
954   DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
955
956   // Resize the surface and inform the scene accordingly
957   Vector2 newSize( 1000.0f, 2000.0f );
958   DALI_TEST_CHECK( stage.GetSize() != newSize );
959   surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
960   scene.SurfaceResized();
961
962   // Ensure the stage hasn't been resized
963   DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
964   DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
965
966   END_TEST;
967 }