ci(test): add unit test for lv_list (#4032)

This commit is contained in:
Carlos Diaz
2023-03-04 10:02:08 -06:00
committed by GitHub
parent 7854d55046
commit 67941f4964
3 changed files with 88 additions and 0 deletions

View File

@@ -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);
/**********************

BIN
tests/ref_imgs/list_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -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