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.
20 #include <dali/dali.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_timer_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_timer_cleanup(void)
33 test_return_value = TET_PASS;
38 bool ecore_timer_running = false;
39 Ecore_Task_Cb timer_callback_func=NULL;
40 const void* timer_callback_data=NULL;
41 bool main_loop_can_run = false;
47 Ecore_Timer* ecore_timer_add(double in,
51 ecore_timer_running = true;
52 timer_callback_func = func;
53 timer_callback_data = data;
55 return (Ecore_Timer*)timerId;
58 void* ecore_timer_del(Ecore_Timer *timer)
60 ecore_timer_running = false;
61 timer_callback_func = NULL;
70 void test_ecore_main_loop_begin()
72 if(timer_callback_func != NULL)
74 main_loop_can_run = true;
75 while( main_loop_can_run )
77 if( ! timer_callback_func(const_cast<void*>(timer_callback_data)) )
83 void test_ecore_main_loop_quit()
85 timer_callback_func = NULL;
86 main_loop_can_run = false;
91 * small class to test timer signal
93 class TimerTestClass : public ConnectionTracker
97 TimerTestClass(bool repeat):mTimerCalled(false),mReturnContiune(repeat) {}
101 tet_printf("timer ticked\n");
103 // quit the main loop otherwise we'll never return to tet
104 test_ecore_main_loop_quit();
105 return mReturnContiune;
107 bool mTimerCalled; // whether tick has been called or not
108 bool mReturnContiune; // whether to return true / false to continue
115 // Positive test case for a method
116 int UtcDaliTimerCreation(void)
118 // TestApplication application;
119 tet_printf("timer creation \n");
120 Timer timer = Timer::New(300);
122 DALI_TEST_CHECK( timer );
124 DALI_TEST_CHECK( timer.GetInterval() == 300);
129 int UtcDaliTimerUnitializedStart(void)
131 tet_printf("unintialized timer start \n");
133 Timer *timer = new Timer;
134 DALI_TEST_CHECK(timer != NULL);
140 catch(Dali::DaliException& e)
142 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
147 int UtcDaliTimerUnitializedStop(void)
149 tet_printf("unintialized timer stop \n");
151 Timer *timer = new Timer;
152 DALI_TEST_CHECK(timer != NULL);
158 catch(Dali::DaliException& e)
160 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
165 int UtcDaliTimerUnitializedGetInterval(void)
167 tet_printf("unintialized get interval \n");
169 Timer *timer = new Timer;
170 DALI_TEST_CHECK(timer != NULL);
174 timer->GetInterval();
176 catch(Dali::DaliException& e)
178 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
183 int UtcDaliTimerUnitializedSetInterval(void)
185 tet_printf("unintialized set interval \n");
187 Timer *timer = new Timer;
188 DALI_TEST_CHECK(timer != NULL);
192 timer->SetInterval(10);
194 catch(Dali::DaliException& e)
196 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
201 int UtcDaliTimerUnitializedIsRunning(void)
203 tet_printf("unintialized is running \n");
205 Timer *timer = new Timer;
206 DALI_TEST_CHECK(timer != NULL);
212 catch(Dali::DaliException& e)
214 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
220 int UtcDaliTimerUnitializedSignalTick(void)
222 tet_printf("unintialized SignalTick \n");
224 Timer *timer = new Timer;
225 DALI_TEST_CHECK(timer != NULL);
229 TimerTestClass testClass(true);// = new TimerTestClass(true);
231 timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
233 catch(Dali::DaliException& e)
235 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
240 int UtcDaliTimerSetInterval(void)
242 tet_printf("timer set interval \n");
243 Timer timer = Timer::New(10);
245 DALI_TEST_CHECK( timer.GetInterval() == 10);
247 timer.SetInterval(5000);
249 DALI_TEST_CHECK( timer.GetInterval() == 5000);
254 int UtcDaliTimerCopyConstructor(void)
256 tet_printf("timer copy constructor \n");
257 Timer timer = Timer::New(10);
259 Timer anotherTimer( timer );
261 DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
265 int UtcDaliTimerAssignmentOperator(void)
267 tet_printf("assignmnet constructor \n");
269 Timer timer = Timer::New(10);
271 DALI_TEST_CHECK( timer );
273 Timer anotherTimer = Timer::New(40);
275 DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
277 tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
278 tet_printf("timer 2 interval %d, \n",timer.GetInterval());
280 DALI_TEST_CHECK(timer != anotherTimer);
282 timer = anotherTimer;
284 DALI_TEST_CHECK(timer == anotherTimer);
286 tet_printf("timer 1 interval %d, \n",timer.GetInterval());
287 tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
289 DALI_TEST_CHECK(timer.GetInterval() == 40);
294 int UtcDaliTimerIsRunning(void)
296 tet_printf("timer is running \n");
298 Timer timer = Timer::New(100);
302 DALI_TEST_CHECK( timer.IsRunning() );
306 DALI_TEST_CHECK( timer.IsRunning() == false );
311 int UtcDaliTimerSignalTickContinue(void)
313 tet_printf("timer call back\n");
315 Timer timer = Timer::New(100);
316 TimerTestClass testClass(true);
318 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
322 test_ecore_main_loop_begin();
324 DALI_TEST_CHECK( testClass.mTimerCalled );
329 int UtcDaliTimerSignalTickStop(void)
331 Timer timer = Timer::New(100);
332 TimerTestClass testClass(false);
334 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
338 test_ecore_main_loop_begin();
340 DALI_TEST_CHECK( testClass.mTimerCalled );
345 int UtcDaliTimerReset(void)
347 Timer timer = Timer::New(100);
349 DALI_TEST_CHECK(timer);
353 DALI_TEST_CHECK(!timer);