test(arc) add initial unit tests (#2617)
* test(arc): Add test for valid creation * test(arc): Add test for max value truncation * test(arc): Add test for min value truncation * test(arc): Add test for value adjustment after updating range * test(arc): Update test for min value truncation * test(arc): Add test for angle updating after changing to symmetrical mode * test(arc): Add test for angle updating after changing to symmetrical mode and value is greater than middle range * test(arc): Use unity setUp function * remove API comments from lv_arc.c Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user