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;
115 TouchEvent receivedTouchEvent;
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 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
133 struct WheelEventSignalData
135 WheelEventSignalData()
136 : functorCalled(false)
141 functorCalled = false;
145 WheelEvent receivedWheelEvent;
148 // Functor that sets the data when wheel-event signal is received
149 struct WheelEventReceivedFunctor
151 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
153 bool operator()( const WheelEvent& wheelEvent )
155 signalData.functorCalled = true;
156 signalData.receivedWheelEvent = wheelEvent;
161 WheelEventSignalData& signalData;
164 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
169 struct ContextStatusFunctor
171 ContextStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
188 struct SceneCreatedStatusFunctor
190 SceneCreatedStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
207 struct ActorCreatedFunctor
209 ActorCreatedFunctor( bool& signalReceived )
210 : mSignalVerified( signalReceived )
214 void operator()( BaseHandle object )
216 tet_infoline( "Verifying TestActorCallback()" );
217 Actor actor = Actor::DownCast( object );
220 mSignalVerified = true;
224 bool& mSignalVerified;
227 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
229 Integration::TouchEvent touchEvent;
230 Integration::Point point;
231 point.SetState( state );
232 point.SetScreenPosition( screenPosition );
233 touchEvent.points.push_back( point );
234 application.ProcessEvent( touchEvent );
237 } // unnamed namespace
240 int UtcDaliStageDefaultConstructorP(void)
242 TestApplication application;
245 DALI_TEST_CHECK( !stage );
249 // Note: No negative test for default constructor.
251 int UtcDaliStageDestructorP(void)
253 TestApplication application;
254 Stage* stage = new Stage();
258 DALI_TEST_CHECK( true );
262 // Note: No negative test for default destructor.
264 int UtcDaliStageGetCurrentP(void)
266 TestApplication application;
267 Stage stage = Stage::GetCurrent();
269 DALI_TEST_CHECK( stage );
273 int UtcDaliStageGetCurrentN(void)
275 bool asserted = false;
278 Stage stage = Stage::GetCurrent();
280 catch( Dali::DaliException& e )
282 DALI_TEST_PRINT_ASSERT( e );
283 DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
287 DALI_TEST_CHECK( asserted );
291 int UtcDaliStageIsInstalledP(void)
293 TestApplication application;
297 DALI_TEST_CHECK( Stage::IsInstalled() );
301 int UtcDaliStageIsInstalledN(void)
303 DALI_TEST_CHECK( !Stage::IsInstalled() );
308 int UtcDaliStageCopyConstructorP(void)
310 TestApplication application;
311 Stage stage = Stage::GetCurrent();
313 Stage copyStage( stage );
315 DALI_TEST_CHECK( copyStage );
316 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
321 // Note: no negative test for UtcDaliStageCopyConstructor.
323 int UtcDaliStageAssignmentOperatorP(void)
325 TestApplication application;
326 const Stage stage = Stage::GetCurrent();
328 Stage copyStage = stage;
330 DALI_TEST_CHECK( copyStage );
331 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
336 // Note: No negative test for UtcDaliStageAssignmentOperator.
338 int UtcDaliStageAddP(void)
340 TestApplication application;
342 Stage stage = Stage::GetCurrent();
344 Actor actor = Actor::New();
345 DALI_TEST_CHECK( !actor.OnStage() );
348 DALI_TEST_CHECK( actor.OnStage() );
352 int UtcDaliStageAddN(void)
354 TestApplication application;
356 Stage stage = Stage::GetCurrent();
359 bool asserted = false;
364 catch( Dali::DaliException& e )
366 DALI_TEST_PRINT_ASSERT( e );
367 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
371 DALI_TEST_CHECK( asserted );
376 int UtcDaliStageRemoveP(void)
378 TestApplication application;
380 Stage stage = Stage::GetCurrent();
382 Actor actor = Actor::New();
383 DALI_TEST_CHECK( !actor.OnStage() );
386 DALI_TEST_CHECK( actor.OnStage() );
389 DALI_TEST_CHECK( !actor.OnStage() );
393 int UtcDaliStageRemoveN1(void)
395 TestApplication application;
397 Stage stage = Stage::GetCurrent();
400 bool asserted = false;
403 // Actor is not valid, confirm a removal attempt does assert.
404 stage.Remove( actor );
406 catch( Dali::DaliException& e )
408 DALI_TEST_PRINT_ASSERT( e );
409 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
413 DALI_TEST_CHECK( asserted );
417 int UtcDaliStageRemoveN2(void)
419 TestApplication application;
421 Stage stage = Stage::GetCurrent();
422 Actor actor = Actor::New();
423 DALI_TEST_CHECK( !actor.OnStage() );
425 bool asserted = false;
428 // Actor is not on stage, confirm a removal attempt does not assert / segfault.
429 stage.Remove( actor );
431 catch( Dali::DaliException& e )
433 DALI_TEST_PRINT_ASSERT( e );
437 DALI_TEST_CHECK( !asserted );
441 int UtcDaliStageRemoveN3(void)
443 TestApplication application;
445 Stage stage = Stage::GetCurrent();
447 // Initially we have a default layer
448 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
450 // Check we cannot remove the root layer from the stage.
451 Layer layer = stage.GetRootLayer();
452 bool asserted = true;
455 stage.Remove( layer );
457 catch( Dali::DaliException& e )
459 DALI_TEST_PRINT_ASSERT( e );
460 DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
464 DALI_TEST_CHECK( asserted );
465 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
469 int UtcDaliStageGetSizeP(void)
471 TestApplication application;
473 Stage stage = Stage::GetCurrent();
475 Vector2 size = stage.GetSize();
477 DALI_TEST_EQUALS( size.width, static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ), TEST_LOCATION );
478 DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
482 int UtcDaliStageGetSizeN(void)
484 TestApplication application;
488 bool asserted = false;
492 size = stage.GetSize();
494 catch( Dali::DaliException& e )
496 DALI_TEST_PRINT_ASSERT( e );
497 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
501 DALI_TEST_CHECK( asserted );
505 int UtcDaliStageGetDpiP1(void)
507 TestApplication application; // Initializes core DPI to default values
509 Stage stage = Stage::GetCurrent();
511 // Test the default DPI.
512 Vector2 dpi = stage.GetDpi();
513 DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
514 DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ), TEST_LOCATION );
518 int UtcDaliStageGetDpiP2(void)
520 TestApplication application; // Initializes core DPI to default values
522 // Test that setting core DPI explicitly also sets up the Stage's DPI.
523 application.GetCore().SetDpi( 200, 180 );
525 Stage stage = Stage::GetCurrent();
526 Vector2 dpi = stage.GetDpi();
527 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
528 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
532 int UtcDaliStageGetDpiP3(void)
534 TestApplication application( 480, 800, 72.0f, 120.0f ); // Initializes core DPI with specific values
536 Stage stage = Stage::GetCurrent();
538 // Test that setting core DPI explicitly also sets up the Stage's DPI.
539 Vector2 dpi = stage.GetDpi();
540 DALI_TEST_EQUALS( dpi.x, 72.0f, TEST_LOCATION );
541 DALI_TEST_EQUALS( dpi.y, 120.0f, TEST_LOCATION) ;
546 * This is not a true negative test, we are checking the DPI if it has not been set.
547 * A test for setting negative DPI values would be part of the application core utc tests.
549 int UtcDaliStageGetDpiN(void)
551 TestApplication application; // Initializes core DPI to default values
553 Stage stage = Stage::GetCurrent();
554 Vector2 dpi = stage.GetDpi();
556 DALI_TEST_EQUALS( dpi.x, 220.0f, TEST_LOCATION );
557 DALI_TEST_EQUALS( dpi.y, 217.0f, TEST_LOCATION );
561 int UtcDaliStageGetLayerCountP(void)
563 TestApplication application;
565 Stage stage = Stage::GetCurrent();
567 // Initially we have a default layer
568 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
570 Layer layer = Layer::New();
573 DALI_TEST_EQUALS( stage.GetLayerCount(), 2u, TEST_LOCATION );
578 * Not a true negative test, but confirms layer count is not affected by an invalid removal.
580 int UtcDaliStageGetLayerCountN(void)
582 TestApplication application;
584 Stage stage = Stage::GetCurrent();
586 // Initially we have a default layer
587 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
589 Layer layer = Layer::New();
590 stage.Remove( layer );
592 // Still have 1 layer.
593 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
597 int UtcDaliStageGetLayerP(void)
599 TestApplication application;
601 Stage stage = Stage::GetCurrent();
603 Layer rootLayer = stage.GetLayer( 0 );
604 DALI_TEST_CHECK( rootLayer );
606 Layer layer = Layer::New();
609 Layer sameLayer = stage.GetLayer( 1 );
610 DALI_TEST_CHECK( layer == sameLayer );
614 int UtcDaliStageGetLayerN(void)
616 TestApplication application;
618 Stage stage = Stage::GetCurrent();
620 bool asserted = false;
623 // Try to get a layer that doesn't exist (note: 0 is the root layer).
624 Layer layer = stage.GetLayer( 1 );
626 catch( Dali::DaliException& e )
628 DALI_TEST_PRINT_ASSERT( e );
629 DALI_TEST_ASSERT( e, "depth < mLayers.size()", TEST_LOCATION );
633 DALI_TEST_CHECK( asserted );
637 int UtcDaliStageGetRootLayerP(void)
639 TestApplication application;
641 Stage stage = Stage::GetCurrent();
643 Layer layer = stage.GetLayer( 0 );
644 DALI_TEST_CHECK( layer );
646 // Check that GetRootLayer() correctly retreived layer 0.
647 DALI_TEST_CHECK( stage.GetRootLayer() == layer );
652 int UtcDaliStageGetRootLayerN(void)
654 TestApplication application;
656 Stage stage = Stage::GetCurrent();
658 Layer rootLayer = stage.GetLayer( 0 );
659 DALI_TEST_CHECK( rootLayer );
660 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
662 // Create a new layer and attempt to lower it below the root layer.
663 Layer layer = Layer::New();
665 layer.LowerToBottom();
667 // Check that GetRootLayer still retrieves the same original layer.
668 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
670 // Check modifying the root layer is also blocked.
671 rootLayer.RaiseToTop();
672 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
677 int UtcDaliStageSetBackgroundColorP(void)
679 TestApplication application;
681 Stage stage = Stage::GetCurrent();
683 Vector4 testColor( 0.1f, 0.2f, 0.3f, 1.0f );
684 stage.SetBackgroundColor( testColor );
686 DALI_TEST_EQUALS( testColor, stage.GetBackgroundColor(), TEST_LOCATION );
690 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
691 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
693 int UtcDaliStageGetBackgroundColorP(void)
695 TestApplication application;
697 Stage stage = Stage::GetCurrent();
699 DALI_TEST_EQUALS( Stage::DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION );
703 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
705 int UtcDaliStageKeepRenderingP(void)
707 TestApplication application;
709 Stage stage = Stage::GetCurrent();
711 // Run core until it wants to sleep
712 bool keepUpdating( true );
713 while ( keepUpdating )
715 application.SendNotification();
716 keepUpdating = application.Render( 1000.0f /*1 second*/ );
719 // Force rendering for the next 5 seconds
720 stage.KeepRendering( 5.0f );
722 application.SendNotification();
724 // Test that core wants to sleep after 10 seconds
725 keepUpdating = application.Render( 1000.0f /*1 second*/ );
726 DALI_TEST_CHECK( keepUpdating );
727 keepUpdating = application.Render( 1000.0f /*2 seconds*/ );
728 DALI_TEST_CHECK( keepUpdating );
729 keepUpdating = application.Render( 1000.0f /*3 seconds*/ );
730 DALI_TEST_CHECK( keepUpdating );
731 keepUpdating = application.Render( 1000.0f /*4 seconds*/ );
732 DALI_TEST_CHECK( keepUpdating );
733 keepUpdating = application.Render( 1000.0f /*5 seconds*/ );
734 DALI_TEST_CHECK( !keepUpdating );
738 int UtcDaliStageKeepRenderingN(void)
740 TestApplication application;
742 Stage stage = Stage::GetCurrent();
744 // Run core until it wants to sleep
745 bool keepUpdating( true );
746 while ( keepUpdating )
748 application.SendNotification();
749 keepUpdating = application.Render( 1000.0f /*1 second*/ );
752 // Force rendering for the next 5 seconds
753 stage.KeepRendering( -1.0f );
755 application.SendNotification();
757 // Test that core wants to sleep after 10 seconds
758 keepUpdating = application.Render( 1000.0f /*1 second*/ );
759 DALI_TEST_CHECK( !keepUpdating );
764 int UtcDaliStageEventProcessingFinishedP(void)
766 TestApplication application;
767 Stage stage = Stage::GetCurrent();
769 bool eventProcessingFinished = false;
770 EventProcessingFinishedFunctor functor( eventProcessingFinished );
771 stage.EventProcessingFinishedSignal().Connect( &application, functor );
773 Actor actor( Actor::New() );
776 application.SendNotification();
777 application.Render();
779 DALI_TEST_CHECK( eventProcessingFinished );
784 int UtcDaliStageEventProcessingFinishedN(void)
786 TestApplication application;
787 Stage stage = Stage::GetCurrent();
789 bool eventProcessingFinished = false;
790 EventProcessingFinishedFunctor functor( eventProcessingFinished );
791 stage.EventProcessingFinishedSignal().Connect( &application, functor );
793 Actor actor( Actor::New() );
796 // Do not complete event processing and confirm the signal has not been emitted.
797 DALI_TEST_CHECK( !eventProcessingFinished );
802 int UtcDaliStageSignalKeyEventP(void)
804 TestApplication application;
805 Stage stage = Stage::GetCurrent();
807 KeyEventSignalData data;
808 KeyEventReceivedFunctor functor( data );
809 stage.KeyEventSignal().Connect( &application, functor );
811 Integration::KeyEvent event( "i", "i", 0, 0, 0, Integration::KeyEvent::Down );
812 application.ProcessEvent( event );
814 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
815 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
816 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
817 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
818 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
822 Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up );
823 application.ProcessEvent( event2 );
825 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
826 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
827 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
828 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
829 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
833 Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down );
834 application.ProcessEvent( event3 );
836 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
837 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
838 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
839 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
840 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
844 Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up );
845 application.ProcessEvent( event4 );
847 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
848 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
849 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
850 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
851 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
855 int UtcDaliStageSignalKeyEventN(void)
857 TestApplication application;
858 Stage stage = Stage::GetCurrent();
860 KeyEventSignalData data;
861 KeyEventReceivedFunctor functor( data );
862 stage.KeyEventSignal().Connect( &application, functor );
864 // Check that a non-pressed key events data is not modified.
865 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
870 int UtcDaliStageTouchedSignalP(void)
872 TestApplication application;
873 Stage stage = Stage::GetCurrent();
875 TouchedSignalData data;
876 TouchedFunctor functor( data );
877 stage.TouchedSignal().Connect( &application, functor );
879 // Render and notify.
880 application.SendNotification();
881 application.Render();
883 // Basic test: No actors, single touch (down then up).
885 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
887 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
888 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
889 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
892 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
894 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
895 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
896 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
900 // Add an actor to the scene.
901 Actor actor = Actor::New();
902 actor.SetSize( 100.0f, 100.0f );
903 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
904 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
905 actor.TouchedSignal().Connect( &DummyTouchCallback );
908 // Render and notify.
909 application.SendNotification();
910 application.Render();
912 // Actor on scene, single touch, down in actor, motion, then up outside actor.
914 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
916 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
917 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
918 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
921 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
923 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
926 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
928 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
929 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
930 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
934 // Multiple touch. Should only receive a touch on first down and last up.
936 Integration::TouchEvent touchEvent;
937 Integration::Point point;
940 point.SetState( PointState::DOWN );
941 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
942 touchEvent.points.push_back( point );
943 application.ProcessEvent( touchEvent );
944 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
945 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
949 touchEvent.points[0].SetState( PointState::STATIONARY );
950 point.SetDeviceId( 1 );
951 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
952 touchEvent.points.push_back( point );
953 application.ProcessEvent( touchEvent );
954 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
955 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
958 // Primary point is up
959 touchEvent.points[0].SetState( PointState::UP );
960 touchEvent.points[1].SetState( PointState::STATIONARY );
961 application.ProcessEvent( touchEvent );
962 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
963 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
966 // Remove 1st point now, 2nd point is now in motion
967 touchEvent.points.erase( touchEvent.points.begin() );
968 touchEvent.points[0].SetState( PointState::MOTION );
969 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
970 application.ProcessEvent( touchEvent );
971 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
972 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
976 touchEvent.points[0].SetState( PointState::UP );
977 application.ProcessEvent( touchEvent );
978 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
979 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
985 int UtcDaliStageTouchedSignalN(void)
987 TestApplication application;
988 Stage stage = Stage::GetCurrent();
990 TouchedSignalData data;
991 TouchedFunctor functor( data );
992 stage.TouchedSignal().Connect( &application, functor );
994 // Render and notify.
995 application.SendNotification();
996 application.Render();
998 // Confirm functor not called before there has been any touch event.
999 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1001 // No actors, single touch, down, motion then up.
1003 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1005 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1006 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1007 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1010 // Confirm there is no signal when the touchpoint is only moved.
1011 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1013 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1016 // Confirm a following up event generates a signal.
1017 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1019 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1020 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1021 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1025 // Add an actor to the scene.
1026 Actor actor = Actor::New();
1027 actor.SetSize( 100.0f, 100.0f );
1028 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1029 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1030 actor.TouchedSignal().Connect( &DummyTouchCallback );
1033 // Render and notify.
1034 application.SendNotification();
1035 application.Render();
1037 // Actor on scene. Interrupted before down and interrupted after down.
1039 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1041 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1042 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1043 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1044 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Interrupted );
1047 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1049 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1050 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1051 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
1052 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Down );
1055 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1057 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1058 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1059 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1060 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Interrupted );
1062 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1064 // Check that getting info about a non-existent point causes an assert.
1065 bool asserted = false;
1068 data.receivedTouchEvent.GetPoint( 1 );
1070 catch( Dali::DaliException& e )
1072 DALI_TEST_PRINT_ASSERT( e );
1073 DALI_TEST_ASSERT( e, "point < points.size() && \"No point at index\"", TEST_LOCATION );
1076 DALI_TEST_CHECK( asserted );
1084 int UtcDaliStageSignalWheelEventP(void)
1086 TestApplication application;
1087 Stage stage = Stage::GetCurrent();
1089 WheelEventSignalData data;
1090 WheelEventReceivedFunctor functor( data );
1091 stage.WheelEventSignal().Connect( &application, functor );
1093 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1094 application.ProcessEvent( event );
1096 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1097 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
1098 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
1099 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
1100 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
1101 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
1102 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
1106 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1107 application.ProcessEvent( event2 );
1109 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1110 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
1111 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
1112 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
1113 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
1114 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
1115 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
1119 int UtcDaliStageContextLostSignalP(void)
1121 TestApplication app;
1122 Stage stage = Stage::GetCurrent();
1124 bool contextLost = false;
1125 ContextStatusFunctor contextLostFunctor( contextLost );
1126 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1128 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1129 notifier->NotifyContextLost();
1130 DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1135 int UtcDaliStageContextLostSignalN(void)
1137 TestApplication app;
1140 // Check that connecting to the signal with a bad stage instance causes an assert.
1141 bool asserted = false;
1142 bool contextLost = false;
1143 ContextStatusFunctor contextLostFunctor( contextLost );
1146 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1148 catch( Dali::DaliException& e )
1150 DALI_TEST_PRINT_ASSERT( e );
1151 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1154 DALI_TEST_CHECK( asserted );
1159 int UtcDaliStageContextRegainedSignalP(void)
1161 TestApplication app;
1162 Stage stage = Stage::GetCurrent();
1164 bool contextRegained = false;
1165 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1166 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1168 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1169 notifier->NotifyContextLost();
1170 notifier->NotifyContextRegained();
1171 DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1176 int UtcDaliStageContextRegainedSignalN(void)
1178 TestApplication app;
1181 // Check that connecting to the signal with a bad stage instance causes an assert.
1182 bool asserted = false;
1183 bool contextRegained = false;
1184 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1187 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1189 catch( Dali::DaliException& e )
1191 DALI_TEST_PRINT_ASSERT( e );
1192 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1195 DALI_TEST_CHECK( asserted );
1200 int UtcDaliStageSceneCreatedSignalP(void)
1202 TestApplication app;
1203 Stage stage = Stage::GetCurrent();
1205 bool signalCalled = false;
1206 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1207 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1209 Integration::Core& core = app.GetCore();
1210 core.SceneCreated();
1211 DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1216 int UtcDaliStageSceneCreatedSignalN(void)
1218 TestApplication app;
1221 // Check that connecting to the signal with a bad stage instance causes an assert.
1222 bool asserted = false;
1223 bool signalCalled = false;
1224 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1227 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1229 catch( Dali::DaliException& e )
1231 DALI_TEST_PRINT_ASSERT( e );
1232 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1235 DALI_TEST_CHECK( asserted );
1240 int UtcDaliStageGetRenderTaskListP(void)
1242 TestApplication app;
1243 Stage stage = Stage::GetCurrent();
1245 // Check we get a valid instance.
1246 const RenderTaskList& tasks = stage.GetRenderTaskList();
1248 // There should be 1 task by default.
1249 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1251 // RenderTaskList has it's own UTC tests.
1252 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1253 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1255 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1260 int UtcDaliStageGetRenderTaskListN(void)
1262 TestApplication app;
1265 // Check that getting the render task list with a bad stage instance causes an assert.
1266 bool asserted = false;
1269 stage.GetRenderTaskList();
1271 catch( Dali::DaliException& e )
1273 DALI_TEST_PRINT_ASSERT( e );
1274 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1277 DALI_TEST_CHECK( asserted );
1282 int UtcDaliStageGetObjectRegistryP(void)
1284 TestApplication app;
1285 Stage stage = Stage::GetCurrent();
1287 ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1289 // Object registry tests are covered in their own module.
1290 // However we want a basic test to confirm the returned registry is valid and works.
1291 bool verified = false;
1292 ActorCreatedFunctor test( verified );
1293 objectRegistry.ObjectCreatedSignal().Connect( &app, test );
1295 Actor actor = Actor::New();
1296 DALI_TEST_CHECK( test.mSignalVerified );
1301 int UtcDaliStageGetObjectRegistryN(void)
1303 TestApplication app;
1306 // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1307 // This is because GetCurrent() is used, always creating a stage if one does not exist.
1308 bool asserted = false;
1311 stage.GetObjectRegistry();
1313 catch( Dali::DaliException& e )
1315 DALI_TEST_PRINT_ASSERT( e );
1318 DALI_TEST_CHECK( !asserted );