Mercurial > MadButterfly
annotate src/animate.c @ 117:e4e47d2cdbcd
Tank
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 14 Sep 2008 18:51:16 +0800 |
parents | 1d74eb3861b7 |
children | 257a1d314bcd |
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 | |
106 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { | |
107 mb_progm_t *progm; | |
108 int i; | |
109 | |
110 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + | |
111 (sizeof(mb_word_t) * (max_words - 1))); | |
112 if(progm == NULL) | |
113 return NULL; | |
114 | |
115 progm->rdman = rdman; | |
116 progm->n_words = 0; | |
117 progm->max_words = max_words; | |
118 for(i = 0; i < max_words; i++) | |
119 STAILQ_INIT(progm->words[i].actions); | |
120 return progm; | |
121 } | |
122 | |
123 void mb_progm_free(mb_progm_t *progm) { | |
124 int n_words; | |
125 mb_word_t *word; | |
126 mb_action_t *cur_act; | |
127 int i; | |
128 | |
129 n_words = progm->n_words; | |
130 for(i = 0; i < n_words; i++) { | |
131 word = progm->words + i; | |
132 for(cur_act = STAILQ_HEAD(word->actions); | |
133 cur_act != NULL; | |
134 cur_act = STAILQ_HEAD(word->actions)) { | |
135 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act); | |
136 cur_act->free(cur_act); | |
137 } | |
138 } | |
139 free(progm); | |
140 } | |
141 | |
142 /*! \brief Add a new word into a program. | |
143 * | |
144 * The start time of new word should bigger or equal to last one. | |
145 * The time should be specified in incremental order. | |
146 */ | |
147 mb_word_t *mb_progm_next_word(mb_progm_t *progm, | |
148 const mb_timeval_t *start, | |
149 const mb_timeval_t *playing) { | |
150 mb_word_t *word; | |
151 if(progm->n_words >= progm->max_words) | |
152 return NULL; | |
153 if(progm->n_words && | |
154 MB_TIMEVAL_LATER(&progm->words[progm->n_words - 1].start_time, start)) | |
155 return NULL; | |
156 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
|
157 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
|
158 MB_TIMEVAL_CP(&word->playing_time, playing); |
41 | 159 return word; |
160 } | |
161 | |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
111
diff
changeset
|
162 void mb_word_add_action(mb_word_t *word, mb_action_t *act) { |
41 | 163 STAILQ_INS_TAIL(word->actions, mb_action_t, next, act); |
164 } | |
165 | |
166 static void mb_word_start(mb_word_t *word, const mb_timeval_t *tmo, | |
167 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 168 mb_action_t *act; |
169 | |
170 for(act = STAILQ_HEAD(word->actions); | |
171 act != NULL; | |
172 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
173 act->start(act, tmo, &word->playing_time, rdman); | |
174 } | |
41 | 175 } |
176 | |
177 static void mb_word_step(mb_word_t *word, const mb_timeval_t *tmo, | |
178 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 179 mb_action_t *act; |
180 | |
181 for(act = STAILQ_HEAD(word->actions); | |
182 act != NULL; | |
183 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
184 act->step(act, tmo, rdman); | |
185 } | |
41 | 186 } |
187 | |
188 static void mb_word_stop(mb_word_t *word, const mb_timeval_t *tmo, | |
189 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 190 mb_action_t *act; |
191 | |
192 for(act = STAILQ_HEAD(word->actions); | |
193 act != NULL; | |
194 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
195 act->stop(act, tmo, rdman); | |
196 } | |
41 | 197 } |
198 | |
46 | 199 /* |
200 * Any two actions in concurrent words never change the same attribute. | |
201 * Start time of words in a program are specified in incremental order. | |
202 */ | |
41 | 203 static void mb_progm_step(const mb_timeval_t *tmo, |
46 | 204 const mb_timeval_t *now, |
205 void *arg) { | |
41 | 206 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
|
207 mb_timeval_t next_tmo; |
41 | 208 mb_word_t *word; |
209 mb_timer_t *timer; | |
210 int i; | |
211 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
212 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
|
213 MB_TIMEVAL_ADD(&next_tmo, tmo); |
41 | 214 |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
215 /* _step() or _stop() words that in playing. */ |
41 | 216 i = progm->first_playing; |
217 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
|
218 i < progm->n_words && MB_TIMEVAL_LATER(tmo, &word->abs_start); |
41 | 219 word = progm->words + ++i) { |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
220 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
|
221 continue; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
222 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 223 mb_word_stop(word, tmo, now, progm->rdman); |
224 else | |
41 | 225 mb_word_step(word, tmo, now, progm->rdman); |
226 } | |
227 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
228 /* 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
|
229 * 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
|
230 */ |
41 | 231 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
|
232 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_start); |
41 | 233 word = progm->words + ++i) { |
234 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
|
235 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 236 mb_word_stop(word, tmo, now, progm->rdman); |
41 | 237 } |
238 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
239 /* 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
|
240 * first_playing word, are stoped. |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
241 */ |
46 | 242 i = progm->first_playing; |
243 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
|
244 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop); |
46 | 245 word = progm->words + ++i) { |
246 progm->first_playing++; | |
247 } | |
248 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
249 /* Setup timeout for next update. */ |
41 | 250 if(progm->first_playing < progm->n_words) { |
42 | 251 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
|
252 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
|
253 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); |
46 | 254 timer = mb_tman_timeout(progm->tman, &next_tmo, |
255 mb_progm_step, progm); | |
41 | 256 } |
257 } | |
258 | |
259 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, | |
260 mb_timeval_t *now) { | |
261 mb_timer_t *timer; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
262 mb_word_t *word; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
263 int i; |
41 | 264 |
265 if(progm->n_words == 0) | |
266 return; | |
267 | |
268 progm->tman = tman; | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
269 MB_TIMEVAL_CP(&progm->start_time, now); |
41 | 270 progm->first_playing = 0; |
271 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
272 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
|
273 word = progm->words + i; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 } |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
279 |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
280 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
|
281 mb_progm_step(now, now, progm); |
41 | 282 return; |
283 } | |
284 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
285 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
|
286 mb_progm_step, progm); |
41 | 287 ASSERT(timer != NULL); |
288 } | |
289 | |
42 | 290 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { |
291 } | |
292 | |
50 | 293 #ifdef UNITTEST |
294 | |
295 #include <CUnit/Basic.h> | |
296 | |
297 typedef struct _mb_dummy mb_dummy_t; | |
298 | |
299 struct _mb_dummy { | |
300 mb_action_t action; | |
301 int id; | |
302 int *logidx; | |
303 int *logs; | |
304 }; | |
305 | |
306 | |
307 static void mb_dummy_start(mb_action_t *act, | |
308 const mb_timeval_t *now, | |
309 const mb_timeval_t *playing_time, | |
310 redraw_man_t *rdman) { | |
311 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
312 | |
313 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
314 } | |
315 | |
316 static void mb_dummy_step(mb_action_t *act, | |
317 const mb_timeval_t *now, | |
318 redraw_man_t *rdman) { | |
319 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
320 | |
321 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
322 } | |
323 | |
324 static void mb_dummy_stop(mb_action_t *act, | |
325 const mb_timeval_t *now, | |
326 redraw_man_t *rdman) { | |
327 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
328 | |
329 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
330 } | |
331 | |
332 static void mb_dummy_free(mb_action_t *act) { | |
333 free(act); | |
334 } | |
335 | |
336 mb_action_t *mb_dummy_new(int id, int *logidx, int *logs, mb_word_t *word) { | |
337 mb_dummy_t *dummy; | |
338 | |
339 dummy = (mb_dummy_t *)malloc(sizeof(mb_dummy_t)); | |
340 if(dummy == NULL) | |
341 return NULL; | |
342 | |
343 dummy->id = id; | |
344 dummy->logidx = logidx; | |
345 dummy->logs = logs; | |
346 | |
347 dummy->action.start = mb_dummy_start; | |
348 dummy->action.step = mb_dummy_step; | |
349 dummy->action.stop = mb_dummy_stop; | |
350 dummy->action.free = mb_dummy_free; | |
351 | |
352 mb_word_add_action(word, (mb_action_t *)dummy); | |
353 | |
354 return (mb_action_t *)dummy; | |
355 } | |
356 | |
357 void test_animate_words(void) { | |
358 mb_progm_t *progm; | |
359 mb_word_t *word; | |
360 mb_action_t *acts[4]; | |
361 mb_tman_t *tman; | |
362 mb_timeval_t tv1, tv2, now, tmo_after; | |
363 int logcnt = 0; | |
364 int logs[256]; | |
365 int r; | |
366 | |
367 tman = mb_tman_new(); | |
368 CU_ASSERT(tman != NULL); | |
369 | |
370 progm = mb_progm_new(3, NULL); | |
371 CU_ASSERT(progm != NULL); | |
372 | |
373 MB_TIMEVAL_SET(&tv1, 1, 0); | |
374 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
375 word = mb_progm_next_word(progm, &tv1, &tv2); | |
376 CU_ASSERT(word != NULL); | |
377 acts[0] = mb_dummy_new(0, &logcnt, logs, word); | |
378 CU_ASSERT(acts[0] != NULL); | |
379 | |
380 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 4 / 3); | |
381 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL / 3); | |
382 word = mb_progm_next_word(progm, &tv1, &tv2); | |
383 CU_ASSERT(word != NULL); | |
384 acts[1] = mb_dummy_new(1, &logcnt, logs, word); | |
385 CU_ASSERT(acts[1] != NULL); | |
386 | |
387 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 2); | |
388 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
389 word = mb_progm_next_word(progm, &tv1, &tv2); | |
390 CU_ASSERT(word != NULL); | |
391 acts[2] = mb_dummy_new(2, &logcnt, logs, word); | |
392 CU_ASSERT(acts[2] != NULL); | |
393 | |
394 MB_TIMEVAL_SET(&now, 0, 0); | |
395 mb_progm_start(progm, tman, &now); | |
396 | |
397 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
398 CU_ASSERT(r == 0); | |
399 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 1 && | |
400 MB_TIMEVAL_USEC(&tmo_after) == 0); | |
401 | |
402 /* 1.0s */ | |
403 MB_TIMEVAL_ADD(&now, &tmo_after); | |
404 mb_tman_handle_timeout(tman, &now); | |
405 CU_ASSERT(logcnt == 1); | |
406 | |
407 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
408 CU_ASSERT(r == 0); | |
409 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
410 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
411 | |
412 /* 1.1s */ | |
413 MB_TIMEVAL_ADD(&now, &tmo_after); | |
414 mb_tman_handle_timeout(tman, &now); | |
415 CU_ASSERT(logcnt == 4); | |
416 | |
417 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
418 CU_ASSERT(r == 0); | |
419 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
420 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
421 | |
422 /* 1.2s */ | |
423 MB_TIMEVAL_ADD(&now, &tmo_after); | |
424 mb_tman_handle_timeout(tman, &now); | |
425 CU_ASSERT(logcnt == 6); | |
426 | |
427 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
428 CU_ASSERT(r == 0); | |
429 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
430 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
431 | |
432 /* 1.3s */ | |
433 MB_TIMEVAL_ADD(&now, &tmo_after); | |
434 mb_tman_handle_timeout(tman, &now); | |
435 CU_ASSERT(logcnt == 8); | |
436 | |
437 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
438 CU_ASSERT(r == 0); | |
439 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
440 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
441 | |
442 /* 1.4s */ | |
443 MB_TIMEVAL_ADD(&now, &tmo_after); | |
444 mb_tman_handle_timeout(tman, &now); | |
445 CU_ASSERT(logcnt == 9); | |
446 | |
447 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
448 CU_ASSERT(r == 0); | |
449 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
450 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
451 | |
452 /* 1.5s */ | |
453 MB_TIMEVAL_ADD(&now, &tmo_after); | |
454 mb_tman_handle_timeout(tman, &now); | |
455 CU_ASSERT(logcnt == 10); | |
456 | |
457 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
458 CU_ASSERT(r == -1); | |
459 | |
460 mb_progm_free(progm); | |
461 mb_tman_free(tman); | |
462 } | |
463 | |
464 CU_pSuite get_animate_suite(void) { | |
465 CU_pSuite suite; | |
466 | |
467 suite = CU_add_suite("Suite_animate", NULL, NULL); | |
468 if(suite == NULL) | |
469 return NULL; | |
470 | |
471 CU_ADD_TEST(suite, test_animate_words); | |
472 | |
473 return suite; | |
474 } | |
475 | |
476 #endif /* UNITTEST */ |