summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_callbacks.c
blob: 58da30565740544f045510752d4b97af9a37fd8e (plain)
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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>

#include <Evas.h>
#include <Ecore_Evas.h>

#include "evas_suite.h"
#include "evas_tests_helpers.h"

#define START_CALLBACK_TEST() \
   Evas *evas; \
   Evas_Object *rect; \
   evas = EVAS_TEST_INIT_EVAS(); \
   rect = evas_object_rectangle_add(evas); \
do \
{ \
} \
while (0)

#define END_CALLBACK_TEST() \
do \
{ \
   evas_object_del(rect); \
   evas_free(evas); \
} \
while (0)

static uintptr_t counter = 1;

static void
_obj_event_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   (void) e;
   (void) obj;
   (void) event_info;

   fail_if(((uintptr_t) data) != counter);

   counter++;
}

EFL_START_TEST(evas_object_event_callbacks_priority)
{
   START_CALLBACK_TEST();
   counter = 1;
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, -10,
         _obj_event_cb, (void *) 1);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 0,
         _obj_event_cb, (void *) 2);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 10,
         _obj_event_cb, (void *) 3);
   evas_object_move(rect, 2, 2);

   /* Make sure we got through all the callbacks */
   fail_if(counter != 4);

   /* Delete _obj_event_cb 3 times */
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   counter = 1;
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 0,
         _obj_event_cb, (void *) 2);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, -10,
         _obj_event_cb, (void *) 1);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 10,
         _obj_event_cb, (void *) 3);
   evas_object_move(rect, 3, 3);

   /* Make sure we got through all the callbacks in priority order */
   fail_if(counter != 4);

   /* Verify order of dels (must be reverse order of adds) */
   counter = 1;
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 10,
         _obj_event_cb, (void *) 2);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, 0,
         _obj_event_cb, (void *) 1);
   evas_object_event_callback_priority_add(rect, EVAS_CALLBACK_MOVE, -10,
         _obj_event_cb, (void *) 3);
   evas_object_event_callback_del(rect, EVAS_CALLBACK_MOVE, _obj_event_cb);
   evas_object_move(rect, 2, 2);

   /* Make sure we got through only the 2 first callbacks (in priority order) */
   fail_if(counter != 3);

   END_CALLBACK_TEST();
}
EFL_END_TEST

static void
_event_cb(void *data, Evas *e, void *event_info)
{
   (void) e;
   (void) event_info;

   fail_if(((uintptr_t) data) != counter);

   counter++;
}

EFL_START_TEST(evas_event_callbacks_priority)
{
   START_CALLBACK_TEST();
   evas_object_focus_set(rect, EINA_FALSE);
   counter = 1;
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         -10, _event_cb, (void *) 1);
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         0, _event_cb, (void *) 2);
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         10, _event_cb, (void *) 3);
   evas_object_focus_set(rect, EINA_TRUE);

   /* Make sure we got through all the callbacks */
   fail_if(counter != 4);

   /* Delete _event_cb 3 times */
   evas_event_callback_del(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         _event_cb);
   evas_event_callback_del(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         _event_cb);
   evas_event_callback_del(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         _event_cb);
   evas_object_focus_set(rect, EINA_FALSE);
   counter = 1;
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         0, _event_cb, (void *) 2);
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         -10, _event_cb, (void *) 1);
   evas_event_callback_priority_add(evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
         10, _event_cb, (void *) 3);
   evas_object_focus_set(rect, EINA_TRUE);

   /* Make sure we got through all the callbacks */
   fail_if(counter != 4);

   END_CALLBACK_TEST();
}
EFL_END_TEST

static void
_smart_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   int *called = data;

   (*called)++;
}

EFL_START_TEST(evas_event_callbacks_smart)
{
   int called = 0;
   Eo *box;
   START_CALLBACK_TEST();
   box = evas_object_box_add(evas);
   evas_object_smart_callback_add(box, "move", _smart_cb, &called);
   evas_object_smart_callback_add(box, "resize", _smart_cb, &called);
   evas_object_smart_callback_add(box, "restack", _smart_cb, &called);
   evas_object_geometry_set(box, 1, 1, 10, 10);
   evas_object_layer_set(box, 10);
   ck_assert_int_eq(called, 3);
   END_CALLBACK_TEST();
}
EFL_END_TEST

void evas_test_callbacks(TCase *tc)
{
   tcase_add_test(tc, evas_object_event_callbacks_priority);
   tcase_add_test(tc, evas_event_callbacks_priority);
   tcase_add_test(tc, evas_event_callbacks_smart);
}