1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4
5 #include "unity/unity.h"
6
setUp(void)7 void setUp(void)
8 {
9 /* Function run before every test */
10 lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP);
11 lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY);
12 }
13
tearDown(void)14 void tearDown(void)
15 {
16 /* Function run after every test */
17 lv_obj_clean(lv_screen_active());
18 }
19
label_create(const lv_font_t * font,lv_style_t * style,const char * text_base)20 static lv_obj_t * label_create(const lv_font_t * font, lv_style_t * style, const char * text_base)
21 {
22 lv_obj_t * label = lv_label_create(lv_screen_active());
23 lv_label_set_text_fmt(label, "%s: the quick brown fox jumps over the lazy dog", text_base);
24 // lv_label_set_text_fmt(label, "l");
25 lv_obj_set_style_text_font(label, font, 0);
26 if(style) lv_obj_add_style(label, style, 0);
27
28 return label;
29 }
30
all_labels_create(const char * name,lv_style_t * style)31 static void all_labels_create(const char * name, lv_style_t * style)
32 {
33 LV_FONT_DECLARE(test_font_montserrat_ascii_1bpp);
34 LV_FONT_DECLARE(test_font_montserrat_ascii_2bpp);
35 LV_FONT_DECLARE(test_font_montserrat_ascii_4bpp);
36 LV_FONT_DECLARE(test_font_montserrat_ascii_3bpp_compressed);
37
38 label_create(&test_font_montserrat_ascii_1bpp, style, "1bpp font");
39 label_create(&test_font_montserrat_ascii_2bpp, style, "2bpp font");
40 label_create(&test_font_montserrat_ascii_4bpp, style, "4bpp font");
41 label_create(&test_font_montserrat_ascii_3bpp_compressed, style, "3bpp compressed font");
42
43 char buf[64];
44 lv_snprintf(buf, sizeof(buf), "draw/label_%s.png", name);
45 TEST_ASSERT_EQUAL_SCREENSHOT(buf);
46 }
47
test_draw_label_normal(void)48 void test_draw_label_normal(void)
49 {
50 all_labels_create("normal", NULL);
51 }
52
test_draw_label_color(void)53 void test_draw_label_color(void)
54 {
55 static lv_style_t style;
56 lv_style_init(&style);
57 lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
58 all_labels_create("color", &style);
59
60 }
61
test_draw_label_opa(void)62 void test_draw_label_opa(void)
63 {
64 static lv_style_t style;
65 lv_style_init(&style);
66 lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
67 all_labels_create("opa", &style);
68 }
69
test_draw_label_color_and_opa(void)70 void test_draw_label_color_and_opa(void)
71 {
72 static lv_style_t style;
73 lv_style_init(&style);
74 lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
75 lv_style_set_text_opa(&style, LV_OPA_50);
76 all_labels_create("color_and_opa", &style);
77 }
78
decor_label_create(lv_text_decor_t decor,lv_text_align_t align,lv_opa_t opa)79 static lv_obj_t * decor_label_create(lv_text_decor_t decor, lv_text_align_t align, lv_opa_t opa)
80 {
81 lv_color_t color = lv_palette_main(LV_PALETTE_BLUE);
82 lv_color_t sel_bg_color = lv_palette_lighten(LV_PALETTE_RED, 4);
83 lv_color_t sel_color = lv_palette_darken(LV_PALETTE_RED, 4);
84
85 lv_obj_t * label = lv_label_create(lv_screen_active());
86 lv_label_set_text(label, "Hi,\nTesting the\nlabels.");
87 lv_obj_set_style_text_decor(label, decor, 0);
88 lv_obj_set_style_text_color(label, color, 0);
89 lv_obj_set_style_text_opa(label, opa, 0);
90 lv_obj_set_style_text_align(label, align, 0);
91 lv_obj_set_style_bg_color(label, sel_bg_color, LV_PART_SELECTED);
92 lv_obj_set_style_text_color(label, sel_color, LV_PART_SELECTED);
93 lv_label_set_text_selection_start(label, 10);
94 lv_label_set_text_selection_end(label, 19);
95
96 return label;
97 }
98
all_decor_labels_create(lv_text_decor_t decor)99 static void all_decor_labels_create(lv_text_decor_t decor)
100 {
101
102 lv_obj_t * label;
103 label = decor_label_create(decor, LV_TEXT_ALIGN_LEFT, LV_OPA_COVER);
104 lv_obj_add_flag(label, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
105
106 label = decor_label_create(decor, LV_TEXT_ALIGN_CENTER, LV_OPA_COVER);
107 label = decor_label_create(decor, LV_TEXT_ALIGN_RIGHT, LV_OPA_COVER);
108
109 label = decor_label_create(decor, LV_TEXT_ALIGN_LEFT, LV_OPA_50);
110 label = decor_label_create(decor, LV_TEXT_ALIGN_CENTER, LV_OPA_50);
111 label = decor_label_create(decor, LV_TEXT_ALIGN_RIGHT, LV_OPA_50);
112 }
113
test_label_decor(void)114 void test_label_decor(void)
115 {
116 all_decor_labels_create(LV_TEXT_DECOR_NONE);
117 all_decor_labels_create(LV_TEXT_DECOR_UNDERLINE);
118 all_decor_labels_create(LV_TEXT_DECOR_STRIKETHROUGH);
119 all_decor_labels_create(LV_TEXT_DECOR_UNDERLINE | LV_TEXT_DECOR_STRIKETHROUGH);
120
121 TEST_ASSERT_EQUAL_SCREENSHOT("draw/label_decor.png");
122 }
123
test_label_selection_and_recolor(void)124 void test_label_selection_and_recolor(void)
125 {
126 lv_text_decor_t decor = LV_TEXT_DECOR_NONE;
127 lv_color_t color = lv_palette_main(LV_PALETTE_BLUE);
128 lv_color_t sel_bg_color = lv_palette_lighten(LV_PALETTE_RED, 4);
129 lv_color_t sel_color = lv_palette_darken(LV_PALETTE_RED, 4);
130
131 lv_obj_t * label = lv_label_create(lv_screen_active());
132 lv_label_set_recolor(label, true);
133 lv_label_set_text(label, "Hi, Testing the #00ff00 colored labels.#");
134 lv_obj_set_style_text_decor(label, decor, 0);
135 lv_obj_set_style_text_color(label, color, 0);
136 lv_obj_set_style_text_opa(label, LV_OPA_COVER, 0);
137 lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_LEFT, 0);
138 lv_obj_set_style_bg_color(label, sel_bg_color, LV_PART_SELECTED);
139 lv_obj_set_style_text_color(label, sel_color, LV_PART_SELECTED);
140 lv_label_set_text_selection_start(label, 10);
141 lv_label_set_text_selection_end(label, 25);
142
143 TEST_ASSERT_EQUAL_SCREENSHOT("draw/label_selection_and_recolor.png");
144 }
145
146 #endif
147