2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include <dali-test-suite-utils.h>
29 // Internal headers are allowed here
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
40 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
42 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
43 : mEventProcessingFinished( eventProcessingFinished )
48 mEventProcessingFinished = true;
51 bool& mEventProcessingFinished;
54 // Stores data that is populated in the key-event callback and will be read by the TET cases
55 struct KeyEventSignalData
58 : functorCalled(false)
63 functorCalled = false;
65 receivedKeyEvent.keyModifier = 0;
66 receivedKeyEvent.keyPressedName.clear();
67 receivedKeyEvent.keyPressed.clear();
71 KeyEvent receivedKeyEvent;
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
77 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
79 bool operator()( const KeyEvent& keyEvent )
81 signalData.functorCalled = true;
82 signalData.receivedKeyEvent = keyEvent;
87 KeyEventSignalData& signalData;
90 // Stores data that is populated in the touched signal callback and will be read by the TET cases
91 struct TouchedSignalData
94 : functorCalled(false),
95 createNewScene(false),
96 newSceneCreated(false)
101 functorCalled = false;
102 createNewScene = false;
103 newSceneCreated = false;
105 receivedTouchEvent.points.clear();
106 receivedTouchEvent.time = 0;
108 receivedTouchData.Reset();
113 bool newSceneCreated;
114 TouchEvent receivedTouchEvent;
115 TouchData receivedTouchData;
118 // Functor that sets the data when touched signal is received
119 struct TouchedFunctor
121 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
123 void operator()( const TouchEvent& touch )
125 signalData.functorCalled = true;
126 signalData.receivedTouchEvent = touch;
129 TouchedSignalData& signalData;
132 // Functor that sets the data when touched signal is received
135 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
137 void operator()( const TouchData& touch )
139 signalData.functorCalled = true;
140 signalData.receivedTouchData = touch;
142 if ( signalData.createNewScene )
144 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
145 DALI_TEST_CHECK( scene );
147 signalData.newSceneCreated = true;
153 signalData.functorCalled = true;
156 TouchedSignalData& signalData;
159 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
160 struct WheelEventSignalData
162 WheelEventSignalData()
163 : functorCalled(false)
168 functorCalled = false;
172 WheelEvent receivedWheelEvent;
175 // Functor that sets the data when wheel-event signal is received
176 struct WheelEventReceivedFunctor
178 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
180 bool operator()( const WheelEvent& wheelEvent )
182 signalData.functorCalled = true;
183 signalData.receivedWheelEvent = wheelEvent;
188 WheelEventSignalData& signalData;
191 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
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 );
201 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
206 } // unnamed namespace
208 int UtcDaliSceneAdd(void)
210 TestApplication application;
211 tet_infoline("Testing Dali::Integration::Scene::Add");
213 Dali::Integration::Scene scene = application.GetScene();
215 Actor actor = Actor::New();
216 DALI_TEST_CHECK( !actor.OnStage() );
219 DALI_TEST_CHECK( actor.OnStage() );
224 int UtcDaliSceneRemove(void)
226 TestApplication application;
227 tet_infoline("Testing Dali::Integration::Scene::Remove");
229 Dali::Integration::Scene scene = application.GetScene();
231 Actor actor = Actor::New();
232 DALI_TEST_CHECK( !actor.OnStage() );
235 DALI_TEST_CHECK( actor.OnStage() );
238 DALI_TEST_CHECK( !actor.OnStage() );
243 int UtcDaliSceneGetSize(void)
245 TestApplication application;
246 tet_infoline("Testing Dali::Integration::Scene::GetSize");
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 );
256 int UtcDaliSceneGetDpi(void)
258 TestApplication application; // Initializes core DPI to default values
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 );
269 int UtcDaliSceneGetRenderTaskList(void)
271 TestApplication application;
272 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
274 Dali::Integration::Scene scene = application.GetScene();
276 // Check we get a valid instance.
277 const RenderTaskList& tasks = scene.GetRenderTaskList();
279 // There should be 1 task by default.
280 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
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();
286 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
291 int UtcDaliSceneGetRootLayer(void)
293 TestApplication application;
294 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
296 Dali::Integration::Scene scene = application.GetScene();
297 Layer layer = scene.GetLayer( 0 );
298 DALI_TEST_CHECK( layer );
300 // Check that GetRootLayer() correctly retreived layer 0.
301 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
306 int UtcDaliSceneGetLayerCount(void)
308 TestApplication application;
309 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
311 Dali::Integration::Scene scene = application.GetScene();
312 // Initially we have a default layer
313 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
315 Layer layer = Layer::New();
318 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
322 int UtcDaliSceneGetLayer(void)
324 TestApplication application;
325 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
327 Dali::Integration::Scene scene = application.GetScene();
329 Layer rootLayer = scene.GetLayer( 0 );
330 DALI_TEST_CHECK( rootLayer );
332 Layer layer = Layer::New();
335 Layer sameLayer = scene.GetLayer( 1 );
336 DALI_TEST_CHECK( layer == sameLayer );
341 int UtcDaliSceneGet(void)
343 TestApplication application;
344 tet_infoline("Testing Dali::Integration::Scene::Get");
346 Dali::Integration::Scene scene = application.GetScene();
348 Actor actor = Actor::New();
349 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
353 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
358 int UtcDaliSceneDiscard(void)
360 TestApplication application;
361 tet_infoline("Testing Dali::Scene::Discard");
363 // Create a new Scene
364 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
365 DALI_TEST_CHECK( scene );
367 // One reference of scene kept here and the other one kept in the Core
368 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
370 // Render and notify.
371 application.SendNotification();
372 application.Render(0);
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 );
379 // Request to discard the scene from the Core
381 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
383 // Reset the scene handle
386 // Render and notify.
387 application.SendNotification();
388 application.Render(0);
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 );
394 // Delete the root layer handle
397 // Render and notify.
398 application.SendNotification();
399 application.Render(0);
404 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
406 TestApplication application;
408 Dali::Integration::Scene scene = application.GetScene();
410 TouchedSignalData data;
411 data.createNewScene = true;
412 TouchFunctor functor( data );
413 scene.TouchSignal().Connect( &application, functor );
415 // Render and notify.
416 application.SendNotification();
417 application.Render();
419 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
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 );
429 int UtcDaliSceneRootLayerAndSceneAlignment(void)
431 TestApplication application;
434 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
435 DALI_TEST_CHECK( scene );
437 // One reference of scene kept here and the other one kept in the Core
438 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
440 // Render and notify.
441 application.SendNotification();
442 application.Render(0);
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 );
449 // Request to discard the scene from the Core
451 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
453 // Reset the scene handle
456 // Render and notify.
457 application.SendNotification();
458 application.Render(0);
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 );
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 );
468 // Render and notify.
469 application.SendNotification();
470 application.Render(0);
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 );
476 // Delete the root layer of the deleted scene
479 // Render and notify.
480 application.SendNotification();
481 application.Render(0);
486 int UtcDaliSceneDeleteSurface(void)
488 TestApplication application;
491 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
492 DALI_TEST_CHECK( scene );
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 );
498 // Render and notify.
499 application.SendNotification();
500 application.Render(0);
502 // Add a renderable actor to the scene
503 auto actor = CreateRenderableActor();
506 // Render and notify.
507 application.SendNotification();
508 application.Render(0);
510 // Notify the Core that the render surface will be deleted.
511 application.GetCore().SurfaceDeleted( renderSurface );
513 // Delete the render surface
514 delete renderSurface;
515 renderSurface = nullptr;
517 // Render and notify.
518 application.SendNotification();
519 application.Render(0);
524 int UtcDaliSceneEventProcessingFinishedP(void)
526 TestApplication application;
527 Dali::Integration::Scene scene = application.GetScene();
529 bool eventProcessingFinished = false;
530 EventProcessingFinishedFunctor functor( eventProcessingFinished );
531 scene.EventProcessingFinishedSignal().Connect( &application, functor );
533 Actor actor( Actor::New() );
536 application.SendNotification();
537 application.Render();
539 DALI_TEST_CHECK( eventProcessingFinished );
544 int UtcDaliSceneEventProcessingFinishedN(void)
546 TestApplication application;
547 Dali::Integration::Scene scene = application.GetScene();
549 bool eventProcessingFinished = false;
550 EventProcessingFinishedFunctor functor( eventProcessingFinished );
551 scene.EventProcessingFinishedSignal().Connect( &application, functor );
553 Actor actor( Actor::New() );
556 // Do not complete event processing and confirm the signal has not been emitted.
557 DALI_TEST_CHECK( !eventProcessingFinished );
562 int UtcDaliSceneSignalKeyEventP(void)
564 TestApplication application;
565 Dali::Integration::Scene scene = application.GetScene();
567 KeyEventSignalData data;
568 KeyEventReceivedFunctor functor( data );
569 scene.KeyEventSignal().Connect( &application, functor );
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 );
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 ) );
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 );
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 ) );
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 );
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 ) );
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 );
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 ) );
615 int UtcDaliSceneSignalKeyEventN(void)
617 TestApplication application;
618 Dali::Integration::Scene scene = application.GetScene();
620 KeyEventSignalData data;
621 KeyEventReceivedFunctor functor( data );
622 scene.KeyEventSignal().Connect( &application, functor );
624 // Check that a non-pressed key events data is not modified.
625 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
630 int UtcDaliSceneTouchSignalP(void)
632 TestApplication application;
633 Dali::Integration::Scene scene = application.GetScene();
635 TouchedSignalData data;
636 TouchFunctor functor( data );
637 scene.TouchSignal().Connect( &application, functor );
639 // Render and notify.
640 application.SendNotification();
641 application.Render();
643 // Basic test: No actors, single touch (down then up).
645 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
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) );
652 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
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) );
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 );
668 // Render and notify.
669 application.SendNotification();
670 application.Render();
672 // Actor on scene, single touch, down in actor, motion, then up outside actor.
674 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
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 );
681 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
683 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
686 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
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) );
694 // Multiple touch. Should only receive a touch on first down and last up.
696 Integration::TouchEvent touchEvent;
697 Integration::Point 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 );
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 );
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 );
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 );
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 );
742 int UtcDaliSceneTouchSignalN(void)
744 TestApplication application;
745 Dali::Integration::Scene scene = application.GetScene();
747 TouchedSignalData data;
748 TouchFunctor functor( data );
749 scene.TouchSignal().Connect( &application, functor );
751 // Render and notify.
752 application.SendNotification();
753 application.Render();
755 // Confirm functor not called before there has been any touch event.
756 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
758 // No actors, single touch, down, motion then up.
760 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
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));
768 // Confirm there is no signal when the touchpoint is only moved.
769 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
771 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
774 // Confirm a following up event generates a signal.
775 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
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));
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 );
791 // Render and notify.
792 application.SendNotification();
793 application.Render();
795 // Actor on scene. Interrupted before down and interrupted after down.
797 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
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 );
805 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
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 );
813 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
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 );
820 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
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 );
832 int UtcDaliSceneSignalWheelEventP(void)
834 TestApplication application;
835 Dali::Integration::Scene scene = application.GetScene();
837 WheelEventSignalData data;
838 WheelEventReceivedFunctor functor( data );
839 scene.WheelEventSignal().Connect( &application, functor );
841 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
842 application.ProcessEvent( event );
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 );
854 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
855 application.ProcessEvent( event2 );
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 );
867 int UtcDaliSceneEnsureEmptySceneCleared(void)
869 tet_infoline( "Ensure we clear the newly added window" );
871 TestApplication application;
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 );
877 auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
878 newScene.SetBackgroundColor( Color::RED );
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();
884 auto& glAbstraction = application.GetGlAbstraction();
885 auto clearCountBefore = glAbstraction.GetClearCountCalled();
887 application.SendNotification();
888 application.Render();
890 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
892 // Add the actor to the main scene
893 defaultScene.Add( actor );
895 application.SendNotification();
896 application.Render();
898 // Add another scene and set its background color, ensure we clear it to the appropriate color
900 auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) );
901 thirdScene.SetBackgroundColor( Color::BLUE );
903 clearCountBefore = glAbstraction.GetClearCountCalled();
905 application.SendNotification();
906 application.Render();
908 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
913 int UtcDaliSceneSurfaceResizedDefaultScene(void)
915 tet_infoline( "Ensure resizing of the surface is handled properly" );
917 TestApplication application;
919 auto defaultScene = application.GetScene();
920 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
921 DALI_TEST_CHECK( defaultSurface );
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 );
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();
933 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
934 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
939 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
941 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
943 TestApplication application;
944 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
946 auto scene = Integration::Scene::New( Vector2::ZERO );
947 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
948 scene.SetSurface( surface );
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 );
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();
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 );