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 } // unnamed namespace
230 int UtcDaliStageDefaultConstructorP(void)
232 TestApplication application;
235 DALI_TEST_CHECK( !stage );
239 // Note: No negative test for default constructor.
241 int UtcDaliStageDestructorP(void)
243 TestApplication application;
244 Stage* stage = new Stage();
248 DALI_TEST_CHECK( true );
252 // Note: No negative test for default destructor.
254 int UtcDaliStageGetCurrentP(void)
256 TestApplication application;
257 Stage stage = Stage::GetCurrent();
259 DALI_TEST_CHECK( stage );
263 int UtcDaliStageGetCurrentN(void)
265 bool asserted = false;
268 Stage stage = Stage::GetCurrent();
270 catch( Dali::DaliException& e )
272 DALI_TEST_PRINT_ASSERT( e );
273 DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
277 DALI_TEST_CHECK( asserted );
281 int UtcDaliStageIsInstalledP(void)
283 TestApplication application;
287 DALI_TEST_CHECK( Stage::IsInstalled() );
291 int UtcDaliStageIsInstalledN(void)
293 DALI_TEST_CHECK( !Stage::IsInstalled() );
298 int UtcDaliStageCopyConstructorP(void)
300 TestApplication application;
301 Stage stage = Stage::GetCurrent();
303 Stage copyStage( stage );
305 DALI_TEST_CHECK( copyStage );
306 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
311 // Note: no negative test for UtcDaliStageCopyConstructor.
313 int UtcDaliStageAssignmentOperatorP(void)
315 TestApplication application;
316 const Stage stage = Stage::GetCurrent();
318 Stage copyStage = stage;
320 DALI_TEST_CHECK( copyStage );
321 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
326 // Note: No negative test for UtcDaliStageAssignmentOperator.
328 int UtcDaliStageAddP(void)
330 TestApplication application;
332 Stage stage = Stage::GetCurrent();
334 Actor actor = Actor::New();
335 DALI_TEST_CHECK( !actor.OnStage() );
338 DALI_TEST_CHECK( actor.OnStage() );
342 int UtcDaliStageAddN(void)
344 TestApplication application;
346 Stage stage = Stage::GetCurrent();
349 bool asserted = false;
354 catch( Dali::DaliException& e )
356 DALI_TEST_PRINT_ASSERT( e );
357 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
361 DALI_TEST_CHECK( asserted );
366 int UtcDaliStageRemoveP(void)
368 TestApplication application;
370 Stage stage = Stage::GetCurrent();
372 Actor actor = Actor::New();
373 DALI_TEST_CHECK( !actor.OnStage() );
376 DALI_TEST_CHECK( actor.OnStage() );
379 DALI_TEST_CHECK( !actor.OnStage() );
383 int UtcDaliStageRemoveN1(void)
385 TestApplication application;
387 Stage stage = Stage::GetCurrent();
390 bool asserted = false;
393 // Actor is not valid, confirm a removal attempt does assert.
394 stage.Remove( actor );
396 catch( Dali::DaliException& e )
398 DALI_TEST_PRINT_ASSERT( e );
399 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
403 DALI_TEST_CHECK( asserted );
407 int UtcDaliStageRemoveN2(void)
409 TestApplication application;
411 Stage stage = Stage::GetCurrent();
412 Actor actor = Actor::New();
413 DALI_TEST_CHECK( !actor.OnStage() );
415 bool asserted = false;
418 // Actor is not on stage, confirm a removal attempt does not assert / segfault.
419 stage.Remove( actor );
421 catch( Dali::DaliException& e )
423 DALI_TEST_PRINT_ASSERT( e );
427 DALI_TEST_CHECK( !asserted );
431 int UtcDaliStageRemoveN3(void)
433 TestApplication application;
435 Stage stage = Stage::GetCurrent();
437 // Initially we have a default layer
438 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
440 // Check we cannot remove the root layer from the stage.
441 Layer layer = stage.GetRootLayer();
442 bool asserted = true;
445 stage.Remove( layer );
447 catch( Dali::DaliException& e )
449 DALI_TEST_PRINT_ASSERT( e );
450 DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
454 DALI_TEST_CHECK( asserted );
455 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
459 int UtcDaliStageGetSizeP(void)
461 TestApplication application;
463 Stage stage = Stage::GetCurrent();
465 Vector2 size = stage.GetSize();
467 DALI_TEST_EQUALS( size.width, static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ), TEST_LOCATION );
468 DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
472 int UtcDaliStageGetSizeN(void)
474 TestApplication application;
478 bool asserted = false;
482 size = stage.GetSize();
484 catch( Dali::DaliException& e )
486 DALI_TEST_PRINT_ASSERT( e );
487 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
491 DALI_TEST_CHECK( asserted );
495 int UtcDaliStageGetDpiP1(void)
497 TestApplication application; // Initializes core DPI to default values
499 Stage stage = Stage::GetCurrent();
501 // Test the default DPI.
502 Vector2 dpi = stage.GetDpi();
503 DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
504 DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ), TEST_LOCATION );
508 int UtcDaliStageGetDpiP2(void)
510 TestApplication application; // Initializes core DPI to default values
512 // Test that setting core DPI explicitly also sets up the Stage's DPI.
513 application.GetCore().SetDpi( 200, 180 );
515 Stage stage = Stage::GetCurrent();
516 Vector2 dpi = stage.GetDpi();
517 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
518 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
522 int UtcDaliStageGetDpiP3(void)
524 TestApplication application( 480, 800, 72.0f, 120.0f ); // Initializes core DPI with specific values
526 Stage stage = Stage::GetCurrent();
528 // Test that setting core DPI explicitly also sets up the Stage's DPI.
529 Vector2 dpi = stage.GetDpi();
530 DALI_TEST_EQUALS( dpi.x, 72.0f, TEST_LOCATION );
531 DALI_TEST_EQUALS( dpi.y, 120.0f, TEST_LOCATION) ;
536 * This is not a true negative test, we are checking the DPI if it has not been set.
537 * A test for setting negative DPI values would be part of the application core utc tests.
539 int UtcDaliStageGetDpiN(void)
541 TestApplication application; // Initializes core DPI to default values
543 Stage stage = Stage::GetCurrent();
544 Vector2 dpi = stage.GetDpi();
546 DALI_TEST_EQUALS( dpi.x, 220.0f, TEST_LOCATION );
547 DALI_TEST_EQUALS( dpi.y, 217.0f, TEST_LOCATION );
551 int UtcDaliStageGetLayerCountP(void)
553 TestApplication application;
555 Stage stage = Stage::GetCurrent();
557 // Initially we have a default layer
558 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
560 Layer layer = Layer::New();
563 DALI_TEST_EQUALS( stage.GetLayerCount(), 2u, TEST_LOCATION );
568 * Not a true negative test, but confirms layer count is not affected by an invalid removal.
570 int UtcDaliStageGetLayerCountN(void)
572 TestApplication application;
574 Stage stage = Stage::GetCurrent();
576 // Initially we have a default layer
577 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
579 Layer layer = Layer::New();
580 stage.Remove( layer );
582 // Still have 1 layer.
583 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
587 int UtcDaliStageGetLayerP(void)
589 TestApplication application;
591 Stage stage = Stage::GetCurrent();
593 Layer rootLayer = stage.GetLayer( 0 );
594 DALI_TEST_CHECK( rootLayer );
596 Layer layer = Layer::New();
599 Layer sameLayer = stage.GetLayer( 1 );
600 DALI_TEST_CHECK( layer == sameLayer );
604 int UtcDaliStageGetLayerN(void)
606 TestApplication application;
608 Stage stage = Stage::GetCurrent();
610 bool asserted = false;
613 // Try to get a layer that doesn't exist (note: 0 is the root layer).
614 Layer layer = stage.GetLayer( 1 );
616 catch( Dali::DaliException& e )
618 DALI_TEST_PRINT_ASSERT( e );
619 DALI_TEST_ASSERT( e, "depth < mLayers.size()", TEST_LOCATION );
623 DALI_TEST_CHECK( asserted );
627 int UtcDaliStageGetRootLayerP(void)
629 TestApplication application;
631 Stage stage = Stage::GetCurrent();
633 Layer layer = stage.GetLayer( 0 );
634 DALI_TEST_CHECK( layer );
636 // Check that GetRootLayer() correctly retreived layer 0.
637 DALI_TEST_CHECK( stage.GetRootLayer() == layer );
642 int UtcDaliStageGetRootLayerN(void)
644 TestApplication application;
646 Stage stage = Stage::GetCurrent();
648 Layer rootLayer = stage.GetLayer( 0 );
649 DALI_TEST_CHECK( rootLayer );
650 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
652 // Create a new layer and attempt to lower it below the root layer.
653 Layer layer = Layer::New();
655 layer.LowerToBottom();
657 // Check that GetRootLayer still retrieves the same original layer.
658 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
660 // Check modifying the root layer is also blocked.
661 rootLayer.RaiseToTop();
662 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
667 int UtcDaliStageSetBackgroundColorP(void)
669 TestApplication application;
671 Stage stage = Stage::GetCurrent();
673 Vector4 testColor( 0.1f, 0.2f, 0.3f, 1.0f );
674 stage.SetBackgroundColor( testColor );
676 DALI_TEST_EQUALS( testColor, stage.GetBackgroundColor(), TEST_LOCATION );
680 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
681 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
683 int UtcDaliStageGetBackgroundColorP(void)
685 TestApplication application;
687 Stage stage = Stage::GetCurrent();
689 DALI_TEST_EQUALS( Stage::DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION );
693 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
695 int UtcDaliStageKeepRenderingP(void)
697 TestApplication application;
699 Stage stage = Stage::GetCurrent();
701 // Run core until it wants to sleep
702 bool keepUpdating( true );
703 while ( keepUpdating )
705 application.SendNotification();
706 keepUpdating = application.Render( 1000.0f /*1 second*/ );
709 // Force rendering for the next 5 seconds
710 stage.KeepRendering( 5.0f );
712 application.SendNotification();
714 // Test that core wants to sleep after 10 seconds
715 keepUpdating = application.Render( 1000.0f /*1 second*/ );
716 DALI_TEST_CHECK( keepUpdating );
717 keepUpdating = application.Render( 1000.0f /*2 seconds*/ );
718 DALI_TEST_CHECK( keepUpdating );
719 keepUpdating = application.Render( 1000.0f /*3 seconds*/ );
720 DALI_TEST_CHECK( keepUpdating );
721 keepUpdating = application.Render( 1000.0f /*4 seconds*/ );
722 DALI_TEST_CHECK( keepUpdating );
723 keepUpdating = application.Render( 1000.0f /*5 seconds*/ );
724 DALI_TEST_CHECK( !keepUpdating );
728 int UtcDaliStageKeepRenderingN(void)
730 TestApplication application;
732 Stage stage = Stage::GetCurrent();
734 // Run core until it wants to sleep
735 bool keepUpdating( true );
736 while ( keepUpdating )
738 application.SendNotification();
739 keepUpdating = application.Render( 1000.0f /*1 second*/ );
742 // Force rendering for the next 5 seconds
743 stage.KeepRendering( -1.0f );
745 application.SendNotification();
747 // Test that core wants to sleep after 10 seconds
748 keepUpdating = application.Render( 1000.0f /*1 second*/ );
749 DALI_TEST_CHECK( !keepUpdating );
754 int UtcDaliStageEventProcessingFinishedP(void)
756 TestApplication application;
757 Stage stage = Stage::GetCurrent();
759 bool eventProcessingFinished = false;
760 EventProcessingFinishedFunctor functor( eventProcessingFinished );
761 stage.EventProcessingFinishedSignal().Connect( &application, functor );
763 Actor actor( Actor::New() );
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_CHECK( eventProcessingFinished );
774 int UtcDaliStageEventProcessingFinishedN(void)
776 TestApplication application;
777 Stage stage = Stage::GetCurrent();
779 bool eventProcessingFinished = false;
780 EventProcessingFinishedFunctor functor( eventProcessingFinished );
781 stage.EventProcessingFinishedSignal().Connect( &application, functor );
783 Actor actor( Actor::New() );
786 // Do not complete event processing and confirm the signal has not been emitted.
787 DALI_TEST_CHECK( !eventProcessingFinished );
792 int UtcDaliStageSignalKeyEventP(void)
794 TestApplication application;
795 Stage stage = Stage::GetCurrent();
797 KeyEventSignalData data;
798 KeyEventReceivedFunctor functor( data );
799 stage.KeyEventSignal().Connect( &application, functor );
801 Integration::KeyEvent event( "i", "i", 0, 0, 0, Integration::KeyEvent::Down );
802 application.ProcessEvent( event );
804 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
805 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
806 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
807 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
808 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
812 Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up );
813 application.ProcessEvent( event2 );
815 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
816 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
817 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
818 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
819 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
823 Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down );
824 application.ProcessEvent( event3 );
826 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
827 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
828 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
829 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
830 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
834 Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up );
835 application.ProcessEvent( event4 );
837 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
838 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
839 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
840 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
841 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
845 int UtcDaliStageSignalKeyEventN(void)
847 TestApplication application;
848 Stage stage = Stage::GetCurrent();
850 KeyEventSignalData data;
851 KeyEventReceivedFunctor functor( data );
852 stage.KeyEventSignal().Connect( &application, functor );
854 // Check that a non-pressed key events data is not modified.
855 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
860 int UtcDaliStageTouchedSignalP(void)
862 TestApplication application;
863 Stage stage = Stage::GetCurrent();
865 TouchedSignalData data;
866 TouchedFunctor functor( data );
867 stage.TouchedSignal().Connect( &application, functor );
869 // Render and notify.
870 application.SendNotification();
871 application.Render();
873 // Basic test: No actors, single touch (down then up).
875 Integration::TouchEvent touchEvent;
876 touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Down, 10.0f, 10.0f ) );
877 application.ProcessEvent( touchEvent );
879 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
880 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
881 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
884 touchEvent.points[0].state = TouchPoint::Up;
885 application.ProcessEvent( touchEvent );
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 );
893 // Add an actor to the scene.
894 Actor actor = Actor::New();
895 actor.SetSize( 100.0f, 100.0f );
896 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
897 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
898 actor.TouchedSignal().Connect( &DummyTouchCallback );
901 // Render and notify.
902 application.SendNotification();
903 application.Render();
905 // Actor on scene, single touch, down in actor, motion, then up outside actor.
907 Integration::TouchEvent touchEvent;
908 touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Down, 10.0f, 10.0f ) );
909 application.ProcessEvent( touchEvent );
911 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
912 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
913 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
916 touchEvent.points[0].state = TouchPoint::Motion;
917 touchEvent.points[0].screen.x = 150.0f; // Some motion
918 application.ProcessEvent( touchEvent );
920 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
923 touchEvent.points[0].state = TouchPoint::Up;
924 application.ProcessEvent( touchEvent );
926 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
927 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
928 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
932 // Multiple touch. Should only receive a touch on first down and last up.
934 Integration::TouchEvent touchEvent;
937 touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Down, 10.0f, 10.0f ) );
938 application.ProcessEvent( touchEvent );
939 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
940 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
944 touchEvent.points[0].state = TouchPoint::Stationary;
945 touchEvent.points.push_back( TouchPoint( 1, TouchPoint::Down, 50.0f, 50.0f ) );
946 application.ProcessEvent( touchEvent );
947 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
948 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
951 // Primary point is up
952 touchEvent.points[0].state = TouchPoint::Up;
953 touchEvent.points[1].state = TouchPoint::Stationary;
954 application.ProcessEvent( touchEvent );
955 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
956 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
959 // Remove 1st point now, 2nd point is now in motion
960 touchEvent.points.erase( touchEvent.points.begin() );
961 touchEvent.points[0].state = TouchPoint::Motion;
962 touchEvent.points[0].screen.x = 150.0f;
963 application.ProcessEvent( touchEvent );
964 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
965 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 0u, TEST_LOCATION );
969 touchEvent.points[0].state = TouchPoint::Up;
970 application.ProcessEvent( touchEvent );
971 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
972 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
978 int UtcDaliStageTouchedSignalN(void)
980 TestApplication application;
981 Stage stage = Stage::GetCurrent();
983 TouchedSignalData data;
984 TouchedFunctor functor( data );
985 stage.TouchedSignal().Connect( &application, functor );
987 // Render and notify.
988 application.SendNotification();
989 application.Render();
991 // Confirm functor not called before there has been any touch event.
992 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
994 // No actors, single touch, down, motion then up.
996 Integration::TouchEvent touchEvent;
997 touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Down, 10.0f, 10.0f ) );
998 application.ProcessEvent( touchEvent );
1000 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1001 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1002 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1005 // Confirm there is no signal when the touchpoint is only moved.
1006 touchEvent.points[0].state = TouchPoint::Motion;
1007 touchEvent.points[0].screen.x = 1200.0f; // Some motion
1008 application.ProcessEvent( touchEvent );
1010 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1013 // Confirm a following up event generates a signal.
1014 touchEvent.points[0].state = TouchPoint::Up;
1015 application.ProcessEvent( touchEvent );
1017 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1018 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1019 DALI_TEST_CHECK( !data.receivedTouchEvent.points[0].hitActor );
1023 // Add an actor to the scene.
1024 Actor actor = Actor::New();
1025 actor.SetSize( 100.0f, 100.0f );
1026 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1027 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1028 actor.TouchedSignal().Connect( &DummyTouchCallback );
1031 // Render and notify.
1032 application.SendNotification();
1033 application.Render();
1035 // Actor on scene. Interrupted before down and interrupted after down.
1037 Integration::TouchEvent touchEvent;
1038 touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Interrupted, 10.0f, 10.0f ) );
1039 application.ProcessEvent( touchEvent );
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 touchEvent.points[0].state = TouchPoint::Down;
1048 application.ProcessEvent( touchEvent );
1050 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1051 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1052 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].hitActor == actor );
1053 DALI_TEST_CHECK( data.receivedTouchEvent.points[0].state == TouchPoint::Down );
1056 touchEvent.points[0].state = TouchPoint::Interrupted;
1057 application.ProcessEvent( touchEvent );
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 );
1064 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1066 // Check that getting info about a non-existent point causes an assert.
1067 bool asserted = false;
1070 data.receivedTouchEvent.GetPoint( 1 );
1072 catch( Dali::DaliException& e )
1074 DALI_TEST_PRINT_ASSERT( e );
1075 DALI_TEST_ASSERT( e, "point < points.size() && \"No point at index\"", TEST_LOCATION );
1078 DALI_TEST_CHECK( asserted );
1086 int UtcDaliStageSignalWheelEventP(void)
1088 TestApplication application;
1089 Stage stage = Stage::GetCurrent();
1091 WheelEventSignalData data;
1092 WheelEventReceivedFunctor functor( data );
1093 stage.WheelEventSignal().Connect( &application, functor );
1095 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1096 application.ProcessEvent( event );
1098 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1099 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
1100 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
1101 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
1102 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
1103 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
1104 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
1108 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1109 application.ProcessEvent( event2 );
1111 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1112 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
1113 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
1114 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
1115 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
1116 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
1117 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
1121 int UtcDaliStageContextLostSignalP(void)
1123 TestApplication app;
1124 Stage stage = Stage::GetCurrent();
1126 bool contextLost = false;
1127 ContextStatusFunctor contextLostFunctor( contextLost );
1128 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1130 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1131 notifier->NotifyContextLost();
1132 DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1137 int UtcDaliStageContextLostSignalN(void)
1139 TestApplication app;
1142 // Check that connecting to the signal with a bad stage instance causes an assert.
1143 bool asserted = false;
1144 bool contextLost = false;
1145 ContextStatusFunctor contextLostFunctor( contextLost );
1148 stage.ContextLostSignal().Connect( &app, contextLostFunctor );
1150 catch( Dali::DaliException& e )
1152 DALI_TEST_PRINT_ASSERT( e );
1153 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1156 DALI_TEST_CHECK( asserted );
1161 int UtcDaliStageContextRegainedSignalP(void)
1163 TestApplication app;
1164 Stage stage = Stage::GetCurrent();
1166 bool contextRegained = false;
1167 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1168 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1170 Integration::ContextNotifierInterface* notifier = app.GetCore().GetContextNotifier();
1171 notifier->NotifyContextLost();
1172 notifier->NotifyContextRegained();
1173 DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1178 int UtcDaliStageContextRegainedSignalN(void)
1180 TestApplication app;
1183 // Check that connecting to the signal with a bad stage instance causes an assert.
1184 bool asserted = false;
1185 bool contextRegained = false;
1186 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1189 stage.ContextRegainedSignal().Connect( &app, contextRegainedFunctor );
1191 catch( Dali::DaliException& e )
1193 DALI_TEST_PRINT_ASSERT( e );
1194 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1197 DALI_TEST_CHECK( asserted );
1202 int UtcDaliStageSceneCreatedSignalP(void)
1204 TestApplication app;
1205 Stage stage = Stage::GetCurrent();
1207 bool signalCalled = false;
1208 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1209 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1211 Integration::Core& core = app.GetCore();
1212 core.SceneCreated();
1213 DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1218 int UtcDaliStageSceneCreatedSignalN(void)
1220 TestApplication app;
1223 // Check that connecting to the signal with a bad stage instance causes an assert.
1224 bool asserted = false;
1225 bool signalCalled = false;
1226 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1229 stage.SceneCreatedSignal().Connect( &app, sceneCreatedFunctor );
1231 catch( Dali::DaliException& e )
1233 DALI_TEST_PRINT_ASSERT( e );
1234 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1237 DALI_TEST_CHECK( asserted );
1242 int UtcDaliStageGetRenderTaskListP(void)
1244 TestApplication app;
1245 Stage stage = Stage::GetCurrent();
1247 // Check we get a valid instance.
1248 const RenderTaskList& tasks = stage.GetRenderTaskList();
1250 // There should be 1 task by default.
1251 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1253 // RenderTaskList has it's own UTC tests.
1254 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1255 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1257 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1262 int UtcDaliStageGetRenderTaskListN(void)
1264 TestApplication app;
1267 // Check that getting the render task list with a bad stage instance causes an assert.
1268 bool asserted = false;
1271 stage.GetRenderTaskList();
1273 catch( Dali::DaliException& e )
1275 DALI_TEST_PRINT_ASSERT( e );
1276 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1279 DALI_TEST_CHECK( asserted );
1284 int UtcDaliStageGetObjectRegistryP(void)
1286 TestApplication app;
1287 Stage stage = Stage::GetCurrent();
1289 ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1291 // Object registry tests are covered in their own module.
1292 // However we want a basic test to confirm the returned registry is valid and works.
1293 bool verified = false;
1294 ActorCreatedFunctor test( verified );
1295 objectRegistry.ObjectCreatedSignal().Connect( &app, test );
1297 Actor actor = Actor::New();
1298 DALI_TEST_CHECK( test.mSignalVerified );
1303 int UtcDaliStageGetObjectRegistryN(void)
1305 TestApplication app;
1308 // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1309 // This is because GetCurrent() is used, always creating a stage if one does not exist.
1310 bool asserted = false;
1313 stage.GetObjectRegistry();
1315 catch( Dali::DaliException& e )
1317 DALI_TEST_PRINT_ASSERT( e );
1320 DALI_TEST_CHECK( !asserted );