[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ControlWrapper.cpp
index c62e11c..f1b934b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -51,6 +51,15 @@ void utc_dali_toolkit_control_wrapper_cleanup(void)
 namespace
 {
 bool gOnRelayout = false;
+
+static bool gKeyInputFocusCallBackCalled;
+
+static void TestKeyInputFocusCallback( Control control )
+{
+  tet_infoline(" TestKeyInputFocusCallback");
+
+  gKeyInputFocusCallBackCalled = true;
+}
 } // namespace
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -78,9 +87,11 @@ struct TestCustomControl : public Toolkit::Internal::ControlWrapper
           mDaliProperty( Property::INVALID_INDEX ),
           mSizeSet( Vector3::ZERO ),
           mTargetSize( Vector3::ZERO ),
-          mNego( nego )
+          mNego( nego ),
+          mDepth( 0u )
   {
   }
+
   /**
    * Destructor
    */
@@ -95,17 +106,18 @@ struct TestCustomControl : public Toolkit::Internal::ControlWrapper
     OnInitialize( name );
   }
 
+  using Control::OnInitialize; ///< To tell the compiler that we really do want to overload OnInitialize in this class & were not trying to override it
   virtual void OnInitialize( const char* name ) {}
 
   // From Toolkit::Internal::ControlWrapper
-  virtual void OnStageConnection( int depth )
+  virtual void OnSceneConnection( int depth )
   {
     mDepth = depth;
-    Control::OnStageConnection(depth);
+    Control::OnSceneConnection(depth);
   }
-  virtual void OnStageDisconnection()
+  virtual void OnSceneDisconnection()
   {
-    Control::OnStageDisconnection();
+    Control::OnSceneDisconnection();
   }
   virtual void OnChildAdd( Actor& child )
   {
@@ -115,7 +127,7 @@ struct TestCustomControl : public Toolkit::Internal::ControlWrapper
   {
     Control::OnChildRemove(child);
   }
-  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
+  virtual void OnPropertySet( Property::Index index, const Property::Value& propertyValue )
   {
     Control::OnPropertySet(index, propertyValue);
   }
@@ -129,10 +141,6 @@ struct TestCustomControl : public Toolkit::Internal::ControlWrapper
     mTargetSize = targetSize;
     Control::OnSizeAnimation( animation, targetSize );
   }
-  virtual bool OnTouchEvent( const TouchEvent& event )
-  {
-    return true;
-  }
   virtual bool OnHoverEvent( const HoverEvent& event )
   {
     return true;
@@ -281,7 +289,7 @@ int UtcDaliControlWrapperConstructor(void)
 
 int UtcDaliControlWrapperDestructor(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   ControlWrapper control = ControlWrapper::New( customControlTypeName, *( new Toolkit::Internal::ControlWrapper( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT ) ) );
 
@@ -300,14 +308,14 @@ int UtcDaliControlWrapperDestructor(void)
 
 int UtcDaliControlWrapperRelayoutRequest(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   DALI_TEST_EQUALS( gOnRelayout, false, TEST_LOCATION );
 
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
 
-  Stage::GetCurrent().Add( controlWrapper );
+  application.GetScene().Add( controlWrapper );
 
   application.SendNotification();
   application.Render();
@@ -326,7 +334,7 @@ int UtcDaliControlWrapperRelayoutRequest(void)
 
 int UtcDaliControlWrapperImplGetHeightForWidthBase(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
@@ -346,7 +354,7 @@ int UtcDaliControlWrapperImplGetHeightForWidthBase(void)
 
 int UtcDaliControlWrapperGetWidthForHeightBase(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
@@ -366,14 +374,14 @@ int UtcDaliControlWrapperGetWidthForHeightBase(void)
 
 int UtcDaliControlWrapperCalculateChildSizeBase(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
 
   Actor child = Actor::New();
   child.SetResizePolicy( Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS );
-  child.SetSize(150, 150);
+  child.SetProperty( Actor::Property::SIZE, Vector2(150, 150) );
 
   application.SendNotification();
   application.Render();
@@ -387,7 +395,7 @@ int UtcDaliControlWrapperCalculateChildSizeBase(void)
 
 int UtcDaliControlWrapperRelayoutDependentOnChildrenBase(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
@@ -413,7 +421,7 @@ int UtcDaliControlWrapperRegisterVisualToSelf(void)
 {
   ToolkitTestApplication application;
 
-  Test::ObjectDestructionTracker objectDestructionTracker;
+  Test::ObjectDestructionTracker objectDestructionTracker( application.GetCore().GetObjectRegistry() );
 
   {
     Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
@@ -449,7 +457,7 @@ int UtcDaliControlWrapperRegisterVisualWithDepthIndexToSelf(void)
 {
   ToolkitTestApplication application;
 
-  Test::ObjectDestructionTracker objectDestructionTracker;
+  Test::ObjectDestructionTracker objectDestructionTracker( application.GetCore().GetObjectRegistry() );
 
   {
     Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
@@ -507,7 +515,7 @@ int UtcDaliControlWrapperRegisterDisabledVisual(void)
   DALI_TEST_EQUALS( controlWrapperImpl->GetVisual( TEST_PROPERTY ), visual, TEST_LOCATION );
   DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION );
 
-  Stage::GetCurrent().Add( controlWrapper );
+  application.GetScene().Add( controlWrapper );
 
   // Render and notify
   application.SendNotification();
@@ -515,7 +523,7 @@ int UtcDaliControlWrapperRegisterDisabledVisual(void)
 
   DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION );
 
-  DALI_TEST_EQUALS( controlWrapper.OnStage(), true, TEST_LOCATION );
+  DALI_TEST_EQUALS( controlWrapper.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ), true, TEST_LOCATION );
 
   controlWrapperImpl->EnableVisual( TEST_PROPERTY, true );
 
@@ -550,7 +558,7 @@ int UtcDaliControlWrapperRegisterDisabledVisualWithDepthIndex(void)
   DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION );
   DALI_TEST_EQUALS( visual.GetDepthIndex(), 10, TEST_LOCATION );
 
-  Stage::GetCurrent().Add( controlWrapper );
+  application.GetScene().Add( controlWrapper );
 
   // Render and notify
   application.SendNotification();
@@ -558,7 +566,7 @@ int UtcDaliControlWrapperRegisterDisabledVisualWithDepthIndex(void)
 
   DALI_TEST_EQUALS( controlWrapperImpl->IsVisualEnabled( TEST_PROPERTY ), false, TEST_LOCATION );
 
-  DALI_TEST_EQUALS( controlWrapper.OnStage(), true, TEST_LOCATION );
+  DALI_TEST_EQUALS( controlWrapper.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ), true, TEST_LOCATION );
 
   controlWrapperImpl->EnableVisual( TEST_PROPERTY, true );
 
@@ -601,7 +609,7 @@ int UtcDaliControlWrapperRegisterUnregisterVisual(void)
 
 int UtcDaliControlWrapperTransitionDataMap1N(void)
 {
-  TestApplication application;
+  ToolkitTestApplication application;
 
   Property::Map map;
   map["target"] = "Actor1";
@@ -621,9 +629,9 @@ int UtcDaliControlWrapperTransitionDataMap1N(void)
 
   //DummyControl actor = DummyControl::New();
   controlWrapper.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
-  controlWrapper.SetName("Actor1");
-  controlWrapper.SetColor(Color::CYAN);
-  Stage::GetCurrent().Add(controlWrapper);
+  controlWrapper.SetProperty( Dali::Actor::Property::NAME,"Actor1");
+  controlWrapper.SetProperty( Actor::Property::COLOR,Color::CYAN);
+  application.GetScene().Add(controlWrapper);
 
   Animation anim = controlWrapperImpl->CreateTransition( transition );
   DALI_TEST_CHECK( ! anim );
@@ -685,7 +693,7 @@ int UtcDaliControlWrapperTestControlProperties(void)
   Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
   ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
 
-  Stage::GetCurrent().Add( controlWrapper );
+  application.GetScene().Add( controlWrapper );
 
   // "background" property
   Property::Map rendererMap;
@@ -694,8 +702,8 @@ int UtcDaliControlWrapperTestControlProperties(void)
   controlWrapper.SetProperty( Control::Property::BACKGROUND, rendererMap );
   Property::Value propertyValue = controlWrapper.GetProperty( Control::Property::BACKGROUND );
   Property::Map* resultMap = propertyValue.GetMap();
-  DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
-  DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
+  DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
+  DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
   DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
   DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
 
@@ -737,7 +745,7 @@ int UtcDaliControlWrapperAnimateVisual(void)
   tet_infoline("Test that the control wrapper's visuals can be animated by name when registered");
 
   ToolkitTestApplication application;
-  Test::ObjectDestructionTracker objectDestructionTracker;
+  Test::ObjectDestructionTracker objectDestructionTracker( application.GetCore().GetObjectRegistry() );
 
   {
     Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
@@ -762,8 +770,8 @@ int UtcDaliControlWrapperAnimateVisual(void)
     // Register to self
     controlWrapperImpl->TestRegisterVisual( index, visual );
 
-    Stage::GetCurrent().Add( controlWrapper );
-    controlWrapper.SetSize( 100, 100 );
+    application.GetScene().Add( controlWrapper );
+    controlWrapper.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
     application.SendNotification();
     application.Render(0); // Trigger animation start
 
@@ -800,10 +808,30 @@ int UtcDaliControlWrapperAnimateVisual(void)
     DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), false, TEST_LOCATION ); // Control not destroyed yet
     DALI_TEST_EQUALS( controlWrapperImpl->GetVisual( index ), visual, TEST_LOCATION );
 
-    Stage::GetCurrent().Remove( controlWrapper );
+    application.GetScene().Remove( controlWrapper );
   }
 
   DALI_TEST_EQUALS( objectDestructionTracker.IsDestroyed(), true, TEST_LOCATION ); // Should be destroyed
 
   END_TEST;
 }
+
+int UtcDaliControlWrapperEmitKeyFocusSignal(void)
+{
+  ToolkitTestApplication application;
+
+  Impl::TestCustomControl* controlWrapperImpl = new ::Impl::TestCustomControl( Toolkit::Internal::ControlWrapper::CONTROL_BEHAVIOUR_DEFAULT );
+  ControlWrapper controlWrapper = ControlWrapper::New( customControlTypeName, *controlWrapperImpl );
+
+  gKeyInputFocusCallBackCalled = false;
+  controlWrapper.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
+
+  application.SendNotification();
+  application.Render();
+
+  controlWrapperImpl->EmitKeyInputFocusSignal( true );
+
+  DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
+
+  END_TEST;
+}