2 * Copyright (c) 2014 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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/context-notifier.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/wheel-event-integ.h>
28 #include <dali-test-suite-utils.h>
32 void stage_test_startup(void)
34 test_return_value = TET_UNDEF;
37 void stage_test_cleanup(void)
39 test_return_value = TET_PASS;
45 // Functor for EventProcessingFinished signal
46 struct EventProcessingFinishedFunctor
49 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
51 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
52 : mEventProcessingFinished( eventProcessingFinished )
57 mEventProcessingFinished = true;
60 bool& mEventProcessingFinished;
63 // Stores data that is populated in the key-event callback and will be read by the TET cases
64 struct KeyEventSignalData
67 : functorCalled(false)
72 functorCalled = false;
74 receivedKeyEvent.keyModifier = 0;
75 receivedKeyEvent.keyPressedName.clear();
76 receivedKeyEvent.keyPressed.clear();
80 KeyEvent receivedKeyEvent;
83 // Functor that sets the data when called
84 struct KeyEventReceivedFunctor
86 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
88 bool operator()( const KeyEvent& keyEvent )
90 signalData.functorCalled = true;
91 signalData.receivedKeyEvent = keyEvent;
96 KeyEventSignalData& signalData;
99 // Stores data that is populated in the touched signal callback and will be read by the TET cases
100 struct TouchedSignalData
103 : functorCalled(false)
108 functorCalled = false;
110 receivedTouchEvent.points.clear();
111 receivedTouchEvent.time = 0;
113 receivedTouchData.Reset();
117 TouchEvent receivedTouchEvent;
118 TouchData receivedTouchData;
121 // Functor that sets the data when touched signal is received
122 struct TouchedFunctor
124 TouchedFunctor( TouchedSignalData& data ) : signalData( data ) { }
126 void operator()( const TouchEvent& touch )
128 signalData.functorCalled = true;
129 signalData.receivedTouchEvent = touch;
132 TouchedSignalData& signalData;
136 // Functor that sets the data when touched signal is received
139 TouchFunctor( TouchedSignalData& data ) : signalData( data ) { }
141 void operator()( const TouchData& touch )
143 signalData.functorCalled = true;
144 signalData.receivedTouchData = touch;
147 TouchedSignalData& signalData;
150 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
151 struct WheelEventSignalData
153 WheelEventSignalData()
154 : functorCalled(false)
159 functorCalled = false;
163 WheelEvent receivedWheelEvent;
166 // Functor that sets the data when wheel-event signal is received
167 struct WheelEventReceivedFunctor
169 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
171 bool operator()( const WheelEvent& wheelEvent )
173 signalData.functorCalled = true;
174 signalData.receivedWheelEvent = wheelEvent;
179 WheelEventSignalData& signalData;
182 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
187 struct ContextStatusFunctor
189 ContextStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
206 struct SceneCreatedStatusFunctor
208 SceneCreatedStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
225 struct ActorCreatedFunctor
227 ActorCreatedFunctor( bool& signalReceived )
228 : mSignalVerified( signalReceived )
232 void operator()( BaseHandle object )
234 tet_infoline( "Verifying TestActorCallback()" );
235 Actor actor = Actor::DownCast( object );
238 mSignalVerified = true;
242 bool& mSignalVerified;
245 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
247 Integration::TouchEvent touchEvent;
248 Integration::Point point;
249 point.SetState( state );
250 point.SetScreenPosition( screenPosition );
251 touchEvent.points.push_back( point );
252 application.ProcessEvent( touchEvent );
255 } // unnamed namespace
258 int UtcDaliStageDefaultConstructorP(void)
260 TestApplication application;
263 DALI_TEST_CHECK( !stage );
267 // Note: No negative test for default constructor.
269 int UtcDaliStageDestructorP(void)
271 TestApplication application;
272 Stage* stage = new Stage();
276 DALI_TEST_CHECK( true );
280 // Note: No negative test for default destructor.
282 int UtcDaliStageGetCurrentP(void)
284 TestApplication application;
285 Stage stage = Stage::GetCurrent();
287 DALI_TEST_CHECK( stage );
291 int UtcDaliStageGetCurrentN(void)
293 bool asserted = false;
296 Stage stage = Stage::GetCurrent();
298 catch( Dali::DaliException& e )
300 DALI_TEST_PRINT_ASSERT( e );
301 DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
305 DALI_TEST_CHECK( asserted );
309 int UtcDaliStageIsInstalledP(void)
311 TestApplication application;
315 DALI_TEST_CHECK( Stage::IsInstalled() );
319 int UtcDaliStageIsInstalledN(void)
321 DALI_TEST_CHECK( !Stage::IsInstalled() );
326 int UtcDaliStageCopyConstructorP(void)
328 TestApplication application;
329 Stage stage = Stage::GetCurrent();
331 Stage copyStage( stage );
333 DALI_TEST_CHECK( copyStage );
334 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
339 // Note: no negative test for UtcDaliStageCopyConstructor.
341 int UtcDaliStageAssignmentOperatorP(void)
343 TestApplication application;
344 const Stage stage = Stage::GetCurrent();
346 Stage copyStage = stage;
348 DALI_TEST_CHECK( copyStage );
349 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
354 // Note: No negative test for UtcDaliStageAssignmentOperator.
356 int UtcDaliStageAddP(void)
358 TestApplication application;
360 Stage stage = Stage::GetCurrent();
362 Actor actor = Actor::New();
363 DALI_TEST_CHECK( !actor.OnStage() );
366 DALI_TEST_CHECK( actor.OnStage() );
370 int UtcDaliStageAddN(void)
372 TestApplication application;
374 Stage stage = Stage::GetCurrent();
377 bool asserted = false;
382 catch( Dali::DaliException& e )
384 DALI_TEST_PRINT_ASSERT( e );
385 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
389 DALI_TEST_CHECK( asserted );
394 int UtcDaliStageRemoveP(void)
396 TestApplication application;
398 Stage stage = Stage::GetCurrent();
400 Actor actor = Actor::New();
401 DALI_TEST_CHECK( !actor.OnStage() );
404 DALI_TEST_CHECK( actor.OnStage() );
407 DALI_TEST_CHECK( !actor.OnStage() );
411 int UtcDaliStageRemoveN1(void)
413 TestApplication application;
415 Stage stage = Stage::GetCurrent();
418 bool asserted = false;
421 // Actor is not valid, confirm a removal attempt does assert.
422 stage.Remove( actor );
424 catch( Dali::DaliException& e )
426 DALI_TEST_PRINT_ASSERT( e );
427 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
431 DALI_TEST_CHECK( asserted );
435 int UtcDaliStageRemoveN2(void)
437 TestApplication application;
439 Stage stage = Stage::GetCurrent();
440 Actor actor = Actor::New();
441 DALI_TEST_CHECK( !actor.OnStage() );
443 bool asserted = false;
446 // Actor is not on stage, confirm a removal attempt does not assert / segfault.
447 stage.Remove( actor );
449 catch( Dali::DaliException& e )
451 DALI_TEST_PRINT_ASSERT( e );
455 DALI_TEST_CHECK( !asserted );
459 int UtcDaliStageRemoveN3(void)
461 TestApplication application;
463 Stage stage = Stage::GetCurrent();
465 // Initially we have a default layer
466 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
468 // Check we cannot remove the root layer from the stage.
469 Layer layer = stage.GetRootLayer();
470 bool asserted = true;
473 stage.Remove( layer );
475 catch( Dali::DaliException& e )
477 DALI_TEST_PRINT_ASSERT( e );
478 DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
482 DALI_TEST_CHECK( asserted );
483 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
487 int UtcDaliStageGetSizeP(void)
489 TestApplication application;
491 Stage stage = Stage::GetCurrent();
493 Vector2 size = stage.GetSize();
495 DALI_TEST_EQUALS( size.width, static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ), TEST_LOCATION );
496 DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
500 int UtcDaliStageGetSizeN(void)
502 TestApplication application;
506 bool asserted = false;
510 size = stage.GetSize();
512 catch( Dali::DaliException& e )
514 DALI_TEST_PRINT_ASSERT( e );
515 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
519 DALI_TEST_CHECK( asserted );
523 int UtcDaliStageGetDpiP1(void)
525 TestApplication application; // Initializes core DPI to default values
527 Stage stage = Stage::GetCurrent();
529 // Test the default DPI.
530 Vector2 dpi = stage.GetDpi();
531 DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
532 DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ), TEST_LOCATION );
536 int UtcDaliStageGetDpiP2(void)
538 TestApplication application; // Initializes core DPI to default values
540 // Test that setting core DPI explicitly also sets up the Stage's DPI.
541 application.GetCore().SetDpi( 200, 180 );
543 Stage stage = Stage::GetCurrent();
544 Vector2 dpi = stage.GetDpi();
545 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
546 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
550 int UtcDaliStageGetDpiP3(void)
552 TestApplication application( 480, 800, 72.0f, 120.0f ); // Initializes core DPI with specific values
554 Stage stage = Stage::GetCurrent();
556 // Test that setting core DPI explicitly also sets up the Stage's DPI.
557 Vector2 dpi = stage.GetDpi();
558 DALI_TEST_EQUALS( dpi.x, 72.0f, TEST_LOCATION );
559 DALI_TEST_EQUALS( dpi.y, 120.0f, TEST_LOCATION) ;
564 * This is not a true negative test, we are checking the DPI if it has not been set.
565 * A test for setting negative DPI values would be part of the application core utc tests.
567 int UtcDaliStageGetDpiN(void)
569 TestApplication application; // Initializes core DPI to default values
571 Stage stage = Stage::GetCurrent();
572 Vector2 dpi = stage.GetDpi();
574 DALI_TEST_EQUALS( dpi.x, 220.0f, TEST_LOCATION );
575 DALI_TEST_EQUALS( dpi.y, 217.0f, TEST_LOCATION );
579 int UtcDaliStageGetLayerCountP(void)
581 TestApplication application;
583 Stage stage = Stage::GetCurrent();
585 // Initially we have a default layer
586 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
588 Layer layer = Layer::New();
591 DALI_TEST_EQUALS( stage.GetLayerCount(), 2u, TEST_LOCATION );
596 * Not a true negative test, but confirms layer count is not affected by an invalid removal.
598 int UtcDaliStageGetLayerCountN(void)
600 TestApplication application;
602 Stage stage = Stage::GetCurrent();
604 // Initially we have a default layer
605 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
607 Layer layer = Layer::New();
608 stage.Remove( layer );
610 // Still have 1 layer.
611 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
615 int UtcDaliStageGetLayerP(void)
617 TestApplication application;
619 Stage stage = Stage::GetCurrent();
621 Layer rootLayer = stage.GetLayer( 0 );
622 DALI_TEST_CHECK( rootLayer );
624 Layer layer = Layer::New();
627 Layer sameLayer = stage.GetLayer( 1 );
628 DALI_TEST_CHECK( layer == sameLayer );
632 int UtcDaliStageGetLayerN(void)
634 TestApplication application;
636 Stage stage = Stage::GetCurrent();
638 bool asserted = false;
641 // Try to get a layer that doesn't exist (note: 0 is the root layer).
642 Layer layer = stage.GetLayer( 1 );
644 catch( Dali::DaliException& e )
646 DALI_TEST_PRINT_ASSERT( e );
647 DALI_TEST_ASSERT( e, "depth < mLayers.size()", TEST_LOCATION );
651 DALI_TEST_CHECK( asserted );
655 int UtcDaliStageGetRootLayerP(void)
657 TestApplication application;
659 Stage stage = Stage::GetCurrent();
661 Layer layer = stage.GetLayer( 0 );
662 DALI_TEST_CHECK( layer );
664 // Check that GetRootLayer() correctly retreived layer 0.
665 DALI_TEST_CHECK( stage.GetRootLayer() == layer );
670 int UtcDaliStageGetRootLayerN(void)
672 TestApplication application;
674 Stage stage = Stage::GetCurrent();
676 Layer rootLayer = stage.GetLayer( 0 );
677 DALI_TEST_CHECK( rootLayer );
678 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
680 // Create a new layer and attempt to lower it below the root layer.
681 Layer layer = Layer::New();
683 layer.LowerToBottom();
685 // Check that GetRootLayer still retrieves the same original layer.
686 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
688 // Check modifying the root layer is also blocked.
689 rootLayer.RaiseToTop();
690 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
695 int UtcDaliStageSetBackgroundColorP(void)
697 TestApplication application;
699 Stage stage = Stage::GetCurrent();
701 Vector4 testColor( 0.1f, 0.2f, 0.3f, 1.0f );
702 stage.SetBackgroundColor( testColor );
704 DALI_TEST_EQUALS( testColor, stage.GetBackgroundColor(), TEST_LOCATION );
708 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
709 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
711 int UtcDaliStageGetBackgroundColorP(void)
713 TestApplication application;
715 Stage stage = Stage::GetCurrent();
717 DALI_TEST_EQUALS( Stage::DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION );
721 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
723 int UtcDaliStageKeepRenderingP(void)
725 TestApplication application;
727 Stage stage = Stage::GetCurrent();
729 // Run core until it wants to sleep
730 bool keepUpdating( true );
731 while ( keepUpdating )
733 application.SendNotification();
734 keepUpdating = application.Render( 1000.0f /*1 second*/ );
737 // Force rendering for the next 5 seconds
738 stage.KeepRendering( 5.0f );
740 application.SendNotification();
742 // Test that core wants to sleep after 10 seconds
743 keepUpdating = application.Render( 1000.0f /*1 second*/ );
744 DALI_TEST_CHECK( keepUpdating );
745 keepUpdating = application.Render( 1000.0f /*2 seconds*/ );
746 DALI_TEST_CHECK( keepUpdating );
747 keepUpdating = application.Render( 1000.0f /*3 seconds*/ );
748 DALI_TEST_CHECK( keepUpdating );
749 keepUpdating = application.Render( 1000.0f /*4 seconds*/ );
750 DALI_TEST_CHECK( keepUpdating );
751 keepUpdating = application.Render( 1000.0f /*5 seconds*/ );
752 DALI_TEST_CHECK( !keepUpdating );
756 int UtcDaliStageKeepRenderingN(void)
758 TestApplication application;
760 Stage stage = Stage::GetCurrent();
762 // Run core until it wants to sleep
763 bool keepUpdating( true );
764 while ( keepUpdating )
766 application.SendNotification();
767 keepUpdating = application.Render( 1000.0f /*1 second*/ );
770 // Force rendering for the next 5 seconds
771 stage.KeepRendering( -1.0f );
773 application.SendNotification();
775 // Test that core wants to sleep after 10 seconds
776 keepUpdating = application.Render( 1000.0f /*1 second*/ );
777 DALI_TEST_CHECK( !keepUpdating );
782 int UtcDaliStageEventProcessingFinishedP(void)
784 TestApplication application;
785 Stage stage = Stage::GetCurrent();
787 bool eventProcessingFinished = false;
788 EventProcessingFinishedFunctor functor( eventProcessingFinished );
789 stage.EventProcessingFinishedSignal().Connect( &application, functor );
791 Actor actor( Actor::New() );
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_CHECK( eventProcessingFinished );
802 int UtcDaliStageEventProcessingFinishedN(void)
804 TestApplication application;
805 Stage stage = Stage::GetCurrent();
807 bool eventProcessingFinished = false;
808 EventProcessingFinishedFunctor functor( eventProcessingFinished );
809 stage.EventProcessingFinishedSignal().Connect( &application, functor );
811 Actor actor( Actor::New() );
814 // Do not complete event processing and confirm the signal has not been emitted.
815 DALI_TEST_CHECK( !eventProcessingFinished );
820 int UtcDaliStageSignalKeyEventP(void)
822 TestApplication application;
823 Stage stage = Stage::GetCurrent();
825 KeyEventSignalData data;
826 KeyEventReceivedFunctor functor( data );
827 stage.KeyEventSignal().Connect( &application, functor );
829 Integration::KeyEvent event( "i", "i", 0, 0, 0, Integration::KeyEvent::Down );
830 application.ProcessEvent( event );
832 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
833 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
834 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
835 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
836 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
840 Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up );
841 application.ProcessEvent( event2 );
843 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
844 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
845 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
846 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
847 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
851 Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down );
852 application.ProcessEvent( event3 );
854 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
855 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
856 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
857 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
858 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
862 Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up );
863 application.ProcessEvent( event4 );
865 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
866 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
867 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
868 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
869 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
873 int UtcDaliStageSignalKeyEventN(void)
875 TestApplication application;
876 Stage stage = Stage::GetCurrent();
878 KeyEventSignalData data;
879 KeyEventReceivedFunctor functor( data );
880 stage.KeyEventSignal().Connect( &application, functor );
882 // Check that a non-pressed key events data is not modified.
883 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
888 int UtcDaliStageTouchedSignalP(void)
890 TestApplication application;
891 Stage stage = Stage::GetCurrent();
893 TouchedSignalData data;
894 TouchedFunctor functor( data );
895 stage.TouchedSignal().Connect( &application, functor );
897 // Render and notify.
898 application.SendNotification();
899 application.Render();
901 // Basic test: No actors, single touch (down then up).
903 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
905 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
906 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
907 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
910 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
912 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
913 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
914 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
918 // Add an actor to the scene.
919 Actor actor = Actor::New();
920 actor.SetSize( 100.0f, 100.0f );
921 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
922 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
923 actor.TouchedSignal().Connect( &DummyTouchCallback );
926 // Render and notify.
927 application.SendNotification();
928 application.Render();
930 // Actor on scene, single touch, down in actor, motion, then up outside actor.
932 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
934 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
935 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
936 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
939 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
941 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
944 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
946 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
947 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
948 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
952 // Multiple touch. Should only receive a touch on first down and last up.
954 Integration::TouchEvent touchEvent;
955 Integration::Point point;
958 point.SetState( PointState::DOWN );
959 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
960 touchEvent.points.push_back( point );
961 application.ProcessEvent( touchEvent );
962 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
963 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
967 touchEvent.points[0].SetState( PointState::STATIONARY );
968 point.SetDeviceId( 1 );
969 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
970 touchEvent.points.push_back( point );
971 application.ProcessEvent( touchEvent );
972 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
973 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
976 // Primary point is up
977 touchEvent.points[0].SetState( PointState::UP );
978 touchEvent.points[1].SetState( PointState::STATIONARY );
979 application.ProcessEvent( touchEvent );
980 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
981 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
984 // Remove 1st point now, 2nd point is now in motion
985 touchEvent.points.erase( touchEvent.points.begin() );
986 touchEvent.points[0].SetState( PointState::MOTION );
987 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
988 application.ProcessEvent( touchEvent );
989 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
990 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
994 touchEvent.points[0].SetState( PointState::UP );
995 application.ProcessEvent( touchEvent );
996 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
997 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1003 int UtcDaliStageTouchedSignalN(void)
1005 TestApplication application;
1006 Stage stage = Stage::GetCurrent();
1008 TouchedSignalData data;
1009 TouchedFunctor functor( data );
1010 stage.TouchedSignal().Connect( &application, functor );
1012 // Render and notify.
1013 application.SendNotification();
1014 application.Render();
1016 // Confirm functor not called before there has been any touch event.
1017 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1019 // No actors, single touch, down, motion then up.
1021 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1023 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1024 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1025 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1028 // Confirm there is no signal when the touchpoint is only moved.
1029 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1031 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1034 // Confirm a following up event generates a signal.
1035 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1037 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1038 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1039 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1043 // Add an actor to the scene.
1044 Actor actor = Actor::New();
1045 actor.SetSize( 100.0f, 100.0f );
1046 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1047 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1048 actor.TouchedSignal().Connect( &DummyTouchCallback );
1051 // Render and notify.
1052 application.SendNotification();
1053 application.Render();
1055 // Actor on scene. Interrupted before down and interrupted after down.
1057 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1059 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1060 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1061 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1062 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Interrupted );
1065 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1067 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1068 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1069 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
1070 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Down );
1073 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1075 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1076 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1077 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1078 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Interrupted );
1080 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1082 // Check that getting info about a non-existent point causes an assert.
1083 bool asserted = false;
1086 data.receivedTouchEvent.GetPoint( 1 );
1088 catch( Dali::DaliException& e )
1090 DALI_TEST_PRINT_ASSERT( e );
1091 DALI_TEST_ASSERT( e, "point < points.size() && \"No point at index\"", TEST_LOCATION );
1094 DALI_TEST_CHECK( asserted );
1103 int UtcDaliStageTouchSignalP(void)
1105 TestApplication application;
1106 Stage stage = Stage::GetCurrent();
1108 TouchedSignalData data;
1109 TouchFunctor functor( data );
1110 stage.TouchSignal().Connect( &application, functor );
1112 // Render and notify.
1113 application.SendNotification();
1114 application.Render();
1116 // Basic test: No actors, single touch (down then up).
1118 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1120 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1121 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1122 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
1125 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
1127 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1128 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1129 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
1133 // Add an actor to the scene.
1134 Actor actor = Actor::New();
1135 actor.SetSize( 100.0f, 100.0f );
1136 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1137 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1138 actor.TouchedSignal().Connect( &DummyTouchCallback );
1141 // Render and notify.
1142 application.SendNotification();
1143 application.Render();
1145 // Actor on scene, single touch, down in actor, motion, then up outside actor.
1147 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1149 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1150 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1151 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
1154 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
1156 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1159 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
1161 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1162 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1163 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
1167 // Multiple touch. Should only receive a touch on first down and last up.
1169 Integration::TouchEvent touchEvent;
1170 Integration::Point point;
1173 point.SetState( PointState::DOWN );
1174 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1175 touchEvent.points.push_back( point );
1176 application.ProcessEvent( touchEvent );
1177 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1178 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
1182 touchEvent.points[0].SetState( PointState::STATIONARY );
1183 point.SetDeviceId( 1 );
1184 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
1185 touchEvent.points.push_back( point );
1186 application.ProcessEvent( touchEvent );
1187 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1190 // Primary point is up
1191 touchEvent.points[0].SetState( PointState::UP );
1192 touchEvent.points[1].SetState( PointState::STATIONARY );
1193 application.ProcessEvent( touchEvent );
1194 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1197 // Remove 1st point now, 2nd point is now in motion
1198 touchEvent.points.erase( touchEvent.points.begin() );
1199 touchEvent.points[0].SetState( PointState::MOTION );
1200 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
1201 application.ProcessEvent( touchEvent );
1202 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1206 touchEvent.points[0].SetState( PointState::UP );
1207 application.ProcessEvent( touchEvent );
1208 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1209 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
1215 int UtcDaliStageTouchSignalN(void)
1217 TestApplication application;
1218 Stage stage = Stage::GetCurrent();
1220 TouchedSignalData data;
1221 TouchFunctor functor( data );
1222 stage.TouchSignal().Connect( &application, functor );
1224 // Render and notify.
1225 application.SendNotification();
1226 application.Render();
1228 // Confirm functor not called before there has been any touch event.
1229 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1231 // No actors, single touch, down, motion then up.
1233 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1235 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1236 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1237 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
1240 // Confirm there is no signal when the touchpoint is only moved.
1241 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1243 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1246 // Confirm a following up event generates a signal.
1247 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1249 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1250 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1251 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0));
1255 // Add an actor to the scene.
1256 Actor actor = Actor::New();
1257 actor.SetSize( 100.0f, 100.0f );
1258 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1259 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1260 actor.TouchedSignal().Connect( &DummyTouchCallback );
1263 // Render and notify.
1264 application.SendNotification();
1265 application.Render();
1267 // Actor on scene. Interrupted before down and interrupted after down.
1269 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1271 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1272 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1273 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
1274 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
1277 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1279 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1280 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1281 DALI_TEST_CHECK( data.receivedTouchData.GetHitActor(0) == actor );
1282 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::DOWN );
1285 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1287 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1288 DALI_TEST_CHECK( data.receivedTouchData.GetPointCount() != 0u );
1289 DALI_TEST_CHECK( !data.receivedTouchData.GetHitActor(0) );
1290 DALI_TEST_CHECK( data.receivedTouchData.GetState(0) == PointState::INTERRUPTED );
1292 DALI_TEST_EQUALS( data.receivedTouchData.GetPointCount(), 1u, TEST_LOCATION );
1294 // Check that getting info about a non-existent point returns an empty handle
1295 Actor actor = data.receivedTouchData.GetHitActor( 1 );
1296 DALI_TEST_CHECK( !actor );
1304 int UtcDaliStageSignalWheelEventP(void)
1306 TestApplication application;
1307 Stage stage = Stage::GetCurrent();
1309 WheelEventSignalData data;
1310 WheelEventReceivedFunctor functor( data );
1311 stage.WheelEventSignal().Connect( &application, functor );
1313 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1314 application.ProcessEvent( event );
1316 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1317 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
1318 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
1319 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
1320 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
1321 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
1322 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
1326 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1327 application.ProcessEvent( event2 );
1329 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1330 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
1331 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
1332 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
1333 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
1334 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
1335 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
1339 int UtcDaliStageContextLostSignalP(void)
1341 TestApplication app;
1342 Stage stage = Stage::GetCurrent();
1344 bool contextLost = false;
1345 ContextStatusFunctor contextLostFunctor( contextLost );
1346 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1348 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1349 notifier->NotifyContextLost();
1350 DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1355 int UtcDaliStageContextLostSignalN(void)
1357 TestApplication app;
1360 // Check that connecting to the signal with a bad stage instance causes an assert.
1361 bool asserted = false;
1362 bool contextLost = false;
1363 ContextStatusFunctor contextLostFunctor( contextLost );
1366 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1368 catch( Dali::DaliException& e )
1370 DALI_TEST_PRINT_ASSERT( e );
1371 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1374 DALI_TEST_CHECK( asserted );
1379 int UtcDaliStageContextRegainedSignalP(void)
1381 TestApplication app;
1382 Stage stage = Stage::GetCurrent();
1384 bool contextRegained = false;
1385 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1386 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1388 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1389 notifier->NotifyContextLost();
1390 notifier->NotifyContextRegained();
1391 DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1396 int UtcDaliStageContextRegainedSignalN(void)
1398 TestApplication app;
1401 // Check that connecting to the signal with a bad stage instance causes an assert.
1402 bool asserted = false;
1403 bool contextRegained = false;
1404 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1407 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1409 catch( Dali::DaliException& e )
1411 DALI_TEST_PRINT_ASSERT( e );
1412 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1415 DALI_TEST_CHECK( asserted );
1420 int UtcDaliStageSceneCreatedSignalP(void)
1422 TestApplication app;
1423 Stage stage = Stage::GetCurrent();
1425 bool signalCalled = false;
1426 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1427 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1429 Integration::Core& core = app.GetCore();
1430 core.SceneCreated();
1431 DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1436 int UtcDaliStageSceneCreatedSignalN(void)
1438 TestApplication app;
1441 // Check that connecting to the signal with a bad stage instance causes an assert.
1442 bool asserted = false;
1443 bool signalCalled = false;
1444 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1447 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1449 catch( Dali::DaliException& e )
1451 DALI_TEST_PRINT_ASSERT( e );
1452 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1455 DALI_TEST_CHECK( asserted );
1460 int UtcDaliStageGetRenderTaskListP(void)
1462 TestApplication app;
1463 Stage stage = Stage::GetCurrent();
1465 // Check we get a valid instance.
1466 const RenderTaskList& tasks = stage.GetRenderTaskList();
1468 // There should be 1 task by default.
1469 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1471 // RenderTaskList has it's own UTC tests.
1472 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1473 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1475 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1480 int UtcDaliStageGetRenderTaskListN(void)
1482 TestApplication app;
1485 // Check that getting the render task list with a bad stage instance causes an assert.
1486 bool asserted = false;
1489 stage.GetRenderTaskList();
1491 catch( Dali::DaliException& e )
1493 DALI_TEST_PRINT_ASSERT( e );
1494 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1497 DALI_TEST_CHECK( asserted );
1502 int UtcDaliStageGetObjectRegistryP(void)
1504 TestApplication app;
1505 Stage stage = Stage::GetCurrent();
1507 ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1509 // Object registry tests are covered in their own module.
1510 // However we want a basic test to confirm the returned registry is valid and works.
1511 bool verified = false;
1512 ActorCreatedFunctor test( verified );
1513 objectRegistry.ObjectCreatedSignal().Connect( &app, test );
1515 Actor actor = Actor::New();
1516 DALI_TEST_CHECK( test.mSignalVerified );
1521 int UtcDaliStageGetObjectRegistryN(void)
1523 TestApplication app;
1526 // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1527 // This is because GetCurrent() is used, always creating a stage if one does not exist.
1528 bool asserted = false;
1531 stage.GetObjectRegistry();
1533 catch( Dali::DaliException& e )
1535 DALI_TEST_PRINT_ASSERT( e );
1538 DALI_TEST_CHECK( !asserted );
1543 int UtcDaliStageOperatorAssign(void)
1545 TestApplication app;
1547 DALI_TEST_CHECK( !stage );
1549 stage = Stage::GetCurrent();
1550 DALI_TEST_CHECK( stage );