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
240
241
|
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "unity/unity.h"
#include "lv_test_indev.h"
/* This function runs before each test */
void setUp(void);
void test_arc_creation_successful(void);
void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void);
void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void);
void test_arc_should_update_value_after_updating_range(void);
void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void);
void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void);
void test_arc_angles_when_reversed(void);
static lv_obj_t * active_screen = NULL;
static lv_obj_t * arc = NULL;
static uint32_t event_cnt;
static void dummy_event_cb(lv_event_t * e);
void setUp(void)
{
active_screen = lv_screen_active();
}
void tearDown(void)
{
lv_obj_clean(active_screen);
lv_obj_set_style_layout(active_screen, LV_LAYOUT_NONE, 0);
}
void test_arc_creation_successful(void)
{
arc = lv_arc_create(active_screen);
TEST_ASSERT_NOT_NULL(arc);
}
void test_arc_basic_render(void)
{
arc = lv_arc_create(active_screen);
lv_obj_set_size(arc, 100, 100);
lv_obj_center(arc);
lv_arc_set_value(arc, 70);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/arc_1.png");
}
void test_arc_rgb565a8_image(void)
{
#if LV_BIN_DECODER_RAM_LOAD
/*RGB565A8 image rendering requires special handling*/
arc = lv_arc_create(active_screen);
lv_obj_set_size(arc, 100, 100);
lv_obj_center(arc);
lv_arc_set_value(arc, 70);
lv_obj_set_style_arc_width(arc, 30, 0);
lv_obj_set_style_arc_width(arc, 30, LV_PART_INDICATOR);
lv_obj_set_style_arc_image_src(arc, "A:src/test_files/binimages/cogwheel.RGB565A8.bin", LV_PART_INDICATOR);
lv_obj_set_style_arc_opa(arc, 150, LV_PART_INDICATOR);
lv_obj_set_style_bg_opa(arc, 0, LV_PART_KNOB);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/arc_2.png");
#endif
}
void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void)
{
/* Default max range is 100 */
int16_t value_after_truncation = 100;
arc = lv_arc_create(active_screen);
lv_arc_set_value(arc, 200);
TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc));
}
void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void)
{
/* Default min range is 100 */
int16_t value_after_truncation = 0;
arc = lv_arc_create(active_screen);
lv_arc_set_value(arc, 0);
TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc));
}
void test_arc_should_update_value_after_updating_range(void)
{
int16_t value_after_updating_max_range = 50;
int16_t value_after_updating_min_range = 30;
arc = lv_arc_create(active_screen);
lv_arc_set_value(arc, 80);
lv_arc_set_range(arc, 1, 50);
TEST_ASSERT_EQUAL_INT16(value_after_updating_max_range, lv_arc_get_value(arc));
lv_arc_set_value(arc, 10);
lv_arc_set_range(arc, 30, 50);
TEST_ASSERT_EQUAL_INT16(value_after_updating_min_range, lv_arc_get_value(arc));
}
void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void)
{
int16_t expected_angle_start = 135;
int16_t expected_angle_end = 270;
/* start angle is 135, end angle is 45 at creation */
arc = lv_arc_create(active_screen);
lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL);
TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc));
TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc));
}
void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void)
{
int16_t expected_angle_start = 270;
int16_t expected_angle_end = 45;
/* start angle is 135, end angle is 45 at creation */
arc = lv_arc_create(active_screen);
lv_arc_set_value(arc, 100);
lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL);
TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc));
TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc));
}
/* See #2522 for more information */
void test_arc_angles_when_reversed(void)
{
uint16_t expected_start_angle = 54;
uint16_t expected_end_angle = 90;
int16_t expected_value = 40;
lv_obj_t * arcBlack;
arcBlack = lv_arc_create(lv_screen_active());
lv_arc_set_mode(arcBlack, LV_ARC_MODE_REVERSE);
lv_arc_set_bg_angles(arcBlack, 0, 90);
lv_arc_set_value(arcBlack, expected_value);
TEST_ASSERT_EQUAL_UINT16(expected_start_angle, lv_arc_get_angle_start(arcBlack));
TEST_ASSERT_EQUAL_UINT16(expected_end_angle, lv_arc_get_angle_end(arcBlack));
TEST_ASSERT_EQUAL_INT16(expected_value, lv_arc_get_value(arcBlack));
}
void test_arc_click_area_with_adv_hittest(void)
{
arc = lv_arc_create(lv_screen_active());
lv_obj_set_size(arc, 100, 100);
lv_obj_set_style_arc_width(arc, 10, 0);
lv_obj_add_flag(arc, LV_OBJ_FLAG_ADV_HITTEST);
lv_obj_add_event_cb(arc, dummy_event_cb, LV_EVENT_PRESSED, NULL);
lv_obj_set_ext_click_area(arc, 5);
/*No click detected at the middle*/
event_cnt = 0;
lv_test_mouse_click_at(50, 50);
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
/*No click close to the radius - bg_arc - ext_click_area*/
event_cnt = 0;
lv_test_mouse_click_at(83, 50);
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
/*Click on the radius - bg_arc - ext_click_area*/
event_cnt = 0;
lv_test_mouse_click_at(86, 50);
TEST_ASSERT_GREATER_THAN(0, event_cnt);
/*Click on the radius + ext_click_area*/
event_cnt = 0;
lv_test_mouse_click_at(104, 50);
TEST_ASSERT_GREATER_THAN(0, event_cnt);
/*No click beyond to the radius + ext_click_area*/
event_cnt = 0;
lv_test_mouse_click_at(106, 50);
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
}
/* Check value doesn't go to max when clicking on the other side of the arc */
void test_arc_click_sustained_from_start_to_end_does_not_set_value_to_max(void)
{
arc = lv_arc_create(lv_screen_active());
lv_arc_set_value(arc, 0);
lv_obj_set_size(arc, 100, 100);
lv_obj_center(arc);
lv_obj_add_event_cb(arc, dummy_event_cb, LV_EVENT_PRESSED, NULL);
event_cnt = 0;
/* Click close to start angle */
event_cnt = 0;
lv_test_mouse_move_to(376, 285);
lv_test_mouse_press();
lv_test_indev_wait(500);
lv_test_mouse_release();
lv_test_indev_wait(50);
TEST_ASSERT_EQUAL_UINT32(1, event_cnt);
TEST_ASSERT_EQUAL_INT32(lv_arc_get_min_value(arc), lv_arc_get_value(arc));
/* Click close to end angle */
event_cnt = 0;
lv_test_mouse_move_to(376, 285);
lv_test_mouse_press();
lv_test_indev_wait(500);
lv_test_mouse_move_to(415, 281);
lv_test_indev_wait(500);
lv_test_mouse_release();
lv_test_indev_wait(50);
TEST_ASSERT_EQUAL_UINT32(1, event_cnt);
TEST_ASSERT_EQUAL_INT32(lv_arc_get_min_value(arc), lv_arc_get_value(arc));
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/arc_3.png");
}
static void dummy_event_cb(lv_event_t * e)
{
LV_UNUSED(e);
event_cnt++;
}
#endif
|