Skip to content

Commit

Permalink
test(scale): Add tests for some properties
Browse files Browse the repository at this point in the history
  • Loading branch information
C47D committed Dec 24, 2023
1 parent c57231e commit 62a2649
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/widgets/scale/lv_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*====================*/
Expand Down
28 changes: 28 additions & 0 deletions src/widgets/scale/lv_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
**********************/
Expand Down
45 changes: 45 additions & 0 deletions tests/src/test_cases/widgets/test_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 62a2649

Please sign in to comment.