Mercurial > MadButterfly
annotate src/animate.c @ 119:257a1d314bcd
Bug of insert sort
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 14 Sep 2008 21:08:25 +0800 |
parents | e4e47d2cdbcd |
children | 5df7403b6fbc |
rev | line source |
---|---|
111 | 1 /*! \file |
2 * \brief Animation tools. | |
3 * | |
117 | 4 * \sa \ref ani |
111 | 5 */ |
6 /*! \page ani What is Animation? | |
41 | 7 * |
117 | 8 * Animation is a program to move, resize, rotate, ..., changing |
9 * graphics on the output screen. | |
10 * | |
11 * \image html program.png | |
12 * | |
41 | 13 * XXX: Program is a sequence of actions duration a perior. |
14 * Actions are grouped into words. A program defines | |
15 * the order and time of playing of words. A word | |
16 * defines how long to perform a set of actions. Actions | |
17 * in a word are performed concurrently. | |
45 | 18 * |
19 * Animation shapes are updated periodically. Every action | |
20 * are working with start, step, and stop 3 calls. start is | |
21 * called when start time the word, contain it, due. step is | |
22 * called periodically in duration of playing time start at | |
23 * 'start time'. When the clock run out the playing time of | |
24 * a word, it call stop of actions in the word. | |
111 | 25 * |
26 * A program is driven by a timer. Once a program is started, it registers | |
27 * with timer for periodic running. \ref mb_tman_t is timer of | |
28 * MadButterfly. The update frequence is 10fps by default, now. | |
29 * | |
117 | 30 * \section use_progm How to Use Animation Program? |
31 * Following code block creates a program with 2 words. First word is | |
32 * started immediately after the program been started. It is consisted | |
33 * for 1 second. Second word is started 1 second after the program been | |
34 * started. It is consisted for 2 seconds. There are 2 action in | |
35 * first word, they shift graphics managed by coord1 & coord2 by (50,50) and | |
36 * (-50,50) pixels, respectly. The shifting is performed incrementally | |
37 * in 1 second. Second word shifts coord1 and coord2, too. And, graphics | |
38 * managed by coord3 are hidden at end of the word. At end of code in the | |
39 * block, mb_progm_start() starts the program. 3rd argument of | |
40 * mb_progm_start() must be current wall time. | |
41 * | |
42 * \code | |
43 * progm = mb_progm_new(10, &rdman); | |
44 * | |
45 * MB_TIMEVAL_SET(&start, 0, 0); | |
46 * MB_TIMEVAL_SET(&playing, 1, 0); | |
47 * word = mb_progm_next_word(progm, &start, &playing); | |
48 * | |
49 * act = mb_shift_new(50, 50, coord1, word); | |
50 * act = mb_shift_new(-50, 50, coord2, word); | |
51 * | |
52 * MB_TIMEVAL_SET(&start, 1, 0); | |
53 * MB_TIMEVAL_SET(&playing, 2, 0); | |
54 * word = mb_progm_next_word(progm, &start, &playing); | |
55 * | |
56 * act = mb_shift_new(0, 20, coord1, word); | |
57 * act = mb_shift_new(0, -20, coord2, word); | |
58 * act = mb_visibility_new(VIS_HIDDEN, coord3, word); | |
59 * | |
60 * gettimeofday(&tv, NULL); | |
61 * MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | |
62 * mb_progm_start(progm, tman, &mbtv); | |
63 * \endcode | |
64 * | |
65 * | |
66 * \sa \ref animate.c | |
41 | 67 */ |
68 #include <stdio.h> | |
69 #include <stdlib.h> | |
70 #include <string.h> | |
71 #include "mb_types.h" | |
72 #include "redraw_man.h" | |
73 #include "mb_timer.h" | |
74 #include "animate.h" | |
75 | |
76 | |
42 | 77 #define STEP_INTERVAL 100000 |
41 | 78 #define ASSERT(x) |
79 | |
80 /*! \brief A word is a set of concurrent actions in a program. | |
81 */ | |
82 struct _mb_word { | |
83 mb_timeval_t start_time; /*!< time to start the word */ | |
84 mb_timeval_t playing_time; /*!< time duration of playing */ | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
85 mb_timeval_t abs_start, abs_stop; |
41 | 86 STAILQ(mb_action_t) actions; |
87 }; | |
88 | |
89 /*! \brief A program describe a series of actions to animate shapes. | |
51 | 90 * |
91 * first_playing is an index to one of words. It always points to | |
92 * the first of words that is playing or waiting for playing. | |
41 | 93 */ |
94 struct _mb_progm { | |
95 redraw_man_t *rdman; | |
96 | |
46 | 97 mb_timeval_t start_time; |
41 | 98 int first_playing; /*!< first playing word. */ |
99 mb_tman_t *tman; | |
100 | |
101 int n_words; | |
102 int max_words; | |
103 mb_word_t words[1]; | |
104 }; | |
105 | |
119 | 106 /*! \brief Create a program object. |
107 * | |
108 * \param max_words is maximum number of words the program can hold. | |
109 * \param rdman is a rdman that show graphics manipulated by it. | |
110 */ | |
41 | 111 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { |
112 mb_progm_t *progm; | |
113 int i; | |
114 | |
115 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + | |
116 (sizeof(mb_word_t) * (max_words - 1))); | |
117 if(progm == NULL) | |
118 return NULL; | |
119 | |
120 progm->rdman = rdman; | |
121 progm->n_words = 0; | |
122 progm->max_words = max_words; | |
123 for(i = 0; i < max_words; i++) | |
124 STAILQ_INIT(progm->words[i].actions); | |
125 return progm; | |
126 } | |
127 | |
128 void mb_progm_free(mb_progm_t *progm) { | |
129 int n_words; | |
130 mb_word_t *word; | |
131 mb_action_t *cur_act; | |
132 int i; | |
133 | |
134 n_words = progm->n_words; | |
135 for(i = 0; i < n_words; i++) { | |
136 word = progm->words + i; | |
137 for(cur_act = STAILQ_HEAD(word->actions); | |
138 cur_act != NULL; | |
139 cur_act = STAILQ_HEAD(word->actions)) { | |
140 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act); | |
141 cur_act->free(cur_act); | |
142 } | |
143 } | |
144 free(progm); | |
145 } | |
146 | |
147 /*! \brief Add a new word into a program. | |
148 * | |
149 * The start time of new word should bigger or equal to last one. | |
150 * The time should be specified in incremental order. | |
151 */ | |
152 mb_word_t *mb_progm_next_word(mb_progm_t *progm, | |
153 const mb_timeval_t *start, | |
154 const mb_timeval_t *playing) { | |
155 mb_word_t *word; | |
156 if(progm->n_words >= progm->max_words) | |
157 return NULL; | |
158 if(progm->n_words && | |
159 MB_TIMEVAL_LATER(&progm->words[progm->n_words - 1].start_time, start)) | |
160 return NULL; | |
161 word = progm->words + progm->n_words++; | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
162 MB_TIMEVAL_CP(&word->start_time, start); |
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
163 MB_TIMEVAL_CP(&word->playing_time, playing); |
41 | 164 return word; |
165 } | |
166 | |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
111
diff
changeset
|
167 void mb_word_add_action(mb_word_t *word, mb_action_t *act) { |
41 | 168 STAILQ_INS_TAIL(word->actions, mb_action_t, next, act); |
169 } | |
170 | |
171 static void mb_word_start(mb_word_t *word, const mb_timeval_t *tmo, | |
172 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 173 mb_action_t *act; |
174 | |
175 for(act = STAILQ_HEAD(word->actions); | |
176 act != NULL; | |
177 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
178 act->start(act, tmo, &word->playing_time, rdman); | |
179 } | |
41 | 180 } |
181 | |
182 static void mb_word_step(mb_word_t *word, const mb_timeval_t *tmo, | |
183 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 184 mb_action_t *act; |
185 | |
186 for(act = STAILQ_HEAD(word->actions); | |
187 act != NULL; | |
188 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
189 act->step(act, tmo, rdman); | |
190 } | |
41 | 191 } |
192 | |
193 static void mb_word_stop(mb_word_t *word, const mb_timeval_t *tmo, | |
194 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 195 mb_action_t *act; |
196 | |
197 for(act = STAILQ_HEAD(word->actions); | |
198 act != NULL; | |
199 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
200 act->stop(act, tmo, rdman); | |
201 } | |
41 | 202 } |
203 | |
46 | 204 /* |
205 * Any two actions in concurrent words never change the same attribute. | |
206 * Start time of words in a program are specified in incremental order. | |
207 */ | |
41 | 208 static void mb_progm_step(const mb_timeval_t *tmo, |
46 | 209 const mb_timeval_t *now, |
210 void *arg) { | |
41 | 211 mb_progm_t *progm = (mb_progm_t *)arg; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
212 mb_timeval_t next_tmo; |
41 | 213 mb_word_t *word; |
214 mb_timer_t *timer; | |
215 int i; | |
216 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
217 MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
218 MB_TIMEVAL_ADD(&next_tmo, tmo); |
41 | 219 |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
220 /* _step() or _stop() words that in playing. */ |
41 | 221 i = progm->first_playing; |
222 for(word = progm->words + i; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
223 i < progm->n_words && MB_TIMEVAL_LATER(tmo, &word->abs_start); |
41 | 224 word = progm->words + ++i) { |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
225 if(MB_TIMEVAL_LATER(tmo, &word->abs_stop)) |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
226 continue; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
227 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 228 mb_word_stop(word, tmo, now, progm->rdman); |
229 else | |
41 | 230 mb_word_step(word, tmo, now, progm->rdman); |
231 } | |
232 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
233 /* Start words that their abs_start is in duration |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
234 * from now to timeout for next update. |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
235 */ |
41 | 236 for(word = progm->words + i; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
237 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_start); |
41 | 238 word = progm->words + ++i) { |
239 mb_word_start(word, tmo, now, progm->rdman); | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
240 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 241 mb_word_stop(word, tmo, now, progm->rdman); |
41 | 242 } |
243 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
244 /* Find a new first_playing if any consequence words, following current |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
245 * first_playing word, are stoped. |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
246 */ |
46 | 247 i = progm->first_playing; |
248 for(word = progm->words + i; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
249 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop); |
46 | 250 word = progm->words + ++i) { |
251 progm->first_playing++; | |
252 } | |
253 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
254 /* Setup timeout for next update. */ |
41 | 255 if(progm->first_playing < progm->n_words) { |
42 | 256 word = progm->words + progm->first_playing; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
257 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
258 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); |
46 | 259 timer = mb_tman_timeout(progm->tman, &next_tmo, |
260 mb_progm_step, progm); | |
41 | 261 } |
262 } | |
263 | |
264 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, | |
265 mb_timeval_t *now) { | |
266 mb_timer_t *timer; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
267 mb_word_t *word; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
268 int i; |
41 | 269 |
270 if(progm->n_words == 0) | |
271 return; | |
272 | |
273 progm->tman = tman; | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
274 MB_TIMEVAL_CP(&progm->start_time, now); |
41 | 275 progm->first_playing = 0; |
276 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
277 for(i = 0; i < progm->n_words; i++) { |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
278 word = progm->words + i; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
279 MB_TIMEVAL_CP(&word->abs_start, &word->start_time); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
280 MB_TIMEVAL_ADD(&word->abs_start, now); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
281 MB_TIMEVAL_CP(&word->abs_stop, &word->abs_start); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
282 MB_TIMEVAL_ADD(&word->abs_stop, &word->playing_time); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
283 } |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
284 |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
285 if(MB_TIMEVAL_EQ(&progm->words[0].abs_start, now)) { |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
286 mb_progm_step(now, now, progm); |
41 | 287 return; |
288 } | |
289 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
290 timer = mb_tman_timeout(tman, &progm->words[0].abs_start, |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
291 mb_progm_step, progm); |
41 | 292 ASSERT(timer != NULL); |
293 } | |
294 | |
42 | 295 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { |
296 } | |
297 | |
50 | 298 #ifdef UNITTEST |
299 | |
300 #include <CUnit/Basic.h> | |
301 | |
302 typedef struct _mb_dummy mb_dummy_t; | |
303 | |
304 struct _mb_dummy { | |
305 mb_action_t action; | |
306 int id; | |
307 int *logidx; | |
308 int *logs; | |
309 }; | |
310 | |
311 | |
312 static void mb_dummy_start(mb_action_t *act, | |
313 const mb_timeval_t *now, | |
314 const mb_timeval_t *playing_time, | |
315 redraw_man_t *rdman) { | |
316 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
317 | |
318 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
319 } | |
320 | |
321 static void mb_dummy_step(mb_action_t *act, | |
322 const mb_timeval_t *now, | |
323 redraw_man_t *rdman) { | |
324 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
325 | |
326 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
327 } | |
328 | |
329 static void mb_dummy_stop(mb_action_t *act, | |
330 const mb_timeval_t *now, | |
331 redraw_man_t *rdman) { | |
332 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
333 | |
334 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
335 } | |
336 | |
337 static void mb_dummy_free(mb_action_t *act) { | |
338 free(act); | |
339 } | |
340 | |
341 mb_action_t *mb_dummy_new(int id, int *logidx, int *logs, mb_word_t *word) { | |
342 mb_dummy_t *dummy; | |
343 | |
344 dummy = (mb_dummy_t *)malloc(sizeof(mb_dummy_t)); | |
345 if(dummy == NULL) | |
346 return NULL; | |
347 | |
348 dummy->id = id; | |
349 dummy->logidx = logidx; | |
350 dummy->logs = logs; | |
351 | |
352 dummy->action.start = mb_dummy_start; | |
353 dummy->action.step = mb_dummy_step; | |
354 dummy->action.stop = mb_dummy_stop; | |
355 dummy->action.free = mb_dummy_free; | |
356 | |
357 mb_word_add_action(word, (mb_action_t *)dummy); | |
358 | |
359 return (mb_action_t *)dummy; | |
360 } | |
361 | |
362 void test_animate_words(void) { | |
363 mb_progm_t *progm; | |
364 mb_word_t *word; | |
365 mb_action_t *acts[4]; | |
366 mb_tman_t *tman; | |
367 mb_timeval_t tv1, tv2, now, tmo_after; | |
368 int logcnt = 0; | |
369 int logs[256]; | |
370 int r; | |
371 | |
372 tman = mb_tman_new(); | |
373 CU_ASSERT(tman != NULL); | |
374 | |
375 progm = mb_progm_new(3, NULL); | |
376 CU_ASSERT(progm != NULL); | |
377 | |
378 MB_TIMEVAL_SET(&tv1, 1, 0); | |
379 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
380 word = mb_progm_next_word(progm, &tv1, &tv2); | |
381 CU_ASSERT(word != NULL); | |
382 acts[0] = mb_dummy_new(0, &logcnt, logs, word); | |
383 CU_ASSERT(acts[0] != NULL); | |
384 | |
385 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 4 / 3); | |
386 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL / 3); | |
387 word = mb_progm_next_word(progm, &tv1, &tv2); | |
388 CU_ASSERT(word != NULL); | |
389 acts[1] = mb_dummy_new(1, &logcnt, logs, word); | |
390 CU_ASSERT(acts[1] != NULL); | |
391 | |
392 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 2); | |
393 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
394 word = mb_progm_next_word(progm, &tv1, &tv2); | |
395 CU_ASSERT(word != NULL); | |
396 acts[2] = mb_dummy_new(2, &logcnt, logs, word); | |
397 CU_ASSERT(acts[2] != NULL); | |
398 | |
399 MB_TIMEVAL_SET(&now, 0, 0); | |
400 mb_progm_start(progm, tman, &now); | |
401 | |
402 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
403 CU_ASSERT(r == 0); | |
404 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 1 && | |
405 MB_TIMEVAL_USEC(&tmo_after) == 0); | |
406 | |
407 /* 1.0s */ | |
408 MB_TIMEVAL_ADD(&now, &tmo_after); | |
409 mb_tman_handle_timeout(tman, &now); | |
410 CU_ASSERT(logcnt == 1); | |
411 | |
412 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
413 CU_ASSERT(r == 0); | |
414 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
415 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
416 | |
417 /* 1.1s */ | |
418 MB_TIMEVAL_ADD(&now, &tmo_after); | |
419 mb_tman_handle_timeout(tman, &now); | |
420 CU_ASSERT(logcnt == 4); | |
421 | |
422 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
423 CU_ASSERT(r == 0); | |
424 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
425 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
426 | |
427 /* 1.2s */ | |
428 MB_TIMEVAL_ADD(&now, &tmo_after); | |
429 mb_tman_handle_timeout(tman, &now); | |
430 CU_ASSERT(logcnt == 6); | |
431 | |
432 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
433 CU_ASSERT(r == 0); | |
434 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
435 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
436 | |
437 /* 1.3s */ | |
438 MB_TIMEVAL_ADD(&now, &tmo_after); | |
439 mb_tman_handle_timeout(tman, &now); | |
440 CU_ASSERT(logcnt == 8); | |
441 | |
442 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
443 CU_ASSERT(r == 0); | |
444 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
445 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
446 | |
447 /* 1.4s */ | |
448 MB_TIMEVAL_ADD(&now, &tmo_after); | |
449 mb_tman_handle_timeout(tman, &now); | |
450 CU_ASSERT(logcnt == 9); | |
451 | |
452 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
453 CU_ASSERT(r == 0); | |
454 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
455 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
456 | |
457 /* 1.5s */ | |
458 MB_TIMEVAL_ADD(&now, &tmo_after); | |
459 mb_tman_handle_timeout(tman, &now); | |
460 CU_ASSERT(logcnt == 10); | |
461 | |
462 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
463 CU_ASSERT(r == -1); | |
464 | |
465 mb_progm_free(progm); | |
466 mb_tman_free(tman); | |
467 } | |
468 | |
469 CU_pSuite get_animate_suite(void) { | |
470 CU_pSuite suite; | |
471 | |
472 suite = CU_add_suite("Suite_animate", NULL, NULL); | |
473 if(suite == NULL) | |
474 return NULL; | |
475 | |
476 CU_ADD_TEST(suite, test_animate_words); | |
477 | |
478 return suite; | |
479 } | |
480 | |
481 #endif /* UNITTEST */ |