Adding new test harness
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-toolkit-test-utils / toolkit-timer.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include "toolkit-timer.h"
18 // INTERNAL INCLUDES
19
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali/public-api/signals/dali-signal-v2.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29
30 Timer gTimer;
31
32 /*
33  * This is a global signal that all users of this stub will connect to.
34  * If we were to use a timer stub with real ticks we may wish to have this as a member variable created with each New Timer.
35  * Currently unable to get the boost singal connect to work with the stub timer when using a member hence this global.
36  */
37 Dali::Timer::TimerSignalV2 gTimerTick;
38 }
39
40 /**
41  * Stub for the Timer
42  */
43
44 Timer Timer::New( unsigned int milliSec )
45 {
46   DALI_ASSERT_ALWAYS( gTimer );
47
48   return gTimer;
49 }
50
51 Timer::TimerSignalV2& Timer::TickSignal()
52 {
53    return gTimerTick;
54 }
55
56 bool Timer::IsRunning() const
57 {
58   return true;
59 }
60
61 Timer::Timer( const Timer& timer )
62 : BaseHandle(timer)
63 {
64 }
65
66 Timer::~Timer()
67 {
68 }
69
70
71 void Timer::Start()
72 {
73 }
74
75 void Timer::Stop()
76 {
77 }
78
79 namespace Internal
80 {
81
82 namespace Adaptor
83 {
84
85 /**
86  * Stub for the Internal Timer
87  */
88 class Timer : public BaseObject
89 {
90 public: // Creation & Destruction
91
92   Timer();
93   Timer(ToolkitTimer *timer);
94   ~Timer();
95
96   void Start();
97
98   void Stop();
99
100   bool IsRunning() const;
101
102 public: // Signals
103
104 private:
105
106   ToolkitTimer* mToolkitTimer;
107   bool mRunning;
108 };
109
110 Timer::Timer()
111 : mToolkitTimer(NULL),
112   mRunning( true )
113 {
114 }
115
116 Timer::Timer(ToolkitTimer *timer)
117 : mToolkitTimer(timer),
118   mRunning( true )
119 {
120 }
121
122 Timer::~Timer()
123 {
124 }
125
126 void Timer::Start()
127 {
128   DALI_ASSERT_ALWAYS( gTimer );
129 }
130
131 void Timer::Stop()
132 {
133   DALI_ASSERT_ALWAYS( gTimer );
134 }
135
136 bool Timer::IsRunning() const
137 {
138   DALI_ASSERT_ALWAYS( gTimer );
139   return mRunning;
140 }
141
142 } // namespace Adaptor
143
144 } // namespace Internal
145
146 ////////////////////////////////////////////////////////////////////////////////////////////////////
147
148 ToolkitTimer::ToolkitTimer()
149 : mTimerStub(new Internal::Adaptor::Timer(this)),
150   mTimer( mTimerStub )
151 {
152   if ( mTimer )
153   {
154     gTimer = mTimer;
155   }
156 }
157
158 ToolkitTimer::~ToolkitTimer()
159 {
160   gTimer.Reset();
161 }
162
163 Timer ToolkitTimer::GetTimer()
164 {
165   return mTimer;
166 }
167
168 } // namespace Dali