summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-07 18:14:13 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-08 19:56:42 +0200
commit52adb65aeaccf54e700e8421daf59e10568df4dd (patch)
tree2f02940b88ac623addc0eeb6ff40481d96a03c48
parentd5df7e459d0bddd63b213ab8ac7a87cd0b1c08fc (diff)
efl_ui_spin_button: add test suite
this adds a testsuite to emulate and check the usage of buttons in the spin button widget. This also verifies that the correct events are emitted. (For now, the testcases from spin are also copied over, since they inherit from each other) Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9232
-rw-r--r--src/lib/elementary/Efl_Ui.h1
-rw-r--r--src/tests/elementary/efl_ui_suite.c1
-rw-r--r--src/tests/elementary/efl_ui_suite.h1
-rw-r--r--src/tests/elementary/efl_ui_test_spin_button.c210
-rw-r--r--src/tests/elementary/meson.build1
5 files changed, 214 insertions, 0 deletions
diff --git a/src/lib/elementary/Efl_Ui.h b/src/lib/elementary/Efl_Ui.h
index 7b99cf3a23..09204faad1 100644
--- a/src/lib/elementary/Efl_Ui.h
+++ b/src/lib/elementary/Efl_Ui.h
@@ -248,6 +248,7 @@ typedef Eo Efl_Ui_Spotlight_Indicator;
248# include <efl_ui_clickable_util.eo.h> 248# include <efl_ui_clickable_util.eo.h>
249# include <efl_ui_format.eo.h> 249# include <efl_ui_format.eo.h>
250# include <efl_ui_spin.eo.h> 250# include <efl_ui_spin.eo.h>
251# include <efl_ui_spin_button.eo.h>
251 252
252/** 253/**
253 * Initialize Elementary 254 * Initialize Elementary
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index 07c47cbd3e..87e4e8c696 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -30,6 +30,7 @@ static const Efl_Test_Case etc[] = {
30 { "efl_ui_radio_group", efl_ui_test_radio_group }, 30 { "efl_ui_radio_group", efl_ui_test_radio_group },
31 { "efl_ui_win", efl_ui_test_win }, 31 { "efl_ui_win", efl_ui_test_win },
32 { "efl_ui_spin", efl_ui_test_spin }, 32 { "efl_ui_spin", efl_ui_test_spin },
33 { "efl_ui_spin_button", efl_ui_test_spin_button },
33 { NULL, NULL } 34 { NULL, NULL }
34}; 35};
35 36
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 1366494c38..0e8be968ff 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -41,6 +41,7 @@ void efl_ui_test_progressbar(TCase *tc);
41void efl_ui_test_radio_group(TCase *tc); 41void efl_ui_test_radio_group(TCase *tc);
42void efl_ui_test_win(TCase *tc); 42void efl_ui_test_win(TCase *tc);
43void efl_ui_test_spin(TCase *tc); 43void efl_ui_test_spin(TCase *tc);
44void efl_ui_test_spin_button(TCase *tc);
44 45
45void loop_timer_interval_set(Eo *obj, double in); 46void loop_timer_interval_set(Eo *obj, double in);
46 47
diff --git a/src/tests/elementary/efl_ui_test_spin_button.c b/src/tests/elementary/efl_ui_test_spin_button.c
new file mode 100644
index 0000000000..c495c881a8
--- /dev/null
+++ b/src/tests/elementary/efl_ui_test_spin_button.c
@@ -0,0 +1,210 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include "efl_ui_suite.h"
7
8static Eo *win, *spin;
9
10static void
11spin_setup()
12{
13 win = win_add();
14
15 spin = efl_add(EFL_UI_SPIN_BUTTON_CLASS, win);
16 efl_content_set(win, spin);
17 efl_gfx_entity_geometry_set(win, EINA_RECT(0, 0, 200, 50));
18}
19
20static void
21_set_flag(void *data, const Efl_Event *ev)
22{
23 Eina_Bool *b = data;
24
25 ck_assert_int_eq(*b, EINA_FALSE);
26 *b = EINA_TRUE;
27 ck_assert_ptr_eq(ev->info, NULL);
28}
29
30static void
31_set_flag_quit(void *data, const Efl_Event *ev)
32{
33 Eina_Bool *b = data;
34
35 ck_assert_int_eq(*b, EINA_FALSE);
36 *b = EINA_TRUE;
37 ck_assert_ptr_eq(ev->info, NULL);
38
39 efl_loop_quit(efl_main_loop_get(), EINA_VALUE_EMPTY);
40}
41
42static void
43click_object(Efl_Part *obj)
44{
45 get_me_to_those_events(spin);
46
47 Evas *e = evas_object_evas_get(spin);
48 //this deletes the part
49 Eina_Rect r = efl_gfx_entity_geometry_get(obj);
50 evas_event_feed_mouse_move(e, r.x+r.w/2, r.y+r.h/2, 1234, NULL);
51 evas_event_feed_mouse_down(e, 1, 0, 1235, NULL);
52 evas_event_feed_mouse_up(e, 1, 0, 1236, NULL);
53 edje_object_message_signal_process(obj);
54}
55
56EFL_START_TEST (spin_value_events)
57{
58 Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE;
59
60 efl_ui_range_limits_set(spin, -3.0, 3.0);
61 efl_ui_range_value_set(spin, 0.0);
62 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_CHANGED, _set_flag, &changed);
63 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MIN_REACHED, _set_flag, &min_reached);
64 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MAX_REACHED, _set_flag, &max_reached);
65
66 efl_ui_range_value_set(spin, 1.0);
67 ck_assert_int_eq(changed, EINA_TRUE);
68 ck_assert_int_eq(min_reached, EINA_FALSE);
69 ck_assert_int_eq(max_reached, EINA_FALSE);
70 changed = EINA_FALSE;
71 min_reached = EINA_FALSE;
72 max_reached = EINA_FALSE;
73
74 efl_ui_range_value_set(spin, 3.0);
75 ck_assert_int_eq(changed, EINA_TRUE);
76 ck_assert_int_eq(min_reached, EINA_FALSE);
77 ck_assert_int_eq(max_reached, EINA_TRUE);
78 changed = EINA_FALSE;
79 min_reached = EINA_FALSE;
80 max_reached = EINA_FALSE;
81
82 efl_ui_range_value_set(spin, -3.0);
83 ck_assert_int_eq(changed, EINA_TRUE);
84 ck_assert_int_eq(min_reached, EINA_TRUE);
85 ck_assert_int_eq(max_reached, EINA_FALSE);
86 changed = EINA_FALSE;
87 min_reached = EINA_FALSE;
88 max_reached = EINA_FALSE;
89}
90EFL_END_TEST
91
92EFL_START_TEST (spin_wheel_test)
93{
94 Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE;
95
96 efl_ui_range_limits_set(spin, -100.0, 100.0);
97 efl_ui_range_value_set(spin, 0.0);
98 efl_ui_range_step_set(spin, 10.0);
99 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_CHANGED, _set_flag, &changed);
100 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MIN_REACHED, _set_flag, &min_reached);
101 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MAX_REACHED, _set_flag, &max_reached);
102
103 efl_gfx_entity_size_set(win, EINA_SIZE2D(60, 60));
104 get_me_to_those_events(spin);
105 evas_event_feed_mouse_move(evas_object_evas_get(spin), 30, 30, 1234, NULL);
106 evas_event_feed_mouse_wheel(evas_object_evas_get(spin), -1, -1, 12345, NULL);
107 ck_assert(efl_ui_range_value_get(spin) == 10.0);
108 ck_assert_int_eq(changed, EINA_TRUE);
109 ck_assert_int_eq(min_reached, EINA_FALSE);
110 ck_assert_int_eq(max_reached, EINA_FALSE);
111 changed = EINA_FALSE;
112 min_reached = EINA_FALSE;
113 max_reached = EINA_FALSE;
114
115 evas_event_feed_mouse_wheel(evas_object_evas_get(spin), -1, 1, 12345, NULL);
116 ck_assert(efl_ui_range_value_get(spin) == 0.0);
117 ck_assert_int_eq(changed, EINA_TRUE);
118 ck_assert_int_eq(min_reached, EINA_FALSE);
119 ck_assert_int_eq(max_reached, EINA_FALSE);
120 changed = EINA_FALSE;
121 min_reached = EINA_FALSE;
122 max_reached = EINA_FALSE;
123}
124EFL_END_TEST
125
126EFL_START_TEST (spin_value_inc)
127{
128 Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;
129
130 efl_ui_range_limits_set(spin, 0.0, 3.0);
131 efl_ui_range_value_set(spin, 1.0);
132 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_CHANGED, _set_flag, &changed);
133 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MIN_REACHED, _set_flag, &min_reached);
134 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MAX_REACHED, _set_flag, &max_reached);
135 efl_event_callback_add(spin, EFL_UI_SPIN_BUTTON_EVENT_DELAY_CHANGED, _set_flag_quit, &delay_changed);
136
137 click_object(efl_content_get(efl_part(spin, "efl.inc_button")));
138
139 ck_assert_int_eq(changed, EINA_TRUE);
140 ck_assert_int_eq(min_reached, EINA_FALSE);
141 ck_assert_int_eq(max_reached, EINA_FALSE);
142 changed = EINA_FALSE;
143 min_reached = EINA_FALSE;
144 max_reached = EINA_FALSE;
145
146 efl_loop_begin(efl_main_loop_get());
147 ck_assert_int_eq(delay_changed, EINA_TRUE);
148}
149EFL_END_TEST
150
151EFL_START_TEST (spin_value_inc_max)
152{
153 Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;
154
155 efl_ui_range_limits_set(spin, 0.0, 3.0);
156 efl_ui_range_value_set(spin, 2.0);
157 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_CHANGED, _set_flag, &changed);
158 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MIN_REACHED, _set_flag, &min_reached);
159 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MAX_REACHED, _set_flag, &max_reached);
160 efl_event_callback_add(spin, EFL_UI_SPIN_BUTTON_EVENT_DELAY_CHANGED, _set_flag_quit, &delay_changed);
161
162 click_object(efl_content_get(efl_part(spin, "efl.inc_button")));
163
164 ck_assert_int_eq(changed, EINA_TRUE);
165 ck_assert_int_eq(min_reached, EINA_FALSE);
166 ck_assert_int_eq(max_reached, EINA_TRUE);
167 changed = EINA_FALSE;
168 min_reached = EINA_FALSE;
169 max_reached = EINA_FALSE;
170
171 efl_loop_begin(efl_main_loop_get());
172 ck_assert_int_eq(delay_changed, EINA_TRUE);
173}
174EFL_END_TEST
175
176EFL_START_TEST (spin_value_dec_min)
177{
178 Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;
179
180 efl_ui_range_limits_set(spin, 0.0, 3.0);
181 efl_ui_range_value_set(spin, 1.0);
182 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_CHANGED, _set_flag, &changed);
183 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MIN_REACHED, _set_flag, &min_reached);
184 efl_event_callback_add(spin, EFL_UI_SPIN_EVENT_MAX_REACHED, _set_flag, &max_reached);
185 efl_event_callback_add(spin, EFL_UI_SPIN_BUTTON_EVENT_DELAY_CHANGED, _set_flag_quit, &delay_changed);
186
187 click_object(efl_content_get(efl_part(spin, "efl.dec_button")));
188
189 ck_assert_int_eq(changed, EINA_TRUE);
190 ck_assert_int_eq(min_reached, EINA_TRUE);
191 ck_assert_int_eq(max_reached, EINA_FALSE);
192 changed = EINA_FALSE;
193 min_reached = EINA_FALSE;
194 max_reached = EINA_FALSE;
195
196 efl_loop_begin(efl_main_loop_get());
197 ck_assert_int_eq(delay_changed, EINA_TRUE);
198}
199EFL_END_TEST
200
201void efl_ui_test_spin_button(TCase *tc)
202{
203 tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
204 tcase_add_checked_fixture(tc, spin_setup, NULL);
205 tcase_add_test(tc, spin_value_events);
206 tcase_add_test(tc, spin_wheel_test);
207 tcase_add_test(tc, spin_value_inc);
208 tcase_add_test(tc, spin_value_inc_max);
209 tcase_add_test(tc, spin_value_dec_min);
210}
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index 17458f36e0..4dc1bd1305 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -144,6 +144,7 @@ efl_ui_suite_src = [
144 'efl_ui_test_radio_group.c', 144 'efl_ui_test_radio_group.c',
145 'efl_ui_test_progressbar.c', 145 'efl_ui_test_progressbar.c',
146 'efl_ui_test_spin.c', 146 'efl_ui_test_spin.c',
147 'efl_ui_test_spin_button.c',
147] 148]
148 149
149efl_ui_suite = executable('efl_ui_suite', 150efl_ui_suite = executable('efl_ui_suite',