1 #if LV_BUILD_TEST
2 #include "lv_test_init.h"
3 #include "lv_test_indev.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <assert.h>
7 #include "../unity/unity.h"
8 
9 #define HOR_RES 800
10 #define VER_RES 480
11 
12 static void hal_init(void);
13 static void dummy_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p);
14 static void test_log_print_cb(lv_log_level_t level, const char * buf);
15 
16 uint8_t * last_flushed_buf;
17 lv_indev_t * lv_test_mouse_indev;
18 lv_indev_t * lv_test_keypad_indev;
19 lv_indev_t * lv_test_encoder_indev;
20 
lv_test_init(void)21 void lv_test_init(void)
22 {
23     lv_init();
24 
25     lv_log_register_print_cb(test_log_print_cb);
26 
27 #if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
28     /* Disable profiler, to reduce redundant profiler log printing  */
29     lv_profiler_builtin_set_enable(false);
30 #endif
31 
32     hal_init();
33 #if LV_USE_SYSMON
34 #if LV_USE_MEM_MONITOR
35     lv_sysmon_hide_memory(NULL);
36 #endif
37 #if LV_USE_PERF_MONITOR
38     lv_sysmon_hide_performance(NULL);
39 #endif
40 #endif
41 }
42 
lv_test_deinit(void)43 void lv_test_deinit(void)
44 {
45     lv_mem_deinit();
46 }
47 
color_format_changled_event_cb(lv_event_t * e)48 static void color_format_changled_event_cb(lv_event_t * e)
49 {
50     lv_display_t * disp = lv_event_get_target(e);
51     lv_color_format_t cf = lv_display_get_color_format(disp);
52     lv_draw_buf_t * draw_buf = lv_display_get_buf_active(NULL);
53 
54     lv_display_set_buffers(disp, lv_draw_buf_align(draw_buf->unaligned_data, cf), NULL, draw_buf->data_size,
55                            LV_DISPLAY_RENDER_MODE_DIRECT);
56 
57 }
58 
hal_init(void)59 static void hal_init(void)
60 {
61 
62     static lv_color32_t test_fb[(HOR_RES + LV_DRAW_BUF_STRIDE_ALIGN - 1) * VER_RES + LV_DRAW_BUF_ALIGN];
63     lv_display_t * disp = lv_display_create(HOR_RES, VER_RES);
64     lv_display_set_buffers(disp, lv_draw_buf_align(test_fb, LV_COLOR_FORMAT_ARGB8888), NULL, HOR_RES * VER_RES * 4,
65                            LV_DISPLAY_RENDER_MODE_DIRECT);
66     lv_display_set_flush_cb(disp, dummy_flush_cb);
67     lv_display_add_event_cb(disp, color_format_changled_event_cb, LV_EVENT_COLOR_FORMAT_CHANGED, NULL);
68     lv_test_mouse_indev = lv_indev_create();
69     lv_indev_set_type(lv_test_mouse_indev, LV_INDEV_TYPE_POINTER);
70     lv_indev_set_read_cb(lv_test_mouse_indev,  lv_test_mouse_read_cb);
71 
72     lv_test_keypad_indev = lv_indev_create();
73     lv_indev_set_type(lv_test_keypad_indev, LV_INDEV_TYPE_KEYPAD);
74     lv_indev_set_read_cb(lv_test_keypad_indev,  lv_test_keypad_read_cb);
75 
76     lv_test_encoder_indev = lv_indev_create();
77     lv_indev_set_type(lv_test_encoder_indev, LV_INDEV_TYPE_ENCODER);
78     lv_indev_set_read_cb(lv_test_encoder_indev,  lv_test_encoder_read_cb);
79 }
80 
dummy_flush_cb(lv_display_t * disp,const lv_area_t * area,uint8_t * color_p)81 static void dummy_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p)
82 {
83     LV_UNUSED(area);
84     LV_UNUSED(color_p);
85     last_flushed_buf = color_p;
86     lv_display_flush_ready(disp);
87 }
88 
test_log_print_cb(lv_log_level_t level,const char * buf)89 static void test_log_print_cb(lv_log_level_t level, const char * buf)
90 {
91     if(level < LV_LOG_LEVEL_WARN) {
92         return;
93     }
94 
95     TEST_PRINTF("%s", buf);
96 }
97 
lv_test_assert_fail(void)98 void lv_test_assert_fail(void)
99 {
100     /*Flush the output*/
101     fflush(stdout);
102 
103     /*Handle error on test*/
104     assert(false);
105 }
106 
107 #endif
108