summaryrefslogtreecommitdiff
path: root/src/tests/evas/evas_test_callbacks.c
blob: 164851e94ad82fd31013a0361b25bb897694c215 (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

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>

#include "evas_suite.h"
#include "Evas.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); \
   evas_shutdown(); \
} \
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++;
}

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 */
   fail_if(counter != 4);

   END_CALLBACK_TEST();
}
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++;
}

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();
}
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);
}