X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftoolkit-timer.cpp;h=f9c89dad59fc6e6603c60a6928e21675efd9e47e;hp=b031a4bf889c22b55e36b1f219ed156f9bc91c5e;hb=6154e1e69b7cd3afb49213c4f6f5730dd3df074e;hpb=a881757839b7abb008873a68c67e17b3ba39669b diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp index b031a4b..f9c89da 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -17,40 +17,246 @@ #include "toolkit-timer.h" -#include - // INTERNAL INCLUDES -#include +#include #include -#include +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ +class Timer; + +typedef IntrusivePtr TimerPtr; + +Dali::Timer::TimerSignalType gTickSignal; +int gTimerCount = 0; +bool gKeepTimersRunning = false; + +/** + * Implementation of the timer + */ +class Timer : public BaseObject +{ +public: + void MockEmitSignal(); + +public: + static TimerPtr New( unsigned int milliSec ); + Timer( unsigned int milliSec ); + virtual ~Timer(); + + void Start(); + void Stop(); + void SetInterval( unsigned int interval ); + unsigned int GetInterval() const; + bool IsRunning() const; + bool Tick(); + +public: // Signals + + Dali::Timer::TimerSignalType& TickSignal(); + +private: // Implementation + + // not implemented + Timer( const Timer& ); + Timer& operator=( const Timer& ); + +private: // Data + + unsigned int mInterval; + bool mRunning; +}; + +inline Timer& GetImplementation(Dali::Timer& timer) +{ + DALI_ASSERT_ALWAYS(timer && "Timer handle is empty"); + + BaseObject& handle = timer.GetBaseObject(); + + return static_cast(handle); +} + +inline const Timer& GetImplementation(const Dali::Timer& timer) +{ + DALI_ASSERT_ALWAYS(timer && "Timer handle is empty"); + + const BaseObject& handle = timer.GetBaseObject(); + return static_cast(handle); +} + +TimerPtr Timer::New( unsigned int milliSec ) +{ + TimerPtr timerImpl = new Timer( milliSec ); + return timerImpl; +} + +Timer::Timer( unsigned int milliSec ) +: mInterval( milliSec ), + mRunning( false ) +{ + ++gTimerCount; +} + +Timer::~Timer() +{ + --gTimerCount; +} + +void Timer::Start() +{ + mRunning = true; +} + +void Timer::Stop() +{ + mRunning = false; +} + +void Timer::SetInterval( unsigned int interval ) +{ + mInterval = interval; +} + +unsigned int Timer::GetInterval() const +{ + return mInterval; +} -namespace +bool Timer::IsRunning() const { -bool ecore_timer_running = false; -Ecore_Task_Cb timer_callback_func=NULL; -const void* timer_callback_data=NULL; -int timerId = 0; -}// anon namespace + return mRunning; +} -extern "C" +bool Timer::Tick() { -Ecore_Timer* ecore_timer_add(double in, - Ecore_Task_Cb func, - const void *data) + return false; +} + +Dali::Timer::TimerSignalType& Timer::TickSignal() +{ + return gTickSignal; +} + +// Mock setup functions: + +void Timer::MockEmitSignal() +{ + if( gTimerCount > 1 ) + { + // Only emit the signal if we have more than just the timer created in the test function + gTickSignal.Emit(); + } +} + +} // namespace Adaptor + +} // namespace Internal + +/********************************************************************************/ +/********************************* PUBLIC CLASS *******************************/ +/********************************************************************************/ + +Timer::Timer() +{ + +} + +Timer Timer::New( unsigned int milliSec ) +{ + Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec ); + return Timer(internal.Get()); +} + +Timer::Timer( const Timer& timer ) +:BaseHandle( timer ) +{ +} + +Timer& Timer::operator=( const Timer& timer ) +{ + // check self assignment + if( *this != timer ) + { + BaseHandle::operator=(timer); + } + return *this; +} + +Timer::~Timer() +{ +} + +void Timer::Start() +{ + Internal::Adaptor::GetImplementation( *this ).Start(); + Dali::Internal::Adaptor::gKeepTimersRunning = true; +} + +void Timer::Stop() +{ + Internal::Adaptor::GetImplementation( *this ).Stop(); +} + +void Timer::SetInterval( unsigned int milliSec ) +{ + Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec ); +} + +unsigned int Timer::GetInterval() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetInterval(); +} + +bool Timer::IsRunning() const +{ + return true; +} + +Timer::TimerSignalType& Timer::TickSignal() +{ + return Internal::Adaptor::GetImplementation( *this ).TickSignal(); +} + +Timer::Timer(Internal::Adaptor::Timer* timer) +: BaseHandle(timer) +{ +} + +// Mock setup functions: + +void Timer::MockEmitSignal() +{ + Internal::Adaptor::GetImplementation( *this ).MockEmitSignal(); +} + +} // namespace Dali + + +namespace Test +{ + +int GetTimerCount() +{ + return Dali::Internal::Adaptor::gTimerCount; +} + +void EmitGlobalTimerSignal() { - ecore_timer_running = true; - timer_callback_func = func; - timer_callback_data = data; - timerId += sizeof(Ecore_Timer*); - return (Ecore_Timer*)timerId; + // @todo Multiplex timers properly. + Dali::Internal::Adaptor::gKeepTimersRunning = Dali::Internal::Adaptor::gTickSignal.Emit(); } -void* ecore_timer_del(Ecore_Timer *timer) +bool AreTimersRunning() { - ecore_timer_running = false; - timer_callback_func = NULL; - return NULL; + return Dali::Internal::Adaptor::gKeepTimersRunning; } }