Mercurial > MadButterfly
comparison src/observer.c @ 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 | a6763f080da5 |
comparison
equal
deleted
inserted
replaced
73:9ab15ebc9061 | 74:3e3e074120a7 |
---|---|
110 }; | 110 }; |
111 | 111 |
112 static void handler(event_t *evt, void *arg) { | 112 static void handler(event_t *evt, void *arg) { |
113 int *cnt = (int *)arg; | 113 int *cnt = (int *)arg; |
114 | 114 |
115 CU_ASSERT(evt->type == EVT_MOUSE_OVER); | 115 CU_ASSERT(evt->type == EVT_MOUSE_OUT); |
116 (*cnt)++; | 116 (*cnt)++; |
117 } | 117 } |
118 | 118 |
119 void test_observer(void) { | 119 void test_observer(void) { |
120 subject_t *subject; | 120 subject_t *subject; |
121 observer_t *observer; | 121 observer_t *observer[2]; |
122 event_t evt; | 122 event_t evt; |
123 int cnt = 0; | 123 int cnt = 0; |
124 | 124 |
125 subject = subject_new(&test_factory, NULL, 0); | 125 subject = subject_new(&test_factory, NULL, 0); |
126 subject->flags |= SUBF_STOP_PROPAGATE; | 126 subject->flags |= SUBF_STOP_PROPAGATE; |
127 observer = subject_add_observer(&test_factory, subject, | 127 observer[0] = subject_add_observer(&test_factory, subject, |
128 handler, &cnt); | 128 handler, &cnt); |
129 observer[1] = subject_add_observer(&test_factory, subject, | |
130 handler, &cnt); | |
129 | 131 |
130 evt.type = EVT_MOUSE_OVER; | 132 evt.type = EVT_MOUSE_OUT; |
131 evt.tgt = NULL; | 133 evt.tgt = NULL; |
132 evt.cur_tgt = NULL; | 134 evt.cur_tgt = NULL; |
133 subject_notify(&test_factory, subject, &evt); | 135 subject_notify(&test_factory, subject, &evt); |
134 CU_ASSERT(cnt == 1); | 136 CU_ASSERT(cnt == 2); |
135 | 137 |
136 subject_remove_observer(&test_factory, subject, observer); | 138 subject_remove_observer(&test_factory, subject, observer[0]); |
139 subject_remove_observer(&test_factory, subject, observer[1]); | |
137 subject_free(&test_factory, subject); | 140 subject_free(&test_factory, subject); |
138 } | 141 } |
139 | 142 |
140 CU_pSuite get_observer_suite(void) { | 143 CU_pSuite get_observer_suite(void) { |
141 CU_pSuite suite; | 144 CU_pSuite suite; |