aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabor Kiss-Vamosi <kisvegabor@gmail.com>2021-06-03 16:38:58 +0200
committerGabor Kiss-Vamosi <kisvegabor@gmail.com>2021-06-18 14:13:41 +0200
commit28d2ad4c3ad013b9e6228eb425fabffbcbe4521c (patch)
tree6554f7c3b6abba3f87f6a531eac7a78996c40232
parentea8bed34b49343a4e881bdd42096f69d245ef66e (diff)
downloadlvgl-28d2ad4c3ad013b9e6228eb425fabffbcbe4521c.tar.gz
lvgl-28d2ad4c3ad013b9e6228eb425fabffbcbe4521c.zip
feat(test) add assert for screenshot compare
-rw-r--r--tests/Makefile1
-rw-r--r--tests/defines.py1
-rw-r--r--tests/lv_test_init.c2
-rw-r--r--tests/lv_test_main.c2
-rwxr-xr-xtests/main.py4
-rw-r--r--tests/ref_imgs/scr1.pngbin0 -> 1950 bytes
-rw-r--r--tests/test_obj_tree.c12
-rw-r--r--tests/unity/unity.c1
-rw-r--r--tests/unity/unity.h5
-rw-r--r--tests/unity/unity_support.c198
-rw-r--r--tests/unity/unity_support.h42
11 files changed, 262 insertions, 6 deletions
diff --git a/tests/Makefile b/tests/Makefile
index f4f13f9c8..9cfe149c2 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -25,6 +25,7 @@ include ../lvgl.mk
CSRCS += ${TEST_SRC}
CSRCS += unity/unity.c
+CSRCS += unity/unity_support.c
CSRCS += lv_test_init.c
OBJEXT ?= .o
diff --git a/tests/defines.py b/tests/defines.py
index d3f4703c3..44fe87480 100644
--- a/tests/defines.py
+++ b/tests/defines.py
@@ -97,6 +97,7 @@ full_32bit = {
"LV_IMG_CACHE_DEF_SIZE":32,
"LV_USE_LOG":1,
+ "LV_USE_LOG_LEVEL":"LV_LOG_LEVEL_TRACE",
"LV_LOG_PRINTF":1,
"LV_USE_FONT_SUBPX": 1,
"LV_FONT_SUBPX_BGR":1,
diff --git a/tests/lv_test_init.c b/tests/lv_test_init.c
index 020795dcc..4f8d91131 100644
--- a/tests/lv_test_init.c
+++ b/tests/lv_test_init.c
@@ -91,7 +91,7 @@ static void hal_init(void)
{
static lv_disp_draw_buf_t draw_buf;
- lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, LV_HOR_RES * LV_VER_RES);
+ lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, HOR_RES * VER_RES);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
diff --git a/tests/lv_test_main.c b/tests/lv_test_main.c
index 7e2e3fb2c..114e18f24 100644
--- a/tests/lv_test_main.c
+++ b/tests/lv_test_main.c
@@ -1,8 +1,6 @@
#include "../lvgl.h"
#include <stdio.h>
#include <stdlib.h>
-#include "lv_test_core/lv_test_core.h"
-#include "lv_test_widgets/lv_test_label.h"
#if LV_BUILD_TEST && !defined(LV_BUILD_TEST_NO_MAIN)
#include <sys/time.h>
diff --git a/tests/main.py b/tests/main.py
index d27bd0e81..bac778562 100755
--- a/tests/main.py
+++ b/tests/main.py
@@ -8,13 +8,13 @@ import test
files = test.prepare()
print("============================================")
-print("Minimal config, 16 bit color depth")
+print("Full config, 32 bit color depth")
print("============================================")
print("")
for f in files:
name = f[:-2] #test_foo.c -> test_foo
- build.build(defines.minimal_16bit, name)
+ build.build(defines.full_32bit, name)
#build("Minimal config monochrome", minimal_monochrome)
diff --git a/tests/ref_imgs/scr1.png b/tests/ref_imgs/scr1.png
new file mode 100644
index 000000000..f0bd85287
--- /dev/null
+++ b/tests/ref_imgs/scr1.png
Binary files differ
diff --git a/tests/test_obj_tree.c b/tests/test_obj_tree.c
index ca34fb806..0d0f8ba46 100644
--- a/tests/test_obj_tree.c
+++ b/tests/test_obj_tree.c
@@ -13,7 +13,7 @@ void test_obj_tree_1(void)
void test_obj_tree_2(void)
{
- return;
+
lv_obj_create(lv_scr_act());
lv_obj_t * o2 = lv_obj_create(lv_scr_act());
lv_obj_create(lv_scr_act());
@@ -24,6 +24,16 @@ void test_obj_tree_2(void)
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
diff --git a/tests/unity/unity.c b/tests/unity/unity.c
index 872da5b0b..efc9c57ee 100644
--- a/tests/unity/unity.c
+++ b/tests/unity/unity.c
@@ -4,6 +4,7 @@
[Released under MIT License. Please refer to license.txt for details]
============================================================================ */
#if LV_BUILD_TEST
+#define UNITY_INCLUDE_PRINT_FORMATTED 1
#include "unity.h"
#include <stddef.h>
diff --git a/tests/unity/unity.h b/tests/unity/unity.h
index 0def296f9..bf8eceaea 100644
--- a/tests/unity/unity.h
+++ b/tests/unity/unity.h
@@ -4,6 +4,8 @@
[Released under MIT License. Please refer to license.txt for details]
========================================== */
#if LV_BUILD_TEST
+#define UNITY_INCLUDE_PRINT_FORMATTED 1
+
#ifndef UNITY_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
#define UNITY
@@ -660,4 +662,7 @@ void verifyTest(void);
#endif
#endif
+
+#include "unity_support.h"
+
#endif /*LV_BUILD_TEST*/
diff --git a/tests/unity/unity_support.c b/tests/unity/unity_support.c
new file mode 100644
index 000000000..8bc8402ac
--- /dev/null
+++ b/tests/unity/unity_support.c
@@ -0,0 +1,198 @@
+/**
+ * @file lv_test_assert.c
+ *
+ * Copyright 2002-2010 Guillaume Cottenceau.
+ *
+ * This software may be freely redistributed under the terms
+ * of the X11 license.
+ *
+ */
+
+/*********************
+ * INCLUDES
+ *********************/
+#if LV_BUILD_TEST
+#include "../lvgl.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include "unity.h"
+#define PNG_DEBUG 3
+#include <png.h>
+
+/*********************
+ * DEFINES
+ *********************/
+//#define REF_IMGS_PATH "lvgl/tests/lv_test_ref_imgs/"
+#define REF_IMGS_PATH "ref_imgs/"
+
+/**********************
+ * TYPEDEFS
+ **********************/
+typedef struct {
+ int width, height;
+ png_byte color_type;
+ png_byte bit_depth;
+
+ png_structp png_ptr;
+ png_infop info_ptr;
+ int number_of_passes;
+ png_bytep * row_pointers;
+}png_img_t;
+
+/**********************
+ * STATIC PROTOTYPES
+ **********************/
+static int read_png_file(png_img_t * p, const char* file_name);
+static void png_release(png_img_t * p);
+
+/**********************
+ * STATIC VARIABLES
+ **********************/
+
+/**********************
+ * MACROS
+ **********************/
+
+/**********************
+ * GLOBAL FUNCTIONS
+ **********************/
+
+bool lv_test_assert_img_eq(const char * fn_ref)
+{
+
+ char fn_ref_full[512];
+ sprintf(fn_ref_full, "%s%s", REF_IMGS_PATH, fn_ref);
+
+ png_img_t p;
+ int res = read_png_file(&p, fn_ref_full);
+ if(res < 0) return false;
+ uint8_t * screen_buf;
+
+ lv_obj_invalidate(lv_scr_act());
+ lv_refr_now(NULL);
+
+ extern lv_color_t test_fb[];
+
+ screen_buf = (uint8_t *)test_fb;
+
+ uint8_t * ptr_act = NULL;
+ const png_byte* ptr_ref = NULL;
+
+ bool err = false;
+ int x, y, i_buf = 0;
+ for (y = 0; y < p.height; y++) {
+ png_byte* row = p.row_pointers[y];
+ for (x = 0; x < p.width; x++) {
+ ptr_ref = &(row[x*3]);
+ ptr_act = &(screen_buf[i_buf*4]);
+
+ uint8_t tmp = ptr_act[0];
+ ptr_act[0] = ptr_act[2];
+ ptr_act[2] = tmp;
+
+ if(memcmp(ptr_act, ptr_ref, 3) != 0) {
+ err = true;
+ break;
+ }
+ i_buf++;
+ }
+ if(err) break;
+ }
+
+ png_release(&p);
+
+ if(err) {
+ uint32_t ref_px = 0;
+ uint32_t act_px = 0;
+ memcpy(&ref_px, ptr_ref, 3);
+ memcpy(&act_px, ptr_act, 3);
+ TEST_PRINTF("Diff in %s at (%d;%d), %x instead of %x)", fn_ref, x, y, act_px, ref_px);
+ return false;
+ }
+
+ return true;
+
+}
+
+/**********************
+ * STATIC FUNCTIONS
+ **********************/
+
+static int read_png_file(png_img_t * p, const char* file_name)
+{
+ char header[8]; // 8 is the maximum size that can be checked
+
+ /*open file and test for it being a png*/
+ FILE *fp = fopen(file_name, "rb");
+ if (!fp) {
+ TEST_PRINTF("%s", "PNG file %s could not be opened for reading");
+ return -1;
+ }
+
+ size_t rcnt = fread(header, 1, 8, fp);
+ if (rcnt != 8 || png_sig_cmp((png_const_bytep)header, 0, 8)) {
+ TEST_PRINTF("%s is not recognized as a PNG file", file_name);
+ return -1;
+ }
+
+ /*initialize stuff*/
+ p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if (!p->png_ptr) {
+ TEST_PRINTF("%s", "png_create_read_struct failed");
+ return -1;
+ }
+
+ p->info_ptr = png_create_info_struct(p->png_ptr);
+ if (!p->info_ptr) {
+ TEST_PRINTF("%s", "png_create_info_struct failed");
+ return -1;
+ }
+ if (setjmp(png_jmpbuf(p->png_ptr))) {
+ TEST_PRINTF("%s", "Error during init_io");
+ return -1;
+ }
+ png_init_io(p->png_ptr, fp);
+ png_set_sig_bytes(p->png_ptr, 8);
+
+ png_read_info(p->png_ptr, p->info_ptr);
+
+ p->width = png_get_image_width(p->png_ptr, p->info_ptr);
+ p->height = png_get_image_height(p->png_ptr, p->info_ptr);
+ p->color_type = png_get_color_type(p->png_ptr, p->info_ptr);
+ p->bit_depth = png_get_bit_depth(p->png_ptr, p->info_ptr);
+
+ p->number_of_passes = png_set_interlace_handling(p->png_ptr);
+ png_read_update_info(p->png_ptr, p->info_ptr);
+
+ /*read file*/
+ if (setjmp(png_jmpbuf(p->png_ptr))) {
+ TEST_PRINTF("%s", "Error during read_image");
+ return -1;
+ }
+ p->row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * p->height);
+
+ int y;
+ for (y=0; y<p->height; y++)
+ p->row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(p->png_ptr,p->info_ptr));
+
+ png_read_image(p->png_ptr, p->row_pointers);
+
+ fclose(fp);
+ return 0;
+}
+
+static void png_release(png_img_t * p)
+{
+ int y;
+ for (y=0; y<p->height; y++) free(p->row_pointers[y]);
+
+ free(p->row_pointers);
+}
+
+
+#endif
diff --git a/tests/unity/unity_support.h b/tests/unity/unity_support.h
new file mode 100644
index 000000000..f3d168cf4
--- /dev/null
+++ b/tests/unity/unity_support.h
@@ -0,0 +1,42 @@
+
+#ifndef LV_UNITY_SUPPORT_H
+#define LV_UNITY_SUPPORT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+#include "../../lvgl.h"
+
+bool lv_test_assert_img_eq(const char * fn_ref);
+
+
+#if LV_COLOR_DEPTH != 32
+# define TEST_ASSERT_EQUAL_SCREENSHOT(path) TEST_IGNORE_MESSAGE("Requires LV_COLOR_DEPTH 32");
+# define TEST_ASSERT_EQUAL_SCREENSHOT_MESSAGE(path, msg) TEST_PRINTF(msg); TEST_IGNORE_MESSAGE("Requires LV_COLOR_DEPTH 32");
+#else
+
+# define TEST_ASSERT_EQUAL_SCREENSHOT(path) if(LV_HOR_RES != 800 || LV_VER_RES != 480) { \
+ TEST_IGNORE_MESSAGE("Requires 800x480 resolution"); \
+ } else { \
+ TEST_ASSERT(lv_test_assert_img_eq(path)); \
+ }
+
+# define TEST_ASSERT_EQUAL_SCREENSHOT_MESSAGE(path, msg) if(LV_HOR_RES != 800 || LV_VER_RES != 480) { \
+ TEST_PRINTF(msg); \
+ TEST_IGNORE_MESSAGE("Requires 800x480 resolution"); \
+ } else { \
+ TEST_ASSERT_MESSAGE(lv_test_assert_img_eq(path), msg); \
+ }
+#endif
+
+# define TEST_ASSERT_EQUAL_COLOR(c1, c2) TEST_ASSERT_EQUAL_UINT32(c1.full, c2.full)
+# define TEST_ASSERT_EQUAL_COLOR_MESSAGE(c1, c2, msg) TEST_ASSERT_EQUAL_UINT32_MESSAGE(c1.full, c2.full, msg)
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*LV_UNITY_SUPPORT_H*/
+