1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4 
5 #include "unity/unity.h"
6 
7 static lv_obj_t * active_screen = NULL;
8 
setUp(void)9 void setUp(void)
10 {
11     active_screen = lv_screen_active();
12 }
13 
tearDown(void)14 void tearDown(void)
15 {
16     lv_obj_clean(active_screen);
17 }
18 
get_imgfont_path(const lv_font_t * font,uint32_t unicode,uint32_t unicode_next,int32_t * offset_y,void * user_data)19 static const void * get_imgfont_path(const lv_font_t * font, uint32_t unicode, uint32_t unicode_next,
20                                      int32_t * offset_y, void * user_data)
21 {
22     LV_UNUSED(font);
23     LV_UNUSED(unicode_next);
24     LV_UNUSED(offset_y);
25     LV_UNUSED(user_data);
26 
27     LV_IMAGE_DECLARE(emoji_F617);
28 
29     if(unicode == 0xF617) {
30         return &emoji_F617;
31     }
32     else if(unicode == 0xF600) {
33         return "A:src/test_assets/test_img_emoji_F600.png";
34     }
35 
36     return NULL;
37 }
38 
test_imgfont_creation(void)39 void test_imgfont_creation(void)
40 {
41     lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path, NULL);
42     TEST_ASSERT_NOT_NULL(imgfont);
43 
44     imgfont->fallback = LV_FONT_DEFAULT;
45 
46     lv_obj_t * label = lv_label_create(lv_screen_active());
47     lv_label_set_text(label, "12\uF600\uF617\uF000AB");
48     lv_obj_set_style_text_font(label, imgfont, LV_PART_MAIN);
49     lv_obj_center(label);
50 
51     lv_refr_now(NULL);
52 
53     TEST_ASSERT_EQUAL_SCREENSHOT("widgets/imgfont_1.png");
54 
55     lv_imgfont_destroy(imgfont);
56 }
57 
58 #endif
59