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/integration-api/events/touch-event-integ.h>
25 #include <dali/integration-api/events/wheel-event-integ.h>
27 #include <dali-test-suite-utils.h>
28 #include <mesh-builder.h>
30 // Internal headers are allowed here
35 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
37 // Functor for EventProcessingFinished signal
38 struct EventProcessingFinishedFunctor
41 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
43 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
44 : mEventProcessingFinished( eventProcessingFinished )
49 mEventProcessingFinished = true;
52 bool& mEventProcessingFinished;
55 // Stores data that is populated in the key-event callback and will be read by the TET cases
56 struct KeyEventSignalData
59 : functorCalled(false)
64 functorCalled = false;
66 receivedKeyEvent.keyModifier = 0;
67 receivedKeyEvent.keyPressedName.clear();
68 receivedKeyEvent.keyPressed.clear();
72 KeyEvent receivedKeyEvent;
75 // Functor that sets the data when called
76 struct KeyEventReceivedFunctor
78 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
80 bool operator()( const KeyEvent& keyEvent )
82 signalData.functorCalled = true;
83 signalData.receivedKeyEvent = keyEvent;
88 KeyEventSignalData& signalData;
91 // Stores data that is populated in the touched signal callback and will be read by the TET cases
92 struct TouchedSignalData
95 : functorCalled(false),
96 createNewScene(false),
97 newSceneCreated(false)
102 functorCalled = false;
103 createNewScene = false;
104 newSceneCreated = false;
106 receivedTouchEvent.points.clear();
107 receivedTouchEvent.time = 0;
109 receivedTouchData.Reset();
114 bool newSceneCreated;
115 TouchEvent receivedTouchEvent;
116 TouchData receivedTouchData;
119 // Functor that sets the data when touched signal is received
120 struct TouchedFunctor
122 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
124 void operator()( const TouchEvent& touch )
126 signalData.functorCalled = true;
127 signalData.receivedTouchEvent = touch;
130 TouchedSignalData& signalData;
133 // Functor that sets the data when touched signal is received
136 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
138 void operator()( const TouchData& touch )
140 signalData.functorCalled = true;
141 signalData.receivedTouchData = touch;
143 if ( signalData.createNewScene )
145 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
146 DALI_TEST_CHECK( scene );
148 signalData.newSceneCreated = true;
154 signalData.functorCalled = true;
157 TouchedSignalData& signalData;
160 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
161 struct WheelEventSignalData
163 WheelEventSignalData()
164 : functorCalled(false)
169 functorCalled = false;
173 WheelEvent receivedWheelEvent;
176 // Functor that sets the data when wheel-event signal is received
177 struct WheelEventReceivedFunctor
179 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
181 bool operator()( const WheelEvent& wheelEvent )
183 signalData.functorCalled = true;
184 signalData.receivedWheelEvent = wheelEvent;
189 WheelEventSignalData& signalData;
192 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
193 struct KeyEventGeneratedSignalData
195 KeyEventGeneratedSignalData()
196 : functorCalled(false)
201 functorCalled = false;
203 receivedKeyEvent.keyModifier = 0;
204 receivedKeyEvent.keyPressedName.clear();
205 receivedKeyEvent.keyPressed.clear();
209 KeyEvent receivedKeyEvent;
212 // Functor that sets the data when called
213 struct KeyEventGeneratedReceivedFunctor
215 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
219 bool operator()( const KeyEvent& keyEvent )
221 signalData.functorCalled = true;
222 signalData.receivedKeyEvent = keyEvent;
229 signalData.functorCalled = true;
233 KeyEventGeneratedSignalData& signalData;
236 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
238 Integration::TouchEvent touchEvent;
239 Integration::Point point;
240 point.SetState( state );
241 point.SetScreenPosition( screenPosition );
242 touchEvent.points.push_back( point );
243 application.ProcessEvent( touchEvent );
246 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
251 void FrameCallback( int frameId )
255 } // unnamed namespace
257 int UtcDaliSceneAdd(void)
259 TestApplication application;
260 tet_infoline("Testing Dali::Integration::Scene::Add");
262 Dali::Integration::Scene scene = application.GetScene();
264 Actor actor = Actor::New();
265 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
268 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
273 int UtcDaliSceneRemove(void)
275 TestApplication application;
276 tet_infoline("Testing Dali::Integration::Scene::Remove");
278 Dali::Integration::Scene scene = application.GetScene();
280 Actor actor = Actor::New();
281 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
284 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
287 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
292 int UtcDaliSceneGetSize(void)
294 TestApplication application;
295 tet_infoline("Testing Dali::Integration::Scene::GetSize");
297 Dali::Integration::Scene scene = application.GetScene();
298 Size size = scene.GetSize();
299 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
300 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
305 int UtcDaliSceneGetDpi(void)
307 TestApplication application; // Initializes core DPI to default values
309 // Test that setting core DPI explicitly also sets up the scene's DPI.
310 Dali::Integration::Scene scene = application.GetScene();
311 scene.SetDpi( Vector2(200.0f, 180.0f) );
312 Vector2 dpi = scene.GetDpi();
313 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
314 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
318 int UtcDaliSceneGetRenderTaskList(void)
320 TestApplication application;
321 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
323 Dali::Integration::Scene scene = application.GetScene();
325 // Check we get a valid instance.
326 const RenderTaskList& tasks = scene.GetRenderTaskList();
328 // There should be 1 task by default.
329 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
331 // RenderTaskList has it's own UTC tests.
332 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
333 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
335 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
340 int UtcDaliSceneGetRootLayer(void)
342 TestApplication application;
343 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
345 Dali::Integration::Scene scene = application.GetScene();
346 Layer layer = scene.GetLayer( 0 );
347 DALI_TEST_CHECK( layer );
349 // Check that GetRootLayer() correctly retreived layer 0.
350 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
355 int UtcDaliSceneGetLayerCount(void)
357 TestApplication application;
358 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
360 Dali::Integration::Scene scene = application.GetScene();
361 // Initially we have a default layer
362 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
364 Layer layer = Layer::New();
367 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
371 int UtcDaliSceneGetLayer(void)
373 TestApplication application;
374 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
376 Dali::Integration::Scene scene = application.GetScene();
378 Layer rootLayer = scene.GetLayer( 0 );
379 DALI_TEST_CHECK( rootLayer );
381 Layer layer = Layer::New();
384 Layer sameLayer = scene.GetLayer( 1 );
385 DALI_TEST_CHECK( layer == sameLayer );
390 int UtcDaliSceneGet(void)
392 TestApplication application;
393 tet_infoline("Testing Dali::Integration::Scene::Get");
395 Dali::Integration::Scene scene = application.GetScene();
397 Actor actor = Actor::New();
398 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
402 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
407 int UtcDaliSceneDiscard(void)
409 TestApplication application;
410 tet_infoline("Testing Dali::Scene::Discard");
412 // Create a new Scene
413 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
414 DALI_TEST_CHECK( scene );
416 // One reference of scene kept here and the other one kept in the Core
417 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
419 // Render and notify.
420 application.SendNotification();
421 application.Render(0);
423 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
424 Layer rootLayer = scene.GetRootLayer();
425 DALI_TEST_CHECK( rootLayer );
426 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
428 // Request to discard the scene from the Core
430 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
432 // Reset the scene handle
435 // Render and notify.
436 application.SendNotification();
437 application.Render(0);
439 // At this point, the scene should have been automatically deleted
440 // To prove this, the ref count of the root layer handle should be decremented to 1
441 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
443 // Delete the root layer handle
446 // Render and notify.
447 application.SendNotification();
448 application.Render(0);
453 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
455 TestApplication application;
457 Dali::Integration::Scene scene = application.GetScene();
459 TouchedSignalData data;
460 data.createNewScene = true;
461 TouchFunctor functor( data );
462 scene.TouchSignal().Connect( &application, functor );
464 // Render and notify.
465 application.SendNotification();
466 application.Render();
468 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
470 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
471 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
472 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
478 int UtcDaliSceneRootLayerAndSceneAlignment(void)
480 TestApplication application;
483 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
484 DALI_TEST_CHECK( scene );
486 // One reference of scene kept here and the other one kept in the Core
487 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
489 // Add a renderable actor to the scene
490 auto actor = CreateRenderableActor();
493 // Render and notify.
494 application.SendNotification();
495 application.Render(0);
497 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
498 Layer rootLayer = scene.GetRootLayer();
499 DALI_TEST_CHECK( rootLayer );
500 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
502 // Request to discard the scene from the Core
504 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
506 // Reset the scene handle
509 // Render and notify.
510 application.SendNotification();
511 application.Render(0);
513 // At this point, the scene should have been automatically deleted
514 // To prove this, the ref count of the root layer handle should be decremented to 1
515 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
517 // Create a new Scene while the root layer of the deleted scene is still alive
518 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Size( 480.0f, 800.0f ) );
519 DALI_TEST_CHECK( newScene );
521 // Render and notify.
522 application.SendNotification();
523 application.Render(0);
525 // At this point, we have only one scene but two root layers
526 // The root layer of the deleted scene is still alive
527 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
529 // Delete the root layer of the deleted scene
532 // Render and notify.
533 application.SendNotification();
534 application.Render(0);
539 int UtcDaliSceneEventProcessingFinishedP(void)
541 TestApplication application;
542 Dali::Integration::Scene scene = application.GetScene();
544 bool eventProcessingFinished = false;
545 EventProcessingFinishedFunctor functor( eventProcessingFinished );
546 scene.EventProcessingFinishedSignal().Connect( &application, functor );
548 Actor actor( Actor::New() );
551 application.SendNotification();
552 application.Render();
554 DALI_TEST_CHECK( eventProcessingFinished );
559 int UtcDaliSceneEventProcessingFinishedN(void)
561 TestApplication application;
562 Dali::Integration::Scene scene = application.GetScene();
564 bool eventProcessingFinished = false;
565 EventProcessingFinishedFunctor functor( eventProcessingFinished );
566 scene.EventProcessingFinishedSignal().Connect( &application, functor );
568 Actor actor( Actor::New() );
571 // Do not complete event processing and confirm the signal has not been emitted.
572 DALI_TEST_CHECK( !eventProcessingFinished );
577 int UtcDaliSceneSignalKeyEventP(void)
579 TestApplication application;
580 Dali::Integration::Scene scene = application.GetScene();
582 KeyEventSignalData data;
583 KeyEventReceivedFunctor functor( data );
584 scene.KeyEventSignal().Connect( &application, functor );
586 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
587 application.ProcessEvent( event );
589 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
590 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
591 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
592 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
593 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
597 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
598 application.ProcessEvent( event2 );
600 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
601 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
602 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
603 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
604 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
608 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
609 application.ProcessEvent( event3 );
611 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
612 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
613 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
614 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
615 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
619 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
620 application.ProcessEvent( event4 );
622 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
623 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
624 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
625 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
626 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
630 int UtcDaliSceneSignalKeyEventN(void)
632 TestApplication application;
633 Dali::Integration::Scene scene = application.GetScene();
635 KeyEventSignalData data;
636 KeyEventReceivedFunctor functor( data );
637 scene.KeyEventSignal().Connect( &application, functor );
639 // Check that a non-pressed key events data is not modified.
640 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
645 int UtcDaliSceneTouchSignalP(void)
647 TestApplication application;
648 Dali::Integration::Scene scene = application.GetScene();
650 TouchedSignalData data;
651 TouchFunctor functor( data );
652 scene.TouchSignal().Connect( &application, functor );
654 // Render and notify.
655 application.SendNotification();
656 application.Render();
658 // Basic test: No actors, single touch (down then up).
660 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
662 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
663 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
664 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
667 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
669 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
670 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
671 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
675 // Add an actor to the scene.
676 Actor actor = Actor::New();
677 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
678 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
679 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
680 actor.TouchedSignal().Connect( &DummyTouchCallback );
683 // Render and notify.
684 application.SendNotification();
685 application.Render();
687 // Actor on scene, single touch, down in actor, motion, then up outside actor.
689 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
691 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
692 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
693 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
696 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
698 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
701 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
703 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
704 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
705 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
709 // Multiple touch. Should only receive a touch on first down and last up.
711 Integration::TouchEvent touchEvent;
712 Integration::Point point;
715 point.SetState( PointState::DOWN );
716 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
717 touchEvent.points.push_back( point );
718 application.ProcessEvent( touchEvent );
719 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
720 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
724 touchEvent.points[0].SetState( PointState::STATIONARY );
725 point.SetDeviceId( 1 );
726 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
727 touchEvent.points.push_back( point );
728 application.ProcessEvent( touchEvent );
729 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
732 // Primary point is up
733 touchEvent.points[0].SetState( PointState::UP );
734 touchEvent.points[1].SetState( PointState::STATIONARY );
735 application.ProcessEvent( touchEvent );
736 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
739 // Remove 1st point now, 2nd point is now in motion
740 touchEvent.points.erase( touchEvent.points.begin() );
741 touchEvent.points[0].SetState( PointState::MOTION );
742 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
743 application.ProcessEvent( touchEvent );
744 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
748 touchEvent.points[0].SetState( PointState::UP );
749 application.ProcessEvent( touchEvent );
750 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
751 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
757 int UtcDaliSceneTouchSignalN(void)
759 TestApplication application;
760 Dali::Integration::Scene scene = application.GetScene();
762 TouchedSignalData data;
763 TouchFunctor functor( data );
764 scene.TouchSignal().Connect( &application, functor );
766 // Render and notify.
767 application.SendNotification();
768 application.Render();
770 // Confirm functor not called before there has been any touch event.
771 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
773 // No actors, single touch, down, motion then up.
775 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
777 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
778 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
779 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
783 // Confirm there is no signal when the touchpoint is only moved.
784 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
786 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
789 // Confirm a following up event generates a signal.
790 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
792 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
793 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
794 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
798 // Add an actor to the scene.
799 Actor actor = Actor::New();
800 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
801 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
802 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
803 actor.TouchedSignal().Connect( &DummyTouchCallback );
806 // Render and notify.
807 application.SendNotification();
808 application.Render();
810 // Actor on scene. Interrupted before down and interrupted after down.
812 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
814 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
815 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
816 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
817 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
820 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
822 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
823 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
824 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
825 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
828 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
830 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
831 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
832 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
833 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
835 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
837 // Check that getting info about a non-existent point returns an empty handle
838 Actor actor = data.receivedTouchData.GetHitActor( 1 );
839 DALI_TEST_CHECK( !actor );
847 int UtcDaliSceneSignalWheelEventP(void)
849 TestApplication application;
850 Dali::Integration::Scene scene = application.GetScene();
852 WheelEventSignalData data;
853 WheelEventReceivedFunctor functor( data );
854 scene.WheelEventSignal().Connect( &application, functor );
856 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
857 application.ProcessEvent( event );
859 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
860 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
861 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
862 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
863 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
864 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
865 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
869 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
870 application.ProcessEvent( event2 );
872 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
873 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
874 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
875 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
876 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
877 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
878 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
882 int UtcDaliSceneSurfaceResizedDefaultScene(void)
884 tet_infoline( "Ensure resizing of the surface is handled properly" );
886 TestApplication application;
888 auto defaultScene = application.GetScene();
889 DALI_TEST_CHECK( defaultScene );
891 // Ensure stage size matches the scene size
892 auto stage = Stage::GetCurrent();
893 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
896 Vector2 newSize( 1000.0f, 2000.0f );
897 DALI_TEST_CHECK( stage.GetSize() != newSize );
898 defaultScene.SurfaceResized( newSize.width, newSize.height );
900 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
901 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
906 int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
908 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
910 TestApplication application;
911 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
912 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
913 glAbstraction.EnableViewportCallTrace( true );
915 // Initial scene setup
916 Geometry geometry = CreateQuadGeometry();
917 Shader shader = CreateShader();
918 Renderer renderer = Renderer::New( geometry, shader );
920 Actor actor = Actor::New();
921 actor.AddRenderer(renderer);
922 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
923 application.GetScene().Add(actor);
925 // Render before resizing surface
926 application.SendNotification();
927 application.Render(0);
928 glAbstraction.ResetViewportCallStack();
930 auto defaultScene = application.GetScene();
931 DALI_TEST_CHECK( defaultScene );
933 // Ensure stage size matches the scene size
934 auto stage = Stage::GetCurrent();
935 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
938 Vector2 newSize( 1000.0f, 2000.0f );
939 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
940 DALI_TEST_CHECK( stage.GetSize() != newSize );
941 defaultScene.SurfaceResized( newSize.width, newSize.height );
943 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
944 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
946 // Render after resizing surface
947 application.SendNotification();
948 application.Render(0);
950 // Check that the viewport is handled properly
951 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
956 int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void)
958 tet_infoline( "Ensure resizing of the surface & viewport is handled properly" );
960 TestApplication application;
961 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
962 TraceCallStack& callStack = glAbstraction.GetViewportTrace();
963 glAbstraction.EnableViewportCallTrace( true );
965 // Initial scene setup
966 auto scene = application.GetScene();
968 Geometry geometry = CreateQuadGeometry();
969 Shader shader = CreateShader();
970 Renderer renderer = Renderer::New( geometry, shader );
972 Actor actor = Actor::New();
973 actor.AddRenderer(renderer);
975 int testHeight = 400;
976 actor.SetProperty( Actor::Property::SIZE, Vector2( testWidth, testHeight) );
979 CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) );
980 application.GetScene().Add( offscreenCameraActor );
982 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
984 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
985 newTask.SetCameraActor( offscreenCameraActor );
986 newTask.SetSourceActor( actor );
987 newTask.SetFrameBuffer( newFrameBuffer );
988 newTask.SetViewportPosition( Vector2(0, 0) );
989 newTask.SetViewportSize( Vector2(testWidth, testHeight) );
991 // Render before resizing surface
992 application.SendNotification();
993 application.Render(0);
994 glAbstraction.ResetViewportCallStack();
996 Rect<int32_t> initialViewport = newTask.GetViewport();
997 int initialWidth = initialViewport.width;
998 int initialHeight = initialViewport.height;
999 DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION );
1000 DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION );
1002 auto defaultScene = application.GetScene();
1003 DALI_TEST_CHECK( defaultScene );
1005 // Ensure stage size matches the scene size
1006 auto stage = Stage::GetCurrent();
1007 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
1010 Vector2 newSize( 1000.0f, 2000.0f );
1011 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
1012 DALI_TEST_CHECK( stage.GetSize() != newSize );
1013 defaultScene.SurfaceResized( newSize.width, newSize.height );
1015 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1016 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1018 // Render after resizing surface
1019 application.SendNotification();
1020 application.Render(0);
1022 // Check that the viewport is handled properly
1023 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1025 // Second render-task should not be affected
1026 Rect<int32_t> viewport = newTask.GetViewport();
1027 int width = viewport.width;
1028 int height = viewport.height;
1029 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1030 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1035 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1037 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1039 TestApplication application;
1040 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1042 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1044 // Ensure stage size does NOT match the surface size
1045 auto stage = Stage::GetCurrent();
1046 const auto stageSize = stage.GetSize();
1047 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1048 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1050 // Resize the surface and inform the scene accordingly
1051 Vector2 newSize( 1000.0f, 2000.0f );
1052 DALI_TEST_CHECK( stage.GetSize() != newSize );
1053 scene.SurfaceResized( newSize.width, newSize.height );
1055 // Ensure the stage hasn't been resized
1056 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1057 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1062 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1064 TestApplication application;
1065 Dali::Integration::Scene scene = application.GetScene();
1067 KeyEventGeneratedSignalData data;
1068 KeyEventGeneratedReceivedFunctor functor( data );
1069 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1071 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1072 application.ProcessEvent( event );
1074 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1075 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1076 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1077 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1078 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1082 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1083 application.ProcessEvent( event2 );
1085 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1086 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1087 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1088 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1089 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1093 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1094 application.ProcessEvent( event3 );
1096 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1097 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1098 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1099 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1100 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1104 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1105 application.ProcessEvent( event4 );
1107 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1108 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1109 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1110 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1111 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1115 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1117 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1119 TestApplication application;
1121 // Create a new scene and set the background color of the main scene
1122 auto defaultScene = application.GetScene();
1123 defaultScene.SetBackgroundColor( Color::BLUE );
1125 // Need to create a renderable as we don't start rendering until we have at least one
1126 // We don't need to add this to any scene
1127 auto actor = CreateRenderableActor();
1129 auto& glAbstraction = application.GetGlAbstraction();
1130 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1132 application.SendNotification();
1133 application.Render();
1135 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1136 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1138 defaultScene.SurfaceReplaced();
1140 application.SendNotification();
1141 application.Render();
1143 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1144 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1146 // Check when the main render task viewport is set the clear color is clipped using scissors
1147 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1148 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1149 scissorTrace.Enable( true );
1150 enabledDisableTrace.Enable( true );
1152 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1154 application.SendNotification();
1155 application.Render();
1157 // Check scissor test was enabled.
1158 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1160 // Check the scissor was set, and the coordinates are correct.
1161 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1163 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1164 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1166 scissorTrace.Enable( false );
1167 scissorTrace.Reset();
1169 enabledDisableTrace.Enable( false );
1170 enabledDisableTrace.Reset();
1175 int UtcDaliSceneEmptySceneRendering(void)
1177 tet_infoline( "Ensure not rendering before a Renderer is added" );
1179 TestApplication application;
1180 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1182 // Render without any renderer
1183 application.SendNotification();
1184 application.Render();
1186 // Check the clear count and the render status
1187 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1188 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1191 Geometry geometry = CreateQuadGeometry();
1192 Shader shader = CreateShader();
1193 Renderer renderer = Renderer::New( geometry, shader );
1195 Actor actor = Actor::New();
1196 actor.AddRenderer( renderer );
1198 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1199 application.GetScene().Add( actor );
1202 application.SendNotification();
1203 application.Render();
1205 // Check the clear count and the render status
1206 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1207 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1209 // Remove the Renderer
1210 application.GetScene().Remove( actor );
1215 application.SendNotification();
1216 application.Render();
1218 // Check the clear count and the render status
1219 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1220 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1225 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1227 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1229 TestApplication application;
1232 Geometry geometry = CreateQuadGeometry();
1233 Shader shader = CreateShader();
1234 Renderer renderer = Renderer::New( geometry, shader );
1236 Actor actor = Actor::New();
1237 actor.AddRenderer( renderer );
1238 application.GetScene().Add( actor );
1240 Dali::Integration::Scene scene = application.GetScene();
1243 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1244 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1247 application.SendNotification();
1248 application.Render();
1250 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1251 scene.GetFrameRenderedCallback( callbackContainer );
1253 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1254 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1256 callbackContainer.clear();
1258 scene.GetFramePresentedCallback( callbackContainer );
1260 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1261 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );