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 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
145 DALI_TEST_CHECK( scene );
147 signalData.newSceneCreated = true;
153 signalData.functorCalled = true;
156 TouchedSignalData& signalData;
159 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
160 struct WheelEventSignalData
162 WheelEventSignalData()
163 : functorCalled(false)
168 functorCalled = false;
172 WheelEvent receivedWheelEvent;
175 // Functor that sets the data when wheel-event signal is received
176 struct WheelEventReceivedFunctor
178 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
180 bool operator()( const WheelEvent& wheelEvent )
182 signalData.functorCalled = true;
183 signalData.receivedWheelEvent = wheelEvent;
188 WheelEventSignalData& signalData;
191 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
193 Integration::TouchEvent touchEvent;
194 Integration::Point point;
195 point.SetState( state );
196 point.SetScreenPosition( screenPosition );
197 touchEvent.points.push_back( point );
198 application.ProcessEvent( touchEvent );
201 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
206 } // unnamed namespace
208 int UtcDaliSceneAdd(void)
210 TestApplication application;
211 tet_infoline("Testing Dali::Integration::Scene::Add");
213 Dali::Integration::Scene scene = application.GetScene();
215 Actor actor = Actor::New();
216 DALI_TEST_CHECK( !actor.OnStage() );
219 DALI_TEST_CHECK( actor.OnStage() );
224 int UtcDaliSceneRemove(void)
226 TestApplication application;
227 tet_infoline("Testing Dali::Integration::Scene::Remove");
229 Dali::Integration::Scene scene = application.GetScene();
231 Actor actor = Actor::New();
232 DALI_TEST_CHECK( !actor.OnStage() );
235 DALI_TEST_CHECK( actor.OnStage() );
238 DALI_TEST_CHECK( !actor.OnStage() );
243 int UtcDaliSceneGetSize(void)
245 TestApplication application;
246 tet_infoline("Testing Dali::Integration::Scene::GetSize");
248 Dali::Integration::Scene scene = application.GetScene();
249 Size size = scene.GetSize();
250 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_WIDTH, size.width, TEST_LOCATION );
251 DALI_TEST_EQUALS( TestApplication::DEFAULT_SURFACE_HEIGHT, size.height, TEST_LOCATION );
256 int UtcDaliSceneGetDpi(void)
258 TestApplication application; // Initializes core DPI to default values
260 // Test that setting core DPI explicitly also sets up the scene's DPI.
261 Dali::Integration::Scene scene = application.GetScene();
262 scene.SetDpi( Vector2(200.0f, 180.0f) );
263 Vector2 dpi = scene.GetDpi();
264 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
265 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
269 int UtcDaliSceneGetRenderTaskList(void)
271 TestApplication application;
272 tet_infoline("Testing Dali::Integration::Scene::GetRenderTaskList");
274 Dali::Integration::Scene scene = application.GetScene();
276 // Check we get a valid instance.
277 const RenderTaskList& tasks = scene.GetRenderTaskList();
279 // There should be 1 task by default.
280 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
282 // RenderTaskList has it's own UTC tests.
283 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
284 RenderTask newTask = scene.GetRenderTaskList().CreateTask();
286 DALI_TEST_EQUALS( scene.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
291 int UtcDaliSceneGetRootLayer(void)
293 TestApplication application;
294 tet_infoline("Testing Dali::Integration::Scene::GetRootLayer");
296 Dali::Integration::Scene scene = application.GetScene();
297 Layer layer = scene.GetLayer( 0 );
298 DALI_TEST_CHECK( layer );
300 // Check that GetRootLayer() correctly retreived layer 0.
301 DALI_TEST_CHECK( scene.GetRootLayer() == layer );
306 int UtcDaliSceneGetLayerCount(void)
308 TestApplication application;
309 tet_infoline("Testing Dali::Integration::Scene::GetLayerCount");
311 Dali::Integration::Scene scene = application.GetScene();
312 // Initially we have a default layer
313 DALI_TEST_EQUALS( scene.GetLayerCount(), 1u, TEST_LOCATION );
315 Layer layer = Layer::New();
318 DALI_TEST_EQUALS( scene.GetLayerCount(), 2u, TEST_LOCATION );
322 int UtcDaliSceneGetLayer(void)
324 TestApplication application;
325 tet_infoline("Testing Dali::Integration::Scene::GetLayer");
327 Dali::Integration::Scene scene = application.GetScene();
329 Layer rootLayer = scene.GetLayer( 0 );
330 DALI_TEST_CHECK( rootLayer );
332 Layer layer = Layer::New();
335 Layer sameLayer = scene.GetLayer( 1 );
336 DALI_TEST_CHECK( layer == sameLayer );
341 int UtcDaliSceneGet(void)
343 TestApplication application;
344 tet_infoline("Testing Dali::Integration::Scene::Get");
346 Dali::Integration::Scene scene = application.GetScene();
348 Actor actor = Actor::New();
349 DALI_TEST_CHECK( Dali::Integration::Scene() == Dali::Integration::Scene::Get( actor ) );
353 DALI_TEST_CHECK( scene == Dali::Integration::Scene::Get( actor ) );
358 int UtcDaliSceneDiscard(void)
360 TestApplication application;
361 tet_infoline("Testing Dali::Scene::Discard");
363 // Create a new Scene
364 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
365 DALI_TEST_CHECK( scene );
367 // One reference of scene kept here and the other one kept in the Core
368 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
370 // Render and notify.
371 application.SendNotification();
372 application.Render(0);
374 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
375 Layer rootLayer = scene.GetRootLayer();
376 DALI_TEST_CHECK( rootLayer );
377 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
379 // Request to discard the scene from the Core
381 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
383 // Reset the scene handle
386 // Render and notify.
387 application.SendNotification();
388 application.Render(0);
390 // At this point, the scene should have been automatically deleted
391 // To prove this, the ref count of the root layer handle should be decremented to 1
392 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
394 // Delete the root layer handle
397 // Render and notify.
398 application.SendNotification();
399 application.Render(0);
404 int UtcDaliSceneCreateNewSceneDuringCoreEventProcessing(void)
406 TestApplication application;
408 Dali::Integration::Scene scene = application.GetScene();
410 TouchedSignalData data;
411 data.createNewScene = true;
412 TouchFunctor functor( data );
413 scene.TouchSignal().Connect( &application, functor );
415 // Render and notify.
416 application.SendNotification();
417 application.Render();
419 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
421 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
422 DALI_TEST_EQUALS( true, data.createNewScene, TEST_LOCATION );
423 DALI_TEST_EQUALS( true, data.newSceneCreated, TEST_LOCATION );
429 int UtcDaliSceneRootLayerAndSceneAlignment(void)
431 TestApplication application;
434 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
435 DALI_TEST_CHECK( scene );
437 // Create the render surface for the scene
438 TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
439 scene.SetSurface( *renderSurface );
441 // One reference of scene kept here and the other one kept in the Core
442 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 2 );
444 // Add a renderable actor to the scene
445 auto actor = CreateRenderableActor();
448 // Render and notify.
449 application.SendNotification();
450 application.Render(0);
452 // Keep the reference of the root layer handle so it will still be alive after the scene is deleted
453 Layer rootLayer = scene.GetRootLayer();
454 DALI_TEST_CHECK( rootLayer );
455 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 2 );
457 // Request to discard the scene from the Core
459 DALI_TEST_CHECK( scene.GetBaseObject().ReferenceCount() == 1 );
461 // Reset the scene handle
464 // Render and notify.
465 application.SendNotification();
466 application.Render(0);
468 // At this point, the scene should have been automatically deleted
469 // To prove this, the ref count of the root layer handle should be decremented to 1
470 DALI_TEST_CHECK( rootLayer.GetBaseObject().ReferenceCount() == 1 );
472 // Create a new Scene while the root layer of the deleted scene is still alive
473 Dali::Integration::Scene newScene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
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;
499 Dali::Integration::Scene scene = Dali::Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
500 DALI_TEST_CHECK( scene );
502 // Create the render surface for the scene
503 TestRenderSurface* renderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, 480.0f, 800.0f ) );
504 scene.SetSurface( *renderSurface );
506 // Render and notify.
507 application.SendNotification();
508 application.Render(0);
510 // Add a renderable actor to the scene
511 auto actor = CreateRenderableActor();
514 // Render and notify.
515 application.SendNotification();
516 application.Render(0);
518 // Notify the Core that the render surface will be deleted.
519 application.GetCore().SurfaceDeleted( renderSurface );
521 // Delete the render surface
522 delete renderSurface;
523 renderSurface = nullptr;
525 // Render and notify.
526 application.SendNotification();
527 application.Render(0);
532 int UtcDaliSceneEventProcessingFinishedP(void)
534 TestApplication application;
535 Dali::Integration::Scene scene = application.GetScene();
537 bool eventProcessingFinished = false;
538 EventProcessingFinishedFunctor functor( eventProcessingFinished );
539 scene.EventProcessingFinishedSignal().Connect( &application, functor );
541 Actor actor( Actor::New() );
544 application.SendNotification();
545 application.Render();
547 DALI_TEST_CHECK( eventProcessingFinished );
552 int UtcDaliSceneEventProcessingFinishedN(void)
554 TestApplication application;
555 Dali::Integration::Scene scene = application.GetScene();
557 bool eventProcessingFinished = false;
558 EventProcessingFinishedFunctor functor( eventProcessingFinished );
559 scene.EventProcessingFinishedSignal().Connect( &application, functor );
561 Actor actor( Actor::New() );
564 // Do not complete event processing and confirm the signal has not been emitted.
565 DALI_TEST_CHECK( !eventProcessingFinished );
570 int UtcDaliSceneSignalKeyEventP(void)
572 TestApplication application;
573 Dali::Integration::Scene scene = application.GetScene();
575 KeyEventSignalData data;
576 KeyEventReceivedFunctor functor( data );
577 scene.KeyEventSignal().Connect( &application, functor );
579 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
580 application.ProcessEvent( event );
582 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
583 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
584 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
585 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
586 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
590 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
591 application.ProcessEvent( event2 );
593 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
594 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
595 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
596 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
597 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
601 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
602 application.ProcessEvent( event3 );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
606 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
607 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
608 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
612 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
613 application.ProcessEvent( event4 );
615 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
616 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
617 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
618 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
619 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
623 int UtcDaliSceneSignalKeyEventN(void)
625 TestApplication application;
626 Dali::Integration::Scene scene = application.GetScene();
628 KeyEventSignalData data;
629 KeyEventReceivedFunctor functor( data );
630 scene.KeyEventSignal().Connect( &application, functor );
632 // Check that a non-pressed key events data is not modified.
633 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
638 int UtcDaliSceneTouchSignalP(void)
640 TestApplication application;
641 Dali::Integration::Scene scene = application.GetScene();
643 TouchedSignalData data;
644 TouchFunctor functor( data );
645 scene.TouchSignal().Connect( &application, functor );
647 // Render and notify.
648 application.SendNotification();
649 application.Render();
651 // Basic test: No actors, single touch (down then up).
653 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
655 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
656 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
657 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
660 GenerateTouch( application, PointState::UP, 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) );
668 // Add an actor to the scene.
669 Actor actor = Actor::New();
670 actor.SetSize( 100.0f, 100.0f );
671 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
673 actor.TouchedSignal().Connect( &DummyTouchCallback );
676 // Render and notify.
677 application.SendNotification();
678 application.Render();
680 // Actor on scene, single touch, down in actor, motion, then up outside actor.
682 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
684 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
686 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
689 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
691 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
694 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
696 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
697 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
698 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
702 // Multiple touch. Should only receive a touch on first down and last up.
704 Integration::TouchEvent touchEvent;
705 Integration::Point point;
708 point.SetState( PointState::DOWN );
709 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
710 touchEvent.points.push_back( point );
711 application.ProcessEvent( touchEvent );
712 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
717 touchEvent.points[0].SetState( PointState::STATIONARY );
718 point.SetDeviceId( 1 );
719 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
720 touchEvent.points.push_back( point );
721 application.ProcessEvent( touchEvent );
722 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
725 // Primary point is up
726 touchEvent.points[0].SetState( PointState::UP );
727 touchEvent.points[1].SetState( PointState::STATIONARY );
728 application.ProcessEvent( touchEvent );
729 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
732 // Remove 1st point now, 2nd point is now in motion
733 touchEvent.points.erase( touchEvent.points.begin() );
734 touchEvent.points[0].SetState( PointState::MOTION );
735 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
736 application.ProcessEvent( touchEvent );
737 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
741 touchEvent.points[0].SetState( PointState::UP );
742 application.ProcessEvent( touchEvent );
743 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
744 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
750 int UtcDaliSceneTouchSignalN(void)
752 TestApplication application;
753 Dali::Integration::Scene scene = application.GetScene();
755 TouchedSignalData data;
756 TouchFunctor functor( data );
757 scene.TouchSignal().Connect( &application, functor );
759 // Render and notify.
760 application.SendNotification();
761 application.Render();
763 // Confirm functor not called before there has been any touch event.
764 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
766 // No actors, single touch, down, motion then up.
768 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
770 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
771 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
772 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
776 // Confirm there is no signal when the touchpoint is only moved.
777 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
779 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
782 // Confirm a following up event generates a signal.
783 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
785 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
787 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
791 // Add an actor to the scene.
792 Actor actor = Actor::New();
793 actor.SetSize( 100.0f, 100.0f );
794 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
795 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
796 actor.TouchedSignal().Connect( &DummyTouchCallback );
799 // Render and notify.
800 application.SendNotification();
801 application.Render();
803 // Actor on scene. Interrupted before down and interrupted after down.
805 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
807 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
808 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
809 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
810 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
813 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
815 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
816 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
817 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
818 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
821 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
823 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
824 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
825 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
826 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
828 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
830 // Check that getting info about a non-existent point returns an empty handle
831 Actor actor = data.receivedTouchData.GetHitActor( 1 );
832 DALI_TEST_CHECK( !actor );
840 int UtcDaliSceneSignalWheelEventP(void)
842 TestApplication application;
843 Dali::Integration::Scene scene = application.GetScene();
845 WheelEventSignalData data;
846 WheelEventReceivedFunctor functor( data );
847 scene.WheelEventSignal().Connect( &application, functor );
849 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
850 application.ProcessEvent( event );
852 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
853 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
854 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
855 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
856 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
857 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
858 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
862 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
863 application.ProcessEvent( event2 );
865 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
866 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
867 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
868 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
869 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
870 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
871 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
875 int UtcDaliSceneEnsureEmptySceneCleared(void)
877 tet_infoline( "Ensure we clear the newly added window" );
879 TestApplication application;
881 // Create a new scene and set the background colors of both the new and the main scenes
882 auto defaultScene = application.GetScene();
883 defaultScene.SetBackgroundColor( Color::WHITE );
885 auto newScene = Integration::Scene::New( Vector2( 480.0f, 800.0f ) );
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 auto thirdScene = Integration::Scene::New( Vector2( 200.0f, 200.0f ) );
909 thirdScene.SetBackgroundColor( Color::BLUE );
911 clearCountBefore = glAbstraction.GetClearCountCalled();
913 application.SendNotification();
914 application.Render();
916 DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 3, TEST_LOCATION );
921 int UtcDaliSceneSurfaceResizedDefaultScene(void)
923 tet_infoline( "Ensure resizing of the surface is handled properly" );
925 TestApplication application;
927 auto defaultScene = application.GetScene();
928 Integration::RenderSurface* defaultSurface = defaultScene.GetSurface();
929 DALI_TEST_CHECK( defaultSurface );
931 // Ensure stage size matches the surface size
932 auto stage = Stage::GetCurrent();
933 DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION );
935 // Resize the surface and inform the scene accordingly
936 Vector2 newSize( 1000.0f, 2000.0f );
937 DALI_TEST_CHECK( stage.GetSize() != newSize );
938 defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) );
939 defaultScene.SurfaceResized();
941 DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION );
942 DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION );
947 int UtcDaliSceneSurfaceResizedAdditionalScene(void)
949 tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" );
951 TestApplication application;
952 Vector2 originalSurfaceSize( 500.0f, 1000.0f );
954 auto scene = Integration::Scene::New( Vector2::ZERO );
955 TestRenderSurface surface( PositionSize( 0.0f, 0.0f, originalSurfaceSize.width, originalSurfaceSize.height ) );
956 scene.SetSurface( 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 );