[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
index 17bd210..3c9445a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
  *
  */
 
-#define __DALI_ADAPTOR_H__
-#define __DALI_ACCESSIBILITY_MANAGER_H__
-#define __DALI_TIMER_H__
-#define __DALI_CLIPBOARD_H__
-#define __DALI_IMF_MANAGER_H__
+#include <algorithm>
 
-#include "toolkit-adaptor.h"
-#include <map>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/signals/dali-signal-v2.h>
+#include <toolkit-window-impl.h>
+
+// Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
+#define DALI_WINDOW_H
+#include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/integration-api/adaptor-framework/scene-holder.h>
+
+#include <dali/integration-api/debug.h>
+#include <dali/integration-api/scene.h>
+#include <test-application.h>
+#include <toolkit-adaptor-impl.h>
+#include <toolkit-application.h>
+#include <toolkit-async-task-manager.h>
+#include <toolkit-scene-holder-impl.h>
+#include <toolkit-test-application.h>
+#include "dali-test-suite-utils.h"
 
 namespace Dali
 {
+namespace Internal
+{
+namespace Adaptor
+{
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Internal::Adaptor::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
 
-////////////////////////////////////////////////////////////////////////////////////////////////////
+Dali::Adaptor* gAdaptor = nullptr;
 
-class TestRenderSurface : public RenderSurface
+Dali::Adaptor& Adaptor::New()
 {
-public:
-  TestRenderSurface(){}
-  virtual ~TestRenderSurface(){}
-  virtual SurfaceType GetType() { return RenderSurface::WINDOW; }
-  virtual Dali::Any GetSurface() { return Dali::Any(); }
-  virtual Dali::Any GetDisplay() { return Dali::Any(); }
-  virtual PositionSize GetPositionSize() const { return PositionSize(0, 0, 640, 480);}
-};
+  DALI_ASSERT_ALWAYS(!gAdaptor);
+  gAdaptor = new Dali::Adaptor;
+  return *gAdaptor;
+}
 
-typedef Dali::Rect<int> PositionSize;
+Dali::Adaptor& Adaptor::Get()
+{
+  DALI_ASSERT_ALWAYS(gAdaptor);
+  return *gAdaptor;
+}
 
-/**
- * Stub for the Adaptor
- */
-class Adaptor
+Adaptor::Adaptor()
 {
-public:
+}
 
-  typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
+Adaptor::~Adaptor()
+{
+  gAdaptor = nullptr;
 
-public:
+  // Ensure all threads and not-excuted tasks are destroyed.
+  // TODO : we'd better make some singletone service for toolkit UTC in future.
+  Test::AsyncTaskManager::DestroyAsyncTaskManager();
+}
 
-  Adaptor(ToolkitAdaptor& toolkitAdaptor);
-  ~Adaptor();
+void Adaptor::Start(Dali::Window window)
+{
+  AddWindow(&GetImplementation(window));
+}
 
-public:
+void Adaptor::Stop()
+{
+  if(mTestApplication)
+  {
+    Integration::Core& core = mTestApplication->GetCore();
+    tet_printf("Adaptor::UnregisterProcessors\n");
+    core.UnregisterProcessors();
+  }
 
-  void Start();
-  void Pause();
-  void Resume();
-  void Stop();
-  bool AddIdle(boost::function<void(void)> callBack);
-  void FeedEvent(TouchPoint& point, int timeStamp);
-  bool MoveResize(const PositionSize& positionSize);
-  void SurfaceResized(const PositionSize& positionSize);
-  void ReplaceSurface(RenderSurface& surface);
-  void RenderSync();
-  RenderSurface& GetSurface();
+  mStopped = true;
+}
 
-public: // static methods
-  static Adaptor& Get();
-  static bool IsAvailable();
+Integration::Scene Adaptor::GetScene(Dali::Window window)
+{
+  return window.GetScene();
+}
 
-public:  // Signals
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
+{
+  if(ToolkitApplication::ADD_IDLE_SUCCESS)
+  {
+    if(hasReturnValue)
+    {
+      mReturnCallbacks.PushBack(callback);
+    }
+    else
+    {
+      mCallbacks.PushBack(callback);
+    }
+  }
+  return ToolkitApplication::ADD_IDLE_SUCCESS;
+}
 
-  AdaptorSignalV2& SignalResize();
+void Adaptor::RemoveIdle(CallbackBase* callback)
+{
+  mCallbacks.Erase(std::remove_if(mCallbacks.Begin(), mCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mCallbacks.End());
+  mReturnCallbacks.Erase(std::remove_if(mReturnCallbacks.Begin(), mReturnCallbacks.End(), [&callback](CallbackBase* current) { return callback == current; }), mReturnCallbacks.End());
+}
 
-  void EmitSignalResize()
+void Adaptor::RunIdles()
+{
+  Dali::Vector<CallbackBase*> reusedCallbacks;
+  for(auto& callback : mReturnCallbacks)
+  {
+    bool retValue = CallbackBase::ExecuteReturn<bool>(*callback);
+    if(retValue)
+    {
+      reusedCallbacks.PushBack(callback);
+    }
+  }
+  for(auto& callback : mCallbacks)
   {
-    mResizeSignal.Emit( *this );
+    CallbackBase::Execute(*callback);
   }
 
-private:
+  mCallbacks.Clear();
+  mReturnCallbacks.Clear();
+  mReturnCallbacks.Swap(reusedCallbacks);
+}
 
-  // Undefined
-  Adaptor(const Adaptor&);
-  Adaptor& operator=(Adaptor&);
+void Adaptor::RequestUpdateOnce()
+{
+  if(mTestApplication)
+  {
+    auto scene = mTestApplication->GetScene();
+    if(scene)
+    {
+      tet_printf("Adaptor::RequestUpdateOnce()\n");
+      scene.KeepRendering(0.0f);
+    }
+  }
+}
 
-  AdaptorSignalV2 mResizeSignal;
-  TestRenderSurface mRenderSurface;
-  ToolkitAdaptor& mToolkitAdaptor;
-};
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  DALI_ASSERT_ALWAYS(!mWindows.empty());
+
+  return reinterpret_cast<Dali::RenderSurfaceInterface&>(mWindows.front()->GetRenderSurface());
+}
 
-namespace
+Dali::WindowContainer Adaptor::GetWindows()
 {
-Adaptor* gAdaptor = NULL;
+  Dali::WindowContainer windows;
 
+  for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
+  {
+    // Downcast to Dali::Window
+    Dali::Window window(dynamic_cast<Dali::Internal::Adaptor::Window*>(*iter));
+    if(window)
+    {
+      windows.push_back(window);
+    }
+  }
+
+  return windows;
 }
 
-Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
-: mToolkitAdaptor(toolkitAdaptor)
+Dali::SceneHolderList Adaptor::GetSceneHolders()
 {
+  Dali::SceneHolderList sceneHolderList;
+
+  for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter)
+  {
+    sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter));
+  }
+
+  return sceneHolderList;
 }
 
-Adaptor::~Adaptor()
+Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor)
+{
+  Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor);
+
+  for(auto window : mWindows)
+  {
+    if(scene == window->GetScene())
+    {
+      return window;
+    }
+  }
+
+  return nullptr;
+}
+
+void Adaptor::AddWindow(Internal::Adaptor::SceneHolder* window)
+{
+  if(window)
+  {
+    mWindows.push_back(window);
+
+    Dali::Integration::SceneHolder newWindow(window);
+    mWindowCreatedSignal.Emit(newWindow);
+  }
+}
+
+void Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* window)
+{
+  auto iter = std::find(mWindows.begin(), mWindows.end(), window);
+  if(iter != mWindows.end())
+  {
+    mWindows.erase(iter);
+  }
+}
+
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::RegisterProcessor : %s\n", processor.GetProcessorName().data());
+  core.RegisterProcessor(processor, postProcessor);
+}
+
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::UnregisterProcessor : %s\n", processor.GetProcessorName().data());
+  core.UnregisterProcessor(processor, postProcessor);
+}
+
+void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::RegisterProcessorOnce : %s\n", processor.GetProcessorName().data());
+  core.RegisterProcessorOnce(processor, postProcessor);
+}
+
+void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
+{
+  Integration::Core& core = mTestApplication->GetCore();
+  tet_printf("Adaptor::UnregisterProcessorOnce : %s\n", processor.GetProcessorName().data());
+  core.UnregisterProcessorOnce(processor, postProcessor);
+}
+
+void Adaptor::SetApplication(Dali::TestApplication& testApplication)
 {
+  mTestApplication = &testApplication;
+}
+
+Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
+{
+  return mResizedSignal;
+}
+
+Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
+{
+  return mLanguageChangedSignal;
+}
+
+Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+{
+  return mWindowCreatedSignal;
+}
+
+} // namespace Adaptor
+} // namespace Internal
 
+///////////////////////////////////////////////////////////////////////////////
+//
+// Dali::Adaptor Stub
+//
+///////////////////////////////////////////////////////////////////////////////
+
+Adaptor::Adaptor()
+: mImpl(new Internal::Adaptor::Adaptor)
+{
+}
+
+Adaptor::~Adaptor()
+{
+  Internal::Adaptor::gAdaptor = nullptr;
+  delete mImpl;
 }
 
 void Adaptor::Start()
 {
-  mToolkitAdaptor.mFunctionsCalled.Start = true;
 }
 
 void Adaptor::Pause()
 {
-  mToolkitAdaptor.mFunctionsCalled.Pause = true;
 }
 
 void Adaptor::Resume()
 {
-  mToolkitAdaptor.mFunctionsCalled.Resume = true;
 }
 
 void Adaptor::Stop()
 {
-  mToolkitAdaptor.mFunctionsCalled.Stop = true;
+  mImpl->Stop();
 }
 
-bool Adaptor::AddIdle(boost::function<void(void)> callBack)
+bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue)
 {
-  mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
-  mToolkitAdaptor.mLastIdleAdded = callBack;
-  return true;
+  return mImpl->AddIdle(callback, hasReturnValue);
 }
 
-void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
+void Adaptor::RemoveIdle(CallbackBase* callback)
 {
-  mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
-  mToolkitAdaptor.mLastTouchPointFed = point;
-  mToolkitAdaptor.mLastTimeStampFed = timeStamp;
+  mImpl->RemoveIdle(callback);
 }
 
-bool Adaptor::MoveResize(const PositionSize& positionSize)
+void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface)
 {
-  mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
-  mToolkitAdaptor.mLastSizeSet = positionSize;
-  return true;
 }
 
-void Adaptor::SurfaceResized(const PositionSize& positionSize)
+void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface)
 {
-  mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
-  mToolkitAdaptor.mLastSizeSet = positionSize;
 }
 
-void Adaptor::ReplaceSurface(RenderSurface& surface)
+Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
 {
-  mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
+  return mImpl->ResizedSignal();
 }
 
-void Adaptor::RenderSync()
+Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
 {
-  mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
+  return mImpl->LanguageChangedSignal();
 }
 
-RenderSurface& Adaptor::GetSurface()
+Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
+{
+  return mImpl->WindowCreatedSignal();
+}
+
+Dali::RenderSurfaceInterface& Adaptor::GetSurface()
+{
+  return mImpl->GetSurface();
+}
+
+Dali::WindowContainer Adaptor::GetWindows() const
+{
+  return mImpl->GetWindows();
+}
+
+Dali::SceneHolderList Adaptor::GetSceneHolders() const
+{
+  return mImpl->GetSceneHolders();
+}
+
+Any Adaptor::GetNativeWindowHandle()
+{
+  Any window;
+  return window;
+}
+
+Any Adaptor::GetNativeWindowHandle(Actor actor)
+{
+  return GetNativeWindowHandle();
+}
+
+void Adaptor::ReleaseSurfaceLock()
+{
+}
+
+void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender)
 {
-  mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
-  return mRenderSurface;
 }
 
 Adaptor& Adaptor::Get()
 {
-  DALI_ASSERT_ALWAYS(gAdaptor);
-  gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
-  return *gAdaptor;
+  return Internal::Adaptor::Adaptor::Get();
 }
 
 bool Adaptor::IsAvailable()
 {
-  bool available(false);
+  return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped());
+}
 
-  if (gAdaptor)
+void Adaptor::NotifySceneCreated()
+{
+}
+
+void Adaptor::NotifyLanguageChanged()
+{
+}
+
+void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp)
+{
+}
+
+void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent)
+{
+}
+
+void Adaptor::FeedKeyEvent(KeyEvent& keyEvent)
+{
+}
+
+void Adaptor::SceneCreated()
+{
+}
+
+class LogFactory : public LogFactoryInterface
+{
+public:
+  virtual void InstallLogFunction() const
+  {
+    Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage);
+    Dali::Integration::Log::InstallLogFunction(logFunction);
+  }
+
+  LogFactory()
   {
-    gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
-    available = true;
   }
+  virtual ~LogFactory()
+  {
+  }
+};
 
-  return available;
+LogFactory*                gLogFactory = NULL;
+const LogFactoryInterface& Adaptor::GetLogFactory()
+{
+  if(gLogFactory == NULL)
+  {
+    gLogFactory = new LogFactory;
+  }
+  return *gLogFactory;
 }
 
-Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
+class TraceFactory : public TraceFactoryInterface
 {
-  mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
-  return mResizeSignal;
+public:
+  virtual void InstallTraceFunction() const
+  {
+    Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
+    Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
+  }
+
+  TraceFactory()
+  {
+  }
+  virtual ~TraceFactory()
+  {
+  }
+};
+
+TraceFactory*                gTraceFactory = NULL;
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
+{
+  if(gTraceFactory == NULL)
+  {
+    gTraceFactory = new TraceFactory;
+  }
+  return *gTraceFactory;
 }
 
-////////////////////////////////////////////////////////////////////////////////////////////////////
+void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
+{
+  mImpl->RegisterProcessor(processor, postProcessor);
+}
 
-ToolkitAdaptor::ToolkitAdaptor()
-: mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
-  mLastTimeStampFed(0),
-  mStyleMonitor(StyleMonitor::Get()),
-  mAccessibilityManager(AccessibilityManager::Get()),
-  mImfManager(ImfManager::Get()),
-  mAdaptorStub(new Adaptor(*this))
+void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
-  gAdaptor = mAdaptorStub;
+  mImpl->UnregisterProcessor(processor, postProcessor);
 }
 
-ToolkitAdaptor::~ToolkitAdaptor()
+void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
 {
-  delete mAdaptorStub;
-  gAdaptor = NULL;
+  mImpl->RegisterProcessorOnce(processor, postProcessor);
 }
 
-void ToolkitAdaptor::EmitSignalResize()
+void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor)
 {
-  mAdaptorStub->EmitSignalResize();
+  mImpl->UnregisterProcessorOnce(processor, postProcessor);
 }
 
 } // namespace Dali