2 * Copyright (c) 2020 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>
22 #include <dali/internal/system/linux/dali-ecore.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 UtcDaliTimerSetInterval02(void)
273 AdaptorTestApplication application;
275 tet_printf("timer set interval 02 \n");
276 Timer timer = Timer::New(10);
277 timer.SetInterval(20);
279 DALI_TEST_CHECK( timer.GetInterval() == 20 );
280 DALI_TEST_CHECK( timer.IsRunning() == true );
282 timer.SetInterval(5000, false);
284 DALI_TEST_CHECK( timer.GetInterval() == 5000 );
285 DALI_TEST_CHECK( timer.IsRunning() == false );
290 int UtcDaliTimerSetInterval03(void)
292 AdaptorTestApplication application;
294 tet_printf("UtcDaliTimerSetInterval03 SetInterval and ensure timer restarts \n");
295 Timer timer = Timer::New(10);
296 timer.SetInterval(20);
298 DALI_TEST_CHECK( timer.GetInterval() == 20 );
299 DALI_TEST_CHECK( timer.IsRunning() == true );
301 timer.SetInterval(5000, true);
303 DALI_TEST_CHECK( timer.GetInterval() == 5000 );
304 DALI_TEST_CHECK( timer.IsRunning() == true );
309 int UtcDaliTimerCopyConstructor(void)
311 AdaptorTestApplication application;
313 tet_printf("timer copy constructor \n");
314 Timer timer = Timer::New(10);
316 Timer anotherTimer( timer );
318 DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
322 int UtcDaliTimerAssignmentOperator(void)
324 AdaptorTestApplication application;
326 tet_printf("assignmnet constructor \n");
328 Timer timer = Timer::New(10);
330 DALI_TEST_CHECK( timer );
332 Timer anotherTimer = Timer::New(40);
334 DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
336 tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
337 tet_printf("timer 2 interval %d, \n",timer.GetInterval());
339 DALI_TEST_CHECK(timer != anotherTimer);
341 timer = anotherTimer;
343 DALI_TEST_CHECK(timer == anotherTimer);
345 tet_printf("timer 1 interval %d, \n",timer.GetInterval());
346 tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
348 DALI_TEST_CHECK(timer.GetInterval() == 40);
353 int UtcDaliTimerMoveConstructor(void)
355 AdaptorTestApplication application;
357 Timer timer = Timer::New( 40 );
358 DALI_TEST_CHECK( timer );
359 DALI_TEST_EQUALS( 1, timer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
360 DALI_TEST_CHECK( timer.GetInterval() == 40) ;
362 Timer moved = std::move( timer );
363 DALI_TEST_CHECK( moved );
364 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
365 DALI_TEST_CHECK( moved.GetInterval() == 40 );
366 DALI_TEST_CHECK( !timer );
371 int UtcDaliTimerMoveAssignmentr(void)
373 AdaptorTestApplication application;
375 Timer timer = Timer::New( 40 );
376 DALI_TEST_CHECK( timer );
377 DALI_TEST_EQUALS( 1, timer.GetBaseObject().ReferenceCount(), TEST_LOCATION );
378 DALI_TEST_CHECK( timer.GetInterval() == 40) ;
381 moved = std::move( timer );
382 DALI_TEST_CHECK( moved );
383 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
384 DALI_TEST_CHECK( moved.GetInterval() == 40 );
385 DALI_TEST_CHECK( !timer );
390 int UtcDaliTimerIsRunning(void)
392 AdaptorTestApplication application;
394 tet_printf("timer is running \n");
396 Timer timer = Timer::New(100);
400 DALI_TEST_CHECK( timer.IsRunning() );
404 DALI_TEST_CHECK( timer.IsRunning() == false );
409 int UtcDaliTimerSignalTickContinue(void)
411 AdaptorTestApplication application;
413 tet_printf("timer call back\n");
415 Timer timer = Timer::New(100);
416 TimerTestClass testClass(true);
418 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
422 test_ecore_main_loop_begin();
424 DALI_TEST_CHECK( testClass.mTimerCalled );
429 int UtcDaliTimerSignalTickStop(void)
431 AdaptorTestApplication application;
433 Timer timer = Timer::New(100);
434 TimerTestClass testClass(false);
436 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
440 test_ecore_main_loop_begin();
442 DALI_TEST_CHECK( testClass.mTimerCalled );
447 int UtcDaliTimerReset(void)
449 AdaptorTestApplication application;
451 Timer timer = Timer::New(100);
453 DALI_TEST_CHECK(timer);
457 DALI_TEST_CHECK(!timer);
462 int UtcDaliTimerDownCastP(void)
464 AdaptorTestApplication application;
466 Timer timer = Timer::New(100);
467 Timer cast = Timer::DownCast( timer );
469 DALI_TEST_CHECK( cast );
474 int UtcDaliTimerDownCastN(void)
476 AdaptorTestApplication application;
479 Timer cast = Timer::DownCast( timer );
481 DALI_TEST_CHECK( ! cast );