From 62a26492cb8ea64cd931998622be7e16242f26dc Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 23 Dec 2023 19:51:35 -0600 Subject: [PATCH] test(scale): Add tests for some properties --- src/widgets/scale/lv_scale.c | 24 ++++++++++++ src/widgets/scale/lv_scale.h | 28 ++++++++++++++ tests/src/test_cases/widgets/test_scale.c | 45 +++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/src/widgets/scale/lv_scale.c b/src/widgets/scale/lv_scale.c index f101e689275a..9aa20873f355 100644 --- a/src/widgets/scale/lv_scale.c +++ b/src/widgets/scale/lv_scale.c @@ -357,6 +357,30 @@ void lv_scale_section_set_style(lv_scale_section_t * section, uint32_t part, lv_ * Getter functions *====================*/ +lv_scale_mode_t lv_scale_get_mode(lv_obj_t * obj) +{ + lv_scale_t * scale = (lv_scale_t *)obj; + return scale->mode; +} + +int32_t lv_scale_get_total_tick_count(lv_obj_t * obj) +{ + lv_scale_t * scale = (lv_scale_t *)obj; + return scale->total_tick_count; +} + +int32_t lv_scale_get_major_tick_every(lv_obj_t * obj) +{ + lv_scale_t * scale = (lv_scale_t *)obj; + return scale->major_tick_every; +} + +bool lv_scale_get_label_show(lv_obj_t * obj) +{ + lv_scale_t * scale = (lv_scale_t *)obj; + return scale->label_enabled; +} + /*===================== * Other functions *====================*/ diff --git a/src/widgets/scale/lv_scale.h b/src/widgets/scale/lv_scale.h index 5004e9eca772..c097cf221f27 100644 --- a/src/widgets/scale/lv_scale.h +++ b/src/widgets/scale/lv_scale.h @@ -239,6 +239,34 @@ void lv_scale_section_set_style(lv_scale_section_t * section, uint32_t part, lv_ * Getter functions *====================*/ +/** + * Get scale mode. See @ref lv_scale_mode_t + * @param obj pointer the scale object + * @return Scale mode + */ +lv_scale_mode_t lv_scale_get_mode(lv_obj_t * obj); + +/** + * Get scale total tick count (including minor and major ticks) + * @param obj pointer the scale object + * @return Scale total tick count + */ +int32_t lv_scale_get_total_tick_count(lv_obj_t * obj); + +/** + * Gets how often the major tick will be drawn + * @param obj pointer the scale object + * @return Scale major tick every count + */ +int32_t lv_scale_get_major_tick_every(lv_obj_t * obj); + +/** + * Gets label visibility + * @param obj pointer the scale object + * @return true if tick label is enabled, false otherwise + */ +bool lv_scale_get_label_show(lv_obj_t * obj); + /********************** * MACROS **********************/ diff --git a/tests/src/test_cases/widgets/test_scale.c b/tests/src/test_cases/widgets/test_scale.c index 76315908a552..020e963087ec 100644 --- a/tests/src/test_cases/widgets/test_scale.c +++ b/tests/src/test_cases/widgets/test_scale.c @@ -322,4 +322,49 @@ void test_scale_custom_labels_count(void) TEST_ASSERT_EQUAL(2U, scale_widget->custom_label_cnt); } +void test_scale_mode(void) +{ + lv_obj_t * scale = lv_scale_create(lv_screen_active()); + + lv_scale_mode_t mode = LV_SCALE_MODE_ROUND_INNER; + lv_scale_set_mode(scale, mode); + + TEST_ASSERT_EQUAL(mode, lv_scale_get_mode(scale)); +} + +void test_scale_total_tick_count(void) +{ + lv_obj_t * scale = lv_scale_create(lv_screen_active()); + + int32_t total_tick_count = 42; + lv_scale_set_total_tick_count(scale, total_tick_count); + + TEST_ASSERT_EQUAL(total_tick_count, lv_scale_get_total_tick_count(scale)); +} + +void test_scale_major_tick_every(void) +{ + lv_obj_t * scale = lv_scale_create(lv_screen_active()); + + int32_t major_tick_every = 6; + lv_scale_set_major_tick_every(scale, major_tick_every); + + TEST_ASSERT_EQUAL(major_tick_every, lv_scale_get_major_tick_every(scale)); +} + +void test_scale_label_show(void) +{ + lv_obj_t * scale = lv_scale_create(lv_screen_active()); + + bool label_show = true; + lv_scale_set_label_show(scale, label_show); + + TEST_ASSERT_EQUAL(label_show, lv_scale_get_label_show(scale)); + + label_show = false; + lv_scale_set_label_show(scale, label_show); + + TEST_ASSERT_EQUAL(label_show, lv_scale_get_label_show(scale)); +} + #endif