X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftoolkit-adaptor.cpp;h=40c73ae1a74d46275baf12363438b170904f67bf;hb=HEAD;hp=eb1f2b898abfa64db7ef32e61ec3602eb40523d2;hpb=eb3f729d9b7ca6fd7e9af953380b41eef4fc0ecb;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp index eb1f2b8..3c9445a 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 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. @@ -15,210 +15,406 @@ * */ -// CLASS HEADER -#include +#include -#include +#include + +// Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h. +#define DALI_WINDOW_H +#include +#include -#include #include +#include #include +#include +#include +#include +#include +#include +#include "dali-test-suite-utils.h" namespace Dali { - namespace Internal { namespace Adaptor { +/////////////////////////////////////////////////////////////////////////////// +// +// Dali::Internal::Adaptor::Adaptor Stub +// +/////////////////////////////////////////////////////////////////////////////// -bool Adaptor::mAvailable = false; -Vector Adaptor::mCallbacks = Vector(); +Dali::Adaptor* gAdaptor = nullptr; -Dali::Adaptor& Adaptor::Get() +Dali::Adaptor& Adaptor::New() { - Dali::Adaptor* adaptor = new Dali::Adaptor; - Adaptor::mAvailable = true; - return *adaptor; + DALI_ASSERT_ALWAYS(!gAdaptor); + gAdaptor = new Dali::Adaptor; + return *gAdaptor; } -Dali::RenderSurface& Adaptor::GetSurface() +Dali::Adaptor& Adaptor::Get() { - Dali::RenderSurface *renderSurface = new Dali::TestRenderSurface; - return *renderSurface; + DALI_ASSERT_ALWAYS(gAdaptor); + return *gAdaptor; } -Dali::Adaptor::AdaptorSignalType& Adaptor::AdaptorSignal() +Adaptor::Adaptor() { - Dali::Adaptor::AdaptorSignalType* signal = new Dali::Adaptor::AdaptorSignalType; - return *signal; } -} // namespace Adaptor -} // namespace Internal +Adaptor::~Adaptor() +{ + gAdaptor = nullptr; -Adaptor& Adaptor::New( Window window ) + // 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(); +} + +void Adaptor::Start(Dali::Window window) { - return Internal::Adaptor::Adaptor::Get(); + AddWindow(&GetImplementation(window)); } -Adaptor& Adaptor::New( Window window, Configuration::ContextLoss configuration ) +void Adaptor::Stop() { - return Internal::Adaptor::Adaptor::Get(); + if(mTestApplication) + { + Integration::Core& core = mTestApplication->GetCore(); + tet_printf("Adaptor::UnregisterProcessors\n"); + core.UnregisterProcessors(); + } + + mStopped = true; } -Adaptor& Adaptor::New( Any nativeWindow, const Dali::RenderSurface& surface ) +Integration::Scene Adaptor::GetScene(Dali::Window window) { - return Internal::Adaptor::Adaptor::Get(); + return window.GetScene(); } -Adaptor& Adaptor::New( Any nativeWindow, const Dali::RenderSurface& surface, Configuration::ContextLoss configuration ) +bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue) { - return Internal::Adaptor::Adaptor::Get(); + if(ToolkitApplication::ADD_IDLE_SUCCESS) + { + if(hasReturnValue) + { + mReturnCallbacks.PushBack(callback); + } + else + { + mCallbacks.PushBack(callback); + } + } + return ToolkitApplication::ADD_IDLE_SUCCESS; } -Adaptor::~Adaptor() +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 Adaptor::Start() +void Adaptor::RunIdles() { + Dali::Vector reusedCallbacks; + for(auto& callback : mReturnCallbacks) + { + bool retValue = CallbackBase::ExecuteReturn(*callback); + if(retValue) + { + reusedCallbacks.PushBack(callback); + } + } + for(auto& callback : mCallbacks) + { + CallbackBase::Execute(*callback); + } + + mCallbacks.Clear(); + mReturnCallbacks.Clear(); + mReturnCallbacks.Swap(reusedCallbacks); } -void Adaptor::Pause() +void Adaptor::RequestUpdateOnce() { + if(mTestApplication) + { + auto scene = mTestApplication->GetScene(); + if(scene) + { + tet_printf("Adaptor::RequestUpdateOnce()\n"); + scene.KeepRendering(0.0f); + } + } } -void Adaptor::Resume() +Dali::RenderSurfaceInterface& Adaptor::GetSurface() { + DALI_ASSERT_ALWAYS(!mWindows.empty()); + + return reinterpret_cast(mWindows.front()->GetRenderSurface()); } -void Adaptor::Stop() +Dali::WindowContainer Adaptor::GetWindows() { + Dali::WindowContainer windows; + + for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter) + { + // Downcast to Dali::Window + Dali::Window window(dynamic_cast(*iter)); + if(window) + { + windows.push_back(window); + } + } + + return windows; } -bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue ) +Dali::SceneHolderList Adaptor::GetSceneHolders() { - const bool isAvailable = IsAvailable(); + Dali::SceneHolderList sceneHolderList; - if( isAvailable ) + for(auto iter = mWindows.begin(); iter != mWindows.end(); ++iter) { - Internal::Adaptor::Adaptor::mCallbacks.PushBack( callback ); + sceneHolderList.push_back(Dali::Integration::SceneHolder(*iter)); } - return isAvailable; + return sceneHolderList; } -void Adaptor::RemoveIdle( CallbackBase* callback ) +Dali::Internal::Adaptor::SceneHolder* Adaptor::GetWindow(Dali::Actor& actor) { - const bool isAvailable = IsAvailable(); + Dali::Integration::Scene scene = Dali::Integration::Scene::Get(actor); - if( isAvailable ) + for(auto window : mWindows) { - for( Vector::Iterator it = Internal::Adaptor::Adaptor::mCallbacks.Begin(), - endIt = Internal::Adaptor::Adaptor::mCallbacks.End(); - it != endIt; - ++it ) + if(scene == window->GetScene()) { - if( callback == *it ) - { - Internal::Adaptor::Adaptor::mCallbacks.Remove( it ); - return; - } + 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() +{ } -void Adaptor::ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface ) +void Adaptor::Pause() +{ +} + +void Adaptor::Resume() +{ +} + +void Adaptor::Stop() +{ + mImpl->Stop(); +} + +bool Adaptor::AddIdle(CallbackBase* callback, bool hasReturnValue) +{ + return mImpl->AddIdle(callback, hasReturnValue); +} + +void Adaptor::RemoveIdle(CallbackBase* callback) +{ + mImpl->RemoveIdle(callback); +} + +void Adaptor::ReplaceSurface(Window window, Dali::RenderSurfaceInterface& surface) +{ +} + +void Adaptor::ReplaceSurface(Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface) { } Adaptor::AdaptorSignalType& Adaptor::ResizedSignal() { - return Internal::Adaptor::Adaptor::AdaptorSignal(); + return mImpl->ResizedSignal(); } Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal() { - return Internal::Adaptor::Adaptor::AdaptorSignal(); + return mImpl->LanguageChangedSignal(); } -RenderSurface& Adaptor::GetSurface() +Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal() { - return Internal::Adaptor::Adaptor::GetSurface(); + return mImpl->WindowCreatedSignal(); } -Any Adaptor::GetNativeWindowHandle() +Dali::RenderSurfaceInterface& Adaptor::GetSurface() { - Any window; - return window; + return mImpl->GetSurface(); } -void Adaptor::ReleaseSurfaceLock() +Dali::WindowContainer Adaptor::GetWindows() const { + return mImpl->GetWindows(); } -void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender ) +Dali::SceneHolderList Adaptor::GetSceneHolders() const { + return mImpl->GetSceneHolders(); } -void Adaptor::SetUseHardwareVSync(bool useHardware) +Any Adaptor::GetNativeWindowHandle() { + Any window; + return window; } -Adaptor& Adaptor::Get() +Any Adaptor::GetNativeWindowHandle(Actor actor) { - return Internal::Adaptor::Adaptor::Get(); + return GetNativeWindowHandle(); } -bool Adaptor::IsAvailable() +void Adaptor::ReleaseSurfaceLock() { - return Internal::Adaptor::Adaptor::mAvailable; } -void Adaptor::NotifySceneCreated() +void Adaptor::SetRenderRefreshRate(unsigned int numberOfVSyncsPerRender) { } -void Adaptor::NotifyLanguageChanged() +Adaptor& Adaptor::Get() { + return Internal::Adaptor::Adaptor::Get(); } -void Adaptor::SetMinimumPinchDistance(float distance) +bool Adaptor::IsAvailable() { + return Internal::Adaptor::gAdaptor && (!Internal::Adaptor::Adaptor::GetImpl(*Internal::Adaptor::gAdaptor).IsStopped()); } -void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp ) +void Adaptor::NotifySceneCreated() { } -void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent ) +void Adaptor::NotifyLanguageChanged() { } -void Adaptor::FeedKeyEvent( KeyEvent& keyEvent ) +void Adaptor::FeedTouchPoint(TouchPoint& point, int timeStamp) { } -void Adaptor::SceneCreated() +void Adaptor::FeedWheelEvent(WheelEvent& wheelEvent) { } -void Adaptor::SetViewMode( ViewMode mode ) +void Adaptor::FeedKeyEvent(KeyEvent& keyEvent) { } -void Adaptor::SetStereoBase( float stereoBase ) +void Adaptor::SceneCreated() { } - class LogFactory : public LogFactoryInterface { public: virtual void InstallLogFunction() const { - Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage); + Dali::Integration::Log::LogFunction logFunction(&ToolkitTestApplication::LogMessage); Dali::Integration::Log::InstallLogFunction(logFunction); } @@ -230,19 +426,61 @@ public: } }; -LogFactory* gLogFactory = NULL; +LogFactory* gLogFactory = NULL; const LogFactoryInterface& Adaptor::GetLogFactory() { - if( gLogFactory == NULL ) + if(gLogFactory == NULL) { gLogFactory = new LogFactory; } return *gLogFactory; } -Adaptor::Adaptor() -: mImpl( NULL ) +class TraceFactory : public TraceFactoryInterface +{ +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); +} + +void Adaptor::UnregisterProcessor(Integration::Processor& processor, bool postProcessor) +{ + mImpl->UnregisterProcessor(processor, postProcessor); +} + +void Adaptor::RegisterProcessorOnce(Integration::Processor& processor, bool postProcessor) +{ + mImpl->RegisterProcessorOnce(processor, postProcessor); +} + +void Adaptor::UnregisterProcessorOnce(Integration::Processor& processor, bool postProcessor) { + mImpl->UnregisterProcessorOnce(processor, postProcessor); } } // namespace Dali