2 * Copyright (c) 2020 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/devel-api/common/stage.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/wheel-event-integ.h>
28 #include <dali-test-suite-utils.h>
29 #include <mesh-builder.h>
31 // Internal headers are allowed here
36 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
38 // Functor for EventProcessingFinished signal
39 struct EventProcessingFinishedFunctor
42 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
44 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
45 : mEventProcessingFinished( eventProcessingFinished )
50 mEventProcessingFinished = true;
53 bool& mEventProcessingFinished;
56 // Stores data that is populated in the key-event callback and will be read by the TET cases
57 struct KeyEventSignalData
60 : functorCalled(false)
65 functorCalled = false;
67 receivedKeyEvent.keyModifier = 0;
68 receivedKeyEvent.keyPressedName.clear();
69 receivedKeyEvent.keyPressed.clear();
73 KeyEvent receivedKeyEvent;
76 // Functor that sets the data when called
77 struct KeyEventReceivedFunctor
79 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
81 bool operator()( const KeyEvent& keyEvent )
83 signalData.functorCalled = true;
84 signalData.receivedKeyEvent = keyEvent;
89 KeyEventSignalData& signalData;
92 // Stores data that is populated in the touched signal callback and will be read by the TET cases
93 struct TouchedSignalData
96 : functorCalled(false),
97 createNewScene(false),
98 newSceneCreated(false)
103 functorCalled = false;
104 createNewScene = false;
105 newSceneCreated = false;
106 receivedTouchEvent.Reset();
111 bool newSceneCreated;
112 TouchEvent receivedTouchEvent;
115 // Functor that sets the data when touched signal is received
118 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
120 void operator()( const TouchEvent& touch )
122 signalData.functorCalled = true;
123 signalData.receivedTouchEvent = touch;
125 if ( signalData.createNewScene )
127 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
128 DALI_TEST_CHECK( scene );
130 signalData.newSceneCreated = true;
136 signalData.functorCalled = true;
139 TouchedSignalData& signalData;
142 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
143 struct WheelEventSignalData
145 WheelEventSignalData()
146 : functorCalled(false)
151 functorCalled = false;
155 WheelEvent receivedWheelEvent;
158 // Functor that sets the data when wheel-event signal is received
159 struct WheelEventReceivedFunctor
161 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
163 bool operator()( const WheelEvent& wheelEvent )
165 signalData.functorCalled = true;
166 signalData.receivedWheelEvent = wheelEvent;
171 WheelEventSignalData& signalData;
174 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
175 struct KeyEventGeneratedSignalData
177 KeyEventGeneratedSignalData()
178 : functorCalled(false)
183 functorCalled = false;
185 receivedKeyEvent.keyModifier = 0;
186 receivedKeyEvent.keyPressedName.clear();
187 receivedKeyEvent.keyPressed.clear();
191 KeyEvent receivedKeyEvent;
194 // Functor that sets the data when called
195 struct KeyEventGeneratedReceivedFunctor
197 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
201 bool operator()( const KeyEvent& keyEvent )
203 signalData.functorCalled = true;
204 signalData.receivedKeyEvent = keyEvent;
211 signalData.functorCalled = true;
215 KeyEventGeneratedSignalData& signalData;
218 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
220 Integration::TouchEvent touchEvent;
221 Integration::Point point;
222 point.SetState( state );
223 point.SetScreenPosition( screenPosition );
224 touchEvent.points.push_back( point );
225 application.ProcessEvent( touchEvent );
228 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
233 void FrameCallback( int frameId )
237 } // unnamed namespace
239 int UtcDaliSceneAdd(void)
241 TestApplication application;
242 tet_infoline("Testing Dali::Integration::Scene::Add");
244 Dali::Integration::Scene scene = application.GetScene();
246 Actor actor = Actor::New();
247 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
250 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
255 int UtcDaliSceneRemove(void)
257 TestApplication application;
258 tet_infoline("Testing Dali::Integration::Scene::Remove");
260 Dali::Integration::Scene scene = application.GetScene();
262 Actor actor = Actor::New();
263 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
266 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
269 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
274 int UtcDaliSceneGetSize(void)
276 TestApplication application;
277 tet_infoline("Testing Dali::Integration::Scene::GetSize");
279 Dali::Integration::Scene scene = application.GetScene();
280 Size size = scene.GetSize();
281 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
282 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
287 int UtcDaliSceneGetDpi(void)
289 TestApplication application; // Initializes core DPI to default values
291 // Test that setting core DPI explicitly also sets up the scene's DPI.
292 Dali::Integration::Scene scene = application.GetScene();
293 scene.SetDpi( Vector2(200.0f, 180.0f) );
294 Vector2 dpi = scene.GetDpi();
295 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
296 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
300 int UtcDaliSceneGetRenderTaskList(void)
302 TestApplication application;
303 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
305 Dali::Integration::Scene scene = application.GetScene();
307 // Check we get a valid instance.
308 const RenderTaskList& tasks = scene.GetRenderTaskList();
310 // There should be 1 task by default.
311 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
313 // RenderTaskList has it's own UTC tests.
314 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
315 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
317 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
322 int UtcDaliSceneGetRootLayer(void)
324 TestApplication application;
325 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
327 Dali::Integration::Scene scene = application.GetScene();
328 Layer layer = scene.GetLayer( 0 );
329 DALI_TEST_CHECK( layer );
331 // Check that GetRootLayer() correctly retreived layer 0.
332 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
337 int UtcDaliSceneGetLayerCount(void)
339 TestApplication application;
340 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
342 Dali::Integration::Scene scene = application.GetScene();
343 // Initially we have a default layer
344 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
346 Layer layer = Layer::New();
349 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
353 int UtcDaliSceneGetLayer(void)
355 TestApplication application;
356 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
358 Dali::Integration::Scene scene = application.GetScene();
360 Layer rootLayer = scene.GetLayer( 0 );
361 DALI_TEST_CHECK( rootLayer );
363 Layer layer = Layer::New();
366 Layer sameLayer = scene.GetLayer( 1 );
367 DALI_TEST_CHECK( layer == sameLayer );
372 int UtcDaliSceneGet(void)
374 TestApplication application;
375 tet_infoline("Testing Dali::Integration::Scene::Get");
377 Dali::Integration::Scene scene = application.GetScene();
379 Actor actor = Actor::New();
380 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
384 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
389 int UtcDaliSceneDiscard(void)
391 TestApplication application;
392 tet_infoline("Testing Dali::Scene::Discard");
394 // Create a new Scene
395 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
396 DALI_TEST_CHECK( scene );
398 // One reference of scene kept here and the other one kept in the Core
399 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
401 // Render and notify.
402 application.SendNotification();
403 application.Render(0);
405 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
406 Layer rootLayer = scene.GetRootLayer();
407 DALI_TEST_CHECK( rootLayer );
408 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
410 // Request to discard the scene from the Core
412 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
414 // Reset the scene handle
417 // Render and notify.
418 application.SendNotification();
419 application.Render(0);
421 // At this point, the scene should have been automatically deleted
422 // To prove this, the ref count of the root layer handle should be decremented to 1
423 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
425 // Delete the root layer handle
428 // Render and notify.
429 application.SendNotification();
430 application.Render(0);
435 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
437 TestApplication application;
439 Dali::Integration::Scene scene = application.GetScene();
441 TouchedSignalData data;
442 data.createNewScene = true;
443 TouchFunctor functor( data );
444 scene.TouchSignal().Connect( &application, functor );
446 // Render and notify.
447 application.SendNotification();
448 application.Render();
450 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
452 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
453 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
454 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
460 int UtcDaliSceneRootLayerAndSceneAlignment(void)
462 TestApplication application;
465 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
466 DALI_TEST_CHECK( scene );
468 // One reference of scene kept here and the other one kept in the Core
469 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
471 // Add a renderable actor to the scene
472 auto actor = CreateRenderableActor();
475 // Render and notify.
476 application.SendNotification();
477 application.Render(0);
479 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
480 Layer rootLayer = scene.GetRootLayer();
481 DALI_TEST_CHECK( rootLayer );
482 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
484 // Request to discard the scene from the Core
486 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
488 // Reset the scene handle
491 // Render and notify.
492 application.SendNotification();
493 application.Render(0);
495 // At this point, the scene should have been automatically deleted
496 // To prove this, the ref count of the root layer handle should be decremented to 1
497 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
499 // Create a new Scene while the root layer of the deleted scene is still alive
500 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
501 DALI_TEST_CHECK( newScene );
503 // Render and notify.
504 application.SendNotification();
505 application.Render(0);
507 // At this point, we have only one scene but two root layers
508 // The root layer of the deleted scene is still alive
509 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
511 // Delete the root layer of the deleted scene
514 // Render and notify.
515 application.SendNotification();
516 application.Render(0);
521 int UtcDaliSceneEventProcessingFinishedP(void)
523 TestApplication application;
524 Dali::Integration::Scene scene = application.GetScene();
526 bool eventProcessingFinished = false;
527 EventProcessingFinishedFunctor functor( eventProcessingFinished );
528 scene.EventProcessingFinishedSignal().Connect( &application, functor );
530 Actor actor( Actor::New() );
533 application.SendNotification();
534 application.Render();
536 DALI_TEST_CHECK( eventProcessingFinished );
541 int UtcDaliSceneEventProcessingFinishedN(void)
543 TestApplication application;
544 Dali::Integration::Scene scene = application.GetScene();
546 bool eventProcessingFinished = false;
547 EventProcessingFinishedFunctor functor( eventProcessingFinished );
548 scene.EventProcessingFinishedSignal().Connect( &application, functor );
550 Actor actor( Actor::New() );
553 // Do not complete event processing and confirm the signal has not been emitted.
554 DALI_TEST_CHECK( !eventProcessingFinished );
559 int UtcDaliSceneSignalKeyEventP(void)
561 TestApplication application;
562 Dali::Integration::Scene scene = application.GetScene();
564 KeyEventSignalData data;
565 KeyEventReceivedFunctor functor( data );
566 scene.KeyEventSignal().Connect( &application, functor );
568 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
569 application.ProcessEvent( event );
571 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
572 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
573 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
574 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
575 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
579 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580 application.ProcessEvent( event2 );
582 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
584 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
585 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
586 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
590 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591 application.ProcessEvent( event3 );
593 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
595 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
596 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
597 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
601 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602 application.ProcessEvent( event4 );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
606 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
607 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
608 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
612 int UtcDaliSceneSignalKeyEventN(void)
614 TestApplication application;
615 Dali::Integration::Scene scene = application.GetScene();
617 KeyEventSignalData data;
618 KeyEventReceivedFunctor functor( data );
619 scene.KeyEventSignal().Connect( &application, functor );
621 // Check that a non-pressed key events data is not modified.
622 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
627 int UtcDaliSceneTouchSignalP(void)
629 TestApplication application;
630 Dali::Integration::Scene scene = application.GetScene();
632 TouchedSignalData data;
633 TouchFunctor functor( data );
634 scene.TouchSignal().Connect( &application, functor );
636 // Render and notify.
637 application.SendNotification();
638 application.Render();
640 // Basic test: No actors, single touch (down then up).
642 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
644 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
645 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
646 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
649 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
651 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
652 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
653 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
657 // Add an actor to the scene.
658 Actor actor = Actor::New();
659 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
660 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
661 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
662 actor.TouchSignal().Connect( &DummyTouchCallback );
665 // Render and notify.
666 application.SendNotification();
667 application.Render();
669 // Actor on scene, single touch, down in actor, motion, then up outside actor.
671 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
673 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
674 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
675 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
678 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
680 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
683 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
685 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
686 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
687 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
691 // Multiple touch. Should only receive a touch on first down and last up.
693 Integration::TouchEvent touchEvent;
694 Integration::Point point;
697 point.SetState( PointState::DOWN );
698 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
699 touchEvent.points.push_back( point );
700 application.ProcessEvent( touchEvent );
701 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
702 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
706 touchEvent.points[0].SetState( PointState::STATIONARY );
707 point.SetDeviceId( 1 );
708 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
709 touchEvent.points.push_back( point );
710 application.ProcessEvent( touchEvent );
711 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
714 // Primary point is up
715 touchEvent.points[0].SetState( PointState::UP );
716 touchEvent.points[1].SetState( PointState::STATIONARY );
717 application.ProcessEvent( touchEvent );
718 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
721 // Remove 1st point now, 2nd point is now in motion
722 touchEvent.points.erase( touchEvent.points.begin() );
723 touchEvent.points[0].SetState( PointState::MOTION );
724 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
725 application.ProcessEvent( touchEvent );
726 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730 touchEvent.points[0].SetState( PointState::UP );
731 application.ProcessEvent( touchEvent );
732 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
733 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
739 int UtcDaliSceneTouchSignalN(void)
741 TestApplication application;
742 Dali::Integration::Scene scene = application.GetScene();
744 TouchedSignalData data;
745 TouchFunctor functor( data );
746 scene.TouchSignal().Connect( &application, functor );
748 // Render and notify.
749 application.SendNotification();
750 application.Render();
752 // Confirm functor not called before there has been any touch event.
753 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
755 // No actors, single touch, down, motion then up.
757 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
759 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
760 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
761 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
765 // Confirm there is no signal when the touchpoint is only moved.
766 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
768 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
771 // Confirm a following up event generates a signal.
772 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
774 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
775 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
776 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
780 // Add an actor to the scene.
781 Actor actor = Actor::New();
782 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
783 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
784 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
785 actor.TouchSignal().Connect( &DummyTouchCallback );
788 // Render and notify.
789 application.SendNotification();
790 application.Render();
792 // Actor on scene. Interrupted before down and interrupted after down.
794 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
796 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
797 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
798 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
799 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
802 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
804 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
805 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
806 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
807 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
810 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
812 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
813 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
814 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
815 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
817 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
819 // Check that getting info about a non-existent point returns an empty handle
820 Actor actor = data.receivedTouchEvent.GetHitActor( 1 );
821 DALI_TEST_CHECK( !actor );
829 int UtcDaliSceneSignalWheelEventP(void)
831 TestApplication application;
832 Dali::Integration::Scene scene = application.GetScene();
834 WheelEventSignalData data;
835 WheelEventReceivedFunctor functor( data );
836 scene.WheelEventSignal().Connect( &application, functor );
838 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
839 application.ProcessEvent( event );
841 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
842 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.GetType() );
843 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.GetDirection() );
844 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.GetModifiers() );
845 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.GetPoint() );
846 DALI_TEST_CHECK( event.delta == data.receivedWheelEvent.GetDelta() );
847 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.GetTime() );
851 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
852 application.ProcessEvent( event2 );
854 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
855 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.GetType() );
856 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.GetDirection() );
857 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.GetModifiers() );
858 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.GetPoint() );
859 DALI_TEST_CHECK( event2.delta == data.receivedWheelEvent.GetDelta() );
860 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.GetTime() );
864 int UtcDaliSceneSurfaceResizedDefaultScene(void)
866 tet_infoline( "Ensure resizing of the surface is handled properly" );
868 TestApplication application;
870 auto defaultScene = application.GetScene();
871 DALI_TEST_CHECK( defaultScene );
873 // Ensure stage size matches the scene size
874 auto stage = Stage::GetCurrent();
875 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
878 Vector2 newSize( 1000.0f, 2000.0f );
879 DALI_TEST_CHECK( stage.GetSize() != newSize );
880 defaultScene.SurfaceResized( newSize.width, newSize.height );
882 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
883 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
888 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
890 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
892 TestApplication application;
893 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
894 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
895 glAbstraction.EnableViewportCallTrace( true );
897 // Initial scene setup
898 Geometry geometry = CreateQuadGeometry();
899 Shader shader = CreateShader();
900 Renderer renderer = Renderer::New( geometry, shader );
902 Actor actor = Actor::New();
903 actor.AddRenderer(renderer);
904 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
905 application.GetScene().Add(actor);
907 // Render before resizing surface
908 application.SendNotification();
909 application.Render(0);
910 glAbstraction.ResetViewportCallStack();
912 auto defaultScene = application.GetScene();
913 DALI_TEST_CHECK( defaultScene );
915 // Ensure stage size matches the scene size
916 auto stage = Stage::GetCurrent();
917 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
920 Vector2 newSize( 1000.0f, 2000.0f );
921 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
922 DALI_TEST_CHECK( stage.GetSize() != newSize );
923 defaultScene.SurfaceResized( newSize.width, newSize.height );
925 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
926 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
928 // Render after resizing surface
929 application.SendNotification();
930 application.Render(0);
932 // Check that the viewport is handled properly
933 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
938 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
940 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
942 TestApplication application;
943 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
944 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
945 glAbstraction.EnableViewportCallTrace( true );
947 // Initial scene setup
948 auto scene = application.GetScene();
950 Geometry geometry = CreateQuadGeometry();
951 Shader shader = CreateShader();
952 Renderer renderer = Renderer::New( geometry, shader );
954 Actor actor = Actor::New();
955 actor.AddRenderer(renderer);
957 int testHeight = 400;
958 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
961 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
962 application.GetScene().Add( offscreenCameraActor );
964 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
966 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
967 newTask.SetCameraActor( offscreenCameraActor );
968 newTask.SetSourceActor( actor );
969 newTask.SetFrameBuffer( newFrameBuffer );
970 newTask.SetViewportPosition( Vector2(0, 0) );
971 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
973 // Render before resizing surface
974 application.SendNotification();
975 application.Render(0);
976 glAbstraction.ResetViewportCallStack();
978 Rect<int32_t> initialViewport = newTask.GetViewport();
979 int initialWidth = initialViewport.width;
980 int initialHeight = initialViewport.height;
981 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
982 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
984 auto defaultScene = application.GetScene();
985 DALI_TEST_CHECK( defaultScene );
987 // Ensure stage size matches the scene size
988 auto stage = Stage::GetCurrent();
989 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
992 Vector2 newSize( 1000.0f, 2000.0f );
993 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
994 DALI_TEST_CHECK( stage.GetSize() != newSize );
995 defaultScene.SurfaceResized( newSize.width, newSize.height );
997 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
998 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1000 // Render after resizing surface
1001 application.SendNotification();
1002 application.Render(0);
1004 // Check that the viewport is handled properly
1005 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1007 // Second render-task should not be affected
1008 Rect<int32_t> viewport = newTask.GetViewport();
1009 int width = viewport.width;
1010 int height = viewport.height;
1011 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1012 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1017 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1019 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1021 TestApplication application;
1022 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1024 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1026 // Ensure stage size does NOT match the surface size
1027 auto stage = Stage::GetCurrent();
1028 const auto stageSize = stage.GetSize();
1029 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1030 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1032 // Resize the surface and inform the scene accordingly
1033 Vector2 newSize( 1000.0f, 2000.0f );
1034 DALI_TEST_CHECK( stage.GetSize() != newSize );
1035 scene.SurfaceResized( newSize.width, newSize.height );
1037 // Ensure the stage hasn't been resized
1038 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1039 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1044 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1046 TestApplication application;
1047 Dali::Integration::Scene scene = application.GetScene();
1049 KeyEventGeneratedSignalData data;
1050 KeyEventGeneratedReceivedFunctor functor( data );
1051 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1053 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1054 application.ProcessEvent( event );
1056 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1057 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1058 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1059 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1060 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1064 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1065 application.ProcessEvent( event2 );
1067 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1068 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1069 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1070 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1071 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1075 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1076 application.ProcessEvent( event3 );
1078 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1079 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1080 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1081 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1082 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1086 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1087 application.ProcessEvent( event4 );
1089 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1090 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1091 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1092 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1093 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1097 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1099 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1101 TestApplication application;
1103 // Create a new scene and set the background color of the main scene
1104 auto defaultScene = application.GetScene();
1105 defaultScene.SetBackgroundColor( Color::BLUE );
1107 // Need to create a renderable as we don't start rendering until we have at least one
1108 // We don't need to add this to any scene
1109 auto actor = CreateRenderableActor();
1111 auto& glAbstraction = application.GetGlAbstraction();
1112 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1114 application.SendNotification();
1115 application.Render();
1117 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1118 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1120 defaultScene.SurfaceReplaced();
1122 application.SendNotification();
1123 application.Render();
1125 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1126 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1128 // Check when the main render task viewport is set the clear color is clipped using scissors
1129 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1130 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1131 scissorTrace.Enable( true );
1132 enabledDisableTrace.Enable( true );
1134 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1136 application.SendNotification();
1137 application.Render();
1139 // Check scissor test was enabled.
1140 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1142 // Check the scissor was set, and the coordinates are correct.
1143 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1145 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1146 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1148 scissorTrace.Enable( false );
1149 scissorTrace.Reset();
1151 enabledDisableTrace.Enable( false );
1152 enabledDisableTrace.Reset();
1157 int UtcDaliSceneEmptySceneRendering(void)
1159 tet_infoline( "Ensure not rendering before a Renderer is added" );
1161 TestApplication application;
1162 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1164 // Render without any renderer
1165 application.SendNotification();
1166 application.Render();
1168 // Check the clear count and the render status
1169 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1170 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1173 Geometry geometry = CreateQuadGeometry();
1174 Shader shader = CreateShader();
1175 Renderer renderer = Renderer::New( geometry, shader );
1177 Actor actor = Actor::New();
1178 actor.AddRenderer( renderer );
1180 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1181 application.GetScene().Add( actor );
1184 application.SendNotification();
1185 application.Render();
1187 // Check the clear count and the render status
1188 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1189 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1191 // Remove the Renderer
1192 application.GetScene().Remove( actor );
1197 application.SendNotification();
1198 application.Render();
1200 // Check the clear count and the render status
1201 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1202 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1207 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1209 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1211 TestApplication application;
1214 Geometry geometry = CreateQuadGeometry();
1215 Shader shader = CreateShader();
1216 Renderer renderer = Renderer::New( geometry, shader );
1218 Actor actor = Actor::New();
1219 actor.AddRenderer( renderer );
1220 application.GetScene().Add( actor );
1222 Dali::Integration::Scene scene = application.GetScene();
1225 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1226 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1229 application.SendNotification();
1230 application.Render();
1232 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1233 scene.GetFrameRenderedCallback( callbackContainer );
1235 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1236 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1238 callbackContainer.clear();
1240 scene.GetFramePresentedCallback( callbackContainer );
1242 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1243 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );