Skip to content

Commit

Permalink
test(dropdown) add tess for keypad and encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Jun 23, 2021
1 parent e536bb6 commit 4143b80
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 7 deletions.
10 changes: 5 additions & 5 deletions tests/defines.py
Expand Up @@ -167,11 +167,11 @@
"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_ASSERT_NULL":0,
"LV_USE_ASSERT_MALLOC":0,
"LV_USE_ASSERT_MEM_INTEGRITY":0,
"LV_USE_ASSERT_OBJ":0,
"LV_USE_ASSERT_STYLE":0,

"LV_USE_USER_DATA": 1,
"LV_USE_LARGE_COORD": 1,
Expand Down
Binary file added tests/ref_imgs/dropdown_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
232 changes: 230 additions & 2 deletions tests/src/test_cases/test_dropdown.c
Expand Up @@ -9,7 +9,10 @@ void test_dropdown_set_text_and_symbol(void);
void test_dropdown_set_options(void);
void test_dropdown_select(void);
void test_dropdown_click(void);
void test_dropdown_render(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)
{
Expand Down Expand Up @@ -153,8 +156,174 @@ void test_dropdown_click(void)
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_render(void)
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());

Expand Down Expand Up @@ -200,5 +369,64 @@ void test_dropdown_render(void)
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_dropdown_open(dd7);

TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_2.png");
}



#endif

0 comments on commit 4143b80

Please sign in to comment.