summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_test_win.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-08-31 15:41:12 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-09-01 14:57:11 +0900
commitb3993b684e30bf20fca66cf25308f627420a199d (patch)
tree1fa5f2ad18a8733f596e9a8e87fc72e0010aafa1 /src/tests/elementary/elm_test_win.c
parente61b7139ffba55504b653e14801d956eac180a63 (diff)
win: Add EO API to query state of multi touch points
This combines evas canvas functions to list and query touch points into a single iterator: - evas_touch_point_list_count - evas_touch_point_list_nth_xy_get - evas_touch_point_list_nth_id_get - evas_touch_point_list_nth_state_get This also fixes a number of issues related to feeding fake input events. Note: I wanted to add delta x,y information as well but it's in fact not really possible outside the event callback itself, as the previous x,y position will not be updated unless there's an event. @feature
Diffstat (limited to '')
-rw-r--r--src/tests/elementary/elm_test_win.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/src/tests/elementary/elm_test_win.c b/src/tests/elementary/elm_test_win.c
index d315463b86..49cc6db951 100644
--- a/src/tests/elementary/elm_test_win.c
+++ b/src/tests/elementary/elm_test_win.c
@@ -12,6 +12,7 @@
12 12
13static const double _timeout1 = 0.1; 13static const double _timeout1 = 0.1;
14static const double _timeout2 = 0.2; 14static const double _timeout2 = 0.2;
15static const double _timeout3 = 0.3;
15static const double _timeout_fail = 2.0; 16static const double _timeout_fail = 2.0;
16 17
17static void 18static void
@@ -193,12 +194,209 @@ START_TEST (elm_win_autohide_and_policy_quit_last_window_hidden)
193} 194}
194END_TEST 195END_TEST
195 196
197/* a very lax definition of == for doubles */
198#define VALEQ(a, b) ((fabs((a) - (b))) <= 0.001)
199
200typedef struct
201{
202 double x, y;
203} point_t;
204
205static point_t points[2][4] =
206{
207 {
208 { 20, 20 },
209 { 40, 10 },
210 { 60, 120 },
211 { 80, 80 }
212 },
213 {
214 { 30, 30 },
215 { 50, 50 },
216 { 70, 60 },
217 { 80, 80 }
218 },
219};
220
221static Eina_Bool
222_inputs_timer1_cb(void *data)
223{
224 Efl_Input_Pointer *ptr;
225 Eo *win = data;
226
227 /* Send down events first (note: stupid, all at once) */
228 for (size_t i = 0; i < 4; i++)
229 {
230 ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
231 efl_input_pointer_position_set(ptr, points[0][i].x, points[0][i].y);
232 efl_input_pointer_tool_set(ptr, i);
233 efl_input_pointer_button_set(ptr, 1);
234
235 if (i == 0)
236 {
237 /* in first */
238 efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_IN);
239 efl_event_callback_call(win, EFL_EVENT_POINTER_IN, ptr);
240
241 /* move second */
242 efl_input_pointer_position_set(ptr, points[0][i].x, points[0][i].y);
243 efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
244 efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
245 }
246
247 /* down finally */
248 efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_DOWN);
249 efl_event_callback_call(win, EFL_EVENT_POINTER_DOWN, ptr);
250 }
251
252 return ECORE_CALLBACK_DONE;
253}
254
255static Eina_Bool
256_inputs_timer2_cb(void *data)
257{
258 Efl_Input_Pointer *ptr;
259 Eina_Iterator *it;
260 Eo *win = data;
261 size_t i = 0, cnt = 0;
262
263 it = efl_input_pointer_iterate(win, 0);
264 EINA_ITERATOR_FOREACH(it, ptr)
265 {
266 double x, y;
267 int tool, ok = 0;
268
269 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
270 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
271 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOOL));
272 fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_DOWN);
273
274 x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
275 y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
276 tool = efl_input_pointer_tool_get(ptr);
277
278 for (i = 0; i < 4; i++)
279 if (tool == i)
280 {
281 fail_if(!VALEQ(x, points[0][i].x));
282 fail_if(!VALEQ(y, points[0][i].y));
283 ok = 1;
284 break;
285 }
286 fail_if(!ok);
287
288 cnt++;
289 }
290 eina_iterator_free(it);
291 fail_if(cnt != 4);
292
293 /* Send some moves */
294 for (i = 0; i < 4; i++)
295 {
296 ptr = efl_add(EFL_INPUT_POINTER_CLASS, win);
297 efl_input_pointer_position_set(ptr, points[1][i].x, points[1][i].y);
298 efl_input_pointer_tool_set(ptr, i);
299 efl_input_pointer_button_set(ptr, 1);
300
301 /* move first */
302 efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_MOVE);
303 efl_event_callback_call(win, EFL_EVENT_POINTER_MOVE, ptr);
304
305 /* then up (one 2 fingers up: #1 and #3) */
306 if ((i % 2) == 1)
307 {
308 efl_input_pointer_action_set(ptr, EFL_POINTER_ACTION_UP);
309 efl_event_callback_call(win, EFL_EVENT_POINTER_UP, ptr);
310 }
311 }
312
313 return ECORE_CALLBACK_DONE;
314}
315
316static Eina_Bool
317_inputs_timer3_cb(void *data)
318{
319 Efl_Input_Pointer *ptr;
320 Eina_Iterator *it;
321 Eo *win = data;
322 size_t i = 0, cnt = 0;
323
324 it = efl_input_pointer_iterate(win, 0);
325 EINA_ITERATOR_FOREACH(it, ptr)
326 {
327 int tool, ok = 0;
328 double x, y;
329
330 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_X));
331 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_Y));
332 fail_if(!efl_input_pointer_value_has_get(ptr, EFL_INPUT_VALUE_TOOL));
333 fail_if(efl_input_pointer_action_get(ptr) != EFL_POINTER_ACTION_MOVE);
334
335 x = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_X);
336 y = efl_input_pointer_value_get(ptr, EFL_INPUT_VALUE_Y);
337 tool = efl_input_pointer_tool_get(ptr);
338
339 for (i = 0; i < 4; i++)
340 if (tool == i)
341 {
342 fail_if(!VALEQ(x, points[1][i].x));
343 fail_if(!VALEQ(y, points[1][i].y));
344 ok = 1;
345 break;
346 }
347 fail_if(!ok);
348
349 cnt++;
350 }
351 eina_iterator_free(it);
352 fail_if(cnt != 2); // 2 moves (in the list), 2 ups (gone)
353
354 elm_exit();
355
356 return ECORE_CALLBACK_DONE;
357}
358
359START_TEST (efl_ui_win_multi_touch_inputs)
360{
361 Eina_Bool fail_flag = EINA_FALSE;
362 Eo *win;
363
364 /* this tests only multi touch inputs - a lot of code but quite basic
365 * faking events is quite hard, as an exact sequence must be followed:
366 *
367 * pointer 0: in, move, down, move, move, ...
368 * pointer x: down, move, move, ...
369 */
370
371 elm_init(0, NULL);
372
373 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
374
375 win = elm_win_add(NULL, "win", ELM_WIN_BASIC);
376 elm_win_autohide_set(win, EINA_TRUE);
377 efl_gfx_visible_set(win, EINA_TRUE);
378 efl_gfx_size_set(win, 100, 100);
379
380 ecore_timer_add(_timeout1, _inputs_timer1_cb, win);
381 ecore_timer_add(_timeout2, _inputs_timer2_cb, win);
382 ecore_timer_add(_timeout3, _inputs_timer3_cb, win);
383 ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
384
385 elm_run();
386
387 fail_if(fail_flag != EINA_FALSE);
388
389 elm_shutdown();
390}
391END_TEST
392
196void elm_test_win(TCase *tc) 393void elm_test_win(TCase *tc)
197{ 394{
198 tcase_add_test(tc, elm_atspi_role_get); 395 tcase_add_test(tc, elm_atspi_role_get);
199 tcase_add_test(tc, elm_atspi_component_position); 396 tcase_add_test(tc, elm_atspi_component_position);
200 tcase_add_test(tc, elm_atspi_component_size); 397 tcase_add_test(tc, elm_atspi_component_size);
201 tcase_add_test(tc, elm_win_policy_quit_last_window_hidden); 398 tcase_add_test(tc, elm_win_policy_quit_last_window_hidden);
399 tcase_add_test(tc, efl_ui_win_multi_touch_inputs);
202#ifdef HAVE_ELEMENTARY_X 400#ifdef HAVE_ELEMENTARY_X
203 tcase_add_test(tc, elm_win_autohide); 401 tcase_add_test(tc, elm_win_autohide);
204 tcase_add_test(tc, elm_win_autohide_and_policy_quit_last_window_hidden); 402 tcase_add_test(tc, elm_win_autohide_and_policy_quit_last_window_hidden);