(Automated Tests) Fix compiler warnings in some test cases
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Timer.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 #include <iostream>
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include <dali/dali.h>
22 #include <Ecore.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 void utc_dali_timer_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_timer_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39 bool ecore_timer_running = false;
40 Ecore_Task_Cb timer_callback_func=NULL;
41 const void* timer_callback_data=NULL;
42 bool main_loop_can_run = false;
43 intptr_t timerId = 0; // intptr_t has the same size as a pointer and is platform independent so this can be returned as a pointer in ecore_timer_add below without compilation warnings
44 }// anon namespace
45
46 extern "C"
47 {
48 Ecore_Timer* ecore_timer_add(double in,
49                              Ecore_Task_Cb func,
50                              const void   *data)
51 {
52   ecore_timer_running = true;
53   timer_callback_func = func;
54   timer_callback_data = data;
55   timerId+=8;
56   return (Ecore_Timer*)timerId;
57 }
58
59 void* ecore_timer_del(Ecore_Timer *timer)
60 {
61   ecore_timer_running = false;
62   timer_callback_func = NULL;
63   return NULL;
64 }
65
66 }
67
68 namespace
69 {
70
71 void test_ecore_main_loop_begin()
72 {
73   if(timer_callback_func != NULL)
74   {
75     main_loop_can_run = true;
76     while( main_loop_can_run )
77     {
78       if( ! timer_callback_func(const_cast<void*>(timer_callback_data)) )
79         break;
80     }
81   }
82 }
83
84 void test_ecore_main_loop_quit()
85 {
86   timer_callback_func = NULL;
87   main_loop_can_run = false;
88 }
89
90
91 /**
92  * small class to test timer signal
93  */
94 class TimerTestClass : public ConnectionTracker
95 {
96 public:
97
98   TimerTestClass(bool repeat):mTimerCalled(false),mReturnContiune(repeat) {}
99
100   bool Tick()
101   {
102     tet_printf("timer ticked\n");
103     mTimerCalled = true;
104     // quit the main loop otherwise we'll never return to tet
105     test_ecore_main_loop_quit();
106     return mReturnContiune;
107   }
108   bool mTimerCalled;    // whether tick has been called or not
109   bool mReturnContiune; // whether to return true / false to continue
110
111 };
112
113 } // anon namespace
114
115
116 // Positive test case for a method
117 int UtcDaliTimerCreation(void)
118 {
119  // TestApplication application;
120   tet_printf("timer creation \n");
121   Timer timer = Timer::New(300);
122
123   DALI_TEST_CHECK( timer );
124
125   DALI_TEST_CHECK( timer.GetInterval() == 300);
126
127   END_TEST;
128 }
129
130 int UtcDaliTimerUnitializedStart(void)
131 {
132   tet_printf("unintialized timer start \n");
133
134   Timer *timer = new Timer;
135   DALI_TEST_CHECK(timer != NULL);
136
137   try
138   {
139     timer->Start();
140   }
141   catch(Dali::DaliException& e)
142   {
143     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
144   }
145   END_TEST;
146 }
147
148 int UtcDaliTimerUnitializedStop(void)
149 {
150   tet_printf("unintialized timer stop \n");
151
152   Timer *timer = new Timer;
153   DALI_TEST_CHECK(timer != NULL);
154
155   try
156   {
157     timer->Stop();
158   }
159   catch(Dali::DaliException& e)
160   {
161     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
162   }
163   END_TEST;
164 }
165
166 int UtcDaliTimerUnitializedGetInterval(void)
167 {
168   tet_printf("unintialized get interval \n");
169
170   Timer *timer = new Timer;
171   DALI_TEST_CHECK(timer != NULL);
172
173   try
174   {
175     timer->GetInterval();
176   }
177   catch(Dali::DaliException& e)
178   {
179     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
180   }
181   END_TEST;
182 }
183
184 int UtcDaliTimerUnitializedSetInterval(void)
185 {
186   tet_printf("unintialized set interval \n");
187
188   Timer *timer = new Timer;
189   DALI_TEST_CHECK(timer != NULL);
190
191   try
192   {
193     timer->SetInterval(10);
194   }
195   catch(Dali::DaliException& e)
196   {
197     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
198   }
199   END_TEST;
200 }
201
202 int UtcDaliTimerUnitializedIsRunning(void)
203 {
204   tet_printf("unintialized is running \n");
205
206   Timer *timer = new Timer;
207   DALI_TEST_CHECK(timer != NULL);
208
209   try
210   {
211     timer->IsRunning();
212   }
213   catch(Dali::DaliException& e)
214   {
215     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
216   }
217   END_TEST;
218 }
219
220
221 int UtcDaliTimerUnitializedSignalTick(void)
222 {
223   tet_printf("unintialized SignalTick \n");
224
225   Timer *timer = new Timer;
226   DALI_TEST_CHECK(timer != NULL);
227
228   try
229   {
230     TimerTestClass testClass(true);// = new TimerTestClass(true);
231
232     timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
233   }
234   catch(Dali::DaliException& e)
235   {
236     DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
237   }
238   END_TEST;
239 }
240
241 int UtcDaliTimerSetInterval(void)
242 {
243   tet_printf("timer set interval \n");
244   Timer timer = Timer::New(10);
245
246   DALI_TEST_CHECK( timer.GetInterval() == 10);
247
248   timer.SetInterval(5000);
249
250   DALI_TEST_CHECK( timer.GetInterval() == 5000);
251
252   END_TEST;
253 }
254
255 int UtcDaliTimerCopyConstructor(void)
256 {
257   tet_printf("timer copy constructor \n");
258   Timer timer = Timer::New(10);
259
260   Timer anotherTimer( timer );
261
262   DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
263   END_TEST;
264 }
265
266 int UtcDaliTimerAssignmentOperator(void)
267 {
268   tet_printf("assignmnet constructor \n");
269
270   Timer timer = Timer::New(10);
271
272   DALI_TEST_CHECK( timer );
273
274   Timer anotherTimer = Timer::New(40);
275
276   DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
277
278   tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
279   tet_printf("timer 2 interval %d, \n",timer.GetInterval());
280
281   DALI_TEST_CHECK(timer != anotherTimer);
282
283   timer = anotherTimer;
284
285   DALI_TEST_CHECK(timer == anotherTimer);
286
287   tet_printf("timer 1 interval %d, \n",timer.GetInterval());
288   tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
289
290   DALI_TEST_CHECK(timer.GetInterval() == 40);
291
292   END_TEST;
293 }
294
295 int UtcDaliTimerIsRunning(void)
296 {
297   tet_printf("timer is running \n");
298
299   Timer timer = Timer::New(100);
300
301   timer.Start();
302
303   DALI_TEST_CHECK( timer.IsRunning() );
304
305   timer.Stop();
306
307   DALI_TEST_CHECK( timer.IsRunning() == false );
308
309   END_TEST;
310 }
311
312 int UtcDaliTimerSignalTickContinue(void)
313 {
314   tet_printf("timer call back\n");
315
316   Timer timer = Timer::New(100);
317   TimerTestClass testClass(true);
318
319   timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
320
321   timer.Start();
322
323   test_ecore_main_loop_begin();
324
325   DALI_TEST_CHECK( testClass.mTimerCalled );
326
327   END_TEST;
328 }
329
330 int UtcDaliTimerSignalTickStop(void)
331 {
332   Timer timer = Timer::New(100);
333   TimerTestClass testClass(false);
334
335   timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
336
337   timer.Start();
338
339   test_ecore_main_loop_begin();
340
341   DALI_TEST_CHECK( testClass.mTimerCalled );
342
343   END_TEST;
344 }
345
346 int UtcDaliTimerReset(void)
347 {
348   Timer timer = Timer::New(100);
349
350   DALI_TEST_CHECK(timer);
351
352   timer.Reset();
353
354   DALI_TEST_CHECK(!timer);
355
356   END_TEST;
357 }