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 Stage::GetCurrent().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 stage = Stage::GetCurrent();
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 Stage::GetCurrent().Add( offscreenCameraActor );
982 FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE );
984 RenderTask newTask = stage.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 DALI_TEST_EQUALS( stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION );
1009 Vector2 newSize( 1000.0f, 2000.0f );
1010 std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize
1011 DALI_TEST_CHECK( stage.GetSize() != newSize );
1012 defaultScene.SurfaceResized( newSize.width, newSize.height );
1014 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
1015 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
1017 // Render after resizing surface
1018 application.SendNotification();
1019 application.Render(0);
1021 // Check that the viewport is handled properly
1022 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) );
1024 // Second render-task should not be affected
1025 Rect<int32_t> viewport = newTask.GetViewport();
1026 int width = viewport.width;
1027 int height = viewport.height;
1028 DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION );
1029 DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION );
1034 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
1036 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
1038 TestApplication application;
1039 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
1041 auto scene = Integration::Scene::New( Size( originalSurfaceSize.width, originalSurfaceSize.height ) );
1043 // Ensure stage size does NOT match the surface size
1044 auto stage = Stage::GetCurrent();
1045 const auto stageSize = stage.GetSize();
1046 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
1047 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
1049 // Resize the surface and inform the scene accordingly
1050 Vector2 newSize( 1000.0f, 2000.0f );
1051 DALI_TEST_CHECK( stage.GetSize() != newSize );
1052 scene.SurfaceResized( newSize.width, newSize.height );
1054 // Ensure the stage hasn't been resized
1055 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
1056 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
1061 int UtcDaliSceneKeyEventGeneratedSignalP(void)
1063 TestApplication application;
1064 Dali::Integration::Scene scene = application.GetScene();
1066 KeyEventGeneratedSignalData data;
1067 KeyEventGeneratedReceivedFunctor functor( data );
1068 scene.KeyEventGeneratedSignal().Connect( &application, functor );
1070 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1071 application.ProcessEvent( event );
1073 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1074 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
1075 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
1076 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
1077 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1081 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1082 application.ProcessEvent( event2 );
1084 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1085 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
1086 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
1087 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
1088 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1092 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1093 application.ProcessEvent( event3 );
1095 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1096 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
1097 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
1098 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
1099 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1103 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
1104 application.ProcessEvent( event4 );
1106 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1107 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
1108 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
1109 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
1110 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
1114 int UtcDaliSceneEnsureReplacedSurfaceKeepsClearColor(void)
1116 tet_infoline( "Ensure we keep background color when the scene surface is replaced " );
1118 TestApplication application;
1120 // Create a new scene and set the background color of the main scene
1121 auto defaultScene = application.GetScene();
1122 defaultScene.SetBackgroundColor( Color::BLUE );
1124 // Need to create a renderable as we don't start rendering until we have at least one
1125 // We don't need to add this to any scene
1126 auto actor = CreateRenderableActor();
1128 auto& glAbstraction = application.GetGlAbstraction();
1129 auto clearCountBefore = glAbstraction.GetClearCountCalled();
1131 application.SendNotification();
1132 application.Render();
1134 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
1135 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1137 defaultScene.SurfaceReplaced();
1139 application.SendNotification();
1140 application.Render();
1142 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
1143 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1145 // Check when the main render task viewport is set the clear color is clipped using scissors
1146 TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace();
1147 TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace();
1148 scissorTrace.Enable( true );
1149 enabledDisableTrace.Enable( true );
1151 defaultScene.GetRenderTaskList().GetTask( 0 ).SetViewport( Viewport( 0.0f, 0.0f, 100.0f, 100.0f ) );
1153 application.SendNotification();
1154 application.Render();
1156 // Check scissor test was enabled.
1157 DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST)
1159 // Check the scissor was set, and the coordinates are correct.
1160 DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", "0, 700, 100, 100" ) );
1162 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
1163 DALI_TEST_EQUALS( glAbstraction.GetLastClearColor(), Color::BLUE, TEST_LOCATION );
1165 scissorTrace.Enable( false );
1166 scissorTrace.Reset();
1168 enabledDisableTrace.Enable( false );
1169 enabledDisableTrace.Reset();
1174 int UtcDaliSceneEmptySceneRendering(void)
1176 tet_infoline( "Ensure not rendering before a Renderer is added" );
1178 TestApplication application;
1179 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1181 // Render without any renderer
1182 application.SendNotification();
1183 application.Render();
1185 // Check the clear count and the render status
1186 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 0, TEST_LOCATION );
1187 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), false, TEST_LOCATION );
1190 Geometry geometry = CreateQuadGeometry();
1191 Shader shader = CreateShader();
1192 Renderer renderer = Renderer::New( geometry, shader );
1194 Actor actor = Actor::New();
1195 actor.AddRenderer( renderer );
1197 actor.SetProperty( Actor::Property::SIZE, Vector2( 400, 400 ) );
1198 Stage::GetCurrent().Add( actor );
1201 application.SendNotification();
1202 application.Render();
1204 // Check the clear count and the render status
1205 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 1, TEST_LOCATION );
1206 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1208 // Remove the Renderer
1209 Stage::GetCurrent().Remove( actor );
1214 application.SendNotification();
1215 application.Render();
1217 // Check the clear count and the render status
1218 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), 2, TEST_LOCATION ); // Should be cleared
1219 DALI_TEST_EQUALS( application.GetRenderNeedsPostRender(), true, TEST_LOCATION );
1224 int UtcDaliSceneFrameRenderedPresentedCallback(void)
1226 tet_infoline( "UtcDaliSceneFrameRenderedCallback" );
1228 TestApplication application;
1231 Geometry geometry = CreateQuadGeometry();
1232 Shader shader = CreateShader();
1233 Renderer renderer = Renderer::New( geometry, shader );
1235 Actor actor = Actor::New();
1236 actor.AddRenderer( renderer );
1237 Stage::GetCurrent().Add( actor );
1239 Dali::Integration::Scene scene = application.GetScene();
1242 scene.AddFrameRenderedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1243 scene.AddFramePresentedCallback( std::unique_ptr< CallbackBase >( MakeCallback( &FrameCallback ) ), frameId );
1246 application.SendNotification();
1247 application.Render();
1249 Dali::Integration::Scene::FrameCallbackContainer callbackContainer;
1250 scene.GetFrameRenderedCallback( callbackContainer );
1252 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1253 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );
1255 callbackContainer.clear();
1257 scene.GetFramePresentedCallback( callbackContainer );
1259 DALI_TEST_EQUALS( callbackContainer.size(), 1, TEST_LOCATION );
1260 DALI_TEST_EQUALS( callbackContainer[0].second, frameId, TEST_LOCATION );