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