summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_test_spin_button.c
blob: a60314ff21490b670c7843c3f1325a7129b99cc0 (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>
#include <Efl_Ui.h>
#include "efl_ui_suite.h"

static Eo *win, *spin;

static void
spin_setup()
{
   win = win_add();

   spin = efl_add(EFL_UI_SPIN_BUTTON_CLASS, win);
   efl_content_set(win, spin);
   efl_gfx_entity_geometry_set(win, EINA_RECT(0, 0, 200, 50));
}

static void
_set_flag(void *data, const Efl_Event *ev)
{
   Eina_Bool *b = data;

   ck_assert_int_eq(*b, EINA_FALSE);
   *b = EINA_TRUE;
   ck_assert_ptr_eq(ev->info, NULL);
}

static void
_set_flag_quit(void *data, const Efl_Event *ev)
{
   Eina_Bool *b = data;

   ck_assert_int_eq(*b, EINA_FALSE);
   *b = EINA_TRUE;
   ck_assert_ptr_eq(ev->info, NULL);

   efl_loop_quit(efl_main_loop_get(), EINA_VALUE_EMPTY);
}

static void
click_spin_part(Eo *obj, const char *part)
{
   get_me_to_those_events(spin);
   click_part(obj, part);
}

EFL_START_TEST (spin_wheel_test)
{
   Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE;

   efl_ui_range_limits_set(spin, -100.0, 100.0);
   efl_ui_range_value_set(spin, 0.0);
   efl_ui_range_step_set(spin, 10.0);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_CHANGED, _set_flag, &changed);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MIN_REACHED, _set_flag, &min_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MAX_REACHED, _set_flag, &max_reached);

   efl_gfx_entity_size_set(win, EINA_SIZE2D(60, 60));
   get_me_to_those_events(spin);
   evas_event_feed_mouse_move(evas_object_evas_get(spin), 30, 30, 1234, NULL);
   evas_event_feed_mouse_wheel(evas_object_evas_get(spin), -1, -1, 12345, NULL);
   ck_assert(efl_ui_range_value_get(spin) == 10.0);
   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   evas_event_feed_mouse_wheel(evas_object_evas_get(spin), -1, 1, 12345, NULL);
   ck_assert(efl_ui_range_value_get(spin) == 0.0);
   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;
}
EFL_END_TEST

EFL_START_TEST (spin_value_inc)
{
   Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;

   efl_ui_range_limits_set(spin, 0.0, 3.0);
   efl_ui_range_value_set(spin, 1.0);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_CHANGED, _set_flag, &changed);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MIN_REACHED, _set_flag, &min_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MAX_REACHED, _set_flag, &max_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_STEADY, _set_flag_quit, &delay_changed);

   click_spin_part(spin, "efl.inc_button");

   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   efl_loop_begin(efl_main_loop_get());
   ck_assert_int_eq(delay_changed, EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST (spin_value_inc_max)
{
   Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;

   efl_ui_range_limits_set(spin, 0.0, 3.0);
   efl_ui_range_value_set(spin, 2.0);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_CHANGED, _set_flag, &changed);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MIN_REACHED, _set_flag, &min_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MAX_REACHED, _set_flag, &max_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_STEADY, _set_flag_quit, &delay_changed);

   click_spin_part(spin, "efl.inc_button");

   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_TRUE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   efl_loop_begin(efl_main_loop_get());
   ck_assert_int_eq(delay_changed, EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST (spin_value_dec_min)
{
   Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE, delay_changed = EINA_FALSE;

   efl_ui_range_limits_set(spin, 0.0, 3.0);
   efl_ui_range_value_set(spin, 1.0);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_CHANGED, _set_flag, &changed);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MIN_REACHED, _set_flag, &min_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_MAX_REACHED, _set_flag, &max_reached);
   efl_event_callback_add(spin, EFL_UI_RANGE_EVENT_STEADY, _set_flag_quit, &delay_changed);

   click_spin_part(spin, "efl.dec_button");

   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_TRUE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   efl_loop_begin(efl_main_loop_get());
   ck_assert_int_eq(delay_changed, EINA_TRUE);
}
EFL_END_TEST

void efl_ui_test_spin_button(TCase *tc)
{
   tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
   tcase_add_checked_fixture(tc, spin_setup, NULL);
   tcase_add_test(tc, spin_wheel_test);
   tcase_add_test(tc, spin_value_inc);
   tcase_add_test(tc, spin_value_inc_max);
   tcase_add_test(tc, spin_value_dec_min);
}