diff --git a/src/widgets/list/lv_list.h b/src/widgets/list/lv_list.h index 036f92fdc..7e789185a 100644 --- a/src/widgets/list/lv_list.h +++ b/src/widgets/list/lv_list.h @@ -32,12 +32,36 @@ extern const lv_obj_class_t lv_list_btn_class; * GLOBAL PROTOTYPES **********************/ +/** + * Create a list object + * @param parent pointer to an object, it will be the parent of the new list + * @return pointer to the created list + */ lv_obj_t * lv_list_create(lv_obj_t * parent); +/** + * Add text to a list + * @param list pointer to a list, it will be the parent of the new label + * @param txt Text of the new label + * @return pointer to the created label + */ lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt); +/** + * Add button to a list + * @param list pointer to a list, it will be the parent of the new button + * @param icon icon for the button, when NULL it will have no icon + * @param txt Text of the new button, when NULL no text will be added + * @return pointer to the created button + */ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * icon, const char * txt); +/** + * Get text of a given list button + * @param list pointer to a list + * @param btn pointer to the button + * @return Text of btn, if btn doesn't have text "" will be returned + */ const char * lv_list_get_btn_text(lv_obj_t * list, lv_obj_t * btn); /********************** diff --git a/tests/ref_imgs/list_1.png b/tests/ref_imgs/list_1.png new file mode 100644 index 000000000..585fd08e9 Binary files /dev/null and b/tests/ref_imgs/list_1.png differ diff --git a/tests/src/test_cases/test_list.c b/tests/src/test_cases/test_list.c new file mode 100644 index 000000000..628ce1770 --- /dev/null +++ b/tests/src/test_cases/test_list.c @@ -0,0 +1,64 @@ +#if LV_BUILD_TEST +#include "../lvgl.h" + +#include "unity/unity.h" + +static lv_obj_t * list; + +void setUp(void) +{ + list = lv_list_create(lv_scr_act()); +} + +void tearDown(void) +{ + +} + +void test_list_get_text_from_added_button(void) +{ + const char * message = "LVGL Rocks!"; + lv_obj_t * button_ok = lv_list_add_btn(list, LV_SYMBOL_OK, message); + + TEST_ASSERT_EQUAL_STRING(message, lv_list_get_btn_text(list, button_ok)); +} + +void test_list_get_text_from_button_without_symbol(void) +{ + const char * message = "LVGL Rocks!"; + lv_obj_t * button_ok = lv_list_add_btn(list, NULL, message); + + TEST_ASSERT_EQUAL_STRING(message, lv_list_get_btn_text(list, button_ok)); +} + +void test_list_gets_empty_text_from_button_without_text(void) +{ + const char * empty_text = ""; + lv_obj_t * button_ok = lv_list_add_btn(list, NULL, NULL); + + TEST_ASSERT_EQUAL_STRING(empty_text, lv_list_get_btn_text(list, button_ok)); +} + +void test_list_get_text_from_label(void) +{ + const char * message = "LVGL Rocks!"; + lv_obj_t * label = lv_list_add_text(list, message); + + TEST_ASSERT_EQUAL_STRING(message, lv_label_get_text(label)); +} + +void test_list_snapshot(void) +{ + lv_obj_t * snapshot_list = lv_list_create(lv_scr_act()); + + lv_list_add_text(snapshot_list, "File"); + lv_list_add_btn(snapshot_list, LV_SYMBOL_FILE, "New"); + lv_list_add_btn(snapshot_list, LV_SYMBOL_DIRECTORY, "Open"); + lv_list_add_btn(snapshot_list, LV_SYMBOL_SAVE, "Save"); + + lv_obj_center(snapshot_list); + + TEST_ASSERT_EQUAL_SCREENSHOT("list_1.png"); +} + +#endif