annotate src/observer.c @ 126:55f2c6402c81

-
author Thinker K.F. Li <thinker@branda.to>
date Tue, 16 Sep 2008 15:44:01 +0800
parents 1c1f28c124c9
children d2cc7400c971
rev   line source
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include "redraw_man.h"
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "observer.h"
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "tools.h"
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
126
Thinker K.F. Li <thinker@branda.to>
parents: 125
diff changeset
6 #ifndef ASSERT
Thinker K.F. Li <thinker@branda.to>
parents: 125
diff changeset
7 #define ASSERT(x)
Thinker K.F. Li <thinker@branda.to>
parents: 125
diff changeset
8 #endif
Thinker K.F. Li <thinker@branda.to>
parents: 125
diff changeset
9
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 subject_t *subject_new(ob_factory_t *factory, void *obj, int obj_type) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 subject_t *subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 subject = factory->subject_alloc(factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 if(subject == NULL)
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 return NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 subject->obj = obj;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 subject->obj_type = obj_type;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 subject->flags = 0;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 STAILQ_INIT(subject->observers);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 return subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24
125
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
25 /*!
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
26 * \todo Keep ob_factory following subject objects.
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
27 */
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 void subject_free(ob_factory_t *factory, subject_t *subject) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 observer_t *observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
126
Thinker K.F. Li <thinker@branda.to>
parents: 125
diff changeset
31 ASSERT(!(subject->flags & SUBF_FREE));
125
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
32 if(subject->flags & SUBF_BUSY) {
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
33 /* Postpond the request until busy status been stoped.
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
34 * SUBF_BUSY means in subject_notify().
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
35 */
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
36 subject->flags |= SUBF_FREE;
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
37 return;
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
38 }
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
39
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 while((observer = STAILQ_HEAD(subject->observers))) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 STAILQ_REMOVE(subject->observers, observer_t, next, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 factory->observer_free(factory, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 factory->subject_free(factory, subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 void subject_notify(ob_factory_t *factory, subject_t *subject, event_t *evt) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 observer_t *observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50
125
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
51 /*!
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
52 * \note What is happend when the subject is freed by observer?
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
53 * Postponding the request of free until notification
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
54 * been finished. (\ref SUBF_BUSY / \ref SUBF_FREE)
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
55 */
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
56 subject->flags |= SUBF_BUSY;
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
57
77
Thinker K.F. Li <thinker@branda.to>
parents: 74
diff changeset
58 evt->tgt = subject;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 while(subject) {
77
Thinker K.F. Li <thinker@branda.to>
parents: 74
diff changeset
60 evt->cur_tgt = subject->obj;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 for(observer = STAILQ_HEAD(subject->observers);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 observer != NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 observer = STAILQ_NEXT(observer_t, next, observer)) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 observer->hdr(evt, observer->arg);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 if(subject->flags & SUBF_STOP_PROPAGATE)
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 break;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 subject = factory->get_parent_subject(factory, subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 }
125
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
72
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
73 subject->flags &= ~SUBF_BUSY;
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
74 if(subject->flags & SUBF_FREE)
1c1f28c124c9 Postponding free request when a subject is in subject_notify
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
75 subject_free(factory, subject);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 observer_t *subject_add_observer(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 subject_t *subject,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 evt_handler hdr, void *arg) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 observer_t *observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 observer = factory->observer_alloc(factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 if(observer == NULL)
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 return NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 observer->hdr = hdr;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 observer->arg = arg;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 STAILQ_INS_TAIL(subject->observers, observer_t, next, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 return observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 void subject_remove_observer(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 subject_t *subject,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 observer_t *observer) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 STAILQ_REMOVE(subject->observers, observer_t, next, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 factory->observer_free(factory, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 #ifdef UNITTEST
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 #include <CUnit/Basic.h>
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 #include <stdlib.h>
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 static subject_t *test_subject_alloc(ob_factory_t *factory) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 subject_t *subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 subject = (subject_t *)malloc(sizeof(subject_t));
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 return subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 static void test_subject_free(ob_factory_t *factory, subject_t *subject) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 free(subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 static observer_t *test_observer_alloc(ob_factory_t *factory) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 observer_t *observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 observer = (observer_t *)malloc(sizeof(observer_t));
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 return observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 static void test_observer_free(ob_factory_t *factory, observer_t *observer) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 free(observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 static subject_t *test_get_parent_subject(ob_factory_t *factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 subject_t *subject) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 return NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 static ob_factory_t test_factory = {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 test_subject_alloc,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 test_subject_free,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 test_observer_alloc,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 test_observer_free,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 test_get_parent_subject
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 };
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 static void handler(event_t *evt, void *arg) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 int *cnt = (int *)arg;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
144 CU_ASSERT(evt->type == EVT_MOUSE_OUT);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 (*cnt)++;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 void test_observer(void) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 subject_t *subject;
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
150 observer_t *observer[2];
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 event_t evt;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 int cnt = 0;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 subject = subject_new(&test_factory, NULL, 0);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 subject->flags |= SUBF_STOP_PROPAGATE;
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
156 observer[0] = subject_add_observer(&test_factory, subject,
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
157 handler, &cnt);
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
158 observer[1] = subject_add_observer(&test_factory, subject,
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
159 handler, &cnt);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
161 evt.type = EVT_MOUSE_OUT;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 evt.tgt = NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 evt.cur_tgt = NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 subject_notify(&test_factory, subject, &evt);
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
165 CU_ASSERT(cnt == 2);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166
74
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
167 subject_remove_observer(&test_factory, subject, observer[0]);
3e3e074120a7 test case for observer
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
168 subject_remove_observer(&test_factory, subject, observer[1]);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 subject_free(&test_factory, subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 CU_pSuite get_observer_suite(void) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 CU_pSuite suite;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 suite = CU_add_suite("Suite_observer", NULL, NULL);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 CU_ADD_TEST(suite, test_observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 return suite;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 #endif /* UNITTEST */