Dali 3D User Interface Engine
utc-Dali-Timer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include <dali/dali.h>
22 #include <Ecore.h>
23 #include <dali-test-suite-utils.h>
24 
25 using namespace Dali;
26 
28 {
30 }
31 
33 {
35 }
36 
37 namespace
38 {
39 bool ecore_timer_running = false;
40 Ecore_Task_Cb timer_callback_func=NULL;
41 const void* timer_callback_data=NULL;
42 bool main_loop_can_run = false;
43 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
44 }// anon namespace
45 
46 extern "C"
47 {
48 Ecore_Timer* ecore_timer_add(double in,
49  Ecore_Task_Cb func,
50  const void *data)
51 {
52  ecore_timer_running = true;
53  timer_callback_func = func;
54  timer_callback_data = data;
55  timerId+=8;
56  return (Ecore_Timer*)timerId;
57 }
58 
59 void* ecore_timer_del(Ecore_Timer *timer)
60 {
61  ecore_timer_running = false;
62  timer_callback_func = NULL;
63  return NULL;
64 }
65 
66 }
67 
68 namespace
69 {
70 
72 {
73  if(timer_callback_func != NULL)
74  {
75  main_loop_can_run = true;
76  while( main_loop_can_run )
77  {
78  if( ! timer_callback_func(const_cast<void*>(timer_callback_data)) )
79  break;
80  }
81  }
82 }
83 
85 {
86  timer_callback_func = NULL;
87  main_loop_can_run = false;
88 }
89 
90 
95 {
96 public:
97 
98  TimerTestClass(bool repeat):mTimerCalled(false),mReturnContiune(repeat) {}
99 
100  bool Tick()
101  {
102  tet_printf("timer ticked\n");
103  mTimerCalled = true;
104  // quit the main loop otherwise we'll never return to tet
106  return mReturnContiune;
107  }
108  bool mTimerCalled; // whether tick has been called or not
109  bool mReturnContiune; // whether to return true / false to continue
110 
111 };
112 
113 } // anon namespace
114 
115 
116 // Positive test case for a method
118 {
119  // TestApplication application;
120  tet_printf("timer creation \n");
121  Timer timer = Timer::New(300);
122 
123  DALI_TEST_CHECK( timer );
124 
125  DALI_TEST_CHECK( timer.GetInterval() == 300);
126 
127  END_TEST;
128 }
129 
131 {
132  tet_printf("unintialized timer start \n");
133 
134  Timer *timer = new Timer;
135  DALI_TEST_CHECK(timer != NULL);
136 
137  try
138  {
139  timer->Start();
140  }
141  catch(Dali::DaliException& e)
142  {
143  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
144  }
145  END_TEST;
146 }
147 
149 {
150  tet_printf("unintialized timer stop \n");
151 
152  Timer *timer = new Timer;
153  DALI_TEST_CHECK(timer != NULL);
154 
155  try
156  {
157  timer->Stop();
158  }
159  catch(Dali::DaliException& e)
160  {
161  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
162  }
163  END_TEST;
164 }
165 
167 {
168  tet_printf("unintialized get interval \n");
169 
170  Timer *timer = new Timer;
171  DALI_TEST_CHECK(timer != NULL);
172 
173  try
174  {
175  timer->GetInterval();
176  }
177  catch(Dali::DaliException& e)
178  {
179  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
180  }
181  END_TEST;
182 }
183 
185 {
186  tet_printf("unintialized set interval \n");
187 
188  Timer *timer = new Timer;
189  DALI_TEST_CHECK(timer != NULL);
190 
191  try
192  {
193  timer->SetInterval(10);
194  }
195  catch(Dali::DaliException& e)
196  {
197  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
198  }
199  END_TEST;
200 }
201 
203 {
204  tet_printf("unintialized is running \n");
205 
206  Timer *timer = new Timer;
207  DALI_TEST_CHECK(timer != NULL);
208 
209  try
210  {
211  timer->IsRunning();
212  }
213  catch(Dali::DaliException& e)
214  {
215  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
216  }
217  END_TEST;
218 }
219 
220 
222 {
223  tet_printf("unintialized SignalTick \n");
224 
225  Timer *timer = new Timer;
226  DALI_TEST_CHECK(timer != NULL);
227 
228  try
229  {
230  TimerTestClass testClass(true);// = new TimerTestClass(true);
231 
232  timer->TickSignal().Connect(&testClass, &TimerTestClass::Tick);
233  }
234  catch(Dali::DaliException& e)
235  {
236  DALI_TEST_ASSERT(e, "timer", TEST_LOCATION);
237  }
238  END_TEST;
239 }
240 
242 {
243  tet_printf("timer set interval \n");
244  Timer timer = Timer::New(10);
245 
246  DALI_TEST_CHECK( timer.GetInterval() == 10);
247 
248  timer.SetInterval(5000);
249 
250  DALI_TEST_CHECK( timer.GetInterval() == 5000);
251 
252  END_TEST;
253 }
254 
256 {
257  tet_printf("timer copy constructor \n");
258  Timer timer = Timer::New(10);
259 
260  Timer anotherTimer( timer );
261 
262  DALI_TEST_CHECK( anotherTimer.GetInterval() == 10);
263  END_TEST;
264 }
265 
267 {
268  tet_printf("assignmnet constructor \n");
269 
270  Timer timer = Timer::New(10);
271 
272  DALI_TEST_CHECK( timer );
273 
274  Timer anotherTimer = Timer::New(40);
275 
276  DALI_TEST_CHECK(anotherTimer.GetInterval() == 40);
277 
278  tet_printf("timer 1 interval %d, \n",anotherTimer.GetInterval());
279  tet_printf("timer 2 interval %d, \n",timer.GetInterval());
280 
281  DALI_TEST_CHECK(timer != anotherTimer);
282 
283  timer = anotherTimer;
284 
285  DALI_TEST_CHECK(timer == anotherTimer);
286 
287  tet_printf("timer 1 interval %d, \n",timer.GetInterval());
288  tet_printf("timer 2 interval %d, \n",anotherTimer.GetInterval());
289 
290  DALI_TEST_CHECK(timer.GetInterval() == 40);
291 
292  END_TEST;
293 }
294 
296 {
297  tet_printf("timer is running \n");
298 
299  Timer timer = Timer::New(100);
300 
301  timer.Start();
302 
303  DALI_TEST_CHECK( timer.IsRunning() );
304 
305  timer.Stop();
306 
307  DALI_TEST_CHECK( timer.IsRunning() == false );
308 
309  END_TEST;
310 }
311 
313 {
314  tet_printf("timer call back\n");
315 
316  Timer timer = Timer::New(100);
317  TimerTestClass testClass(true);
318 
319  timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
320 
321  timer.Start();
322 
324 
325  DALI_TEST_CHECK( testClass.mTimerCalled );
326 
327  END_TEST;
328 }
329 
331 {
332  Timer timer = Timer::New(100);
333  TimerTestClass testClass(false);
334 
335  timer.TickSignal().Connect(&testClass, &TimerTestClass::Tick);
336 
337  timer.Start();
338 
340 
341  DALI_TEST_CHECK( testClass.mTimerCalled );
342 
343  END_TEST;
344 }
345 
347 {
348  Timer timer = Timer::New(100);
349 
350  DALI_TEST_CHECK(timer);
351 
352  timer.Reset();
353 
354  DALI_TEST_CHECK(!timer);
355 
356  END_TEST;
357 }
358 
360 {
361  Timer timer = Timer::New(100);
362  Timer cast = Timer::DownCast( timer );
363 
364  DALI_TEST_CHECK( cast );
365 
366  END_TEST;
367 }
368 
370 {
371  Timer timer;
372  Timer cast = Timer::DownCast( timer );
373 
374  DALI_TEST_CHECK( ! cast );
375 
376  END_TEST;
377 }
Dali Docs Home
Read more about Dali