changeset 74:3e3e074120a7

test case for observer
author Thinker K.F. Li <thinker@branda.to>
date Mon, 18 Aug 2008 10:46:03 +0800
parents 9ab15ebc9061
children 23bc382d9683
files src/observer.c
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/observer.c	Mon Aug 18 01:59:26 2008 +0800
+++ b/src/observer.c	Mon Aug 18 10:46:03 2008 +0800
@@ -112,28 +112,31 @@
 static void handler(event_t *evt, void *arg) {
     int *cnt = (int *)arg;
 
-    CU_ASSERT(evt->type == EVT_MOUSE_OVER);
+    CU_ASSERT(evt->type == EVT_MOUSE_OUT);
     (*cnt)++;
 }
 
 void test_observer(void) {
     subject_t *subject;
-    observer_t *observer;
+    observer_t *observer[2];
     event_t evt;
     int cnt = 0;
 
     subject = subject_new(&test_factory, NULL, 0);
     subject->flags |= SUBF_STOP_PROPAGATE;
-    observer = subject_add_observer(&test_factory, subject,
-				    handler, &cnt);
+    observer[0] = subject_add_observer(&test_factory, subject,
+				       handler, &cnt);
+    observer[1] = subject_add_observer(&test_factory, subject,
+				       handler, &cnt);
 
-    evt.type = EVT_MOUSE_OVER;
+    evt.type = EVT_MOUSE_OUT;
     evt.tgt = NULL;
     evt.cur_tgt = NULL;
     subject_notify(&test_factory, subject, &evt);
-    CU_ASSERT(cnt == 1);
+    CU_ASSERT(cnt == 2);
 
-    subject_remove_observer(&test_factory, subject, observer);
+    subject_remove_observer(&test_factory, subject, observer[0]);
+    subject_remove_observer(&test_factory, subject, observer[1]);
     subject_free(&test_factory, subject);
 }