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 receivedTouchData.Reset();
111 bool newSceneCreated;
112 TouchData receivedTouchData;
115 // Functor that sets the data when touched signal is received
118 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
120 void operator()( const TouchData& touch )
122 signalData.functorCalled = true;
123 Dali::TouchData touchData (touch);
124 signalData.receivedTouchData = touchData;
126 if ( signalData.createNewScene )
128 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
129 DALI_TEST_CHECK( scene );
131 signalData.newSceneCreated = true;
137 signalData.functorCalled = true;
140 TouchedSignalData& signalData;
143 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
144 struct WheelEventSignalData
146 WheelEventSignalData()
147 : functorCalled(false)
152 functorCalled = false;
156 WheelEvent receivedWheelEvent;
159 // Functor that sets the data when wheel-event signal is received
160 struct WheelEventReceivedFunctor
162 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
164 bool operator()( const WheelEvent& wheelEvent )
166 signalData.functorCalled = true;
167 signalData.receivedWheelEvent = wheelEvent;
172 WheelEventSignalData& signalData;
175 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
176 struct KeyEventGeneratedSignalData
178 KeyEventGeneratedSignalData()
179 : functorCalled(false)
184 functorCalled = false;
186 receivedKeyEvent.keyModifier = 0;
187 receivedKeyEvent.keyPressedName.clear();
188 receivedKeyEvent.keyPressed.clear();
192 KeyEvent receivedKeyEvent;
195 // Functor that sets the data when called
196 struct KeyEventGeneratedReceivedFunctor
198 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
202 bool operator()( const KeyEvent& keyEvent )
204 signalData.functorCalled = true;
205 signalData.receivedKeyEvent = keyEvent;
212 signalData.functorCalled = true;
216 KeyEventGeneratedSignalData& signalData;
219 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
221 Integration::TouchEvent touchEvent;
222 Integration::Point point;
223 point.SetState( state );
224 point.SetScreenPosition( screenPosition );
225 touchEvent.points.push_back( point );
226 application.ProcessEvent( touchEvent );
229 bool DummyTouchCallback( Actor actor, const TouchData& touch )
234 void FrameCallback( int frameId )
238 } // unnamed namespace
240 int UtcDaliSceneAdd(void)
242 TestApplication application;
243 tet_infoline("Testing Dali::Integration::Scene::Add");
245 Dali::Integration::Scene scene = application.GetScene();
247 Actor actor = Actor::New();
248 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
251 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
256 int UtcDaliSceneRemove(void)
258 TestApplication application;
259 tet_infoline("Testing Dali::Integration::Scene::Remove");
261 Dali::Integration::Scene scene = application.GetScene();
263 Actor actor = Actor::New();
264 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
267 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
270 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
275 int UtcDaliSceneGetSize(void)
277 TestApplication application;
278 tet_infoline("Testing Dali::Integration::Scene::GetSize");
280 Dali::Integration::Scene scene = application.GetScene();
281 Size size = scene.GetSize();
282 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
283 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
288 int UtcDaliSceneGetDpi(void)
290 TestApplication application; // Initializes core DPI to default values
292 // Test that setting core DPI explicitly also sets up the scene's DPI.
293 Dali::Integration::Scene scene = application.GetScene();
294 scene.SetDpi( Vector2(200.0f, 180.0f) );
295 Vector2 dpi = scene.GetDpi();
296 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
297 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
301 int UtcDaliSceneGetRenderTaskList(void)
303 TestApplication application;
304 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
306 Dali::Integration::Scene scene = application.GetScene();
308 // Check we get a valid instance.
309 const RenderTaskList& tasks = scene.GetRenderTaskList();
311 // There should be 1 task by default.
312 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
314 // RenderTaskList has it's own UTC tests.
315 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
316 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
318 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
323 int UtcDaliSceneGetRootLayer(void)
325 TestApplication application;
326 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
328 Dali::Integration::Scene scene = application.GetScene();
329 Layer layer = scene.GetLayer( 0 );
330 DALI_TEST_CHECK( layer );
332 // Check that GetRootLayer() correctly retreived layer 0.
333 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
338 int UtcDaliSceneGetLayerCount(void)
340 TestApplication application;
341 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
343 Dali::Integration::Scene scene = application.GetScene();
344 // Initially we have a default layer
345 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
347 Layer layer = Layer::New();
350 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
354 int UtcDaliSceneGetLayer(void)
356 TestApplication application;
357 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
359 Dali::Integration::Scene scene = application.GetScene();
361 Layer rootLayer = scene.GetLayer( 0 );
362 DALI_TEST_CHECK( rootLayer );
364 Layer layer = Layer::New();
367 Layer sameLayer = scene.GetLayer( 1 );
368 DALI_TEST_CHECK( layer == sameLayer );
373 int UtcDaliSceneGet(void)
375 TestApplication application;
376 tet_infoline("Testing Dali::Integration::Scene::Get");
378 Dali::Integration::Scene scene = application.GetScene();
380 Actor actor = Actor::New();
381 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
385 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
390 int UtcDaliSceneDiscard(void)
392 TestApplication application;
393 tet_infoline("Testing Dali::Scene::Discard");
395 // Create a new Scene
396 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
397 DALI_TEST_CHECK( scene );
399 // One reference of scene kept here and the other one kept in the Core
400 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
402 // Render and notify.
403 application.SendNotification();
404 application.Render(0);
406 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
407 Layer rootLayer = scene.GetRootLayer();
408 DALI_TEST_CHECK( rootLayer );
409 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
411 // Request to discard the scene from the Core
413 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
415 // Reset the scene handle
418 // Render and notify.
419 application.SendNotification();
420 application.Render(0);
422 // At this point, the scene should have been automatically deleted
423 // To prove this, the ref count of the root layer handle should be decremented to 1
424 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
426 // Delete the root layer handle
429 // Render and notify.
430 application.SendNotification();
431 application.Render(0);
436 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
438 TestApplication application;
440 Dali::Integration::Scene scene = application.GetScene();
442 TouchedSignalData data;
443 data.createNewScene = true;
444 TouchFunctor functor( data );
445 scene.TouchSignal().Connect( &application, functor );
447 // Render and notify.
448 application.SendNotification();
449 application.Render();
451 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
453 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
454 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
455 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
461 int UtcDaliSceneRootLayerAndSceneAlignment(void)
463 TestApplication application;
466 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
467 DALI_TEST_CHECK( scene );
469 // One reference of scene kept here and the other one kept in the Core
470 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
472 // Add a renderable actor to the scene
473 auto actor = CreateRenderableActor();
476 // Render and notify.
477 application.SendNotification();
478 application.Render(0);
480 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
481 Layer rootLayer = scene.GetRootLayer();
482 DALI_TEST_CHECK( rootLayer );
483 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
485 // Request to discard the scene from the Core
487 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
489 // Reset the scene handle
492 // Render and notify.
493 application.SendNotification();
494 application.Render(0);
496 // At this point, the scene should have been automatically deleted
497 // To prove this, the ref count of the root layer handle should be decremented to 1
498 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
500 // Create a new Scene while the root layer of the deleted scene is still alive
501 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
502 DALI_TEST_CHECK( newScene );
504 // Render and notify.
505 application.SendNotification();
506 application.Render(0);
508 // At this point, we have only one scene but two root layers
509 // The root layer of the deleted scene is still alive
510 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
512 // Delete the root layer of the deleted scene
515 // Render and notify.
516 application.SendNotification();
517 application.Render(0);
522 int UtcDaliSceneEventProcessingFinishedP(void)
524 TestApplication application;
525 Dali::Integration::Scene scene = application.GetScene();
527 bool eventProcessingFinished = false;
528 EventProcessingFinishedFunctor functor( eventProcessingFinished );
529 scene.EventProcessingFinishedSignal().Connect( &application, functor );
531 Actor actor( Actor::New() );
534 application.SendNotification();
535 application.Render();
537 DALI_TEST_CHECK( eventProcessingFinished );
542 int UtcDaliSceneEventProcessingFinishedN(void)
544 TestApplication application;
545 Dali::Integration::Scene scene = application.GetScene();
547 bool eventProcessingFinished = false;
548 EventProcessingFinishedFunctor functor( eventProcessingFinished );
549 scene.EventProcessingFinishedSignal().Connect( &application, functor );
551 Actor actor( Actor::New() );
554 // Do not complete event processing and confirm the signal has not been emitted.
555 DALI_TEST_CHECK( !eventProcessingFinished );
560 int UtcDaliSceneSignalKeyEventP(void)
562 TestApplication application;
563 Dali::Integration::Scene scene = application.GetScene();
565 KeyEventSignalData data;
566 KeyEventReceivedFunctor functor( data );
567 scene.KeyEventSignal().Connect( &application, functor );
569 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
570 application.ProcessEvent( event );
572 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
573 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
574 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
575 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
576 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
580 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
581 application.ProcessEvent( event2 );
583 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
584 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
585 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
586 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
587 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
591 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
592 application.ProcessEvent( event3 );
594 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
595 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
596 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
597 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
598 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
602 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
603 application.ProcessEvent( event4 );
605 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
606 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
607 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
608 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
609 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
613 int UtcDaliSceneSignalKeyEventN(void)
615 TestApplication application;
616 Dali::Integration::Scene scene = application.GetScene();
618 KeyEventSignalData data;
619 KeyEventReceivedFunctor functor( data );
620 scene.KeyEventSignal().Connect( &application, functor );
622 // Check that a non-pressed key events data is not modified.
623 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
628 int UtcDaliSceneTouchSignalP(void)
630 TestApplication application;
631 Dali::Integration::Scene scene = application.GetScene();
633 TouchedSignalData data;
634 TouchFunctor functor( data );
635 scene.TouchSignal().Connect( &application, functor );
637 // Render and notify.
638 application.SendNotification();
639 application.Render();
641 // Basic test: No actors, single touch (down then up).
643 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
645 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
646 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
647 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
650 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
652 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
653 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
654 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
658 // Add an actor to the scene.
659 Actor actor = Actor::New();
660 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
661 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
662 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
663 actor.TouchSignal().Connect( &DummyTouchCallback );
666 // Render and notify.
667 application.SendNotification();
668 application.Render();
670 // Actor on scene, single touch, down in actor, motion, then up outside actor.
672 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
674 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
675 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
676 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
679 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
681 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
684 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
686 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
687 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
688 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
692 // Multiple touch. Should only receive a touch on first down and last up.
694 Integration::TouchEvent touchEvent;
695 Integration::Point point;
698 point.SetState( PointState::DOWN );
699 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
700 touchEvent.points.push_back( point );
701 application.ProcessEvent( touchEvent );
702 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
703 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
707 touchEvent.points[0].SetState( PointState::STATIONARY );
708 point.SetDeviceId( 1 );
709 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
710 touchEvent.points.push_back( point );
711 application.ProcessEvent( touchEvent );
712 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
715 // Primary point is up
716 touchEvent.points[0].SetState( PointState::UP );
717 touchEvent.points[1].SetState( PointState::STATIONARY );
718 application.ProcessEvent( touchEvent );
719 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
722 // Remove 1st point now, 2nd point is now in motion
723 touchEvent.points.erase( touchEvent.points.begin() );
724 touchEvent.points[0].SetState( PointState::MOTION );
725 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
726 application.ProcessEvent( touchEvent );
727 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
731 touchEvent.points[0].SetState( PointState::UP );
732 application.ProcessEvent( touchEvent );
733 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
734 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
740 int UtcDaliSceneTouchSignalN(void)
742 TestApplication application;
743 Dali::Integration::Scene scene = application.GetScene();
745 TouchedSignalData data;
746 TouchFunctor functor( data );
747 scene.TouchSignal().Connect( &application, functor );
749 // Render and notify.
750 application.SendNotification();
751 application.Render();
753 // Confirm functor not called before there has been any touch event.
754 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
756 // No actors, single touch, down, motion then up.
758 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
760 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
761 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
762 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
766 // Confirm there is no signal when the touchpoint is only moved.
767 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
769 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
772 // Confirm a following up event generates a signal.
773 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
775 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
776 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
777 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
781 // Add an actor to the scene.
782 Actor actor = Actor::New();
783 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
784 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
785 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
786 actor.TouchSignal().Connect( &DummyTouchCallback );
789 // Render and notify.
790 application.SendNotification();
791 application.Render();
793 // Actor on scene. Interrupted before down and interrupted after down.
795 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
797 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
798 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
799 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
800 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
803 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
805 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
806 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
807 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
808 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
811 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
813 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
814 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
815 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
816 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
818 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
820 // Check that getting info about a non-existent point returns an empty handle
821 Actor actor = data.receivedTouchData.GetHitActor( 1 );
822 DALI_TEST_CHECK( !actor );
830 int UtcDaliSceneSignalWheelEventP(void)
832 TestApplication application;
833 Dali::Integration::Scene scene = application.GetScene();
835 WheelEventSignalData data;
836 WheelEventReceivedFunctor functor( data );
837 scene.WheelEventSignal().Connect( &application, functor );
839 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
840 application.ProcessEvent( event );
842 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
843 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
844 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
845 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
846 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
847 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
848 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
852 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
853 application.ProcessEvent( event2 );
855 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
856 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
857 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
858 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
859 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
860 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
861 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
865 int UtcDaliSceneSurfaceResizedDefaultScene(void)
867 tet_infoline( "Ensure resizing of the surface is handled properly" );
869 TestApplication application;
871 auto defaultScene = application.GetScene();
872 DALI_TEST_CHECK( defaultScene );
874 // Ensure stage size matches the scene size
875 auto stage = Stage::GetCurrent();
876 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
879 Vector2 newSize( 1000.0f, 2000.0f );
880 DALI_TEST_CHECK( stage.GetSize() != newSize );
882 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
884 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
885 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
890 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
892 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
894 TestApplication application;
895 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
896 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
897 glAbstraction.EnableViewportCallTrace( true );
899 // Initial scene setup
900 Geometry geometry = CreateQuadGeometry();
901 Shader shader = CreateShader();
902 Renderer renderer = Renderer::New( geometry, shader );
904 Actor actor = Actor::New();
905 actor.AddRenderer(renderer);
906 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
907 application.GetScene().Add(actor);
909 // Render before resizing surface
910 application.SendNotification();
911 application.Render(0);
912 glAbstraction.ResetViewportCallStack();
914 auto defaultScene = application.GetScene();
915 DALI_TEST_CHECK( defaultScene );
917 // Ensure stage size matches the scene size
918 auto stage = Stage::GetCurrent();
919 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
922 Vector2 newSize( 1000.0f, 2000.0f );
923 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
924 DALI_TEST_CHECK( stage.GetSize() != newSize );
925 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
927 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
928 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
930 // Render after resizing surface
931 application.SendNotification();
932 application.Render(0);
934 // Check that the viewport is handled properly
935 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
940 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
942 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
944 TestApplication application;
945 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
946 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
947 glAbstraction.EnableViewportCallTrace( true );
949 // Initial scene setup
950 auto scene = application.GetScene();
952 Geometry geometry = CreateQuadGeometry();
953 Shader shader = CreateShader();
954 Renderer renderer = Renderer::New( geometry, shader );
956 Actor actor = Actor::New();
957 actor.AddRenderer(renderer);
959 int testHeight = 400;
960 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
963 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
964 application.GetScene().Add( offscreenCameraActor );
966 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
968 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
969 newTask.SetCameraActor( offscreenCameraActor );
970 newTask.SetSourceActor( actor );
971 newTask.SetFrameBuffer( newFrameBuffer );
972 newTask.SetViewportPosition( Vector2(0, 0) );
973 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
975 // Render before resizing surface
976 application.SendNotification();
977 application.Render(0);
978 glAbstraction.ResetViewportCallStack();
980 Rect<int32_t> initialViewport = newTask.GetViewport();
981 int initialWidth = initialViewport.width;
982 int initialHeight = initialViewport.height;
983 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
984 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
986 auto defaultScene = application.GetScene();
987 DALI_TEST_CHECK( defaultScene );
989 // Ensure stage size matches the scene size
990 auto stage = Stage::GetCurrent();
991 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
994 Vector2 newSize( 1000.0f, 2000.0f );
995 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
996 DALI_TEST_CHECK( stage.GetSize() != newSize );
997 defaultScene.SurfaceResized( newSize.width, newSize.height, 0, false );
999 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1000 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1002 // Render after resizing surface
1003 application.SendNotification();
1004 application.Render(0);
1006 // Check that the viewport is handled properly
1007 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1009 // Second render-task should not be affected
1010 Rect<int32_t> viewport = newTask.GetViewport();
1011 int width = viewport.width;
1012 int height = viewport.height;
1013 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1014 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1019 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1021 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1023 TestApplication application;
1024 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1026 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1028 // Ensure stage size does NOT match the surface size
1029 auto stage = Stage::GetCurrent();
1030 const auto stageSize = stage.GetSize();
1031 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1032 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1034 // Resize the surface and inform the scene accordingly
1035 Vector2 newSize( 1000.0f, 2000.0f );
1036 DALI_TEST_CHECK( stage.GetSize() != newSize );
1038 scene.SurfaceResized( newSize.width, newSize.height, 0, false );
1040 // Ensure the stage hasn't been resized
1041 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1042 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1047 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1049 TestApplication application;
1050 Dali::Integration::Scene scene = application.GetScene();
1052 KeyEventGeneratedSignalData data;
1053 KeyEventGeneratedReceivedFunctor functor( data );
1054 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1056 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1057 application.ProcessEvent( event );
1059 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1060 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1061 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1062 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1063 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1067 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1068 application.ProcessEvent( event2 );
1070 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1071 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1072 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1073 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1074 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1078 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1079 application.ProcessEvent( event3 );
1081 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1082 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1083 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1084 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1085 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1089 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1090 application.ProcessEvent( event4 );
1092 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1093 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1094 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1095 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1096 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1100 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1102 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1104 TestApplication application;
1106 // Create a new scene and set the background color of the main scene
1107 auto defaultScene = application.GetScene();
1108 defaultScene.SetBackgroundColor( Color::BLUE );
1110 // Need to create a renderable as we don't start rendering until we have at least one
1111 // We don't need to add this to any scene
1112 auto actor = CreateRenderableActor();
1114 auto& glAbstraction = application.GetGlAbstraction();
1115 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1117 application.SendNotification();
1118 application.Render();
1120 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1121 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1123 defaultScene.SurfaceReplaced();
1125 application.SendNotification();
1126 application.Render();
1128 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1129 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1131 // Check when the main render task viewport is set the clear color is clipped using scissors
1132 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1133 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1134 scissorTrace.Enable( true );
1135 enabledDisableTrace.Enable( true );
1137 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1139 application.SendNotification();
1140 application.Render();
1142 // Check scissor test was enabled.
1143 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1145 // Check the scissor was set, and the coordinates are correct.
1146 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1148 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1149 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1151 scissorTrace.Enable( false );
1152 scissorTrace.Reset();
1154 enabledDisableTrace.Enable( false );
1155 enabledDisableTrace.Reset();
1160 int UtcDaliSceneEmptySceneRendering(void)
1162 tet_infoline( "Ensure not rendering before a Renderer is added" );
1164 TestApplication application;
1165 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1167 // Render without any renderer
1168 application.SendNotification();
1169 application.Render();
1171 // Check the clear count and the render status
1172 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1173 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1176 Geometry geometry = CreateQuadGeometry();
1177 Shader shader = CreateShader();
1178 Renderer renderer = Renderer::New( geometry, shader );
1180 Actor actor = Actor::New();
1181 actor.AddRenderer( renderer );
1183 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1184 application.GetScene().Add( actor );
1187 application.SendNotification();
1188 application.Render();
1190 // Check the clear count and the render status
1191 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1192 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1194 // Remove the Renderer
1195 application.GetScene().Remove( actor );
1200 application.SendNotification();
1201 application.Render();
1203 // Check the clear count and the render status
1204 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1205 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1210 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1212 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1214 TestApplication application;
1217 Geometry geometry = CreateQuadGeometry();
1218 Shader shader = CreateShader();
1219 Renderer renderer = Renderer::New( geometry, shader );
1221 Actor actor = Actor::New();
1222 actor.AddRenderer( renderer );
1223 application.GetScene().Add( actor );
1225 Dali::Integration::Scene scene = application.GetScene();
1228 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1229 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1232 application.SendNotification();
1233 application.Render();
1235 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1236 scene.GetFrameRenderedCallback( callbackContainer );
1238 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1239 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1241 callbackContainer.clear();
1243 scene.GetFramePresentedCallback( callbackContainer );
1245 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1246 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );