mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 11:07:34 +08:00
test(array): improve lv_array test coverage (#9108)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ lv_result_t lv_array_erase(lv_array_t * array, uint32_t start, uint32_t end)
|
||||
uint8_t * start_p = lv_array_at(array, start);
|
||||
uint8_t * remaining = start_p + (end - start) * array->element_size;
|
||||
uint32_t remaining_size = (array->size - end) * array->element_size;
|
||||
lv_memcpy(start_p, remaining, remaining_size);
|
||||
lv_memmove(start_p, remaining, remaining_size);
|
||||
array->size -= (end - start);
|
||||
lv_array_shrink(array);
|
||||
return LV_RESULT_OK;
|
||||
|
||||
@@ -100,4 +100,172 @@ void test_array_concat(void)
|
||||
lv_array_deinit(&b);
|
||||
}
|
||||
|
||||
void test_array_init_from_buf(void)
|
||||
{
|
||||
int32_t buf[4] = { 0 };
|
||||
lv_array_t a;
|
||||
lv_array_init_from_buf(&a, buf, 4, sizeof(int32_t));
|
||||
|
||||
TEST_ASSERT_FALSE(lv_array_resize(&a, 8));
|
||||
|
||||
lv_array_t b;
|
||||
lv_array_init(&b, 4, sizeof(int32_t));
|
||||
lv_array_push_back(&b, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(4, lv_array_capacity(&a));
|
||||
|
||||
for(int32_t i = 0; i < 4; i++) {
|
||||
lv_array_push_back(&a, &i);
|
||||
}
|
||||
|
||||
/* Test overflow handling, should fail */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_push_back(&a, NULL));
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_concat(&a, &b));
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(4, lv_array_size(&a));
|
||||
for(int32_t i = 0; i < 4; i++) {
|
||||
int32_t * v = lv_array_at(&a, i);
|
||||
TEST_ASSERT_EQUAL_INT32(i, *v);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(buf, lv_array_front(&a));
|
||||
TEST_ASSERT_EQUAL_PTR(buf + 3, lv_array_back(&a));
|
||||
|
||||
lv_array_deinit(&a);
|
||||
lv_array_deinit(&b);
|
||||
}
|
||||
|
||||
void test_array_shrink(void)
|
||||
{
|
||||
for(int32_t i = 0; i < 10; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
TEST_ASSERT_EQUAL_UINT32(10, lv_array_size(&array));
|
||||
|
||||
lv_array_resize(&array, 20);
|
||||
TEST_ASSERT_EQUAL_UINT32(20, lv_array_capacity(&array));
|
||||
|
||||
lv_array_shrink(&array);
|
||||
TEST_ASSERT_EQUAL_UINT32(10, lv_array_capacity(&array));
|
||||
|
||||
/* Double shrink should not shrink more */
|
||||
lv_array_shrink(&array);
|
||||
TEST_ASSERT_EQUAL_UINT32(10, lv_array_capacity(&array));
|
||||
}
|
||||
|
||||
void test_array_remove(void)
|
||||
{
|
||||
for(int32_t i = 0; i < 5; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
TEST_ASSERT_EQUAL_UINT32(5, lv_array_size(&array));
|
||||
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_remove(&array, 4));
|
||||
TEST_ASSERT_EQUAL_UINT32(4, lv_array_size(&array));
|
||||
|
||||
/* Test remove out of range, should fail */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_remove(&array, 4));
|
||||
TEST_ASSERT_EQUAL_UINT32(4, lv_array_size(&array));
|
||||
|
||||
/* remove the last element */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_remove(&array, 3));
|
||||
TEST_ASSERT_EQUAL_UINT32(3, lv_array_size(&array));
|
||||
|
||||
/* remove the first element */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_remove(&array, 0));
|
||||
TEST_ASSERT_EQUAL_UINT32(2, lv_array_size(&array));
|
||||
|
||||
/* verify the content */
|
||||
for(int32_t i = 0; i < 2; i++) {
|
||||
int32_t * v = lv_array_at(&array, i);
|
||||
TEST_ASSERT_EQUAL_INT32(i + 1, *v);
|
||||
}
|
||||
}
|
||||
|
||||
void test_array_erase(void)
|
||||
{
|
||||
/* Test overlapping memory regions */
|
||||
for(int32_t i = 0; i < 5; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_erase(&array, 0, 1));
|
||||
TEST_ASSERT_EQUAL_UINT32(4, lv_array_size(&array));
|
||||
for(int32_t i = 0; i < 4; i++) {
|
||||
int32_t * v = lv_array_at(&array, i);
|
||||
TEST_ASSERT_EQUAL_INT32(i + 1, *v);
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < 10; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
/* Test erase from the middle */
|
||||
lv_array_clear(&array);
|
||||
for(int32_t i = 0; i < 10; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT32(10, lv_array_size(&array));
|
||||
lv_array_erase(&array, 3, 7);
|
||||
TEST_ASSERT_EQUAL_UINT32(6, lv_array_size(&array));
|
||||
for(int32_t i = 0; i < 6; i++) {
|
||||
int32_t * v = lv_array_at(&array, i);
|
||||
if(i < 3) {
|
||||
TEST_ASSERT_EQUAL_INT32(i, *v);
|
||||
}
|
||||
else {
|
||||
TEST_ASSERT_EQUAL_INT32(i + 4, *v);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test edge cases */
|
||||
lv_array_clear(&array);
|
||||
for(int32_t i = 0; i < 10; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
/* end > array->size */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_erase(&array, 3, 15));
|
||||
TEST_ASSERT_EQUAL_UINT32(3, lv_array_size(&array));
|
||||
for(int32_t i = 0; i < 3; i++) {
|
||||
int32_t * v = lv_array_at(&array, i);
|
||||
TEST_ASSERT_EQUAL_INT32(i, *v);
|
||||
}
|
||||
|
||||
/* Reset array */
|
||||
lv_array_clear(&array);
|
||||
for(int32_t i = 0; i < 10; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
/* start >= end */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_erase(&array, 5, 5));
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_erase(&array, 7, 6));
|
||||
|
||||
/* end == array->size */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_erase(&array, 5, 10));
|
||||
TEST_ASSERT_EQUAL_UINT32(5, lv_array_size(&array));
|
||||
for(int32_t i = 0; i < 5; i++) {
|
||||
int32_t * v = lv_array_at(&array, i);
|
||||
TEST_ASSERT_EQUAL_INT32(i, *v);
|
||||
}
|
||||
}
|
||||
|
||||
void test_array_assign(void)
|
||||
{
|
||||
for(int32_t i = 0; i < 5; i++) {
|
||||
lv_array_push_back(&array, &i);
|
||||
}
|
||||
|
||||
int32_t v = 100;
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_OK, lv_array_assign(&array, 2, &v));
|
||||
|
||||
int32_t * r = lv_array_at(&array, 2);
|
||||
TEST_ASSERT_EQUAL_INT32(100, *r);
|
||||
|
||||
/* Test out of range, should fail */
|
||||
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, lv_array_assign(&array, 5, &v));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user