2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/dali.h>
23 #include <dali-test-suite-utils.h>
24 #include <adaptor-test-application.h>
28 void utc_dali_timer_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_timer_cleanup(void)
35 test_return_value = TET_PASS;
40 bool ecore_timer_running = false;
41 Ecore_Task_Cb timer_callback_func=NULL;
42 const void* timer_callback_data=NULL;
43 bool main_loop_can_run = false;
44 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
49 Ecore_Timer* ecore_timer_add(double in,
53 ecore_timer_running = true;
54 timer_callback_func = func;
55 timer_callback_data = data;
57 return (Ecore_Timer*)timerId;
60 void* ecore_timer_del(Ecore_Timer *timer)
62 ecore_timer_running = false;
63 timer_callback_func = NULL;
72 void test_ecore_main_loop_begin()
74 if(timer_callback_func != NULL)
76 main_loop_can_run = true;
77 while( main_loop_can_run )
79 if( ! timer_callback_func(const_cast<void*>(timer_callback_data)) )
85 void test_ecore_main_loop_quit()
87 timer_callback_func = NULL;
88 main_loop_can_run = false;
93 * small class to test timer signal
95 class TimerTestClass : public ConnectionTracker
99 TimerTestClass(bool repeat):mTimerCalled(false),mReturnContiune(repeat) {}
103 tet_printf("timer ticked\n");
105 // quit the main loop otherwise we'll never return to tet
106 test_ecore_main_loop_quit();
107 return mReturnContiune;
109 bool mTimerCalled; // whether tick has been called or not
110 bool mReturnContiune; // whether to return true / false to continue
117 // Positive test case for a method
118 int UtcDaliTimerCreation(void)
120 AdaptorTestApplication application;
122 tet_printf("timer creation \n");
123 Timer timer = Timer::New(300);
125 DALI_TEST_CHECK( timer );
127 DALI_TEST_CHECK( timer.GetInterval() == 300);
132 int UtcDaliTimerUnitializedStart(void)
134 AdaptorTestApplication application;
136 tet_printf("unintialized timer start \n");
138 Timer *timer = new Timer;
139 DALI_TEST_CHECK(timer != NULL);
145 catch(Dali::DaliException& e)
147 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
152 int UtcDaliTimerUnitializedStop(void)
154 AdaptorTestApplication application;
156 tet_printf("unintialized timer stop \n");
158 Timer *timer = new Timer;
159 DALI_TEST_CHECK(timer != NULL);
165 catch(Dali::DaliException& e)
167 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
172 int UtcDaliTimerUnitializedGetInterval(void)
174 AdaptorTestApplication application;
176 tet_printf("unintialized get interval \n");
178 Timer *timer = new Timer;
179 DALI_TEST_CHECK(timer != NULL);
183 timer->GetInterval();
185 catch(Dali::DaliException& e)
187 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
192 int UtcDaliTimerUnitializedSetInterval(void)
194 AdaptorTestApplication application;
196 tet_printf("unintialized set interval \n");
198 Timer *timer = new Timer;
199 DALI_TEST_CHECK(timer != NULL);
203 timer->SetInterval(10);
205 catch(Dali::DaliException& e)
207 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
212 int UtcDaliTimerUnitializedIsRunning(void)
214 AdaptorTestApplication application;
216 tet_printf("unintialized is running \n");
218 Timer *timer = new Timer;
219 DALI_TEST_CHECK(timer != NULL);
225 catch(Dali::DaliException& e)
227 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
233 int UtcDaliTimerUnitializedSignalTick(void)
235 AdaptorTestApplication application;
237 tet_printf("unintialized SignalTick \n");
239 Timer *timer = new Timer;
240 DALI_TEST_CHECK(timer != NULL);
244 TimerTestClass testClass(true);// = new TimerTestClass(true);
246 timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
248 catch(Dali::DaliException& e)
250 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
255 int UtcDaliTimerSetInterval(void)
257 AdaptorTestApplication application;
259 tet_printf("timer set interval \n");
260 Timer timer = Timer::New(10);
262 DALI_TEST_CHECK( timer.GetInterval() == 10);
264 timer.SetInterval(5000);
266 DALI_TEST_CHECK( timer.GetInterval() == 5000);
271 int UtcDaliTimerCopyConstructor(void)
273 AdaptorTestApplication application;
275 tet_printf("timer copy constructor \n");
276 Timer timer = Timer::New(10);
278 Timer anotherTimer( timer );
280 DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
284 int UtcDaliTimerAssignmentOperator(void)
286 AdaptorTestApplication application;
288 tet_printf("assignmnet constructor \n");
290 Timer timer = Timer::New(10);
292 DALI_TEST_CHECK( timer );
294 Timer anotherTimer = Timer::New(40);
296 DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
298 tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
299 tet_printf("timer 2 interval %d, \n",timer.GetInterval());
301 DALI_TEST_CHECK(timer != anotherTimer);
303 timer = anotherTimer;
305 DALI_TEST_CHECK(timer == anotherTimer);
307 tet_printf("timer 1 interval %d, \n",timer.GetInterval());
308 tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
310 DALI_TEST_CHECK(timer.GetInterval() == 40);
315 int UtcDaliTimerIsRunning(void)
317 AdaptorTestApplication application;
319 tet_printf("timer is running \n");
321 Timer timer = Timer::New(100);
325 DALI_TEST_CHECK( timer.IsRunning() );
329 DALI_TEST_CHECK( timer.IsRunning() == false );
334 int UtcDaliTimerSignalTickContinue(void)
336 AdaptorTestApplication application;
338 tet_printf("timer call back\n");
340 Timer timer = Timer::New(100);
341 TimerTestClass testClass(true);
343 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
347 test_ecore_main_loop_begin();
349 DALI_TEST_CHECK( testClass.mTimerCalled );
354 int UtcDaliTimerSignalTickStop(void)
356 AdaptorTestApplication application;
358 Timer timer = Timer::New(100);
359 TimerTestClass testClass(false);
361 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
365 test_ecore_main_loop_begin();
367 DALI_TEST_CHECK( testClass.mTimerCalled );
372 int UtcDaliTimerReset(void)
374 AdaptorTestApplication application;
376 Timer timer = Timer::New(100);
378 DALI_TEST_CHECK(timer);
382 DALI_TEST_CHECK(!timer);
387 int UtcDaliTimerDownCastP(void)
389 AdaptorTestApplication application;
391 Timer timer = Timer::New(100);
392 Timer cast = Timer::DownCast( timer );
394 DALI_TEST_CHECK( cast );
399 int UtcDaliTimerDownCastN(void)
401 AdaptorTestApplication application;
404 Timer cast = Timer::DownCast( timer );
406 DALI_TEST_CHECK( ! cast );