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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/common/stage-devel.h>
20 #include <dali/integration-api/context-notifier.h>
21 #include <dali/integration-api/events/key-event-integ.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/wheel-event-integ.h>
24 #include <dali/public-api/dali-core.h>
25 #include <dali/public-api/events/key-event.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;
44 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
46 // Functor for EventProcessingFinished signal
47 struct EventProcessingFinishedFunctor
50 * @param[in] eventProcessingFinished reference to a boolean variable used to check if signal has been called.
52 EventProcessingFinishedFunctor(bool& eventProcessingFinished)
53 : mEventProcessingFinished(eventProcessingFinished)
59 mEventProcessingFinished = true;
62 bool& mEventProcessingFinished;
65 // Stores data that is populated in the KeyEventGeneratedSignal callback and will be read by the TET cases
66 struct KeyEventGeneratedSignalData
68 KeyEventGeneratedSignalData()
69 : functorCalled(false)
75 functorCalled = false;
77 receivedKeyEvent.Reset();
81 KeyEvent receivedKeyEvent;
84 // Functor that sets the data when called
85 struct KeyEventGeneratedReceivedFunctor
87 KeyEventGeneratedReceivedFunctor(KeyEventGeneratedSignalData& data)
92 bool operator()(const KeyEvent& keyEvent)
94 signalData.functorCalled = true;
95 signalData.receivedKeyEvent = keyEvent;
102 signalData.functorCalled = true;
106 KeyEventGeneratedSignalData& signalData;
109 // Stores data that is populated in the key-event callback and will be read by the TET cases
110 struct KeyEventSignalData
113 : functorCalled(false)
119 functorCalled = false;
121 receivedKeyEvent.Reset();
125 KeyEvent receivedKeyEvent;
128 // Functor that sets the data when called
129 struct KeyEventReceivedFunctor
131 KeyEventReceivedFunctor(KeyEventSignalData& 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 TouchedSignalData
151 : functorCalled(false)
157 functorCalled = false;
159 receivedTouchEvent.Reset();
163 TouchEvent receivedTouchEvent;
166 // Functor that sets the data when touched signal is received
169 TouchFunctor(TouchedSignalData& data)
174 void operator()(const TouchEvent& touch)
176 signalData.functorCalled = true;
177 TouchEvent handle(touch);
178 signalData.receivedTouchEvent = handle;
183 signalData.functorCalled = true;
186 TouchedSignalData& signalData;
189 // Stores data that is populated in the wheel-event callback and will be read by the TET cases
190 struct WheelEventSignalData
192 WheelEventSignalData()
193 : functorCalled(false)
199 functorCalled = false;
203 WheelEvent receivedWheelEvent;
206 // Functor that sets the data when wheel-event signal is received
207 struct WheelEventReceivedFunctor
209 WheelEventReceivedFunctor(WheelEventSignalData& data)
214 bool operator()(const WheelEvent& wheelEvent)
216 signalData.functorCalled = true;
217 signalData.receivedWheelEvent = wheelEvent;
222 WheelEventSignalData& signalData;
225 bool DummyTouchCallback(Actor actor, const TouchEvent& touch)
230 struct ContextStatusFunctor
232 ContextStatusFunctor(bool& calledFlag)
233 : mCalledFlag(calledFlag)
250 struct SceneCreatedStatusFunctor
252 SceneCreatedStatusFunctor(bool& calledFlag)
253 : mCalledFlag(calledFlag)
270 struct ActorCreatedFunctor
272 ActorCreatedFunctor(bool& signalReceived)
273 : mSignalVerified(signalReceived)
277 void operator()(BaseHandle object)
279 tet_infoline("Verifying TestActorCallback()");
280 Actor actor = Actor::DownCast(object);
283 mSignalVerified = true;
287 bool& mSignalVerified;
290 void GenerateTouch(TestApplication& application, PointState::Type state, const Vector2& screenPosition)
292 Integration::TouchEvent touchEvent;
293 Integration::Point point;
294 point.SetState(state);
295 point.SetScreenPosition(screenPosition);
296 touchEvent.points.push_back(point);
297 application.ProcessEvent(touchEvent);
300 } // unnamed namespace
302 int UtcDaliStageDefaultConstructorP(void)
304 TestApplication application;
307 DALI_TEST_CHECK(!stage);
311 // Note: No negative test for default constructor.
313 int UtcDaliStageDestructorP(void)
315 TestApplication application;
316 Stage* stage = new Stage();
320 DALI_TEST_CHECK(true);
324 // Note: No negative test for default destructor.
326 int UtcDaliStageGetCurrentP(void)
328 TestApplication application;
329 Stage stage = Stage::GetCurrent();
331 DALI_TEST_CHECK(stage);
335 int UtcDaliStageGetCurrentN(void)
337 bool asserted = false;
340 Stage stage = Stage::GetCurrent();
342 catch(Dali::DaliException& e)
344 DALI_TEST_PRINT_ASSERT(e);
345 DALI_TEST_ASSERT(e, "stage && \"Stage doesn't exist\"", TEST_LOCATION);
349 DALI_TEST_CHECK(asserted);
353 int UtcDaliStageIsInstalledP(void)
355 TestApplication application;
359 DALI_TEST_CHECK(Stage::IsInstalled());
363 int UtcDaliStageIsInstalledN(void)
365 DALI_TEST_CHECK(!Stage::IsInstalled());
370 int UtcDaliStageCopyConstructorP(void)
372 TestApplication application;
373 Stage stage = Stage::GetCurrent();
375 Stage copyStage(stage);
377 DALI_TEST_CHECK(copyStage);
378 DALI_TEST_CHECK(copyStage.GetRootLayer() == stage.GetRootLayer());
383 // Note: no negative test for UtcDaliStageCopyConstructor.
385 int UtcDaliStageAssignmentOperatorP(void)
387 TestApplication application;
388 const Stage stage = Stage::GetCurrent();
390 Stage copyStage = stage;
392 DALI_TEST_CHECK(copyStage);
393 DALI_TEST_CHECK(copyStage.GetRootLayer() == stage.GetRootLayer());
398 // Note: No negative test for UtcDaliStageAssignmentOperator.
400 int UtcDaliStageAddP(void)
402 TestApplication application;
404 Stage stage = Stage::GetCurrent();
406 Actor actor = Actor::New();
407 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
410 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
414 int UtcDaliStageAddN(void)
416 TestApplication application;
418 Stage stage = Stage::GetCurrent();
421 bool asserted = false;
426 catch(Dali::DaliException& e)
428 DALI_TEST_PRINT_ASSERT(e);
429 DALI_TEST_ASSERT(e, "actor && \"Actor handle is empty\"", TEST_LOCATION);
433 DALI_TEST_CHECK(asserted);
438 int UtcDaliStageRemoveP(void)
440 TestApplication application;
442 Stage stage = Stage::GetCurrent();
444 Actor actor = Actor::New();
445 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
448 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
451 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
455 int UtcDaliStageRemoveN1(void)
457 TestApplication application;
459 Stage stage = Stage::GetCurrent();
462 bool asserted = false;
465 // Actor is not valid, confirm a removal attempt does assert.
468 catch(Dali::DaliException& e)
470 DALI_TEST_PRINT_ASSERT(e);
471 DALI_TEST_ASSERT(e, "actor && \"Actor handle is empty\"", TEST_LOCATION);
475 DALI_TEST_CHECK(asserted);
479 int UtcDaliStageRemoveN2(void)
481 TestApplication application;
483 Stage stage = Stage::GetCurrent();
484 Actor actor = Actor::New();
485 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
487 bool asserted = false;
490 // Actor is not on stage, confirm a removal attempt does not assert / segfault.
493 catch(Dali::DaliException& e)
495 DALI_TEST_PRINT_ASSERT(e);
499 DALI_TEST_CHECK(!asserted);
503 int UtcDaliStageRemoveN3(void)
505 TestApplication application;
507 Stage stage = Stage::GetCurrent();
509 // Initially we have a default layer
510 DALI_TEST_EQUALS(stage.GetLayerCount(), 1u, TEST_LOCATION);
512 // Check we cannot remove the root layer from the stage.
513 Layer layer = stage.GetRootLayer();
514 bool asserted = true;
519 catch(Dali::DaliException& e)
521 DALI_TEST_PRINT_ASSERT(e);
522 DALI_TEST_ASSERT(e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION);
526 DALI_TEST_CHECK(asserted);
527 DALI_TEST_EQUALS(stage.GetLayerCount(), 1u, TEST_LOCATION);
531 int UtcDaliStageGetSizeP(void)
533 TestApplication application;
535 Stage stage = Stage::GetCurrent();
537 Vector2 size = stage.GetSize();
539 DALI_TEST_EQUALS(size.width, static_cast<float>(TestApplication::DEFAULT_SURFACE_WIDTH), TEST_LOCATION);
540 DALI_TEST_EQUALS(size.height, static_cast<float>(TestApplication::DEFAULT_SURFACE_HEIGHT), TEST_LOCATION);
544 int UtcDaliStageGetSizeN(void)
546 TestApplication application;
550 bool asserted = false;
554 size = stage.GetSize();
556 catch(Dali::DaliException& e)
558 DALI_TEST_PRINT_ASSERT(e);
559 DALI_TEST_ASSERT(e, "stage && \"Stage handle is empty\"", TEST_LOCATION);
563 DALI_TEST_CHECK(asserted);
567 int UtcDaliStageGetDpiP1(void)
569 TestApplication application; // Initializes core DPI to default values
571 Stage stage = Stage::GetCurrent();
573 // Test the default DPI.
574 Vector2 dpi = stage.GetDpi();
575 DALI_TEST_EQUALS(dpi.x, static_cast<float>(TestApplication::DEFAULT_HORIZONTAL_DPI), TEST_LOCATION);
576 DALI_TEST_EQUALS(dpi.y, static_cast<float>(TestApplication::DEFAULT_VERTICAL_DPI), TEST_LOCATION);
580 int UtcDaliStageGetDpiP2(void)
582 TestApplication application; // Initializes core DPI to default values
584 // Test that setting core DPI explicitly also sets up the Stage's DPI.
585 Dali::Integration::Scene scene = application.GetScene();
586 scene.SetDpi(Vector2(200.0f, 180.0f));
588 Stage stage = Stage::GetCurrent();
589 Vector2 dpi = stage.GetDpi();
590 DALI_TEST_EQUALS(dpi.x, 200.0f, TEST_LOCATION);
591 DALI_TEST_EQUALS(dpi.y, 180.0f, TEST_LOCATION);
595 int UtcDaliStageGetDpiP3(void)
597 TestApplication application(480, 800, 72, 120); // Initializes core DPI with specific values
599 Stage stage = Stage::GetCurrent();
601 // Test that setting core DPI explicitly also sets up the Stage's DPI.
602 Vector2 dpi = stage.GetDpi();
603 DALI_TEST_EQUALS(dpi.x, 72.0f, TEST_LOCATION);
604 DALI_TEST_EQUALS(dpi.y, 120.0f, TEST_LOCATION);
609 * This is not a true negative test, we are checking the DPI if it has not been set.
610 * A test for setting negative DPI values would be part of the application core utc tests.
612 int UtcDaliStageGetDpiN(void)
614 TestApplication application; // Initializes core DPI to default values
616 Stage stage = Stage::GetCurrent();
617 Vector2 dpi = stage.GetDpi();
619 DALI_TEST_EQUALS(dpi.x, 220.0f, TEST_LOCATION);
620 DALI_TEST_EQUALS(dpi.y, 217.0f, TEST_LOCATION);
624 int UtcDaliStageGetLayerCountP(void)
626 TestApplication application;
628 Stage stage = Stage::GetCurrent();
630 // Initially we have a default layer
631 DALI_TEST_EQUALS(stage.GetLayerCount(), 1u, TEST_LOCATION);
633 Layer layer = Layer::New();
636 DALI_TEST_EQUALS(stage.GetLayerCount(), 2u, TEST_LOCATION);
641 * Not a true negative test, but confirms layer count is not affected by an invalid removal.
643 int UtcDaliStageGetLayerCountN(void)
645 TestApplication application;
647 Stage stage = Stage::GetCurrent();
649 // Initially we have a default layer
650 DALI_TEST_EQUALS(stage.GetLayerCount(), 1u, TEST_LOCATION);
652 Layer layer = Layer::New();
655 // Still have 1 layer.
656 DALI_TEST_EQUALS(stage.GetLayerCount(), 1u, TEST_LOCATION);
660 int UtcDaliStageGetLayerP(void)
662 TestApplication application;
664 Stage stage = Stage::GetCurrent();
666 Layer rootLayer = stage.GetLayer(0);
667 DALI_TEST_CHECK(rootLayer);
669 Layer layer = Layer::New();
672 Layer sameLayer = stage.GetLayer(1);
673 DALI_TEST_CHECK(layer == sameLayer);
677 int UtcDaliStageGetLayerN(void)
679 TestApplication application;
681 Stage stage = Stage::GetCurrent();
683 bool asserted = false;
686 // Try to get a layer that doesn't exist (note: 0 is the root layer).
687 Layer layer = stage.GetLayer(1);
689 catch(Dali::DaliException& e)
691 DALI_TEST_PRINT_ASSERT(e);
692 DALI_TEST_ASSERT(e, "depth < mLayers.size()", TEST_LOCATION);
696 DALI_TEST_CHECK(asserted);
700 int UtcDaliStageGetRootLayerP(void)
702 TestApplication application;
704 Stage stage = Stage::GetCurrent();
706 Layer layer = stage.GetLayer(0);
707 DALI_TEST_CHECK(layer);
709 // Check that GetRootLayer() correctly retreived layer 0.
710 DALI_TEST_CHECK(stage.GetRootLayer() == layer);
715 int UtcDaliStageGetRootLayerN(void)
717 TestApplication application;
719 Stage stage = Stage::GetCurrent();
721 Layer rootLayer = stage.GetLayer(0);
722 DALI_TEST_CHECK(rootLayer);
723 DALI_TEST_CHECK(stage.GetRootLayer() == rootLayer);
725 // Create a new layer and attempt to lower it below the root layer.
726 Layer layer = Layer::New();
728 layer.LowerToBottom();
730 // Check that GetRootLayer still retrieves the same original layer.
731 DALI_TEST_CHECK(stage.GetRootLayer() == rootLayer);
733 // Check modifying the root layer is also blocked.
734 rootLayer.RaiseToTop();
735 DALI_TEST_CHECK(stage.GetRootLayer() == rootLayer);
740 int UtcDaliStageSetBackgroundColorP(void)
742 TestApplication application;
744 Stage stage = Stage::GetCurrent();
746 Vector4 testColor(0.1f, 0.2f, 0.3f, 1.0f);
747 stage.SetBackgroundColor(testColor);
749 DALI_TEST_EQUALS(testColor, stage.GetBackgroundColor(), TEST_LOCATION);
753 // Note: No negative test for UtcDaliStageSetBackgroundColor as we do not wish to implement
754 // range checking for colors due to speed. Colors are clamped with glclampf within GL anyway.
756 int UtcDaliStageGetBackgroundColorP(void)
758 TestApplication application;
760 Stage stage = Stage::GetCurrent();
762 DALI_TEST_EQUALS(DEFAULT_BACKGROUND_COLOR, stage.GetBackgroundColor(), TEST_LOCATION);
766 // Note: No negative test for UtcDaliStageGetBackgroundColor as this is covered by UtcDaliStageSetBackgroundColorN.
768 int UtcDaliStageKeepRenderingP(void)
770 TestApplication application;
772 Stage stage = Stage::GetCurrent();
774 // Run core until it wants to sleep
775 bool keepUpdating(true);
778 application.SendNotification();
779 keepUpdating = application.Render(1000.0f /*1 second*/);
782 // Force rendering for the next 5 seconds
783 stage.KeepRendering(5.0f);
785 application.SendNotification();
787 // Test that core wants to sleep after 10 seconds
788 keepUpdating = application.Render(1000.0f /*1 second*/);
789 DALI_TEST_CHECK(keepUpdating);
790 keepUpdating = application.Render(1000.0f /*2 seconds*/);
791 DALI_TEST_CHECK(keepUpdating);
792 keepUpdating = application.Render(1000.0f /*3 seconds*/);
793 DALI_TEST_CHECK(keepUpdating);
794 keepUpdating = application.Render(1000.0f /*4 seconds*/);
795 DALI_TEST_CHECK(keepUpdating);
796 keepUpdating = application.Render(1000.0f /*5 seconds*/);
797 DALI_TEST_CHECK(!keepUpdating);
801 int UtcDaliStageKeepRenderingN(void)
803 TestApplication application;
805 Stage stage = Stage::GetCurrent();
807 // Run core until it wants to sleep
808 bool keepUpdating(true);
811 application.SendNotification();
812 keepUpdating = application.Render(1000.0f /*1 second*/);
815 // Force rendering for the next 5 seconds
816 stage.KeepRendering(-1.0f);
818 application.SendNotification();
820 // Test that core wants to sleep after 10 seconds
821 keepUpdating = application.Render(1000.0f /*1 second*/);
822 DALI_TEST_CHECK(!keepUpdating);
827 int UtcDaliStageEventProcessingFinishedP(void)
829 TestApplication application;
830 Stage stage = Stage::GetCurrent();
832 bool eventProcessingFinished = false;
833 EventProcessingFinishedFunctor functor(eventProcessingFinished);
834 stage.EventProcessingFinishedSignal().Connect(&application, functor);
836 Actor actor(Actor::New());
839 application.SendNotification();
840 application.Render();
842 DALI_TEST_CHECK(eventProcessingFinished);
847 int UtcDaliStageEventProcessingFinishedN(void)
849 TestApplication application;
850 Stage stage = Stage::GetCurrent();
852 bool eventProcessingFinished = false;
853 EventProcessingFinishedFunctor functor(eventProcessingFinished);
854 stage.EventProcessingFinishedSignal().Connect(&application, functor);
856 Actor actor(Actor::New());
859 // Do not complete event processing and confirm the signal has not been emitted.
860 DALI_TEST_CHECK(!eventProcessingFinished);
865 int UtcDaliStageKeyEventGeneratedSignalP(void)
867 TestApplication application;
868 Stage stage = Stage::GetCurrent();
870 KeyEventGeneratedSignalData data;
871 KeyEventGeneratedReceivedFunctor functor(data);
872 DevelStage::KeyEventGeneratedSignal(stage).Connect(&application, functor);
874 KeyEventGeneratedSignalData data2;
875 KeyEventGeneratedReceivedFunctor functor2(data2);
876 GetImplementation(stage).ConnectSignal(&application, "keyEventGenerated", functor2);
878 Integration::KeyEvent event("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
879 application.ProcessEvent(event);
881 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
882 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
883 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
884 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
885 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
889 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
890 application.ProcessEvent(event2);
892 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
893 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
894 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
895 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
896 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
900 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
901 application.ProcessEvent(event3);
903 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
904 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
905 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
906 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
907 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
911 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
912 application.ProcessEvent(event4);
914 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
915 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
916 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
917 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
918 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
922 int UtcDaliStageSignalKeyEventP(void)
924 TestApplication application;
925 Stage stage = Stage::GetCurrent();
927 KeyEventSignalData data;
928 KeyEventReceivedFunctor functor(data);
929 stage.KeyEventSignal().Connect(&application, functor);
931 Integration::KeyEvent event("i", "", "i", 0, 0, 0, Integration::KeyEvent::DOWN, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
932 application.ProcessEvent(event);
934 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
935 DALI_TEST_CHECK(event.keyModifier == data.receivedKeyEvent.GetKeyModifier());
936 DALI_TEST_CHECK(event.keyName == data.receivedKeyEvent.GetKeyName());
937 DALI_TEST_CHECK(event.keyString == data.receivedKeyEvent.GetKeyString());
938 DALI_TEST_CHECK(event.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
942 Integration::KeyEvent event2("i", "", "i", 0, 0, 0, Integration::KeyEvent::UP, "i", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
943 application.ProcessEvent(event2);
945 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
946 DALI_TEST_CHECK(event2.keyModifier == data.receivedKeyEvent.GetKeyModifier());
947 DALI_TEST_CHECK(event2.keyName == data.receivedKeyEvent.GetKeyName());
948 DALI_TEST_CHECK(event2.keyString == data.receivedKeyEvent.GetKeyString());
949 DALI_TEST_CHECK(event2.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
953 Integration::KeyEvent event3("a", "", "a", 0, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
954 application.ProcessEvent(event3);
956 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
957 DALI_TEST_CHECK(event3.keyModifier == data.receivedKeyEvent.GetKeyModifier());
958 DALI_TEST_CHECK(event3.keyName == data.receivedKeyEvent.GetKeyName());
959 DALI_TEST_CHECK(event3.keyString == data.receivedKeyEvent.GetKeyString());
960 DALI_TEST_CHECK(event3.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
964 Integration::KeyEvent event4("a", "", "a", 0, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE);
965 application.ProcessEvent(event4);
967 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
968 DALI_TEST_CHECK(event4.keyModifier == data.receivedKeyEvent.GetKeyModifier());
969 DALI_TEST_CHECK(event4.keyName == data.receivedKeyEvent.GetKeyName());
970 DALI_TEST_CHECK(event4.keyString == data.receivedKeyEvent.GetKeyString());
971 DALI_TEST_CHECK(event4.state == static_cast<Integration::KeyEvent::State>(data.receivedKeyEvent.GetState()));
975 int UtcDaliStageSignalKeyEventN(void)
977 TestApplication application;
978 Stage stage = Stage::GetCurrent();
980 KeyEventSignalData data;
981 KeyEventReceivedFunctor functor(data);
982 stage.KeyEventSignal().Connect(&application, functor);
984 // Check that a non-pressed key events data is not modified.
985 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
990 int UtcDaliStageTouchedSignalP(void)
992 TestApplication application;
993 Stage stage = Stage::GetCurrent();
995 TouchedSignalData data;
996 TouchFunctor functor(data);
997 stage.TouchedSignal().Connect(&application, functor);
999 // Render and notify.
1000 application.SendNotification();
1001 application.Render();
1003 // Basic test: No actors, single touch (down then up).
1005 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
1007 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1008 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1009 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1012 GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f));
1014 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1015 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1016 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1021 // Add an actor to the scene.
1022 Actor actor = Actor::New();
1023 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1024 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1025 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1026 actor.TouchedSignal().Connect(&DummyTouchCallback);
1029 // Render and notify.
1030 application.SendNotification();
1031 application.Render();
1033 // Actor on scene, single touch, down in actor, motion, then up outside actor.
1035 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
1037 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1039 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0));
1042 GenerateTouch(application, PointState::MOTION, Vector2(150.0f, 10.0f)); // Some motion
1044 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1047 GenerateTouch(application, PointState::UP, Vector2(150.0f, 10.0f)); // Some motion
1049 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1050 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1051 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1055 // Multiple touch. Should only receive a touch on first down and last up.
1057 Integration::TouchEvent touchEvent;
1058 Integration::Point point;
1061 point.SetState(PointState::DOWN);
1062 point.SetScreenPosition(Vector2(10.0f, 10.0f));
1063 touchEvent.points.push_back(point);
1064 application.ProcessEvent(touchEvent);
1065 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1066 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
1070 touchEvent.points[0].SetState(PointState::STATIONARY);
1071 point.SetDeviceId(1);
1072 point.SetScreenPosition(Vector2(50.0f, 50.0f));
1073 touchEvent.points.push_back(point);
1074 application.ProcessEvent(touchEvent);
1075 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1076 DALI_TEST_EQUALS((bool)data.receivedTouchEvent, false, TEST_LOCATION);
1079 // Primary point is up
1080 touchEvent.points[0].SetState(PointState::UP);
1081 touchEvent.points[1].SetState(PointState::STATIONARY);
1082 application.ProcessEvent(touchEvent);
1083 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1084 DALI_TEST_EQUALS((bool)data.receivedTouchEvent, false, TEST_LOCATION);
1087 // Remove 1st point now, 2nd point is now in motion
1088 touchEvent.points.erase(touchEvent.points.begin());
1089 touchEvent.points[0].SetState(PointState::MOTION);
1090 touchEvent.points[0].SetScreenPosition(Vector2(150.0f, 50.0f));
1091 application.ProcessEvent(touchEvent);
1092 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1093 DALI_TEST_EQUALS((bool)data.receivedTouchEvent, false, TEST_LOCATION);
1097 touchEvent.points[0].SetState(PointState::UP);
1098 application.ProcessEvent(touchEvent);
1099 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1100 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
1106 int UtcDaliStageTouchedSignalN(void)
1108 TestApplication application;
1109 Stage stage = Stage::GetCurrent();
1111 TouchedSignalData data;
1112 TouchFunctor functor(data);
1113 stage.TouchedSignal().Connect(&application, functor);
1115 // Render and notify.
1116 application.SendNotification();
1117 application.Render();
1119 // Confirm functor not called before there has been any touch event.
1120 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1122 // No actors, single touch, down, motion then up.
1124 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
1126 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1127 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1128 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1131 // Confirm there is no signal when the touchpoint is only moved.
1132 GenerateTouch(application, PointState::MOTION, Vector2(1200.0f, 10.0f)); // Some motion
1134 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1137 // Confirm a following up event generates a signal.
1138 GenerateTouch(application, PointState::UP, Vector2(1200.0f, 10.0f));
1140 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1141 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1142 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1146 // Add an actor to the scene.
1147 Actor actor = Actor::New();
1148 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1149 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1150 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1151 actor.TouchedSignal().Connect(&DummyTouchCallback);
1154 // Render and notify.
1155 application.SendNotification();
1156 application.Render();
1158 // Actor on scene. Interrupted before down and interrupted after down.
1160 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
1162 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1163 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1164 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1165 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
1168 GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f));
1170 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1171 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1172 DALI_TEST_CHECK(data.receivedTouchEvent.GetHitActor(0) == actor);
1173 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::DOWN);
1176 GenerateTouch(application, PointState::INTERRUPTED, Vector2(10.0f, 10.0f));
1178 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1179 DALI_TEST_CHECK(data.receivedTouchEvent.GetPointCount() != 0u);
1180 DALI_TEST_CHECK(!data.receivedTouchEvent.GetHitActor(0));
1181 DALI_TEST_CHECK(data.receivedTouchEvent.GetState(0) == PointState::INTERRUPTED);
1183 DALI_TEST_EQUALS(data.receivedTouchEvent.GetPointCount(), 1u, TEST_LOCATION);
1185 // Check that getting info about a non-existent point causes an assert.
1186 DALI_TEST_EQUALS(data.receivedTouchEvent.GetState(1), PointState::FINISHED, TEST_LOCATION);
1194 int UtcDaliStageSignalWheelEventP(void)
1196 TestApplication application;
1197 Stage stage = Stage::GetCurrent();
1199 WheelEventSignalData data;
1200 WheelEventReceivedFunctor functor(data);
1201 stage.WheelEventSignal().Connect(&application, functor);
1203 Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u);
1204 application.ProcessEvent(event);
1206 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1207 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event.type) == data.receivedWheelEvent.GetType());
1208 DALI_TEST_CHECK(event.direction == data.receivedWheelEvent.GetDirection());
1209 DALI_TEST_CHECK(event.modifiers == data.receivedWheelEvent.GetModifiers());
1210 DALI_TEST_CHECK(event.point == data.receivedWheelEvent.GetPoint());
1211 DALI_TEST_CHECK(event.delta == data.receivedWheelEvent.GetDelta());
1212 DALI_TEST_CHECK(event.timeStamp == data.receivedWheelEvent.GetTime());
1216 Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u);
1217 application.ProcessEvent(event2);
1219 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1220 DALI_TEST_CHECK(static_cast<WheelEvent::Type>(event2.type) == data.receivedWheelEvent.GetType());
1221 DALI_TEST_CHECK(event2.direction == data.receivedWheelEvent.GetDirection());
1222 DALI_TEST_CHECK(event2.modifiers == data.receivedWheelEvent.GetModifiers());
1223 DALI_TEST_CHECK(event2.point == data.receivedWheelEvent.GetPoint());
1224 DALI_TEST_CHECK(event2.delta == data.receivedWheelEvent.GetDelta());
1225 DALI_TEST_CHECK(event2.timeStamp == data.receivedWheelEvent.GetTime());
1229 int UtcDaliStageContextLostSignalP(void)
1231 TestApplication application;
1232 Stage stage = Stage::GetCurrent();
1234 bool contextLost = false;
1235 ContextStatusFunctor contextLostFunctor(contextLost);
1236 stage.ContextLostSignal().Connect(&application, contextLostFunctor);
1238 Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1239 notifier->NotifyContextLost();
1240 DALI_TEST_EQUALS(contextLost, true, TEST_LOCATION);
1245 int UtcDaliStageContextLostSignalN(void)
1247 TestApplication application;
1250 // Check that connecting to the signal with a bad stage instance causes an assert.
1251 bool asserted = false;
1252 bool contextLost = false;
1253 ContextStatusFunctor contextLostFunctor(contextLost);
1256 stage.ContextLostSignal().Connect(&application, contextLostFunctor);
1258 catch(Dali::DaliException& e)
1260 DALI_TEST_PRINT_ASSERT(e);
1261 DALI_TEST_ASSERT(e, "stage && \"Stage handle is empty\"", TEST_LOCATION);
1264 DALI_TEST_CHECK(asserted);
1269 int UtcDaliStageContextRegainedSignalP(void)
1271 TestApplication application;
1272 Stage stage = Stage::GetCurrent();
1274 bool contextRegained = false;
1275 ContextStatusFunctor contextRegainedFunctor(contextRegained);
1276 stage.ContextRegainedSignal().Connect(&application, contextRegainedFunctor);
1278 Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier();
1279 notifier->NotifyContextLost();
1280 notifier->NotifyContextRegained();
1281 DALI_TEST_EQUALS(contextRegained, true, TEST_LOCATION);
1286 int UtcDaliStageContextRegainedSignalN(void)
1288 TestApplication application;
1291 // Check that connecting to the signal with a bad stage instance causes an assert.
1292 bool asserted = false;
1293 bool contextRegained = false;
1294 ContextStatusFunctor contextRegainedFunctor(contextRegained);
1297 stage.ContextRegainedSignal().Connect(&application, contextRegainedFunctor);
1299 catch(Dali::DaliException& e)
1301 DALI_TEST_PRINT_ASSERT(e);
1302 DALI_TEST_ASSERT(e, "stage && \"Stage handle is empty\"", TEST_LOCATION);
1305 DALI_TEST_CHECK(asserted);
1310 int UtcDaliStageSceneCreatedSignalP(void)
1312 TestApplication application;
1313 Stage stage = Stage::GetCurrent();
1315 bool signalCalled = false;
1316 SceneCreatedStatusFunctor sceneCreatedFunctor(signalCalled);
1317 stage.SceneCreatedSignal().Connect(&application, sceneCreatedFunctor);
1319 Integration::Core& core = application.GetCore();
1320 core.SceneCreated();
1321 DALI_TEST_EQUALS(signalCalled, true, TEST_LOCATION);
1326 int UtcDaliStageSceneCreatedSignalN(void)
1328 TestApplication application;
1331 // Check that connecting to the signal with a bad stage instance causes an assert.
1332 bool asserted = false;
1333 bool signalCalled = false;
1334 SceneCreatedStatusFunctor sceneCreatedFunctor(signalCalled);
1337 stage.SceneCreatedSignal().Connect(&application, sceneCreatedFunctor);
1339 catch(Dali::DaliException& e)
1341 DALI_TEST_PRINT_ASSERT(e);
1342 DALI_TEST_ASSERT(e, "stage && \"Stage handle is empty\"", TEST_LOCATION);
1345 DALI_TEST_CHECK(asserted);
1350 int UtcDaliStageGetRenderTaskListP(void)
1352 TestApplication application;
1353 Stage stage = Stage::GetCurrent();
1355 // Check we get a valid instance.
1356 const RenderTaskList& tasks = stage.GetRenderTaskList();
1358 // There should be 1 task by default.
1359 DALI_TEST_EQUALS(tasks.GetTaskCount(), 1u, TEST_LOCATION);
1361 // RenderTaskList has it's own UTC tests.
1362 // But we can confirm that GetRenderTaskList in Stage retrieves the same RenderTaskList each time.
1363 RenderTask newTask = stage.GetRenderTaskList().CreateTask();
1365 DALI_TEST_EQUALS(stage.GetRenderTaskList().GetTask(1), newTask, TEST_LOCATION);
1370 int UtcDaliStageGetRenderTaskListN(void)
1372 TestApplication application;
1375 // Check that getting the render task list with a bad stage instance causes an assert.
1376 bool asserted = false;
1379 stage.GetRenderTaskList();
1381 catch(Dali::DaliException& e)
1383 DALI_TEST_PRINT_ASSERT(e);
1384 DALI_TEST_ASSERT(e, "stage && \"Stage handle is empty\"", TEST_LOCATION);
1387 DALI_TEST_CHECK(asserted);
1392 int UtcDaliStageGetObjectRegistryP(void)
1394 TestApplication application;
1395 Stage stage = Stage::GetCurrent();
1397 ObjectRegistry objectRegistry = stage.GetObjectRegistry();
1399 // Object registry tests are covered in their own module.
1400 // However we want a basic test to confirm the returned registry is valid and works.
1401 bool verified = false;
1402 ActorCreatedFunctor test(verified);
1403 objectRegistry.ObjectCreatedSignal().Connect(&application, test);
1405 Actor actor = Actor::New();
1406 DALI_TEST_CHECK(test.mSignalVerified);
1411 int UtcDaliStageGetObjectRegistryN(void)
1413 TestApplication application;
1416 // Check that getting the object registry with a bad stage instance DOES NOT cause an assert.
1417 // This is because GetCurrent() is used, always creating a stage if one does not exist.
1418 bool asserted = false;
1421 stage.GetObjectRegistry();
1423 catch(Dali::DaliException& e)
1425 DALI_TEST_PRINT_ASSERT(e);
1428 DALI_TEST_CHECK(!asserted);
1433 int UtcDaliStageOperatorAssign(void)
1435 TestApplication application;
1437 DALI_TEST_CHECK(!stage);
1439 stage = Stage::GetCurrent();
1440 DALI_TEST_CHECK(stage);
1445 int UtcDaliStageRenderingBehavior(void)
1447 TestApplication application;
1448 Stage stage = Stage::GetCurrent();
1450 tet_infoline("Check default rendering behavior is only if required");
1451 DALI_TEST_CHECK(DevelStage::GetRenderingBehavior(stage) == DevelStage::Rendering::IF_REQUIRED);
1453 tet_infoline("No update required with an empty application");
1454 application.SendNotification();
1455 DALI_TEST_CHECK(application.UpdateOnly() == false);
1456 application.RenderOnly();
1458 tet_infoline("Change to continuous rendering, further updates should be required");
1459 DevelStage::SetRenderingBehavior(stage, DevelStage::Rendering::CONTINUOUSLY);
1461 DALI_TEST_CHECK(DevelStage::GetRenderingBehavior(stage) == DevelStage::Rendering::CONTINUOUSLY);
1463 application.SendNotification();
1464 DALI_TEST_CHECK(application.UpdateOnly() == true);
1465 application.RenderOnly();
1467 application.SendNotification();
1468 DALI_TEST_CHECK(application.UpdateOnly() == true);
1469 application.RenderOnly();
1471 tet_infoline("Change to rendering only if required, further updates should NOT be required");
1472 DevelStage::SetRenderingBehavior(stage, DevelStage::Rendering::IF_REQUIRED);
1474 DALI_TEST_CHECK(DevelStage::GetRenderingBehavior(stage) == DevelStage::Rendering::IF_REQUIRED);
1476 application.SendNotification();
1477 DALI_TEST_CHECK(application.UpdateOnly() == false);
1478 application.RenderOnly();
1480 tet_infoline("The next update is not required so TestApplication should print a warning");
1481 application.SendNotification();
1482 DALI_TEST_CHECK(application.UpdateOnly() == false);
1483 application.RenderOnly();