summaryrefslogtreecommitdiff
path: root/src/tests/eo/signals/signals_main.c
blob: 4fcfaef2fe4ab96df906747b069da31c2ad9c5e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Eo.h"
#include "signals_simple.h"

#include "../eunit_tests.h"

static int cb_count = 0;

static Eina_Bool
_null_cb(void *data EINA_UNUSED, const Eo_Event *event EINA_UNUSED)
{
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_a_changed_cb(void *data, const Eo_Event *event)
{
   int new_a = *((int *) event->event_info);
   printf("%s event_info:'%d' data:'%d'\n", __func__, new_a, (int) (intptr_t) data);

   cb_count++;

   eo_do(event->obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _null_cb, (void *) 23423));
   eo_do(event->obj, eo_event_callback_del(EV_A_CHANGED, _null_cb, (void *) 23423));

   /* Stop as we reached the 3rd one. */
   return (cb_count != 3);
}

int
main(int argc, char *argv[])
{
   (void) argc;
   (void) argv;
   eo_init();

   Eo *obj = eo_add(SIMPLE_CLASS, NULL);
   Simple_Public_Data *pd = eo_data_scope_get(obj, SIMPLE_CLASS);

   /* The order of these two is undetermined. */
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
   /* This will be called afterwards. */
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_DEFAULT, _a_changed_cb, (void *) 3));
   /* This will never be called because the previous callback returns NULL. */
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_AFTER, _a_changed_cb, (void *) 4));

   eo_do(obj, simple_a_set(1));

   fail_if(cb_count != 3);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 3));
   fail_if(pd->cb_count != 3);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 12));
   fail_if(pd->cb_count != 3);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 4));
   fail_if(pd->cb_count != 2);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 2));
   fail_if(pd->cb_count != 1);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 1));
   fail_if(pd->cb_count != 0);

   /* Freeze/thaw. */
   int fcount = 0;
   cb_count = 0;
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
   fail_if(pd->cb_count != 1);

   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(obj, eo_event_freeze());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(obj, eo_event_freeze());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 2);

   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
   fail_if(pd->cb_count != 2);

   eo_do(obj, simple_a_set(2));
   fail_if(cb_count != 0);
   eo_do(obj, eo_event_thaw());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(obj, eo_event_thaw());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(obj, simple_a_set(3));
   fail_if(cb_count != 2);

   cb_count = 0;
   eo_do(obj, eo_event_thaw());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(obj, eo_event_freeze());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(obj, simple_a_set(2));
   fail_if(cb_count != 0);
   eo_do(obj, eo_event_thaw());
   eo_do(obj, fcount = eo_event_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 1));
   fail_if(pd->cb_count != 1);
   eo_do(obj, eo_event_callback_del(EV_A_CHANGED, _a_changed_cb, (void *) 2));
   fail_if(pd->cb_count != 0);

   /* Global Freeze/thaw. */
   fcount = 0;
   cb_count = 0;
   pd->cb_count = 0;
   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1));
   fail_if(pd->cb_count != 1);

   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(EO_CLASS, eo_event_global_freeze());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(EO_CLASS, eo_event_global_freeze());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 2);

   eo_do(obj, eo_event_callback_priority_add(EV_A_CHANGED, EO_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2));
   fail_if(pd->cb_count != 2);

   eo_do(obj, simple_a_set(2));
   fail_if(cb_count != 0);
   eo_do(EO_CLASS, eo_event_global_thaw());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(EO_CLASS, eo_event_global_thaw());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(obj, simple_a_set(3));
   fail_if(cb_count != 2);

   cb_count = 0;
   eo_do(EO_CLASS, eo_event_global_thaw());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 0);

   eo_do(EO_CLASS, eo_event_global_freeze());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 1);

   eo_do(obj, simple_a_set(2));
   fail_if(cb_count != 0);
   eo_do(EO_CLASS, eo_event_global_thaw());
   eo_do(EO_CLASS, fcount = eo_event_global_freeze_count_get());
   fail_if(fcount != 0);


   eo_unref(obj);
   eo_shutdown();
   return 0;
}