diff --git a/src/widgets/lv_arc.c b/src/widgets/lv_arc.c index 4df3dc015..5af367fce 100644 --- a/src/widgets/lv_arc.c +++ b/src/widgets/lv_arc.c @@ -57,11 +57,6 @@ const lv_obj_class_t lv_arc_class = { * GLOBAL FUNCTIONS **********************/ -/** - * Create an arc object - * @param par pointer to an object, it will be the parent of the new arc - * @return pointer to the created arc - */ lv_obj_t * lv_arc_create(lv_obj_t * parent) { LV_LOG_INFO("begin"); @@ -82,11 +77,6 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent) * Setter functions *====================*/ -/** - * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object - * @param start the start angle [0..360] - */ void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -107,11 +97,6 @@ void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start) arc->indic_angle_start = start; } -/** - * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object - * @param start the start angle [0..360] - */ void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -131,23 +116,12 @@ void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end) arc->indic_angle_end = end; } -/** - * Set the start and end angles - * @param arc pointer to an arc object - * @param start the start angle - * @param end the end angle - */ void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end) { lv_arc_set_end_angle(obj, end); lv_arc_set_start_angle(obj, start); } -/** - * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object - * @param start the start angle - */ void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -170,11 +144,6 @@ void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start) value_update(obj); } -/** - * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. - * @param arc pointer to an arc object - * @param end the end angle - */ void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -197,23 +166,12 @@ void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end) value_update(obj); } -/** - * Set the start and end angles of the arc background - * @param arc pointer to an arc object - * @param start the start angle - * @param end the end angle - */ void lv_arc_set_bg_angles(lv_obj_t * obj, uint16_t start, uint16_t end) { lv_arc_set_bg_end_angle(obj, end); lv_arc_set_bg_start_angle(obj, start); } -/** - * Set the rotation for the whole arc - * @param arc pointer to an arc object - * @param rotation rotation angle - */ void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -224,11 +182,6 @@ void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation) lv_obj_invalidate(obj); } -/** - * Set the type of arc. - * @param arc pointer to arc object - * @param type arc type - */ void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -258,11 +211,6 @@ void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type) lv_arc_set_value(obj, val); } -/** - * Set a new value on the arc - * @param arc pointer to an arc object - * @param value new value - */ void lv_arc_set_value(lv_obj_t * obj, int16_t value) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -280,12 +228,6 @@ void lv_arc_set_value(lv_obj_t * obj, int16_t value) value_update(obj); } -/** - * Set minimum and the maximum values of an arc - * @param arc pointer to the arc object - * @param min minimum value - * @param max maximum value - */ void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -306,12 +248,6 @@ void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max) value_update(obj); /*value has changed relative to the new range*/ } -/** - * Set the threshold of arc knob increments - * position. - * @param arc pointer to an arc object - * @param threshold increment threshold - */ void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -324,103 +260,54 @@ void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate) * Getter functions *====================*/ -/** - * Get the start angle of an arc. - * @param arc pointer to an arc object - * @return the start angle [0..360] - */ uint16_t lv_arc_get_angle_start(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->indic_angle_start; } -/** - * Get the end angle of an arc. - * @param arc pointer to an arc object - * @return the end angle [0..360] - */ uint16_t lv_arc_get_angle_end(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->indic_angle_end; } -/** - * Get the start angle of an arc background. - * @param arc pointer to an arc object - * @return the start angle [0..360] - */ uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->bg_angle_start; } -/** - * Get the end angle of an arc background. - * @param arc pointer to an arc object - * @return the end angle [0..360] - */ uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->bg_angle_end; } - -/** - * Get the value of an arc - * @param arc pointer to an arc object - * @return the value of the arc - */ int16_t lv_arc_get_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->value; } -/** - * Get the minimum value of an arc - * @param arc pointer to an arc object - * @return the minimum value of the arc - */ int16_t lv_arc_get_min_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->min_value; } -/** - * Get the maximum value of an arc - * @param arc pointer to an arc object - * @return the maximum value of the arc - */ int16_t lv_arc_get_max_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->max_value; } -/** - * Get whether the arc is type or not. - * @param arc pointer to an arc object - * @return arc type - */ lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); return ((lv_arc_t *) obj)->type; } -/*===================== - * Other functions - *====================*/ - -/* - * New object specific "other" functions come here - */ - /********************** * STATIC FUNCTIONS **********************/ diff --git a/tests/src/test_cases/test_arc.c b/tests/src/test_cases/test_arc.c index ab91c1b73..0bf27ed1c 100644 --- a/tests/src/test_cases/test_arc.c +++ b/tests/src/test_cases/test_arc.c @@ -3,8 +3,101 @@ #include "unity/unity.h" +/* This function runs before each test */ +void setUp(void); + +void test_arc_creation_successfull(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; + +void setUp(void) +{ + active_screen = lv_scr_act(); +} + +void test_arc_creation_successfull(void) +{ + arc = lv_arc_create(active_screen); + + TEST_ASSERT_NOT_NULL(arc); +} + +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) {