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;
107 receivedTouchEvent.points.clear();
108 receivedTouchEvent.time = 0;
110 receivedTouchData.Reset();
115 bool newSceneCreated;
116 TouchEvent receivedTouchEvent;
117 TouchData receivedTouchData;
120 // Functor that sets the data when touched signal is received
121 struct TouchedFunctor
123 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
125 void operator()( const TouchEvent& touch )
127 signalData.functorCalled = true;
128 signalData.receivedTouchEvent = touch;
131 TouchedSignalData& signalData;
134 // Functor that sets the data when touched signal is received
137 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
139 void operator()( const TouchData& touch )
141 signalData.functorCalled = true;
142 signalData.receivedTouchData = touch;
144 if ( signalData.createNewScene )
146 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
147 DALI_TEST_CHECK( scene );
149 signalData.newSceneCreated = true;
155 signalData.functorCalled = true;
158 TouchedSignalData& signalData;
161 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
162 struct WheelEventSignalData
164 WheelEventSignalData()
165 : functorCalled(false)
170 functorCalled = false;
174 WheelEvent receivedWheelEvent;
177 // Functor that sets the data when wheel-event signal is received
178 struct WheelEventReceivedFunctor
180 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
182 bool operator()( const WheelEvent& wheelEvent )
184 signalData.functorCalled = true;
185 signalData.receivedWheelEvent = wheelEvent;
190 WheelEventSignalData& signalData;
193 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
194 struct KeyEventGeneratedSignalData
196 KeyEventGeneratedSignalData()
197 : functorCalled(false)
202 functorCalled = false;
204 receivedKeyEvent.keyModifier = 0;
205 receivedKeyEvent.keyPressedName.clear();
206 receivedKeyEvent.keyPressed.clear();
210 KeyEvent receivedKeyEvent;
213 // Functor that sets the data when called
214 struct KeyEventGeneratedReceivedFunctor
216 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
220 bool operator()( const KeyEvent& keyEvent )
222 signalData.functorCalled = true;
223 signalData.receivedKeyEvent = keyEvent;
230 signalData.functorCalled = true;
234 KeyEventGeneratedSignalData& signalData;
237 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
239 Integration::TouchEvent touchEvent;
240 Integration::Point point;
241 point.SetState( state );
242 point.SetScreenPosition( screenPosition );
243 touchEvent.points.push_back( point );
244 application.ProcessEvent( touchEvent );
247 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
252 void FrameCallback( int frameId )
256 } // unnamed namespace
258 int UtcDaliSceneAdd(void)
260 TestApplication application;
261 tet_infoline("Testing Dali::Integration::Scene::Add");
263 Dali::Integration::Scene scene = application.GetScene();
265 Actor actor = Actor::New();
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 UtcDaliSceneRemove(void)
276 TestApplication application;
277 tet_infoline("Testing Dali::Integration::Scene::Remove");
279 Dali::Integration::Scene scene = application.GetScene();
281 Actor actor = Actor::New();
282 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
285 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
288 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
293 int UtcDaliSceneGetSize(void)
295 TestApplication application;
296 tet_infoline("Testing Dali::Integration::Scene::GetSize");
298 Dali::Integration::Scene scene = application.GetScene();
299 Size size = scene.GetSize();
300 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
301 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
306 int UtcDaliSceneGetDpi(void)
308 TestApplication application; // Initializes core DPI to default values
310 // Test that setting core DPI explicitly also sets up the scene's DPI.
311 Dali::Integration::Scene scene = application.GetScene();
312 scene.SetDpi( Vector2(200.0f, 180.0f) );
313 Vector2 dpi = scene.GetDpi();
314 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
315 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
319 int UtcDaliSceneGetRenderTaskList(void)
321 TestApplication application;
322 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
324 Dali::Integration::Scene scene = application.GetScene();
326 // Check we get a valid instance.
327 const RenderTaskList& tasks = scene.GetRenderTaskList();
329 // There should be 1 task by default.
330 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
332 // RenderTaskList has it's own UTC tests.
333 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
334 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
336 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
341 int UtcDaliSceneGetRootLayer(void)
343 TestApplication application;
344 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
346 Dali::Integration::Scene scene = application.GetScene();
347 Layer layer = scene.GetLayer( 0 );
348 DALI_TEST_CHECK( layer );
350 // Check that GetRootLayer() correctly retreived layer 0.
351 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
356 int UtcDaliSceneGetLayerCount(void)
358 TestApplication application;
359 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
361 Dali::Integration::Scene scene = application.GetScene();
362 // Initially we have a default layer
363 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
365 Layer layer = Layer::New();
368 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
372 int UtcDaliSceneGetLayer(void)
374 TestApplication application;
375 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
377 Dali::Integration::Scene scene = application.GetScene();
379 Layer rootLayer = scene.GetLayer( 0 );
380 DALI_TEST_CHECK( rootLayer );
382 Layer layer = Layer::New();
385 Layer sameLayer = scene.GetLayer( 1 );
386 DALI_TEST_CHECK( layer == sameLayer );
391 int UtcDaliSceneGet(void)
393 TestApplication application;
394 tet_infoline("Testing Dali::Integration::Scene::Get");
396 Dali::Integration::Scene scene = application.GetScene();
398 Actor actor = Actor::New();
399 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
403 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
408 int UtcDaliSceneDiscard(void)
410 TestApplication application;
411 tet_infoline("Testing Dali::Scene::Discard");
413 // Create a new Scene
414 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
415 DALI_TEST_CHECK( scene );
417 // One reference of scene kept here and the other one kept in the Core
418 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
420 // Render and notify.
421 application.SendNotification();
422 application.Render(0);
424 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
425 Layer rootLayer = scene.GetRootLayer();
426 DALI_TEST_CHECK( rootLayer );
427 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
429 // Request to discard the scene from the Core
431 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
433 // Reset the scene handle
436 // Render and notify.
437 application.SendNotification();
438 application.Render(0);
440 // At this point, the scene should have been automatically deleted
441 // To prove this, the ref count of the root layer handle should be decremented to 1
442 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
444 // Delete the root layer handle
447 // Render and notify.
448 application.SendNotification();
449 application.Render(0);
454 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
456 TestApplication application;
458 Dali::Integration::Scene scene = application.GetScene();
460 TouchedSignalData data;
461 data.createNewScene = true;
462 TouchFunctor functor( data );
463 scene.TouchSignal().Connect( &application, functor );
465 // Render and notify.
466 application.SendNotification();
467 application.Render();
469 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
471 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
472 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
473 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
479 int UtcDaliSceneRootLayerAndSceneAlignment(void)
481 TestApplication application;
484 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
485 DALI_TEST_CHECK( scene );
487 // One reference of scene kept here and the other one kept in the Core
488 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
490 // Add a renderable actor to the scene
491 auto actor = CreateRenderableActor();
494 // Render and notify.
495 application.SendNotification();
496 application.Render(0);
498 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
499 Layer rootLayer = scene.GetRootLayer();
500 DALI_TEST_CHECK( rootLayer );
501 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
503 // Request to discard the scene from the Core
505 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
507 // Reset the scene handle
510 // Render and notify.
511 application.SendNotification();
512 application.Render(0);
514 // At this point, the scene should have been automatically deleted
515 // To prove this, the ref count of the root layer handle should be decremented to 1
516 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
518 // Create a new Scene while the root layer of the deleted scene is still alive
519 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
520 DALI_TEST_CHECK( newScene );
522 // Render and notify.
523 application.SendNotification();
524 application.Render(0);
526 // At this point, we have only one scene but two root layers
527 // The root layer of the deleted scene is still alive
528 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
530 // Delete the root layer of the deleted scene
533 // Render and notify.
534 application.SendNotification();
535 application.Render(0);
540 int UtcDaliSceneEventProcessingFinishedP(void)
542 TestApplication application;
543 Dali::Integration::Scene scene = application.GetScene();
545 bool eventProcessingFinished = false;
546 EventProcessingFinishedFunctor functor( eventProcessingFinished );
547 scene.EventProcessingFinishedSignal().Connect( &application, functor );
549 Actor actor( Actor::New() );
552 application.SendNotification();
553 application.Render();
555 DALI_TEST_CHECK( eventProcessingFinished );
560 int UtcDaliSceneEventProcessingFinishedN(void)
562 TestApplication application;
563 Dali::Integration::Scene scene = application.GetScene();
565 bool eventProcessingFinished = false;
566 EventProcessingFinishedFunctor functor( eventProcessingFinished );
567 scene.EventProcessingFinishedSignal().Connect( &application, functor );
569 Actor actor( Actor::New() );
572 // Do not complete event processing and confirm the signal has not been emitted.
573 DALI_TEST_CHECK( !eventProcessingFinished );
578 int UtcDaliSceneSignalKeyEventP(void)
580 TestApplication application;
581 Dali::Integration::Scene scene = application.GetScene();
583 KeyEventSignalData data;
584 KeyEventReceivedFunctor functor( data );
585 scene.KeyEventSignal().Connect( &application, functor );
587 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
588 application.ProcessEvent( event );
590 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
591 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
592 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
593 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
594 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
598 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
599 application.ProcessEvent( event2 );
601 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
602 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
603 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
604 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
605 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
609 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
610 application.ProcessEvent( event3 );
612 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
613 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
614 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
615 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
616 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
620 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
621 application.ProcessEvent( event4 );
623 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
624 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
625 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
626 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
627 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
631 int UtcDaliSceneSignalKeyEventN(void)
633 TestApplication application;
634 Dali::Integration::Scene scene = application.GetScene();
636 KeyEventSignalData data;
637 KeyEventReceivedFunctor functor( data );
638 scene.KeyEventSignal().Connect( &application, functor );
640 // Check that a non-pressed key events data is not modified.
641 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
646 int UtcDaliSceneTouchSignalP(void)
648 TestApplication application;
649 Dali::Integration::Scene scene = application.GetScene();
651 TouchedSignalData data;
652 TouchFunctor functor( data );
653 scene.TouchSignal().Connect( &application, functor );
655 // Render and notify.
656 application.SendNotification();
657 application.Render();
659 // Basic test: No actors, single touch (down then up).
661 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
663 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
664 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
665 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
668 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
670 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
671 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
672 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
676 // Add an actor to the scene.
677 Actor actor = Actor::New();
678 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
679 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
680 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
681 actor.TouchedSignal().Connect( &DummyTouchCallback );
684 // Render and notify.
685 application.SendNotification();
686 application.Render();
688 // Actor on scene, single touch, down in actor, motion, then up outside actor.
690 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
692 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
693 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
694 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
697 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
699 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
702 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
704 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
705 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
706 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
710 // Multiple touch. Should only receive a touch on first down and last up.
712 Integration::TouchEvent touchEvent;
713 Integration::Point point;
716 point.SetState( PointState::DOWN );
717 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
718 touchEvent.points.push_back( point );
719 application.ProcessEvent( touchEvent );
720 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
721 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
725 touchEvent.points[0].SetState( PointState::STATIONARY );
726 point.SetDeviceId( 1 );
727 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
728 touchEvent.points.push_back( point );
729 application.ProcessEvent( touchEvent );
730 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
733 // Primary point is up
734 touchEvent.points[0].SetState( PointState::UP );
735 touchEvent.points[1].SetState( PointState::STATIONARY );
736 application.ProcessEvent( touchEvent );
737 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
740 // Remove 1st point now, 2nd point is now in motion
741 touchEvent.points.erase( touchEvent.points.begin() );
742 touchEvent.points[0].SetState( PointState::MOTION );
743 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
744 application.ProcessEvent( touchEvent );
745 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
749 touchEvent.points[0].SetState( PointState::UP );
750 application.ProcessEvent( touchEvent );
751 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
752 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
758 int UtcDaliSceneTouchSignalN(void)
760 TestApplication application;
761 Dali::Integration::Scene scene = application.GetScene();
763 TouchedSignalData data;
764 TouchFunctor functor( data );
765 scene.TouchSignal().Connect( &application, functor );
767 // Render and notify.
768 application.SendNotification();
769 application.Render();
771 // Confirm functor not called before there has been any touch event.
772 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
774 // No actors, single touch, down, motion then up.
776 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
778 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
779 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
780 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
784 // Confirm there is no signal when the touchpoint is only moved.
785 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
787 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
790 // Confirm a following up event generates a signal.
791 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
793 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
794 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
795 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
799 // Add an actor to the scene.
800 Actor actor = Actor::New();
801 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
802 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
803 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
804 actor.TouchedSignal().Connect( &DummyTouchCallback );
807 // Render and notify.
808 application.SendNotification();
809 application.Render();
811 // Actor on scene. Interrupted before down and interrupted after 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 );
821 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
823 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
824 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
825 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
826 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
829 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
831 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
832 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
833 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
834 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
836 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
838 // Check that getting info about a non-existent point returns an empty handle
839 Actor actor = data.receivedTouchData.GetHitActor( 1 );
840 DALI_TEST_CHECK( !actor );
848 int UtcDaliSceneSignalWheelEventP(void)
850 TestApplication application;
851 Dali::Integration::Scene scene = application.GetScene();
853 WheelEventSignalData data;
854 WheelEventReceivedFunctor functor( data );
855 scene.WheelEventSignal().Connect( &application, functor );
857 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
858 application.ProcessEvent( event );
860 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
861 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
862 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
863 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
864 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
865 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
866 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
870 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
871 application.ProcessEvent( event2 );
873 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
874 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
875 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
876 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
877 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
878 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
879 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
883 int UtcDaliSceneSurfaceResizedDefaultScene(void)
885 tet_infoline( "Ensure resizing of the surface is handled properly" );
887 TestApplication application;
889 auto defaultScene = application.GetScene();
890 DALI_TEST_CHECK( defaultScene );
892 // Ensure stage size matches the scene size
893 auto stage = Stage::GetCurrent();
894 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
897 Vector2 newSize( 1000.0f, 2000.0f );
898 DALI_TEST_CHECK( stage.GetSize() != newSize );
899 defaultScene.SurfaceResized( newSize.width, newSize.height );
901 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
902 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
907 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
909 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
911 TestApplication application;
912 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
913 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
914 glAbstraction.EnableViewportCallTrace( true );
916 // Initial scene setup
917 Geometry geometry = CreateQuadGeometry();
918 Shader shader = CreateShader();
919 Renderer renderer = Renderer::New( geometry, shader );
921 Actor actor = Actor::New();
922 actor.AddRenderer(renderer);
923 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
924 application.GetScene().Add(actor);
926 // Render before resizing surface
927 application.SendNotification();
928 application.Render(0);
929 glAbstraction.ResetViewportCallStack();
931 auto defaultScene = application.GetScene();
932 DALI_TEST_CHECK( defaultScene );
934 // Ensure stage size matches the scene size
935 auto stage = Stage::GetCurrent();
936 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
939 Vector2 newSize( 1000.0f, 2000.0f );
940 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
941 DALI_TEST_CHECK( stage.GetSize() != newSize );
942 defaultScene.SurfaceResized( newSize.width, newSize.height );
944 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
945 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
947 // Render after resizing surface
948 application.SendNotification();
949 application.Render(0);
951 // Check that the viewport is handled properly
952 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
957 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
959 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
961 TestApplication application;
962 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
963 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
964 glAbstraction.EnableViewportCallTrace( true );
966 // Initial scene setup
967 auto scene = application.GetScene();
969 Geometry geometry = CreateQuadGeometry();
970 Shader shader = CreateShader();
971 Renderer renderer = Renderer::New( geometry, shader );
973 Actor actor = Actor::New();
974 actor.AddRenderer(renderer);
976 int testHeight = 400;
977 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
980 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
981 application.GetScene().Add( offscreenCameraActor );
983 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
985 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
986 newTask.SetCameraActor( offscreenCameraActor );
987 newTask.SetSourceActor( actor );
988 newTask.SetFrameBuffer( newFrameBuffer );
989 newTask.SetViewportPosition( Vector2(0, 0) );
990 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
992 // Render before resizing surface
993 application.SendNotification();
994 application.Render(0);
995 glAbstraction.ResetViewportCallStack();
997 Rect<int32_t> initialViewport = newTask.GetViewport();
998 int initialWidth = initialViewport.width;
999 int initialHeight = initialViewport.height;
1000 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
1001 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
1003 auto defaultScene = application.GetScene();
1004 DALI_TEST_CHECK( defaultScene );
1006 // Ensure stage size matches the scene size
1007 auto stage = Stage::GetCurrent();
1008 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
1011 Vector2 newSize( 1000.0f, 2000.0f );
1012 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
1013 DALI_TEST_CHECK( stage.GetSize() != newSize );
1014 defaultScene.SurfaceResized( newSize.width, newSize.height );
1016 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1017 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1019 // Render after resizing surface
1020 application.SendNotification();
1021 application.Render(0);
1023 // Check that the viewport is handled properly
1024 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1026 // Second render-task should not be affected
1027 Rect<int32_t> viewport = newTask.GetViewport();
1028 int width = viewport.width;
1029 int height = viewport.height;
1030 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1031 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1036 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1038 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1040 TestApplication application;
1041 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1043 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1045 // Ensure stage size does NOT match the surface size
1046 auto stage = Stage::GetCurrent();
1047 const auto stageSize = stage.GetSize();
1048 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1049 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1051 // Resize the surface and inform the scene accordingly
1052 Vector2 newSize( 1000.0f, 2000.0f );
1053 DALI_TEST_CHECK( stage.GetSize() != newSize );
1054 scene.SurfaceResized( newSize.width, newSize.height );
1056 // Ensure the stage hasn't been resized
1057 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1058 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1063 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1065 TestApplication application;
1066 Dali::Integration::Scene scene = application.GetScene();
1068 KeyEventGeneratedSignalData data;
1069 KeyEventGeneratedReceivedFunctor functor( data );
1070 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1072 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1073 application.ProcessEvent( event );
1075 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1076 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1077 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1078 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1079 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1083 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1084 application.ProcessEvent( event2 );
1086 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1087 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1088 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1089 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1090 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1094 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1095 application.ProcessEvent( event3 );
1097 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1098 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1099 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1100 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1101 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1105 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1106 application.ProcessEvent( event4 );
1108 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1109 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1110 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1111 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1112 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1116 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1118 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1120 TestApplication application;
1122 // Create a new scene and set the background color of the main scene
1123 auto defaultScene = application.GetScene();
1124 defaultScene.SetBackgroundColor( Color::BLUE );
1126 // Need to create a renderable as we don't start rendering until we have at least one
1127 // We don't need to add this to any scene
1128 auto actor = CreateRenderableActor();
1130 auto& glAbstraction = application.GetGlAbstraction();
1131 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1133 application.SendNotification();
1134 application.Render();
1136 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1137 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1139 defaultScene.SurfaceReplaced();
1141 application.SendNotification();
1142 application.Render();
1144 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1145 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1147 // Check when the main render task viewport is set the clear color is clipped using scissors
1148 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1149 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1150 scissorTrace.Enable( true );
1151 enabledDisableTrace.Enable( true );
1153 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1155 application.SendNotification();
1156 application.Render();
1158 // Check scissor test was enabled.
1159 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1161 // Check the scissor was set, and the coordinates are correct.
1162 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1164 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1165 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1167 scissorTrace.Enable( false );
1168 scissorTrace.Reset();
1170 enabledDisableTrace.Enable( false );
1171 enabledDisableTrace.Reset();
1176 int UtcDaliSceneEmptySceneRendering(void)
1178 tet_infoline( "Ensure not rendering before a Renderer is added" );
1180 TestApplication application;
1181 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1183 // Render without any renderer
1184 application.SendNotification();
1185 application.Render();
1187 // Check the clear count and the render status
1188 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1189 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1192 Geometry geometry = CreateQuadGeometry();
1193 Shader shader = CreateShader();
1194 Renderer renderer = Renderer::New( geometry, shader );
1196 Actor actor = Actor::New();
1197 actor.AddRenderer( renderer );
1199 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1200 application.GetScene().Add( actor );
1203 application.SendNotification();
1204 application.Render();
1206 // Check the clear count and the render status
1207 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1208 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1210 // Remove the Renderer
1211 application.GetScene().Remove( actor );
1216 application.SendNotification();
1217 application.Render();
1219 // Check the clear count and the render status
1220 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1221 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1226 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1228 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1230 TestApplication application;
1233 Geometry geometry = CreateQuadGeometry();
1234 Shader shader = CreateShader();
1235 Renderer renderer = Renderer::New( geometry, shader );
1237 Actor actor = Actor::New();
1238 actor.AddRenderer( renderer );
1239 application.GetScene().Add( actor );
1241 Dali::Integration::Scene scene = application.GetScene();
1244 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1245 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1248 application.SendNotification();
1249 application.Render();
1251 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1252 scene.GetFrameRenderedCallback( callbackContainer );
1254 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1255 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1257 callbackContainer.clear();
1259 scene.GetFramePresentedCallback( callbackContainer );
1261 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1262 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );