2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
25 void utc_dali_timer_startup(void)
27 test_return_value = TET_UNDEF;
30 void utc_dali_timer_cleanup(void)
32 test_return_value = TET_PASS;
37 bool ecore_timer_running = false;
38 Ecore_Task_Cb timer_callback_func=NULL;
39 const void* timer_callback_data=NULL;
40 bool main_loop_can_run = false;
46 Ecore_Timer* ecore_timer_add(double in,
50 ecore_timer_running = true;
51 timer_callback_func = func;
52 timer_callback_data = data;
54 return (Ecore_Timer*)timerId;
57 void* ecore_timer_del(Ecore_Timer *timer)
59 ecore_timer_running = false;
60 timer_callback_func = NULL;
69 void test_ecore_main_loop_begin()
71 if(timer_callback_func != NULL)
73 main_loop_can_run = true;
74 while( main_loop_can_run )
76 if( ! timer_callback_func(const_cast<void*>(timer_callback_data)) )
82 void test_ecore_main_loop_quit()
84 timer_callback_func = NULL;
85 main_loop_can_run = false;
90 * small class to test timer signal
92 class TimerTestClass : public ConnectionTracker
96 TimerTestClass(bool repeat):mTimerCalled(false),mReturnContiune(repeat) {}
100 tet_printf("timer ticked\n");
102 // quit the main loop otherwise we'll never return to tet
103 test_ecore_main_loop_quit();
104 return mReturnContiune;
106 bool mTimerCalled; // whether tick has been called or not
107 bool mReturnContiune; // whether to return true / false to continue
114 // Positive test case for a method
115 int UtcDaliTimerCreation(void)
117 // TestApplication application;
118 tet_printf("timer creation \n");
119 Timer timer = Timer::New(300);
121 DALI_TEST_CHECK( timer );
123 DALI_TEST_CHECK( timer.GetInterval() == 300);
128 int UtcDaliTimerUnitializedStart(void)
130 tet_printf("unintialized timer start \n");
132 Timer *timer = new Timer;
133 DALI_TEST_CHECK(timer != NULL);
139 catch(Dali::DaliException& e)
141 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
146 int UtcDaliTimerUnitializedStop(void)
148 tet_printf("unintialized timer stop \n");
150 Timer *timer = new Timer;
151 DALI_TEST_CHECK(timer != NULL);
157 catch(Dali::DaliException& e)
159 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
164 int UtcDaliTimerUnitializedGetInterval(void)
166 tet_printf("unintialized get interval \n");
168 Timer *timer = new Timer;
169 DALI_TEST_CHECK(timer != NULL);
173 timer->GetInterval();
175 catch(Dali::DaliException& e)
177 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
182 int UtcDaliTimerUnitializedSetInterval(void)
184 tet_printf("unintialized set interval \n");
186 Timer *timer = new Timer;
187 DALI_TEST_CHECK(timer != NULL);
191 timer->SetInterval(10);
193 catch(Dali::DaliException& e)
195 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
200 int UtcDaliTimerUnitializedIsRunning(void)
202 tet_printf("unintialized is running \n");
204 Timer *timer = new Timer;
205 DALI_TEST_CHECK(timer != NULL);
211 catch(Dali::DaliException& e)
213 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
219 int UtcDaliTimerUnitializedSignalTick(void)
221 tet_printf("unintialized SignalTick \n");
223 Timer *timer = new Timer;
224 DALI_TEST_CHECK(timer != NULL);
228 TimerTestClass testClass(true);// = new TimerTestClass(true);
230 timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
232 catch(Dali::DaliException& e)
234 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
239 int UtcDaliTimerSetInterval(void)
241 tet_printf("timer set interval \n");
242 Timer timer = Timer::New(10);
244 DALI_TEST_CHECK( timer.GetInterval() == 10);
246 timer.SetInterval(5000);
248 DALI_TEST_CHECK( timer.GetInterval() == 5000);
253 int UtcDaliTimerCopyConstructor(void)
255 tet_printf("timer copy constructor \n");
256 Timer timer = Timer::New(10);
258 Timer anotherTimer( timer );
260 DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
264 int UtcDaliTimerAssignmentOperator(void)
266 tet_printf("assignmnet constructor \n");
268 Timer timer = Timer::New(10);
270 DALI_TEST_CHECK( timer );
272 Timer anotherTimer = Timer::New(40);
274 DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
276 tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
277 tet_printf("timer 2 interval %d, \n",timer.GetInterval());
279 DALI_TEST_CHECK(timer != anotherTimer);
281 timer = anotherTimer;
283 DALI_TEST_CHECK(timer == anotherTimer);
285 tet_printf("timer 1 interval %d, \n",timer.GetInterval());
286 tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
288 DALI_TEST_CHECK(timer.GetInterval() == 40);
293 int UtcDaliTimerIsRunning(void)
295 tet_printf("timer is running \n");
297 Timer timer = Timer::New(100);
301 DALI_TEST_CHECK( timer.IsRunning() );
305 DALI_TEST_CHECK( timer.IsRunning() == false );
310 int UtcDaliTimerSignalTickContinue(void)
312 tet_printf("timer call back\n");
314 Timer timer = Timer::New(100);
315 TimerTestClass testClass(true);
317 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
321 test_ecore_main_loop_begin();
323 DALI_TEST_CHECK( testClass.mTimerCalled );
328 int UtcDaliTimerSignalTickStop(void)
330 Timer timer = Timer::New(100);
331 TimerTestClass testClass(false);
333 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
337 test_ecore_main_loop_begin();
339 DALI_TEST_CHECK( testClass.mTimerCalled );
344 int UtcDaliTimerReset(void)
346 Timer timer = Timer::New(100);
348 DALI_TEST_CHECK(timer);
352 DALI_TEST_CHECK(!timer);