aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/eo/signals/signals_main.c
blob: 84de4647429762cd190e8530fa8af652fc0f61b3 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#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 void
_null_cb(void *data EINA_UNUSED, const Eo_Event *event EINA_UNUSED)
{
}

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

   cb_count++;

   efl_event_callback_priority_add(event->object, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _null_cb, (void *) 23423);
   efl_event_callback_del(event->object, EV_A_CHANGED, _null_cb, (void *) 23423);

   /* Stop as we reached the 3rd one. */
   if (cb_count == 3)
      efl_event_callback_stop(event->object);
}

static Eina_Bool inside = EINA_FALSE;
static int called = 0;

static void
_restart_1_cb(void *data EINA_UNUSED, const Eo_Event *event EINA_UNUSED)
{
   fprintf(stderr, "restart 1 inside: %i\n", inside);
   fail_if(!inside);
   called++;
   efl_event_callback_stop(event->object);
}

static void
_restart_2_cb(void *data, const Eo_Event *event)
{
   fprintf(stderr, "restart 2 inside: %i\n", inside);
   fail_if(inside);

   inside = EINA_TRUE;
   efl_event_callback_call(event->object, event->desc, data);
   inside = EINA_FALSE;

   called++;

   fprintf(stderr, "restart 2 exit inside: %i (%i)\n", inside, called);
   efl_event_callback_stop(event->object);
}

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

   Eo *obj = efl_add(SIMPLE_CLASS, NULL);
   Simple_Public_Data *pd = efl_data_scope_get(obj, SIMPLE_CLASS);

   /* The order of these two is undetermined. */
   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2);
   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1);
   /* This will be called afterwards. */
   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_DEFAULT, _a_changed_cb, (void *) 3);
   /* This will never be called because the previous callback returns NULL. */
   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_AFTER, _a_changed_cb, (void *) 4);

   simple_a_set(obj, 1);

   fail_if(cb_count != 3);

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

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

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

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

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

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

   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 0);

   efl_event_freeze(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 1);

   efl_event_freeze(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 2);

   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2);
   fail_if(pd->cb_count != 2);

   simple_a_set(obj, 2);
   fail_if(cb_count != 0);
   efl_event_thaw(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 1);

   efl_event_thaw(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 0);

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

   cb_count = 0;
   efl_event_thaw(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 0);

   efl_event_freeze(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 1);

   simple_a_set(obj, 2);
   fail_if(cb_count != 0);
   efl_event_thaw(obj);
   fcount = efl_event_freeze_count_get(obj);
   fail_if(fcount != 0);

   efl_event_callback_del(obj, EV_A_CHANGED, _a_changed_cb, (void *) 1);
   fail_if(pd->cb_count != 1);
   efl_event_callback_del(obj, 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;
   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 1);
   fail_if(pd->cb_count != 1);

   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 0);

   efl_event_global_freeze(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 1);

   efl_event_global_freeze(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 2);

   efl_event_callback_priority_add(obj, EV_A_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, _a_changed_cb, (void *) 2);
   fail_if(pd->cb_count != 2);

   simple_a_set(obj, 2);
   fail_if(cb_count != 0);
   efl_event_global_thaw(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 1);

   efl_event_global_thaw(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 0);

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

   cb_count = 0;
   efl_event_global_thaw(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 0);

   efl_event_global_freeze(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 1);

   simple_a_set(obj, 2);
   fail_if(cb_count != 0);
   efl_event_global_thaw(EO_CLASS);
   fcount = efl_event_global_freeze_count_get(EO_CLASS);
   fail_if(fcount != 0);

   efl_event_callback_priority_add(obj, EV_RESTART, EFL_CALLBACK_PRIORITY_DEFAULT, _restart_1_cb, NULL);
   efl_event_callback_priority_add(obj, EV_RESTART, EFL_CALLBACK_PRIORITY_BEFORE, _restart_2_cb, NULL);
   efl_event_callback_call(obj, EV_RESTART, NULL);
   fail_if(inside);
   fail_if(called != 2);

   efl_unref(obj);
   efl_object_shutdown();
   return 0;
}