forked from xuos/xiuos
resubmit the lvgl code
This commit is contained in:
26
APP_Framework/lib/lvgl/tests/src/test_cases/_test_template.c
Normal file
26
APP_Framework/lib/lvgl/tests/src/test_cases/_test_template.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void setUp(void);
|
||||
void tearDown(void);
|
||||
|
||||
void test_func_1(void);
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
/* Function run before every test */
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Function run after every test */
|
||||
}
|
||||
|
||||
void test_func_1(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(actual, expected);
|
||||
}
|
||||
|
||||
#endif
|
||||
167
APP_Framework/lib/lvgl/tests/src/test_cases/test_arc.c
Normal file
167
APP_Framework/lib/lvgl/tests/src/test_cases/test_arc.c
Normal file
@@ -0,0 +1,167 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
#include "lv_test_indev.h"
|
||||
|
||||
/* This function runs before each test */
|
||||
void setUp(void);
|
||||
|
||||
void test_arc_creation_successfull(void);
|
||||
void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void);
|
||||
void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void);
|
||||
void test_arc_should_update_value_after_updating_range(void);
|
||||
void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void);
|
||||
void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void);
|
||||
void test_arc_angles_when_reversed(void);
|
||||
|
||||
static lv_obj_t *active_screen = NULL;
|
||||
static lv_obj_t *arc = NULL;
|
||||
static uint32_t event_cnt;
|
||||
|
||||
static void dummy_event_cb(lv_event_t * e);
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
active_screen = lv_scr_act();
|
||||
}
|
||||
|
||||
void test_arc_creation_successfull(void)
|
||||
{
|
||||
arc = lv_arc_create(active_screen);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(arc);
|
||||
}
|
||||
|
||||
void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void)
|
||||
{
|
||||
/* Default max range is 100 */
|
||||
int16_t value_after_truncation = 100;
|
||||
|
||||
arc = lv_arc_create(active_screen);
|
||||
|
||||
lv_arc_set_value(arc, 200);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc));
|
||||
}
|
||||
|
||||
void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void)
|
||||
{
|
||||
/* Default min range is 100 */
|
||||
int16_t value_after_truncation = 0;
|
||||
|
||||
arc = lv_arc_create(active_screen);
|
||||
|
||||
lv_arc_set_value(arc, 0);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc));
|
||||
}
|
||||
|
||||
void test_arc_should_update_value_after_updating_range(void)
|
||||
{
|
||||
int16_t value_after_updating_max_range = 50;
|
||||
int16_t value_after_updating_min_range = 30;
|
||||
|
||||
arc = lv_arc_create(active_screen);
|
||||
|
||||
lv_arc_set_value(arc, 80);
|
||||
lv_arc_set_range(arc, 1, 50);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(value_after_updating_max_range, lv_arc_get_value(arc));
|
||||
|
||||
lv_arc_set_value(arc, 10);
|
||||
lv_arc_set_range(arc, 30, 50);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(value_after_updating_min_range, lv_arc_get_value(arc));
|
||||
}
|
||||
|
||||
void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void)
|
||||
{
|
||||
int16_t expected_angle_start = 135;
|
||||
int16_t expected_angle_end = 270;
|
||||
|
||||
/* start angle is 135, end angle is 45 at creation */
|
||||
arc = lv_arc_create(active_screen);
|
||||
lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc));
|
||||
TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc));
|
||||
}
|
||||
|
||||
void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void)
|
||||
{
|
||||
int16_t expected_angle_start = 270;
|
||||
int16_t expected_angle_end = 45;
|
||||
|
||||
/* start angle is 135, end angle is 45 at creation */
|
||||
arc = lv_arc_create(active_screen);
|
||||
lv_arc_set_value(arc, 100);
|
||||
lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc));
|
||||
TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc));
|
||||
}
|
||||
|
||||
/* See #2522 for more information */
|
||||
void test_arc_angles_when_reversed(void)
|
||||
{
|
||||
uint16_t expected_start_angle = 36;
|
||||
uint16_t expected_end_angle = 90;
|
||||
int16_t expected_value = 40;
|
||||
|
||||
lv_obj_t *arcBlack;
|
||||
arcBlack = lv_arc_create(lv_scr_act());
|
||||
|
||||
lv_arc_set_mode(arcBlack, LV_ARC_MODE_REVERSE);
|
||||
|
||||
lv_arc_set_bg_angles(arcBlack, 0, 90);
|
||||
|
||||
lv_arc_set_value(arcBlack, expected_value);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT16(expected_start_angle, lv_arc_get_angle_start(arcBlack));
|
||||
TEST_ASSERT_EQUAL_UINT16(expected_end_angle, lv_arc_get_angle_end(arcBlack));
|
||||
TEST_ASSERT_EQUAL_INT16(expected_value, lv_arc_get_value(arcBlack));
|
||||
}
|
||||
|
||||
void test_arc_click_area_with_adv_hittest(void)
|
||||
{
|
||||
arc = lv_arc_create(lv_scr_act());
|
||||
lv_obj_set_size(arc, 100, 100);
|
||||
lv_obj_set_style_arc_width(arc, 10, 0);
|
||||
lv_obj_add_flag(arc, LV_OBJ_FLAG_ADV_HITTEST);
|
||||
lv_obj_add_event_cb(arc, dummy_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_obj_set_ext_click_area(arc, 5);
|
||||
|
||||
/*No click detected at the middle*/
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_click_at(50, 50);
|
||||
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
|
||||
|
||||
/*No click close to the radius - bg_arc - ext_click_area*/
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_click_at(83, 50);
|
||||
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
|
||||
|
||||
/*Click on the radius - bg_arc - ext_click_area*/
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_click_at(86, 50);
|
||||
TEST_ASSERT_GREATER_THAN(0, event_cnt);
|
||||
|
||||
/*Click on the radius + ext_click_area*/
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_click_at(104, 50);
|
||||
TEST_ASSERT_GREATER_THAN(0, event_cnt);
|
||||
|
||||
/*No click beyond to the radius + ext_click_area*/
|
||||
event_cnt = 0;
|
||||
lv_test_mouse_click_at(106, 50);
|
||||
TEST_ASSERT_EQUAL_UINT32(0, event_cnt);
|
||||
}
|
||||
|
||||
static void dummy_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
event_cnt++;
|
||||
}
|
||||
|
||||
#endif
|
||||
95
APP_Framework/lib/lvgl/tests/src/test_cases/test_checkbox.c
Normal file
95
APP_Framework/lib/lvgl/tests/src/test_cases/test_checkbox.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
#include "lv_test_indev.h"
|
||||
|
||||
void test_checkbox_creation_successfull(void);
|
||||
void test_checkbox_should_call_event_handler_on_click_when_enabled(void);
|
||||
void test_checkbox_should_have_default_text_when_created(void);
|
||||
void test_checkbox_should_return_dinamically_allocated_text(void);
|
||||
void test_checkbox_should_allocate_memory_for_static_text(void);
|
||||
|
||||
static lv_obj_t *active_screen = NULL;
|
||||
static lv_obj_t *checkbox = NULL;
|
||||
|
||||
static volatile bool event_called = false;
|
||||
|
||||
static void event_handler(lv_event_t *e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
if (LV_EVENT_VALUE_CHANGED == code) {
|
||||
event_called = true;
|
||||
}
|
||||
}
|
||||
|
||||
void test_checkbox_creation_successfull(void)
|
||||
{
|
||||
active_screen = lv_scr_act();
|
||||
checkbox = lv_checkbox_create(active_screen);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(checkbox);
|
||||
}
|
||||
|
||||
void test_checkbox_should_call_event_handler_on_click_when_enabled(void)
|
||||
{
|
||||
active_screen = lv_scr_act();
|
||||
checkbox = lv_checkbox_create(active_screen);
|
||||
|
||||
lv_obj_add_state(checkbox, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(checkbox, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
lv_test_mouse_click_at(checkbox->coords.x1, checkbox->coords.y1);
|
||||
|
||||
TEST_ASSERT_TRUE(event_called);
|
||||
|
||||
event_called = false;
|
||||
}
|
||||
|
||||
void test_checkbox_should_have_default_text_when_created(void)
|
||||
{
|
||||
const char *default_text = "Check box";
|
||||
|
||||
active_screen = lv_scr_act();
|
||||
checkbox = lv_checkbox_create(active_screen);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(default_text, lv_checkbox_get_text(checkbox));
|
||||
TEST_ASSERT_NOT_NULL(lv_checkbox_get_text(checkbox));
|
||||
}
|
||||
|
||||
void test_checkbox_should_return_dinamically_allocated_text(void)
|
||||
{
|
||||
const char *message = "Hello World!";
|
||||
|
||||
active_screen = lv_scr_act();
|
||||
checkbox = lv_checkbox_create(active_screen);
|
||||
|
||||
lv_checkbox_set_text(checkbox, message);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(message, lv_checkbox_get_text(checkbox));
|
||||
TEST_ASSERT_NOT_NULL(lv_checkbox_get_text(checkbox));
|
||||
}
|
||||
|
||||
void test_checkbox_should_allocate_memory_for_static_text(void)
|
||||
{
|
||||
uint32_t initial_available_memory = 0;
|
||||
const char *static_text = "Keep me while you exist";
|
||||
|
||||
lv_mem_monitor_t m1;
|
||||
lv_mem_monitor(&m1);
|
||||
|
||||
active_screen = lv_scr_act();
|
||||
checkbox = lv_checkbox_create(active_screen);
|
||||
|
||||
initial_available_memory = m1.free_size;
|
||||
|
||||
lv_checkbox_set_text_static(checkbox, static_text);
|
||||
|
||||
lv_mem_monitor(&m1);
|
||||
|
||||
TEST_ASSERT_LESS_THAN(initial_available_memory, m1.free_size);
|
||||
}
|
||||
|
||||
#endif
|
||||
19
APP_Framework/lib/lvgl/tests/src/test_cases/test_config.c
Normal file
19
APP_Framework/lib/lvgl/tests/src/test_cases/test_config.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#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
|
||||
427
APP_Framework/lib/lvgl/tests/src/test_cases/test_dropdown.c
Normal file
427
APP_Framework/lib/lvgl/tests/src/test_cases/test_dropdown.c
Normal file
@@ -0,0 +1,427 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
#include "lv_test_indev.h"
|
||||
|
||||
void test_dropdown_create_delete(void);
|
||||
void test_dropdown_set_options(void);
|
||||
void test_dropdown_select(void);
|
||||
void test_dropdown_click(void);
|
||||
void test_dropdown_keypad(void);
|
||||
void test_dropdown_encoder(void);
|
||||
void test_dropdown_render_1(void);
|
||||
void test_dropdown_render_2(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_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_click(void)
|
||||
{
|
||||
lv_obj_clean(lv_scr_act());
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_update_layout(dd1);
|
||||
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
lv_test_mouse_click_at(dd1->coords.x1 + 5, dd1->coords.y1 + 5);
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
|
||||
lv_obj_t * list = lv_dropdown_get_list(dd1);
|
||||
TEST_ASSERT_EQUAL(0, lv_dropdown_get_selected(dd1));
|
||||
lv_test_mouse_click_at(list->coords.x1 + 5, list->coords.y2 - 25);
|
||||
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
}
|
||||
|
||||
static uint32_t event_cnt;
|
||||
static void dd_event(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
event_cnt++;
|
||||
}
|
||||
|
||||
void test_dropdown_keypad(void)
|
||||
{
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
lv_group_t * g = lv_group_create();
|
||||
lv_indev_set_group(lv_test_keypad_indev, g);
|
||||
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd1, 20, 20);
|
||||
lv_dropdown_set_options(dd1, "1\n2\n3\n4\n5\n6\n7\n8");
|
||||
lv_group_add_obj(g, dd1);
|
||||
lv_obj_add_event_cb(dd1, dd_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
lv_obj_t * dd2 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd2, 300, 20);
|
||||
lv_group_add_obj(g, dd2);
|
||||
|
||||
event_cnt = 0;
|
||||
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_RIGHT); /*Same as down*/
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(1, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_DOWN); /*Open the list too*/
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(3, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(2, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_RIGHT); /*Open the list too*/
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
lv_test_key_hit(LV_KEY_RIGHT);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(4, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(3, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_LEFT); /*Open the list too*/
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
lv_test_key_hit(LV_KEY_LEFT);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(3, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(4, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_UP); /*Open the list too*/
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
lv_test_key_hit(LV_KEY_UP);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(5, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_UP);
|
||||
lv_test_key_hit(LV_KEY_UP);
|
||||
lv_test_key_hit(LV_KEY_UP);
|
||||
lv_test_key_hit(LV_KEY_UP);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(0, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(6, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_DOWN);
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(7, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(7, event_cnt);
|
||||
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
|
||||
lv_test_key_hit(LV_KEY_NEXT);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
|
||||
lv_test_key_hit(LV_KEY_ENTER);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd2));
|
||||
|
||||
lv_indev_set_group(lv_test_keypad_indev, NULL);
|
||||
lv_group_del(g);
|
||||
}
|
||||
|
||||
|
||||
void test_dropdown_encoder(void)
|
||||
{
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
lv_group_t * g = lv_group_create();
|
||||
lv_indev_set_group(lv_test_encoder_indev, g);
|
||||
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd1, 20, 20);
|
||||
lv_dropdown_set_options(dd1, "1\n2\n3\n4\n5\n6\n7\n8");
|
||||
lv_group_add_obj(g, dd1);
|
||||
lv_obj_add_event_cb(dd1, dd_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
lv_obj_t * dd2 = lv_dropdown_create(lv_scr_act());
|
||||
lv_obj_set_pos(dd2, 300, 20);
|
||||
lv_group_add_obj(g, dd2);
|
||||
|
||||
event_cnt = 0;
|
||||
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
lv_test_encoder_click();
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd2));
|
||||
|
||||
lv_test_encoder_turn(5);
|
||||
lv_test_encoder_click();
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(5, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(1, event_cnt);
|
||||
|
||||
lv_test_encoder_click();
|
||||
lv_test_encoder_turn(-1);
|
||||
lv_test_encoder_click();
|
||||
TEST_ASSERT_EQUAL(4, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(2, event_cnt);
|
||||
|
||||
lv_test_encoder_click();
|
||||
lv_test_encoder_turn(2);
|
||||
lv_test_encoder_press();
|
||||
lv_test_indev_wait(1000); //Long press
|
||||
lv_test_encoder_release();
|
||||
lv_test_indev_wait(50);
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_EQUAL(4, lv_dropdown_get_selected(dd1));
|
||||
TEST_ASSERT_EQUAL(2, event_cnt);
|
||||
|
||||
lv_test_encoder_turn(1);
|
||||
lv_test_encoder_click();
|
||||
TEST_ASSERT_NULL(lv_dropdown_get_list(dd1));
|
||||
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd2));
|
||||
|
||||
lv_indev_set_group(lv_test_encoder_indev, NULL);
|
||||
lv_group_del(g);
|
||||
}
|
||||
|
||||
|
||||
void test_dropdown_render_1(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);
|
||||
TEST_ASSERT_TRUE(lv_dropdown_get_selected_highlight(dd2));
|
||||
lv_dropdown_set_selected_highlight(dd2, false);
|
||||
TEST_ASSERT_FALSE(lv_dropdown_get_selected_highlight(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);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, lv_dropdown_get_text(dd3));
|
||||
lv_dropdown_set_text(dd3, "A text");
|
||||
TEST_ASSERT_EQUAL_STRING("A text", lv_dropdown_get_text(dd3));
|
||||
|
||||
lv_dropdown_set_selected(dd3, 2);
|
||||
|
||||
TEST_ASSERT_EQUAL(LV_DIR_BOTTOM, lv_dropdown_get_dir(dd3));
|
||||
lv_dropdown_set_dir(dd3, LV_DIR_LEFT);
|
||||
TEST_ASSERT_EQUAL(LV_DIR_LEFT, lv_dropdown_get_dir(dd3));
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(LV_SYMBOL_DOWN, lv_dropdown_get_symbol(dd3));
|
||||
lv_dropdown_set_symbol(dd3, LV_SYMBOL_LEFT);
|
||||
TEST_ASSERT_EQUAL_STRING(LV_SYMBOL_LEFT, lv_dropdown_get_symbol(dd3));
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
void test_dropdown_render_2(void)
|
||||
{
|
||||
lv_obj_clean(lv_scr_act());
|
||||
LV_IMG_DECLARE(img_caret_down);
|
||||
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd1, "Short");
|
||||
lv_dropdown_set_options(dd1, "1\n2");
|
||||
lv_dropdown_set_symbol(dd1, &img_caret_down);
|
||||
lv_dropdown_open(dd1);
|
||||
|
||||
lv_obj_t * dd2 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd2, "Go Up");
|
||||
lv_dropdown_set_options(dd2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
||||
lv_dropdown_set_symbol(dd2, NULL);
|
||||
lv_obj_align(dd2, LV_ALIGN_LEFT_MID, 150, 50);
|
||||
lv_dropdown_open(dd2);
|
||||
|
||||
lv_obj_t * dd3 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd3, "Limit Down");
|
||||
lv_dropdown_set_options(dd3, "1aaaaaaaaaaaaaaaa\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
||||
lv_obj_align(dd3, LV_ALIGN_LEFT_MID, 300, -10);
|
||||
lv_dropdown_open(dd3);
|
||||
|
||||
lv_obj_t * dd4 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd4, "Limit Top");
|
||||
lv_dropdown_set_options(dd4, "1aaaaaaaaaaaaaaaa\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
||||
lv_obj_align(dd4, LV_ALIGN_LEFT_MID, 450, 10);
|
||||
lv_dropdown_set_dir(dd4, LV_DIR_TOP);
|
||||
lv_dropdown_set_symbol(dd4, LV_SYMBOL_UP);
|
||||
lv_dropdown_open(dd4);
|
||||
|
||||
lv_obj_t * dd5 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd5, "Go Down");
|
||||
lv_dropdown_set_options(dd5, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
||||
lv_dropdown_set_dir(dd5, LV_DIR_TOP);
|
||||
lv_dropdown_set_symbol(dd5, LV_SYMBOL_UP);
|
||||
lv_obj_align(dd5, LV_ALIGN_LEFT_MID, 650, -200);
|
||||
lv_dropdown_open(dd5);
|
||||
|
||||
lv_obj_t * dd6 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd6, "Right");
|
||||
lv_dropdown_set_options(dd6, "1aaa\n2aa\n3aa");
|
||||
lv_dropdown_set_dir(dd6, LV_DIR_RIGHT);
|
||||
lv_dropdown_set_symbol(dd6, LV_SYMBOL_RIGHT);
|
||||
lv_obj_align(dd6, LV_ALIGN_BOTTOM_LEFT, 20, -20);
|
||||
lv_dropdown_open(dd6);
|
||||
lv_obj_set_style_text_align(lv_dropdown_get_list(dd6), LV_TEXT_ALIGN_RIGHT, 0);
|
||||
|
||||
lv_obj_t * dd7 = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_text(dd7, "Left");
|
||||
lv_dropdown_set_options(dd7, "1aaa\n2\n3");
|
||||
lv_dropdown_set_dir(dd7, LV_DIR_LEFT);
|
||||
lv_dropdown_set_symbol(dd7, LV_SYMBOL_LEFT);
|
||||
lv_obj_align(dd7, LV_ALIGN_BOTTOM_RIGHT, -20, -20);
|
||||
lv_dropdown_open(dd7);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_2.png");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
206
APP_Framework/lib/lvgl/tests/src/test_cases/test_font_loader.c
Normal file
206
APP_Framework/lib/lvgl/tests/src/test_cases/test_font_loader.c
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* @file test_font_loader.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#if LV_BUILD_TEST
|
||||
#include "../../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
static int compare_fonts(lv_font_t * f1, lv_font_t * f2);
|
||||
void test_font_loader(void);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
extern lv_font_t font_1;
|
||||
extern lv_font_t font_2;
|
||||
extern lv_font_t font_3;
|
||||
|
||||
void test_font_loader(void)
|
||||
{
|
||||
lv_font_t * font_1_bin = lv_font_load("F:src/test_fonts/font_1.fnt");
|
||||
lv_font_t * font_2_bin = lv_font_load("F:src/test_fonts/font_2.fnt");
|
||||
lv_font_t * font_3_bin = lv_font_load("F:src/test_fonts/font_3.fnt");
|
||||
|
||||
compare_fonts(&font_1, font_1_bin);
|
||||
compare_fonts(&font_2, font_2_bin);
|
||||
compare_fonts(&font_3, font_3_bin);
|
||||
|
||||
lv_font_free(font_1_bin);
|
||||
lv_font_free(font_2_bin);
|
||||
lv_font_free(font_3_bin);
|
||||
}
|
||||
|
||||
static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
|
||||
{
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(f1, "font not null");
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(f2, "font not null");
|
||||
|
||||
// Skip these test because -Wpedantic tells
|
||||
// ISO C forbids passing argument 1 of ‘lv_test_assert_ptr_eq’ between function pointer and ‘void *’
|
||||
// TEST_ASSERT_EQUAL_PTR_MESSAGE(f1->get_glyph_dsc, f2->get_glyph_dsc, "glyph_dsc");
|
||||
// TEST_ASSERT_EQUAL_PTR_MESSAGE(f1->get_glyph_bitmap, f2->get_glyph_bitmap, "glyph_bitmap");
|
||||
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(f1->line_height, f2->line_height, "line_height");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(f1->base_line, f2->base_line, "base_line");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(f1->subpx, f2->subpx, "subpx");
|
||||
lv_font_fmt_txt_dsc_t * dsc1 = (lv_font_fmt_txt_dsc_t *)f1->dsc;
|
||||
lv_font_fmt_txt_dsc_t * dsc2 = (lv_font_fmt_txt_dsc_t *)f2->dsc;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(dsc1->kern_scale, dsc2->kern_scale, "kern_scale");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(dsc1->cmap_num, dsc2->cmap_num, "cmap_num");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(dsc1->bpp, dsc2->bpp, "bpp");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(dsc1->kern_classes, dsc2->kern_classes, "kern_classes");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(dsc1->bitmap_format, dsc2->bitmap_format, "bitmap_format");
|
||||
|
||||
// cmaps
|
||||
int total_glyphs = 0;
|
||||
for(int i = 0; i < dsc1->cmap_num; ++i) {
|
||||
lv_font_fmt_txt_cmap_t * cmaps1 = (lv_font_fmt_txt_cmap_t *)&dsc1->cmaps[i];
|
||||
lv_font_fmt_txt_cmap_t * cmaps2 = (lv_font_fmt_txt_cmap_t *)&dsc2->cmaps[i];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(cmaps1->range_start, cmaps2->range_start, "range_start");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(cmaps1->range_length, cmaps2->range_length, "range_length");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(cmaps1->glyph_id_start, cmaps2->glyph_id_start, "glyph_id_start");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(cmaps1->type, cmaps2->type, "type");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(cmaps1->list_length, cmaps2->list_length, "list_length");
|
||||
|
||||
if(cmaps1->unicode_list != NULL && cmaps2->unicode_list != NULL) {
|
||||
TEST_ASSERT_TRUE_MESSAGE(cmaps1->unicode_list && cmaps2->unicode_list, "unicode_list");
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
(uint8_t *)cmaps1->unicode_list,
|
||||
(uint8_t *)cmaps2->unicode_list,
|
||||
sizeof(uint16_t) * cmaps1->list_length,
|
||||
"unicode_list");
|
||||
total_glyphs += cmaps1->list_length;
|
||||
}
|
||||
else {
|
||||
total_glyphs += cmaps1->range_length;
|
||||
TEST_ASSERT_EQUAL_PTR_MESSAGE(cmaps1->unicode_list, cmaps2->unicode_list, "unicode_list");
|
||||
}
|
||||
|
||||
if(cmaps1->glyph_id_ofs_list != NULL && cmaps2->glyph_id_ofs_list != NULL) {
|
||||
uint8_t * ids1 = (uint8_t *)cmaps1->glyph_id_ofs_list;
|
||||
uint8_t * ids2 = (uint8_t *)cmaps2->glyph_id_ofs_list;
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(ids1, ids2, cmaps1->list_length, "glyph_id_ofs_list");
|
||||
}
|
||||
else {
|
||||
TEST_ASSERT_EQUAL_PTR_MESSAGE(cmaps1->glyph_id_ofs_list, cmaps2->glyph_id_ofs_list, "glyph_id_ofs_list");
|
||||
}
|
||||
}
|
||||
|
||||
// kern_dsc
|
||||
if (dsc1->kern_classes == 1 && dsc2->kern_classes == 1) {
|
||||
lv_font_fmt_txt_kern_classes_t * kern1 = (lv_font_fmt_txt_kern_classes_t *)dsc1->kern_dsc;
|
||||
lv_font_fmt_txt_kern_classes_t * kern2 = (lv_font_fmt_txt_kern_classes_t *)dsc2->kern_dsc;
|
||||
if (kern1 != NULL && kern2 != NULL) {
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(kern1->right_class_cnt, kern2->right_class_cnt, "right_class_cnt");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(kern1->left_class_cnt, kern2->left_class_cnt, "left_class_cnt");
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
(uint8_t *)kern1->left_class_mapping,
|
||||
(uint8_t *)kern2->left_class_mapping,
|
||||
kern1->left_class_cnt,
|
||||
"left_class_mapping");
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
(uint8_t *)kern1->right_class_mapping,
|
||||
(uint8_t *)kern2->right_class_mapping,
|
||||
kern1->right_class_cnt,
|
||||
"right_class_mapping");
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
(uint8_t *)kern1->class_pair_values,
|
||||
(uint8_t *)kern2->class_pair_values,
|
||||
kern1->right_class_cnt * kern1->left_class_cnt,
|
||||
"class_pair_values");
|
||||
}
|
||||
else {
|
||||
TEST_ASSERT_EQUAL_PTR_MESSAGE(kern1, kern2, "kern");
|
||||
}
|
||||
}
|
||||
else if (dsc1->kern_classes == 0 && dsc2->kern_classes == 0) {
|
||||
lv_font_fmt_txt_kern_pair_t * kern1 = (lv_font_fmt_txt_kern_pair_t *)dsc1->kern_dsc;
|
||||
lv_font_fmt_txt_kern_pair_t * kern2 = (lv_font_fmt_txt_kern_pair_t *)dsc2->kern_dsc;
|
||||
if (kern1 != NULL && kern2 != NULL) {
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(kern1->glyph_ids_size, kern2->glyph_ids_size, "glyph_ids_size");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(kern1->pair_cnt, kern2->pair_cnt, "pair_cnt");
|
||||
|
||||
int ids_size;
|
||||
|
||||
if (kern1->glyph_ids_size == 0) {
|
||||
ids_size = sizeof(int8_t) * 2 * kern1->pair_cnt;
|
||||
}
|
||||
else {
|
||||
ids_size = sizeof(int16_t) * 2 * kern1->pair_cnt;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(kern1->glyph_ids, kern2->glyph_ids, ids_size, "glyph_ids");
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
(uint8_t * ) kern1->values,
|
||||
(uint8_t * ) kern2->values,
|
||||
kern1->pair_cnt,
|
||||
"glyph_values");
|
||||
}
|
||||
}
|
||||
|
||||
lv_font_fmt_txt_glyph_dsc_t * glyph_dsc1 = (lv_font_fmt_txt_glyph_dsc_t *)dsc1->glyph_dsc;
|
||||
lv_font_fmt_txt_glyph_dsc_t * glyph_dsc2 = (lv_font_fmt_txt_glyph_dsc_t *)dsc2->glyph_dsc;
|
||||
|
||||
for(int i = 0; i < total_glyphs; ++i) {
|
||||
if (i < total_glyphs - 1) {
|
||||
int size1 = glyph_dsc1[i+1].bitmap_index - glyph_dsc1[i].bitmap_index;
|
||||
|
||||
if (size1 > 0) {
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
|
||||
dsc1->glyph_bitmap + glyph_dsc1[i].bitmap_index,
|
||||
dsc2->glyph_bitmap + glyph_dsc2[i].bitmap_index,
|
||||
size1 - 1, "glyph_bitmap");
|
||||
}
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(glyph_dsc1[i].adv_w, glyph_dsc2[i].adv_w, "adv_w");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(glyph_dsc1[i].box_w, glyph_dsc2[i].box_w, "box_w");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(glyph_dsc1[i].box_h, glyph_dsc2[i].box_h, "box_h");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(glyph_dsc1[i].ofs_x, glyph_dsc2[i].ofs_x, "ofs_x");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(glyph_dsc1[i].ofs_y, glyph_dsc2[i].ofs_y, "ofs_y");
|
||||
}
|
||||
|
||||
LV_LOG_INFO("No differences found!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif // LV_BUILD_TEST
|
||||
|
||||
39
APP_Framework/lib/lvgl/tests/src/test_cases/test_obj_tree.c
Normal file
39
APP_Framework/lib/lvgl/tests/src/test_cases/test_obj_tree.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void test_obj_tree_1(void);
|
||||
void test_obj_tree_2(void);
|
||||
|
||||
void test_obj_tree_1(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(lv_obj_get_child_cnt(lv_scr_act()), 0);
|
||||
}
|
||||
|
||||
void test_obj_tree_2(void)
|
||||
{
|
||||
|
||||
lv_obj_create(lv_scr_act());
|
||||
lv_obj_t * o2 = lv_obj_create(lv_scr_act());
|
||||
lv_obj_create(lv_scr_act());
|
||||
TEST_ASSERT_EQUAL(lv_obj_get_child_cnt(lv_scr_act()), 3);
|
||||
|
||||
lv_obj_del(o2);
|
||||
TEST_ASSERT_EQUAL(lv_obj_get_child_cnt(lv_scr_act()), 2);
|
||||
|
||||
lv_obj_clean(lv_scr_act());
|
||||
TEST_ASSERT_EQUAL(lv_obj_get_child_cnt(lv_scr_act()), 0);
|
||||
|
||||
lv_color_t c1 = lv_color_hex(0x444444);
|
||||
lv_color_t c2 = lv_color_hex3(0x444);
|
||||
TEST_ASSERT_EQUAL_COLOR(c1, c2);
|
||||
|
||||
lv_obj_remove_style_all(lv_scr_act());
|
||||
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")
|
||||
}
|
||||
|
||||
#endif
|
||||
13
APP_Framework/lib/lvgl/tests/src/test_cases/test_style.c
Normal file
13
APP_Framework/lib/lvgl/tests/src/test_cases/test_style.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
//void test_func_1(void);
|
||||
|
||||
//void test_func_1(void)
|
||||
//{
|
||||
// TEST_ASSERT_EQUAL(actual, expected);
|
||||
//}
|
||||
|
||||
#endif
|
||||
207
APP_Framework/lib/lvgl/tests/src/test_cases/test_txt.c
Normal file
207
APP_Framework/lib/lvgl/tests/src/test_cases/test_txt.c
Normal file
@@ -0,0 +1,207 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
static const char color_cmd = LV_TXT_COLOR_CMD[0];
|
||||
|
||||
void test_txt_should_identify_valid_start_of_command(void)
|
||||
{
|
||||
uint32_t character = color_cmd;
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_WAIT;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_TRUE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_PAR);
|
||||
}
|
||||
|
||||
void test_txt_should_identify_invalid_start_of_command(void)
|
||||
{
|
||||
uint32_t character = '$';
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_WAIT;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_FALSE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_WAIT);
|
||||
}
|
||||
|
||||
void test_txt_should_identify_scaped_command_in_parameter(void)
|
||||
{
|
||||
uint32_t character = color_cmd;
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_PAR;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_FALSE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_WAIT);
|
||||
}
|
||||
|
||||
void test_txt_should_skip_color_parameter_in_parameter(void)
|
||||
{
|
||||
uint32_t character = '$';
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_PAR;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_TRUE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_PAR);
|
||||
}
|
||||
|
||||
void test_txt_should_reset_state_when_receiving_color_cmd_while_processing_commands(void)
|
||||
{
|
||||
uint32_t character = color_cmd;
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_IN;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_TRUE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_WAIT);
|
||||
}
|
||||
|
||||
void test_txt_should_identify_space_after_parameter(void)
|
||||
{
|
||||
uint32_t character = ' ';
|
||||
lv_text_cmd_state_t state = LV_TEXT_CMD_STATE_PAR;
|
||||
|
||||
bool is_cmd = _lv_txt_is_cmd(&state, character);
|
||||
|
||||
TEST_ASSERT_TRUE(is_cmd);
|
||||
TEST_ASSERT_EQUAL_UINT8(state, LV_TEXT_CMD_STATE_IN);
|
||||
}
|
||||
|
||||
void test_txt_should_insert_string_into_another(void)
|
||||
{
|
||||
const char *msg = "Hello ";
|
||||
const char *suffix = "World";
|
||||
char target[20] = {0};
|
||||
size_t msg_len = strlen(msg);
|
||||
|
||||
strcpy(target, msg);
|
||||
|
||||
_lv_txt_ins(target, msg_len, suffix);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("Hello World", target);
|
||||
}
|
||||
|
||||
void test_txt_should_handle_null_pointers_when_inserting(void)
|
||||
{
|
||||
const char *msg = "Hello ";
|
||||
char target[20] = {0};
|
||||
size_t msg_len = strlen(msg);
|
||||
|
||||
strcpy(target, msg);
|
||||
|
||||
_lv_txt_ins(target, msg_len, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("Hello ", target);
|
||||
}
|
||||
|
||||
void test_txt_cut_should_handle_null_pointer_to_txt(void)
|
||||
{
|
||||
_lv_txt_cut(NULL, 0, 6);
|
||||
}
|
||||
|
||||
void test_txt_cut_happy_path(void)
|
||||
{
|
||||
char msg[] = "Hello World";
|
||||
|
||||
_lv_txt_cut(msg, 0, 6);
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("World", msg);
|
||||
}
|
||||
|
||||
void test_txt_cut_should_handle_len_longer_than_string_length(void)
|
||||
{
|
||||
char msg[] = "Hello World";
|
||||
|
||||
_lv_txt_cut(msg, 0, 30);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(msg[0], 0x00);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_should_decode_valid_ascii(void)
|
||||
{
|
||||
char msg[] = "Hello World!";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32((uint32_t) 'H', result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_valid_2_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xc3\xb1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(241, result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_invalid_2_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xc3\x28";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_valid_3_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xe2\x82\xa1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(8353, result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_invalid_3_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xe2\x28\xa1";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_valid_4_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xf0\x90\x8c\xbc";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(66364, result);
|
||||
}
|
||||
|
||||
void test_txt_get_encoded_next_detect_invalid_4_byte_input(void)
|
||||
{
|
||||
char msg[] = "\xf0\x28\x8c\x28";
|
||||
uint32_t result = 0;
|
||||
|
||||
result = _lv_txt_encoded_next(msg, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, result);
|
||||
}
|
||||
|
||||
/* See #2615 for more information */
|
||||
void test_txt_next_line_should_handle_empty_string(void)
|
||||
{
|
||||
const lv_font_t *font_ptr = NULL;
|
||||
lv_coord_t letter_space = 0;
|
||||
lv_coord_t max_width = 0;
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
|
||||
uint32_t next_line = _lv_txt_get_next_line("", font_ptr, letter_space, max_width, flag);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(0, next_line);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user