1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

chore(test): format test cases (#3071)

This commit is contained in:
Carlos Diaz 2022-02-03 02:59:55 -06:00 committed by GitHub
parent e400a87df9
commit 2c7760c687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 474 additions and 447 deletions

View File

@ -0,0 +1,26 @@
--style=kr
--indent=spaces=4
--indent-classes
--indent-switches
--indent-cases
--indent-preproc-block
--indent-preproc-define
--indent-col1-comments
--pad-oper
--unpad-paren
--align-pointer=middle
--align-reference=middle
--convert-tabs
--max-code-length=120
--break-after-logical
--break-closing-braces
--attach-closing-while
--min-conditional-indent=0
--max-continuation-indent=120
--mode=c
--lineend=linux
--recursive
--suffix=none
--preserve-date
--formatted
--exclude=../tests/src/test_cases/_test_template.c

View File

@ -3,3 +3,4 @@
import os
os.system('astyle --options=code-format.cfg "../src/*.c,*.h"')
os.system('astyle --options=code-format-tests.cfg "../tests/src/test_cases/*.c"')

View File

@ -15,8 +15,8 @@ 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 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);
@ -109,7 +109,7 @@ void test_arc_angles_when_reversed(void)
uint16_t expected_end_angle = 90;
int16_t expected_value = 40;
lv_obj_t *arcBlack;
lv_obj_t * arcBlack;
arcBlack = lv_arc_create(lv_scr_act());
lv_arc_set_mode(arcBlack, LV_ARC_MODE_REVERSE);
@ -160,8 +160,8 @@ void test_arc_click_area_with_adv_hittest(void)
static void dummy_event_cb(lv_event_t * e)
{
LV_UNUSED(e);
event_cnt++;
LV_UNUSED(e);
event_cnt++;
}
#endif

View File

@ -5,8 +5,8 @@
#include "lv_test_indev.h"
static lv_obj_t *active_screen = NULL;
static lv_obj_t *bar = NULL;
static lv_obj_t * active_screen = NULL;
static lv_obj_t * bar = NULL;
void setUp(void)
{

View File

@ -12,16 +12,16 @@ 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 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)
static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if (LV_EVENT_VALUE_CHANGED == code) {
if(LV_EVENT_VALUE_CHANGED == code) {
event_called = true;
}
}
@ -51,7 +51,7 @@ void test_checkbox_should_call_event_handler_on_click_when_enabled(void)
void test_checkbox_should_have_default_text_when_created(void)
{
const char *default_text = "Check box";
const char * default_text = "Check box";
active_screen = lv_scr_act();
checkbox = lv_checkbox_create(active_screen);
@ -62,7 +62,7 @@ void test_checkbox_should_have_default_text_when_created(void)
void test_checkbox_should_return_dinamically_allocated_text(void)
{
const char *message = "Hello World!";
const char * message = "Hello World!";
active_screen = lv_scr_act();
checkbox = lv_checkbox_create(active_screen);
@ -76,7 +76,7 @@ void test_checkbox_should_return_dinamically_allocated_text(void)
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";
const char * static_text = "Keep me while you exist";
lv_mem_monitor_t m1;
lv_mem_monitor(&m1);

View File

@ -7,13 +7,13 @@ 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);
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

View File

@ -10,7 +10,7 @@
static void loop_through_stress_test(void)
{
#if LV_USE_DEMO_STRESS
lv_test_indev_wait(LV_DEMO_STRESS_TIME_STEP*33); /* FIXME: remove magic number of states */
lv_test_indev_wait(LV_DEMO_STRESS_TIME_STEP * 33); /* FIXME: remove magic number of states */
#endif
}
void test_demo_stress(void)

View File

@ -16,411 +16,411 @@ void tearDown(void)
}
void test_dropdown_create_delete(void)
{
lv_dropdown_create(lv_scr_act());
TEST_ASSERT_EQUAL(2, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_create(lv_scr_act());
TEST_ASSERT_EQUAL(2, 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(4, lv_obj_get_child_cnt(lv_scr_act()));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_dropdown_open(dd2);
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd2));
lv_dropdown_open(dd2); /*Try to open again*/
TEST_ASSERT_EQUAL(4, 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(4, lv_obj_get_child_cnt(lv_scr_act()));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_dropdown_open(dd2);
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd2));
lv_dropdown_open(dd2); /*Try to open again*/
TEST_ASSERT_EQUAL(4, 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(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_open(dd3);
TEST_ASSERT_EQUAL(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_close(dd3);
TEST_ASSERT_EQUAL(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_close(dd3); /*Try to close again*/
TEST_ASSERT_EQUAL(6, 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(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_open(dd3);
TEST_ASSERT_EQUAL(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_close(dd3);
TEST_ASSERT_EQUAL(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_dropdown_close(dd3); /*Try to close again*/
TEST_ASSERT_EQUAL(6, lv_obj_get_child_cnt(lv_scr_act()));
lv_obj_del(dd2);
TEST_ASSERT_EQUAL(4, lv_obj_get_child_cnt(lv_scr_act()));
lv_obj_del(dd2);
TEST_ASSERT_EQUAL(4, 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()));
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_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_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_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_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_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, "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, "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_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_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(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_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, "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, "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_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_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_obj_del(dd1);
lv_mem_monitor_t m2;
lv_mem_monitor(&m2);
TEST_ASSERT_UINT32_WITHIN(48, m1.free_size, m2.free_size);
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);
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));
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);
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);
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));
/*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);
lv_obj_clean(lv_scr_act());
lv_obj_t * dd1 = lv_dropdown_create(lv_scr_act());
lv_obj_update_layout(dd1);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
lv_test_mouse_click_at(dd1->coords.x1 + 5, dd1->coords.y1 + 5);
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
lv_test_mouse_click_at(dd1->coords.x1 + 5, dd1->coords.y1 + 5);
TEST_ASSERT_TRUE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
}
static uint32_t event_cnt;
static void dd_event(lv_event_t * e)
{
LV_UNUSED(e);
event_cnt++;
LV_UNUSED(e);
event_cnt++;
}
void test_dropdown_keypad(void)
{
lv_obj_clean(lv_scr_act());
lv_obj_clean(lv_scr_act());
lv_group_t * g = lv_group_create();
lv_indev_set_group(lv_test_keypad_indev, g);
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 * 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);
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;
event_cnt = 0;
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(1, event_cnt);
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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(3, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(2, 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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(4, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(3, 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_FALSE(lv_dropdown_is_open(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_TRUE(lv_dropdown_is_open(dd1));
lv_test_key_hit(LV_KEY_LEFT);
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(3, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(4, event_cnt);
lv_test_key_hit(LV_KEY_LEFT); /*Open the list too*/
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
lv_test_key_hit(LV_KEY_LEFT);
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(5, 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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(0, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(6, 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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(7, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(7, 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_FALSE(lv_dropdown_is_open(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_TRUE(lv_dropdown_is_open(dd1));
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
lv_test_key_hit(LV_KEY_NEXT);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_key_hit(LV_KEY_NEXT);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd2));
lv_test_key_hit(LV_KEY_ENTER);
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_NOT_NULL(lv_dropdown_get_list(dd2));
lv_indev_set_group(lv_test_keypad_indev, NULL);
lv_group_del(g);
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_obj_clean(lv_scr_act());
lv_group_t * g = lv_group_create();
lv_indev_set_group(lv_test_encoder_indev, g);
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 * 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);
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;
event_cnt = 0;
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_encoder_click();
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_encoder_click();
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd1));
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd2));
lv_test_encoder_turn(5);
lv_test_encoder_click();
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_EQUAL(5, lv_dropdown_get_selected(dd1));
TEST_ASSERT_EQUAL(1, event_cnt);
lv_test_encoder_turn(5);
lv_test_encoder_click();
TEST_ASSERT_FALSE(lv_dropdown_is_open(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(-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_FALSE(lv_dropdown_is_open(dd1));
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_FALSE(lv_dropdown_is_open(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_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd2));
lv_test_encoder_turn(1);
lv_test_encoder_click();
TEST_ASSERT_FALSE(lv_dropdown_is_open(dd1));
TEST_ASSERT_TRUE(lv_dropdown_is_open(dd2));
lv_indev_set_group(lv_test_encoder_indev, NULL);
lv_group_del(g);
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_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 * 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 * 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_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);
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(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));
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);
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");
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_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 * 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 * 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 * 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 * 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 * 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);
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");
TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_2.png");
}
/* See #2893 */

View File

@ -3,7 +3,7 @@
#include "unity/unity.h"
static void event_object_deletion_cb(const lv_obj_class_t *cls, lv_event_t *e)
static void event_object_deletion_cb(const lv_obj_class_t * cls, lv_event_t * e)
{
LV_UNUSED(cls);
if(lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {

View File

@ -63,10 +63,10 @@ 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");
// 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");
@ -96,10 +96,10 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
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");
(uint8_t *)cmaps1->unicode_list,
(uint8_t *)cmaps2->unicode_list,
sizeof(uint16_t) * cmaps1->list_length,
"unicode_list");
total_glyphs += cmaps1->list_length;
}
else {
@ -119,45 +119,45 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
}
// kern_dsc
if (dsc1->kern_classes == 1 && dsc2->kern_classes == 1) {
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) {
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");
(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");
(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");
(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) {
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) {
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) {
if(kern1->glyph_ids_size == 0) {
ids_size = sizeof(int8_t) * 2 * kern1->pair_cnt;
}
else {
@ -166,10 +166,10 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
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");
(uint8_t *) kern1->values,
(uint8_t *) kern2->values,
kern1->pair_cnt,
"glyph_values");
}
}
@ -177,14 +177,14 @@ static int compare_fonts(lv_font_t * f1, lv_font_t * f2)
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(i < total_glyphs - 1) {
int size1 = glyph_dsc1[i + 1].bitmap_index - glyph_dsc1[i].bitmap_index;
if (size1 > 0) {
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");
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");

View File

@ -8,32 +8,32 @@ void test_obj_tree_2(void);
void test_obj_tree_1(void)
{
TEST_ASSERT_EQUAL(lv_obj_get_child_cnt(lv_scr_act()), 0);
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_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_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_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_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);
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")
//TEST_ASSERT_EQUAL_SCREENSHOT("scr1.png")
}
#endif

View File

@ -15,7 +15,7 @@ void test_snapshot_should_not_leak_memory(void)
uint32_t final_available_memory = 0;
lv_mem_monitor_t monitor;
lv_img_dsc_t *snapshots[NUM_SNAPSHOTS] = {NULL};
lv_img_dsc_t * snapshots[NUM_SNAPSHOTS] = {NULL};
lv_mem_monitor(&monitor);
initial_available_memory = monitor.free_size;

View File

@ -9,8 +9,8 @@
#define SWITCHES_CNT 10
uint8_t value_changed_event_cnt = 0;
lv_obj_t *scr = NULL;
lv_obj_t *sw = NULL;
lv_obj_t * scr = NULL;
lv_obj_t * sw = NULL;
void setUp(void)
{
@ -30,11 +30,11 @@ static void mouse_click_on_switch(void)
lv_test_mouse_click_at(sw->coords.x1, sw->coords.y1);
}
static void event_handler(lv_event_t *e)
static void event_handler(lv_event_t * e)
{
lv_event_code_t event = lv_event_get_code(e);
if (LV_EVENT_VALUE_CHANGED == event) {
if(LV_EVENT_VALUE_CHANGED == event) {
value_changed_event_cnt++;
}
@ -52,16 +52,16 @@ void test_switch_should_not_leak_memory_after_deletion(void)
uint32_t initial_available_memory = 0;
uint32_t final_available_memory = 0;
lv_mem_monitor_t monitor;
lv_obj_t *switches[SWITCHES_CNT] = {NULL};
lv_obj_t * switches[SWITCHES_CNT] = {NULL};
lv_mem_monitor(&monitor);
initial_available_memory = monitor.free_size;
for (idx = 0; idx < SWITCHES_CNT; idx++) {
for(idx = 0; idx < SWITCHES_CNT; idx++) {
switches[idx] = lv_switch_create(scr);
}
for (idx = 0; idx < SWITCHES_CNT; idx++) {
for(idx = 0; idx < SWITCHES_CNT; idx++) {
lv_obj_del(switches[idx]);
}

View File

@ -73,8 +73,8 @@ void test_txt_should_identify_space_after_parameter(void)
void test_txt_should_insert_string_into_another(void)
{
const char *msg = "Hello ";
const char *suffix = "World";
const char * msg = "Hello ";
const char * suffix = "World";
char target[20] = {0};
size_t msg_len = strlen(msg);
@ -87,7 +87,7 @@ void test_txt_should_insert_string_into_another(void)
void test_txt_should_handle_null_pointers_when_inserting(void)
{
const char *msg = "Hello ";
const char * msg = "Hello ";
char target[20] = {0};
size_t msg_len = strlen(msg);
@ -194,7 +194,7 @@ void test_txt_get_encoded_next_detect_invalid_4_byte_input(void)
/* See #2615 for more information */
void test_txt_next_line_should_handle_empty_string(void)
{
const lv_font_t *font_ptr = NULL;
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;