Update common test util
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-timer.cpp
index 864e41e..2259719 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -34,12 +34,18 @@ class Timer;
 
 typedef IntrusivePtr<Timer> TimerPtr;
 
+Dali::Timer::TimerSignalType gTickSignal;
+int gTimerCount = 0;
+
 /**
  * Implementation of the timer
  */
 class Timer : public BaseObject
 {
 public:
+  void MockEmitSignal();
+
+public:
   static TimerPtr New( unsigned int milliSec );
   Timer( unsigned int milliSec );
   virtual ~Timer();
@@ -63,7 +69,6 @@ private: // Implementation
 
 private: // Data
 
-  Dali::Timer::TimerSignalType mTickSignal;
   unsigned int mInterval;
 };
 
@@ -87,17 +92,19 @@ 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 )
 {
+  ++gTimerCount;
 }
 
 Timer::~Timer()
 {
+  --gTimerCount;
 }
 
 void Timer::Start()
@@ -130,9 +137,21 @@ bool Timer::Tick()
 
 Dali::Timer::TimerSignalType& Timer::TickSignal()
 {
-  return mTickSignal;
+  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
@@ -206,5 +225,27 @@ 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()
+{
+  Dali::Internal::Adaptor::gTickSignal.Emit();
+}
+
+}