Fix the build fail of toolkit-test-util
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-timer.cpp
index c6facd5..f9c89da 100644 (file)
@@ -1,25 +1,26 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include "toolkit-timer.h"
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
 #include <dali/public-api/object/base-object.h>
-#include <dali/public-api/signals/dali-signal-v2.h>
+#include <dali/public-api/signals/dali-signal.h>
 
 namespace Dali
 {
@@ -33,12 +34,19 @@ class Timer;
 
 typedef IntrusivePtr<Timer> 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();
@@ -52,7 +60,7 @@ public:
 
 public: // Signals
 
-  Dali::Timer::TimerSignalV2& TickSignal();
+  Dali::Timer::TimerSignalType& TickSignal();
 
 private: // Implementation
 
@@ -62,8 +70,8 @@ private: // Implementation
 
 private: // Data
 
-  Dali::Timer::TimerSignalV2 mTickSignal;
   unsigned int mInterval;
+  bool mRunning;
 };
 
 inline Timer& GetImplementation(Dali::Timer& timer)
@@ -86,25 +94,30 @@ inline const Timer& GetImplementation(const Dali::Timer& timer)
 
 TimerPtr Timer::New( unsigned int milliSec )
 {
-  TimerPtr timerImpl = new Timer(10);
+  TimerPtr timerImpl = new Timer( milliSec );
   return timerImpl;
 }
 
 Timer::Timer( unsigned int milliSec )
-: mInterval( 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 )
@@ -119,7 +132,7 @@ unsigned int Timer::GetInterval() const
 
 bool Timer::IsRunning() const
 {
-  return true;
+  return mRunning;
 }
 
 bool Timer::Tick()
@@ -127,9 +140,20 @@ bool Timer::Tick()
   return false;
 }
 
-Dali::Timer::TimerSignalV2& Timer::TickSignal()
+Dali::Timer::TimerSignalType& Timer::TickSignal()
+{
+  return gTickSignal;
+}
+
+// Mock setup functions:
+
+void Timer::MockEmitSignal()
 {
-  return mTickSignal;
+  if( gTimerCount > 1 )
+  {
+    // Only emit the signal if we have more than just the timer created in the test function
+    gTickSignal.Emit();
+  }
 }
 
 } // namespace Adaptor
@@ -173,6 +197,7 @@ Timer::~Timer()
 void Timer::Start()
 {
   Internal::Adaptor::GetImplementation( *this ).Start();
+  Dali::Internal::Adaptor::gKeepTimersRunning = true;
 }
 
 void Timer::Stop()
@@ -195,7 +220,7 @@ bool Timer::IsRunning() const
   return true;
 }
 
-Timer::TimerSignalV2& Timer::TickSignal()
+Timer::TimerSignalType& Timer::TickSignal()
 {
   return Internal::Adaptor::GetImplementation( *this ).TickSignal();
 }
@@ -205,5 +230,33 @@ Timer::Timer(Internal::Adaptor::Timer* 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()
+{
+  // @todo Multiplex timers properly.
+  Dali::Internal::Adaptor::gKeepTimersRunning = Dali::Internal::Adaptor::gTickSignal.Emit();
+}
+
+bool AreTimersRunning()
+{
+  return Dali::Internal::Adaptor::gKeepTimersRunning;
+}
+
+}