2 * Copyright (c) 2019 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>
29 // Internal headers are allowed here
34 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
36 // Functor for EventProcessingFinished signal
37 struct EventProcessingFinishedFunctor
40 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
42 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
43 : mEventProcessingFinished( eventProcessingFinished )
48 mEventProcessingFinished = true;
51 bool& mEventProcessingFinished;
54 // Stores data that is populated in the key-event callback and will be read by the TET cases
55 struct KeyEventSignalData
58 : functorCalled(false)
63 functorCalled = false;
65 receivedKeyEvent.keyModifier = 0;
66 receivedKeyEvent.keyPressedName.clear();
67 receivedKeyEvent.keyPressed.clear();
71 KeyEvent receivedKeyEvent;
74 // Functor that sets the data when called
75 struct KeyEventReceivedFunctor
77 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
79 bool operator()( const KeyEvent& keyEvent )
81 signalData.functorCalled = true;
82 signalData.receivedKeyEvent = keyEvent;
87 KeyEventSignalData& signalData;
90 // Stores data that is populated in the touched signal callback and will be read by the TET cases
91 struct TouchedSignalData
94 : functorCalled(false),
95 createNewScene(false),
96 newSceneCreated(false)
101 functorCalled = false;
102 createNewScene = false;
103 newSceneCreated = false;
105 receivedTouchEvent.points.clear();
106 receivedTouchEvent.time = 0;
108 receivedTouchData.Reset();
113 bool newSceneCreated;
114 TouchEvent receivedTouchEvent;
115 TouchData receivedTouchData;
118 // Functor that sets the data when touched signal is received
119 struct TouchedFunctor
121 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
123 void operator()( const TouchEvent& touch )
125 signalData.functorCalled = true;
126 signalData.receivedTouchEvent = touch;
129 TouchedSignalData& signalData;
132 // Functor that sets the data when touched signal is received
135 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
137 void operator()( const TouchData& touch )
139 signalData.functorCalled = true;
140 signalData.receivedTouchData = touch;
142 if ( signalData.createNewScene )
144 TestRenderSurface* surface = new TestRenderSurface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) ); // This is a leak, but we need to keep the surface alive till the end
145 Dali::Integration::Scene scene = Dali::Integration::Scene::New( *surface );
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 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
194 Integration::TouchEvent touchEvent;
195 Integration::Point point;
196 point.SetState( state );
197 point.SetScreenPosition( screenPosition );
198 touchEvent.points.push_back( point );
199 application.ProcessEvent( touchEvent );
202 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
207 } // unnamed namespace
209 int UtcDaliSceneAdd(void)
211 TestApplication application;
212 tet_infoline("Testing Dali::Integration::Scene::Add");
214 Dali::Integration::Scene scene = application.GetScene();
216 Actor actor = Actor::New();
217 DALI_TEST_CHECK( !actor.OnStage() );
220 DALI_TEST_CHECK( actor.OnStage() );
225 int UtcDaliSceneRemove(void)
227 TestApplication application;
228 tet_infoline("Testing Dali::Integration::Scene::Remove");
230 Dali::Integration::Scene scene = application.GetScene();
232 Actor actor = Actor::New();
233 DALI_TEST_CHECK( !actor.OnStage() );
236 DALI_TEST_CHECK( actor.OnStage() );
239 DALI_TEST_CHECK( !actor.OnStage() );
244 int UtcDaliSceneGetSize(void)
246 TestApplication application;
247 tet_infoline("Testing Dali::Integration::Scene::GetSize");
249 Dali::Integration::Scene scene = application.GetScene();
250 Size size = scene.GetSize();
251 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
252 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
257 int UtcDaliSceneGetDpi(void)
259 TestApplication application; // Initializes core DPI to default values
261 // Test that setting core DPI explicitly also sets up the scene's DPI.
262 Dali::Integration::Scene scene = application.GetScene();
263 scene.SetDpi( Vector2(200.0f, 180.0f) );
264 Vector2 dpi = scene.GetDpi();
265 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
266 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
270 int UtcDaliSceneGetRenderTaskList(void)
272 TestApplication application;
273 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
275 Dali::Integration::Scene scene = application.GetScene();
277 // Check we get a valid instance.
278 const RenderTaskList& tasks = scene.GetRenderTaskList();
280 // There should be 1 task by default.
281 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
283 // RenderTaskList has it's own UTC tests.
284 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
285 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
287 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
292 int UtcDaliSceneGetRootLayer(void)
294 TestApplication application;
295 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
297 Dali::Integration::Scene scene = application.GetScene();
298 Layer layer = scene.GetLayer( 0 );
299 DALI_TEST_CHECK( layer );
301 // Check that GetRootLayer() correctly retreived layer 0.
302 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
307 int UtcDaliSceneGetLayerCount(void)
309 TestApplication application;
310 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
312 Dali::Integration::Scene scene = application.GetScene();
313 // Initially we have a default layer
314 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
316 Layer layer = Layer::New();
319 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
323 int UtcDaliSceneGetLayer(void)
325 TestApplication application;
326 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
328 Dali::Integration::Scene scene = application.GetScene();
330 Layer rootLayer = scene.GetLayer( 0 );
331 DALI_TEST_CHECK( rootLayer );
333 Layer layer = Layer::New();
336 Layer sameLayer = scene.GetLayer( 1 );
337 DALI_TEST_CHECK( layer == sameLayer );
342 int UtcDaliSceneGet(void)
344 TestApplication application;
345 tet_infoline("Testing Dali::Integration::Scene::Get");
347 Dali::Integration::Scene scene = application.GetScene();
349 Actor actor = Actor::New();
350 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
354 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
359 int UtcDaliSceneDiscard(void)
361 TestApplication application;
362 tet_infoline("Testing Dali::Scene::Discard");
364 // Create a new Scene
365 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
366 Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
367 DALI_TEST_CHECK( scene );
369 // One reference of scene kept here and the other one kept in the Core
370 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
372 // Render and notify.
373 application.SendNotification();
374 application.Render(0);
376 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
377 Layer rootLayer = scene.GetRootLayer();
378 DALI_TEST_CHECK( rootLayer );
379 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
381 // Request to discard the scene from the Core
383 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
385 // Reset the scene handle
388 // Render and notify.
389 application.SendNotification();
390 application.Render(0);
392 // At this point, the scene should have been automatically deleted
393 // To prove this, the ref count of the root layer handle should be decremented to 1
394 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
396 // Delete the root layer handle
399 // Render and notify.
400 application.SendNotification();
401 application.Render(0);
406 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
408 TestApplication application;
410 Dali::Integration::Scene scene = application.GetScene();
412 TouchedSignalData data;
413 data.createNewScene = true;
414 TouchFunctor functor( data );
415 scene.TouchSignal().Connect( &application, functor );
417 // Render and notify.
418 application.SendNotification();
419 application.Render();
421 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
423 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
424 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
425 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
431 int UtcDaliSceneRootLayerAndSceneAlignment(void)
433 TestApplication application;
436 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
437 Dali::Integration::Scene scene = Dali::Integration::Scene::New( surface );
438 DALI_TEST_CHECK( scene );
440 // One reference of scene kept here and the other one kept in the Core
441 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
443 // Add a renderable actor to the scene
444 auto actor = CreateRenderableActor();
447 // Render and notify.
448 application.SendNotification();
449 application.Render(0);
451 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
452 Layer rootLayer = scene.GetRootLayer();
453 DALI_TEST_CHECK( rootLayer );
454 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
456 // Request to discard the scene from the Core
458 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
460 // Reset the scene handle
463 // Render and notify.
464 application.SendNotification();
465 application.Render(0);
467 // At this point, the scene should have been automatically deleted
468 // To prove this, the ref count of the root layer handle should be decremented to 1
469 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
471 // Create a new Scene while the root layer of the deleted scene is still alive
472 TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
473 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( surface2 );
474 DALI_TEST_CHECK( newScene );
476 // Render and notify.
477 application.SendNotification();
478 application.Render(0);
480 // At this point, we have only one scene but two root layers
481 // The root layer of the deleted scene is still alive
482 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
484 // Delete the root layer of the deleted scene
487 // Render and notify.
488 application.SendNotification();
489 application.Render(0);
494 int UtcDaliSceneDeleteSurface(void)
496 TestApplication application;
498 // Create the render surface for the scene
499 TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
502 Dali::Integration::Scene scene = Dali::Integration::Scene::New( *renderSurface );
503 DALI_TEST_CHECK( scene );
505 // Render and notify.
506 application.SendNotification();
507 application.Render(0);
509 // Add a renderable actor to the scene
510 auto actor = CreateRenderableActor();
513 // Render and notify.
514 application.SendNotification();
515 application.Render(0);
517 // Notify the Core that the render surface will be deleted.
518 application.GetCore().SurfaceDeleted( renderSurface );
520 // Delete the render surface
521 delete renderSurface;
522 renderSurface = nullptr;
524 // Render and notify.
525 application.SendNotification();
526 application.Render(0);
531 int UtcDaliSceneEventProcessingFinishedP(void)
533 TestApplication application;
534 Dali::Integration::Scene scene = application.GetScene();
536 bool eventProcessingFinished = false;
537 EventProcessingFinishedFunctor functor( eventProcessingFinished );
538 scene.EventProcessingFinishedSignal().Connect( &application, functor );
540 Actor actor( Actor::New() );
543 application.SendNotification();
544 application.Render();
546 DALI_TEST_CHECK( eventProcessingFinished );
551 int UtcDaliSceneEventProcessingFinishedN(void)
553 TestApplication application;
554 Dali::Integration::Scene scene = application.GetScene();
556 bool eventProcessingFinished = false;
557 EventProcessingFinishedFunctor functor( eventProcessingFinished );
558 scene.EventProcessingFinishedSignal().Connect( &application, functor );
560 Actor actor( Actor::New() );
563 // Do not complete event processing and confirm the signal has not been emitted.
564 DALI_TEST_CHECK( !eventProcessingFinished );
569 int UtcDaliSceneSignalKeyEventP(void)
571 TestApplication application;
572 Dali::Integration::Scene scene = application.GetScene();
574 KeyEventSignalData data;
575 KeyEventReceivedFunctor functor( data );
576 scene.KeyEventSignal().Connect( &application, functor );
578 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
579 application.ProcessEvent( event );
581 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
582 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
583 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
584 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
585 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
589 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
590 application.ProcessEvent( event2 );
592 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
593 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
594 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
595 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
596 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
600 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
601 application.ProcessEvent( event3 );
603 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
604 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
605 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
606 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
607 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
611 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
612 application.ProcessEvent( event4 );
614 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
615 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
616 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
617 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
618 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
622 int UtcDaliSceneSignalKeyEventN(void)
624 TestApplication application;
625 Dali::Integration::Scene scene = application.GetScene();
627 KeyEventSignalData data;
628 KeyEventReceivedFunctor functor( data );
629 scene.KeyEventSignal().Connect( &application, functor );
631 // Check that a non-pressed key events data is not modified.
632 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
637 int UtcDaliSceneTouchSignalP(void)
639 TestApplication application;
640 Dali::Integration::Scene scene = application.GetScene();
642 TouchedSignalData data;
643 TouchFunctor functor( data );
644 scene.TouchSignal().Connect( &application, functor );
646 // Render and notify.
647 application.SendNotification();
648 application.Render();
650 // Basic test: No actors, single touch (down then up).
652 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
654 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
655 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
656 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
659 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
661 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
662 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
663 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
667 // Add an actor to the scene.
668 Actor actor = Actor::New();
669 actor.SetSize( 100.0f, 100.0f );
670 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
671 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
672 actor.TouchedSignal().Connect( &DummyTouchCallback );
675 // Render and notify.
676 application.SendNotification();
677 application.Render();
679 // Actor on scene, single touch, down in actor, motion, then up outside actor.
681 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
683 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
684 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
685 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
688 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
690 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
693 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
695 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
696 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
697 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
701 // Multiple touch. Should only receive a touch on first down and last up.
703 Integration::TouchEvent touchEvent;
704 Integration::Point point;
707 point.SetState( PointState::DOWN );
708 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
709 touchEvent.points.push_back( point );
710 application.ProcessEvent( touchEvent );
711 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
712 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
716 touchEvent.points[0].SetState( PointState::STATIONARY );
717 point.SetDeviceId( 1 );
718 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
719 touchEvent.points.push_back( point );
720 application.ProcessEvent( touchEvent );
721 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
724 // Primary point is up
725 touchEvent.points[0].SetState( PointState::UP );
726 touchEvent.points[1].SetState( PointState::STATIONARY );
727 application.ProcessEvent( touchEvent );
728 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
731 // Remove 1st point now, 2nd point is now in motion
732 touchEvent.points.erase( touchEvent.points.begin() );
733 touchEvent.points[0].SetState( PointState::MOTION );
734 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
735 application.ProcessEvent( touchEvent );
736 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
740 touchEvent.points[0].SetState( PointState::UP );
741 application.ProcessEvent( touchEvent );
742 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
743 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
749 int UtcDaliSceneTouchSignalN(void)
751 TestApplication application;
752 Dali::Integration::Scene scene = application.GetScene();
754 TouchedSignalData data;
755 TouchFunctor functor( data );
756 scene.TouchSignal().Connect( &application, functor );
758 // Render and notify.
759 application.SendNotification();
760 application.Render();
762 // Confirm functor not called before there has been any touch event.
763 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
765 // No actors, single touch, down, motion then up.
767 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
769 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
770 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
771 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
775 // Confirm there is no signal when the touchpoint is only moved.
776 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
778 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
781 // Confirm a following up event generates a signal.
782 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
784 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
785 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
786 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
790 // Add an actor to the scene.
791 Actor actor = Actor::New();
792 actor.SetSize( 100.0f, 100.0f );
793 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
794 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
795 actor.TouchedSignal().Connect( &DummyTouchCallback );
798 // Render and notify.
799 application.SendNotification();
800 application.Render();
802 // Actor on scene. Interrupted before down and interrupted after down.
804 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
806 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
807 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
808 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
809 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
812 GenerateTouch( application, PointState::DOWN, 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) == actor );
817 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
820 GenerateTouch( application, PointState::INTERRUPTED, 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) );
825 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
827 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
829 // Check that getting info about a non-existent point returns an empty handle
830 Actor actor = data.receivedTouchData.GetHitActor( 1 );
831 DALI_TEST_CHECK( !actor );
839 int UtcDaliSceneSignalWheelEventP(void)
841 TestApplication application;
842 Dali::Integration::Scene scene = application.GetScene();
844 WheelEventSignalData data;
845 WheelEventReceivedFunctor functor( data );
846 scene.WheelEventSignal().Connect( &application, functor );
848 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
849 application.ProcessEvent( event );
851 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
852 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
853 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
854 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
855 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
856 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
857 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
861 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
862 application.ProcessEvent( event2 );
864 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
865 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
866 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
867 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
868 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
869 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
870 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
874 int UtcDaliSceneEnsureEmptySceneCleared(void)
876 tet_infoline( "Ensure we clear the newly added window" );
878 TestApplication application;
880 // Create a new scene and set the background colors of both the new and the main scenes
881 auto defaultScene = application.GetScene();
882 defaultScene.SetBackgroundColor( Color::WHITE );
884 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
885 auto newScene = Integration::Scene::New( surface );
886 newScene.SetBackgroundColor( Color::RED );
888 // Need to create a renderable as we don't start rendering until we have at least one
889 // We don't need to add this to any scene
890 auto actor = CreateRenderableActor();
892 auto& glAbstraction = application.GetGlAbstraction();
893 auto clearCountBefore = glAbstraction.GetClearCountCalled();
895 application.SendNotification();
896 application.Render();
898 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 2, TEST_LOCATION );
900 // Add the actor to the main scene
901 defaultScene.Add( actor );
903 application.SendNotification();
904 application.Render();
906 // Add another scene and set its background color, ensure we clear it to the appropriate color
908 TestRenderSurface surface2( PositionSize( 0.0f, 0.0f, 480.0f, 800.0f ) );
909 auto thirdScene = Integration::Scene::New( surface2 );
910 thirdScene.SetBackgroundColor( Color::BLUE );
912 clearCountBefore = glAbstraction.GetClearCountCalled();
914 application.SendNotification();
915 application.Render();
917 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
922 int UtcDaliSceneSurfaceResizedDefaultScene(void)
924 tet_infoline( "Ensure resizing of the surface is handled properly" );
926 TestApplication application;
928 auto defaultScene = application.GetScene();
929 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
930 DALI_TEST_CHECK( defaultSurface );
932 // Ensure stage size matches the surface size
933 auto stage = Stage::GetCurrent();
934 DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
936 // Resize the surface and inform the scene accordingly
937 Vector2 newSize( 1000.0f, 2000.0f );
938 DALI_TEST_CHECK( stage.GetSize() != newSize );
939 defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
940 defaultScene.SurfaceResized();
942 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
943 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
948 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
950 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
952 TestApplication application;
953 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
955 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
956 auto scene = Integration::Scene::New( surface );
958 // Ensure stage size does NOT match the surface size
959 auto stage = Stage::GetCurrent();
960 const auto stageSize = stage.GetSize();
961 DALI_TEST_CHECK( stageSize != originalSurfaceSize );
962 DALI_TEST_EQUALS( originalSurfaceSize, scene.GetSize(), TEST_LOCATION );
964 // Resize the surface and inform the scene accordingly
965 Vector2 newSize( 1000.0f, 2000.0f );
966 DALI_TEST_CHECK( stage.GetSize() != newSize );
967 surface.MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
968 scene.SurfaceResized();
970 // Ensure the stage hasn't been resized
971 DALI_TEST_EQUALS( stage.GetSize(), stageSize, TEST_LOCATION );
972 DALI_TEST_EQUALS( scene.GetSize(), newSize, TEST_LOCATION );
977 int UtcDaliSceneSetSurface(void)
979 tet_infoline( "Scene::SetSurface test" );
981 TestApplication application;
983 // Create a scene with a surface and ensure the size and surface is set correctly on the scene
984 Vector2 surfaceSize( 480.0f, 800.0f );
985 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, surfaceSize.width, surfaceSize.height ) );
986 auto scene = Integration::Scene::New( surface );
987 DALI_TEST_EQUALS( scene.GetSize(), surfaceSize, TEST_LOCATION );
988 DALI_TEST_CHECK( scene.GetSurface() == &surface );
990 // Create a new surface and set that on the scene
991 Vector2 newSurfaceSize( 1000.0f, 1000.0f );
992 TestRenderSurface newSurface( PositionSize( 0.0f, 0.0f, newSurfaceSize.width, newSurfaceSize.height ) );
993 scene.SetSurface( newSurface );
994 DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
995 DALI_TEST_CHECK( scene.GetSurface() == &newSurface );
997 // Ensure setting the same surface again doesn't have any side effects
998 scene.SetSurface( newSurface );
999 DALI_TEST_EQUALS( scene.GetSize(), newSurfaceSize, TEST_LOCATION );
1000 DALI_TEST_CHECK( scene.GetSurface() == &newSurface );