summaryrefslogtreecommitdiff
path: root/src/tests/edje/edje_test_signal.c
blob: 553be69abecd1c6ba92ed9aaaf8eac0e4c6bfabd (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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <unistd.h>
#include <stdio.h>

#define EFL_GFX_FILTER_BETA
#define EFL_CANVAS_LAYOUT_BETA

#include "edje_suite.h"

#define EVAS_DATA_DIR TESTS_SRC_DIR "/../../lib/evas"

static void
_message_signal_reply_cb(void *data, Evas_Object *obj EINA_UNUSED,
                         const char *emission, const char *source)
{
   int *id = data;

   fprintf(stderr, "source %s emit %s id %d\n", source, emission, *id);
   fflush(stderr);
   ck_assert_str_eq(source, "edc");
   ck_assert_ptr_ne(emission, NULL);

   if (!strncmp(emission, "int set", 7))
     ck_assert_str_eq(emission, "int set 7 12 42 255");
   else if (!strncmp(emission, "int", 3))
     ck_assert_str_eq(emission, "int 42");
   else if (!strncmp(emission, "float", 5))
     {
        char buf[64];
        sprintf(buf, "float %f", 0.12);
        ck_assert_str_eq(emission, buf);
     }
   else if (!strncmp(emission, "str", 3))
     ck_assert_str_eq(emission, "str hello world");
   else ck_abort_msg("Invalid emission!");

   (*id)++;
}

EFL_START_TEST(edje_test_message_send_legacy)
{
   Evas *evas;
   Evas_Object *obj;
   Edje_Message_Int msgi;
   Edje_Message_Float msgf;
   Edje_Message_String msgs;
   Edje_Message_Int_Set *msgis;
   int id = 0;

   /* Ugly calls to process:
    *
    * 1. Send edje message (async)
    * 2. Process edje message (sync)
    * 3. EDC program emits edje signal (async)
    * 4. Process edje signal (sync)
    * 5. Finally reached signal cb
    */

   evas = _setup_evas();

   obj = edje_object_add(evas);
   fail_unless(edje_object_file_set(obj, test_layout_get("test_messages.edj"), "test_group"));
   edje_object_signal_callback_add(obj, "*", "edc", _message_signal_reply_cb, &id);

   msgs.str = "hello world";
   edje_object_message_send(obj, EDJE_MESSAGE_STRING, 0, &msgs);
   edje_message_signal_process();
   ck_assert_int_eq(id, 1);

   msgi.val = 42;
   edje_object_message_send(obj, EDJE_MESSAGE_INT, 1, &msgi);
   edje_message_signal_process();
   ck_assert_int_eq(id, 2);

   msgf.val = 0.12;
   edje_object_message_send(obj, EDJE_MESSAGE_FLOAT, 2, &msgf);
   edje_message_signal_process();
   ck_assert_int_eq(id, 3);

   msgis = alloca(sizeof(*msgis) + 4 * sizeof(msgis->val));
   msgis->count = 4;
   msgis->val[0] = 7;
   msgis->val[1] = 12;
   msgis->val[2] = 42;
   msgis->val[3] = 255;
   edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 3, msgis);
   edje_message_signal_process();
   ck_assert_int_eq(id, 4);

   evas_object_del(obj);

}
EFL_END_TEST

EFL_START_TEST(edje_test_message_send_eo)
{
   Evas *evas;
   Evas_Object *obj;
   Eina_Value v, *va;
   int id = 0;

   evas = _setup_evas();

   obj = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
                 efl_file_set(efl_added, test_layout_get("test_messages.edj")),
                 efl_file_key_set(efl_added, "test_group"));

   // FIXME: EO API HERE
   edje_object_signal_callback_add(obj, "*", "edc", _message_signal_reply_cb, &id);

   // NOTE: edje_object_message_signal_process may or may not be in EO (TBD)

   eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
   eina_value_set(&v, "hello world");
   efl_layout_signal_message_send(obj, 0, v);
   eina_value_flush(&v);
   edje_message_signal_process();
   edje_object_calc_force(obj);
   ck_assert_int_eq(id, 1);

   eina_value_setup(&v, EINA_VALUE_TYPE_INT);
   eina_value_set(&v, 42);
   efl_layout_signal_message_send(obj, 1, v);
   eina_value_flush(&v);
   edje_message_signal_process();
   edje_object_calc_force(obj);
   ck_assert_int_eq(id, 2);

   eina_value_setup(&v, EINA_VALUE_TYPE_FLOAT);
   eina_value_set(&v, 0.12);
   efl_layout_signal_message_send(obj, 2, v);
   eina_value_flush(&v);
   edje_message_signal_process();
   edje_object_calc_force(obj);
   ck_assert_int_eq(id, 3);

   va = eina_value_array_new(EINA_VALUE_TYPE_INT, 4);
   eina_value_array_append(va, 7);
   eina_value_array_append(va, 12);
   eina_value_array_append(va, 42);
   eina_value_array_append(va, 255);
   efl_layout_signal_message_send(obj, 3, *va);
   eina_value_free(va);
   edje_message_signal_process();
   edje_object_calc_force(obj);
   ck_assert_int_eq(id, 4);

   efl_del(obj);

}
EFL_END_TEST

EFL_START_TEST(edje_test_signals)
{
   Evas *evas;
   Evas_Object *obj;
   const char *state;

   evas = _setup_evas();

   obj = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
                 efl_file_set(efl_added, test_layout_get("test_signals.edj")),
                 efl_file_key_set(efl_added, "level1"),
                 efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(320, 240)),
                 efl_gfx_entity_visible_set(efl_added, 1));

   edje_object_signal_emit(obj, "mouse,in", "text");

   edje_object_message_signal_process(obj);
   state = edje_object_part_state_get(obj, "group:group:text", NULL);
   ck_assert_str_eq(state, "default");

   edje_object_message_signal_process(obj);
   state = edje_object_part_state_get(obj, "group:group:text", NULL);
   ck_assert_str_eq(state, "default");

   edje_object_message_signal_recursive_process(obj);
   state = edje_object_part_state_get(obj, "group:group:text", NULL);
   ck_assert_str_eq(state, "over");

   efl_del(obj);

}
EFL_END_TEST

static int _signal_count;

static void
_signal_callback_count_cb(void *data, Evas_Object *obj EINA_UNUSED,
                         const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
{
   int *_data = data;
   _signal_count += *_data;
}

EFL_START_TEST(edje_test_signal_callback_del_full)
{
   Evas *evas;
   Evas_Object *obj;
   int data[4] = { 1, 2, 4, 8 };

   evas = _setup_evas();

   obj = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas,
                 efl_file_set(efl_added,
                 test_layout_get("test_signal_callback_del_full.edj")),
                 efl_file_key_set(efl_added, "test"),
                 efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(320, 240)),
                 efl_gfx_entity_visible_set(efl_added, 1));

   edje_object_signal_callback_add(obj, "some_signal", "event", _signal_callback_count_cb, &data[0]);
   edje_object_signal_callback_add(obj, "some_signal", "event", _signal_callback_count_cb, &data[1]);
   edje_object_signal_callback_add(obj, "some_signal", "event", _signal_callback_count_cb, &data[2]);
   edje_object_signal_callback_add(obj, "some_signal", "event", _signal_callback_count_cb, &data[3]);

   edje_object_signal_callback_del_full(obj, "some_signal", "event", _signal_callback_count_cb, &data[0]);
   edje_object_signal_callback_del_full(obj, "some_signal", "event", _signal_callback_count_cb, &data[3]);

   edje_object_signal_emit(obj, "some_signal", "event");

   edje_object_message_signal_process(obj);
   ck_assert_int_eq(_signal_count, (data[1] + data[2]));

   efl_del(obj);

}
EFL_END_TEST

void edje_test_signal(TCase *tc)
{
   tcase_add_test(tc, edje_test_message_send_legacy);
   tcase_add_test(tc, edje_test_message_send_eo);
   tcase_add_test(tc, edje_test_signals);
   tcase_add_test(tc, edje_test_signal_callback_del_full);

}