test add build test again, add dropdown test, integrate gcov and gvocr
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,6 +2,8 @@
|
||||
**/*bin
|
||||
**/*.swp
|
||||
**/*.swo
|
||||
**/*.gcda
|
||||
**/*.gcno
|
||||
tags
|
||||
docs/api_doc
|
||||
scripts/cppcheck_res.txt
|
||||
@@ -15,3 +17,4 @@ docs/env
|
||||
out_html
|
||||
__pycache__
|
||||
/emscripten_builder
|
||||
image_err.h
|
||||
|
||||
@@ -335,7 +335,7 @@ const char * lv_dropdown_get_options(const lv_obj_t * obj)
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
|
||||
return dropdown->options;
|
||||
return dropdown->options == NULL ? "" : dropdown->options;
|
||||
}
|
||||
|
||||
uint16_t lv_dropdown_get_selected(const lv_obj_t * obj)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
CC ?= gcc
|
||||
LVGL_DIR ?= ${shell pwd}/../..
|
||||
LVGL_DIR_NAME ?= lvgl
|
||||
OBJDIR = objs
|
||||
|
||||
WARNINGS = -Werror -Wall -Wextra \
|
||||
-Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wpointer-arith -Wuninitialized \
|
||||
@@ -15,22 +14,18 @@ WARNINGS = -Werror -Wall -Wextra \
|
||||
WARNINGS += -Wpedantic -pedantic-errors
|
||||
|
||||
#-Wno-unused-value -Wno-unused-parameter
|
||||
OPTIMIZATION ?= -O3 -g0
|
||||
OPTIMIZATION ?= -g0
|
||||
|
||||
CFLAGS ?= -I$(LVGL_DIR)/ -Iunity $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR) -I.
|
||||
CFLAGS ?= -I$(LVGL_DIR)/ --coverage -Iunity $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR) -I.
|
||||
|
||||
LDFLAGS ?= -lpng
|
||||
LDFLAGS ?= -lpng --coverage
|
||||
BIN ?= test
|
||||
|
||||
include ../lvgl.mk
|
||||
|
||||
CSRCS += ${TEST_SRC}
|
||||
CSRCS += unity/unity.c
|
||||
CSRCS += unity/unity_support.c
|
||||
CSRCS += lv_test_init.c
|
||||
CSRCS += src/test_fonts/font_1.c
|
||||
CSRCS += src/test_fonts/font_2.c
|
||||
CSRCS += src/test_fonts/font_3.c
|
||||
CSRCS := $(CSRCS) $(EXTRA_CSRCS)
|
||||
|
||||
OBJEXT ?= .o
|
||||
|
||||
@@ -46,13 +41,13 @@ OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
all: default
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
%.o: %.c
|
||||
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||
@echo "CC $<"
|
||||
# @echo "CC $<"
|
||||
|
||||
default: $(AOBJS) $(COBJS) $(MAINOBJ)
|
||||
$(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
find . -type f -name '*.o' -exec rm -f {} +
|
||||
find ../ -type f -name '*.o' -exec rm -f {} +
|
||||
rm -f $(BIN)
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
lvgldirname = os.path.abspath('..')
|
||||
lvgldirname = os.path.basename(lvgldirname)
|
||||
lvgldirname = '"' + lvgldirname + '"'
|
||||
|
||||
base_defines = '"-DLV_CONF_PATH=' + lvgldirname +'/tests/lv_test_conf.h -DLV_BUILD_TEST"'
|
||||
|
||||
def build(defines):
|
||||
global base_defines
|
||||
optimization = '"-O3 -g0"'
|
||||
|
||||
def build(defines, test_name):
|
||||
global base_defines, optimization
|
||||
|
||||
print("~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
print(test_name)
|
||||
print("~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
|
||||
d_all = base_defines[:-1] + " ";
|
||||
|
||||
for d in defines:
|
||||
d_all += " -D" + d + "=" + str(defines[d])
|
||||
|
||||
d_all += '"'
|
||||
test_file_name = test_name + ".c"
|
||||
test_file_runner_name = test_name + "_Runner.c"
|
||||
test_file_runner_name = test_file_runner_name.replace("/test_cases/", "/test_runners/")
|
||||
# -s makes it silence
|
||||
cmd = "make -s -j BIN=test.bin MAINSRC=" + test_file_name + " TEST_SRC=" + test_file_runner_name + " LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization
|
||||
cmd = "make -s -j BIN=test.bin " + "MAINSRC=lv_test_main.c LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization
|
||||
|
||||
print("")
|
||||
print("Build")
|
||||
print("-----------------------")
|
||||
# print(cmd)
|
||||
ret = os.system(cmd)
|
||||
if(ret != 0):
|
||||
print("BUILD ERROR! (error code " + str(ret) + ")")
|
||||
@@ -44,9 +38,46 @@ def build(defines, test_name):
|
||||
print("RUN ERROR! (error code " + str(ret) + ")")
|
||||
exit(1)
|
||||
|
||||
|
||||
def build_test(defines, test_name):
|
||||
global base_defines
|
||||
optimization = '"-g0"'
|
||||
|
||||
print("")
|
||||
print("Finished")
|
||||
print("")
|
||||
print("~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
print(re.search("/[a-z_]*$", test_name).group(0)[1:])
|
||||
print("~~~~~~~~~~~~~~~~~~~~~~~~")
|
||||
|
||||
d_all = base_defines[:-1] + " ";
|
||||
|
||||
for d in defines:
|
||||
d_all += " -D" + d + "=" + str(defines[d])
|
||||
|
||||
d_all += '"'
|
||||
test_file_name = test_name + ".c"
|
||||
test_file_runner_name = test_name + "_Runner.c"
|
||||
test_file_runner_name = test_file_runner_name.replace("/test_cases/", "/test_runners/")
|
||||
csrcs = " EXTRA_CSRCS=\"unity/unity.c unity/unity_support.c src/test_fonts/font_1.c src/test_fonts/font_2.c src/test_fonts/font_3.c \" "
|
||||
# -s makes it silence
|
||||
cmd = "make -s -j BIN=test.bin MAINSRC=" + test_file_name + " TEST_SRC=" + test_file_runner_name + csrcs + " LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization
|
||||
|
||||
print("")
|
||||
print("Build")
|
||||
print("-----------------------")
|
||||
# print(cmd)
|
||||
ret = os.system(cmd)
|
||||
if(ret != 0):
|
||||
print("BUILD ERROR! (error code " + str(ret) + ")")
|
||||
exit(1)
|
||||
|
||||
print("")
|
||||
print("Run")
|
||||
print("-----------------------")
|
||||
ret = os.system("./test.bin")
|
||||
if(ret != 0):
|
||||
print("RUN ERROR! (error code " + str(ret) + ")")
|
||||
exit(1)
|
||||
|
||||
def clean():
|
||||
print("")
|
||||
|
||||
@@ -56,14 +56,14 @@ minimal_16bit = {
|
||||
|
||||
}
|
||||
|
||||
minimal_16bit_swap = {
|
||||
normal_16bit_swap = {
|
||||
"LV_COLOR_DEPTH":16,
|
||||
"LV_COLOR_16_SWAP":1,
|
||||
|
||||
"LV_MEM_SIZE":64 * 1024,
|
||||
|
||||
"LV_DPI_DEF":40,
|
||||
"LV_DRAW_COMPLEX":0,
|
||||
"LV_DRAW_COMPLEX":1,
|
||||
|
||||
"LV_USE_LOG":1,
|
||||
|
||||
@@ -152,5 +152,52 @@ full_32bit = {
|
||||
|
||||
"LV_BUILD_EXAMPLES":1,
|
||||
|
||||
"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_32\\\"",
|
||||
"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_24\\\"",
|
||||
}
|
||||
|
||||
test = {
|
||||
"LV_COLOR_DEPTH":32,
|
||||
"LV_MEM_SIZE":2 * 1024 * 1024,
|
||||
|
||||
"LV_SHADOW_CACHE_SIZE":10*1024,
|
||||
"LV_IMG_CACHE_DEF_SIZE":32,
|
||||
|
||||
"LV_USE_LOG":1,
|
||||
"LV_LOG_PRINTF":1,
|
||||
"LV_USE_FONT_SUBPX": 1,
|
||||
"LV_FONT_SUBPX_BGR":1,
|
||||
|
||||
"LV_USE_ASSERT_NULL":1,
|
||||
"LV_USE_ASSERT_MALLOC":1,
|
||||
"LV_USE_ASSERT_MEM_INTEGRITY":1,
|
||||
"LV_USE_ASSERT_OBJ":1,
|
||||
"LV_USE_ASSERT_STYLE":1,
|
||||
|
||||
"LV_USE_USER_DATA": 1,
|
||||
"LV_USE_LARGE_COORD": 1,
|
||||
|
||||
"LV_FONT_MONTSERRAT_14":1,
|
||||
"LV_FONT_MONTSERRAT_16":1,
|
||||
"LV_FONT_MONTSERRAT_18":1,
|
||||
"LV_FONT_MONTSERRAT_24":1,
|
||||
"LV_FONT_MONTSERRAT_48":1,
|
||||
"LV_FONT_MONTSERRAT_12_SUBPX":1,
|
||||
"LV_FONT_MONTSERRAT_28_COMPRESSED":1,
|
||||
"LV_FONT_DEJAVU_16_PERSIAN_HEBREW":1,
|
||||
"LV_FONT_SIMSUN_16_CJK":1,
|
||||
"LV_FONT_UNSCII_8":1,
|
||||
"LV_FONT_UNSCII_16":1,
|
||||
"LV_FONT_FMT_TXT_LARGE":1,
|
||||
"LV_USE_FONT_COMPRESSED":1,
|
||||
|
||||
"LV_USE_BIDI": 1,
|
||||
"LV_USE_ARABIC_PERSIAN_CHARS":1,
|
||||
"LV_USE_PERF_MONITOR":1,
|
||||
"LV_USE_MEM_MONITOR":1,
|
||||
|
||||
"LV_LABEL_TEXT_SELECTION":1,
|
||||
|
||||
"LV_BUILD_EXAMPLES":1,
|
||||
|
||||
"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_14\\\"",
|
||||
}
|
||||
|
||||
@@ -17,14 +17,12 @@ static lv_color_t disp_buf1[HOR_RES * VER_RES];
|
||||
|
||||
void lv_test_init(void)
|
||||
{
|
||||
printf("Call lv_init...\n");
|
||||
lv_init();
|
||||
hal_init();
|
||||
}
|
||||
|
||||
void lv_test_deinit(void)
|
||||
{
|
||||
printf("Call lv_deinit...\n");
|
||||
lv_mem_deinit();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,144 +4,14 @@
|
||||
|
||||
#if LV_BUILD_TEST && !defined(LV_BUILD_TEST_NO_MAIN)
|
||||
#include <sys/time.h>
|
||||
|
||||
#define HOR_RES 800
|
||||
#define VER_RES 480
|
||||
|
||||
static void hal_init(void);
|
||||
static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
|
||||
|
||||
lv_color_t test_fb[HOR_RES * VER_RES];
|
||||
#include "lv_test_init.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("Call lv_init...\n");
|
||||
lv_init();
|
||||
|
||||
hal_init();
|
||||
|
||||
lv_test_core();
|
||||
// lv_test_label();
|
||||
lv_test_init();
|
||||
|
||||
printf("Exit with success!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void * open_cb(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
|
||||
{
|
||||
(void) drv;
|
||||
(void) mode;
|
||||
|
||||
FILE * fp = fopen(path, "rb"); // only reading is supported
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
static lv_fs_res_t close_cb(lv_fs_drv_t * drv, void * file_p)
|
||||
{
|
||||
(void) drv;
|
||||
|
||||
fclose(file_p);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
static lv_fs_res_t read_cb(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||
{
|
||||
(void) drv;
|
||||
|
||||
*br = fread(buf, 1, btr, file_p);
|
||||
return (*br <= 0) ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
static lv_fs_res_t seek_cb(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t w)
|
||||
{
|
||||
(void) drv;
|
||||
|
||||
uint32_t w2;
|
||||
switch(w) {
|
||||
case LV_FS_SEEK_SET:
|
||||
w2 = SEEK_SET;
|
||||
break;
|
||||
case LV_FS_SEEK_CUR:
|
||||
w2 = SEEK_CUR;
|
||||
break;
|
||||
case LV_FS_SEEK_END:
|
||||
w2 = SEEK_END;
|
||||
break;
|
||||
default:
|
||||
w2 = SEEK_SET;
|
||||
}
|
||||
|
||||
fseek (file_p, pos, w2);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
static lv_fs_res_t tell_cb(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
|
||||
{
|
||||
(void) drv;
|
||||
|
||||
*pos_p = ftell(file_p);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
static void hal_init(void)
|
||||
{
|
||||
static lv_disp_draw_buf_t draw_buf;
|
||||
lv_color_t * disp_buf1 = (lv_color_t *)malloc(LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t));
|
||||
|
||||
lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, LV_HOR_RES * LV_VER_RES);
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.draw_buf = &draw_buf;
|
||||
disp_drv.flush_cb = dummy_flush_cb;
|
||||
disp_drv.hor_res = HOR_RES;
|
||||
disp_drv.ver_res = VER_RES;
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
static lv_fs_drv_t drv;
|
||||
lv_fs_drv_init(&drv); /*Basic initialization*/
|
||||
|
||||
drv.letter = 'F'; /*An uppercase letter to identify the drive*/
|
||||
drv.open_cb = open_cb; /*Callback to open a file*/
|
||||
drv.close_cb = close_cb; /*Callback to close a file*/
|
||||
drv.read_cb = read_cb; /*Callback to read a file*/
|
||||
drv.seek_cb = seek_cb; /*Callback to seek in a file (Move cursor)*/
|
||||
drv.tell_cb = tell_cb; /*Callback to tell the cursor position*/
|
||||
|
||||
lv_fs_drv_register(&drv); /*Finally register the drive*/
|
||||
}
|
||||
#include <stdio.h>
|
||||
|
||||
static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
||||
{
|
||||
LV_UNUSED(area);
|
||||
LV_UNUSED(color_p);
|
||||
|
||||
memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));
|
||||
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
uint32_t custom_tick_get(void)
|
||||
{
|
||||
static uint64_t start_ms = 0;
|
||||
if(start_ms == 0) {
|
||||
struct timeval tv_start;
|
||||
gettimeofday(&tv_start, NULL);
|
||||
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
|
||||
}
|
||||
|
||||
struct timeval tv_now;
|
||||
gettimeofday(&tv_now, NULL);
|
||||
uint64_t now_ms;
|
||||
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
|
||||
|
||||
uint32_t time_ms = now_ms - start_ms;
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,21 +3,47 @@
|
||||
import defines
|
||||
import build
|
||||
import test
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
files = test.prepare()
|
||||
|
||||
def build_conf(title, defs):
|
||||
print("")
|
||||
print("")
|
||||
print("============================================")
|
||||
print("Full config, 32 bit color depth")
|
||||
print(title)
|
||||
print("============================================")
|
||||
print("")
|
||||
|
||||
build.clean()
|
||||
build.build(defs)
|
||||
|
||||
|
||||
test_only = False;
|
||||
test_report = False;
|
||||
test_noclean = False;
|
||||
if "test" in sys.argv: test_only = True;
|
||||
if "report" in sys.argv: test_report = True;
|
||||
if "noclean" in sys.argv: test_noclean = True;
|
||||
|
||||
if not test_only:
|
||||
build_conf("Minimal config monochrome", defines.minimal_monochrome)
|
||||
build_conf("Minimal config, 16 bit color depth", defines.minimal_16bit)
|
||||
build_conf("Normal config, 16 bit color depth swapped", defines.normal_16bit_swap)
|
||||
build_conf("Full config, 32 bit color depth", defines.full_32bit)
|
||||
|
||||
|
||||
files = test.prepare()
|
||||
if test_noclean == False:
|
||||
build.clean()
|
||||
|
||||
for f in files:
|
||||
name = f[:-2] #test_foo.c -> test_foo
|
||||
build.build(defines.full_32bit, name)
|
||||
build.build_test(defines.test, name)
|
||||
|
||||
if test_report:
|
||||
print("")
|
||||
print("Generating report")
|
||||
print("-----------------------")
|
||||
os.system("gcovr -r ../ --html-details -o report/index.html --exclude-directories '\.\./examples' --exclude-directories 'src/.*' --exclude-directories 'unity' --exclude 'lv_test_.*\.c'")
|
||||
print("Done: See report/index.html")
|
||||
|
||||
#build("Minimal config monochrome", minimal_monochrome)
|
||||
#build.build("Minimal config, 16 bit color depth", defines.minimal_16bit, "test_obj_tree")
|
||||
#build("Minimal config, 16 bit color depth swapped", minimal_16bit_swap)
|
||||
#build("Full config, 32 bit color depth", full_32bit)
|
||||
|
||||
BIN
tests/ref_imgs/dropdown_1.png
Normal file
BIN
tests/ref_imgs/dropdown_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
13
tests/src/test_cases/_test_template.c
Normal file
13
tests/src/test_cases/_test_template.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "../lvgl.h"
|
||||
#if LV_BUILD_TEST
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void test_func_1(void);
|
||||
|
||||
void test_func_1(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(actual, expected);
|
||||
}
|
||||
|
||||
#endif
|
||||
19
tests/src/test_cases/test_config.c
Normal file
19
tests/src/test_cases/test_config.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "../lvgl.h"
|
||||
#if LV_BUILD_TEST
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void test_config(void);
|
||||
|
||||
void test_config(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(130, LV_DPI_DEF);
|
||||
TEST_ASSERT_EQUAL(130, lv_disp_get_dpi(NULL));
|
||||
TEST_ASSERT_EQUAL(800, LV_HOR_RES);
|
||||
TEST_ASSERT_EQUAL(800, lv_disp_get_hor_res(NULL));
|
||||
TEST_ASSERT_EQUAL(480, LV_VER_RES);
|
||||
TEST_ASSERT_EQUAL(480, lv_disp_get_ver_res(NULL));
|
||||
TEST_ASSERT_EQUAL(32, LV_COLOR_DEPTH);
|
||||
}
|
||||
|
||||
#endif
|
||||
170
tests/src/test_cases/test_dropdown.c
Normal file
170
tests/src/test_cases/test_dropdown.c
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "../lvgl.h"
|
||||
#if LV_BUILD_TEST
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void test_dropdown_create_delete(void);
|
||||
void test_dropdown_set_text_and_symbol(void);
|
||||
void test_dropdown_set_options(void);
|
||||
void test_dropdown_select(void);
|
||||
void test_dropdown_render(void);
|
||||
|
||||
void test_dropdown_create_delete(void)
|
||||
{
|
||||
lv_dropdown_create(lv_scr_act());
|
||||
TEST_ASSERT_EQUAL(1, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
|
||||
lv_obj_t * dd2 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd2, 200, 0);
|
||||
TEST_ASSERT_EQUAL(2, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
lv_dropdown_open(dd2);
|
||||
TEST_ASSERT_EQUAL(3, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd2));
|
||||
lv_dropdown_open(dd2); /*Try to pen again*/
|
||||
TEST_ASSERT_EQUAL(3, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
|
||||
lv_obj_t * dd3 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd3, 400, 0);
|
||||
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
lv_dropdown_open(dd3);
|
||||
TEST_ASSERT_EQUAL(5, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
lv_dropdown_close(dd3);
|
||||
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
lv_dropdown_close(dd3); /*Try to close again*/
|
||||
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
|
||||
lv_obj_del(dd2);
|
||||
TEST_ASSERT_EQUAL(2, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
|
||||
lv_obj_clean(lv_scr_act());
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_child_cnt(lv_scr_act()));
|
||||
|
||||
}
|
||||
|
||||
void test_dropdown_set_text_and_symbol(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, 0);
|
||||
}
|
||||
|
||||
void test_dropdown_set_options(void)
|
||||
{
|
||||
|
||||
lv_mem_monitor_t m1;
|
||||
lv_mem_monitor(&m1);
|
||||
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
TEST_ASSERT_EQUAL_STRING("Option 1\nOption 2\nOption 3", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(3, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_set_options(dd1, "a1\nb2\nc3\nd4\ne5\nf6");
|
||||
TEST_ASSERT_EQUAL_STRING("a1\nb2\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(6, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_obj_set_width(dd1, 200);
|
||||
lv_dropdown_open(dd1);
|
||||
lv_obj_update_layout(dd1);
|
||||
TEST_ASSERT_EQUAL(200, lv_obj_get_width(lv_dropdown_get_list(dd1)));
|
||||
|
||||
lv_dropdown_close(dd1);
|
||||
|
||||
lv_dropdown_add_option(dd1, "x0", 0);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(7, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_add_option(dd1, "y0", 3);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\ny0\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(8, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_add_option(dd1, "z0", LV_DROPDOWN_POS_LAST);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\ny0\nc3\nd4\ne5\nf6\nz0", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(9, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_clear_options(dd1);
|
||||
TEST_ASSERT_EQUAL_STRING("", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(0, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_set_options(dd1, "o1\no2"); /*Just to add some content before lv_dropdown_set_options_static*/
|
||||
|
||||
lv_dropdown_set_options_static(dd1, "a1\nb2\nc3\nd4\ne5\nf6");
|
||||
TEST_ASSERT_EQUAL_STRING("a1\nb2\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(6, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_add_option(dd1, "x0", 0);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(7, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_add_option(dd1, "y0", 3);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\ny0\nc3\nd4\ne5\nf6", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(8, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_add_option(dd1, "z0", LV_DROPDOWN_POS_LAST);
|
||||
TEST_ASSERT_EQUAL_STRING("x0\na1\nb2\ny0\nc3\nd4\ne5\nf6\nz0", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(9, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_dropdown_clear_options(dd1);
|
||||
TEST_ASSERT_EQUAL_STRING("", lv_dropdown_get_options(dd1));
|
||||
TEST_ASSERT_EQUAL(0, lv_dropdown_get_option_cnt(dd1));
|
||||
|
||||
lv_obj_del(dd1);
|
||||
|
||||
lv_mem_monitor_t m2;
|
||||
lv_mem_monitor(&m2);
|
||||
TEST_ASSERT_UINT32_WITHIN(48, m1.free_size, m2.free_size);
|
||||
}
|
||||
|
||||
void test_dropdown_select(void)
|
||||
{
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_selected(dd1, 2);
|
||||
|
||||
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
|
||||
|
||||
char buf[32];
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
lv_dropdown_get_selected_str(dd1, buf, sizeof(buf));
|
||||
TEST_ASSERT_EQUAL_STRING("Option 3", buf);
|
||||
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
lv_dropdown_get_selected_str(dd1, buf, 4);
|
||||
TEST_ASSERT_EQUAL_STRING("Opt", buf);
|
||||
|
||||
/*Out of range*/
|
||||
lv_dropdown_set_selected(dd1, 3);
|
||||
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
|
||||
}
|
||||
|
||||
void test_dropdown_render(void)
|
||||
{
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd1, 10, 10);
|
||||
lv_dropdown_set_selected(dd1, 1);
|
||||
|
||||
lv_obj_t * dd2 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd2, 200, 10);
|
||||
lv_obj_set_width(dd2, 200);
|
||||
lv_dropdown_set_selected(dd2, 2);
|
||||
lv_dropdown_open(dd2);
|
||||
|
||||
lv_obj_t * dd3 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_style_pad_hor(dd3, 5, 0);
|
||||
lv_obj_set_style_pad_ver(dd3, 20, 0);
|
||||
lv_obj_set_pos(dd3, 500, 150);
|
||||
lv_dropdown_set_selected(dd3, 2);
|
||||
lv_dropdown_set_dir(dd3, LV_DIR_LEFT);
|
||||
lv_dropdown_set_symbol(dd3, LV_SYMBOL_LEFT);
|
||||
lv_dropdown_set_options(dd3, "a0\na1\na2\na3\na4\na5\na6\na7\na8\na9\na10\na11\na12\na13\na14\na15\na16");
|
||||
lv_dropdown_open(dd3);
|
||||
lv_dropdown_set_selected(dd3, 3);
|
||||
lv_obj_t * list = lv_dropdown_get_list(dd3);
|
||||
lv_obj_set_style_text_line_space(list, 5, 0);
|
||||
lv_obj_set_style_bg_color(list, lv_color_hex3(0xf00), LV_PART_SELECTED | LV_STATE_CHECKED);
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_1.png");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -33,7 +33,7 @@ void test_obj_tree_2(void)
|
||||
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x112233), 0);
|
||||
lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, 0);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("scr1.png")
|
||||
//TEST_ASSERT_EQUAL_SCREENSHOT("scr1.png")
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
13
tests/src/test_cases/test_style.c
Normal file
13
tests/src/test_cases/test_style.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "../lvgl.h"
|
||||
#if LV_BUILD_TEST
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
//void test_func_1(void);
|
||||
|
||||
//void test_func_1(void)
|
||||
//{
|
||||
// TEST_ASSERT_EQUAL(actual, expected);
|
||||
//}
|
||||
|
||||
#endif
|
||||
@@ -5,6 +5,16 @@ def prepare():
|
||||
os.system("rm src/test_runners/test_*_Runner.c")
|
||||
os.system("rm src/*.o")
|
||||
files = glob.glob("./src/test_cases/test_*.c")
|
||||
|
||||
for index, item in enumerate(files):
|
||||
if item == "./src/test_cases/test_config.c":
|
||||
files.pop(index)
|
||||
break
|
||||
|
||||
files.insert(0, "./src/test_cases/test_config.c")
|
||||
print(files)
|
||||
|
||||
|
||||
for f in files:
|
||||
r = f[:-2] + "_Runner.c"
|
||||
r = r.replace("/test_cases/", "/test_runners/")
|
||||
|
||||
@@ -63,7 +63,6 @@ static void png_release(png_img_t * p);
|
||||
|
||||
bool lv_test_assert_img_eq(const char * fn_ref)
|
||||
{
|
||||
|
||||
char fn_ref_full[512];
|
||||
sprintf(fn_ref_full, "%s%s", REF_IMGS_PATH, fn_ref);
|
||||
|
||||
@@ -86,15 +85,21 @@ bool lv_test_assert_img_eq(const char * fn_ref)
|
||||
int x, y, i_buf = 0;
|
||||
for (y = 0; y < p.height; y++) {
|
||||
png_byte* row = p.row_pointers[y];
|
||||
//printf("\n");
|
||||
|
||||
for (x = 0; x < p.width; x++) {
|
||||
ptr_ref = &(row[x*3]);
|
||||
ptr_act = &(screen_buf[i_buf*4]);
|
||||
|
||||
uint8_t tmp = ptr_act[0];
|
||||
ptr_act[0] = ptr_act[2];
|
||||
ptr_act[2] = tmp;
|
||||
uint32_t ref_px = 0;
|
||||
uint32_t act_px = 0;
|
||||
memcpy(&ref_px, ptr_ref, 3);
|
||||
memcpy(&act_px, ptr_act, 3);
|
||||
//printf("0xFF%06x, ", act_px);
|
||||
|
||||
if(memcmp(ptr_act, ptr_ref, 3) != 0) {
|
||||
uint8_t act_swap[3] = {ptr_act[2], ptr_act[1], ptr_act[0]};
|
||||
|
||||
if(memcmp(act_swap, ptr_ref, 3) != 0) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
@@ -111,6 +116,39 @@ bool lv_test_assert_img_eq(const char * fn_ref)
|
||||
memcpy(&ref_px, ptr_ref, 3);
|
||||
memcpy(&act_px, ptr_act, 3);
|
||||
TEST_PRINTF("Diff in %s at (%d;%d), %x instead of %x)", fn_ref, x, y, act_px, ref_px);
|
||||
|
||||
FILE * f = fopen("../image_err.h", "w");
|
||||
|
||||
fprintf(f, "static const uint32_t img_data[] = {\n");
|
||||
|
||||
i_buf = 0;
|
||||
for (y = 0; y < 480; y++) {
|
||||
fprintf(f, "\n");
|
||||
for (x = 0; x < 800; x++) {
|
||||
ptr_act = &(screen_buf[i_buf * 4]);
|
||||
act_px = 0;
|
||||
memcpy(&act_px, ptr_act, 3);
|
||||
fprintf(f, "0xFF%06X, ", act_px);
|
||||
i_buf++;
|
||||
}
|
||||
}
|
||||
fprintf(f, "};\n\n");
|
||||
|
||||
fprintf(f, "static lv_img_dsc_t dsc = { \n"
|
||||
" .header.w = 800,\n"
|
||||
" .header.h = 480,\n"
|
||||
" .header.always_zero = 0,\n"
|
||||
" .header.cf = LV_IMG_CF_TRUE_COLOR,\n"
|
||||
" .data_size = 800 * 480 * 4,\n"
|
||||
" .data = img_data};\n\n"
|
||||
"static inline void show_test_img_error(void)\n"
|
||||
"{\n"
|
||||
" lv_obj_t * img = lv_img_create(lv_scr_act());\n"
|
||||
" lv_img_set_src(img, &dsc);\n"
|
||||
"}\n");
|
||||
|
||||
fclose(f);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user