mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-24 02:03:53 +08:00
ci(span): add unit test (#4595)
This commit is contained in:
parent
f751ad3c5e
commit
0b66468f2f
@ -99,7 +99,7 @@ too.
|
||||
lines
|
||||
-----
|
||||
|
||||
Use :cpp:expr:`lv_spangroup_set_lines(spangroup, 10)` to set the maximum number
|
||||
Use :cpp:expr:`lv_spangroup_set_max_lines(spangroup, 10)` to set the maximum number
|
||||
of lines to be displayed in LV_SPAN_MODE_BREAK mode, negative values
|
||||
indicate no limit.
|
||||
|
||||
|
@ -210,7 +210,7 @@ void lv_spangroup_set_overflow(lv_obj_t * obj, lv_span_overflow_t overflow)
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
|
||||
if(spans->overflow == overflow) return;
|
||||
|
||||
if(overflow >= _LV_SPAN_OVERFLOW_LAST) return;
|
||||
spans->overflow = overflow;
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
@ -230,11 +230,14 @@ void lv_spangroup_set_mode(lv_obj_t * obj, lv_span_mode_t mode)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
|
||||
|
||||
if(mode >= _LV_SPAN_MODE_LAST) return;
|
||||
|
||||
spans->mode = mode;
|
||||
lv_spangroup_refr_mode(obj);
|
||||
}
|
||||
|
||||
void lv_spangroup_set_lines(lv_obj_t * obj, int32_t lines)
|
||||
void lv_spangroup_set_max_lines(lv_obj_t * obj, int32_t lines)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
|
||||
@ -322,7 +325,7 @@ lv_span_mode_t lv_spangroup_get_mode(lv_obj_t * obj)
|
||||
return spans->mode;
|
||||
}
|
||||
|
||||
int32_t lv_spangroup_get_lines(lv_obj_t * obj)
|
||||
int32_t lv_spangroup_get_max_lines(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
|
||||
|
@ -30,6 +30,7 @@ extern "C" {
|
||||
enum _lv_span_overflow_t {
|
||||
LV_SPAN_OVERFLOW_CLIP,
|
||||
LV_SPAN_OVERFLOW_ELLIPSIS,
|
||||
_LV_SPAN_OVERFLOW_LAST, /**< Fence member*/
|
||||
};
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@ -42,6 +43,7 @@ enum _lv_span_mode_t {
|
||||
LV_SPAN_MODE_FIXED, /**< fixed the obj size*/
|
||||
LV_SPAN_MODE_EXPAND, /**< Expand the object size to the text size*/
|
||||
LV_SPAN_MODE_BREAK, /**< Keep width, break the too long lines and expand height*/
|
||||
_LV_SPAN_MODE_LAST /**< Fence member*/
|
||||
};
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@ -149,11 +151,11 @@ void lv_spangroup_set_indent(lv_obj_t * obj, lv_coord_t indent);
|
||||
void lv_spangroup_set_mode(lv_obj_t * obj, lv_span_mode_t mode);
|
||||
|
||||
/**
|
||||
* Set lines of the spangroup.
|
||||
* Set maximum lines of the spangroup.
|
||||
* @param obj pointer to a spangroup object.
|
||||
* @param lines max lines that can be displayed in LV_SPAN_MODE_BREAK mode. < 0 means no limit.
|
||||
*/
|
||||
void lv_spangroup_set_lines(lv_obj_t * obj, int32_t lines);
|
||||
void lv_spangroup_set_max_lines(lv_obj_t * obj, int32_t lines);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@ -208,11 +210,11 @@ lv_coord_t lv_spangroup_get_indent(lv_obj_t * obj);
|
||||
lv_span_mode_t lv_spangroup_get_mode(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* get lines of the spangroup.
|
||||
* get maximum lines of the spangroup.
|
||||
* @param obj pointer to a spangroup object.
|
||||
* @return the lines value.
|
||||
* @return the max lines value.
|
||||
*/
|
||||
int32_t lv_spangroup_get_lines(lv_obj_t * obj);
|
||||
int32_t lv_spangroup_get_max_lines(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* get max line height of all span in the spangroup.
|
||||
|
BIN
tests/ref_imgs/span_01.png
Normal file
BIN
tests/ref_imgs/span_01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
BIN
tests/ref_imgs/span_02.png
Normal file
BIN
tests/ref_imgs/span_02.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
BIN
tests/ref_imgs/span_03.png
Normal file
BIN
tests/ref_imgs/span_03.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
BIN
tests/ref_imgs/span_04.png
Normal file
BIN
tests/ref_imgs/span_04.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
tests/ref_imgs/span_05.png
Normal file
BIN
tests/ref_imgs/span_05.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
279
tests/src/test_cases/test_span.c
Normal file
279
tests/src/test_cases/test_span.c
Normal file
@ -0,0 +1,279 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
static lv_obj_t * spangroup = NULL;
|
||||
static lv_obj_t * active_screen = NULL;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
spangroup = lv_spangroup_create(NULL);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
lv_obj_del(spangroup);
|
||||
|
||||
if(active_screen) {
|
||||
lv_obj_clean(active_screen);
|
||||
}
|
||||
|
||||
spangroup = NULL;
|
||||
active_screen = NULL;
|
||||
}
|
||||
|
||||
void test_spangroup_create_returns_not_null_object(void)
|
||||
{
|
||||
lv_obj_t * obj = lv_spangroup_create(NULL);
|
||||
|
||||
TEST_ASSERT(NULL != obj);
|
||||
}
|
||||
|
||||
void test_spangroup_new_span_with_null_parameter_returns_null_object(void)
|
||||
{
|
||||
lv_span_t * span = lv_spangroup_new_span(NULL);
|
||||
|
||||
TEST_ASSERT(NULL == span);
|
||||
TEST_ASSERT_EQUAL_INT(0, lv_spangroup_get_child_cnt(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_new_span_with_valid_parameter_returns_not_null_object(void)
|
||||
{
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
TEST_ASSERT(NULL != span);
|
||||
TEST_ASSERT_EQUAL_INT(1, lv_spangroup_get_child_cnt(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_del_span_span_is_null(void)
|
||||
{
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_spangroup_del_span(spangroup, span);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, lv_spangroup_get_child_cnt(spangroup));
|
||||
}
|
||||
|
||||
void test_span_set_text(void)
|
||||
{
|
||||
const char * test_text = "Test Text";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_span_set_text(span, test_text);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, test_text);
|
||||
}
|
||||
|
||||
void test_span_set_text_with_bad_parameter_no_action_performed(void)
|
||||
{
|
||||
const char * test_text = "Test Text";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_span_set_text(span, test_text);
|
||||
lv_span_set_text(span, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, test_text);
|
||||
}
|
||||
|
||||
void test_span_set_text_with_previous_test_overwrites(void)
|
||||
{
|
||||
const char * old_test_text = "Old Test Text";
|
||||
const char * new_test_text = "New Test Text and it is longer";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_span_set_text(span, old_test_text);
|
||||
lv_span_set_text(span, new_test_text);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, new_test_text);
|
||||
}
|
||||
|
||||
void test_span_set_text_static(void)
|
||||
{
|
||||
const char * test_text = "Test Text";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_span_set_text_static(span, test_text);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, test_text);
|
||||
}
|
||||
|
||||
void test_span_set_text_static_with_bad_parameter_no_action_performed(void)
|
||||
{
|
||||
const char * test_text = "Test Text";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
|
||||
lv_span_set_text_static(span, test_text);
|
||||
lv_span_set_text_static(span, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, test_text);
|
||||
}
|
||||
|
||||
void test_span_set_text_static_with_previous_text_overwrites(void)
|
||||
{
|
||||
const char * old_test_text = "Old Test Text";
|
||||
const char * new_test_text = "New Test Text and it is longer";
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
lv_span_set_text_static(span, old_test_text);
|
||||
lv_span_set_text_static(span, new_test_text);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(span->txt, new_test_text);
|
||||
}
|
||||
|
||||
void test_spangroup_set_align(void)
|
||||
{
|
||||
const lv_text_align_t align = LV_TEXT_ALIGN_CENTER;
|
||||
lv_spangroup_set_align(spangroup, align);
|
||||
|
||||
TEST_ASSERT_EQUAL(align, lv_spangroup_get_align(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_overflow(void)
|
||||
{
|
||||
const lv_span_overflow_t overflow = LV_SPAN_OVERFLOW_ELLIPSIS;
|
||||
lv_spangroup_set_overflow(spangroup, overflow);
|
||||
|
||||
TEST_ASSERT_EQUAL(overflow, lv_spangroup_get_overflow(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_overflow_invalid_parameters_overflow_not_changed(void)
|
||||
{
|
||||
lv_spangroup_set_overflow(spangroup, LV_SPAN_OVERFLOW_ELLIPSIS);
|
||||
lv_spangroup_set_overflow(spangroup, _LV_SPAN_OVERFLOW_LAST);
|
||||
|
||||
TEST_ASSERT_EQUAL(LV_SPAN_OVERFLOW_ELLIPSIS, lv_spangroup_get_overflow(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_indent(void)
|
||||
{
|
||||
const lv_coord_t indent = 100;
|
||||
|
||||
lv_spangroup_set_indent(spangroup, indent);
|
||||
|
||||
TEST_ASSERT_EQUAL(indent, lv_spangroup_get_indent(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_mode(void)
|
||||
{
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_EXPAND);
|
||||
TEST_ASSERT_EQUAL(LV_SPAN_MODE_EXPAND, lv_spangroup_get_mode(spangroup));
|
||||
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK);
|
||||
TEST_ASSERT_EQUAL(LV_SPAN_MODE_BREAK, lv_spangroup_get_mode(spangroup));
|
||||
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_FIXED);
|
||||
TEST_ASSERT_EQUAL(LV_SPAN_MODE_FIXED, lv_spangroup_get_mode(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_mode_invalid_parameter_mode_not_changed(void)
|
||||
{
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_EXPAND);
|
||||
lv_spangroup_set_mode(spangroup, _LV_SPAN_MODE_LAST);
|
||||
TEST_ASSERT_EQUAL(LV_SPAN_MODE_EXPAND, lv_spangroup_get_mode(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_set_max_lines(void)
|
||||
{
|
||||
const int32_t lines = 100;
|
||||
|
||||
lv_spangroup_set_max_lines(spangroup, lines);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(lines, lv_spangroup_get_max_lines(spangroup));
|
||||
}
|
||||
|
||||
void test_spangroup_get_max_lines_for_new_span_group(void)
|
||||
{
|
||||
int32_t lines;
|
||||
|
||||
lines = lv_spangroup_get_max_lines(spangroup);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(-1, lines);
|
||||
|
||||
lines = 3;
|
||||
lv_spangroup_set_max_lines(spangroup, lines);
|
||||
lines = lv_spangroup_get_max_lines(spangroup);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(3, lines);
|
||||
}
|
||||
|
||||
void test_spangroup_get_max_line_h(void)
|
||||
{
|
||||
lv_coord_t max_line;
|
||||
|
||||
max_line = lv_spangroup_get_max_line_h(spangroup);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, (uint32_t)max_line);
|
||||
|
||||
(void)lv_spangroup_new_span(spangroup);
|
||||
max_line = lv_spangroup_get_max_line_h(spangroup);
|
||||
|
||||
// TODO: find out why this magic numberdd
|
||||
TEST_ASSERT_EQUAL(16, (uint32_t)max_line);
|
||||
}
|
||||
|
||||
void test_spangroup_draw(void)
|
||||
{
|
||||
active_screen = lv_scr_act();
|
||||
spangroup = lv_spangroup_create(active_screen);
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK);
|
||||
lv_obj_set_width(spangroup, 100);
|
||||
lv_span_t * span_1 = lv_spangroup_new_span(spangroup);
|
||||
lv_span_t * span_2 = lv_spangroup_new_span(spangroup);
|
||||
lv_span_set_text(span_1, "This text is over 100 pixels width");
|
||||
lv_span_set_text(span_2, "This text is also over 100 pixels width");
|
||||
lv_style_set_text_decor(&span_2->style, LV_TEXT_DECOR_STRIKETHROUGH);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("span_02.png");
|
||||
|
||||
lv_spangroup_set_align(spangroup, LV_TEXT_ALIGN_CENTER);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("span_03.png");
|
||||
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_EXPAND);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("span_04.png");
|
||||
|
||||
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_FIXED);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("span_05.png");
|
||||
}
|
||||
|
||||
void test_spangroup_get_child(void)
|
||||
{
|
||||
const int32_t span_1_idx = 0;
|
||||
const int32_t span_2_idx = 1;
|
||||
lv_span_t * span_1 = lv_spangroup_new_span(spangroup);
|
||||
lv_span_t * span_2 = lv_spangroup_new_span(spangroup);
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(span_2, lv_spangroup_get_child(spangroup, span_2_idx));
|
||||
TEST_ASSERT_EQUAL_PTR(span_1, lv_spangroup_get_child(spangroup, span_1_idx));
|
||||
}
|
||||
|
||||
void test_spangroup_get_child_cnt(void)
|
||||
{
|
||||
(void)lv_spangroup_new_span(spangroup);
|
||||
(void)lv_spangroup_new_span(spangroup);
|
||||
|
||||
const uint32_t cnt = lv_spangroup_get_child_cnt(spangroup);
|
||||
|
||||
TEST_ASSERT_EQUAL(2, cnt);
|
||||
}
|
||||
|
||||
void test_spangroup_get_expand_width(void)
|
||||
{
|
||||
const uint32_t experimental_size = 232;
|
||||
const uint32_t constrained_size = 232;
|
||||
active_screen = lv_scr_act();
|
||||
|
||||
spangroup = lv_spangroup_create(active_screen);
|
||||
lv_span_t * span = lv_spangroup_new_span(spangroup);
|
||||
lv_span_set_text(span, "This text is over 100 pixels width");
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(experimental_size,
|
||||
lv_spangroup_get_expand_width(spangroup, UINT32_MAX));
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(constrained_size,
|
||||
lv_spangroup_get_expand_width(spangroup, experimental_size));
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user