45eee5c0832349cf95672941cd0a95fd8c4a6514
[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 UtcDaliSceneEventProcessingFinishedP(void)
487 {
488   TestApplication application;
489   Dali::Integration::Scene scene = application.GetScene();
490
491   bool eventProcessingFinished = false;
492   EventProcessingFinishedFunctor functor( eventProcessingFinished );
493   scene.EventProcessingFinishedSignal().Connect( &application, functor );
494
495   Actor actor( Actor::New() );
496   scene.Add( actor );
497
498   application.SendNotification();
499   application.Render();
500
501   DALI_TEST_CHECK( eventProcessingFinished );
502
503   END_TEST;
504 }
505
506 int UtcDaliSceneEventProcessingFinishedN(void)
507 {
508   TestApplication application;
509   Dali::Integration::Scene scene = application.GetScene();
510
511   bool eventProcessingFinished = false;
512   EventProcessingFinishedFunctor functor( eventProcessingFinished );
513   scene.EventProcessingFinishedSignal().Connect( &application, functor );
514
515   Actor actor( Actor::New() );
516   scene.Add( actor );
517
518   // Do not complete event processing and confirm the signal has not been emitted.
519   DALI_TEST_CHECK( !eventProcessingFinished );
520
521   END_TEST;
522 }
523
524 int UtcDaliSceneSignalKeyEventP(void)
525 {
526   TestApplication application;
527   Dali::Integration::Scene scene = application.GetScene();
528
529   KeyEventSignalData data;
530   KeyEventReceivedFunctor functor( data );
531   scene.KeyEventSignal().Connect( &application, functor );
532
533   Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
534   application.ProcessEvent( event );
535
536   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
537   DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
538   DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
539   DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
540   DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
541
542   data.Reset();
543
544   Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
545   application.ProcessEvent( event2 );
546
547   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
548   DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
549   DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
550   DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
551   DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
552
553   data.Reset();
554
555   Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
556   application.ProcessEvent( event3 );
557
558   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
559   DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
560   DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
561   DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
562   DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
563
564   data.Reset();
565
566   Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
567   application.ProcessEvent( event4 );
568
569   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
570   DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
571   DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
572   DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
573   DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
574   END_TEST;
575 }
576
577 int UtcDaliSceneSignalKeyEventN(void)
578 {
579   TestApplication application;
580   Dali::Integration::Scene scene = application.GetScene();
581
582   KeyEventSignalData data;
583   KeyEventReceivedFunctor functor( data );
584   scene.KeyEventSignal().Connect( &application, functor );
585
586   // Check that a non-pressed key events data is not modified.
587   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
588
589   END_TEST;
590 }
591
592 int UtcDaliSceneTouchSignalP(void)
593 {
594   TestApplication application;
595   Dali::Integration::Scene scene = application.GetScene();
596
597   TouchedSignalData data;
598   TouchFunctor functor( data );
599   scene.TouchSignal().Connect( &application, functor );
600
601   // Render and notify.
602   application.SendNotification();
603   application.Render();
604
605   // Basic test: No actors, single touch (down then up).
606   {
607     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
608
609     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
610     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
611     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
612     data.Reset();
613
614     GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
615
616     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
617     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
618     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
619     data.Reset();
620   }
621
622   // Add an actor to the scene.
623   Actor actor = Actor::New();
624   actor.SetSize( 100.0f, 100.0f );
625   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
626   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
627   actor.TouchedSignal().Connect( &DummyTouchCallback );
628   scene.Add( actor );
629
630   // Render and notify.
631   application.SendNotification();
632   application.Render();
633
634   // Actor on scene, single touch, down in actor, motion, then up outside actor.
635   {
636     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
637
638     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
639     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
640     DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
641     data.Reset();
642
643     GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
644
645     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
646     data.Reset();
647
648     GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
649
650     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
651     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
652     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
653     data.Reset();
654   }
655
656   // Multiple touch. Should only receive a touch on first down and last up.
657   {
658     Integration::TouchEvent touchEvent;
659     Integration::Point point;
660
661     // 1st point
662     point.SetState( PointState::DOWN );
663     point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
664     touchEvent.points.push_back( point );
665     application.ProcessEvent( touchEvent );
666     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
667     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
668     data.Reset();
669
670     // 2nd point
671     touchEvent.points[0].SetState( PointState::STATIONARY );
672     point.SetDeviceId( 1 );
673     point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
674     touchEvent.points.push_back( point );
675     application.ProcessEvent( touchEvent );
676     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
677     data.Reset();
678
679     // Primary point is up
680     touchEvent.points[0].SetState( PointState::UP );
681     touchEvent.points[1].SetState( PointState::STATIONARY );
682     application.ProcessEvent( touchEvent );
683     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
684     data.Reset();
685
686     // Remove 1st point now, 2nd point is now in motion
687     touchEvent.points.erase( touchEvent.points.begin() );
688     touchEvent.points[0].SetState( PointState::MOTION );
689     touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
690     application.ProcessEvent( touchEvent );
691     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
692     data.Reset();
693
694     // Final point Up
695     touchEvent.points[0].SetState( PointState::UP );
696     application.ProcessEvent( touchEvent );
697     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
698     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
699     data.Reset();
700   }
701   END_TEST;
702 }
703
704 int UtcDaliSceneTouchSignalN(void)
705 {
706   TestApplication application;
707   Dali::Integration::Scene scene = application.GetScene();
708
709   TouchedSignalData data;
710   TouchFunctor functor( data );
711   scene.TouchSignal().Connect( &application, functor );
712
713   // Render and notify.
714   application.SendNotification();
715   application.Render();
716
717   // Confirm functor not called before there has been any touch event.
718   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
719
720   // No actors, single touch, down, motion then up.
721   {
722     GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
723
724     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
725     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
726     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
727
728     data.Reset();
729
730     // Confirm there is no signal when the touchpoint is only moved.
731     GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
732
733     DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
734     data.Reset();
735
736     // Confirm a following up event generates a signal.
737     GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
738
739     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
740     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
741     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
742     data.Reset();
743   }
744
745   // Add an actor to the scene.
746   Actor actor = Actor::New();
747   actor.SetSize( 100.0f, 100.0f );
748   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
749   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
750   actor.TouchedSignal().Connect( &DummyTouchCallback );
751   scene.Add( actor );
752
753   // Render and notify.
754   application.SendNotification();
755   application.Render();
756
757   // Actor on scene. Interrupted before down and interrupted after down.
758   {
759     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
760
761     DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
762     DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
763     DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
764     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
765     data.Reset();
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) == actor );
772     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
773     data.Reset();
774
775     GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.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     DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
781
782     DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
783
784     // Check that getting info about a non-existent point returns an empty handle
785     Actor actor = data.receivedTouchData.GetHitActor( 1 );
786     DALI_TEST_CHECK( !actor );
787
788     data.Reset();
789   }
790
791   END_TEST;
792 }
793
794 int UtcDaliSceneSignalWheelEventP(void)
795 {
796   TestApplication application;
797   Dali::Integration::Scene scene = application.GetScene();
798
799   WheelEventSignalData data;
800   WheelEventReceivedFunctor functor( data );
801   scene.WheelEventSignal().Connect( &application, functor );
802
803   Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
804   application.ProcessEvent( event );
805
806   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
807   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
808   DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
809   DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
810   DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
811   DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
812   DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
813
814   data.Reset();
815
816   Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
817   application.ProcessEvent( event2 );
818
819   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
820   DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
821   DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
822   DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
823   DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
824   DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
825   DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
826   END_TEST;
827 }
828
829 int UtcDaliSceneEnsureEmptySceneCleared(void)
830 {
831   tet_infoline( "Ensure we clear the newly added window" );
832
833   TestApplication application;
834
835   // Create a new scene and set the background colors of both the new and the main scenes
836   auto defaultScene = application.GetScene();
837   defaultScene.SetBackgroundColor( Color::WHITE );
838
839   auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
840   newScene.SetBackgroundColor( Color::RED );
841
842   // Need to create a renderable as we don't start rendering until we have at least one
843   // We don't need to add this to any scene
844   auto actor = CreateRenderableActor();
845
846   auto& glAbstraction = application.GetGlAbstraction();
847   auto clearCountBefore = glAbstraction.GetClearCountCalled();
848
849   application.SendNotification();
850   application.Render();
851
852   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
853
854   // Add the actor to the main scene
855   defaultScene.Add( actor );
856
857   application.SendNotification();
858   application.Render();
859
860   // Add another scene and set its background color, ensure we clear it to the appropriate color
861
862   auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) );
863   thirdScene.SetBackgroundColor( Color::BLUE );
864
865   clearCountBefore = glAbstraction.GetClearCountCalled();
866
867   application.SendNotification();
868   application.Render();
869
870   DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
871
872   END_TEST;
873 }