bu5hm4n pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=18e9bc9a9fa530f5f0d48e8834b930b7b58c01d9
commit 18e9bc9a9fa530f5f0d48e8834b930b7b58c01d9 Author: Mike Blumenkrantz <zm...@samsung.com> Date: Mon Jan 6 12:30:45 2020 -0500 tests/efl_ui: begin some gesture unit tests adds basic testing for taps and flick Differential Revision: https://phab.enlightenment.org/D11029 --- src/tests/elementary/efl_ui_suite.c | 1 + src/tests/elementary/efl_ui_suite.h | 1 + src/tests/elementary/efl_ui_test_gesture.c | 157 +++++++++++++++++++++++++++++ src/tests/elementary/meson.build | 1 + 4 files changed, 160 insertions(+) diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c index b9d8e9bbff..cfe45f4cf7 100644 --- a/src/tests/elementary/efl_ui_suite.c +++ b/src/tests/elementary/efl_ui_suite.c @@ -14,6 +14,7 @@ static const Efl_Test_Case etc[] = { { "efl_ui_config", efl_ui_test_config}, { "efl_ui_focus", efl_ui_test_focus}, { "efl_ui_focus_sub", efl_ui_test_focus_sub}, + { "efl_ui_gesture", efl_ui_test_gesture}, { "efl_ui_box", efl_ui_test_box}, { "efl_ui_box_flow", efl_ui_test_box_flow}, { "efl_ui_box_stack", efl_ui_test_box_stack}, diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h index af58984840..4963b4a77c 100644 --- a/src/tests/elementary/efl_ui_suite.h +++ b/src/tests/elementary/efl_ui_suite.h @@ -33,6 +33,7 @@ void efl_ui_test_image(TCase *tc); void efl_ui_test_callback(TCase *tc); void efl_ui_test_focus(TCase *tc); void efl_ui_test_focus_sub(TCase *tc); +void efl_ui_test_gesture(TCase *tc); void efl_ui_model(TCase *tc); void efl_ui_test_widget(TCase *tc); void efl_ui_test_spotlight(TCase *tc); diff --git a/src/tests/elementary/efl_ui_test_gesture.c b/src/tests/elementary/efl_ui_test_gesture.c new file mode 100644 index 0000000000..106fa1a2a1 --- /dev/null +++ b/src/tests/elementary/efl_ui_test_gesture.c @@ -0,0 +1,157 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif + +#include <Efl_Ui.h> +#include "efl_ui_suite.h" + +/* +typedef enum +{ + EFL_GESTURE_STATE_NONE = 0, + EFL_GESTURE_STATE_STARTED = 1, + EFL_GESTURE_STATE_UPDATED, + EFL_GESTURE_STATE_FINISHED, + EFL_GESTURE_STATE_CANCELED +} Efl_Canvas_Gesture_State; +*/ + +enum +{ + TAP, + LONG_TAP, + DOUBLE_TAP, + TRIPLE_TAP, + MOMENTUM, + FLICK, + ZOOM, + LAST +}; + +static int count[LAST][4] = {0}; + +/* macros to simplify checking gesture counts */ +#define CHECK_START(type, val) \ + ck_assert_int_eq(count[(type)][EFL_GESTURE_STATE_STARTED - 1], (val)) +#define CHECK_UPDATE(type, val) \ + ck_assert_int_eq(count[(type)][EFL_GESTURE_STATE_UPDATED - 1], (val)) +#define CHECK_FINISH(type, val) \ + ck_assert_int_eq(count[(type)][EFL_GESTURE_STATE_FINISHED - 1], (val)) +#define CHECK_CANCEL(type, val) \ + ck_assert_int_eq(count[(type)][EFL_GESTURE_STATE_CANCELED - 1], (val)) +#define CHECK_ALL(type, ...) \ + do {\ + int state_vals[] = {__VA_ARGS__}; \ + for (int i = 0; i < 4; i++) \ + ck_assert_int_eq(count[(type)][i], state_vals[i]); \ + } while (0) +#define CHECK_ZERO(type) CHECK_ALL((type), 0, 0, 0, 0) +#define RESET memset(count, 0, sizeof(count)) + +static void +gesture_cb(void *data , const Efl_Event *ev) +{ + Efl_Canvas_Gesture *g = ev->info; + int *count = data; + /* increment counter for event state which has been processed */ + count[efl_gesture_state_get(g) - 1]++; +} + +static Eo * +setup(void) +{ + Eo *win, *rect; + + RESET; + + win = win_add(); + efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100)); + + rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win); + efl_content_set(win, rect); + +#define WATCH(type) \ + efl_event_callback_add(rect, EFL_EVENT_GESTURE_##type, gesture_cb, &count[(type)]) + WATCH(TAP); + WATCH(LONG_TAP); + WATCH(DOUBLE_TAP); + WATCH(TRIPLE_TAP); + WATCH(MOMENTUM); + WATCH(FLICK); + WATCH(ZOOM); + + get_me_to_those_events(win); + return rect; +} + +EFL_START_TEST(test_efl_ui_gesture_taps) +{ + Eo *rect = setup(); + + /* basic tap */ + click_object(rect); + CHECK_ALL(TAP, 1, 0, 1, 0); + CHECK_ALL(LONG_TAP, 1, 0, 0, 1); + CHECK_ALL(DOUBLE_TAP, 1, 1, 0, 0); + CHECK_ALL(TRIPLE_TAP, 1, 1, 0, 0); + CHECK_ZERO(MOMENTUM); + CHECK_ZERO(FLICK); + CHECK_ZERO(ZOOM); + + RESET; + + /* add a second tap */ + click_object(rect); + CHECK_ALL(TAP, 1, 0, 1, 0); + CHECK_ALL(LONG_TAP, 1, 0, 0, 1); + /* UPDATE -> FINISH */ + CHECK_ALL(DOUBLE_TAP, 0, 1, 1, 0); + CHECK_ALL(TRIPLE_TAP, 0, 2, 0, 0); + CHECK_ZERO(MOMENTUM); + CHECK_ZERO(FLICK); + CHECK_ZERO(ZOOM); + + RESET; + + /* add a third tap */ + click_object(rect); + CHECK_ALL(TAP, 1, 0, 1, 0); + CHECK_ALL(LONG_TAP, 1, 0, 0, 1); + /* UPDATE -> FINISH */ + CHECK_ALL(DOUBLE_TAP, 1, 1, 0, 0); + CHECK_ALL(TRIPLE_TAP, 0, 1, 1, 0); + CHECK_ZERO(MOMENTUM); + CHECK_ZERO(FLICK); + CHECK_ZERO(ZOOM); +} +EFL_END_TEST + +EFL_START_TEST(test_efl_ui_gesture_flick) +{ + Eo *rect = setup(); + + /* basic flick */ + drag_object(rect, 0, 0, 75, 0, EINA_FALSE); + /* canceled */ + CHECK_ALL(TAP, 1, 0, 0, 1); + /* canceled */ + CHECK_ALL(LONG_TAP, 1, 0, 0, 1); + /* canceled */ + CHECK_ALL(DOUBLE_TAP, 1, 0, 0, 1); + /* canceled */ + CHECK_ALL(TRIPLE_TAP, 1, 0, 0, 1); + /* updated but canceled */ + CHECK_ALL(MOMENTUM, 1, DRAG_OBJECT_NUM_MOVES - 1, 0, 1); + /* triggered */ + CHECK_ALL(FLICK, 1, DRAG_OBJECT_NUM_MOVES - 1, 1, 0); + CHECK_ZERO(ZOOM); + + RESET; +} +EFL_END_TEST + +void efl_ui_test_gesture(TCase *tc) +{ + tcase_add_test(tc, test_efl_ui_gesture_taps); + tcase_add_test(tc, test_efl_ui_gesture_flick); +} diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build index 4540486b1b..745a63daf7 100644 --- a/src/tests/elementary/meson.build +++ b/src/tests/elementary/meson.build @@ -129,6 +129,7 @@ efl_ui_suite_src = [ 'efl_ui_test_focus_common.h', 'efl_ui_test_focus.c', 'efl_ui_test_focus_sub.c', + 'efl_ui_test_gesture.c', 'efl_ui_test_box.c', 'efl_ui_test_box_flow.c', 'efl_ui_test_box_stack.c', --