2 * Copyright (c) 2022 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.
18 #include <adaptor-test-application.h>
19 #include <dali-test-suite-utils.h>
20 #include <dali/dali.h>
21 #include <dali/internal/system/linux/dali-ecore.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;
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;
90 * small class to test timer signal
92 class TimerTestClass : public ConnectionTracker
95 TimerTestClass(bool repeat)
96 : mTimerCalled(false),
97 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
115 // Positive test case for a method
116 int UtcDaliTimerCreation(void)
118 AdaptorTestApplication application;
120 tet_printf("timer creation \n");
121 Timer timer = Timer::New(300);
123 DALI_TEST_CHECK(timer);
125 DALI_TEST_CHECK(timer.GetInterval() == 300);
130 int UtcDaliTimerUnitializedStart(void)
132 AdaptorTestApplication application;
134 tet_printf("unintialized timer start \n");
136 Timer* timer = new Timer;
137 DALI_TEST_CHECK(timer != NULL);
143 catch(Dali::DaliException& e)
145 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
150 int UtcDaliTimerUnitializedStop(void)
152 AdaptorTestApplication application;
154 tet_printf("unintialized timer stop \n");
156 Timer* timer = new Timer;
157 DALI_TEST_CHECK(timer != NULL);
163 catch(Dali::DaliException& e)
165 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
170 int UtcDaliTimerUnitializedGetInterval(void)
172 AdaptorTestApplication application;
174 tet_printf("unintialized get interval \n");
176 Timer* timer = new Timer;
177 DALI_TEST_CHECK(timer != NULL);
181 timer->GetInterval();
183 catch(Dali::DaliException& e)
185 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
190 int UtcDaliTimerUnitializedSetInterval(void)
192 AdaptorTestApplication application;
194 tet_printf("unintialized set interval \n");
196 Timer* timer = new Timer;
197 DALI_TEST_CHECK(timer != NULL);
201 timer->SetInterval(10);
203 catch(Dali::DaliException& e)
205 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
210 int UtcDaliTimerUnitializedIsRunning(void)
212 AdaptorTestApplication application;
214 tet_printf("unintialized is running \n");
216 Timer* timer = new Timer;
217 DALI_TEST_CHECK(timer != NULL);
223 catch(Dali::DaliException& e)
225 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
230 int UtcDaliTimerUnitializedSignalTick(void)
232 AdaptorTestApplication application;
234 tet_printf("unintialized SignalTick \n");
236 Timer* timer = new Timer;
237 DALI_TEST_CHECK(timer != NULL);
241 TimerTestClass testClass(true); // = new TimerTestClass(true);
243 timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
245 catch(Dali::DaliException& e)
247 DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
252 int UtcDaliTimerSetInterval(void)
254 AdaptorTestApplication application;
256 tet_printf("timer set interval \n");
257 Timer timer = Timer::New(10);
259 DALI_TEST_CHECK(timer.GetInterval() == 10);
261 timer.SetInterval(5000);
263 DALI_TEST_CHECK(timer.GetInterval() == 5000);
268 int UtcDaliTimerSetInterval02(void)
270 AdaptorTestApplication application;
272 tet_printf("timer set interval 02 \n");
273 Timer timer = Timer::New(10);
274 timer.SetInterval(20);
276 DALI_TEST_CHECK(timer.GetInterval() == 20);
277 DALI_TEST_CHECK(timer.IsRunning() == true);
279 timer.SetInterval(5000, false);
281 DALI_TEST_CHECK(timer.GetInterval() == 5000);
282 DALI_TEST_CHECK(timer.IsRunning() == false);
287 int UtcDaliTimerSetInterval03(void)
289 AdaptorTestApplication application;
291 tet_printf("UtcDaliTimerSetInterval03 SetInterval and ensure timer restarts \n");
292 Timer timer = Timer::New(10);
293 timer.SetInterval(20);
295 DALI_TEST_CHECK(timer.GetInterval() == 20);
296 DALI_TEST_CHECK(timer.IsRunning() == true);
298 timer.SetInterval(5000, true);
300 DALI_TEST_CHECK(timer.GetInterval() == 5000);
301 DALI_TEST_CHECK(timer.IsRunning() == true);
306 int UtcDaliTimerCopyConstructor(void)
308 AdaptorTestApplication application;
310 tet_printf("timer copy constructor \n");
311 Timer timer = Timer::New(10);
313 Timer anotherTimer(timer);
315 DALI_TEST_CHECK(anotherTimer.GetInterval() == 10);
319 int UtcDaliTimerAssignmentOperator(void)
321 AdaptorTestApplication application;
323 tet_printf("assignmnet constructor \n");
325 Timer timer = Timer::New(10);
327 DALI_TEST_CHECK(timer);
329 Timer anotherTimer = Timer::New(40);
331 DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
333 tet_printf("timer 1 interval %d, \n", anotherTimer.GetInterval());
334 tet_printf("timer 2 interval %d, \n", timer.GetInterval());
336 DALI_TEST_CHECK(timer != anotherTimer);
338 timer = anotherTimer;
340 DALI_TEST_CHECK(timer == anotherTimer);
342 tet_printf("timer 1 interval %d, \n", timer.GetInterval());
343 tet_printf("timer 2 interval %d, \n", anotherTimer.GetInterval());
345 DALI_TEST_CHECK(timer.GetInterval() == 40);
350 int UtcDaliTimerMoveConstructor(void)
352 AdaptorTestApplication application;
354 Timer timer = Timer::New(40);
355 DALI_TEST_CHECK(timer);
356 DALI_TEST_EQUALS(1, timer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
357 DALI_TEST_CHECK(timer.GetInterval() == 40);
359 Timer moved = std::move(timer);
360 DALI_TEST_CHECK(moved);
361 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
362 DALI_TEST_CHECK(moved.GetInterval() == 40);
363 DALI_TEST_CHECK(!timer);
368 int UtcDaliTimerMoveAssignmentr(void)
370 AdaptorTestApplication application;
372 Timer timer = Timer::New(40);
373 DALI_TEST_CHECK(timer);
374 DALI_TEST_EQUALS(1, timer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
375 DALI_TEST_CHECK(timer.GetInterval() == 40);
378 moved = std::move(timer);
379 DALI_TEST_CHECK(moved);
380 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
381 DALI_TEST_CHECK(moved.GetInterval() == 40);
382 DALI_TEST_CHECK(!timer);
387 int UtcDaliTimerIsRunning(void)
389 AdaptorTestApplication application;
391 tet_printf("timer is running \n");
393 Timer timer = Timer::New(100);
397 DALI_TEST_CHECK(timer.IsRunning());
401 DALI_TEST_CHECK(timer.IsRunning() == false);
406 int UtcDaliTimerSignalTickContinue(void)
408 AdaptorTestApplication application;
410 tet_printf("timer call back\n");
412 Timer timer = Timer::New(100);
413 TimerTestClass testClass(true);
415 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
419 test_ecore_main_loop_begin();
421 DALI_TEST_CHECK(testClass.mTimerCalled);
426 int UtcDaliTimerSignalTickStop(void)
428 AdaptorTestApplication application;
430 Timer timer = Timer::New(100);
431 TimerTestClass testClass(false);
433 timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
437 test_ecore_main_loop_begin();
439 DALI_TEST_CHECK(testClass.mTimerCalled);
444 int UtcDaliTimerReset(void)
446 AdaptorTestApplication application;
448 Timer timer = Timer::New(100);
450 DALI_TEST_CHECK(timer);
454 DALI_TEST_CHECK(!timer);
459 int UtcDaliTimerDownCastP(void)
461 AdaptorTestApplication application;
463 Timer timer = Timer::New(100);
464 Timer cast = Timer::DownCast(timer);
466 DALI_TEST_CHECK(cast);
471 int UtcDaliTimerDownCastN(void)
473 AdaptorTestApplication application;
476 Timer cast = Timer::DownCast(timer);
478 DALI_TEST_CHECK(!cast);
483 int UtcDaliTimerPauseN(void)
490 DALI_TEST_CHECK(false); // Should not get here
494 DALI_TEST_CHECK(true);
499 int UtcDaliTimerResumeN(void)
506 DALI_TEST_CHECK(false); // Should not get here
510 DALI_TEST_CHECK(true);