mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-27 03:33:48 +08:00
fix(file_exploer): fix path issues when returning to open other folders after opening a certain folder (#7258)
Signed-off-by: lhdjply <lhdjply@126.com>
This commit is contained in:
parent
825c4efeca
commit
62d9f10f61
@ -619,7 +619,7 @@ static void show_dir(lv_obj_t * obj, const char * path)
|
|||||||
/*Move the table to the top*/
|
/*Move the table to the top*/
|
||||||
lv_obj_scroll_to_y(explorer->file_table, 0, LV_ANIM_OFF);
|
lv_obj_scroll_to_y(explorer->file_table, 0, LV_ANIM_OFF);
|
||||||
|
|
||||||
lv_strlcpy(explorer->current_path, path, sizeof(explorer->current_path));
|
lv_strncpy(explorer->current_path, path, sizeof(explorer->current_path));
|
||||||
lv_label_set_text_fmt(explorer->path_label, LV_SYMBOL_EYE_OPEN" %s", path);
|
lv_label_set_text_fmt(explorer->path_label, LV_SYMBOL_EYE_OPEN" %s", path);
|
||||||
|
|
||||||
size_t current_path_len = lv_strlen(explorer->current_path);
|
size_t current_path_len = lv_strlen(explorer->current_path);
|
||||||
|
104
tests/src/test_cases/test_file_explorer.c
Normal file
104
tests/src/test_cases/test_file_explorer.c
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#if LV_BUILD_TEST
|
||||||
|
#include "../lvgl.h"
|
||||||
|
#include "../../lvgl_private.h"
|
||||||
|
|
||||||
|
#include "unity/unity.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
static lv_obj_t * active_screen = NULL;
|
||||||
|
static lv_obj_t * file_explorer_obj;
|
||||||
|
static lv_file_explorer_t * file_explorer;
|
||||||
|
static lv_table_t * file_table;
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
active_screen = lv_screen_active();
|
||||||
|
file_explorer_obj = lv_file_explorer_create(active_screen);
|
||||||
|
file_explorer = (lv_file_explorer_t *)file_explorer_obj;
|
||||||
|
file_table = (lv_table_t *)file_explorer->file_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
/* Is there a way to destroy a chart without having to call remove_series for each of it series? */
|
||||||
|
lv_obj_clean(active_screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_file_explorer_read_dir(void)
|
||||||
|
{
|
||||||
|
uint8_t back_row = 0, dev_row = 0, shm_row = 0, home_row = 0, user_row = 0;
|
||||||
|
|
||||||
|
mkdir("src/test_files/test_file_explorer_folder", 0777);
|
||||||
|
mkdir("src/test_files/test_file_explorer_folder/dev", 0777);
|
||||||
|
mkdir("src/test_files/test_file_explorer_folder/dev/shm", 0777);
|
||||||
|
mkdir("src/test_files/test_file_explorer_folder/home", 0777);
|
||||||
|
mkdir("src/test_files/test_file_explorer_folder/home/web_user", 0777);
|
||||||
|
|
||||||
|
lv_file_explorer_open_dir(file_explorer_obj, "A:src/test_files/test_file_explorer_folder");
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < file_table->row_cnt; i++) {
|
||||||
|
if(lv_strcmp(lv_table_get_cell_value(file_explorer->file_table, i, 0), LV_SYMBOL_DIRECTORY " ..") == 0) {
|
||||||
|
back_row = i;
|
||||||
|
}
|
||||||
|
if(lv_strcmp(lv_table_get_cell_value(file_explorer->file_table, i, 0), LV_SYMBOL_DIRECTORY " dev") == 0) {
|
||||||
|
dev_row = i;
|
||||||
|
}
|
||||||
|
if(lv_strcmp(lv_table_get_cell_value(file_explorer->file_table, i, 0), LV_SYMBOL_DIRECTORY " home") == 0) {
|
||||||
|
home_row = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_table->row_act = dev_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/dev/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < file_table->row_cnt; i++) {
|
||||||
|
if(lv_strcmp(lv_table_get_cell_value(file_explorer->file_table, i, 0), LV_SYMBOL_DIRECTORY " shm") == 0) {
|
||||||
|
shm_row = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_table->row_act = shm_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/dev/shm/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
file_table->row_act = back_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/dev/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
file_table->row_act = back_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
file_table->row_act = home_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/home/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < file_table->row_cnt; i++) {
|
||||||
|
if(lv_strcmp(lv_table_get_cell_value(file_explorer->file_table, i, 0), LV_SYMBOL_DIRECTORY " web_user") == 0) {
|
||||||
|
user_row = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_table->row_act = user_row;
|
||||||
|
lv_obj_send_event(file_explorer->file_table, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A:src/test_files/test_file_explorer_folder/home/web_user/",
|
||||||
|
lv_file_explorer_get_current_path(file_explorer_obj));
|
||||||
|
|
||||||
|
rmdir("src/test_files/test_file_explorer_folder/dev/shm");
|
||||||
|
rmdir("src/test_files/test_file_explorer_folder/dev");
|
||||||
|
rmdir("src/test_files/test_file_explorer_folder/home/web_user");
|
||||||
|
rmdir("src/test_files/test_file_explorer_folder/home");
|
||||||
|
rmdir("src/test_files/test_file_explorer_folder");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user