2 * Copyright (c) 2020 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/devel-api/common/stage-devel.h>
24 #include <dali/integration-api/context-notifier.h>
25 #include <dali/integration-api/events/key-event-integ.h>
26 #include <dali/public-api/events/key-event.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28 #include <dali/integration-api/events/wheel-event-integ.h>
30 #include <dali-test-suite-utils.h>
34 void stage_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void stage_test_cleanup(void)
41 test_return_value = TET_PASS;
47 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
49 // Functor for EventProcessingFinished signal
50 struct EventProcessingFinishedFunctor
53 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
55 EventProcessingFinishedFunctor( bool& eventProcessingFinished )
56 : mEventProcessingFinished( eventProcessingFinished )
61 mEventProcessingFinished = true;
64 bool& mEventProcessingFinished;
67 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
68 struct KeyEventGeneratedSignalData
70 KeyEventGeneratedSignalData()
71 : functorCalled(false)
76 functorCalled = false;
78 receivedKeyEvent.keyModifier = 0;
79 receivedKeyEvent.keyPressedName.clear();
80 receivedKeyEvent.keyPressed.clear();
84 KeyEvent receivedKeyEvent;
87 // Functor that sets the data when called
88 struct KeyEventGeneratedReceivedFunctor
90 KeyEventGeneratedReceivedFunctor( KeyEventGeneratedSignalData& data )
94 bool operator()( const KeyEvent& keyEvent )
96 signalData.functorCalled = true;
97 signalData.receivedKeyEvent = keyEvent;
104 signalData.functorCalled = true;
108 KeyEventGeneratedSignalData& signalData;
111 // Stores data that is populated in the key-event callback and will be read by the TET cases
112 struct KeyEventSignalData
115 : functorCalled(false)
120 functorCalled = false;
122 receivedKeyEvent.keyModifier = 0;
123 receivedKeyEvent.keyPressedName.clear();
124 receivedKeyEvent.keyPressed.clear();
128 KeyEvent receivedKeyEvent;
131 // Functor that sets the data when called
132 struct KeyEventReceivedFunctor
134 KeyEventReceivedFunctor( KeyEventSignalData& data ) : signalData( data ) { }
136 bool operator()( const KeyEvent& keyEvent )
138 signalData.functorCalled = true;
139 signalData.receivedKeyEvent = keyEvent;
144 KeyEventSignalData& signalData;
147 // Stores data that is populated in the touched signal callback and will be read by the TET cases
148 struct TouchSignalData
151 : functorCalled(false)
156 functorCalled = false;
158 receivedTouchEvent.Reset();
162 TouchEvent receivedTouchEvent;
165 // Functor that sets the data when touched signal is received
168 TouchFunctor( TouchSignalData& data ) : signalData( data ) { }
170 void operator()( const TouchEvent& touch )
172 signalData.functorCalled = true;
173 TouchEvent handle(touch);
174 signalData.receivedTouchEvent = handle;
179 signalData.functorCalled = true;
182 TouchSignalData& signalData;
185 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
186 struct WheelEventSignalData
188 WheelEventSignalData()
189 : functorCalled(false)
194 functorCalled = false;
198 WheelEvent receivedWheelEvent;
201 // Functor that sets the data when wheel-event signal is received
202 struct WheelEventReceivedFunctor
204 WheelEventReceivedFunctor( WheelEventSignalData& data ) : signalData( data ) { }
206 bool operator()( const WheelEvent& wheelEvent )
208 signalData.functorCalled = true;
209 signalData.receivedWheelEvent = wheelEvent;
214 WheelEventSignalData& signalData;
217 bool DummyTouchCallback( Actor actor, const TouchEvent& touch )
222 struct ContextStatusFunctor
224 ContextStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
241 struct SceneCreatedStatusFunctor
243 SceneCreatedStatusFunctor(bool& calledFlag) : mCalledFlag( calledFlag )
260 struct ActorCreatedFunctor
262 ActorCreatedFunctor( bool& signalReceived )
263 : mSignalVerified( signalReceived )
267 void operator()( BaseHandle object )
269 tet_infoline( "Verifying TestActorCallback()" );
270 Actor actor = Actor::DownCast( object );
273 mSignalVerified = true;
277 bool& mSignalVerified;
280 void GenerateTouch( TestApplication& application, PointState::Type state, const Vector2& screenPosition )
282 Integration::TouchEvent touchEvent;
283 Integration::Point point;
284 point.SetState( state );
285 point.SetScreenPosition( screenPosition );
286 touchEvent.points.push_back( point );
287 application.ProcessEvent( touchEvent );
290 } // unnamed namespace
293 int UtcDaliStageDefaultConstructorP(void)
295 TestApplication application;
298 DALI_TEST_CHECK( !stage );
302 // Note: No negative test for default constructor.
304 int UtcDaliStageDestructorP(void)
306 TestApplication application;
307 Stage* stage = new Stage();
311 DALI_TEST_CHECK( true );
315 // Note: No negative test for default destructor.
317 int UtcDaliStageGetCurrentP(void)
319 TestApplication application;
320 Stage stage = Stage::GetCurrent();
322 DALI_TEST_CHECK( stage );
326 int UtcDaliStageGetCurrentN(void)
328 bool asserted = false;
331 Stage stage = Stage::GetCurrent();
333 catch( Dali::DaliException& e )
335 DALI_TEST_PRINT_ASSERT( e );
336 DALI_TEST_ASSERT( e, "stage && \"Stage doesn't exist\"", TEST_LOCATION );
340 DALI_TEST_CHECK( asserted );
344 int UtcDaliStageIsInstalledP(void)
346 TestApplication application;
350 DALI_TEST_CHECK( Stage::IsInstalled() );
354 int UtcDaliStageIsInstalledN(void)
356 DALI_TEST_CHECK( !Stage::IsInstalled() );
361 int UtcDaliStageCopyConstructorP(void)
363 TestApplication application;
364 Stage stage = Stage::GetCurrent();
366 Stage copyStage( stage );
368 DALI_TEST_CHECK( copyStage );
369 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
374 // Note: no negative test for UtcDaliStageCopyConstructor.
376 int UtcDaliStageAssignmentOperatorP(void)
378 TestApplication application;
379 const Stage stage = Stage::GetCurrent();
381 Stage copyStage = stage;
383 DALI_TEST_CHECK( copyStage );
384 DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() );
389 // Note: No negative test for UtcDaliStageAssignmentOperator.
391 int UtcDaliStageAddP(void)
393 TestApplication application;
395 Stage stage = Stage::GetCurrent();
397 Actor actor = Actor::New();
398 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
401 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
405 int UtcDaliStageAddN(void)
407 TestApplication application;
409 Stage stage = Stage::GetCurrent();
412 bool asserted = false;
417 catch( Dali::DaliException& e )
419 DALI_TEST_PRINT_ASSERT( e );
420 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
424 DALI_TEST_CHECK( asserted );
429 int UtcDaliStageRemoveP(void)
431 TestApplication application;
433 Stage stage = Stage::GetCurrent();
435 Actor actor = Actor::New();
436 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
439 DALI_TEST_CHECK( actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
442 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
446 int UtcDaliStageRemoveN1(void)
448 TestApplication application;
450 Stage stage = Stage::GetCurrent();
453 bool asserted = false;
456 // Actor is not valid, confirm a removal attempt does assert.
457 stage.Remove( actor );
459 catch( Dali::DaliException& e )
461 DALI_TEST_PRINT_ASSERT( e );
462 DALI_TEST_ASSERT( e, "actor && \"Actor handle is empty\"", TEST_LOCATION );
466 DALI_TEST_CHECK( asserted );
470 int UtcDaliStageRemoveN2(void)
472 TestApplication application;
474 Stage stage = Stage::GetCurrent();
475 Actor actor = Actor::New();
476 DALI_TEST_CHECK( !actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) );
478 bool asserted = false;
481 // Actor is not on stage, confirm a removal attempt does not assert / segfault.
482 stage.Remove( actor );
484 catch( Dali::DaliException& e )
486 DALI_TEST_PRINT_ASSERT( e );
490 DALI_TEST_CHECK( !asserted );
494 int UtcDaliStageRemoveN3(void)
496 TestApplication application;
498 Stage stage = Stage::GetCurrent();
500 // Initially we have a default layer
501 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
503 // Check we cannot remove the root layer from the stage.
504 Layer layer = stage.GetRootLayer();
505 bool asserted = true;
508 stage.Remove( layer );
510 catch( Dali::DaliException& e )
512 DALI_TEST_PRINT_ASSERT( e );
513 DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION );
517 DALI_TEST_CHECK( asserted );
518 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
522 int UtcDaliStageGetSizeP(void)
524 TestApplication application;
526 Stage stage = Stage::GetCurrent();
528 Vector2 size = stage.GetSize();
530 DALI_TEST_EQUALS( size.width, static_cast<float>( TestApplication::DEFAULT_SURFACE_WIDTH ), TEST_LOCATION );
531 DALI_TEST_EQUALS( size.height, static_cast<float>( TestApplication::DEFAULT_SURFACE_HEIGHT ), TEST_LOCATION );
535 int UtcDaliStageGetSizeN(void)
537 TestApplication application;
541 bool asserted = false;
545 size = stage.GetSize();
547 catch( Dali::DaliException& e )
549 DALI_TEST_PRINT_ASSERT( e );
550 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
554 DALI_TEST_CHECK( asserted );
558 int UtcDaliStageGetDpiP1(void)
560 TestApplication application; // Initializes core DPI to default values
562 Stage stage = Stage::GetCurrent();
564 // Test the default DPI.
565 Vector2 dpi = stage.GetDpi();
566 DALI_TEST_EQUALS( dpi.x, static_cast<float>( TestApplication::DEFAULT_HORIZONTAL_DPI ), TEST_LOCATION );
567 DALI_TEST_EQUALS( dpi.y, static_cast<float>( TestApplication::DEFAULT_VERTICAL_DPI ), TEST_LOCATION );
571 int UtcDaliStageGetDpiP2(void)
573 TestApplication application; // Initializes core DPI to default values
575 // Test that setting core DPI explicitly also sets up the Stage's DPI.
576 Dali::Integration::Scene scene = application.GetScene();
577 scene.SetDpi( Vector2(200.0f, 180.0f) );
579 Stage stage = Stage::GetCurrent();
580 Vector2 dpi = stage.GetDpi();
581 DALI_TEST_EQUALS( dpi.x, 200.0f, TEST_LOCATION );
582 DALI_TEST_EQUALS( dpi.y, 180.0f, TEST_LOCATION );
586 int UtcDaliStageGetDpiP3(void)
588 TestApplication application( 480, 800, 72, 120 ); // Initializes core DPI with specific values
590 Stage stage = Stage::GetCurrent();
592 // Test that setting core DPI explicitly also sets up the Stage's DPI.
593 Vector2 dpi = stage.GetDpi();
594 DALI_TEST_EQUALS( dpi.x, 72.0f, TEST_LOCATION );
595 DALI_TEST_EQUALS( dpi.y, 120.0f, TEST_LOCATION) ;
600 * This is not a true negative test, we are checking the DPI if it has not been set.
601 * A test for setting negative DPI values would be part of the application core utc tests.
603 int UtcDaliStageGetDpiN(void)
605 TestApplication application; // Initializes core DPI to default values
607 Stage stage = Stage::GetCurrent();
608 Vector2 dpi = stage.GetDpi();
610 DALI_TEST_EQUALS( dpi.x, 220.0f, TEST_LOCATION );
611 DALI_TEST_EQUALS( dpi.y, 217.0f, TEST_LOCATION );
615 int UtcDaliStageGetLayerCountP(void)
617 TestApplication application;
619 Stage stage = Stage::GetCurrent();
621 // Initially we have a default layer
622 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
624 Layer layer = Layer::New();
627 DALI_TEST_EQUALS( stage.GetLayerCount(), 2u, TEST_LOCATION );
632 * Not a true negative test, but confirms layer count is not affected by an invalid removal.
634 int UtcDaliStageGetLayerCountN(void)
636 TestApplication application;
638 Stage stage = Stage::GetCurrent();
640 // Initially we have a default layer
641 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
643 Layer layer = Layer::New();
644 stage.Remove( layer );
646 // Still have 1 layer.
647 DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION );
651 int UtcDaliStageGetLayerP(void)
653 TestApplication application;
655 Stage stage = Stage::GetCurrent();
657 Layer rootLayer = stage.GetLayer( 0 );
658 DALI_TEST_CHECK( rootLayer );
660 Layer layer = Layer::New();
663 Layer sameLayer = stage.GetLayer( 1 );
664 DALI_TEST_CHECK( layer == sameLayer );
668 int UtcDaliStageGetLayerN(void)
670 TestApplication application;
672 Stage stage = Stage::GetCurrent();
674 bool asserted = false;
677 // Try to get a layer that doesn't exist (note: 0 is the root layer).
678 Layer layer = stage.GetLayer( 1 );
680 catch( Dali::DaliException& e )
682 DALI_TEST_PRINT_ASSERT( e );
683 DALI_TEST_ASSERT( e, "depth < mLayers.size()", TEST_LOCATION );
687 DALI_TEST_CHECK( asserted );
691 int UtcDaliStageGetRootLayerP(void)
693 TestApplication application;
695 Stage stage = Stage::GetCurrent();
697 Layer layer = stage.GetLayer( 0 );
698 DALI_TEST_CHECK( layer );
700 // Check that GetRootLayer() correctly retreived layer 0.
701 DALI_TEST_CHECK( stage.GetRootLayer() == layer );
706 int UtcDaliStageGetRootLayerN(void)
708 TestApplication application;
710 Stage stage = Stage::GetCurrent();
712 Layer rootLayer = stage.GetLayer( 0 );
713 DALI_TEST_CHECK( rootLayer );
714 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
716 // Create a new layer and attempt to lower it below the root layer.
717 Layer layer = Layer::New();
719 layer.LowerToBottom();
721 // Check that GetRootLayer still retrieves the same original layer.
722 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
724 // Check modifying the root layer is also blocked.
725 rootLayer.RaiseToTop();
726 DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer );
731 int UtcDaliStageSetBackgroundColorP(void)
733 TestApplication application;
735 Stage stage = Stage::GetCurrent();
737 Vector4 testColor( 0.1f, 0.2f, 0.3f, 1.0f );
738 stage.SetBackgroundColor( testColor );
740 DALI_TEST_EQUALS( testColor, stage.GetBackgroundColor(), TEST_LOCATION );
744 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
745 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
747 int UtcDaliStageGetBackgroundColorP(void)
749 TestApplication application;
751 Stage stage = Stage::GetCurrent();
753 DALI_TEST_EQUALS( Stage::DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION );
757 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
759 int UtcDaliStageKeepRenderingP(void)
761 TestApplication application;
763 Stage stage = Stage::GetCurrent();
765 // Run core until it wants to sleep
766 bool keepUpdating( true );
767 while ( keepUpdating )
769 application.SendNotification();
770 keepUpdating = application.Render( 1000.0f /*1 second*/ );
773 // Force rendering for the next 5 seconds
774 stage.KeepRendering( 5.0f );
776 application.SendNotification();
778 // Test that core wants to sleep after 10 seconds
779 keepUpdating = application.Render( 1000.0f /*1 second*/ );
780 DALI_TEST_CHECK( keepUpdating );
781 keepUpdating = application.Render( 1000.0f /*2 seconds*/ );
782 DALI_TEST_CHECK( keepUpdating );
783 keepUpdating = application.Render( 1000.0f /*3 seconds*/ );
784 DALI_TEST_CHECK( keepUpdating );
785 keepUpdating = application.Render( 1000.0f /*4 seconds*/ );
786 DALI_TEST_CHECK( keepUpdating );
787 keepUpdating = application.Render( 1000.0f /*5 seconds*/ );
788 DALI_TEST_CHECK( !keepUpdating );
792 int UtcDaliStageKeepRenderingN(void)
794 TestApplication application;
796 Stage stage = Stage::GetCurrent();
798 // Run core until it wants to sleep
799 bool keepUpdating( true );
800 while ( keepUpdating )
802 application.SendNotification();
803 keepUpdating = application.Render( 1000.0f /*1 second*/ );
806 // Force rendering for the next 5 seconds
807 stage.KeepRendering( -1.0f );
809 application.SendNotification();
811 // Test that core wants to sleep after 10 seconds
812 keepUpdating = application.Render( 1000.0f /*1 second*/ );
813 DALI_TEST_CHECK( !keepUpdating );
818 int UtcDaliStageEventProcessingFinishedP(void)
820 TestApplication application;
821 Stage stage = Stage::GetCurrent();
823 bool eventProcessingFinished = false;
824 EventProcessingFinishedFunctor functor( eventProcessingFinished );
825 stage.EventProcessingFinishedSignal().Connect( &application, functor );
827 Actor actor( Actor::New() );
830 application.SendNotification();
831 application.Render();
833 DALI_TEST_CHECK( eventProcessingFinished );
838 int UtcDaliStageEventProcessingFinishedN(void)
840 TestApplication application;
841 Stage stage = Stage::GetCurrent();
843 bool eventProcessingFinished = false;
844 EventProcessingFinishedFunctor functor( eventProcessingFinished );
845 stage.EventProcessingFinishedSignal().Connect( &application, functor );
847 Actor actor( Actor::New() );
850 // Do not complete event processing and confirm the signal has not been emitted.
851 DALI_TEST_CHECK( !eventProcessingFinished );
856 int UtcDaliStageKeyEventGeneratedSignalP(void)
858 TestApplication application;
859 Stage stage = Stage::GetCurrent();
861 KeyEventGeneratedSignalData data;
862 KeyEventGeneratedReceivedFunctor functor( data );
863 DevelStage::KeyEventGeneratedSignal( stage ).Connect( &application, functor );
865 KeyEventGeneratedSignalData data2;
866 KeyEventGeneratedReceivedFunctor functor2( data2 );
867 GetImplementation( stage ).ConnectSignal( &application, "keyEventGenerated", functor2 );
869 Integration::KeyEvent event( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
870 application.ProcessEvent( event );
872 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
873 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
874 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
875 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
876 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
880 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
881 application.ProcessEvent( event2 );
883 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
884 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
885 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
886 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
887 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
891 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
892 application.ProcessEvent( event3 );
894 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
895 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
896 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
897 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
898 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
902 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
903 application.ProcessEvent( event4 );
905 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
906 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
907 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
908 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
909 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
913 int UtcDaliStageSignalKeyEventP(void)
915 TestApplication application;
916 Stage stage = Stage::GetCurrent();
918 KeyEventSignalData data;
919 KeyEventReceivedFunctor functor( data );
920 stage.KeyEventSignal().Connect( &application, functor );
922 Integration::KeyEvent event( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Down, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
923 application.ProcessEvent( event );
925 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
926 DALI_TEST_CHECK( event.keyModifier == data.receivedKeyEvent.keyModifier );
927 DALI_TEST_CHECK( event.keyName == data.receivedKeyEvent.keyPressedName );
928 DALI_TEST_CHECK( event.keyString == data.receivedKeyEvent.keyPressed );
929 DALI_TEST_CHECK( event.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
933 Integration::KeyEvent event2( "i", "", "i", 0, 0, 0, Integration::KeyEvent::Up, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
934 application.ProcessEvent( event2 );
936 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
937 DALI_TEST_CHECK( event2.keyModifier == data.receivedKeyEvent.keyModifier );
938 DALI_TEST_CHECK( event2.keyName == data.receivedKeyEvent.keyPressedName );
939 DALI_TEST_CHECK( event2.keyString == data.receivedKeyEvent.keyPressed );
940 DALI_TEST_CHECK( event2.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
944 Integration::KeyEvent event3( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
945 application.ProcessEvent( event3 );
947 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
948 DALI_TEST_CHECK( event3.keyModifier == data.receivedKeyEvent.keyModifier );
949 DALI_TEST_CHECK( event3.keyName == data.receivedKeyEvent.keyPressedName );
950 DALI_TEST_CHECK( event3.keyString == data.receivedKeyEvent.keyPressed );
951 DALI_TEST_CHECK( event3.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
955 Integration::KeyEvent event4( "a", "", "a", 0, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE );
956 application.ProcessEvent( event4 );
958 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
959 DALI_TEST_CHECK( event4.keyModifier == data.receivedKeyEvent.keyModifier );
960 DALI_TEST_CHECK( event4.keyName == data.receivedKeyEvent.keyPressedName );
961 DALI_TEST_CHECK( event4.keyString == data.receivedKeyEvent.keyPressed );
962 DALI_TEST_CHECK( event4.state == static_cast<Integration::KeyEvent::State>( data.receivedKeyEvent.state ) );
966 int UtcDaliStageSignalKeyEventN(void)
968 TestApplication application;
969 Stage stage = Stage::GetCurrent();
971 KeyEventSignalData data;
972 KeyEventReceivedFunctor functor( data );
973 stage.KeyEventSignal().Connect( &application, functor );
975 // Check that a non-pressed key events data is not modified.
976 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
981 int UtcDaliStageTouchedSignalP(void)
983 TestApplication application;
984 Stage stage = Stage::GetCurrent();
986 TouchSignalData data;
987 TouchFunctor functor( data );
988 stage.TouchSignal().Connect( &application, functor );
990 // Render and notify.
991 application.SendNotification();
992 application.Render();
994 // Basic test: No actors, single touch (down then up).
996 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
998 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
999 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1000 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1003 GenerateTouch( application, PointState::UP, 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.GetHitActor(0) );
1012 // Add an actor to the scene.
1013 Actor actor = Actor::New();
1014 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1015 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1016 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1017 actor.TouchSignal().Connect( &DummyTouchCallback );
1020 // Render and notify.
1021 application.SendNotification();
1022 application.Render();
1024 // Actor on scene, single touch, down in actor, motion, then up outside actor.
1026 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1028 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1029 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1030 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) );
1033 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
1035 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1038 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
1040 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1041 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1042 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1046 // Multiple touch. Should only receive a touch on first down and last up.
1048 Integration::TouchEvent touchEvent;
1049 Integration::Point point;
1052 point.SetState( PointState::DOWN );
1053 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1054 touchEvent.points.push_back( point );
1055 application.ProcessEvent( touchEvent );
1056 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1057 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1061 touchEvent.points[0].SetState( PointState::STATIONARY );
1062 point.SetDeviceId( 1 );
1063 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
1064 touchEvent.points.push_back( point );
1065 application.ProcessEvent( touchEvent );
1066 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1067 DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1070 // Primary point is up
1071 touchEvent.points[0].SetState( PointState::UP );
1072 touchEvent.points[1].SetState( PointState::STATIONARY );
1073 application.ProcessEvent( touchEvent );
1074 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1075 DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1078 // Remove 1st point now, 2nd point is now in motion
1079 touchEvent.points.erase( touchEvent.points.begin() );
1080 touchEvent.points[0].SetState( PointState::MOTION );
1081 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
1082 application.ProcessEvent( touchEvent );
1083 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1084 DALI_TEST_EQUALS( (bool)data.receivedTouchEvent, false, TEST_LOCATION );
1088 touchEvent.points[0].SetState( PointState::UP );
1089 application.ProcessEvent( touchEvent );
1090 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1091 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1097 int UtcDaliStageTouchedSignalN(void)
1099 TestApplication application;
1100 Stage stage = Stage::GetCurrent();
1102 TouchSignalData data;
1103 TouchFunctor functor( data );
1104 stage.TouchSignal().Connect( &application, functor );
1106 // Render and notify.
1107 application.SendNotification();
1108 application.Render();
1110 // Confirm functor not called before there has been any touch event.
1111 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1113 // No actors, single touch, down, motion then up.
1115 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1117 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1118 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1119 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1122 // Confirm there is no signal when the touchpoint is only moved.
1123 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1125 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1128 // Confirm a following up event generates a signal.
1129 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1131 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1132 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1133 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1137 // Add an actor to the scene.
1138 Actor actor = Actor::New();
1139 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1140 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1141 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1142 actor.TouchSignal().Connect( &DummyTouchCallback );
1145 // Render and notify.
1146 application.SendNotification();
1147 application.Render();
1149 // Actor on scene. Interrupted before down and interrupted after down.
1151 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1153 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1154 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1155 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1156 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1159 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1161 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1162 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1163 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1164 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
1167 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1169 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1170 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1171 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1172 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1174 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1176 // Check that getting info about a non-existent point causes an assert.
1177 DALI_TEST_EQUALS( data.receivedTouchEvent.GetState( 1 ), PointState::FINISHED, TEST_LOCATION );
1186 int UtcDaliStageTouchSignalP(void)
1188 TestApplication application;
1189 Stage stage = Stage::GetCurrent();
1191 TouchSignalData data;
1192 TouchFunctor functor( data );
1193 stage.TouchSignal().Connect( &application, functor );
1195 // Render and notify.
1196 application.SendNotification();
1197 application.Render();
1199 // Basic test: No actors, single touch (down then up).
1201 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1203 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1204 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1205 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1208 GenerateTouch( application, PointState::UP, Vector2( 10.0f, 10.0f ) );
1210 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1211 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1212 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1216 // Add an actor to the scene.
1217 Actor actor = Actor::New();
1218 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1219 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1220 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1221 actor.TouchSignal().Connect( &DummyTouchCallback );
1224 // Render and notify.
1225 application.SendNotification();
1226 application.Render();
1228 // Actor on scene, single touch, down in actor, motion, then up outside actor.
1230 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1232 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1233 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1234 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1237 GenerateTouch( application, PointState::MOTION, Vector2( 150.0f, 10.0f ) ); // Some motion
1239 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1242 GenerateTouch( application, PointState::UP, Vector2( 150.0f, 10.0f ) ); // Some motion
1244 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1245 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1246 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1250 // Multiple touch. Should only receive a touch on first down and last up.
1252 Integration::TouchEvent touchEvent;
1253 Integration::Point point;
1256 point.SetState( PointState::DOWN );
1257 point.SetScreenPosition( Vector2( 10.0f, 10.0f ) );
1258 touchEvent.points.push_back( point );
1259 application.ProcessEvent( touchEvent );
1260 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1261 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1265 touchEvent.points[0].SetState( PointState::STATIONARY );
1266 point.SetDeviceId( 1 );
1267 point.SetScreenPosition( Vector2( 50.0f, 50.0f ) );
1268 touchEvent.points.push_back( point );
1269 application.ProcessEvent( touchEvent );
1270 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1273 // Primary point is up
1274 touchEvent.points[0].SetState( PointState::UP );
1275 touchEvent.points[1].SetState( PointState::STATIONARY );
1276 application.ProcessEvent( touchEvent );
1277 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1280 // Remove 1st point now, 2nd point is now in motion
1281 touchEvent.points.erase( touchEvent.points.begin() );
1282 touchEvent.points[0].SetState( PointState::MOTION );
1283 touchEvent.points[0].SetScreenPosition( Vector2( 150.0f, 50.0f ) );
1284 application.ProcessEvent( touchEvent );
1285 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1289 touchEvent.points[0].SetState( PointState::UP );
1290 application.ProcessEvent( touchEvent );
1291 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1292 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1298 int UtcDaliStageTouchSignalN(void)
1300 TestApplication application;
1301 Stage stage = Stage::GetCurrent();
1303 TouchSignalData data;
1304 TouchFunctor functor( data );
1305 stage.TouchSignal().Connect( &application, functor );
1307 TouchSignalData data2;
1308 TouchFunctor functor2( data2 );
1309 GetImplementation( stage ).ConnectSignal( &application, "touch", functor2 );
1311 // Render and notify.
1312 application.SendNotification();
1313 application.Render();
1315 // Confirm functor not called before there has been any touch event.
1316 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1317 DALI_TEST_EQUALS( false, data2.functorCalled, TEST_LOCATION );
1319 // No actors, single touch, down, motion then up.
1321 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1323 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1324 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1325 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
1327 DALI_TEST_EQUALS( true, data2.functorCalled, TEST_LOCATION );
1332 // Confirm there is no signal when the touchpoint is only moved.
1333 GenerateTouch( application, PointState::MOTION, Vector2( 1200.0f, 10.0f ) ); // Some motion
1335 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1338 // Confirm a following up event generates a signal.
1339 GenerateTouch( application, PointState::UP, Vector2( 1200.0f, 10.0f ) );
1341 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1342 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1343 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0));
1347 // Add an actor to the scene.
1348 Actor actor = Actor::New();
1349 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1350 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1351 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1352 actor.TouchSignal().Connect( &DummyTouchCallback );
1355 // Render and notify.
1356 application.SendNotification();
1357 application.Render();
1359 // Actor on scene. Interrupted before down and interrupted after down.
1361 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1363 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1364 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1365 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1366 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1369 GenerateTouch( application, PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1372 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1373 DALI_TEST_CHECK( data.receivedTouchEvent.GetHitActor(0) == actor );
1374 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::DOWN );
1377 GenerateTouch( application, PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) );
1379 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1380 DALI_TEST_CHECK( data.receivedTouchEvent.GetPointCount() != 0u );
1381 DALI_TEST_CHECK( !data.receivedTouchEvent.GetHitActor(0) );
1382 DALI_TEST_CHECK( data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED );
1384 DALI_TEST_EQUALS( data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION );
1386 // Check that getting info about a non-existent point returns an empty handle
1387 Actor actor = data.receivedTouchEvent.GetHitActor( 1 );
1388 DALI_TEST_CHECK( !actor );
1396 int UtcDaliStageSignalWheelEventP(void)
1398 TestApplication application;
1399 Stage stage = Stage::GetCurrent();
1401 WheelEventSignalData data;
1402 WheelEventReceivedFunctor functor( data );
1403 stage.WheelEventSignal().Connect( &application, functor );
1405 Integration::WheelEvent event( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), 1, 1000u );
1406 application.ProcessEvent( event );
1408 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1409 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event.type) == data.receivedWheelEvent.type );
1410 DALI_TEST_CHECK( event.direction == data.receivedWheelEvent.direction );
1411 DALI_TEST_CHECK( event.modifiers == data.receivedWheelEvent.modifiers );
1412 DALI_TEST_CHECK( event.point == data.receivedWheelEvent.point );
1413 DALI_TEST_CHECK( event.z == data.receivedWheelEvent.z );
1414 DALI_TEST_CHECK( event.timeStamp == data.receivedWheelEvent.timeStamp );
1418 Integration::WheelEvent event2( Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2( 0.0f, 0.0f ), -1, 1000u );
1419 application.ProcessEvent( event2 );
1421 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1422 DALI_TEST_CHECK( static_cast< WheelEvent::Type >(event2.type) == data.receivedWheelEvent.type );
1423 DALI_TEST_CHECK( event2.direction == data.receivedWheelEvent.direction );
1424 DALI_TEST_CHECK( event2.modifiers == data.receivedWheelEvent.modifiers );
1425 DALI_TEST_CHECK( event2.point == data.receivedWheelEvent.point );
1426 DALI_TEST_CHECK( event2.z == data.receivedWheelEvent.z );
1427 DALI_TEST_CHECK( event2.timeStamp == data.receivedWheelEvent.timeStamp );
1431 int UtcDaliStageContextLostSignalP(void)
1433 TestApplication application;
1434 Stage stage = Stage::GetCurrent();
1436 bool contextLost = false;
1437 ContextStatusFunctor contextLostFunctor( contextLost );
1438 stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1440 Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1441 notifier->NotifyContextLost();
1442 DALI_TEST_EQUALS( contextLost, true, TEST_LOCATION );
1447 int UtcDaliStageContextLostSignalN(void)
1449 TestApplication application;
1452 // Check that connecting to the signal with a bad stage instance causes an assert.
1453 bool asserted = false;
1454 bool contextLost = false;
1455 ContextStatusFunctor contextLostFunctor( contextLost );
1458 stage.ContextLostSignal().Connect( &application, contextLostFunctor );
1460 catch( Dali::DaliException& e )
1462 DALI_TEST_PRINT_ASSERT( e );
1463 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1466 DALI_TEST_CHECK( asserted );
1471 int UtcDaliStageContextRegainedSignalP(void)
1473 TestApplication application;
1474 Stage stage = Stage::GetCurrent();
1476 bool contextRegained = false;
1477 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1478 stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1480 Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1481 notifier->NotifyContextLost();
1482 notifier->NotifyContextRegained();
1483 DALI_TEST_EQUALS( contextRegained, true, TEST_LOCATION );
1488 int UtcDaliStageContextRegainedSignalN(void)
1490 TestApplication application;
1493 // Check that connecting to the signal with a bad stage instance causes an assert.
1494 bool asserted = false;
1495 bool contextRegained = false;
1496 ContextStatusFunctor contextRegainedFunctor( contextRegained );
1499 stage.ContextRegainedSignal().Connect( &application, contextRegainedFunctor );
1501 catch( Dali::DaliException& e )
1503 DALI_TEST_PRINT_ASSERT( e );
1504 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1507 DALI_TEST_CHECK( asserted );
1512 int UtcDaliStageSceneCreatedSignalP(void)
1514 TestApplication application;
1515 Stage stage = Stage::GetCurrent();
1517 bool signalCalled = false;
1518 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1519 stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1521 Integration::Core& core = application.GetCore();
1522 core.SceneCreated();
1523 DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION );
1528 int UtcDaliStageSceneCreatedSignalN(void)
1530 TestApplication application;
1533 // Check that connecting to the signal with a bad stage instance causes an assert.
1534 bool asserted = false;
1535 bool signalCalled = false;
1536 SceneCreatedStatusFunctor sceneCreatedFunctor( signalCalled );
1539 stage.SceneCreatedSignal().Connect( &application, sceneCreatedFunctor );
1541 catch( Dali::DaliException& e )
1543 DALI_TEST_PRINT_ASSERT( e );
1544 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1547 DALI_TEST_CHECK( asserted );
1552 int UtcDaliStageGetRenderTaskListP(void)
1554 TestApplication application;
1555 Stage stage = Stage::GetCurrent();
1557 // Check we get a valid instance.
1558 const RenderTaskList& tasks = stage.GetRenderTaskList();
1560 // There should be 1 task by default.
1561 DALI_TEST_EQUALS( tasks.GetTaskCount(), 1u, TEST_LOCATION );
1563 // RenderTaskList has it's own UTC tests.
1564 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1565 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1567 DALI_TEST_EQUALS( stage.GetRenderTaskList().GetTask( 1 ), newTask, TEST_LOCATION );
1572 int UtcDaliStageGetRenderTaskListN(void)
1574 TestApplication application;
1577 // Check that getting the render task list with a bad stage instance causes an assert.
1578 bool asserted = false;
1581 stage.GetRenderTaskList();
1583 catch( Dali::DaliException& e )
1585 DALI_TEST_PRINT_ASSERT( e );
1586 DALI_TEST_ASSERT( e, "stage && \"Stage handle is empty\"", TEST_LOCATION );
1589 DALI_TEST_CHECK( asserted );
1594 int UtcDaliStageGetObjectRegistryP(void)
1596 TestApplication application;
1597 Stage stage = Stage::GetCurrent();
1599 ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1601 // Object registry tests are covered in their own module.
1602 // However we want a basic test to confirm the returned registry is valid and works.
1603 bool verified = false;
1604 ActorCreatedFunctor test( verified );
1605 objectRegistry.ObjectCreatedSignal().Connect( &application, test );
1607 Actor actor = Actor::New();
1608 DALI_TEST_CHECK( test.mSignalVerified );
1613 int UtcDaliStageGetObjectRegistryN(void)
1615 TestApplication application;
1618 // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1619 // This is because GetCurrent() is used, always creating a stage if one does not exist.
1620 bool asserted = false;
1623 stage.GetObjectRegistry();
1625 catch( Dali::DaliException& e )
1627 DALI_TEST_PRINT_ASSERT( e );
1630 DALI_TEST_CHECK( !asserted );
1635 int UtcDaliStageOperatorAssign(void)
1637 TestApplication application;
1639 DALI_TEST_CHECK( !stage );
1641 stage = Stage::GetCurrent();
1642 DALI_TEST_CHECK( stage );
1647 int UtcDaliStageRenderingBehavior(void)
1649 TestApplication application;
1650 Stage stage = Stage::GetCurrent();
1652 tet_infoline( "Check default rendering behavior is only if required" );
1653 DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1655 tet_infoline( "No update required with an empty application" );
1656 application.SendNotification();
1657 DALI_TEST_CHECK( application.UpdateOnly() == false );
1658 application.RenderOnly();
1660 tet_infoline( "Change to continuous rendering, further updates should be required" );
1661 DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::CONTINUOUSLY );
1663 DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::CONTINUOUSLY );
1665 application.SendNotification();
1666 DALI_TEST_CHECK( application.UpdateOnly() == true );
1667 application.RenderOnly();
1669 application.SendNotification();
1670 DALI_TEST_CHECK( application.UpdateOnly() == true );
1671 application.RenderOnly();
1673 tet_infoline( "Change to rendering only if required, further updates should NOT be required" );
1674 DevelStage::SetRenderingBehavior( stage, DevelStage::Rendering::IF_REQUIRED );
1676 DALI_TEST_CHECK( DevelStage::GetRenderingBehavior( stage ) == DevelStage::Rendering::IF_REQUIRED );
1678 application.SendNotification();
1679 DALI_TEST_CHECK( application.UpdateOnly() == false );
1680 application.RenderOnly();
1682 tet_infoline( "The next update is not required so TestApplication should print a warning" );
1683 application.SendNotification();
1684 DALI_TEST_CHECK( application.UpdateOnly() == false );
1685 application.RenderOnly();