changeset 1019:1a3cc22ee1bd refine_backend_if

Fix testcase of animate.c for mb_timer_man_t
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 13:52:59 +0800
parents 7ccc094bdbe5
children f25b8ad338b4
files include/mb_backend.h include/mb_backend_utils.h src/animate.c
diffstat 3 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_backend.h	Mon Nov 22 13:15:33 2010 +0800
+++ b/include/mb_backend.h	Mon Nov 22 13:52:59 2010 +0800
@@ -140,5 +140,7 @@
     (tm_man)->timeout((tm_man), (tmout), (cb), (data))
 #define mb_timer_man_remove(tm_man, tm_hdl)	\
     (tm_man)->remove((tm_man), (tm_hdl))
+#define mb_timer_man_new(tm_fact) (tm_fact)->new()
+#define mb_timer_man_free(tm_fact, tm_man) (tm_fact)->free(tm_man)
 
 #endif /* __MB_BACKEND_H_ */
--- a/include/mb_backend_utils.h	Mon Nov 22 13:15:33 2010 +0800
+++ b/include/mb_backend_utils.h	Mon Nov 22 13:52:59 2010 +0800
@@ -7,6 +7,6 @@
 /*! \brief A facotry of timer manager implemented with mb_tman_t.
  */
 extern mb_timer_factory_t tman_timer_factory;
-extern mb_tman_t * tman_timer_man_get_tman(mb_timer_man_t *tm_man);
+extern mb_tman_t *tman_timer_man_get_tman(mb_timer_man_t *tm_man);
 
 #endif /* __MB_BACKEND_UTILS_H_ */
--- a/src/animate.c	Mon Nov 22 13:15:33 2010 +0800
+++ b/src/animate.c	Mon Nov 22 13:52:59 2010 +0800
@@ -377,6 +377,7 @@
 
 #ifdef UNITTEST
 
+#include "mb_backend_utils.h"
 #include <CUnit/Basic.h>
 
 typedef struct _mb_dummy mb_dummy_t;
@@ -444,13 +445,16 @@
     mb_word_t *word;
     mb_action_t *acts[4];
     mb_timer_man_t *timer_man;
+    mb_tman_t *tman;
     mb_timeval_t tv1, tv2, now, tmo_after;
     int logcnt = 0;
     int logs[256];
     int r;
 
-    timer_man = mb_tman_new();
-    CU_ASSERT(tman != NULL);
+    timer_man = mb_timer_man_new(&tman_timer_factory);
+    CU_ASSERT(timer_man != NULL);
+
+    tman = tman_timer_man_get_tman(timer_man);
 
     progm = mb_progm_new(3, NULL);
     CU_ASSERT(progm != NULL);
@@ -477,7 +481,7 @@
     CU_ASSERT(acts[2] != NULL);
 
     MB_TIMEVAL_SET(&now, 0, 0);
-    mb_progm_start(progm, tman, &now);
+    mb_progm_start(progm, timer_man, &now);
 
     r = mb_tman_next_timeout(tman, &now, &tmo_after);
     CU_ASSERT(r == 0);
@@ -543,7 +547,7 @@
     CU_ASSERT(r == -1);
 
     mb_progm_free(progm);
-    mb_tman_free(tman);
+    mb_timer_man_free(&tman_timer_factory, timer_man);
 }
 
 CU_pSuite get_animate_suite(void) {